Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-68147] Support Java 17 #75

Closed
wants to merge 10 commits into from
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>version-number</artifactId>
<version>1.10</version>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already included in Jenkins core as of 2.342, so rather than duplicate the library in this plugin, I suggest bumping the core baseline to 2.346 or later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like deleting this new dependency and instead doing:

diff --git a/pom.xml b/pom.xml
index 22f57f5..573bf80 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,15 +51,15 @@
     <properties>
         <revision>2.3</revision>
         <changelist>-SNAPSHOT</changelist>
-        <jenkins.version>2.277.4</jenkins.version>
+        <jenkins.version>2.346.1</jenkins.version>
         <gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
     </properties>
     <dependencyManagement>
         <dependencies>
             <dependency>
                 <groupId>io.jenkins.tools.bom</groupId>
-                <artifactId>bom-2.277.x</artifactId>
-                <version>984.vb5eaac999a7e</version>
+                <artifactId>bom-2.346.x</artifactId>
+                <version>1382.v7d694476f340</version>
                 <scope>import</scope>
                 <type>pom</type>
             </dependency>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 503ada6

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
41 changes: 0 additions & 41 deletions src/main/java/hudson/plugin/versioncolumn/JVMConstants.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.google.common.annotations.VisibleForTesting;
import hudson.util.VersionNumber;
import io.jenkins.lib.versionnumber.JavaSpecificationVersion;
import jenkins.model.Jenkins;
import org.apache.commons.codec.binary.Hex;

Expand All @@ -38,7 +39,6 @@
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;

import static hudson.plugin.versioncolumn.JVMConstants.JDK_VERSION_NUMBER_TO_BYTECODE_LEVEL_MAPPING;

/**
* Responsible for master and agent jvm versions comparisons, and notions of "compatibility".
Expand Down Expand Up @@ -90,17 +90,25 @@ private int getMasterBytecodeMajorVersionNumber() {
}

private boolean isAgentRuntimeCompatibleWithJenkinsBytecodeLevel(String agentMajorMinorVersion) {
Integer masterBytecodeLevel = getMasterBytecodeMajorVersionNumber();
Integer agentVMMaxBytecodeLevel = JDK_VERSION_NUMBER_TO_BYTECODE_LEVEL_MAPPING.get(agentMajorMinorVersion);
if (agentVMMaxBytecodeLevel != null) {
return masterBytecodeLevel <= agentVMMaxBytecodeLevel;
int masterBytecodeLevel = getMasterBytecodeMajorVersionNumber();
int releaseVersion;
if (agentMajorMinorVersion.startsWith("1.")) {
releaseVersion = Integer.parseInt(agentMajorMinorVersion.split("\\.")[1]);
} else {
releaseVersion = Integer.parseInt(agentMajorMinorVersion.split("\\.")[0]);
}
try {
int agentVMMaxBytecodeLevel = JavaSpecificationVersion.fromReleaseVersion(releaseVersion).toClassVersion();
return masterBytecodeLevel <= agentVMMaxBytecodeLevel;
} catch (NullPointerException e) {
LOGGER.log(Level.WARNING, Messages.JVMVersionMonitor_UnrecognizedAgentJVM(agentMajorMinorVersion));
/*
* Even if the version might be compatible, we still mark the node as incompatible to prevent potential issues.
*/
return false;

}

}

public boolean isCompatible() {
Expand Down Expand Up @@ -164,13 +172,13 @@ public int get() {
// So Jenkins started with Java 1.4 (or less?) reading the *old* changelog (like around ~1.100)
// but well not sure I'll bother
if (jenkinsVersion.isOlderThan(new VersionNumber("1.520"))) {
return JVMConstants.JAVA_5;
return JavaSpecificationVersion.JAVA_5.toClassVersion();
} else if (jenkinsVersion.isOlderThan(new VersionNumber("1.612"))) {
return JVMConstants.JAVA_6;
return JavaSpecificationVersion.JAVA_6.toClassVersion();
} else if (jenkinsVersion.isOlderThan(new VersionNumber("2.54"))) {
return JVMConstants.JAVA_7;
return JavaSpecificationVersion.JAVA_7.toClassVersion();
} else if (jenkinsVersion.isNewerThan(new VersionNumber("2.54"))) {
return JVMConstants.JAVA_8;
return JavaSpecificationVersion.JAVA_8.toClassVersion();
}

throw new IllegalStateException("Jenkins Bytecode Level could not be inferred");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hudson.plugin.versioncolumn;


import io.jenkins.lib.versionnumber.JavaSpecificationVersion;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Test;
Expand All @@ -23,20 +24,25 @@ public void computeMajorMinor() {
assertEquals("1.8", JVMVersionComparator.computeMajorMinor("1.8.1-blah_whatever$wat"));
}

@SuppressWarnings("unused")
private Object[] parametersForCompatible() {
return new Object[][]{
{"1.8.0", "1.8.0", true},
{"11.0.11", "11.0.11", true},
{"1.8.0", "1.8.0", false},
{"1.6.0", "1.6.0", true},
{"1.6.0", "1.6.1_ublah_whatever", false},
{"1.8.066", "1.8.0110", false},
};
}

@SuppressWarnings("unused")
private Object[] parametersForIncompatible() {
return new Object[][]{
{"1.5.0", "1.5.1", true},
{"1.7.0", "1.6.0", true},
{"1.7.0", "11.0.2", true},
{"17.0.3", "11.0.2", true},
{"1.8.0_66", "1.8.0_110", true},
{"1.6.0", "1.6.1", true},
};
Expand Down Expand Up @@ -64,19 +70,23 @@ private JVMVersionComparator.ComparisonMode toExactMatch(boolean exactMatch) {
}
}

@SuppressWarnings("unused")
private Object[] parametersForCompatibleBytecodeLevel() {
return new Object[][]{
{"1.8.0", JVMConstants.JAVA_8},
{"1.8.0", JVMConstants.JAVA_7},
{"1.8.0", JVMConstants.JAVA_6},
{"1.8.0", JavaSpecificationVersion.JAVA_8.toClassVersion()},
{"1.8.0", JavaSpecificationVersion.JAVA_7.toClassVersion()},
{"1.8.0", JavaSpecificationVersion.JAVA_6.toReleaseVersion()},
{"11.0.1", JavaSpecificationVersion.JAVA_11.toReleaseVersion()},
Comment on lines +71 to +72
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't these toClassVersion? This parameter represents a class version, not a release version.

};
}

@SuppressWarnings("unused")
private Object[] parametersForIncompatibleBytecodeLevel() {
return new Object[][]{
{"1.7.0", JVMConstants.JAVA_8},
{"1.6.1", JVMConstants.JAVA_7},
{"1.5.3", JVMConstants.JAVA_6},
{"1.7.0", JavaSpecificationVersion.JAVA_8.toClassVersion()},
{"1.6.1", JavaSpecificationVersion.JAVA_7.toClassVersion()},
{"1.5.3", JavaSpecificationVersion.JAVA_6.toClassVersion()},
{"11.0.3", JavaSpecificationVersion.JAVA_12.toClassVersion()},
};
}

Expand All @@ -85,34 +95,34 @@ private Object[] parametersForIncompatibleBytecodeLevel() {
@Parameters
public void compatibleBytecodeLevel(String agentVMVersion, final int masterBytecodeMajorVersion) {
assertTrue(new JVMVersionComparator("whatever", agentVMVersion,
JVMVersionComparator.ComparisonMode.RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE,
new JVMVersionComparator.MasterBytecodeMajorVersionNumberGetter() {
@Override
public int get() {
return masterBytecodeMajorVersion;
}
}).isCompatible());
JVMVersionComparator.ComparisonMode.RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE,
new JVMVersionComparator.MasterBytecodeMajorVersionNumberGetter() {
@Override
public int get() {
return masterBytecodeMajorVersion;
}
}).isCompatible());
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
@Parameters
public void incompatibleBytecodeLevel(String agentVMVersion, final int masterBytecodeMajorVersion) {
assertTrue(new JVMVersionComparator("whatever", agentVMVersion,
JVMVersionComparator.ComparisonMode.RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE,
new JVMVersionComparator.MasterBytecodeMajorVersionNumberGetter() {
@Override
public int get() {
return masterBytecodeMajorVersion;
}
}).isNotCompatible());
JVMVersionComparator.ComparisonMode.RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE,
new JVMVersionComparator.MasterBytecodeMajorVersionNumberGetter() {
@Override
public int get() {
return masterBytecodeMajorVersion;
}
}).isNotCompatible());
}

@Issue("JENKINS-53445")
@Test
public void shouldNotThrowNPEWhenJVMVersionIsNotRecognized() {
JVMVersionComparator jvmVersionComparator =
new JVMVersionComparator("99.9", "99.9",
JVMVersionComparator.ComparisonMode.RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE);
new JVMVersionComparator("99.9", "99.9",
JVMVersionComparator.ComparisonMode.RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE);
assertNotNull(jvmVersionComparator);
assertFalse(jvmVersionComparator.isCompatible());
}
Expand Down