From aca76fc8518734054a1660fd9bfa8405a0f0de06 Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sun, 30 Oct 2022 18:07:20 +0100 Subject: [PATCH 1/9] fix: check for modifier existence before refactoring --- .../analyzer/qodana/rules/UnnecessaryModifier.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/analyzer/qodana/rules/UnnecessaryModifier.java b/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/analyzer/qodana/rules/UnnecessaryModifier.java index 761178cbd..922fb11e2 100644 --- a/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/analyzer/qodana/rules/UnnecessaryModifier.java +++ b/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/analyzer/qodana/rules/UnnecessaryModifier.java @@ -43,6 +43,9 @@ public void refactor(ChangeListener listener, CtType type) { } for (CtElement match : PositionScanner.findLineOnly(type, result.position())) { if (match instanceof CtModifiable ctModifierHandler) { + if (!hasModifier(ctModifierHandler, modifier)) { + continue; + } var modifiers = new HashSet<>(ctModifierHandler.getModifiers()); modifiers.removeIf(v -> v.toString().equals(modifier.toLowerCase())); ctModifierHandler.setModifiers(modifiers); @@ -59,6 +62,11 @@ public void refactor(ChangeListener listener, CtType type) { } } + private boolean hasModifier(CtModifiable ctModifierHandler, String modifier) { + return ctModifierHandler.getModifiers().stream() + .anyMatch(v -> v.toString().equalsIgnoreCase(modifier)); + } + @Override public List getHandledBadSmells() { return List.of(UNNECESSARY_MODIFIER); From 258307c82f72be306739147cc2e9ca02be9da91d Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sun, 30 Oct 2022 18:07:56 +0100 Subject: [PATCH 2/9] up --- .../io/github/martinwitt/laughing_train/ChangelogPrinter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/ChangelogPrinter.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/ChangelogPrinter.java index 73f181918..859305098 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/ChangelogPrinter.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/ChangelogPrinter.java @@ -52,7 +52,7 @@ private String toYaml(AnalyzerResult analyzerResult) { public String printRepairedIssues(Collection changes) { StringBuilder sb = new StringBuilder(); sb.append("# Repairing Code Style Issues\n"); - sb.append(""); + sb.append("\n"); changes.stream().map(Change::getBadSmell).distinct().forEach(v -> sb.append( "## " + v.getName().asText() + "\n") .append(v.getDescription().asMarkdown()) From c3e07fd14386b142b0c39c9342eb4bb465d652c9 Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sun, 30 Oct 2022 19:13:36 +0100 Subject: [PATCH 3/9] pin hash --- ...yz.keksdose.spoon.code_solver.java-common-conventions.gradle | 2 +- code-transformation/build.gradle | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/buildSrc/src/main/groovy/xyz.keksdose.spoon.code_solver.java-common-conventions.gradle b/buildSrc/src/main/groovy/xyz.keksdose.spoon.code_solver.java-common-conventions.gradle index 0dd8a71c7..7703d429c 100644 --- a/buildSrc/src/main/groovy/xyz.keksdose.spoon.code_solver.java-common-conventions.gradle +++ b/buildSrc/src/main/groovy/xyz.keksdose.spoon.code_solver.java-common-conventions.gradle @@ -21,7 +21,7 @@ dependencies { // Use JUnit Jupiter for testing. testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1' implementation 'com.google.guava:guava:31.1-jre' - implementation 'fr.inria.gforge.spoon:spoon-core:+' + implementation 'fr.inria.gforge.spoon:spoon-core:10.2.0' implementation 'com.google.flogger:flogger:0.7.4' implementation 'com.google.flogger:flogger-system-backend:0.7.4' implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.4.4' diff --git a/code-transformation/build.gradle b/code-transformation/build.gradle index 79b812680..331532409 100644 --- a/code-transformation/build.gradle +++ b/code-transformation/build.gradle @@ -16,7 +16,6 @@ jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } dependencies { - // implementation 'fr.inria.gforge.spoon:spoon-core:10.0.1-beta-2' implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '6.3.0.202209071007-r' implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit.ssh.apache', version: '6.3.0.202209071007-r' testImplementation "com.google.truth:truth:1.1.3" From ff447592be9e0f9580c6574a9856265b7216a5c8 Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sun, 30 Oct 2022 19:21:30 +0100 Subject: [PATCH 4/9] pin more versions --- code-transformation/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code-transformation/build.gradle b/code-transformation/build.gradle index 331532409..d7c5677fa 100644 --- a/code-transformation/build.gradle +++ b/code-transformation/build.gradle @@ -19,9 +19,9 @@ dependencies { implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '6.3.0.202209071007-r' implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit.ssh.apache', version: '6.3.0.202209071007-r' testImplementation "com.google.truth:truth:1.1.3" - implementation "com.github.docker-java:docker-java-core:+" - implementation "com.github.docker-java:docker-java-transport-httpclient5:+" - implementation "com.contrastsecurity:java-sarif:+" + implementation 'com.github.docker-java:docker-java:3.2.13' + implementation 'com.github.docker-java:docker-java-transport-httpclient5:3.2.13' + implementation "com.contrastsecurity:java-sarif:2.0" testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.23.1' } From 80c794a9661372f3e7910e742e0a08056ec3425a Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sun, 30 Oct 2022 20:57:46 +0100 Subject: [PATCH 5/9] up --- .github/workflows/codeql-analysis.yml | 42 --------------------------- .github/workflows/test.yml | 25 ++++++++++++++++ 2 files changed, 25 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 2bdc10114..000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '17 15 * * 3' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: microsoft - - name: Setup Gradle - uses: gradle/gradle-build-action@v2 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - - run: | - gradle build - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..68d4ac17f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Unit Tests +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + - 'releases/*' + +jobs: + qodana: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: microsoft + - name: Run Tests + run: | + gradle test \ No newline at end of file From 45f290d10900901d3f77428761e84497580d3199 Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sun, 30 Oct 2022 21:01:17 +0100 Subject: [PATCH 6/9] up --- github-bot/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/github-bot/build.gradle b/github-bot/build.gradle index 98c8d74a9..eca2f092b 100644 --- a/github-bot/build.gradle +++ b/github-bot/build.gradle @@ -28,7 +28,6 @@ dependencies { implementation("io.quarkus:quarkus-oidc") implementation("io.quarkus:quarkus-keycloak-authorization") testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.23.1' - implementation 'io.vertx:vertx-junit5:+' } group 'io.github.martinwitt' From c32c6010f16d485cebfa6e7c7c1772278a3a950a Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sun, 30 Oct 2022 21:06:43 +0100 Subject: [PATCH 7/9] up --- .github/workflows/test.yml | 2 +- ...yz.keksdose.spoon.code_solver.java-common-conventions.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 68d4ac17f..6b6e7682a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ on: - 'releases/*' jobs: - qodana: + junit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/buildSrc/src/main/groovy/xyz.keksdose.spoon.code_solver.java-common-conventions.gradle b/buildSrc/src/main/groovy/xyz.keksdose.spoon.code_solver.java-common-conventions.gradle index 7703d429c..0dd8a71c7 100644 --- a/buildSrc/src/main/groovy/xyz.keksdose.spoon.code_solver.java-common-conventions.gradle +++ b/buildSrc/src/main/groovy/xyz.keksdose.spoon.code_solver.java-common-conventions.gradle @@ -21,7 +21,7 @@ dependencies { // Use JUnit Jupiter for testing. testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1' implementation 'com.google.guava:guava:31.1-jre' - implementation 'fr.inria.gforge.spoon:spoon-core:10.2.0' + implementation 'fr.inria.gforge.spoon:spoon-core:+' implementation 'com.google.flogger:flogger:0.7.4' implementation 'com.google.flogger:flogger-system-backend:0.7.4' implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.4.4' From 1b06da71a055ccfedddaca2ba2e27be876c4047c Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sun, 30 Oct 2022 21:17:40 +0100 Subject: [PATCH 8/9] up --- github-bot/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-bot/build.gradle b/github-bot/build.gradle index eca2f092b..d03298c95 100644 --- a/github-bot/build.gradle +++ b/github-bot/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id "io.quarkus" version "2.13.3.Final" + id "io.quarkus" version "3.0.0.Alpha1" id 'xyz.keksdose.spoon.code_solver.java-common-conventions' } From 2a63b4ce3397dfe772258b8e7a71913b6a2cf24a Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sun, 30 Oct 2022 23:18:54 +0100 Subject: [PATCH 9/9] up --- .github/workflows/codeql-analysis.yml | 42 +++++++++++++++++++++++++++ code-transformation/build.gradle | 6 ++-- github-bot/build.gradle | 2 +- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 000000000..2bdc10114 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,42 @@ +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '17 15 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'java' ] + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: microsoft + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + - run: | + gradle build + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/code-transformation/build.gradle b/code-transformation/build.gradle index d7c5677fa..331532409 100644 --- a/code-transformation/build.gradle +++ b/code-transformation/build.gradle @@ -19,9 +19,9 @@ dependencies { implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '6.3.0.202209071007-r' implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit.ssh.apache', version: '6.3.0.202209071007-r' testImplementation "com.google.truth:truth:1.1.3" - implementation 'com.github.docker-java:docker-java:3.2.13' - implementation 'com.github.docker-java:docker-java-transport-httpclient5:3.2.13' - implementation "com.contrastsecurity:java-sarif:2.0" + implementation "com.github.docker-java:docker-java-core:+" + implementation "com.github.docker-java:docker-java-transport-httpclient5:+" + implementation "com.contrastsecurity:java-sarif:+" testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.23.1' } diff --git a/github-bot/build.gradle b/github-bot/build.gradle index d03298c95..eca2f092b 100644 --- a/github-bot/build.gradle +++ b/github-bot/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id "io.quarkus" version "3.0.0.Alpha1" + id "io.quarkus" version "2.13.3.Final" id 'xyz.keksdose.spoon.code_solver.java-common-conventions' }