From 6a028709266fdb1f708bf320cd287b03f59d1533 Mon Sep 17 00:00:00 2001 From: Eric Gao Date: Sat, 6 Aug 2022 19:29:23 +0800 Subject: [PATCH] [Feature][style] Add spotless maven plugin for automatic style fix. (#11272) * [Feature][style] Add spotless maven plugin for automatic style fix (#10963) * Fix spotless ratchet configuration * Remove license-check and decrease line length threshold value * Update related docs * Remove checkstyle and add pre-commit hook * Test updated pre-commit hook * Replace checkstyle with spotless in CI * Remove reviewdog --- .github/actions/reviewdog-setup | 1 - .github/actions/sanity-check/action.yml | 17 +- .gitmodules | 3 - .licenserc.yaml | 1 - .../development-environment-setup.md | 16 +- .../development-environment-setup.md | 13 + dolphinscheduler-api-test/pom.xml | 32 - .../plugin/task/jupyter/JupyterTask.java | 15 +- pom.xml | 857 +++++++++--------- style/checkstyle.xml | 289 ------ style/pre-commit | 24 + style/spotless_dolphinscheduler_formatter.xml | 51 ++ 12 files changed, 543 insertions(+), 776 deletions(-) delete mode 160000 .github/actions/reviewdog-setup delete mode 100644 style/checkstyle.xml create mode 100644 style/pre-commit create mode 100644 style/spotless_dolphinscheduler_formatter.xml diff --git a/.github/actions/reviewdog-setup b/.github/actions/reviewdog-setup deleted file mode 160000 index c2fa3e5a37..0000000000 --- a/.github/actions/reviewdog-setup +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c2fa3e5a37b75a5819e2c8127caec1c2a0d088e8 diff --git a/.github/actions/sanity-check/action.yml b/.github/actions/sanity-check/action.yml index 01189a9a39..c9ffa8be58 100644 --- a/.github/actions/sanity-check/action.yml +++ b/.github/actions/sanity-check/action.yml @@ -34,20 +34,5 @@ runs: - name: Check License Header uses: apache/skywalking-eyes@30367d8286e324d5efc58de4c70c37ea3648306d - - uses: ./.github/actions/reviewdog-setup - with: - reviewdog_version: v0.10.2 - - - shell: bash - run: ./mvnw -B -q checkstyle:checkstyle-aggregate - - shell: bash - env: - REVIEWDOG_GITHUB_API_TOKEN: ${{ inputs.token }} - run: | - if [[ -n "${{ inputs.token }}" ]]; then - reviewdog -f=checkstyle \ - -reporter="github-pr-review" \ - -filter-mode="added" \ - -fail-on-error="true" < target/checkstyle-result.xml - fi + run: ./mvnw spotless:check diff --git a/.gitmodules b/.gitmodules index e7b1606ceb..3b91677a6a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -21,6 +21,3 @@ [submodule ".github/actions/translate-on-issue"] path = .github/actions/translate-on-issue url = https://github.com/xingchun-chen/translation-helper -[submodule ".github/actions/reviewdog-setup"] - path = .github/actions/reviewdog-setup - url = https://github.com/reviewdog/action-setup diff --git a/.licenserc.yaml b/.licenserc.yaml index 58543512ae..7793c21a73 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -44,7 +44,6 @@ header: - '**/NOTICE' - '**/node_modules/**' - '.github/actions/comment-on-issue/**' - - '.github/actions/reviewdog-setup/**' - '.github/actions/translate-on-issue/**' - '**/.gitkeep' diff --git a/docs/docs/en/contribute/development-environment-setup.md b/docs/docs/en/contribute/development-environment-setup.md index 0940682d6e..31d386f49b 100644 --- a/docs/docs/en/contribute/development-environment-setup.md +++ b/docs/docs/en/contribute/development-environment-setup.md @@ -19,7 +19,7 @@ cd dolphinscheduler git clone git@github.com:apache/dolphinscheduler.git ``` -### compile source code +### Compile Source Code Supporting system: * MacOS @@ -27,6 +27,20 @@ Supporting system: Run `mvn clean install -Prelease -Dmaven.test.skip=true` +### Code Style + +DolphinScheduler uses `Spotless` for code style and formatting checks. +You could run the following command and `Spotless` will automatically fix +the code style and formatting errors for you: + +```shell +./mvnw spotless:apply +``` + +You could copy the `pre-commit hook` file `/style/pre-commit` to your `.git/hooks/` +directory so that every time you commit your code with `git commit`, `Spotless` will automatically +fix things for you. + ## Docker image build DolphinScheduler will release new Docker images after it released, you could find them in [Docker Hub](https://hub.docker.com/search?q=DolphinScheduler). diff --git a/docs/docs/zh/contribute/development-environment-setup.md b/docs/docs/zh/contribute/development-environment-setup.md index 5b2dbe0595..433e6bfc14 100644 --- a/docs/docs/zh/contribute/development-environment-setup.md +++ b/docs/docs/zh/contribute/development-environment-setup.md @@ -27,6 +27,19 @@ git clone git@github.com:apache/dolphinscheduler.git 运行 `mvn clean install -Prelease -Dmaven.test.skip=true` + +### 代码风格 + +DolphinScheduler使用`Spotless`检查并修复代码风格和格式问题。 +您可以执行如下的命令,`Spotless`将会为您自动检查并修复代码风格和格式问题。 + +```shell +./mvnw spotless:apply +``` + +您可将`/style/pre-commit`目录下的`pre-commit hook`文件拷贝到您的`.git/hooks/` +目录下,这样您每次使用`git commit`命令时,`Spotless`将会自动为您修复代码风格和格式问题。 + ## Docker镜像构建 DolphinScheduler 每次发版都会同时发布 Docker 镜像,你可以在 [Docker Hub](https://hub.docker.com/search?q=DolphinScheduler) 中找到这些镜像 diff --git a/dolphinscheduler-api-test/pom.xml b/dolphinscheduler-api-test/pom.xml index 4c9b4cef31..5a246e5b87 100644 --- a/dolphinscheduler-api-test/pom.xml +++ b/dolphinscheduler-api-test/pom.xml @@ -138,38 +138,6 @@ maven-surefire-plugin 2.22.2 - - org.apache.maven.plugins - maven-checkstyle-plugin - ${checkstyle.version} - - - com.puppycrawl.tools - checkstyle - 8.45 - - - - true - UTF-8 - ../style/checkstyle.xml - true - warning - true - - ${project.build.sourceDirectory} - - **\/generated-sources\/ - - - - compile - - check - - - - diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/main/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/main/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTask.java index 0ce6052bdd..ea3bf750c6 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/main/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-jupyter/src/main/java/org/apache/dolphinscheduler/plugin/task/jupyter/JupyterTask.java @@ -17,25 +17,23 @@ package org.apache.dolphinscheduler.plugin.task.jupyter; - +import org.apache.dolphinscheduler.spi.utils.JSONUtils; +import org.apache.dolphinscheduler.spi.utils.PropertyUtils; +import org.apache.dolphinscheduler.spi.utils.StringUtils; +import org.apache.dolphinscheduler.plugin.task.api.parser.ParamUtils; +import org.apache.dolphinscheduler.plugin.task.api.parser.ParameterUtils; import org.apache.dolphinscheduler.plugin.task.api.AbstractTaskExecutor; import org.apache.dolphinscheduler.plugin.task.api.ShellCommandExecutor; import org.apache.dolphinscheduler.plugin.task.api.TaskConstants; + import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.model.Property; import org.apache.dolphinscheduler.plugin.task.api.model.TaskResponse; import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters; -import org.apache.dolphinscheduler.plugin.task.api.parser.ParamUtils; -import org.apache.dolphinscheduler.plugin.task.api.parser.ParameterUtils; -import org.apache.dolphinscheduler.plugin.task.api.utils.MapUtils; import org.apache.dolphinscheduler.spi.utils.DateUtils; -import org.apache.dolphinscheduler.spi.utils.JSONUtils; -import org.apache.dolphinscheduler.spi.utils.PropertyUtils; -import org.apache.dolphinscheduler.spi.utils.StringUtils; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -152,7 +150,6 @@ public class JupyterTask extends AbstractTaskExecutor { return command; } - /** * build jupyter parameterization * diff --git a/pom.xml b/pom.xml index 8cfcec8e77..76f697c4df 100644 --- a/pom.xml +++ b/pom.xml @@ -16,38 +16,49 @@ ~ limitations under the License. --> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + org.apache + apache + 25 + org.apache.dolphinscheduler dolphinscheduler dev-SNAPSHOT pom ${project.artifactId} - https://dolphinscheduler.apache.org Dolphin Scheduler is a distributed and easy-to-expand visual DAG workflow scheduling system, dedicated to solving the complex dependencies in data processing, making the scheduling system out of the box for data - processing. - - - scm:git:https://github.com/apache/dolphinscheduler.git - scm:git:https://github.com/apache/dolphinscheduler.git - https://github.com/apache/dolphinscheduler - HEAD - - - - DolphinScheduler Developer List - dev@dolphinscheduler.apache.org - dev-subscribe@dolphinscheduler.apache.org - dev-unsubscribe@dolphinscheduler.apache.org - - - - org.apache - apache - 25 - - + processing. + + + dolphinscheduler-bom + dolphinscheduler-alert + dolphinscheduler-spi + dolphinscheduler-registry + dolphinscheduler-task-plugin + dolphinscheduler-server + dolphinscheduler-common + dolphinscheduler-api + dolphinscheduler-dao + dolphinscheduler-dist + dolphinscheduler-remote + dolphinscheduler-service + dolphinscheduler-microbench + dolphinscheduler-data-quality + dolphinscheduler-standalone-server + dolphinscheduler-datasource-plugin + dolphinscheduler-python + dolphinscheduler-meter + dolphinscheduler-master + dolphinscheduler-worker + dolphinscheduler-log-server + dolphinscheduler-tools + dolphinscheduler-ui + dolphinscheduler-scheduler-plugin + + UTF-8 UTF-8 @@ -55,7 +66,6 @@ 1.8 4.12 3.1.12 - 3.1.2 3.3 3.3.0 2.5.3 @@ -65,6 +75,7 @@ 3.1.1 3.2.1 2.2.0 + 2.23.0 0.8.7 false 2.7 @@ -80,373 +91,11 @@ ${project.version} true true - + true true - - - - - - org.codehaus.mojo - rpm-maven-plugin - ${rpm-maven-plugion.version} - false - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - ${java.version} - ${java.version} - - ${maven-compiler-plugin.version} - - - - org.apache.maven.plugins - maven-release-plugin - ${maven-release-plugin.version} - - @{project.version} - - - - - org.apache.maven.plugins - maven-assembly-plugin - ${maven-assembly-plugin.version} - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - 8 - false - - - - - org.apache.maven.plugins - maven-dependency-plugin - ${maven-dependency-plugin.version} - - - org.apache.maven.plugins - maven-shade-plugin - ${maven-shade-plugin.version} - - - org.apache.maven.plugins - maven-jar-plugin - ${maven-jar-plugin.version} - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - docker-build - package - - exec - - - ${docker.build.skip} - docker - ${project.basedir} - - build - --no-cache - -t - ${docker.hub}/${docker.repo}:${docker.tag} - -t - ${docker.hub}/${docker.repo}:latest - ${project.basedir} - --file=src/main/docker/Dockerfile - - - - - docker-push - deploy - - exec - - - ${docker.push.skip} - - 1 - - docker - ${project.basedir} - - buildx - build - --platform - linux/amd64,linux/arm64 - --no-cache - --push - -t - ${docker.hub}/${docker.repo}:${docker.tag} - -t - ${docker.hub}/${docker.repo}:latest - ${project.basedir} - --file=src/main/docker/Dockerfile - - - - - - - org.owasp - dependency-check-maven - ${owasp-dependency-check-maven.version} - - ${skipDepCheck} - true - true - true - 7 - - - - - aggregate - - - - - - - - - - org.owasp - dependency-check-maven - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - - attach-javadocs - - jar - - - - - true - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - - - - org.apache.maven.plugins - maven-release-plugin - ${maven-release-plugin.version} - - true - @{project.version} - ${project.version} - - - - org.apache.maven.scm - maven-scm-provider-jgit - 1.9.5 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - ${java.version} - ${project.build.sourceEncoding} - false - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - org.apache.maven.surefire - surefire-junit4 - ${maven-surefire-plugin.version} - - - - - ${project.build.directory}/jacoco.exec - - - - - - - org.jacoco - jacoco-maven-plugin - ${jacoco.version} - - ${jacoco.skip} - ${project.build.directory}/jacoco.exec - - - - default-instrument - - instrument - - - - default-restore-instrumented-classes - - restore-instrumented-classes - - - com/github/dreamhead/moco/* - - - - default-report - - report - - - - - - com.github.spotbugs - spotbugs-maven-plugin - ${spotbugs.version} - - true - medium - default - dev-config/spotbugs-exclude.xml - true - - - - com.github.spotbugs - spotbugs - 4.0.0-beta4 - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - ${checkstyle.version} - - - com.puppycrawl.tools - checkstyle - 8.45 - - - - true - UTF-8 - style/checkstyle.xml - true - warning - true - - ${project.build.sourceDirectory} - - **\/generated-sources\/ - - - - compile - - check - - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura-maven-plugin.version} - - - - true - ./target/cobertura - ${project.build.sourceEncoding} - true - xml - - true - - - - - maven-source-plugin - ${maven-source-plugin.version} - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-dependency-plugin - ${maven-dependency-plugin.version} - - - analyze-dependencies - - analyze-only - - - - - - - org.springframework*:* - org.apache.dolphinscheduler:dolphinscheduler-meter - - true - - - - - - - - - - docker - - false - false - - - - + @@ -524,13 +173,13 @@ dolphinscheduler-spi ${project.version} - + org.apache.dolphinscheduler dolphinscheduler-data-quality ${project.version} - + org.apache.dolphinscheduler dolphinscheduler-python @@ -611,7 +260,7 @@ dolphinscheduler-registry-mysql ${project.version} - + org.apache.dolphinscheduler dolphinscheduler-scheduler-api @@ -622,7 +271,7 @@ dolphinscheduler-scheduler-quartz ${project.version} - + org.apache.dolphinscheduler dolphinscheduler-datasource-all @@ -633,7 +282,7 @@ dolphinscheduler-datasource-api ${project.version} - + org.apache.dolphinscheduler dolphinscheduler-task-api @@ -649,7 +298,7 @@ dolphinscheduler-task-all ${project.version} - + org.apache.dolphinscheduler dolphinscheduler-ui @@ -661,9 +310,9 @@ ${project.version} - + - + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + ${project.build.directory}/jacoco.exec + + + + + org.apache.maven.surefire + surefire-junit4 + ${maven-surefire-plugin.version} + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + ${jacoco.skip} + ${project.build.directory}/jacoco.exec + + + + default-instrument + + instrument + + + + default-restore-instrumented-classes + + restore-instrumented-classes + + + com/github/dreamhead/moco/* + + + + default-report + + report + + + + + + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs.version} + + true + medium + default + dev-config/spotbugs-exclude.xml + true + + + + com.github.spotbugs + spotbugs + 4.0.0-beta4 + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + HEAD + + + style/spotless_dolphinscheduler_formatter.xml + + + + + UTF-8 + 4 + true + true + true + true + false + false + custom_1 + false + false + + + Leading blank line + project + project + + + + + + + check + + compile + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura-maven-plugin.version} + + + true + ./target/cobertura + ${project.build.sourceEncoding} + true + xml + + true + + + + + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin.version} + + + analyze-dependencies + + analyze-only + + + + + + + org.springframework*:* + org.apache.dolphinscheduler:dolphinscheduler-meter + + true + + + + + + + https://dolphinscheduler.apache.org + + + DolphinScheduler Developer List + dev-subscribe@dolphinscheduler.apache.org + dev-unsubscribe@dolphinscheduler.apache.org + dev@dolphinscheduler.apache.org + + + + scm:git:https://github.com/apache/dolphinscheduler.git + scm:git:https://github.com/apache/dolphinscheduler.git + https://github.com/apache/dolphinscheduler + HEAD + + + + + docker + + false + false + + + diff --git a/style/checkstyle.xml b/style/checkstyle.xml deleted file mode 100644 index 07a3aaf570..0000000000 --- a/style/checkstyle.xml +++ /dev/null @@ -1,289 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/style/pre-commit b/style/pre-commit new file mode 100644 index 0000000000..89ef99f755 --- /dev/null +++ b/style/pre-commit @@ -0,0 +1,24 @@ +#!/bin/sh +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# A hook script to automatically fix code style and formatting errors with spotless +if ./mvnw spotless:check; then + exit 0 +fi +./mvnw spotless:apply +exit 1 diff --git a/style/spotless_dolphinscheduler_formatter.xml b/style/spotless_dolphinscheduler_formatter.xml new file mode 100644 index 0000000000..0e45f7be39 --- /dev/null +++ b/style/spotless_dolphinscheduler_formatter.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +