diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/LocalRepositoryDir.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/LocalRepositoryDir.java index 85ae594745..e8b38df60b 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/LocalRepositoryDir.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/LocalRepositoryDir.java @@ -54,4 +54,8 @@ public class LocalRepositoryDir { public static String getSystemCacheDir() { return SYSTEM_CACHE_DIR; } + + public static String getFuncJarDir() { + return ROOT_DIR + "/api/func-jar"; + } } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequestDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequestDTO.java index 992987101d..36ebffdba6 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequestDTO.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequestDTO.java @@ -66,6 +66,12 @@ public class TaskRequestDTO implements Serializable { * id 为插件的 id + 更新时间戳 */ private List pluginFiles; + + /** + * 接口测试函数包 + */ + private List funcJars; + /** * 误报规则 */ diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java index b6996927d8..ea1181a737 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java @@ -1,5 +1,6 @@ package io.metersphere.api.parser.jmeter.processor; +import io.metersphere.plugin.api.constants.ElementProperty; import io.metersphere.project.constants.ScriptLanguageType; import io.metersphere.project.api.processor.ScriptProcessor; import io.metersphere.api.parser.jmeter.constants.JmeterAlias; @@ -17,6 +18,7 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter fileMetadataList = fileManagementService.findJarByProjectId(List.of(taskRequest.getProjectId())); + taskRequest.setFuncJars(fileMetadataList.stream() + .map(file -> { + String fileName = file.getName() + "." + file.getType(); + ApiExecuteFileInfo tempFileInfo = getApiExecuteFileInfo(file.getId(), fileName, file.getProjectId(), file.getStorage()); + if (StorageType.isGit(file.getStorage())) { + // 设置Git信息 + tempFileInfo.setFileMetadataRepositoryDTO(fileManagementService.getFileMetadataRepositoryDTO(file.getId())); + tempFileInfo.setFileModuleRepositoryDTO(fileManagementService.getFileModuleRepositoryDTO(file.getModuleId())); + } + return tempFileInfo; + }).toList()); + + // TODO 当前项目没有包分两种情况,1 之前存在被删除,2 一直不存在 + // 为了兼容1 这种情况需要初始化一条空的数据,由执行机去做卸载 + if (CollectionUtils.isEmpty(taskRequest.getFuncJars())) { + ApiExecuteFileInfo tempFileInfo = new ApiExecuteFileInfo(); + tempFileInfo.setProjectId(request.getProjectId()); + taskRequest.setFuncJars(List.of(tempFileInfo)); + } } private static ApiExecuteFileInfo getApiExecuteFileInfo(String fileId, String fileName, String projectId) { 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 ac54390804..331f9f5ff8 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 @@ -231,4 +231,13 @@ public class FileManagementService { byte[] fileBytes = this.getFile(fileMetadata); return TempFileUtils.compressPic(fileBytes); } + + public List findJarByProjectId(List projectIds) { + FileMetadataExample example = new FileMetadataExample(); + example.createCriteria().andProjectIdIn(projectIds) + .andEnableEqualTo(true) + .andTypeEqualTo("jar") + .andLatestEqualTo(true); + return fileMetadataMapper.selectByExample(example); + } }