diff --git a/.ci/diff-report.sh b/.ci/diff-report.sh index f3170e0b6b6..74cb3c70b6c 100755 --- a/.ci/diff-report.sh +++ b/.ci/diff-report.sh @@ -36,7 +36,7 @@ case $1 in # Downloads all files necessary to generate regression report to the parent directory. download-files) checkForVariable "GITHUB_TOKEN" - mkdir .ci-temp + mkdir -p .ci-temp echo "Downloading files..." # check for projects link from PR, if not found use default from contribution repo diff --git a/.github/workflows/regression-report.yml b/.github/workflows/regression-report.yml index 17259f14595..bd312c8076c 100644 --- a/.github/workflows/regression-report.yml +++ b/.github/workflows/regression-report.yml @@ -16,6 +16,15 @@ env: AWS_REGION: us-east-2 AWS_BUCKET_NAME: "checkstyle-diff-reports" USER_LOGIN: ${{ github.event.issue.user.login }} + # yamllint disable-line rule:line-length + DEFAULT_PROJECTS_LINK: "https://raw.githubusercontent.com/checkstyle/test-configs/main/extractor/src/main/resources/list-of-projects.properties" + EXTRACTOR_VERSION: 2024-08-27 + CACHE_KEY_PR: "simple-cache-key-PR-${{ github.sha }}" + CACHE_KEY_MASTER: "simple-cache-key-MASTER-${{ github.sha }}" + CACHE_KEY_CONTRIBUTION: "simple-cache-key-CONTRIBUTION-${{ github.sha }}" + CACHE_KEY_CONFIG_FILES: "config-files-${{ github.sha }}" + CACHE_KEY_GENERATED_CONFIGS: "generated-configs-${{ github.sha }}" + GENERATED_CONFIGS_PATH: generated_configs on: issue_comment: @@ -26,15 +35,24 @@ permissions: pull-requests: write concurrency: - group: ${{ github.workflow }}-${{ github.event.issue.number }} + group: ${{ github.run_id }} cancel-in-progress: true jobs: check_pr_status: if: | github.event.issue.pull_request - && (startsWith(github.event.comment.body, 'Github, generate report for ') - || startsWith(github.event.comment.body, 'GitHub, generate report for ')) + && (startsWith(github.event.comment.body, 'Github, generate report for ') + || startsWith(github.event.comment.body, 'GitHub, generate report for ') + || startsWith(github.event.comment.body, + 'Github, generate report for configs in PR description') + || startsWith(github.event.comment.body, + 'GitHub, generate report for configs in PR description') + || startsWith(github.event.comment.body, + 'Github, generate report by config from') + || startsWith(github.event.comment.body, + 'GitHub, generate report by config from')) + runs-on: ubuntu-latest steps: - name: Check PR status @@ -50,16 +68,68 @@ jobs: exit 1 fi + checkout_and_cache: + runs-on: ubuntu-latest + needs: [ check_pr_status ] + steps: + - name: Create .ci-temp directory + run: mkdir -p .ci-temp + + - name: Checkout Checkstyle root + uses: actions/checkout@v4 + with: + repository: checkstyle/checkstyle + path: . + + - name: Cache Checkstyle root checkout + uses: actions/cache@v4 + with: + path: . + key: ${{ env.CACHE_KEY_MASTER }} + + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + path: . + + - name: Cache PR Checkout + uses: actions/cache@v4 + with: + path: . + key: ${{ env.CACHE_KEY_PR }} + + - name: Checkout master branch + uses: actions/checkout@v4 + with: + repository: checkstyle/checkstyle + path: .ci-temp/checkstyle + + - name: Cache checkouts + uses: actions/cache@v4 + with: + path: .ci-temp/checkstyle + key: ${{ env.CACHE_KEY_MASTER }} + + - name: Checkout contribution repository + uses: actions/checkout@v4 + with: + repository: checkstyle/contribution + path: .ci-temp/contribution + + - name: Cache contribution checkout + uses: actions/cache@v4 + with: + path: .ci-temp/contribution + key: ${{ env.CACHE_KEY_CONTRIBUTION }} + parse_comment: runs-on: ubuntu-latest - needs: check_pr_status + needs: [ check_pr_status, checkout_and_cache ] outputs: - config_bundle_path: ${{ steps.parse.outputs.config_bundle_path }} - config_link: ${{ steps.set_links.outputs.config_link }} - projects_link: ${{ steps.set_links.outputs.projects_link }} - branch: ${{ steps.set_branch.outputs.ref }} - commit_sha: ${{ steps.set_branch.outputs.commit_sha }} - + mode: ${{ steps.parse.outputs.mode }} + config_bundle: ${{ steps.parse.outputs.config_bundle }} + input_file: ${{ steps.parse.outputs.input_file }} steps: - name: React to comment uses: actions/github-script@v7 @@ -73,31 +143,262 @@ jobs: content: 'rocket' }) - - name: Checkout repository - uses: actions/checkout@v4 + - name: Restore Master Checkstyle Checkout + uses: actions/cache@v4 + with: + path: .ci-temp/checkstyle + key: "${{ env.CACHE_KEY_MASTER }}" + + - name: Restore PR Checkout + uses: actions/cache@v4 + with: + path: . + key: "${{ env.CACHE_KEY_PR }}" - name: Parse comment id: parse env: COMMENT_BODY: ${{ github.event.comment.body }} run: | - CONFIG_BUNDLE_PATH=$(echo "$COMMENT_BODY" | \ - sed -E 's/.*(Github|GitHub), generate report for //g') - echo "CONFIG_BUNDLE_PATH=$CONFIG_BUNDLE_PATH" - ./.ci/append-to-github-output.sh "config_bundle_path" "$CONFIG_BUNDLE_PATH" + PATTERN_FOR_DESCRIPTION='^Git[Hh]ub, generate report for configs in PR description$' + PATTERN_FOR='^Git[Hh]ub, generate report for' + PATTERN_BY_CONFIG_FROM='^Git[Hh]ub, generate report by config from' + + if [[ "$COMMENT_BODY" =~ $PATTERN_FOR_DESCRIPTION ]]; then + ./.ci/append-to-github-output.sh "mode" "configs_in_pr_description" + + elif [[ "$COMMENT_BODY" =~ $PATTERN_FOR ]]; then + ./.ci/append-to-github-output.sh "mode" "existing_config_bundle" + CONFIG_BUNDLE=$(echo "$COMMENT_BODY" | sed -E "s/$PATTERN_FOR //g") + ./.ci/append-to-github-output.sh "config_bundle" "$CONFIG_BUNDLE" + + elif [[ "$COMMENT_BODY" =~ $PATTERN_BY_CONFIG_FROM ]]; then + ./.ci/append-to-github-output.sh "mode" "generated_config_bundle" + INPUT_FILE=$(echo "$COMMENT_BODY" | sed -E "s/$PATTERN_BY_CONFIG_FROM //g") + ./.ci/append-to-github-output.sh "input_file" "$INPUT_FILE" + + else + echo "No recognized pattern found in '$COMMENT_BODY'." + exit 1 + fi + + handle_existing_config_bundle: + needs: [ parse_comment, checkout_and_cache ] + if: needs.parse_comment.outputs.mode == 'existing_config_bundle' + runs-on: ubuntu-latest + outputs: + config_link: ${{ steps.set_links.outputs.config_link }} + projects_link: ${{ steps.set_links.outputs.projects_link }} + steps: + - name: Restore Master Checkstyle Checkout + uses: actions/cache@v4 + with: + path: . + key: "${{ env.CACHE_KEY_MASTER }}" - name: Set config and projects links id: set_links run: | BASE_URL="https://raw.githubusercontent.com/checkstyle/test-configs/main" - CONFIG_BUNDLE_PATH="${{ steps.parse.outputs.config_bundle_path }}" - CONFIG_LINK="$BASE_URL/$CONFIG_BUNDLE_PATH/config.xml" - PROJECTS_LINK="$BASE_URL/$CONFIG_BUNDLE_PATH/list-of-projects.properties" - echo "CONFIG_LINK=$CONFIG_LINK" - echo "PROJECTS_LINK=$PROJECTS_LINK" + CONFIG_BUNDLE="${{ needs.parse_comment.outputs.config_bundle }}" + CONFIG_LINK="$BASE_URL/$CONFIG_BUNDLE/config.xml" + PROJECTS_LINK="$BASE_URL/$CONFIG_BUNDLE/list-of-projects.properties" ./.ci/append-to-github-output.sh "config_link" "$CONFIG_LINK" ./.ci/append-to-github-output.sh "projects_link" "$PROJECTS_LINK" + handle_generated_config_bundle: + needs: [ parse_comment, checkout_and_cache ] + if: needs.parse_comment.outputs.mode == 'generated_config_bundle' + runs-on: ubuntu-latest + outputs: + config_link: ${{ steps.generated_config_bundle.outputs.config_link }} + projects_link: ${{ steps.generated_config_bundle.outputs.projects_link }} + steps: + - name: Restore PR Checkout + uses: actions/cache@v4 + with: + path: . + key: "${{ env.CACHE_KEY_PR }}" + + - name: Find input file + id: find_input_file + run: | + INPUT_FILE="${{ needs.parse_comment.outputs.input_file }}" + WORKSPACE="${{ github.workspace }}" + + FOUND_FILES=$(find "$WORKSPACE/src" -type f -path "*$INPUT_FILE") + + if [ "$(echo "$FOUND_FILE" | wc -l)" -gt 1 ]; then + echo "Error: Multiple matching files found" + exit 1 + elif [ -z "$FOUND_FILES" ]; then + echo "Error: Could not find input file" + exit 1 + fi + + FOUND_FILE="$FOUND_FILES" + ./.ci/append-to-github-output.sh "input_file" "$FOUND_FILE" + + - name: Download DiffTool JAR + uses: robinraju/release-downloader@v1.8 + with: + repository: "checkstyle/test-configs" + tag: "extractor-${{env.EXTRACTOR_VERSION}}" + fileName: "extractor-all-${{env.EXTRACTOR_VERSION}}.jar" + + - name: Set up Java 21 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - name: Generate config + id: generated_config_bundle + env: + DEFAULT_PROJECTS_LINK: ${{ env.DEFAULT_PROJECTS_LINK }} + run: | + FOUND_FILE="${{ steps.find_input_file.outputs.input_file }}" + BASE_PATH=".ci-temp/checkstyle" + OUTPUT_DIR="${{ env.GENERATED_CONFIGS_PATH }}" + mkdir -p "$OUTPUT_DIR" + + echo "Original FOUND_FILE = $FOUND_FILE" + + # Remove .ci-temp/checkstyle/ from the beginning of FOUND_FILE + RELATIVE_PATH=${FOUND_FILE#.ci-temp/checkstyle/} + + echo "Processed RELATIVE_PATH = $RELATIVE_PATH" + + # Generate a unique name for the config file + CONFIG_FILE_NAME=$(basename "$FOUND_FILE" .java)_config.xml + CONFIG_FILE_PATH="$OUTPUT_DIR/$CONFIG_FILE_NAME" + + # Generate a name for the projects file + PROJECT_FILE_PATH="$OUTPUT_DIR/projects.properties" + + # Run the extractor + java -jar extractor-all-${{env.EXTRACTOR_VERSION}}.jar \ + "$BASE_PATH" \ + --input-file "$RELATIVE_PATH" \ + "$CONFIG_FILE_PATH" \ + "$PROJECT_FILE_PATH" + + # Set the config and project file paths + ./.ci/append-to-github-output.sh "config_link" "$CONFIG_FILE_PATH" + ./.ci/append-to-github-output.sh "projects_link" "$PROJECT_FILE_PATH" + + # Print the contents of the files to the logs + echo "Contents of CONFIG_FILE_PATH:" + cat "$CONFIG_FILE_PATH" + + - name: Cache Generated Config and Project Files + uses: actions/cache@v4 + with: + path: ${{ env.GENERATED_CONFIGS_PATH }} + key: ${{ env.CACHE_KEY_GENERATED_CONFIGS }} + + handle_configs_in_pr_description: + needs: [ parse_comment, checkout_and_cache ] + if: needs.parse_comment.outputs.mode == 'configs_in_pr_description' + runs-on: ubuntu-latest + outputs: + config_link: ${{ steps.parse_description.outputs.config_link }} + projects_link: ${{ steps.parse_description.outputs.projects_link }} + steps: + - name: Restore Master Checkstyle Checkout + uses: actions/cache@v4 + with: + path: . + key: "${{ env.CACHE_KEY_MASTER }}" + + - name: Getting PR description + env: + ISSUE_BODY: ${{ github.event.issue.body }} + PULL_REQUEST_URL: ${{ github.event.issue.pull_request.url }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + mkdir -p .ci-temp + # convert windows line endings to unix in event text + echo "$ISSUE_BODY" > .ci-temp/windows.txt + tr -d '\15\32' < .ci-temp/windows.txt > .ci-temp/text + + curl --fail-with-body -X GET "${PULL_REQUEST_URL}" \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: token $GITHUB_TOKEN" \ + -o .ci-temp/info.json + + jq --raw-output .head.ref .ci-temp/info.json > .ci-temp/branch + jq --raw-output .head.sha .ci-temp/info.json > .ci-temp/commit_sha + + - name: Parsing content of PR description + id: parse_description + run: | + ./.ci/diff-report.sh parse-pr-description-text + + download_configs: + needs: [ + parse_comment, + handle_existing_config_bundle, + handle_generated_config_bundle, + handle_configs_in_pr_description + ] + if: | + always() && + (needs.handle_existing_config_bundle.result == 'success' + || needs.handle_generated_config_bundle.result == 'success' + || needs.handle_configs_in_pr_description.result == 'success') + runs-on: ubuntu-latest + outputs: + branch: ${{ steps.set_branch.outputs.ref }} + commit_sha: ${{ steps.set_branch.outputs.commit_sha }} + steps: + - name: Restore Master Checkstyle Checkout + uses: actions/cache@v4 + with: + path: . + key: "${{ env.CACHE_KEY_MASTER }}" + + - name: Restore Generated Config and Project Files + if: needs.handle_generated_config_bundle.result == 'success' + uses: actions/cache@v4 + with: + path: ${{ env.GENERATED_CONFIGS_PATH }} + key: ${{ env.CACHE_KEY_GENERATED_CONFIGS }} + + - name: Process local-based generated Config and Project File + if: needs.handle_generated_config_bundle.result == 'success' + env: + DIFF_CONFIG_LINK: ${{ needs.handle_generated_config_bundle.outputs.config_link }} + DIFF_PROJECTS_LINK: ${{ needs.handle_generated_config_bundle.outputs.projects_link }} + run: | + mkdir -p .ci-temp + echo "Config link: $DIFF_CONFIG_LINK" + echo "Projects link: $DIFF_PROJECTS_LINK" + cp "$DIFF_CONFIG_LINK" .ci-temp/diff_config.xml + cp "$DIFF_PROJECTS_LINK" .ci-temp/project.properties + + - name: Download URL-based Config and Project File + id: download_files + if: needs.handle_existing_config_bundle.result == 'success' + || needs.handle_configs_in_pr_description.result == 'success' + env: + DIFF_CONFIG_LINK: ${{ + needs.handle_existing_config_bundle.outputs.config_link + || needs.handle_configs_in_pr_description.outputs.config_link + }} + DIFF_PROJECTS_LINK: ${{ + needs.handle_existing_config_bundle.outputs.projects_link + || needs.handle_configs_in_pr_description.outputs.projects_link + || env.DEFAULT_PROJECTS_LINK + }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + mkdir -p .ci-temp + if ! ./.ci/diff-report.sh download-files; then + ./.ci/append-to-github-output.sh "failed" "true" + exit 1 + fi + - name: Set branch env: PULL_REQUEST_URL: ${{ github.event.issue.pull_request.url }} @@ -122,36 +423,45 @@ jobs: # shellcheck disable=SC2005 echo "$(cat "$GITHUB_OUTPUT")" + - name: Cache config files + uses: actions/cache@v4 + with: + path: | + .ci-temp/*.xml + .ci-temp/project.properties + key: ${{ env.CACHE_KEY_CONFIG_FILES }} + make_report: + needs: [ download_configs ] + if: always() && needs.download_configs.result == 'success' runs-on: ubuntu-latest - needs: parse_comment - if: needs.parse_comment.outputs.config_link != '' - || needs.parse_comment.outputs.projects_link != '' outputs: message: ${{ steps.out.outputs.message }} - download_files_failed: ${{ steps.download_files.outputs.failed }} steps: + - name: Restore Master Checkstyle Checkout + uses: actions/cache@v4 + with: + path: .ci-temp/checkstyle + key: "${{ env.CACHE_KEY_MASTER }}" - - name: Download checkstyle - uses: actions/checkout@v4 + - name: Restore PR Checkout + uses: actions/cache@v4 + with: + path: . + key: "${{ env.CACHE_KEY_PR }}" - - name: Download files - id: download_files - env: - DIFF_CONFIG_LINK: ${{ needs.parse_comment.outputs.config_link }} - DIFF_PROJECTS_LINK: ${{ needs.parse_comment.outputs.projects_link }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - if ! ./.ci/diff-report.sh download-files; then - ./.ci/append-to-github-output.sh "failed" "true" - exit 1 - fi + - name: Restore config files from cache + uses: actions/cache@v4 + with: + path: | + .ci-temp/*.xml + .ci-temp/project.properties + key: ${{ env.CACHE_KEY_CONFIG_FILES }} - # set main checkstyle repo as an upstream - # Diff report will be generated taking upstream's master branch as a base branch - - name: set upstream + - name: Set upstream run: | bash + cd .ci-temp/checkstyle MAIN_REPO_GIT_URL="https://github.com/checkstyle/checkstyle.git" git remote add upstream "$MAIN_REPO_GIT_URL" git fetch upstream @@ -165,11 +475,11 @@ jobs: path: ~/.m2/repository key: checkstyle-maven-cache-${{ hashFiles('**/pom.xml') }} - - name: Download contribution - uses: actions/checkout@v4 + - name: Restore Contribution Checkout + uses: actions/cache@v4 with: - repository: checkstyle/contribution path: .ci-temp/contribution + key: "${{ env.CACHE_KEY_CONTRIBUTION }}" - name: Prepare environment run: | @@ -186,12 +496,12 @@ jobs: - name: Generate report env: - BRANCH: ${{ needs.parse_comment.outputs.branch }} + BRANCH: ${{ needs.download_configs.outputs.branch }} run: | cd .ci-temp/contribution/checkstyle-tester bash REF="forked/$BRANCH" - REPO="../../../../checkstyle" + REPO="${{ github.workspace }}/.ci-temp/checkstyle" BASE_BRANCH="upstream/master" export MAVEN_OPTS="-Xmx5g" if [ -f new_module_config.xml ]; then @@ -212,7 +522,7 @@ jobs: run: | bash TIME=$(date +%Y%H%M%S) - FOLDER="${{needs.parse_comment.outputs.commit_sha}}_$TIME" + FOLDER="${{needs.download_configs.outputs.commit_sha}}_$TIME" DIFF="./.ci-temp/contribution/checkstyle-tester/reports/diff" LINK="https://${{env.AWS_BUCKET_NAME}}.s3.${{env.AWS_REGION}}.amazonaws.com" aws s3 cp $DIFF "s3://${{env.AWS_BUCKET_NAME}}/$FOLDER/reports/diff/" --recursive @@ -246,8 +556,15 @@ jobs: # should be always last step send_message: runs-on: ubuntu-latest - needs: [ check_pr_status, parse_comment, make_report ] - if: failure() || success() + needs: [ + handle_generated_config_bundle, + download_configs, + make_report ] + if: always() + && (needs.make_report.result == 'failure' + || needs.make_report.outputs.message != '' + || needs.download_configs.result == 'failure' + || needs.handle_generated_config_bundle.result == 'failure') steps: - name: Checkout repository uses: actions/checkout@v4 @@ -255,29 +572,51 @@ jobs: - name: Get message env: MSG: ${{ needs.make_report.outputs.message }} - DOWNLOAD_FAILED: ${{ needs.make_report.outputs.download_files_failed }} + DOWNLOAD_RESULT: ${{ needs.download_configs.result }} + MAKE_REPORT_RESULT: ${{ needs.make_report.result }} + GENERATED_CONFIG_RESULT: ${{ needs.handle_generated_config_bundle.result }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | mkdir -p .ci-temp JOBS_LINK="https://github.com/checkstyle/checkstyle/actions/runs/${{github.run_id}}" - if [ "$DOWNLOAD_FAILED" == "true" ]; then - echo "Report generation failed. Please use 'GitHub, generate report for" \ - "check_name/example_type'
Link: $JOBS_LINK" > .ci-temp/message + if [ "$DOWNLOAD_RESULT" == "failure" ]; then + { + echo "Failed to download or process the specified configuration(s)." + echo "Error details: $DOWNLOAD_ERROR" + echo "
Please ensure you've used one of the following commands correctly:" + echo "- 'GitHub, generate report for '" + echo "- 'GitHub, generate report by config from '" + echo "- 'GitHub, generate report for configs in PR description'" + echo "
And check that all specified configs or files exist and are valid." + echo "
Link: $JOBS_LINK" + } > .ci-temp/message + elif [ "$GENERATED_CONFIG_RESULT" == "failure" ]; then + { + echo "Failed to generate config from the specified file." + echo "Please ensure the file exists and the path is correct." + echo "
Usage: 'GitHub, generate report by config from '" + echo "
Link: $JOBS_LINK" + } > .ci-temp/message + elif [ "$MAKE_REPORT_RESULT" == "failure" ]; then + { + echo "Report generation failed. Please check the logs for more details." + echo "
Link: $JOBS_LINK" + } > .ci-temp/message elif [ -z "$MSG" ]; then - API_LINK="https://api.github.com/repos/checkstyle/checkstyle/actions/runs/" - API_LINK="${API_LINK}${{github.run_id}}/jobs" - + API_LINK="https://api.github.com/repos/checkstyle/checkstyle/actions/runs/${{github.run_id}}/jobs" curl --fail-with-body -X GET "${API_LINK}" \ -H "Accept: application/vnd.github+json" \ -H "Authorization: token $GITHUB_TOKEN" \ -o .ci-temp/info.json - jq '.jobs' .ci-temp/info.json > ".ci-temp/jobs" jq '.[] | select(.conclusion == "failure") | .name' .ci-temp/jobs > .ci-temp/job_name jq '.[] | select(.conclusion == "failure") | .steps' .ci-temp/jobs > .ci-temp/steps jq '.[] | select(.conclusion == "failure") | .name' .ci-temp/steps > .ci-temp/step_name - echo "Report generation failed on phase $(cat .ci-temp/job_name)," > .ci-temp/message - echo "step $(cat .ci-temp/step_name).
Link: $JOBS_LINK" >> .ci-temp/message + { + echo "Report generation failed on phase $(cat .ci-temp/job_name)," + echo "step $(cat .ci-temp/step_name)." + echo "
Link: $JOBS_LINK" + } > .ci-temp/message else echo "$MSG" > .ci-temp/message fi diff --git a/README.md b/README.md index 2b36b088fa7..82305ca4851 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,6 @@ or set of validation rules (best practices). [![][milestone img]][milestone] -Contributors chat: [![][matrix_con img]][matrix_con] - The latest release version can be found at [GitHub releases](https://github.com/checkstyle/checkstyle/releases/) or at [Maven repo](https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/). diff --git a/config/jsoref-spellchecker/whitelist.words b/config/jsoref-spellchecker/whitelist.words index 3ff866f02c6..bce2e288e4f 100644 --- a/config/jsoref-spellchecker/whitelist.words +++ b/config/jsoref-spellchecker/whitelist.words @@ -1349,6 +1349,7 @@ tw typecastparenpad typename typevariablenames +ub uber ubuntu ucc diff --git a/pom.xml b/pom.xml index cd6437626da..09630b4c958 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.puppycrawl.tools checkstyle - 10.18.0 + 10.18.1 jar checkstyle @@ -223,7 +223,7 @@ 3.13.0 11 ${java.version} - 1.16.1 + 1.16.2 10 HTML,XML 50000 @@ -235,7 +235,7 @@ 3.7 1.2.0 3.46.0 - 2.30.0 + 2.31.0 0.15.0 1.12.0 @@ -302,7 +302,7 @@ org.apache.ant ant - 1.10.14 + 1.10.15 provided @@ -535,7 +535,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.8.0 + 3.10.0 @@ -1514,7 +1514,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.4.0 + 3.5.0 com/google/**/*.java @@ -1541,7 +1541,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 -Dfile.encoding=UTF-8 ${surefire.options} @@ -1943,7 +1943,7 @@ org.apache.maven.plugins maven-surefire-report-plugin - 3.4.0 + 3.5.0 diff --git a/src/it/java/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/OrderingAndSpacingTest.java b/src/it/java/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/OrderingAndSpacingTest.java index 8f8a6c27f0d..b7238d3645f 100644 --- a/src/it/java/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/OrderingAndSpacingTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/OrderingAndSpacingTest.java @@ -34,39 +34,79 @@ public void testCustomImport1() throws Exception { verifyWithWholeConfig(getPath("InputOrderingAndSpacing1.java")); } + @Test + public void testCustomImport1Formatted() throws Exception { + verifyWithWholeConfig(getPath("InputFormattedOrderingAndSpacing1.java")); + } + @Test public void testCustomImport2() throws Exception { verifyWithWholeConfig(getPath("InputOrderingAndSpacing2.java")); } + @Test + public void testCustomImport2Formatted() throws Exception { + verifyWithWholeConfig(getPath("InputFormattedOrderingAndSpacing2.java")); + } + @Test public void testCustomImport3() throws Exception { verifyWithWholeConfig(getPath("InputOrderingAndSpacing3.java")); } + @Test + public void testCustomImport3Formatted() throws Exception { + verifyWithWholeConfig(getPath("InputFormattedOrderingAndSpacing3.java")); + } + @Test public void testCustomImport4() throws Exception { verifyWithWholeConfig(getPath("InputOrderingAndSpacing4.java")); } + @Test + public void testCustomImport4Formatted() throws Exception { + verifyWithWholeConfig(getPath("InputFormattedOrderingAndSpacing4.java")); + } + @Test public void testCustomImport5() throws Exception { verifyWithWholeConfig(getPath("InputOrderingAndSpacing5.java")); } + @Test + public void testCustomImport5Formatted() throws Exception { + verifyWithWholeConfig(getPath("InputFormattedOrderingAndSpacing5.java")); + } + @Test public void testValid() throws Exception { verifyWithWholeConfig(getPath("InputOrderingAndSpacingValid.java")); } + @Test + public void testValidFormatted() throws Exception { + verifyWithWholeConfig(getPath("InputFormattedOrderingAndSpacingValid.java")); + } + @Test public void testValid2() throws Exception { verifyWithWholeConfig(getPath("InputOrderingAndSpacingValid2.java")); } + @Test + public void testValid2Formatted() throws Exception { + verifyWithWholeConfig(getPath("InputFormattedOrderingAndSpacingValid2.java")); + } + @Test public void testValidGoogleStyleOrderOfImports() throws Exception { verifyWithWholeConfig(getPath("InputOrderingAndSpacingNoImports.java")); } + @Test + public void testValidGoogleStyleOrderOfImportsFormatted() throws Exception { + verifyWithWholeConfig(getPath("InputFormattedOrderingAndSpacingNoImports.java")); + } + } diff --git a/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule713atclauses/BlockTagsTest.java b/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule713atclauses/BlockTagsTest.java index a3805957563..5529c8d0df8 100644 --- a/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule713atclauses/BlockTagsTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter7javadoc/rule713atclauses/BlockTagsTest.java @@ -65,6 +65,11 @@ public void testJavadocTagContinuationIndentation() throws Exception { verifyWithWholeConfig(getPath("InputJavaDocTagContinuationIndentation.java")); } + @Test + public void testJavadocTagContinuationIndentationFormatted() throws Exception { + verifyWithWholeConfig(getPath("InputFormattedJavaDocTagContinuationIndentation.java")); + } + @Test public void testNonEmptyAtclauseDescription() throws Exception { verifyWithWholeConfig(getPath("InputNonEmptyAtclauseDescription.java")); diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing1.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing1.java new file mode 100644 index 00000000000..661aa36b897 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing1.java @@ -0,0 +1,38 @@ +package com.google.checkstyle.test.chapter3filestructure.rule333orderingandspacing; + +import static java.awt.Button.ABORT; +import static java.io.File.createTempFile; +import static javax.swing.WindowConstants.*; // violation '.*' form of import should be avoided' + +import com.google.common.base.Ascii; +import java.awt.*; // violation 'Using the '.*' form of import should be avoided' +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import javax.swing.*; // violation 'Using the '.*' form of import should be avoided' + +/** Some javadoc. */ +public class InputFormattedOrderingAndSpacing1 { + /** some javadoc. */ + public static void main(String[] args) { + // Use of static imports + try { + File tempFile = createTempFile("temp", ".txt"); + } catch (IOException e) { + e.printStackTrace(); + } + int abortAction = ABORT; + + Frame frame = new Frame(); + + JTable table = new JTable(); + int closeOperation = EXIT_ON_CLOSE; + + File file = new File("example.txt"); + InputStream inputStream = System.in; + Reader reader = null; + + char ascii = Ascii.BS; + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing2.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing2.java new file mode 100644 index 00000000000..ef7277bedb8 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing2.java @@ -0,0 +1,67 @@ +package com.google.checkstyle.test.chapter3filestructure.rule333orderingandspacing; + +import static java.awt.Button.ABORT; +import static java.io.File.createTempFile; +import static javax.swing.WindowConstants.*; // violation '.*' form of import should be avoided' + +import com.google.checkstyle.test.chapter2filebasic.rule21filename.*; // violation '.*' +import com.google.checkstyle.test.chapter3filestructure.rule3sourcefile.*; // violation '.*' +import com.google.common.reflect.*; // violation 'Using the '.*' form of import should be avoided' +import java.util.*; // violation 'Using the '.*' form of import should be avoided' +import java.util.List; +import java.util.StringTokenizer; +import java.util.concurrent.*; // violation 'Using the '.*' form of import should be avoided' +import java.util.concurrent.AbstractExecutorService; + +/** Some javadoc. */ +public class InputFormattedOrderingAndSpacing2 { + /** Some javadoc. */ + public static void main(String[] args) { + try { + createTempFile("temp", ".txt"); + } catch (Exception e) { + e.printStackTrace(); + } + int abortAction = ABORT; + int closeOperation = EXIT_ON_CLOSE; + + List list = new ArrayList<>(); + StringTokenizer tokenizer = new StringTokenizer("Hello World"); + + AbstractExecutorService abstractExecutorService = + new AbstractExecutorService() { + @Override + public void shutdown() {} + + @Override + public List shutdownNow() { + return null; + } + + @Override + public boolean isShutdown() { + return false; + } + + @Override + public boolean isTerminated() { + return false; + } + + @Override + public boolean awaitTermination(long timeout, TimeUnit unit) { + return false; + } + + @Override + public void execute(Runnable command) {} + }; + ExecutorService executorService = Executors.newSingleThreadExecutor(); + + TypeToken typeToken = TypeToken.of(String.class); + + FileNameTest testing1 = new FileNameTest(); + + SourceFileStructureTest testing2 = new SourceFileStructureTest(); + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing3.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing3.java new file mode 100644 index 00000000000..d453fb48977 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing3.java @@ -0,0 +1,83 @@ +package com.google.checkstyle.test.chapter3filestructure.rule333orderingandspacing; + +import static java.awt.Button.ABORT; +import static java.io.File.createTempFile; +import static javax.swing.WindowConstants.EXIT_ON_CLOSE; + +import com.google.checkstyle.test.chapter2filebasic.rule21filename.FileNameTest; +import com.google.checkstyle.test.chapter3filestructure.rule3sourcefile.SourceFileStructureTest; +import com.google.common.reflect.ImmutableTypeToInstanceMap; +import java.awt.Dialog; +import java.io.File; +import java.util.LinkedHashMap; +import java.util.StringTokenizer; +import java.util.concurrent.AbstractExecutorService; +import java.util.concurrent.ThreadFactory; + +/** Some javadoc. */ +public class InputFormattedOrderingAndSpacing3 { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + int abortAction = ABORT; + int closeOperation = EXIT_ON_CLOSE; + + try { + createTempFile("temp", ".txt"); + } catch (Exception e) { + e.printStackTrace(); + } + + // Use of java.awt and javax.swing classes + Dialog dialog = new Dialog(new java.awt.Frame()); + + // Use of java.io classes + File file = new File("example.txt"); + + // Use of java.util classes + StringTokenizer tokenizer = new StringTokenizer("Hello World"); + LinkedHashMap map = new LinkedHashMap<>(); + + // Use of java.util.concurrent classes + ThreadFactory threadFactory = + new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + return new Thread(r); + } + }; + AbstractExecutorService abstractExecutorService = + new AbstractExecutorService() { + @Override + public void shutdown() {} + + @Override + public java.util.List shutdownNow() { + return null; + } + + @Override + public boolean isShutdown() { + return false; + } + + @Override + public boolean isTerminated() { + return false; + } + + @Override + public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) { + return false; + } + + @Override + public void execute(Runnable command) {} + }; + + // Use of com.google classes + FileNameTest fileNameTest = new FileNameTest(); + ImmutableTypeToInstanceMap mapInstance = ImmutableTypeToInstanceMap.builder().build(); + SourceFileStructureTest sourceFileStructureTest = new SourceFileStructureTest(); + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing4.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing4.java new file mode 100644 index 00000000000..62d983e43a3 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing4.java @@ -0,0 +1,66 @@ +package com.google.checkstyle.test.chapter3filestructure.rule333orderingandspacing; + +import static java.awt.Button.ABORT; +import static java.io.File.createTempFile; +import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE; + +import com.google.checkstyle.test.chapter2filebasic.rule21filename.FileNameTest; +import com.google.checkstyle.test.chapter3filestructure.rule3sourcefile.SourceFileStructureTest; +import com.google.common.reflect.Invokable; +import java.util.List; +import java.util.StringTokenizer; +import java.util.concurrent.AbstractExecutorService; + +/** Some javadoc. */ +public class InputFormattedOrderingAndSpacing4 { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + try { + createTempFile("temp", ".txt"); + } catch (Exception e) { + e.printStackTrace(); + } + int abortAction = ABORT; + int closeOperation = DO_NOTHING_ON_CLOSE; + + // Use of com.google classes + FileNameTest fileNameTest = new FileNameTest(); + SourceFileStructureTest sourceFileStructureTest = new SourceFileStructureTest(); + Invokable invokable = Invokable.from(Object.class.getDeclaredMethods()[0]); + + // Use of java.util classes + List list; + StringTokenizer tokenizer = new StringTokenizer("Hello World"); + + // Use of java.util.concurrent classes + AbstractExecutorService abstractExecutorService = + new AbstractExecutorService() { + @Override + public void shutdown() {} + + @Override + public List shutdownNow() { + return null; + } + + @Override + public boolean isShutdown() { + return false; + } + + @Override + public boolean isTerminated() { + return false; + } + + @Override + public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) { + return false; + } + + @Override + public void execute(Runnable command) {} + }; + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing5.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing5.java new file mode 100644 index 00000000000..a15b57d2cc2 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing5.java @@ -0,0 +1,66 @@ +package com.google.checkstyle.test.chapter3filestructure.rule333orderingandspacing; + +import static java.awt.Button.ABORT; +import static java.io.File.createTempFile; +import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE; + +import com.google.checkstyle.test.chapter2filebasic.rule21filename.InputFileName1; +import com.google.checkstyle.test.chapter3filestructure.rule3sourcefile.SourceFileStructureTest; +import com.google.common.reflect.TypeToken; +import java.util.List; +import java.util.StringTokenizer; +import java.util.concurrent.AbstractExecutorService; + +/** Some javadoc. */ +public class InputFormattedOrderingAndSpacing5 { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + int abortAction = ABORT; + try { + createTempFile("temp", ".txt"); + } catch (Exception e) { + e.printStackTrace(); + } + int closeOperation = DISPOSE_ON_CLOSE; + + // Use of com.google classes + InputFileName1 inputFileName1 = new InputFileName1(); + SourceFileStructureTest sourceFileStructureTest = new SourceFileStructureTest(); + TypeToken typeToken = TypeToken.of(String.class); + + // Use of java.util classes + List list; + StringTokenizer tokenizer = new StringTokenizer("Hello World"); + + // Use of java.util.concurrent classes + AbstractExecutorService abstractExecutorService = + new AbstractExecutorService() { + @Override + public void shutdown() {} + + @Override + public List shutdownNow() { + return null; + } + + @Override + public boolean isShutdown() { + return false; + } + + @Override + public boolean isTerminated() { + return false; + } + + @Override + public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) { + return false; + } + + @Override + public void execute(Runnable command) {} + }; + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingNoImports.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingNoImports.java new file mode 100644 index 00000000000..a9562970eef --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingNoImports.java @@ -0,0 +1,4 @@ +package com.google.checkstyle.test.chapter3filestructure.rule333orderingandspacing; + +/** Some javadoc. */ +public class InputFormattedOrderingAndSpacingNoImports {} diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingValid.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingValid.java new file mode 100644 index 00000000000..7d24ed92813 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingValid.java @@ -0,0 +1,51 @@ +package com.google.checkstyle.test.chapter3filestructure.rule333orderingandspacing; + +// it is not forbidden to have extra lines (more than one) between package and import group + +import static com.puppycrawl.tools.checkstyle.utils.AnnotationUtil.containsAnnotation; +import static com.puppycrawl.tools.checkstyle.utils.AnnotationUtil.getAnnotation; + +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck; +import com.puppycrawl.tools.checkstyle.checks.design.ThrowsCountCheck; +import com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck; +import java.util.Arrays; +import java.util.BitSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NoSuchElementException; +import javax.accessibility.Accessible; +import org.apache.commons.beanutils.converters.ArrayConverter; + +/** Some javadoc. */ +public class InputFormattedOrderingAndSpacingValid { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + boolean hasAnnotation = containsAnnotation((DetailAST) new Object(), "Override"); + Object annotation = getAnnotation((DetailAST) new Object(), "Override"); + + // Use of com.puppycrawl.tools.checkstyle classes + FinalClassCheck finalClassCheck = new FinalClassCheck(); + ThrowsCountCheck throwsCountCheck = new ThrowsCountCheck(); + VisibilityModifierCheck visibilityModifierCheck = new VisibilityModifierCheck(); + + // Use of java.util classes + int[] numbers = {1, 2, 3}; + Arrays.sort(numbers); + BitSet bitSet = new BitSet(); + Map map; + Entry entry = Map.entry("key", "value"); + try { + throw new NoSuchElementException(); + } catch (NoSuchElementException e) { + e.printStackTrace(); + } + + // Use of javax.accessibility classes + Accessible accessible; + + // Use of org.apache.commons.beanutils.converters classes + ArrayConverter arrayConverter = new ArrayConverter(int[].class, null); + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingValid2.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingValid2.java new file mode 100644 index 00000000000..3e17ce6b9f2 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingValid2.java @@ -0,0 +1,53 @@ +package com.google.checkstyle.test.chapter3filestructure.rule333orderingandspacing; + +import static com.puppycrawl.tools.checkstyle.utils.AnnotationUtil.containsAnnotation; +import static com.puppycrawl.tools.checkstyle.utils.AnnotationUtil.getAnnotation; + +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck; +import com.puppycrawl.tools.checkstyle.checks.design.ThrowsCountCheck; +import com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck; +import java.util.Arrays; +import java.util.BitSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NoSuchElementException; +import javax.accessibility.Accessible; +import org.apache.commons.beanutils.converters.ArrayConverter; + +/** Some javadoc. */ +public class InputFormattedOrderingAndSpacingValid2 { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + boolean hasAnnotation = containsAnnotation((DetailAST) new Object(), "Override"); + Object annotation = getAnnotation((DetailAST) new Object(), "Override"); + + // comments + + // Use of com.puppycrawl.tools.checkstyle classes + FinalClassCheck finalClassCheck = new FinalClassCheck(); + ThrowsCountCheck throwsCountCheck = new ThrowsCountCheck(); + VisibilityModifierCheck visibilityModifierCheck = new VisibilityModifierCheck(); + + // Use of java.util classes + int[] numbers = {1, 2, 3}; + Arrays.sort(numbers); + BitSet bitSet = new BitSet(); + Map map; + Entry entry = Map.entry("key", "value"); + try { + throw new NoSuchElementException(); + } catch (NoSuchElementException e) { + e.printStackTrace(); + } + + // comments + + // Use of javax.accessibility classes + Accessible accessible; + + // Use of org.apache.commons.beanutils.converters classes + ArrayConverter arrayConverter = new ArrayConverter(int[].class, null); + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing1.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing1.java index 068b9eb46df..986c9cef386 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing1.java +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing1.java @@ -28,4 +28,26 @@ // '.* 'com.google.common.base.Ascii' .* Should be before 'javax.swing.JTable'.' /** Some javadoc. */ -public class InputOrderingAndSpacing1 {} +public class InputOrderingAndSpacing1 { + /** some javadoc. */ + public static void main(String[] args) { + // Use of static imports + try { + File tempFile = createTempFile("temp", ".txt"); + } catch (IOException e) { + e.printStackTrace(); + } + int abortAction = ABORT; + + Frame frame = new Frame(); + + JTable table = new JTable(); + int closeOperation = EXIT_ON_CLOSE; + + File file = new File("example.txt"); + InputStream inputStream = System.in; + Reader reader = null; + + char ascii = Ascii.BS; + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing2.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing2.java index 2b5b6018460..924fd170984 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing2.java +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing2.java @@ -38,4 +38,54 @@ /** Some javadoc. */ public class InputOrderingAndSpacing2 { + /** Some javadoc. */ + public static void main(String[] args) { + try { + createTempFile("temp", ".txt"); + } catch (Exception e) { + e.printStackTrace(); + } + int abortAction = ABORT; + int closeOperation = EXIT_ON_CLOSE; + + List list = new ArrayList<>(); + StringTokenizer tokenizer = new StringTokenizer("Hello World"); + + AbstractExecutorService abstractExecutorService = new AbstractExecutorService() { + @Override + public void shutdown() { + } + + @Override + public List shutdownNow() { + return null; + } + + @Override + public boolean isShutdown() { + return false; + } + + @Override + public boolean isTerminated() { + return false; + } + + @Override + public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) { + return false; + } + + @Override + public void execute(Runnable command) { + } + }; + ExecutorService executorService = Executors.newSingleThreadExecutor(); + + TypeToken typeToken = TypeToken.of(String.class); + + FileNameTest testing1 = new FileNameTest(); + + SourceFileStructureTest testing2 = new SourceFileStructureTest(); + } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing3.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing3.java index 5a30c6c8f51..538af8b8a39 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing3.java +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing3.java @@ -26,4 +26,68 @@ /** Some javadoc. */ public class InputOrderingAndSpacing3 { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + int abortAction = ABORT; + int closeOperation = EXIT_ON_CLOSE; + + try { + createTempFile("temp", ".txt"); + } catch (Exception e) { + e.printStackTrace(); + } + + // Use of java.awt and javax.swing classes + Dialog dialog = new Dialog(new java.awt.Frame()); + + // Use of java.io classes + File file = new File("example.txt"); + + // Use of java.util classes + StringTokenizer tokenizer = new StringTokenizer("Hello World"); + LinkedHashMap map = new LinkedHashMap<>(); + + // Use of java.util.concurrent classes + ThreadFactory threadFactory = new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + return new Thread(r); + } + }; + AbstractExecutorService abstractExecutorService = new AbstractExecutorService() { + @Override + public void shutdown() { + } + + @Override + public java.util.List shutdownNow() { + return null; + } + + @Override + public boolean isShutdown() { + return false; + } + + @Override + public boolean isTerminated() { + return false; + } + + @Override + public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) { + return false; + } + + @Override + public void execute(Runnable command) { + } + }; + + // Use of com.google classes + FileNameTest fileNameTest = new FileNameTest(); + ImmutableTypeToInstanceMap mapInstance = ImmutableTypeToInstanceMap.builder().build(); + SourceFileStructureTest sourceFileStructureTest = new SourceFileStructureTest(); + } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing4.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing4.java index f5fd342113e..beb05e4ada7 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing4.java +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing4.java @@ -21,4 +21,55 @@ /** Some javadoc. */ public class InputOrderingAndSpacing4 { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + try { + createTempFile("temp", ".txt"); + } catch (Exception e) { + e.printStackTrace(); + } + int abortAction = ABORT; + int closeOperation = DO_NOTHING_ON_CLOSE; + + // Use of com.google classes + FileNameTest fileNameTest = new FileNameTest(); + SourceFileStructureTest sourceFileStructureTest = new SourceFileStructureTest(); + Invokable invokable = Invokable.from(Object.class.getDeclaredMethods()[0]); + + // Use of java.util classes + List list; + StringTokenizer tokenizer = new StringTokenizer("Hello World"); + + // Use of java.util.concurrent classes + AbstractExecutorService abstractExecutorService = new AbstractExecutorService() { + @Override + public void shutdown() { + } + + @Override + public java.util.List shutdownNow() { + return null; + } + + @Override + public boolean isShutdown() { + return false; + } + + @Override + public boolean isTerminated() { + return false; + } + + @Override + public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) { + return false; + } + + @Override + public void execute(Runnable command) { + } + }; + } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing5.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing5.java index a6880ff4496..c384e75eef2 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing5.java +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacing5.java @@ -31,4 +31,55 @@ /** Some javadoc. */ public class InputOrderingAndSpacing5 { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + int abortAction = ABORT; + try { + createTempFile("temp", ".txt"); + } catch (Exception e) { + e.printStackTrace(); + } + int closeOperation = DISPOSE_ON_CLOSE; + + // Use of com.google classes + InputFileName1 inputFileName1 = new InputFileName1(); + SourceFileStructureTest sourceFileStructureTest = new SourceFileStructureTest(); + TypeToken typeToken = TypeToken.of(String.class); + + // Use of java.util classes + List list; + StringTokenizer tokenizer = new StringTokenizer("Hello World"); + + // Use of java.util.concurrent classes + AbstractExecutorService abstractExecutorService = new AbstractExecutorService() { + @Override + public void shutdown() { + } + + @Override + public java.util.List shutdownNow() { + return null; + } + + @Override + public boolean isShutdown() { + return false; + } + + @Override + public boolean isTerminated() { + return false; + } + + @Override + public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) { + return false; + } + + @Override + public void execute(Runnable command) { + } + }; + } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacingValid.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacingValid.java index 9d393d2a277..db6facd0689 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacingValid.java +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacingValid.java @@ -6,6 +6,7 @@ import static com.puppycrawl.tools.checkstyle.utils.AnnotationUtil.containsAnnotation; import static com.puppycrawl.tools.checkstyle.utils.AnnotationUtil.getAnnotation; +import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck; import com.puppycrawl.tools.checkstyle.checks.design.ThrowsCountCheck; import com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck; @@ -19,4 +20,33 @@ /** Some javadoc. */ public class InputOrderingAndSpacingValid { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + boolean hasAnnotation = containsAnnotation((DetailAST) new Object(), "Override"); + Object annotation = getAnnotation((DetailAST) new Object(), "Override"); + + // Use of com.puppycrawl.tools.checkstyle classes + FinalClassCheck finalClassCheck = new FinalClassCheck(); + ThrowsCountCheck throwsCountCheck = new ThrowsCountCheck(); + VisibilityModifierCheck visibilityModifierCheck = new VisibilityModifierCheck(); + + // Use of java.util classes + int[] numbers = {1, 2, 3}; + Arrays.sort(numbers); + BitSet bitSet = new BitSet(); + Map map; + Entry entry = Map.entry("key", "value"); + try { + throw new NoSuchElementException(); + } catch (NoSuchElementException e) { + e.printStackTrace(); + } + + // Use of javax.accessibility classes + Accessible accessible; + + // Use of org.apache.commons.beanutils.converters classes + ArrayConverter arrayConverter = new ArrayConverter(int[].class, null); + } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacingValid2.java b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacingValid2.java index 192c52b12d7..e6fcfd62f59 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacingValid2.java +++ b/src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputOrderingAndSpacingValid2.java @@ -5,6 +5,7 @@ // comments // comments +import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck; import com.puppycrawl.tools.checkstyle.checks.design.ThrowsCountCheck; import com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck; @@ -19,4 +20,37 @@ /** Some javadoc. */ public class InputOrderingAndSpacingValid2 { + /** Some javadoc. */ + public static void main(String[] args) { + // Use of static imports + boolean hasAnnotation = containsAnnotation((DetailAST) new Object(), "Override"); + Object annotation = getAnnotation((DetailAST) new Object(), "Override"); + + // comments + + // Use of com.puppycrawl.tools.checkstyle classes + FinalClassCheck finalClassCheck = new FinalClassCheck(); + ThrowsCountCheck throwsCountCheck = new ThrowsCountCheck(); + VisibilityModifierCheck visibilityModifierCheck = new VisibilityModifierCheck(); + + // Use of java.util classes + int[] numbers = {1, 2, 3}; + Arrays.sort(numbers); + BitSet bitSet = new BitSet(); + Map map; + Entry entry = Map.entry("key", "value"); + try { + throw new NoSuchElementException(); + } catch (NoSuchElementException e) { + e.printStackTrace(); + } + + // comments + + // Use of javax.accessibility classes + Accessible accessible; + + // Use of org.apache.commons.beanutils.converters classes + ArrayConverter arrayConverter = new ArrayConverter(int[].class, null); + } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule523methodnames/InputMethodName.java b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule523methodnames/InputMethodName.java index 9bc9ed48147..93a55586a5c 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule523methodnames/InputMethodName.java +++ b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule523methodnames/InputMethodName.java @@ -1,6 +1,10 @@ package com.google.checkstyle.test.chapter5naming.rule523methodnames; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; /** * Test input for MethodNameCheck specifically whether the method name equals the class name. @@ -56,6 +60,79 @@ void Testing_Foo2() {} // violation 'Method name 'Testing_Foo2' must match patte @Test void TestingFooBad() {} // violation 'Method name 'TestingFooBad' must match pattern' + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void testing_foo1(String str) {} + + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void testing_Foo1(String str) {} + + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void testing_fOo1(String str) {} + + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void testingFoo1(String str) {} + + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void testingFoo_foo1(String str) {} + + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void testing_01231(String str) {} + + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void Testing_Foo1(String str) {} // violation 'Method name 'Testing_Foo1' must match pattern' + + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void t_esting1(String str) {} // violation 'Method name 't_esting1' must match pattern' + + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void _testing1(String str) {} // violation 'Method name '_testing1' must match pattern' + + @ParameterizedTest + @ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"}) + void TestingFooBad1(String str) {} // violation 'Method name 'TestingFooBad1' must match pattern' + + @RepeatedTest(2) + void testing_foo2() {} + + @RepeatedTest(2) + void testing_Foo2() {} + + @RepeatedTest(2) + void testing_fOo2() {} + + @RepeatedTest(2) + void testingFoo2() {} + + @RepeatedTest(2) + void testingFoo_foo2() {} + + @RepeatedTest(2) + void testing_01232() {} + + @RepeatedTest(2) + void Testing_Foo3() {} // violation 'Method name 'Testing_Foo3' must match pattern' + + @RepeatedTest(2) + void t_esting2() {} // violation 'Method name 't_esting2' must match pattern' + + @RepeatedTest(2) + void _testing2() {} // violation 'Method name '_testing2' must match pattern' + + @RepeatedTest(2) + void TestingFooBad2() {} // violation 'Method name 'TestingFooBad2' must match pattern' + + @BeforeAll + static void _testingFoooo() {} // violation 'Method name '_testingFoooo' must match pattern' + class InnerFoo { void foo() {} diff --git a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule713atclauses/InputFormattedJavaDocTagContinuationIndentation.java b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule713atclauses/InputFormattedJavaDocTagContinuationIndentation.java new file mode 100644 index 00000000000..a3d4e14f785 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule713atclauses/InputFormattedJavaDocTagContinuationIndentation.java @@ -0,0 +1,297 @@ +package com.google.checkstyle.test.chapter7javadoc.rule713atclauses; + +import java.io.Serializable; + +/** + * Some javadoc. + * + * @since Some javadoc. Some javadoc. + * @version 1.0 + * @deprecated Some javadoc. Some javadoc. + * @see Some javadoc. + * @author max Some javadoc. + */ +class InputFormattedJavaDocTagContinuationIndentation implements Serializable { + /** + * The client's first name. + * + * @serial Some javadoc. Some javadoc. + */ + private String firstName; + + /** + * The client's first name. + * + * @serial Some javadoc. + */ + private String secondName; + + /** + * The client's first name. + * + * @serialField secondName String Some components to be serial. + */ + private String thirdName; + + /** + * Some text. + * + * @param str Some javadoc. Some javadoc. + * @return Some text. + * @serialData Some javadoc. + * @throws Exception Some text. Some javadoc. + * @deprecated Some text. + */ + String method(String str) throws Exception { + return "null"; + } + + /** + * Some text. + * + * @serialData Some javadoc. + * @param str Some text. Some javadoc. + * @return Some text. + * @throws Exception Some text. + */ + String method1(String str) throws Exception { + return "null"; + } + + /** + * Some text. + * + * @param str Some text. Some javadoc. + * @throws Exception Some text. + */ + void method2(String str) throws Exception {} + + /** + * Some text. + * + * @throws Exception Some text. + * @deprecated Some text. Some javadoc. + */ + void method3() throws Exception {} + + /** + * Some text. + * + * @return Some text. + * @throws Exception Some text. + */ + String method4() throws Exception { + return "null"; + } + + /** + * Some text. + * + * @param str Some text. + * @return Some text. + * @deprecated Some text. + */ + String method5(String str) { + return "null"; + } + + /** + * Some text. + * + * @param str Some text. + * @param bool Some text. + * @param number Some text. Some javadoc. + * @return Some text. Some javadoc. + * @serialData Some javadoc. + * @throws Exception Some text. + * @deprecated Some text. + */ + String method6(String str, int number, boolean bool) throws Exception { + return "null"; + } + + /** + * Some javadoc. + * + * @version 1.0 + * @since Some javadoc. + * @serialData Some javadoc. + * @author max + */ + class InnerClassWithAnnotations { + /** + * Some text. + * + * @param str Some text. + * @return Some text. + * @throws Exception Some text. Some javadoc. + * @deprecated Some text. Some javadoc. + */ + String method(String str) throws Exception { + return "null"; + } + + /** + * Some text. + * + * @param str Some text. Some javadoc. + * @return Some text. + * @throws Exception Some text. Some javadoc. + */ + String method1(String str) throws Exception { + return "null"; + } + + /** + * Some text. + * + * @serialData Some javadoc. Some javadoc. + * @param str Some text. Some javadoc. + * @throws Exception Some text. + */ + void method2(String str) throws Exception {} + + /** + * Some text. + * + * @throws Exception Some text. + * @deprecated Some text. + */ + void method3() throws Exception {} + + /** + * Some text. + * + * @return Some text. + * @throws Exception Some text. + * @serialData Some javadoc. + */ + String method4() throws Exception { + return "null"; + } + + /** + * Some text. + * + * @param str Some text. + * @return Some text. + * @deprecated Some text. + */ + String method5(String str) { + return "null"; + } + + /** + * Some text. + * + * @param str Some text. + * @param number Some text. Some javadoc. + * @param bool Some text. Some javadoc. + * @return Some text. + * @throws Exception Some text. + * @deprecated Some text. + */ + String method6(String str, int number, boolean bool) throws Exception { + return "null"; + } + } + + InnerClassWithAnnotations anon = + new InnerClassWithAnnotations() { + /** + * Some text. + * + * @param str Some text. Some javadoc. + * @return Some text. + * @throws Exception Some text. + * @serialData Some javadoc. Some javadoc. + * @deprecated Some text. + */ + String method(String str) throws Exception { + return "null"; + } + + /** + * Some text. + * + * @param str Some text. Some javadoc. + * @return Some text. + * @throws Exception Some text. + */ + String method1(String str) throws Exception { + return "null"; + } + + /** + * Some text. + * + * @param str Some text. + * @throws Exception Some text. Some javadoc. + */ + void method2(String str) throws Exception {} + + /** + * Some text. + * + * @throws Exception Some text. + * @deprecated Some text. Some javadoc. + */ + void method3() throws Exception {} + + /** + * Some text. + * + * @return Some text. + * @throws Exception Some text. + */ + String method4() throws Exception { + return "null"; + } + + /** + * Some text. + * + * @param str Some text. + * @return Some text. + * @deprecated Some text. + */ + String method5(String str) { + return "null"; + } + + /** + * Some text. Some javadoc. + * + * @param str Some text. Some javadoc. + * @param number Some text. Some javadoc. + * @param bool Some text. + * @return Some text. + * @throws Exception Some text. Some javadoc. + * @deprecated Some text. + */ + String method6(String str, int number, boolean bool) throws Exception { + return "null"; + } + }; + + /** + * Some javadoc. + * + * @since Some javadoc. + * @version 1.0 + * @deprecated Some javadoc. Some javadoc. Some javadoc. + * @see Some javadoc. Some javadoc. + * @author max + */ + enum Foo3 {} + + /** + * Some javadoc. + * + * @version 1.0 + * @since Some javadoc. Some javadoc. + * @serialData Some javadoc. Some javadoc. + * @author max + */ + interface FooIn5 {} +} diff --git a/src/main/resources/google_checks.xml b/src/main/resources/google_checks.xml index 1141a088d4b..5e3b2b29e4e 100644 --- a/src/main/resources/google_checks.xml +++ b/src/main/resources/google_checks.xml @@ -358,7 +358,7 @@ + .//ANNOTATION/IDENT[contains(@text, 'Test')]]//*"/> diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index 01a49a257eb..e2fccedea9e 100644 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -10,6 +10,50 @@ +
+
30.08.2024
+

Bug fixes:

+
    +
  • + google_checks failing on 'MethodName' with @ParameterizedTest. + Author: Mauryan Kansara + #15556 +
  • +
+

Notes:

+
    +
  • + Failure in make_report of regression-report.yml does not make comment in PR. + Author: piyush kumar sadangi + #15579 +
  • +
  • + Handling the concurrency model in the new workflow. + Author: piyush kumar sadangi + #15573 +
  • +
  • + regression-report.yml workflow sending messages upon successful completition. + Author: piyush kumar sadangi + #15567 +
  • +
  • + create "InputFormattedXxxxxx" files for Indentation and other formatting Checks. + Author: Mauryan Kansara + #15340 +
  • +
  • + Fix the error of the new workflow running for every comment not matching pattern. + Author: piyush kumar sadangi + #15565 +
  • +
  • + Updating regression-report.yml to allow running regression for input java file. + Author: piyush kumar sadangi + #15518 +
  • +
+
25.08.2024

Breaking backward compatibility:

@@ -171,7 +215,8 @@ #15504
  • - Update NPathComplexity Check to Account for when expression as a Possible Execution Path. + Update NPathComplexity Check to Account for + when expression as a Possible Execution Path. Author: mahfouz72 #15445
  • @@ -208,7 +253,8 @@ #15029
  • - MissingSwitchDefault : False positive when `case null` in switch labeled statement group. + MissingSwitchDefault : False positive when `case null` + in switch labeled statement group. Author: mahfouz72 #15123
  • @@ -223,7 +269,8 @@ #14891
  • - Remove href from LineLength module property in google style config and update test cases. + Remove href from LineLength module property in google style config + and update test cases. Author: Mauryan Kansara #14955
  • @@ -245,7 +292,8 @@ Author: mahfouz72
  • - create "InputFormattedXxxxxx" files for Indentation and other formatting Checks. + create "InputFormattedXxxxxx" files for Indentation + and other formatting Checks. Author: Mauryan Kansara #15340
  • @@ -296,7 +344,8 @@ #4006
  • - Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: NoWhitespaceAfter. + Add Check Support for Java 21 Unnamed Variables & + Patterns Syntax: NoWhitespaceAfter. Author: mahfouz72 #15224
  • @@ -447,7 +496,8 @@ #15079
  • - Add Check Support for Java 21 Pattern Matching for Switch Syntax: UnnecessaryParentheses. + Add Check Support for Java 21 Pattern Matching for Switch Syntax: + UnnecessaryParentheses. Author: mahfouz72 #14972
  • @@ -505,7 +555,8 @@ #15261
  • - XDoc conversion from Javadoc do not relativize links and break previous document version. + XDoc conversion from Javadoc do not relativize links + and break previous document version. Author: Roman Ivanov #14875