From a07d7d330d1ae3e1bc4c420c68f215bf86fc7adb Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 22 Jan 2025 12:30:12 +0100 Subject: [PATCH 1/8] Revert jth to same version as before, but with web-fragment backport --- src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java b/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java index 6ec4608a..891f6927 100644 --- a/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java +++ b/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java @@ -28,7 +28,7 @@ public String getProperty() { @Override public String getMinimumVersion() { - return "2384.va_d3a_58a_4b_df5"; + return "2244.2246.v8e44578e0f42"; } @Override From 7f534d48d2e9aac1714a73dc8f8379584f2b783a Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 22 Jan 2025 14:11:14 +0100 Subject: [PATCH 2/8] Introduce a new hook for newer Jenkins core --- .../jenkins/tools/test/hook/Jetty12Hook.java | 12 +++- .../tools/test/hook/PropertyVersionHook.java | 8 ++- .../tools/test/hook/WarFragmentHook.java | 68 +++++++++++++++++++ 3 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java diff --git a/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java b/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java index 891f6927..15b17726 100644 --- a/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java +++ b/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java @@ -21,6 +21,8 @@ @MetaInfServices(PluginCompatTesterHookBeforeExecution.class) public class Jetty12Hook extends PropertyVersionHook { + public static final String JTH_VERSION = "2244.2246.v8e44578e0f42"; + @Override public String getProperty() { return "jenkins-test-harness.version"; @@ -28,19 +30,23 @@ public String getProperty() { @Override public String getMinimumVersion() { - return "2244.2246.v8e44578e0f42"; + return JTH_VERSION; } @Override public boolean check(@NonNull BeforeExecutionContext context) { + return staticCheck(context, getProperty(), getMinimumVersion()); + } + + static boolean staticCheck(BeforeExecutionContext context, String property, String minimumVersion) { VersionNumber winstoneVersion = getWinstoneVersion(context.getConfig().getWar()); if (winstoneVersion.getDigitAt(0) < 7) { return false; } - return super.check(context); + return PropertyVersionHook.check(context, property, minimumVersion); } - private VersionNumber getWinstoneVersion(File war) { + static VersionNumber getWinstoneVersion(File war) { try (JarFile jarFile = new JarFile(war)) { ZipEntry zipEntry = jarFile.getEntry("executable/winstone.jar"); if (zipEntry == null) { diff --git a/src/main/java/org/jenkins/tools/test/hook/PropertyVersionHook.java b/src/main/java/org/jenkins/tools/test/hook/PropertyVersionHook.java index 3ac6fc31..cede7ae4 100644 --- a/src/main/java/org/jenkins/tools/test/hook/PropertyVersionHook.java +++ b/src/main/java/org/jenkins/tools/test/hook/PropertyVersionHook.java @@ -26,12 +26,16 @@ public abstract class PropertyVersionHook extends PluginCompatTesterHookBeforeEx @Override public boolean check(@NonNull BeforeExecutionContext context) { + return check(context, getProperty(), getMinimumVersion()); + } + + static boolean check(BeforeExecutionContext context, String property, String minimumVersion) { MavenRunner runner = new ExternalMavenRunner(context.getConfig()); ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator( context.getCloneDirectory(), context.getPlugin().getModule(), runner); try { - String version = expressionEvaluator.evaluateString(getProperty()); - return new VersionNumber(version).isOlderThan(new VersionNumber(getMinimumVersion())); + String version = expressionEvaluator.evaluateString(property); + return new VersionNumber(version).isOlderThan(new VersionNumber(minimumVersion)); } catch (PomExecutionException e) { return false; } diff --git a/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java b/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java new file mode 100644 index 00000000..b68fce39 --- /dev/null +++ b/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java @@ -0,0 +1,68 @@ +package org.jenkins.tools.test.hook; + +import edu.umd.cs.findbugs.annotations.NonNull; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.JarInputStream; +import org.jenkins.tools.test.model.hook.BeforeExecutionContext; +import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution; +import org.kohsuke.MetaInfServices; + +@MetaInfServices(PluginCompatTesterHookBeforeExecution.class) +public class WarFragmentHook extends PropertyVersionHook { + @Override + public String getProperty() { + return "jenkins-test-harness.version"; + } + + @Override + public String getMinimumVersion() { + return "2384.va_d3a_58a_4b_df5"; + } + + @Override + public boolean check(@NonNull BeforeExecutionContext context) { + if (Jetty12Hook.staticCheck(context, getProperty(), Jetty12Hook.JTH_VERSION)) { + return false; + } + // We only want this hook to be enabled if the Jetty 12 hook is not enabled at the same time + File war = context.getConfig().getWar(); + try (JarFile jarFile = new JarFile(war)) { + var jenkinsCoreEntry = getJenkinsCoreEntry(jarFile); + if (jenkinsCoreEntry == null) { + throw new IllegalArgumentException("Failed to find jenkins-core jar in " + war); + } + try (var is = jarFile.getInputStream(jenkinsCoreEntry); + var bis = new BufferedInputStream(is); + var jis = new JarInputStream(bis)) { + return hasWebFragment(jis); + } + } catch (IOException e) { + throw new UncheckedIOException("Failed to determine whether " + war + " uses web fragments", e); + } + } + + private static boolean hasWebFragment(JarInputStream jis) throws IOException { + for (var entry = jis.getNextEntry(); entry != null; entry = jis.getNextEntry()) { + if ("META-INF/web-fragment.xml".equals(entry.getName())) { + return true; + } + } + return false; + } + + private JarEntry getJenkinsCoreEntry(JarFile jarFile) { + for (var entries = jarFile.entries(); entries.hasMoreElements();) { + JarEntry entry = entries.nextElement(); + if (entry.getName().startsWith("WEB-INF/lib/jenkins-core-")) { + return entry; + } + } + return null; + } + +} From 54eda518f5cc67d724f3aee2bc32c03ad8383f66 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 22 Jan 2025 16:39:34 +0100 Subject: [PATCH 3/8] Update to jth release versions --- src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java | 2 +- .../java/org/jenkins/tools/test/hook/WarFragmentHook.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java b/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java index 15b17726..c1d5f93a 100644 --- a/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java +++ b/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java @@ -21,7 +21,7 @@ @MetaInfServices(PluginCompatTesterHookBeforeExecution.class) public class Jetty12Hook extends PropertyVersionHook { - public static final String JTH_VERSION = "2244.2246.v8e44578e0f42"; + public static final String JTH_VERSION = "2244.2247.ve6b_a_8191b_95f"; @Override public String getProperty() { diff --git a/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java b/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java index b68fce39..d9ec00fc 100644 --- a/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java +++ b/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java @@ -21,7 +21,7 @@ public String getProperty() { @Override public String getMinimumVersion() { - return "2384.va_d3a_58a_4b_df5"; + return "2385.vfe86233d0d36"; } @Override @@ -56,7 +56,7 @@ private static boolean hasWebFragment(JarInputStream jis) throws IOException { } private JarEntry getJenkinsCoreEntry(JarFile jarFile) { - for (var entries = jarFile.entries(); entries.hasMoreElements();) { + for (var entries = jarFile.entries(); entries.hasMoreElements(); ) { JarEntry entry = entries.nextElement(); if (entry.getName().startsWith("WEB-INF/lib/jenkins-core-")) { return entry; From 5eaf4787345233dc8e53a809cbd618e74a168b88 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 22 Jan 2025 16:49:52 +0100 Subject: [PATCH 4/8] Spotless --- .../java/org/jenkins/tools/test/hook/WarFragmentHook.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java b/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java index d9ec00fc..8b6dcb45 100644 --- a/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java +++ b/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java @@ -37,8 +37,8 @@ public boolean check(@NonNull BeforeExecutionContext context) { throw new IllegalArgumentException("Failed to find jenkins-core jar in " + war); } try (var is = jarFile.getInputStream(jenkinsCoreEntry); - var bis = new BufferedInputStream(is); - var jis = new JarInputStream(bis)) { + var bis = new BufferedInputStream(is); + var jis = new JarInputStream(bis)) { return hasWebFragment(jis); } } catch (IOException e) { @@ -64,5 +64,4 @@ private JarEntry getJenkinsCoreEntry(JarFile jarFile) { } return null; } - } From dcd6af2519b3192b0b40f37ebb044492e381fad9 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Thu, 23 Jan 2025 11:12:59 +0100 Subject: [PATCH 5/8] Replace existing hooks with a unified version managing jenkins-test-harness version depending on the case --- .../test/hook/JenkinsTestHarnessHook.java | 158 ++++++++++++++++++ .../jenkins/tools/test/hook/Jetty12Hook.java | 83 --------- .../tools/test/hook/WarFragmentHook.java | 67 -------- .../test/hook/JenkinsTestHarnessHookTest.java | 23 +++ 4 files changed, 181 insertions(+), 150 deletions(-) create mode 100644 src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java delete mode 100644 src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java delete mode 100644 src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java create mode 100644 src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java diff --git a/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java b/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java new file mode 100644 index 00000000..512c6e0f --- /dev/null +++ b/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java @@ -0,0 +1,158 @@ +package org.jenkins.tools.test.hook; + +import edu.umd.cs.findbugs.annotations.NonNull; +import hudson.util.VersionNumber; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.JarInputStream; +import java.util.stream.Collectors; +import org.jenkins.tools.test.exception.PluginCompatibilityTesterException; +import org.jenkins.tools.test.exception.PomExecutionException; +import org.jenkins.tools.test.maven.ExpressionEvaluator; +import org.jenkins.tools.test.maven.ExternalMavenRunner; +import org.jenkins.tools.test.model.hook.BeforeExecutionContext; +import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution; +import org.kohsuke.MetaInfServices; + +@MetaInfServices(PluginCompatTesterHookBeforeExecution.class) +public class JenkinsTestHarnessHook extends PluginCompatTesterHookBeforeExecution { + public static final String VERSION_WITH_WEB_FRAGMENTS = "2385.vfe86233d0d36"; + public static final List VALID_VERSIONS = + List.of("2244.2247.ve6b_a_8191b_95f", "2270.2272.vd890c8c611b_3", VERSION_WITH_WEB_FRAGMENTS); + private static final String PROPERTY_NAME = "jenkins-test-harness.version"; + + private static boolean usesWebFragment(@NonNull BeforeExecutionContext context) { + // We only want this hook to be enabled if the Jetty 12 hook is not enabled at the same time + var war = context.getConfig().getWar(); + try (var jarFile = new JarFile(war)) { + var jenkinsCoreEntry = getJenkinsCoreEntry(jarFile); + if (jenkinsCoreEntry == null) { + throw new IllegalArgumentException("Failed to find jenkins-core jar in " + war); + } + try (var is = jarFile.getInputStream(jenkinsCoreEntry); + var bis = new BufferedInputStream(is); + var jis = new JarInputStream(bis)) { + return hasWebFragment(jis); + } + } catch (IOException e) { + throw new UncheckedIOException("Failed to determine whether " + war + " uses web fragments", e); + } + } + + @NonNull + private static VersionNumber getPropertyAsVersion( + @NonNull BeforeExecutionContext context, @NonNull String propertyName) throws PomExecutionException { + var expressionEvaluator = new ExpressionEvaluator( + context.getCloneDirectory(), + context.getPlugin().getModule(), + new ExternalMavenRunner(context.getConfig())); + return new VersionNumber(expressionEvaluator.evaluateString(propertyName)); + } + + private static boolean hasWebFragment(JarInputStream jis) throws IOException { + for (var entry = jis.getNextEntry(); entry != null; entry = jis.getNextEntry()) { + if ("META-INF/web-fragment.xml".equals(entry.getName())) { + return true; + } + } + return false; + } + + private static JarEntry getJenkinsCoreEntry(JarFile jarFile) { + for (var entries = jarFile.entries(); entries.hasMoreElements(); ) { + var entry = entries.nextElement(); + if (entry.getName().startsWith("WEB-INF/lib/jenkins-core-")) { + return entry; + } + } + return null; + } + + private static VersionNumber getWinstoneVersion(File war) { + try (var jarFile = new JarFile(war)) { + var zipEntry = jarFile.getEntry("executable/winstone.jar"); + if (zipEntry == null) { + throw new IllegalArgumentException("Failed to find winstone.jar in " + war); + } + try (var is = jarFile.getInputStream(zipEntry); + var bis = new BufferedInputStream(is); + var jis = new JarInputStream(bis)) { + var manifest = jis.getManifest(); + if (manifest == null) { + throw new IllegalArgumentException("Failed to read manifest in " + war); + } + var version = manifest.getMainAttributes().getValue("Implementation-Version"); + if (version == null) { + throw new IllegalArgumentException("Failed to read Winstone version from manifest in " + war); + } + return new VersionNumber(version); + } + } catch (IOException e) { + throw new UncheckedIOException("Failed to read Winstone version in " + war, e); + } + } + + /** + * Determines the version of Jenkins Test Harness to use depending on the original version. + */ + @NonNull + static VersionNumber determineNextVersion(@NonNull VersionNumber version) { + var first = true; + VersionNumber older = null; + for (var validVersion : VALID_VERSIONS.stream().map(VersionNumber::new).collect(Collectors.toList())) { + if (first) { + if (validVersion.isNewerThan(version)) { + return validVersion; + } + first = false; + } + if (validVersion.isOlderThan(version)) { + older = validVersion; + } else { + if (older != null) { + return validVersion; + } + } + } + // Keep the version as is. If that happens, it means check() method returned true by mistake. + return version; + } + + @Override + public boolean check(@NonNull BeforeExecutionContext context) { + var winstoneVersion = getWinstoneVersion(context.getConfig().getWar()); + if (winstoneVersion.getDigitAt(0) < 7) { + // Don't upgrade anything if winstone version is too old. + return false; + } + try { + var existingVersion = getPropertyAsVersion(context, PROPERTY_NAME); + // If core uses web fragments, we need a version of jth with web fragments support + if (!usesWebFragment(context)) { + return existingVersion.isOlderThan(new VersionNumber(VERSION_WITH_WEB_FRAGMENTS)); + } else { + return VALID_VERSIONS.stream().map(VersionNumber::new).anyMatch(existingVersion::equals) + || existingVersion.isOlderThan(new VersionNumber(VERSION_WITH_WEB_FRAGMENTS)); + } + } catch (PomExecutionException e) { + return false; + } + } + + @Override + public void action(@NonNull BeforeExecutionContext context) throws PluginCompatibilityTesterException { + var version = getPropertyAsVersion(context, PROPERTY_NAME); + context.getArgs().add(String.format("-D%s=%s", PROPERTY_NAME, determineNextVersion(version))); + /* + * The version of JUnit 5 used at runtime must match the version of JUnit 5 used to compile the tests, but the + * inclusion of a newer test harness might cause the HPI plugin to try to use a newer version of JUnit 5 at + * runtime to satisfy upper bounds checks, so exclude JUnit 5 from upper bounds analysis. + */ + context.getUpperBoundsExcludes().add("org.junit.jupiter:junit-jupiter-api"); + } +} diff --git a/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java b/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java deleted file mode 100644 index c1d5f93a..00000000 --- a/src/main/java/org/jenkins/tools/test/hook/Jetty12Hook.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.jenkins.tools.test.hook; - -import edu.umd.cs.findbugs.annotations.NonNull; -import hudson.util.VersionNumber; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.util.jar.JarFile; -import java.util.jar.JarInputStream; -import java.util.jar.Manifest; -import java.util.zip.ZipEntry; -import org.jenkins.tools.test.model.hook.BeforeExecutionContext; -import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution; -import org.kohsuke.MetaInfServices; - -/** - * Ensure that if the core is on Jetty 12, that the test harness is on Jetty 12 as well. - */ -@MetaInfServices(PluginCompatTesterHookBeforeExecution.class) -public class Jetty12Hook extends PropertyVersionHook { - - public static final String JTH_VERSION = "2244.2247.ve6b_a_8191b_95f"; - - @Override - public String getProperty() { - return "jenkins-test-harness.version"; - } - - @Override - public String getMinimumVersion() { - return JTH_VERSION; - } - - @Override - public boolean check(@NonNull BeforeExecutionContext context) { - return staticCheck(context, getProperty(), getMinimumVersion()); - } - - static boolean staticCheck(BeforeExecutionContext context, String property, String minimumVersion) { - VersionNumber winstoneVersion = getWinstoneVersion(context.getConfig().getWar()); - if (winstoneVersion.getDigitAt(0) < 7) { - return false; - } - return PropertyVersionHook.check(context, property, minimumVersion); - } - - static VersionNumber getWinstoneVersion(File war) { - try (JarFile jarFile = new JarFile(war)) { - ZipEntry zipEntry = jarFile.getEntry("executable/winstone.jar"); - if (zipEntry == null) { - throw new IllegalArgumentException("Failed to find winstone.jar in " + war); - } - try (InputStream is = jarFile.getInputStream(zipEntry); - BufferedInputStream bis = new BufferedInputStream(is); - JarInputStream jis = new JarInputStream(bis)) { - Manifest manifest = jis.getManifest(); - if (manifest == null) { - throw new IllegalArgumentException("Failed to read manifest in " + war); - } - String version = manifest.getMainAttributes().getValue("Implementation-Version"); - if (version == null) { - throw new IllegalArgumentException("Failed to read Winstone version from manifest in " + war); - } - return new VersionNumber(version); - } - } catch (IOException e) { - throw new UncheckedIOException("Failed to read Winstone version in " + war, e); - } - } - - @Override - public void action(@NonNull BeforeExecutionContext context) { - super.action(context); - /* - * The version of JUnit 5 used at runtime must match the version of JUnit 5 used to compile the tests, but the - * inclusion of a newer test harness might cause the HPI plugin to try to use a newer version of JUnit 5 at - * runtime to satisfy upper bounds checks, so exclude JUnit 5 from upper bounds analysis. - */ - context.getUpperBoundsExcludes().add("org.junit.jupiter:junit-jupiter-api"); - } -} diff --git a/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java b/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java deleted file mode 100644 index 8b6dcb45..00000000 --- a/src/main/java/org/jenkins/tools/test/hook/WarFragmentHook.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.jenkins.tools.test.hook; - -import edu.umd.cs.findbugs.annotations.NonNull; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.jar.JarInputStream; -import org.jenkins.tools.test.model.hook.BeforeExecutionContext; -import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution; -import org.kohsuke.MetaInfServices; - -@MetaInfServices(PluginCompatTesterHookBeforeExecution.class) -public class WarFragmentHook extends PropertyVersionHook { - @Override - public String getProperty() { - return "jenkins-test-harness.version"; - } - - @Override - public String getMinimumVersion() { - return "2385.vfe86233d0d36"; - } - - @Override - public boolean check(@NonNull BeforeExecutionContext context) { - if (Jetty12Hook.staticCheck(context, getProperty(), Jetty12Hook.JTH_VERSION)) { - return false; - } - // We only want this hook to be enabled if the Jetty 12 hook is not enabled at the same time - File war = context.getConfig().getWar(); - try (JarFile jarFile = new JarFile(war)) { - var jenkinsCoreEntry = getJenkinsCoreEntry(jarFile); - if (jenkinsCoreEntry == null) { - throw new IllegalArgumentException("Failed to find jenkins-core jar in " + war); - } - try (var is = jarFile.getInputStream(jenkinsCoreEntry); - var bis = new BufferedInputStream(is); - var jis = new JarInputStream(bis)) { - return hasWebFragment(jis); - } - } catch (IOException e) { - throw new UncheckedIOException("Failed to determine whether " + war + " uses web fragments", e); - } - } - - private static boolean hasWebFragment(JarInputStream jis) throws IOException { - for (var entry = jis.getNextEntry(); entry != null; entry = jis.getNextEntry()) { - if ("META-INF/web-fragment.xml".equals(entry.getName())) { - return true; - } - } - return false; - } - - private JarEntry getJenkinsCoreEntry(JarFile jarFile) { - for (var entries = jarFile.entries(); entries.hasMoreElements(); ) { - JarEntry entry = entries.nextElement(); - if (entry.getName().startsWith("WEB-INF/lib/jenkins-core-")) { - return entry; - } - } - return null; - } -} diff --git a/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java b/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java new file mode 100644 index 00000000..dd6bf42b --- /dev/null +++ b/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java @@ -0,0 +1,23 @@ +package org.jenkins.tools.test.hook; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasToString; + +import hudson.util.VersionNumber; +import org.junit.jupiter.api.Test; + +class JenkinsTestHarnessHookTest { + @Test + void nextVersion() { + assertThat( + JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2244")), + hasToString("2244.2247.ve6b_a_8191b_95f")); + assertThat( + JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2270")), + hasToString("2270.2272.v2db_a_04531041")); + assertThat( + JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2271")), + hasToString("2385.vfe86233d0d36")); + assertThat(JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2386")), hasToString("2386")); + } +} From 3d0fac1c0c9e59c44f9ad477a056bc1d2855240a Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Thu, 23 Jan 2025 11:28:19 +0100 Subject: [PATCH 6/8] Forgot to apply release version here --- .../org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java b/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java index dd6bf42b..4b070e03 100644 --- a/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java +++ b/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java @@ -14,7 +14,7 @@ void nextVersion() { hasToString("2244.2247.ve6b_a_8191b_95f")); assertThat( JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2270")), - hasToString("2270.2272.v2db_a_04531041")); + hasToString("2270.2272.vd890c8c611b_3")); assertThat( JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2271")), hasToString("2385.vfe86233d0d36")); From 971058ae8c0d8d797768e0a0ad441e4ec7a3dc21 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Thu, 23 Jan 2025 18:03:28 +0100 Subject: [PATCH 7/8] Pick up JTH @LocalData fix --- .../org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java b/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java index 512c6e0f..7e7bfffa 100644 --- a/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java +++ b/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java @@ -21,7 +21,7 @@ @MetaInfServices(PluginCompatTesterHookBeforeExecution.class) public class JenkinsTestHarnessHook extends PluginCompatTesterHookBeforeExecution { - public static final String VERSION_WITH_WEB_FRAGMENTS = "2385.vfe86233d0d36"; + public static final String VERSION_WITH_WEB_FRAGMENTS = "2386.v82359624ea_05"; public static final List VALID_VERSIONS = List.of("2244.2247.ve6b_a_8191b_95f", "2270.2272.vd890c8c611b_3", VERSION_WITH_WEB_FRAGMENTS); private static final String PROPERTY_NAME = "jenkins-test-harness.version"; From dcf5d2eba06721825e4901b454eb4a483ab699c8 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Fri, 24 Jan 2025 10:14:01 +0100 Subject: [PATCH 8/8] Adjust versions/tests --- .../tools/test/hook/JenkinsTestHarnessHook.java | 4 +++- .../test/hook/JenkinsTestHarnessHookTest.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java b/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java index 7e7bfffa..eed7fdcf 100644 --- a/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java +++ b/src/main/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHook.java @@ -22,8 +22,10 @@ @MetaInfServices(PluginCompatTesterHookBeforeExecution.class) public class JenkinsTestHarnessHook extends PluginCompatTesterHookBeforeExecution { public static final String VERSION_WITH_WEB_FRAGMENTS = "2386.v82359624ea_05"; + public static final String VERSION_BACKPORT_2244 = "2244.2247.ve6b_a_8191b_95f"; + public static final String VERSION_BACKPORT_2270 = "2270.2272.vd890c8c611b_3"; public static final List VALID_VERSIONS = - List.of("2244.2247.ve6b_a_8191b_95f", "2270.2272.vd890c8c611b_3", VERSION_WITH_WEB_FRAGMENTS); + List.of(VERSION_BACKPORT_2244, VERSION_BACKPORT_2270, VERSION_WITH_WEB_FRAGMENTS); private static final String PROPERTY_NAME = "jenkins-test-harness.version"; private static boolean usesWebFragment(@NonNull BeforeExecutionContext context) { diff --git a/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java b/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java index 4b070e03..fb8e7f53 100644 --- a/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java +++ b/src/test/java/org/jenkins/tools/test/hook/JenkinsTestHarnessHookTest.java @@ -9,15 +9,21 @@ class JenkinsTestHarnessHookTest { @Test void nextVersion() { + assertThat( + JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2243")), + hasToString(JenkinsTestHarnessHook.VERSION_BACKPORT_2244)); assertThat( JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2244")), - hasToString("2244.2247.ve6b_a_8191b_95f")); + hasToString(JenkinsTestHarnessHook.VERSION_BACKPORT_2244)); + assertThat( + JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2269")), + hasToString(JenkinsTestHarnessHook.VERSION_BACKPORT_2270)); assertThat( JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2270")), - hasToString("2270.2272.vd890c8c611b_3")); + hasToString(JenkinsTestHarnessHook.VERSION_BACKPORT_2270)); assertThat( JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2271")), - hasToString("2385.vfe86233d0d36")); - assertThat(JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2386")), hasToString("2386")); + hasToString(JenkinsTestHarnessHook.VERSION_WITH_WEB_FRAGMENTS)); + assertThat(JenkinsTestHarnessHook.determineNextVersion(new VersionNumber("2387")), hasToString("2387")); } }