diff --git a/backend/app/src/main/java/io/metersphere/listener/AppStartListener.java b/backend/app/src/main/java/io/metersphere/listener/AppStartListener.java index 0265a153fe..be13ca21dc 100644 --- a/backend/app/src/main/java/io/metersphere/listener/AppStartListener.java +++ b/backend/app/src/main/java/io/metersphere/listener/AppStartListener.java @@ -2,9 +2,13 @@ package io.metersphere.listener; import io.metersphere.api.event.ApiEventSource; import io.metersphere.plan.listener.ExecEventListener; +import io.metersphere.sdk.constants.StorageType; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.MinioRepository; import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.service.PluginLoadService; +import io.minio.MinioClient; import jakarta.annotation.Resource; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; @@ -15,10 +19,15 @@ public class AppStartListener implements ApplicationRunner { @Resource private PluginLoadService pluginLoadService; + @Resource + private MinioClient minioClient; @Override public void run(ApplicationArguments args) throws Exception { LogUtils.info("================= 应用启动 ================="); + // 初始化MinIO配置 + ((MinioRepository) FileCenter.getRepository(StorageType.MINIO)).init(minioClient); + // 注册所有监听源 LogUtils.info("初始化接口事件源"); ApiEventSource apiEventSource = CommonBeanFactory.getBean(ApiEventSource.class); diff --git a/backend/framework/sdk/pom.xml b/backend/framework/sdk/pom.xml index 5506cd008b..c25d9788bd 100644 --- a/backend/framework/sdk/pom.xml +++ b/backend/framework/sdk/pom.xml @@ -217,6 +217,14 @@ otp-java ${otp-java.version} + + + + org.eclipse.jgit + org.eclipse.jgit + ${jgit.version} + + diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/FileMetadataRepositoryDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/FileMetadataRepositoryDTO.java new file mode 100644 index 0000000000..1d7987e915 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/FileMetadataRepositoryDTO.java @@ -0,0 +1,18 @@ +package io.metersphere.sdk.dto; + +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +public class FileMetadataRepositoryDTO implements Serializable { + private String fileMetadataId; + private String branch; + private String commitId; + + private String commitMessage; + + @Serial + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/FileModuleRepositoryDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/FileModuleRepositoryDTO.java new file mode 100644 index 0000000000..65015c0d26 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/FileModuleRepositoryDTO.java @@ -0,0 +1,22 @@ +package io.metersphere.sdk.dto; + +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +public class FileModuleRepositoryDTO implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + private String fileModuleId; + + private String platform; + + private String url; + + private String token; + + private String userName; +} \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/RemoteFileAttachInfo.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/RemoteFileAttachInfo.java similarity index 93% rename from backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/RemoteFileAttachInfo.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/RemoteFileAttachInfo.java index 96cbf6c971..c1a17f9b6f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/RemoteFileAttachInfo.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/RemoteFileAttachInfo.java @@ -1,4 +1,4 @@ -package io.metersphere.system.dto.sdk; +package io.metersphere.sdk.dto; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.AllArgsConstructor; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/RepositoryQuery.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/RepositoryQuery.java similarity index 85% rename from backend/services/system-setting/src/main/java/io/metersphere/system/dto/RepositoryQuery.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/RepositoryQuery.java index 08bd02dc27..0b533eda8e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/RepositoryQuery.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/RepositoryQuery.java @@ -1,4 +1,4 @@ -package io.metersphere.system.dto; +package io.metersphere.sdk.dto; import lombok.Data; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/file/FileCenter.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileCenter.java similarity index 59% rename from backend/services/system-setting/src/main/java/io/metersphere/system/file/FileCenter.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileCenter.java index b1b6eba615..1c6d21c689 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/file/FileCenter.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileCenter.java @@ -1,4 +1,4 @@ -package io.metersphere.system.file; +package io.metersphere.sdk.file; import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.util.CommonBeanFactory; @@ -7,15 +7,16 @@ import java.util.HashMap; import java.util.Map; public class FileCenter { + private FileCenter() { + } public static FileRepository getRepository(StorageType storageType) { - Map repositoryMap = new HashMap<>() {{ - put(StorageType.MINIO, CommonBeanFactory.getBean(MinioRepository.class)); - put(StorageType.LOCAL, CommonBeanFactory.getBean(LocalFileRepository.class)); - put(StorageType.GIT, CommonBeanFactory.getBean(GitRepository.class)); - }}; - FileRepository fileRepository = repositoryMap.get(storageType); - return fileRepository == null ? getDefaultRepository() : fileRepository; + return switch (storageType) { + case MINIO -> CommonBeanFactory.getBean(MinioRepository.class); + case LOCAL -> CommonBeanFactory.getBean(LocalFileRepository.class); + case GIT -> CommonBeanFactory.getBean(GitRepository.class); + default -> getDefaultRepository(); + }; } public static FileRepository getRepository(String storage) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/file/FileCopyRequest.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileCopyRequest.java similarity index 87% rename from backend/services/system-setting/src/main/java/io/metersphere/system/file/FileCopyRequest.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileCopyRequest.java index 707d23083c..1a1c490ba5 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/file/FileCopyRequest.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileCopyRequest.java @@ -1,4 +1,4 @@ -package io.metersphere.system.file; +package io.metersphere.sdk.file; import lombok.Data; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/file/FileRepository.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileRepository.java similarity index 98% rename from backend/services/system-setting/src/main/java/io/metersphere/system/file/FileRepository.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileRepository.java index 896e4e5bd1..0edfd7da3c 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/file/FileRepository.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileRepository.java @@ -1,4 +1,4 @@ -package io.metersphere.system.file; +package io.metersphere.sdk.file; import org.springframework.web.multipart.MultipartFile; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/file/FileRequest.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileRequest.java similarity index 71% rename from backend/services/system-setting/src/main/java/io/metersphere/system/file/FileRequest.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileRequest.java index bff52673c2..df4a6a2ed6 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/file/FileRequest.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/FileRequest.java @@ -1,7 +1,7 @@ -package io.metersphere.system.file; +package io.metersphere.sdk.file; -import io.metersphere.project.domain.FileMetadataRepository; -import io.metersphere.project.domain.FileModuleRepository; +import io.metersphere.sdk.dto.FileMetadataRepositoryDTO; +import io.metersphere.sdk.dto.FileModuleRepositoryDTO; import lombok.AllArgsConstructor; import lombok.Data; @@ -19,7 +19,7 @@ public class FileRequest { //Git文件信息 private GitFileRequest gitFileRequest; - public void setGitFileRequest(FileModuleRepository repository, FileMetadataRepository file) { + public void setGitFileRequest(FileModuleRepositoryDTO repository, FileMetadataRepositoryDTO file) { gitFileRequest = new GitFileRequest(repository.getUrl(), repository.getToken(), repository.getUserName(), file.getBranch(), file.getCommitId()); } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/file/GitRepository.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/GitRepository.java similarity index 96% rename from backend/services/system-setting/src/main/java/io/metersphere/system/file/GitRepository.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/file/GitRepository.java index 648761f692..a34f8d20e4 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/file/GitRepository.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/GitRepository.java @@ -1,7 +1,7 @@ -package io.metersphere.system.file; +package io.metersphere.sdk.file; import io.metersphere.sdk.exception.MSException; -import io.metersphere.system.utils.GitRepositoryUtil; +import io.metersphere.sdk.util.GitRepositoryUtil; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/file/LocalFileRepository.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java similarity index 99% rename from backend/services/system-setting/src/main/java/io/metersphere/system/file/LocalFileRepository.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java index adf49ef045..ad02b9c096 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/file/LocalFileRepository.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java @@ -1,4 +1,4 @@ -package io.metersphere.system.file; +package io.metersphere.sdk.file; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.MsFileUtils; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/file/MinioRepository.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/MinioRepository.java similarity index 70% rename from backend/services/system-setting/src/main/java/io/metersphere/system/file/MinioRepository.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/file/MinioRepository.java index 00b7509501..2f17362c61 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/file/MinioRepository.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/MinioRepository.java @@ -1,10 +1,11 @@ -package io.metersphere.system.file; +package io.metersphere.sdk.file; +import io.metersphere.plugin.sdk.util.PluginUtils; import io.metersphere.sdk.exception.MSException; -import io.metersphere.system.config.MinioConfig; +import io.metersphere.sdk.util.LogUtils; import io.minio.*; import io.minio.messages.Item; -import jakarta.annotation.Resource; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -15,14 +16,57 @@ import java.io.FileOutputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.Map; @Component public class MinioRepository implements FileRepository { - @Resource private MinioClient client; // 缓冲区大小 private static final int BUFFER_SIZE = 8192; + public static final String BUCKET = "metersphere"; + public static final String ENDPOINT = "endpoint"; + public static final String ACCESS_KEY = "accessKey"; + public static final String SECRET_KEY = "secretKey"; + + /** + * 初始化 + */ + public void init(MinioClient client) { + if (this.client == null) { + this.client = client; + } + } + + /** + * 根据配置信息动态创建 + */ + public void init(Map minioConfig) { + if (minioConfig == null || minioConfig.isEmpty()) { + LogUtils.info("MinIO初始化失败,参数[minioConfig]为空"); + return; + } + + try { + Object serverUrl = minioConfig.get(ENDPOINT).toString(); + if (ObjectUtils.isNotEmpty(serverUrl)) { + LogUtils.info("开始初始化MinIO插件。配置:", PluginUtils.toJSONString(minioConfig)); + // 创建 MinioClient 客户端 + client = MinioClient.builder() + .endpoint(minioConfig.get(ENDPOINT).toString()) + .credentials(minioConfig.get(ACCESS_KEY).toString(), minioConfig.get(SECRET_KEY).toString()) + .build(); + boolean exist = client.bucketExists(BucketExistsArgs.builder().bucket(BUCKET).build()); + if (!exist) { + client.makeBucket(MakeBucketArgs.builder().bucket(BUCKET).build()); + } + LogUtils.info("初始化MinIO成功"); + } + } catch (Exception e) { + LogUtils.error("MinIOClient初始化失败!", e); + } + } + private String getPath(FileRequest request) { String folder = request.getFolder(); @@ -37,7 +81,7 @@ public class MinioRepository implements FileRepository { // 文件存储路径 String filePath = getPath(request); client.putObject(PutObjectArgs.builder() - .bucket(MinioConfig.BUCKET) + .bucket(BUCKET) .object(filePath) .stream(file.getInputStream(), file.getSize(), -1) // 文件内容 .build()); @@ -49,7 +93,7 @@ public class MinioRepository implements FileRepository { String filePath = getPath(request); try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { client.putObject(PutObjectArgs.builder() - .bucket(MinioConfig.BUCKET) + .bucket(BUCKET) .object(filePath) .stream(inputStream, bytes.length, -1) .build()); @@ -66,19 +110,19 @@ public class MinioRepository implements FileRepository { public void delete(FileRequest request) throws Exception { String filePath = getPath(request); // 删除单个文件 - removeObject(MinioConfig.BUCKET, filePath); + removeObject(BUCKET, filePath); } @Override public void deleteFolder(FileRequest request) throws Exception { String filePath = getPath(request); // 删除文件夹 - removeObjects(MinioConfig.BUCKET, filePath); + removeObjects(BUCKET, filePath); } @Override public List getFolderFileNames(FileRequest request) throws Exception { - return listObjects(MinioConfig.BUCKET, getPath(request)); + return listObjects(BUCKET, getPath(request)); } @Override @@ -86,10 +130,10 @@ public class MinioRepository implements FileRepository { String sourcePath = StringUtils.join(request.getCopyFolder(), "/", request.getCopyfileName()); String targetPath = getPath(request); client.copyObject(CopyObjectArgs.builder() - .bucket(MinioConfig.BUCKET) + .bucket(BUCKET) .object(targetPath) .source(CopySource.builder() - .bucket(MinioConfig.BUCKET) + .bucket(BUCKET) .object(sourcePath) .build()) .build()); @@ -142,7 +186,7 @@ public class MinioRepository implements FileRepository { // 下载对象到本地文件 try (InputStream inputStream = client.getObject( GetObjectArgs.builder() - .bucket(MinioConfig.BUCKET) + .bucket(BUCKET) .object(fileName) .build()); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(fullPath))) { @@ -158,7 +202,7 @@ public class MinioRepository implements FileRepository { public InputStream getFileAsStream(FileRequest request) throws Exception { String fileName = getPath(request); return client.getObject(GetObjectArgs.builder() - .bucket(MinioConfig.BUCKET) // 存储桶 + .bucket(BUCKET) // 存储桶 .object(fileName) // 文件名 .build()); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/utils/GitRepositoryUtil.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java similarity index 97% rename from backend/services/system-setting/src/main/java/io/metersphere/system/utils/GitRepositoryUtil.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java index b0fc14ae3f..f2d3691e57 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/utils/GitRepositoryUtil.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java @@ -1,8 +1,7 @@ -package io.metersphere.system.utils; +package io.metersphere.sdk.util; -import io.metersphere.sdk.util.LogUtils; -import io.metersphere.system.dto.RepositoryQuery; -import io.metersphere.system.dto.sdk.RemoteFileAttachInfo; +import io.metersphere.sdk.dto.RemoteFileAttachInfo; +import io.metersphere.sdk.dto.RepositoryQuery; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.jgit.api.Git; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiFileResourceService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiFileResourceService.java index 61f75dc7aa..62e227b40a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiFileResourceService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiFileResourceService.java @@ -11,10 +11,10 @@ import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.Translator; -import io.metersphere.system.file.FileCenter; -import io.metersphere.system.file.FileCopyRequest; -import io.metersphere.system.file.FileRepository; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.FileCopyRequest; +import io.metersphere.sdk.file.FileRepository; +import io.metersphere.sdk.file.FileRequest; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java index eba0ac1427..1d3a28fa9b 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java @@ -42,8 +42,8 @@ import io.metersphere.system.domain.TestResourcePoolOrganizationExample; import io.metersphere.system.dto.pool.TestResourceDTO; import io.metersphere.system.dto.pool.TestResourceNodeDTO; import io.metersphere.system.dto.pool.TestResourcePoolDTO; -import io.metersphere.system.file.FileCenter; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.FileRequest; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.mapper.TestResourcePoolBlobMapper; import io.metersphere.system.mapper.TestResourcePoolMapper; diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java index 904b4f9876..e2105454cf 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java @@ -22,8 +22,8 @@ import io.metersphere.sdk.util.*; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.dto.sdk.BaseCondition; -import io.metersphere.system.file.FileCenter; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.FileRequest; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java index bc3b61b9ce..d7fbdae2b0 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java @@ -26,9 +26,9 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.dto.sdk.request.PosRequest; -import io.metersphere.system.file.FileCenter; -import io.metersphere.system.file.FileRequest; -import io.metersphere.system.file.MinioRepository; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.file.MinioRepository; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.uid.NumGenerator; import io.metersphere.system.utils.Pager; diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java index d98ea48e16..e372915380 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java @@ -26,7 +26,7 @@ import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.Template; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.TemplateDTO; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileRequest; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.mapper.BaseUserMapper; import io.metersphere.system.mapper.TemplateMapper; diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseAttachmentService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseAttachmentService.java index 2cbd207f88..a258bb1f4c 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseAttachmentService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseAttachmentService.java @@ -20,7 +20,7 @@ import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.FileAssociationSourceUtil; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileRequest; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseAttachmentControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseAttachmentControllerTests.java index 938f693f00..3da495f409 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseAttachmentControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseAttachmentControllerTests.java @@ -15,7 +15,7 @@ import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileRequest; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java index 148bfaf81f..29d0926aa1 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java @@ -21,8 +21,8 @@ import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.sdk.BaseSystemConfigDTO; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.request.PosRequest; -import io.metersphere.system.file.FileRequest; -import io.metersphere.system.file.MinioRepository; +import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.file.MinioRepository; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.dto.LogDTO; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileManagementService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileManagementService.java index dc4c0c5e20..0c441c50c5 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileManagementService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileManagementService.java @@ -8,7 +8,7 @@ import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.TempFileUtils; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileRequest; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java index a9ba7ecf9a..be92dd5004 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java @@ -17,18 +17,16 @@ import io.metersphere.project.utils.FileMetadataUtils; import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.constants.StorageType; +import io.metersphere.sdk.dto.FileMetadataRepositoryDTO; +import io.metersphere.sdk.dto.FileModuleRepositoryDTO; +import io.metersphere.sdk.dto.RemoteFileAttachInfo; import io.metersphere.sdk.exception.MSException; -import io.metersphere.sdk.util.CommonBeanFactory; -import io.metersphere.sdk.util.JSON; -import io.metersphere.sdk.util.TempFileUtils; -import io.metersphere.sdk.util.Translator; -import io.metersphere.system.dto.sdk.RemoteFileAttachInfo; -import io.metersphere.system.file.FileRepository; -import io.metersphere.system.file.FileRequest; -import io.metersphere.system.file.MinioRepository; +import io.metersphere.sdk.file.FileRepository; +import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.file.MinioRepository; +import io.metersphere.sdk.util.*; import io.metersphere.system.mapper.BaseUserMapper; import io.metersphere.system.uid.IDGenerator; -import io.metersphere.system.utils.GitRepositoryUtil; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; @@ -346,7 +344,12 @@ public class FileMetadataService { if (StringUtils.equals(fileMetadata.getStorage(), StorageType.GIT.name())) { FileModuleRepository fileModuleRepository = fileModuleRepositoryMapper.selectByPrimaryKey(fileMetadata.getModuleId()); FileMetadataRepository fileMetadataRepository = fileMetadataRepositoryMapper.selectByPrimaryKey(fileMetadata.getId()); - fileRequest.setGitFileRequest(fileModuleRepository, fileMetadataRepository); + + FileModuleRepositoryDTO repositoryDTO = new FileModuleRepositoryDTO(); + BeanUtils.copyBean(repositoryDTO, fileModuleRepository); + FileMetadataRepositoryDTO metadataRepositoryDTO = new FileMetadataRepositoryDTO(); + BeanUtils.copyBean(metadataRepositoryDTO, fileMetadataRepository); + fileRequest.setGitFileRequest(repositoryDTO, metadataRepositoryDTO); } return fileService.download(fileRequest); @@ -432,6 +435,7 @@ public class FileMetadataService { throw new MSException(Translator.get("file.size.is.too.large")); } } + private static final String FILE_MODULE_COUNT_MY = "my"; /** diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileRepositoryService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileRepositoryService.java index b3e2347c95..ee05b2e868 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileRepositoryService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileRepositoryService.java @@ -18,9 +18,9 @@ import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.sdk.BaseTreeNode; -import io.metersphere.system.dto.sdk.RemoteFileAttachInfo; +import io.metersphere.sdk.dto.RemoteFileAttachInfo; import io.metersphere.system.uid.IDGenerator; -import io.metersphere.system.utils.GitRepositoryUtil; +import io.metersphere.sdk.util.GitRepositoryUtil; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileService.java index a7652a9750..aa2acfacc6 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileService.java @@ -1,7 +1,7 @@ package io.metersphere.project.service; -import io.metersphere.system.file.FileCenter; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.FileRequest; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java index 73889568f1..61426fb1ea 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java @@ -35,8 +35,8 @@ import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.request.PosRequest; -import io.metersphere.system.file.FileRequest; -import io.metersphere.system.file.MinioRepository; +import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.file.MinioRepository; import io.metersphere.system.log.constants.OperationLogType; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java index 1b6ee71d25..cc2e5f9f1e 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java @@ -29,7 +29,7 @@ import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.dto.AddProjectRequest; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.request.NodeMoveRequest; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileRequest; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.service.CommonProjectService; diff --git a/backend/services/system-setting/pom.xml b/backend/services/system-setting/pom.xml index 0997ea689c..dce35c3532 100644 --- a/backend/services/system-setting/pom.xml +++ b/backend/services/system-setting/pom.xml @@ -139,13 +139,6 @@ springdoc-openapi-starter-webmvc-ui ${springdoc-openapi-ui.version} - - - - org.eclipse.jgit - org.eclipse.jgit - ${jgit.version} - diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/config/RsaConfig.java b/backend/services/system-setting/src/main/java/io/metersphere/system/config/RsaConfig.java index 49794190e2..cde1160be9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/config/RsaConfig.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/config/RsaConfig.java @@ -2,11 +2,14 @@ package io.metersphere.system.config; import io.metersphere.sdk.constants.DefaultRepositoryDir; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.FileRepository; +import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.file.MinioRepository; import io.metersphere.sdk.util.RsaKey; import io.metersphere.sdk.util.RsaUtils; -import io.metersphere.system.file.FileCenter; -import io.metersphere.system.file.FileRepository; -import io.metersphere.system.file.FileRequest; +import io.minio.MinioClient; +import jakarta.annotation.Resource; import org.apache.commons.lang3.SerializationUtils; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; @@ -14,6 +17,8 @@ import org.springframework.context.annotation.Configuration; @Configuration public class RsaConfig implements ApplicationRunner { + @Resource + private MinioClient client; @Override public void run(ApplicationArguments args) throws Exception { @@ -21,6 +26,8 @@ public class RsaConfig implements ApplicationRunner { request.setFileName("rsa.key"); request.setFolder(DefaultRepositoryDir.getSystemRootDir()); FileRepository fileRepository = FileCenter.getDefaultRepository(); + // 初始化MinIO配置 + ((MinioRepository) fileRepository).init(client); try { byte[] file = fileRepository.getFile(request); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseDisplayService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseDisplayService.java index 47c03920d8..4736f17b42 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseDisplayService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseDisplayService.java @@ -3,8 +3,8 @@ package io.metersphere.system.service; import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.exception.MSException; import io.metersphere.system.domain.SystemParameter; -import io.metersphere.system.file.FileRequest; -import io.metersphere.system.file.MinioRepository; +import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.file.MinioRepository; import io.metersphere.system.mapper.SystemParameterMapper; import jakarta.annotation.Resource; import org.apache.commons.io.IOUtils; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/PluginLoadService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/PluginLoadService.java index 29d491ea3a..34f12c2f8e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/PluginLoadService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/PluginLoadService.java @@ -6,8 +6,8 @@ import io.metersphere.sdk.constants.LocalRepositoryDir; import io.metersphere.sdk.constants.StorageType; import io.metersphere.system.controller.handler.result.CommonResultCode; import io.metersphere.sdk.exception.MSException; -import io.metersphere.system.file.FileCenter; -import io.metersphere.system.file.FileRequest; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.FileRequest; import io.metersphere.sdk.plugin.MsPluginManager; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.LogUtils; diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/base/BaseTest.java b/backend/services/system-setting/src/test/java/io/metersphere/system/base/BaseTest.java index e59c8b7ec2..846f4ac571 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/base/BaseTest.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/base/BaseTest.java @@ -2,10 +2,13 @@ package io.metersphere.system.base; import com.jayway.jsonpath.JsonPath; import io.metersphere.sdk.constants.SessionConstants; +import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.constants.UserRoleType; import io.metersphere.sdk.domain.OperationLogExample; import io.metersphere.sdk.exception.IResultCode; import io.metersphere.sdk.exception.MSException; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.MinioRepository; import io.metersphere.sdk.mapper.OperationLogMapper; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.param.InvalidateParamInfo; @@ -20,6 +23,7 @@ import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.utils.Pager; import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Updated; +import io.minio.MinioClient; import jakarta.annotation.Resource; import lombok.Data; import org.apache.commons.lang3.StringUtils; @@ -79,6 +83,8 @@ public abstract class BaseTest { private UserMapper userMapper; @Resource private MockServerClient mockServerClient; + @Resource + private MinioClient client; protected static final String DEFAULT_LIST = "list"; protected static final String DEFAULT_GET = "get/{0}"; @@ -103,6 +109,9 @@ public abstract class BaseTest { this.sessionId = this.adminAuthInfo.getSessionId(); this.csrfToken = this.adminAuthInfo.getCsrfToken(); } + // 初始化MinIO配置 + ((MinioRepository) FileCenter.getRepository(StorageType.MINIO)).init(client); + if (permissionAuthInfoMap.isEmpty()) { // 获取系统,组织,项目对应的权限测试用户的认证信息 List permissionUserNames = Arrays.asList(UserRoleType.SYSTEM.name(), UserRoleType.ORGANIZATION.name(), UserRoleType.PROJECT.name()); @@ -239,6 +248,7 @@ public abstract class BaseTest { /** * 设置 mock get 接口 + * * @param path * @param mockBody */ @@ -258,6 +268,7 @@ public abstract class BaseTest { /** * 设置 mock post 接口 + * * @param path * @param mockBody */ diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseDisplayControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseDisplayControllerTests.java index 92abc75c09..67647f05ba 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseDisplayControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseDisplayControllerTests.java @@ -3,8 +3,8 @@ package io.metersphere.system.controller; import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.system.base.BaseTest; -import io.metersphere.system.file.FileRequest; -import io.metersphere.system.file.MinioRepository; +import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.file.MinioRepository; import jakarta.annotation.Resource; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.MethodOrderer; diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/CleanupResourceTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/CleanupResourceTests.java index fb7f688cb0..6e20ce070e 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/CleanupResourceTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/CleanupResourceTests.java @@ -1,5 +1,6 @@ package io.metersphere.system.controller; +import io.metersphere.system.base.BaseTest; import io.metersphere.system.invoker.ProjectServiceInvoker; import io.metersphere.system.mock.CleanupTestResourceService; import jakarta.annotation.Resource; @@ -15,7 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @AutoConfigureMockMvc -public class CleanupResourceTests { +public class CleanupResourceTests extends BaseTest { private final ProjectServiceInvoker serviceInvoker; @Resource private CleanupTestResourceService cleanupTestResourceService; diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/FileCenterTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/FileCenterTests.java index 659fc8a181..c81b789888 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/FileCenterTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/FileCenterTests.java @@ -1,9 +1,9 @@ package io.metersphere.system.controller; -import io.metersphere.system.file.FileCenter; -import io.metersphere.system.file.FileRepository; -import io.metersphere.system.file.FileRequest; -import io.metersphere.system.file.MinioRepository; +import io.metersphere.sdk.file.FileCenter; +import io.metersphere.sdk.file.FileRepository; +import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.file.MinioRepository; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/PluginControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/PluginControllerTests.java index 30700274d5..773f9de287 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/PluginControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/PluginControllerTests.java @@ -12,8 +12,8 @@ import io.metersphere.system.domain.*; import io.metersphere.system.dto.OrganizationDTO; import io.metersphere.system.dto.PluginDTO; import io.metersphere.system.dto.sdk.OptionDTO; -import io.metersphere.system.file.FileRequest; -import io.metersphere.system.file.LocalFileRepository; +import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.file.LocalFileRepository; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.mapper.PluginMapper; import io.metersphere.system.mapper.PluginOrganizationMapper;