From c2ae76c0bd6a115164002cfff3be10e16aa0eeb9 Mon Sep 17 00:00:00 2001 From: Eric Gao Date: Thu, 1 Dec 2022 14:15:28 +0800 Subject: [PATCH] Expand all static imports and add CI check to block wildcard static imports (#13067) --- .../controller/ProcessInstanceController.java | 24 +++++++-------- .../WorkflowInstanceV2Controller.java | 11 ++++--- .../impl/ProcessInstanceServiceImpl.java | 29 ++++++++++++------- .../TaskInstanceV2ControllerTest.java | 3 +- .../plugin/task/linkis/LinkisTask.java | 4 ++- pom.xml | 2 +- 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java index c6e807e47e..f75970e466 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java @@ -17,8 +17,6 @@ package org.apache.dolphinscheduler.api.controller; -import static org.apache.dolphinscheduler.api.enums.Status.*; - import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; @@ -103,7 +101,7 @@ public class ProcessInstanceController extends BaseController { }) @GetMapping() @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR) + @ApiException(Status.QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessInstanceList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -143,7 +141,7 @@ public class ProcessInstanceController extends BaseController { }) @GetMapping(value = "/{id}/tasks") @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR) + @ApiException(Status.QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTaskListByProcessId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -180,7 +178,7 @@ public class ProcessInstanceController extends BaseController { }) @PutMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) - @ApiException(UPDATE_PROCESS_INSTANCE_ERROR) + @ApiException(Status.UPDATE_PROCESS_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result updateProcessInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -213,7 +211,7 @@ public class ProcessInstanceController extends BaseController { }) @GetMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) + @ApiException(Status.QUERY_PROCESS_INSTANCE_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProcessInstanceById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -240,7 +238,7 @@ public class ProcessInstanceController extends BaseController { }) @GetMapping(value = "/top-n") @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) + @ApiException(Status.QUERY_PROCESS_INSTANCE_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryTopNLongestRunningProcessInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -267,7 +265,7 @@ public class ProcessInstanceController extends BaseController { }) @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.OK) - @ApiException(DELETE_PROCESS_INSTANCE_BY_ID_ERROR) + @ApiException(Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteProcessInstanceById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -290,7 +288,7 @@ public class ProcessInstanceController extends BaseController { }) @GetMapping(value = "/query-sub-by-parent") @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR) + @ApiException(Status.QUERY_SUB_PROCESS_INSTANCE_DETAIL_INFO_BY_TASK_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result querySubProcessInstanceByTaskId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -314,7 +312,7 @@ public class ProcessInstanceController extends BaseController { }) @GetMapping(value = "/query-parent-by-sub") @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR) + @ApiException(Status.QUERY_PARENT_PROCESS_INSTANCE_DETAIL_INFO_BY_SUB_PROCESS_INSTANCE_ID_ERROR) @AccessLogAnnotation public Result queryParentInstanceBySubId(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -336,7 +334,7 @@ public class ProcessInstanceController extends BaseController { }) @GetMapping(value = "/{id}/view-variables") @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR) + @ApiException(Status.QUERY_PROCESS_INSTANCE_ALL_VARIABLES_ERROR) @AccessLogAnnotation public Result viewVariables(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -359,7 +357,7 @@ public class ProcessInstanceController extends BaseController { }) @GetMapping(value = "/{id}/view-gantt") @ResponseStatus(HttpStatus.OK) - @ApiException(ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR) + @ApiException(Status.ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR) @AccessLogAnnotation public Result viewTree(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @@ -384,7 +382,7 @@ public class ProcessInstanceController extends BaseController { }) @PostMapping(value = "/batch-delete") @ResponseStatus(HttpStatus.OK) - @ApiException(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR) + @ApiException(Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR) @AccessLogAnnotation public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, @PathVariable long projectCode, diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkflowInstanceV2Controller.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkflowInstanceV2Controller.java index 09d39e79ab..e2128151da 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkflowInstanceV2Controller.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkflowInstanceV2Controller.java @@ -17,11 +17,10 @@ package org.apache.dolphinscheduler.api.controller; -import static org.apache.dolphinscheduler.api.enums.Status.*; - import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.dto.workflowInstance.WorkflowInstanceQueryRequest; import org.apache.dolphinscheduler.api.enums.ExecuteType; +import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ExecutorService; import org.apache.dolphinscheduler.api.service.ProcessInstanceService; @@ -72,7 +71,7 @@ public class WorkflowInstanceV2Controller extends BaseController { @Operation(summary = "queryWorkflowInstanceListPaging", description = "QUERY_PROCESS_INSTANCE_LIST_NOTES") @GetMapping(consumes = {"application/json"}) @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR) + @ApiException(Status.QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryWorkflowInstanceListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestBody WorkflowInstanceQueryRequest workflowInstanceQueryRequest) { @@ -99,7 +98,7 @@ public class WorkflowInstanceV2Controller extends BaseController { }) @GetMapping(value = "/{workflowInstanceId}") @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_PROCESS_INSTANCE_BY_ID_ERROR) + @ApiException(Status.QUERY_PROCESS_INSTANCE_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryWorkflowInstanceById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @PathVariable("workflowInstanceId") Integer workflowInstanceId) { @@ -120,7 +119,7 @@ public class WorkflowInstanceV2Controller extends BaseController { }) @DeleteMapping(value = "/{workflowInstanceId}") @ResponseStatus(HttpStatus.OK) - @ApiException(DELETE_PROCESS_DEFINE_BY_CODE_ERROR) + @ApiException(Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteWorkflowInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @PathVariable("workflowInstanceId") Integer workflowInstanceId) { @@ -143,7 +142,7 @@ public class WorkflowInstanceV2Controller extends BaseController { }) @PostMapping(value = "/{workflowInstanceId}/execute/{executeType}") @ResponseStatus(HttpStatus.OK) - @ApiException(EXECUTE_PROCESS_INSTANCE_ERROR) + @ApiException(Status.EXECUTE_PROCESS_INSTANCE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result execute(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @PathVariable("workflowInstanceId") Integer workflowInstanceId, diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java index 21b50ebec7..40cea0ba73 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java @@ -17,7 +17,6 @@ package org.apache.dolphinscheduler.api.service.impl; -import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.*; import static org.apache.dolphinscheduler.api.enums.Status.PROCESS_INSTANCE_NOT_EXIST; import static org.apache.dolphinscheduler.api.enums.Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR; import static org.apache.dolphinscheduler.common.constants.Constants.DATA_LIST; @@ -29,6 +28,7 @@ import static org.apache.dolphinscheduler.common.constants.Constants.TASK_LIST; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.TASK_TYPE_DEPENDENT; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.TASK_TYPE_SUB_PROCESS; +import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant; import org.apache.dolphinscheduler.api.dto.gantt.GanttDto; import org.apache.dolphinscheduler.api.dto.gantt.Task; import org.apache.dolphinscheduler.api.dto.workflowInstance.WorkflowInstanceQueryRequest; @@ -186,7 +186,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Project project = projectMapper.queryByCode(projectCode); // check user access for project Map result = - projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE); + projectService.checkProjectAndAuth(loginUser, project, projectCode, + ApiFuncIdentificationConstant.WORKFLOW_INSTANCE); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -234,7 +235,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Project project = projectMapper.queryByCode(projectCode); // check user access for project Map result = - projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE); + projectService.checkProjectAndAuth(loginUser, project, projectCode, + ApiFuncIdentificationConstant.WORKFLOW_INSTANCE); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -304,7 +306,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Project project = projectMapper.queryByCode(projectCode); // check user access for project Map checkResult = - projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE); + projectService.checkProjectAndAuth(loginUser, project, projectCode, + ApiFuncIdentificationConstant.WORKFLOW_INSTANCE); Status resultEnum = (Status) checkResult.get(Constants.STATUS); if (resultEnum != Status.SUCCESS) { putMsg(result, resultEnum); @@ -373,7 +376,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce String projectName = workflowInstanceQueryRequest.getProjectName(); if (!StringUtils.isBlank(projectName)) { Project project = projectMapper.queryByName(projectName); - projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_DEFINITION); + projectService.checkProjectAndAuthThrowException(loginUser, project, + ApiFuncIdentificationConstant.WORKFLOW_DEFINITION); ProcessDefinition processDefinition = processDefineMapper.queryByDefineName(project.getCode(), processInstance.getName()); processInstance.setProcessDefinitionCode(processDefinition.getCode()); @@ -430,7 +434,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Project project = projectMapper.queryByCode(projectCode); // check user access for project Map result = - projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE); + projectService.checkProjectAndAuth(loginUser, project, projectCode, + ApiFuncIdentificationConstant.WORKFLOW_INSTANCE); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -518,7 +523,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Project project = projectMapper.queryByCode(projectCode); // check user access for project Map result = - projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE); + projectService.checkProjectAndAuth(loginUser, project, projectCode, + ApiFuncIdentificationConstant.WORKFLOW_INSTANCE); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -586,7 +592,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Project project = projectMapper.queryByCode(projectCode); // check user access for project Map result = - projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_UPDATE); + projectService.checkProjectAndAuth(loginUser, project, projectCode, + ApiFuncIdentificationConstant.INSTANCE_UPDATE); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -740,7 +747,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Project project = projectMapper.queryByCode(projectCode); // check user access for project Map result = - projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE); + projectService.checkProjectAndAuth(loginUser, project, projectCode, + ApiFuncIdentificationConstant.WORKFLOW_INSTANCE); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -783,7 +791,8 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Project project = projectMapper.queryByCode(projectCode); // check user access for project Map result = - projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_DELETE); + projectService.checkProjectAndAuth(loginUser, project, projectCode, + ApiFuncIdentificationConstant.INSTANCE_DELETE); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2ControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2ControllerTest.java index 3aed7ecb44..7624255087 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2ControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceV2ControllerTest.java @@ -17,7 +17,8 @@ package org.apache.dolphinscheduler.api.controller; -import static org.mockito.ArgumentMatchers.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceQueryRequest; diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-linkis/src/main/java/org/apache/dolphinscheduler/plugin/task/linkis/LinkisTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-linkis/src/main/java/org/apache/dolphinscheduler/plugin/task/linkis/LinkisTask.java index cf79fff077..c11888e4a8 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-linkis/src/main/java/org/apache/dolphinscheduler/plugin/task/linkis/LinkisTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-linkis/src/main/java/org/apache/dolphinscheduler/plugin/task/linkis/LinkisTask.java @@ -17,7 +17,9 @@ package org.apache.dolphinscheduler.plugin.task.linkis; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.*; +import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_FAILURE; +import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_KILL; +import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_SUCCESS; import org.apache.dolphinscheduler.plugin.task.api.AbstractRemoteTask; import org.apache.dolphinscheduler.plugin.task.api.ShellCommandExecutor; diff --git a/pom.xml b/pom.xml index b398e94fc7..7f78d69de4 100755 --- a/pom.xml +++ b/pom.xml @@ -669,7 +669,7 @@ Remove wildcard imports - import\s+[^\*\s]+\*;(\r\n|\r|\n) + import\s+(static)*\s*[^\*\s]+\*;(\r\n|\r|\n) $1