Move java version checker back to its own jar (#30708)

The java version checker requires being written with java 7 APIs.
In order to use java 8 apis in other launcher utilities, this commit
moves the java version checker back to its own jar.
This commit is contained in:
Ryan Ernst 2018-06-11 02:03:21 +02:00 committed by Jason Tedor
parent f8cbc81258
commit bd5c1a4590
11 changed files with 59 additions and 23 deletions

View File

@ -231,6 +231,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
from { project(':server').jar }
from { project(':server').configurations.runtime }
from { project(':libs:plugin-classloader').jar }
from { project(':distribution:tools:java-version-checker').jar }
from { project(':distribution:tools:launchers').jar }
into('tools/plugin-cli') {
from { project(':distribution:tools:plugin-cli').jar }

View File

@ -63,7 +63,7 @@ if [ ! -z "$JAVA_OPTS" ]; then
fi
# check the Java version
"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JavaVersionChecker
"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.java_version_checker.JavaVersionChecker
export HOSTNAME=$HOSTNAME

View File

@ -42,7 +42,7 @@ if defined JAVA_OPTS (
)
rem check the Java version
%JAVA% -cp "%ES_CLASSPATH%" "org.elasticsearch.tools.launchers.JavaVersionChecker" || exit /b 1
%JAVA% -cp "%ES_CLASSPATH%" "org.elasticsearch.tools.java_version_checker.JavaVersionChecker" || exit /b 1
set HOSTNAME=%COMPUTERNAME%

View File

@ -0,0 +1,14 @@
import org.elasticsearch.gradle.precommit.PrecommitTasks
apply plugin: 'elasticsearch.build'
targetCompatibility = JavaVersion.VERSION_1_7
// java_version_checker do not depend on core so only JDK signatures should be checked
forbiddenApisMain.signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
test.enabled = false
namingConventions.enabled = false
javadoc.enabled = false
loggerUsageCheck.enabled = false
jarHell.enabled = false

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.tools.launchers;
package org.elasticsearch.tools.java_version_checker;
import java.util.ArrayList;
import java.util.List;
@ -25,8 +25,8 @@ import java.util.Objects;
public class JavaVersion {
static final List<Integer> CURRENT = parse(System.getProperty("java.specification.version"));
static final List<Integer> JAVA_8 = parse("1.8");
public static final List<Integer> CURRENT = parse(System.getProperty("java.specification.version"));
public static final List<Integer> JAVA_8 = parse("1.8");
static List<Integer> parse(final String value) {
if (!value.matches("^0*[0-9]+(\\.[0-9]+)*$")) {
@ -41,7 +41,7 @@ public class JavaVersion {
return version;
}
static int majorVersion(final List<Integer> javaVersion) {
public static int majorVersion(final List<Integer> javaVersion) {
Objects.requireNonNull(javaVersion);
if (javaVersion.get(0) > 1) {
return javaVersion.get(0);

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.tools.launchers;
package org.elasticsearch.tools.java_version_checker;
import java.util.Arrays;
import java.util.Locale;
@ -45,10 +45,30 @@ final class JavaVersionChecker {
Locale.ROOT,
"the minimum required Java version is 8; your Java version from [%s] does not meet this requirement",
System.getProperty("java.home"));
Launchers.errPrintln(message);
Launchers.exit(1);
errPrintln(message);
exit(1);
}
Launchers.exit(0);
exit(0);
}
/**
* Prints a string and terminates the line on standard error.
*
* @param message the message to print
*/
@SuppressForbidden(reason = "System#err")
static void errPrintln(final String message) {
System.err.println(message);
}
/**
* Exit the VM with the specified status.
*
* @param status the status
*/
@SuppressForbidden(reason = "System#exit")
static void exit(final int status) {
System.exit(status);
}
}

View File

@ -17,17 +17,18 @@
* under the License.
*/
package org.elasticsearch.tools.launchers;
package org.elasticsearch.tools.java_version_checker;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to suppress forbidden-apis errors inside a whole class, a method, or a field.
*/
@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
@interface SuppressForbidden {
public @interface SuppressForbidden {
String reason();
}

View File

@ -22,10 +22,8 @@ import org.gradle.api.JavaVersion
apply plugin: 'elasticsearch.build'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
compile parent.project('java-version-checker')
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
testCompile "junit:junit:${versions.junit}"
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
@ -33,13 +31,10 @@ dependencies {
archivesBaseName = 'elasticsearch-launchers'
// launchers do not depend on core so only JDK signatures should be checked
forbiddenApisMain {
signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
}
forbiddenApisTest {
signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
}
// java_version_checker do not depend on core so only JDK signatures should be checked
List jdkSignatures = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
forbiddenApisMain.signaturesURLs = jdkSignatures
forbiddenApisTest.signaturesURLs = jdkSignatures
namingConventions {
testClass = 'org.elasticsearch.tools.launchers.LaunchersTestCase'
@ -48,4 +43,4 @@ namingConventions {
javadoc.enabled = false
loggerUsageCheck.enabled = false
jarHell.enabled=false
jarHell.enabled = false

View File

@ -38,6 +38,8 @@ import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.elasticsearch.tools.java_version_checker.JavaVersion;
/**
* Parses JVM options from a file and prints a single line with all JVM options to standard output.
*/

View File

@ -19,6 +19,8 @@
package org.elasticsearch.tools.launchers;
import org.elasticsearch.tools.java_version_checker.SuppressForbidden;
/**
* Utility methods for launchers.
*/

View File

@ -28,6 +28,7 @@ List projects = [
'distribution:bwc:staged-minor-snapshot',
'distribution:bwc:next-bugfix-snapshot',
'distribution:bwc:maintenance-bugfix-snapshot',
'distribution:tools:java-version-checker',
'distribution:tools:launchers',
'distribution:tools:plugin-cli',
'server',