Skip to content

Commit

Permalink
Move java version checker back to its own jar (#30708)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjernst authored and jasontedor committed Jun 11, 2018
1 parent 49695b0 commit 3797dda
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 23 deletions.
1 change: 1 addition & 0 deletions distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion distribution/src/bin/elasticsearch-env
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion distribution/src/bin/elasticsearch-env.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%

Expand Down
14 changes: 14 additions & 0 deletions distribution/tools/java-version-checker/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
* under the License.
*/

package org.elasticsearch.tools.launchers;
package org.elasticsearch.tools.java_version_checker;

import java.util.ArrayList;
import java.util.List;
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]+)*$")) {
Expand All @@ -41,7 +41,7 @@ static List<Integer> parse(final String value) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,10 +45,30 @@ public static void main(final String[] args) {
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
17 changes: 6 additions & 11 deletions distribution/tools/launchers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,19 @@ 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}"
}

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'
Expand All @@ -48,4 +43,4 @@ namingConventions {

javadoc.enabled = false
loggerUsageCheck.enabled = false
jarHell.enabled=false
jarHell.enabled = false
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.tools.launchers;

import org.elasticsearch.tools.java_version_checker.SuppressForbidden;

/**
* Utility methods for launchers.
*/
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 3797dda

Please sign in to comment.