From 319088f33cc45b36c9b642227a64b51026c05a4b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 25 Aug 2024 13:54:02 +0000 Subject: [PATCH 01/21] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cd6437626da..e6b179ed3d8 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.puppycrawl.tools checkstyle - 10.18.0 + 10.18.1-SNAPSHOT jar checkstyle From 4c4be2e51e5adc677027fe10cad55307feb23e41 Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Sun, 25 Aug 2024 07:10:07 -0700 Subject: [PATCH 02/21] minor: wrap long lines after release in releasenotes --- src/xdocs/releasenotes.xml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index 01a49a257eb..da18d8d3f5c 100644 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -171,7 +171,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 +209,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 +225,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 +248,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 +300,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 +452,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 +511,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
  • From 28c50973f23158bad3e8cc2cef1b36320af84952 Mon Sep 17 00:00:00 2001 From: Mauryan Kansara Date: Fri, 23 Aug 2024 17:30:51 +0530 Subject: [PATCH 03/21] Issue #15340: created InputFormatted file for section 7.1.3 Block Tags --- .../rule713atclauses/BlockTagsTest.java | 5 + ...ttedJavaDocTagContinuationIndentation.java | 297 ++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100644 src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule713atclauses/InputFormattedJavaDocTagContinuationIndentation.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/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 {} +} From 7a1a47fc9796a91a91d2b91401975a70b8ef6377 Mon Sep 17 00:00:00 2001 From: piyush kumar sadangi Date: Sun, 18 Aug 2024 05:51:06 +0530 Subject: [PATCH 04/21] Issue #15518: Update the new workflow to add regression testing for input java files --- .ci/diff-report.sh | 2 +- .github/workflows/regression-report.yml | 409 ++++++++++++++++++--- config/jsoref-spellchecker/whitelist.words | 1 + 3 files changed, 362 insertions(+), 50 deletions(-) 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..0682514800d 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: @@ -33,8 +42,17 @@ 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,263 @@ 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@v3 + 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: + download_files_failed: ${{ steps.download_files.outputs.failed }} + 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 +424,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 +476,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 +497,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 +523,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 +557,8 @@ jobs: # should be always last step send_message: runs-on: ubuntu-latest - needs: [ check_pr_status, parse_comment, make_report ] - if: failure() || success() + needs: [ check_pr_status, parse_comment, download_configs, make_report ] + if: always() steps: - name: Checkout repository uses: actions/checkout@v4 @@ -255,7 +566,7 @@ jobs: - name: Get message env: MSG: ${{ needs.make_report.outputs.message }} - DOWNLOAD_FAILED: ${{ needs.make_report.outputs.download_files_failed }} + DOWNLOAD_FAILED: ${{ needs.download_configs.outputs.download_files_failed }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | mkdir -p .ci-temp 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 From 2ed46092c2f300f9ffff4e353661ebe638f4701a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:57:44 +0000 Subject: [PATCH 05/21] dependency: bump org.apache.maven.plugins:maven-surefire-report-plugin Bumps [org.apache.maven.plugins:maven-surefire-report-plugin](https://github.com/apache/maven-surefire) from 3.4.0 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.4.0...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-report-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e6b179ed3d8..ec5d60821cb 100644 --- a/pom.xml +++ b/pom.xml @@ -1943,7 +1943,7 @@ org.apache.maven.plugins maven-surefire-report-plugin - 3.4.0 + 3.5.0 From dcd4fb7eb3db9df940c91a629b10b728ce3c87e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:57:54 +0000 Subject: [PATCH 06/21] dependency: bump org.apache.maven.plugins:maven-failsafe-plugin Bumps [org.apache.maven.plugins:maven-failsafe-plugin](https://github.com/apache/maven-surefire) from 3.4.0 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.4.0...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-failsafe-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ec5d60821cb..fe188374b80 100644 --- a/pom.xml +++ b/pom.xml @@ -1514,7 +1514,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.4.0 + 3.5.0 com/google/**/*.java From 1d1eb18df8dcdf2709bd3dc7d5c4dd93d72e59f4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:57:59 +0000 Subject: [PATCH 07/21] dependency: bump org.apache.maven.plugins:maven-javadoc-plugin Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.8.0 to 3.10.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.8.0...maven-javadoc-plugin-3.10.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fe188374b80..2b4846cccc7 100644 --- a/pom.xml +++ b/pom.xml @@ -535,7 +535,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.8.0 + 3.10.0 From 8d6f485190c2a32a71337d34314dfe6d9daad64b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:58:35 +0000 Subject: [PATCH 08/21] dependency: bump org.apache.maven.plugins:maven-surefire-plugin Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.4.0 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.4.0...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2b4846cccc7..a259497997f 100644 --- a/pom.xml +++ b/pom.xml @@ -1541,7 +1541,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 -Dfile.encoding=UTF-8 ${surefire.options} From 7f35c358302b4dee7503c623f9d4f31f2fe2d346 Mon Sep 17 00:00:00 2001 From: piyush kumar sadangi Date: Wed, 28 Aug 2024 06:34:05 +0530 Subject: [PATCH 09/21] Issue #15565: Fix the error of the new workflow. --- .github/workflows/regression-report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/regression-report.yml b/.github/workflows/regression-report.yml index 0682514800d..b528b3777ca 100644 --- a/.github/workflows/regression-report.yml +++ b/.github/workflows/regression-report.yml @@ -558,7 +558,7 @@ jobs: send_message: runs-on: ubuntu-latest needs: [ check_pr_status, parse_comment, download_configs, make_report ] - if: always() + if: failure() || success() steps: - name: Checkout repository uses: actions/checkout@v4 From b3847a01dd27183d277cc5ac07f4ff2fb1555d2f Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Tue, 27 Aug 2024 18:34:47 -0700 Subject: [PATCH 10/21] minor: Update README.md to remove matrix chat --- README.md | 2 -- 1 file changed, 2 deletions(-) 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/). From 360cab650aa808bb35d1aee89993579f99b134d1 Mon Sep 17 00:00:00 2001 From: Mauryan Kansara Date: Mon, 26 Aug 2024 23:26:04 +0530 Subject: [PATCH 11/21] Issue #15340: created InputFormatted files for section 3.3.3 Ordering And Spacing --- .../OrderingAndSpacingTest.java | 40 +++++++++ .../InputFormattedOrderingAndSpacing1.java | 38 +++++++++ .../InputFormattedOrderingAndSpacing2.java | 67 +++++++++++++++ .../InputFormattedOrderingAndSpacing3.java | 83 +++++++++++++++++++ .../InputFormattedOrderingAndSpacing4.java | 66 +++++++++++++++ .../InputFormattedOrderingAndSpacing5.java | 66 +++++++++++++++ ...tFormattedOrderingAndSpacingNoImports.java | 4 + ...InputFormattedOrderingAndSpacingValid.java | 51 ++++++++++++ ...nputFormattedOrderingAndSpacingValid2.java | 53 ++++++++++++ .../InputOrderingAndSpacing1.java | 24 +++++- .../InputOrderingAndSpacing2.java | 50 +++++++++++ .../InputOrderingAndSpacing3.java | 64 ++++++++++++++ .../InputOrderingAndSpacing4.java | 51 ++++++++++++ .../InputOrderingAndSpacing5.java | 51 ++++++++++++ .../InputOrderingAndSpacingValid.java | 30 +++++++ .../InputOrderingAndSpacingValid2.java | 34 ++++++++ 16 files changed, 771 insertions(+), 1 deletion(-) create mode 100644 src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing1.java create mode 100644 src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing2.java create mode 100644 src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing3.java create mode 100644 src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing4.java create mode 100644 src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacing5.java create mode 100644 src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingNoImports.java create mode 100644 src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingValid.java create mode 100644 src/it/resources/com/google/checkstyle/test/chapter3filestructure/rule333orderingandspacing/InputFormattedOrderingAndSpacingValid2.java 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/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); + } } From 9dac1f2dda7f7e52fa4698928eae17dc491e4f82 Mon Sep 17 00:00:00 2001 From: Mauryan Kansara Date: Tue, 27 Aug 2024 23:22:52 +0530 Subject: [PATCH 12/21] Issue #15556: updated MethodName module in google_checks.xml to ignore methods with Test annotations --- .../rule523methodnames/InputMethodName.java | 77 +++++++++++++++++++ src/main/resources/google_checks.xml | 2 +- 2 files changed, 78 insertions(+), 1 deletion(-) 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/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')]]//*"/> From 2137cfd2201ad99f04e8f3537f6fb8da63f31b26 Mon Sep 17 00:00:00 2001 From: piyush kumar sadangi Date: Wed, 28 Aug 2024 22:34:44 +0530 Subject: [PATCH 13/21] Issue #15567: Fix the new workflow and Optimise it --- .github/workflows/regression-report.yml | 47 ++++++++++++++++++------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/.github/workflows/regression-report.yml b/.github/workflows/regression-report.yml index b528b3777ca..6cc61eca5b5 100644 --- a/.github/workflows/regression-report.yml +++ b/.github/workflows/regression-report.yml @@ -349,7 +349,6 @@ jobs: || needs.handle_configs_in_pr_description.result == 'success') runs-on: ubuntu-latest outputs: - download_files_failed: ${{ steps.download_files.outputs.failed }} branch: ${{ steps.set_branch.outputs.ref }} commit_sha: ${{ steps.set_branch.outputs.commit_sha }} steps: @@ -557,8 +556,14 @@ jobs: # should be always last step send_message: runs-on: ubuntu-latest - needs: [ check_pr_status, parse_comment, download_configs, make_report ] - if: failure() || success() + needs: [ + handle_generated_config_bundle, + download_configs, + make_report ] + if: always() + && (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 @@ -566,29 +571,45 @@ jobs: - name: Get message env: MSG: ${{ needs.make_report.outputs.message }} - DOWNLOAD_FAILED: ${{ needs.download_configs.outputs.download_files_failed }} + DOWNLOAD_RESULT: ${{ needs.download_configs.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 [ -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 From 72bd71797fc15bbfe4e45972493642d5d9e0149b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 21:35:29 +0000 Subject: [PATCH 14/21] dependency: bump com.google.errorprone:error_prone_core Bumps [com.google.errorprone:error_prone_core](https://github.com/google/error-prone) from 2.30.0 to 2.31.0. - [Release notes](https://github.com/google/error-prone/releases) - [Commits](https://github.com/google/error-prone/compare/v2.30.0...v2.31.0) --- updated-dependencies: - dependency-name: com.google.errorprone:error_prone_core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a259497997f..e5881dc2b7c 100644 --- a/pom.xml +++ b/pom.xml @@ -235,7 +235,7 @@ 3.7 1.2.0 3.46.0 - 2.30.0 + 2.31.0 0.15.0 1.12.0 From ab89486c6733bc61ff9d73e47164a782d1b707f1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 21:35:37 +0000 Subject: [PATCH 15/21] dependency: bump org.pitest:pitest-maven from 1.16.1 to 1.16.2 Bumps [org.pitest:pitest-maven](https://github.com/hcoles/pitest) from 1.16.1 to 1.16.2. - [Release notes](https://github.com/hcoles/pitest/releases) - [Commits](https://github.com/hcoles/pitest/compare/1.16.1...1.16.2) --- updated-dependencies: - dependency-name: org.pitest:pitest-maven dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e5881dc2b7c..11a203b267a 100644 --- a/pom.xml +++ b/pom.xml @@ -223,7 +223,7 @@ 3.13.0 11 ${java.version} - 1.16.1 + 1.16.2 10 HTML,XML 50000 From e2c65c14881c088807fcee6efb254e3cf984c3f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 21:17:40 +0000 Subject: [PATCH 16/21] dependency: bump actions/setup-java from 3 to 4 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 3 to 4. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/regression-report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/regression-report.yml b/.github/workflows/regression-report.yml index 6cc61eca5b5..81a1c97ce7d 100644 --- a/.github/workflows/regression-report.yml +++ b/.github/workflows/regression-report.yml @@ -247,7 +247,7 @@ jobs: fileName: "extractor-all-${{env.EXTRACTOR_VERSION}}.jar" - name: Set up Java 21 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '21' From 3bb8d52c9884ec50e7195fdbe9dda6660c04aa40 Mon Sep 17 00:00:00 2001 From: piyush kumar sadangi Date: Thu, 29 Aug 2024 04:05:02 +0530 Subject: [PATCH 17/21] Issue #15573: Handling the concurrency model in the new workflow --- .github/workflows/regression-report.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/regression-report.yml b/.github/workflows/regression-report.yml index 81a1c97ce7d..af5fb27abe2 100644 --- a/.github/workflows/regression-report.yml +++ b/.github/workflows/regression-report.yml @@ -35,7 +35,7 @@ permissions: pull-requests: write concurrency: - group: ${{ github.workflow }}-${{ github.event.issue.number }} + group: ${{ github.run_id }} cancel-in-progress: true jobs: @@ -582,7 +582,7 @@ jobs: 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 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." From 6c1f0b4c89f528d364178d2dcc9bb08e05ed601c Mon Sep 17 00:00:00 2001 From: piyush kumar sadangi Date: Fri, 30 Aug 2024 01:45:29 +0530 Subject: [PATCH 18/21] Issue #15579: Issue of failure of make_report in new workflow does not make comment in PR --- .github/workflows/regression-report.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/regression-report.yml b/.github/workflows/regression-report.yml index af5fb27abe2..bd312c8076c 100644 --- a/.github/workflows/regression-report.yml +++ b/.github/workflows/regression-report.yml @@ -561,7 +561,8 @@ jobs: download_configs, make_report ] if: always() - && (needs.make_report.outputs.message != '' + && (needs.make_report.result == 'failure' + || needs.make_report.outputs.message != '' || needs.download_configs.result == 'failure' || needs.handle_generated_config_bundle.result == 'failure') steps: @@ -572,6 +573,7 @@ jobs: env: MSG: ${{ needs.make_report.outputs.message }} 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: | @@ -595,6 +597,11 @@ jobs: 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/${{github.run_id}}/jobs" curl --fail-with-body -X GET "${API_LINK}" \ From 33e7f9009aa22e7198cdf295622b7ad8a0b0e6c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:53:47 +0000 Subject: [PATCH 19/21] dependency: bump org.apache.ant:ant from 1.10.14 to 1.10.15 Bumps org.apache.ant:ant from 1.10.14 to 1.10.15. --- updated-dependencies: - dependency-name: org.apache.ant:ant dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 11a203b267a..35e0cc620e5 100644 --- a/pom.xml +++ b/pom.xml @@ -302,7 +302,7 @@ org.apache.ant ant - 1.10.14 + 1.10.15 provided From 20a7ac15d73331293bf1aa39143bb794427e77db Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 30 Aug 2024 12:56:58 +0000 Subject: [PATCH 20/21] doc: release notes for 10.18.1 --- src/xdocs/releasenotes.xml | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index da18d8d3f5c..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:

    From fa2f4b8a62780fc3c09669ccfa894c087d5cdcaf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 30 Aug 2024 12:58:32 +0000 Subject: [PATCH 21/21] [maven-release-plugin] prepare release checkstyle-10.18.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 35e0cc620e5..09630b4c958 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.puppycrawl.tools checkstyle - 10.18.1-SNAPSHOT + 10.18.1 jar checkstyle