-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into snapshots-JENKINS-51594
- Loading branch information
Showing
6 changed files
with
260 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
pipeline { | ||
agent none | ||
tools { | ||
maven "mvn" | ||
jdk 'jdk8' | ||
} | ||
options { | ||
buildDiscarder(logRotator(numToKeepStr: '10')) | ||
} | ||
stages { | ||
stage('Parallel Stage') { | ||
failFast true | ||
parallel { | ||
stage('Linux') { | ||
agent { | ||
label "linux" | ||
} | ||
steps { | ||
sh 'mvn -V -B clean verify' | ||
} | ||
} | ||
stage('Windows') { | ||
agent { | ||
label "windows" | ||
} | ||
steps { | ||
bat 'mvn -V -B clean verify' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/io/jenkins/lib/versionnumber/JavaSpecificationVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2019 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package io.jenkins.lib.versionnumber; | ||
|
||
import hudson.util.VersionNumber; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Java Version Specification. | ||
* Implemented according to https://openjdk.java.net/jeps/223 | ||
* @author Oleg Nenashev | ||
* @since 1.6 | ||
*/ | ||
public class JavaSpecificationVersion extends VersionNumber { | ||
|
||
private static final String JAVA_SPEC_VERSION_PROPERTY_NAME = "java.specification.version"; | ||
|
||
public static final JavaSpecificationVersion JAVA_5 = new JavaSpecificationVersion("1.5"); | ||
public static final JavaSpecificationVersion JAVA_6 = new JavaSpecificationVersion("1.6"); | ||
public static final JavaSpecificationVersion JAVA_7 = new JavaSpecificationVersion("1.7"); | ||
public static final JavaSpecificationVersion JAVA_8 = new JavaSpecificationVersion("1.8"); | ||
public static final JavaSpecificationVersion JAVA_9 = new JavaSpecificationVersion("9"); | ||
public static final JavaSpecificationVersion JAVA_10 = new JavaSpecificationVersion("10"); | ||
public static final JavaSpecificationVersion JAVA_11 = new JavaSpecificationVersion("11"); | ||
public static final JavaSpecificationVersion JAVA_12 = new JavaSpecificationVersion("12"); | ||
public static final JavaSpecificationVersion JAVA_13 = new JavaSpecificationVersion("13"); | ||
|
||
/** | ||
* Constructor which automatically normalizes version strings. | ||
* @param version Java specification version, should follow JEP-223 or the previous format. | ||
* @throws NumberFormatException Illegal Java specification version number | ||
*/ | ||
public JavaSpecificationVersion(@Nonnull String version) | ||
throws NumberFormatException { | ||
super(normalizeVersion(version)); | ||
} | ||
|
||
@Nonnull | ||
private static String normalizeVersion(@Nonnull String input) | ||
throws NumberFormatException { | ||
input = input.trim(); | ||
if (input.startsWith("1.")) { | ||
String[] split = input.split("\\."); | ||
if (split.length != 2) { | ||
throw new NumberFormatException("Malformed old Java Specification Version. " + | ||
"There should be exactly one dot and something after it: " + input); | ||
} | ||
input = split[1]; | ||
} | ||
|
||
int majorVersion = Integer.parseInt(input); | ||
if (majorVersion > 8) { | ||
return input; | ||
} else { | ||
return "1." + input; | ||
} | ||
} | ||
|
||
/** | ||
* Get the Java Specification version for the current JVM | ||
* @return Java Specification version | ||
* @throws NumberFormatException Version parsing error | ||
* @throws IllegalStateException JVM does not specify the mandatory {@link #JAVA_SPEC_VERSION_PROPERTY_NAME} property. | ||
*/ | ||
@Nonnull | ||
public static JavaSpecificationVersion forCurrentJVM() throws NumberFormatException { | ||
final String value = System.getProperty(JAVA_SPEC_VERSION_PROPERTY_NAME); | ||
if (value == null) { | ||
throw new IllegalStateException("Missing mandatory JVM system property: " + JAVA_SPEC_VERSION_PROPERTY_NAME); | ||
} | ||
return new JavaSpecificationVersion(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/test/java/io/jenkins/lib/versionnumber/JavaSpecificationVersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2019 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package io.jenkins.lib.versionnumber; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.For; | ||
import static io.jenkins.lib.versionnumber.JavaSpecificationVersion.*; | ||
|
||
/** | ||
* Tests for {@link JavaSpecificationVersion}. | ||
*/ | ||
@For(JavaSpecificationVersion.class) | ||
public class JavaSpecificationVersionTest { | ||
|
||
@Test | ||
public void shouldParseValidNumbersCorrectly() { | ||
assertSpecEquals(JAVA_6, "1.6"); | ||
assertSpecEquals(JAVA_7, "1.7"); | ||
assertSpecEquals(JAVA_8, "1.8"); | ||
assertSpecEquals(JAVA_9, "9"); | ||
assertSpecEquals(JAVA_10, "10"); | ||
assertSpecEquals(JAVA_11, "11"); | ||
} | ||
|
||
@Test | ||
public void shouldParseOldSpecCorrectly() { | ||
assertSpecEquals(JAVA_9, "1.9"); | ||
assertSpecEquals(JAVA_10, "1.10"); | ||
assertSpecEquals(JAVA_11, "1.11"); | ||
assertSpecEquals(JAVA_12, "1.12"); | ||
} | ||
|
||
@Test | ||
public void shouldResolveIncorrectSpecs() { | ||
assertSpecEquals(JAVA_8, "8"); | ||
assertSpecEquals(JAVA_7, "7"); | ||
assertSpecEquals(JAVA_5, "5"); | ||
} | ||
|
||
@Test | ||
public void shouldCompareVersionsProperly() { | ||
Assert.assertTrue(JAVA_5.isOlderThan(JAVA_6)); | ||
Assert.assertTrue(JAVA_6.isOlderThan(JAVA_7)); | ||
Assert.assertTrue(JAVA_7.isOlderThan(JAVA_8)); | ||
Assert.assertTrue(JAVA_8.isOlderThan(JAVA_9)); | ||
Assert.assertTrue(JAVA_8.isNewerThan(JAVA_7)); | ||
Assert.assertTrue(JAVA_9.isOlderThan(JAVA_10)); | ||
Assert.assertTrue(JAVA_10.isOlderThan(JAVA_11)); | ||
Assert.assertTrue(JAVA_10.isNewerThan(JAVA_8)); | ||
} | ||
|
||
@Test | ||
public void shouldRetrieveSpecVersionForTheCurrentJVM() { | ||
System.out.println("Current JVM Specification Version: " + JavaSpecificationVersion.forCurrentJVM()); | ||
} | ||
|
||
public void assertSpecEquals(JavaSpecificationVersion version, String value) { | ||
JavaSpecificationVersion actualSpec = new JavaSpecificationVersion(value); | ||
Assert.assertEquals("Wrong Java version", version, actualSpec); | ||
} | ||
|
||
public void assertOlder(JavaSpecificationVersion version1, JavaSpecificationVersion version2) { | ||
Assert.assertTrue(String.format("Version %s should be older than %s", version1, version2), | ||
version1.isOlderThan(version2)); | ||
} | ||
|
||
public void assertNewer(JavaSpecificationVersion version1, JavaSpecificationVersion version2) { | ||
Assert.assertTrue(String.format("Version %s should be newer than %s", version1, version2), | ||
version1.isNewerThan(version2)); | ||
} | ||
} |