diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java index 3399bfde0df..71efdaeaa25 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java @@ -72,6 +72,7 @@ public class AnnotationConfiguration extends AbstractConfiguration public static final String CONTAINER_INITIALIZER_STARTER = "org.eclipse.jetty.containerInitializerStarter"; public static final String MULTI_THREADED = "org.eclipse.jetty.annotations.multiThreaded"; public static final String MAX_SCAN_WAIT = "org.eclipse.jetty.annotations.maxWait"; + public static final String JAVA_TARGET_VERSION = "org.eclipse.jetty.annotations.javaTargetVersion"; public static final int DEFAULT_MAX_SCAN_WAIT = 60; /* time in sec */ public static final boolean DEFAULT_MULTI_THREADED = true; @@ -502,7 +503,11 @@ public class AnnotationConfiguration extends AbstractConfiguration protected void scanForAnnotations (WebAppContext context) throws Exception { - AnnotationParser parser = createAnnotationParser(); + int javaPlatform = 0; + Object target = context.getAttribute(JAVA_TARGET_VERSION); + if (target!=null) + javaPlatform = Integer.valueOf(target.toString()); + AnnotationParser parser = createAnnotationParser(javaPlatform); _parserTasks = new ArrayList(); long start = 0; @@ -582,12 +587,13 @@ public class AnnotationConfiguration extends AbstractConfiguration /** + * @param javaPlatform The java platform to scan for. * @return a new AnnotationParser. This method can be overridden to use a different implementation of * the AnnotationParser. Note that this is considered internal API. */ - protected AnnotationParser createAnnotationParser() + protected AnnotationParser createAnnotationParser(int javaPlatform) { - return new AnnotationParser(); + return new AnnotationParser(javaPlatform); } /** diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java index d1c8d984bda..80a5c38e1d8 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java @@ -34,6 +34,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.eclipse.jetty.util.JavaVersion; import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.MultiReleaseJarFile; @@ -72,7 +73,8 @@ public class AnnotationParser protected static int ASM_OPCODE_VERSION = Opcodes.ASM5; //compatibility of api protected Map> _parsedClassNames = new ConcurrentHashMap<>(); - + private final int _javaPlatform; + /** * Convert internal name to simple name * @@ -472,6 +474,24 @@ public class AnnotationParser } } + public AnnotationParser() + { + this(JavaVersion.VERSION.getPlatform()); + } + + /** + * @param javaPlatform The target java version or 0 for the current runtime. + */ + public AnnotationParser(int javaPlatform) + { + if (javaPlatform==0) + javaPlatform = JavaVersion.VERSION.getPlatform(); + // TODO can only support 8 until ASM 6 is available + if (javaPlatform!=8) + LOG.warn("Annotation parsing only supports java8 until ASM6 upgrade"); + _javaPlatform = 8; + } + /** * Add a class as having been parsed. * @@ -835,10 +855,7 @@ public class AnnotationParser LOG.debug("Scanning jar {}", jarResource); MultiException me = new MultiException(); - - // TODO do not force version 8 once ASM can scan 9 - // TODO support a different target for quickstart generation - MultiReleaseJarFile jarFile = new MultiReleaseJarFile(jarResource.getFile(),8,false); + MultiReleaseJarFile jarFile = new MultiReleaseJarFile(jarResource.getFile(),_javaPlatform,false); jarFile.stream().forEach(e-> { try diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java index 6b149275b8f..4ba875c38aa 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationConfiguration.java @@ -74,9 +74,9 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot * This parser scans the bundles using the OSGi APIs instead of assuming a jar. */ @Override - protected org.eclipse.jetty.annotations.AnnotationParser createAnnotationParser() + protected org.eclipse.jetty.annotations.AnnotationParser createAnnotationParser(int javaTargetVersion) { - return new AnnotationParser(); + return new AnnotationParser(javaTargetVersion); } /** diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java index 1330173ca66..b4231a334bd 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java @@ -48,6 +48,10 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa private ConcurrentHashMap _resourceToBundle = new ConcurrentHashMap(); private ConcurrentHashMap _bundleToUri = new ConcurrentHashMap(); + public AnnotationParser(int javaPlatform) + { + super(javaPlatform); + } /** * Keep track of a jetty URI Resource and its associated OSGi bundle. diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiReleaseJarFile.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiReleaseJarFile.java index a8720cefdf4..b5a7552bcc1 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiReleaseJarFile.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiReleaseJarFile.java @@ -38,7 +38,7 @@ public class MultiReleaseJarFile private static final String META_INF_VERSIONS = "META-INF/versions/"; private final JarFile jarFile; - private final int majorVersion; + private final int platform; private final boolean multiRelease; /* Map to hold unversioned name to VersionedJarEntry */ @@ -50,23 +50,23 @@ public class MultiReleaseJarFile */ public MultiReleaseJarFile(File file) throws IOException { - this(file,JavaVersion.VERSION.getMajor(),false); + this(file,JavaVersion.VERSION.getPlatform(),false); } /** * Construct a multi release jar file * @param file The file to open - * @param majorVersion The major JVM version to apply when selecting a version. + * @param javaPlatform The JVM platform to apply when selecting a version. * @param includeDirectories true if any directory entries should not be ignored * @throws IOException if the jar file cannot be read */ - public MultiReleaseJarFile(File file, int majorVersion, boolean includeDirectories) throws IOException + public MultiReleaseJarFile(File file, int javaPlatform, boolean includeDirectories) throws IOException { if (file==null || !file.exists() || !file.canRead() || file.isDirectory()) throw new IllegalArgumentException("bad jar file: "+file); jarFile = new JarFile(file,true,JarFile.OPEN_READ); - this.majorVersion = majorVersion; + this.platform = javaPlatform; Manifest manifest = jarFile.getManifest(); if (manifest==null) @@ -110,7 +110,7 @@ public class MultiReleaseJarFile */ public int getVersion() { - return majorVersion; + return platform; } /** @@ -230,7 +230,7 @@ public class MultiReleaseJarFile boolean isApplicable() { if (multiRelease) - return this.version>=0 && this.version <= majorVersion && name.length()>0; + return this.version>=0 && this.version <= platform && name.length()>0; return this.version==0; }