From b87e2ad581e723281282300ddcd686a1856d2769 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sat, 12 Jul 2025 15:46:04 -0700 Subject: [PATCH 1/4] chore: fixes code smells unused checked exceptions, deprecated methods --- .github/workflows/master-2.yml | 3 +- .github/workflows/master.yml | 3 +- .github/workflows/release.yml | 1 - .github/workflows/sonar.yml | 50 +++++++++++++++++++ .../service/validators/DateTimeValidator.java | 2 +- .../SwitcherBasicCriteriaResponseTest.java | 2 +- .../switcherapi/client/SwitcherBasicTest.java | 2 +- .../client/SwitcherConfigNativeTest.java | 2 +- .../SwitcherContextRemoteExecutorTest.java | 2 +- .../switcherapi/client/SwitcherFail1Test.java | 2 +- .../switcherapi/client/SwitcherFail2Test.java | 2 +- .../client/SwitcherForceResolveTest.java | 2 +- .../client/SwitcherSilentModeTest.java | 2 +- .../SwitcherSnapshotValidationFailTest.java | 2 +- .../SwitcherSnapshotValidationTest.java | 2 +- .../client/SwitcherThrottleTest.java | 2 +- .../client/SwitcherValidateTest.java | 2 +- .../client/remote/ClientRemoteTest.java | 2 +- .../client/remote/ClientWSTest.java | 2 +- 19 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/sonar.yml diff --git a/.github/workflows/master-2.yml b/.github/workflows/master-2.yml index dd38f92f..7fc39a5c 100644 --- a/.github/workflows/master-2.yml +++ b/.github/workflows/master-2.yml @@ -10,7 +10,7 @@ jobs: build-scan: name: SonarCloud Scan runs-on: ubuntu-latest - if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" + if: secrets.SONAR_TOKEN != '' steps: - uses: actions/checkout@v4 @@ -35,7 +35,6 @@ jobs: java: ['11', '17', '21'] os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} - if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 926b22ec..e4e613e6 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -10,7 +10,7 @@ jobs: build-scan: name: SonarCloud Scan runs-on: ubuntu-latest - if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" + if: secrets.SONAR_TOKEN != '' steps: - uses: actions/checkout@v4 @@ -35,7 +35,6 @@ jobs: java: ['8', '11', '17', '21'] os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} - if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7a892d8e..0ee87e7d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,6 @@ jobs: java: ['11', '17', '21'] os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} - if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml new file mode 100644 index 00000000..fda90c14 --- /dev/null +++ b/.github/workflows/sonar.yml @@ -0,0 +1,50 @@ +name: Manual SonarCloud Analysis + +on: + workflow_dispatch: + inputs: + pr_id: + description: 'Pull Request ID to analyze' + required: true + type: string + +jobs: + sonar-analysis: + name: SonarCloud Analysis for PR + runs-on: ubuntu-latest + if: secrets.SONAR_TOKEN != '' + + steps: + - name: Get PR details + id: pr + uses: actions/github-script@v7 + with: + script: | + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: ${{ inputs.pr_id }} + }); + core.setOutput('head_ref', pr.data.head.ref); + core.setOutput('base_ref', pr.data.base.ref); + core.setOutput('head_sha', pr.data.head.sha); + + - uses: actions/checkout@v4 + with: + ref: ${{ steps.pr.outputs.head_sha }} + fetch-depth: 0 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'temurin' + cache: maven + + - name: Build/Test & SonarCloud Scan + run: | + mvn -B clean verify -Pcoverage,sonar \ + -Dsonar.token=${{ secrets.SONAR_TOKEN }} \ + -Dsonar.pullrequest.key=${{ inputs.pr_id }} \ + -Dsonar.pullrequest.branch=${{ steps.pr.outputs.head_ref }} \ + -Dsonar.pullrequest.base=${{ steps.pr.outputs.base_ref }} \ No newline at end of file diff --git a/src/main/java/com/github/switcherapi/client/service/validators/DateTimeValidator.java b/src/main/java/com/github/switcherapi/client/service/validators/DateTimeValidator.java index 613f40b0..4c9af227 100644 --- a/src/main/java/com/github/switcherapi/client/service/validators/DateTimeValidator.java +++ b/src/main/java/com/github/switcherapi/client/service/validators/DateTimeValidator.java @@ -19,7 +19,7 @@ public abstract class DateTimeValidator extends Validator { protected String getFullDate(final String date) { SwitcherUtils.debug(logger, LOG_DATE, date); - final String time = RegExUtils.removePattern(date, FULL_DATE_REGEX).trim(); + final String time = RegExUtils.removePattern((CharSequence) date, FULL_DATE_REGEX).trim(); return getFullTime(date, time); } diff --git a/src/test/java/com/github/switcherapi/client/SwitcherBasicCriteriaResponseTest.java b/src/test/java/com/github/switcherapi/client/SwitcherBasicCriteriaResponseTest.java index 875ceafe..3b0dd791 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherBasicCriteriaResponseTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherBasicCriteriaResponseTest.java @@ -37,7 +37,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); } diff --git a/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java b/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java index 5a57c12f..e17fe72b 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java @@ -35,7 +35,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); } diff --git a/src/test/java/com/github/switcherapi/client/SwitcherConfigNativeTest.java b/src/test/java/com/github/switcherapi/client/SwitcherConfigNativeTest.java index aa05535a..3d80e6ba 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherConfigNativeTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherConfigNativeTest.java @@ -20,7 +20,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); } diff --git a/src/test/java/com/github/switcherapi/client/SwitcherContextRemoteExecutorTest.java b/src/test/java/com/github/switcherapi/client/SwitcherContextRemoteExecutorTest.java index 0763c8b0..681414d9 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherContextRemoteExecutorTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherContextRemoteExecutorTest.java @@ -22,7 +22,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); } diff --git a/src/test/java/com/github/switcherapi/client/SwitcherFail1Test.java b/src/test/java/com/github/switcherapi/client/SwitcherFail1Test.java index 4deabe53..ac20d9b8 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherFail1Test.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherFail1Test.java @@ -28,7 +28,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); //clean generated outputs diff --git a/src/test/java/com/github/switcherapi/client/SwitcherFail2Test.java b/src/test/java/com/github/switcherapi/client/SwitcherFail2Test.java index d9cce345..1c10e56c 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherFail2Test.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherFail2Test.java @@ -28,7 +28,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); } diff --git a/src/test/java/com/github/switcherapi/client/SwitcherForceResolveTest.java b/src/test/java/com/github/switcherapi/client/SwitcherForceResolveTest.java index 7dfb2f13..ca5907bf 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherForceResolveTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherForceResolveTest.java @@ -35,7 +35,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); } diff --git a/src/test/java/com/github/switcherapi/client/SwitcherSilentModeTest.java b/src/test/java/com/github/switcherapi/client/SwitcherSilentModeTest.java index 39c1ae7e..930956fb 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherSilentModeTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherSilentModeTest.java @@ -29,7 +29,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); } diff --git a/src/test/java/com/github/switcherapi/client/SwitcherSnapshotValidationFailTest.java b/src/test/java/com/github/switcherapi/client/SwitcherSnapshotValidationFailTest.java index 7a75148c..eeb6a45f 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherSnapshotValidationFailTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherSnapshotValidationFailTest.java @@ -31,7 +31,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); //clean generated outputs diff --git a/src/test/java/com/github/switcherapi/client/SwitcherSnapshotValidationTest.java b/src/test/java/com/github/switcherapi/client/SwitcherSnapshotValidationTest.java index 01014688..e86a6bdc 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherSnapshotValidationTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherSnapshotValidationTest.java @@ -28,7 +28,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); //clean generated outputs diff --git a/src/test/java/com/github/switcherapi/client/SwitcherThrottleTest.java b/src/test/java/com/github/switcherapi/client/SwitcherThrottleTest.java index 19aca2e5..04da78cc 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherThrottleTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherThrottleTest.java @@ -26,7 +26,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); } diff --git a/src/test/java/com/github/switcherapi/client/SwitcherValidateTest.java b/src/test/java/com/github/switcherapi/client/SwitcherValidateTest.java index c5910c58..9e1d648b 100644 --- a/src/test/java/com/github/switcherapi/client/SwitcherValidateTest.java +++ b/src/test/java/com/github/switcherapi/client/SwitcherValidateTest.java @@ -27,7 +27,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); //clean generated outputs diff --git a/src/test/java/com/github/switcherapi/client/remote/ClientRemoteTest.java b/src/test/java/com/github/switcherapi/client/remote/ClientRemoteTest.java index 66bad3eb..f7e15df0 100644 --- a/src/test/java/com/github/switcherapi/client/remote/ClientRemoteTest.java +++ b/src/test/java/com/github/switcherapi/client/remote/ClientRemoteTest.java @@ -50,7 +50,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); executorService.shutdown(); } diff --git a/src/test/java/com/github/switcherapi/client/remote/ClientWSTest.java b/src/test/java/com/github/switcherapi/client/remote/ClientWSTest.java index 853b2a61..58707f9f 100644 --- a/src/test/java/com/github/switcherapi/client/remote/ClientWSTest.java +++ b/src/test/java/com/github/switcherapi/client/remote/ClientWSTest.java @@ -32,7 +32,7 @@ static void setup() throws IOException { } @AfterAll - static void tearDown() throws IOException { + static void tearDown() { MockWebServerHelper.tearDownMockServer(); executorService.shutdown(); } From 1987fb80effe321f6b5dbc3634dfeefd6bb2e3ab Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sat, 12 Jul 2025 15:47:55 -0700 Subject: [PATCH 2/4] ci: fixes secret check --- .github/workflows/master-2.yml | 2 +- .github/workflows/master.yml | 2 +- .github/workflows/sonar.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/master-2.yml b/.github/workflows/master-2.yml index 7fc39a5c..c29ea91a 100644 --- a/.github/workflows/master-2.yml +++ b/.github/workflows/master-2.yml @@ -10,7 +10,7 @@ jobs: build-scan: name: SonarCloud Scan runs-on: ubuntu-latest - if: secrets.SONAR_TOKEN != '' + if: ${{ secrets.SONAR_TOKEN != '' }} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index e4e613e6..b64f15a8 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -10,7 +10,7 @@ jobs: build-scan: name: SonarCloud Scan runs-on: ubuntu-latest - if: secrets.SONAR_TOKEN != '' + if: ${{ secrets.SONAR_TOKEN != '' }} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index fda90c14..777913a1 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -12,7 +12,7 @@ jobs: sonar-analysis: name: SonarCloud Analysis for PR runs-on: ubuntu-latest - if: secrets.SONAR_TOKEN != '' + if: ${{ secrets.SONAR_TOKEN != '' }} steps: - name: Get PR details From 372a3c453ea1ae4fc17109fc4caaf2c6ab00eff4 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sat, 12 Jul 2025 15:51:09 -0700 Subject: [PATCH 3/4] ci: moved secret check to step --- .github/workflows/master-2.yml | 2 +- .github/workflows/master.yml | 2 +- .github/workflows/sonar.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/master-2.yml b/.github/workflows/master-2.yml index c29ea91a..1b7c2169 100644 --- a/.github/workflows/master-2.yml +++ b/.github/workflows/master-2.yml @@ -10,7 +10,6 @@ jobs: build-scan: name: SonarCloud Scan runs-on: ubuntu-latest - if: ${{ secrets.SONAR_TOKEN != '' }} steps: - uses: actions/checkout@v4 @@ -25,6 +24,7 @@ jobs: cache: maven - name: Build/Test & SonarCloud Scan + if: ${{ secrets.SONAR_TOKEN != '' }} run: mvn -B clean verify -Pcoverage,sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }} build-test: diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index b64f15a8..37f9b5d3 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -10,7 +10,6 @@ jobs: build-scan: name: SonarCloud Scan runs-on: ubuntu-latest - if: ${{ secrets.SONAR_TOKEN != '' }} steps: - uses: actions/checkout@v4 @@ -25,6 +24,7 @@ jobs: cache: maven - name: Build/Test & SonarCloud Scan + if: ${{ secrets.SONAR_TOKEN != '' }} run: mvn -B clean verify -Pcoverage,sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }} build-test: diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 777913a1..f4e2570a 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -12,7 +12,6 @@ jobs: sonar-analysis: name: SonarCloud Analysis for PR runs-on: ubuntu-latest - if: ${{ secrets.SONAR_TOKEN != '' }} steps: - name: Get PR details @@ -42,6 +41,7 @@ jobs: cache: maven - name: Build/Test & SonarCloud Scan + if: ${{ secrets.SONAR_TOKEN != '' }} run: | mvn -B clean verify -Pcoverage,sonar \ -Dsonar.token=${{ secrets.SONAR_TOKEN }} \ From 31ae5cd7934a489ebdf17cfd8bf5f0276a0c497c Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sat, 12 Jul 2025 15:52:33 -0700 Subject: [PATCH 4/4] ci: fix secret check --- .github/workflows/master-2.yml | 4 +++- .github/workflows/master.yml | 4 +++- .github/workflows/sonar.yml | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/master-2.yml b/.github/workflows/master-2.yml index 1b7c2169..b94ab7f3 100644 --- a/.github/workflows/master-2.yml +++ b/.github/workflows/master-2.yml @@ -24,7 +24,9 @@ jobs: cache: maven - name: Build/Test & SonarCloud Scan - if: ${{ secrets.SONAR_TOKEN != '' }} + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + if: env.SONAR_TOKEN != '' run: mvn -B clean verify -Pcoverage,sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }} build-test: diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 37f9b5d3..c8000c74 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -24,7 +24,9 @@ jobs: cache: maven - name: Build/Test & SonarCloud Scan - if: ${{ secrets.SONAR_TOKEN != '' }} + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + if: env.SONAR_TOKEN != '' run: mvn -B clean verify -Pcoverage,sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }} build-test: diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index f4e2570a..db54d6ec 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -41,7 +41,9 @@ jobs: cache: maven - name: Build/Test & SonarCloud Scan - if: ${{ secrets.SONAR_TOKEN != '' }} + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + if: env.SONAR_TOKEN != '' run: | mvn -B clean verify -Pcoverage,sonar \ -Dsonar.token=${{ secrets.SONAR_TOKEN }} \