Skip to content

Commit

Permalink
[MODULES-189] Enforce a minimum JVM spec version
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Apr 21, 2014
1 parent 453d89c commit f7e2861
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/org/jboss/modules/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@

import java.util.jar.Manifest;
import java.util.prefs.Preferences;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jboss.modules.log.JDKModuleLogger;

import static java.security.AccessController.doPrivileged;
import static org.jboss.modules.SecurityActions.setContextClassLoader;

/**
Expand Down Expand Up @@ -207,7 +210,7 @@ public static void main(String[] args) throws Throwable {
}
classpathDefined = true;
classpath = args[++i];
AccessController.doPrivileged(new PropertyWriteAction("java.class.path", classpath));
doPrivileged(new PropertyWriteAction("java.class.path", classpath));
} else if ("-dep".equals(arg) || "-dependencies".equals(arg)) {
if (deps != null) {
System.err.println("-dep or -dependencies may only be specified once.");
Expand Down Expand Up @@ -389,6 +392,15 @@ public static void main(String[] args) throws Throwable {
System.exit(1);
return;
}
final String ourJavaVersion = doPrivileged(new PropertyReadAction("java.specification.version", "1.6"));
final String requireJavaVersion = module.getProperty("jboss.require-java-version", ourJavaVersion);
final Pattern versionPattern = Pattern.compile("1\\.(\\d+)");
final Matcher requireMatcher = versionPattern.matcher(requireJavaVersion);
final Matcher ourMatcher = versionPattern.matcher(ourJavaVersion);
if (requireMatcher.matches() && ourMatcher.matches() && Integer.valueOf(requireMatcher.group(1)) > Integer.valueOf(ourMatcher.group(1))) {
System.err.printf("This application requires Java specification version %s or later to run (this Java virtual machine implements specification version %s)%n", requireJavaVersion, ourJavaVersion);
System.exit(1);
}

ModularURLStreamHandlerFactory.addHandlerModule(module);
ModularContentHandlerFactory.addHandlerModule(module);
Expand Down

0 comments on commit f7e2861

Please sign in to comment.