From 745fe7864aa47423b418f15b1f7bbda141cf8538 Mon Sep 17 00:00:00 2001 From: Damian Szczepanik Date: Sun, 31 Dec 2023 00:06:38 +0100 Subject: [PATCH] Better support for JDK 11 (#100) --- .github/workflows/build.yml | 3 ++- Jenkinsfile | 9 ++++---- pom.xml | 23 ++++++++++--------- .../BuildHistoryManagerTest.java | 6 ++--- .../utils/DescriptorMocker.java | 2 +- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 096efc3b..bf4a610f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,6 +14,7 @@ jobs: build: strategy: matrix: + java: [ '11' ] os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ] runs-on: ${{ matrix.os }} @@ -23,7 +24,7 @@ jobs: - uses: actions/setup-java@v3 with: - java-version: 11 + java-version: ${{ matrix.java }} distribution: adopt - run: mvn --batch-mode verify diff --git a/Jenkinsfile b/Jenkinsfile index c432705b..92f89834 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,8 @@ +// `buildPlugin` step provided by: https://github.com/jenkins-infra/pipeline-library + buildPlugin( useContainerAgent: true, failFast: false, - configurations: [ - [platform: 'linux', jdk: 11], - [platform: 'windows', jdk: 11], -]) + platforms: ['linux', 'windows'], + jdkVersions: [11] +) diff --git a/pom.xml b/pom.xml index 64a1b073..262b2f09 100644 --- a/pom.xml +++ b/pom.xml @@ -1,16 +1,19 @@ - + 4.0.0 org.jenkins-ci.plugins plugin 4.75 + pl.damianszczepanik build-history-manager 1.7.2-SNAPSHOT hpi + @@ -23,6 +26,7 @@ + Build History Manager Jenkins plugin that allows to build complex rules to decide when and which builds should be removed from the @@ -33,7 +37,6 @@ 2.387.3 - 1.7.30 9.4 2.0.9 @@ -41,9 +44,6 @@ **/*IT.java - damianszczepanik_build-history-manager-plugin - damianszczepanik - https://sonarcloud.io @@ -53,7 +53,7 @@ HEAD - jenkins + Jenkins https://ci.jenkins.io/job/Plugins/job/build-history-manager-plugin/ @@ -93,8 +93,8 @@ maven-compiler-plugin 3.8.1 - 1.8 - 1.8 + 11 + 11 UTF-8 @@ -167,17 +167,18 @@ org.apache.maven.plugins maven-release-plugin - 2.5.3 + 3.0.1 - - + + org.jenkins-ci.plugins token-macro + org.jenkins-ci.plugins structs diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/BuildHistoryManagerTest.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/BuildHistoryManagerTest.java index ea5c140c..af1e2498 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/BuildHistoryManagerTest.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/BuildHistoryManagerTest.java @@ -18,7 +18,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import pl.damianszczepanik.jenkins.buildhistorymanager.model.ConditionBuilder; +import pl.damianszczepanik.jenkins.buildhistorymanager.model.ConditionBuilder.NegativeCondition; import pl.damianszczepanik.jenkins.buildhistorymanager.model.Rule; import pl.damianszczepanik.jenkins.buildhistorymanager.model.RuleBuilder; import pl.damianszczepanik.jenkins.buildhistorymanager.model.RuleConfiguration; @@ -72,9 +72,9 @@ public void getRules_ReturnsRules() { public void perform_InitializesRule() throws IOException, InterruptedException { // given - Rule rule = new Rule(Arrays.asList(new ConditionBuilder.NegativeCondition()), null); + Rule rule = new Rule(List.of(new NegativeCondition()), null); Deencapsulation.setField(rule, "matchedTimes", 1); - BuildHistoryManager discarder = new BuildHistoryManager(Arrays.asList(rule)); + BuildHistoryManager discarder = new BuildHistoryManager(List.of(rule)); Job job = JobBuilder.buildSampleJob(); // when diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/DescriptorMocker.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/DescriptorMocker.java index f91141b9..3d02ec3d 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/DescriptorMocker.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/DescriptorMocker.java @@ -17,7 +17,7 @@ public DescriptorMocker(Descriptor descriptor) { mockStatic(Jenkins.class); Jenkins jenkins = mock(Jenkins.class); when(Jenkins.get()).thenReturn(jenkins); // for new Jenkins - when(Jenkins.getInstance()).thenReturn(jenkins); // for old Jenkins + when(Jenkins.getInstanceOrNull()).thenReturn(jenkins); // for old Jenkins when(jenkins.getDescriptorOrDie(ArgumentMatchers.any())).thenReturn(descriptor); } }