Issue #1797 use platform for MR jars

This commit is contained in:
Greg Wilkins 2017-10-18 12:19:33 +11:00
parent d2acd1acae
commit 44a1f1e1a6
5 changed files with 44 additions and 41 deletions

View File

@ -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;
@ -418,7 +419,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<ParserTask>();
long start = 0;
@ -498,12 +503,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);
}
/**

View File

@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
@ -34,17 +33,14 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import org.eclipse.jetty.util.JavaVersion;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.MultiException;
import org.eclipse.jetty.util.MultiReleaseJarFile;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.JarScanner;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
@ -74,30 +70,11 @@ public class AnnotationParser
{
private static final Logger LOG = Log.getLogger(AnnotationParser.class);
private static final int JVM_MAJOR_VER;
protected static int ASM_OPCODE_VERSION = Opcodes.ASM5; //compatibility of api
protected Map<String, List<String>> _parsedClassNames = new ConcurrentHashMap<>();
static
{
// Determine JVM spec version
// Using guidance from http://openjdk.java.net/jeps/223
String jvmSpecVer = System.getProperty("java.vm.specification.version");
if (jvmSpecVer.indexOf('.') >= 0)
{
// Old spec version (Java 1.8 and older)
String parts[] = jvmSpecVer.split("\\.");
JVM_MAJOR_VER = Integer.parseInt(parts[1]);
}
else
{
// Newer spec version (Java 9+)
JVM_MAJOR_VER = Integer.parseInt(jvmSpecVer);
}
}
private final int _javaPlatform;
/**
* Convert internal name to simple name
*
@ -497,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.
*
@ -814,9 +809,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

View File

@ -79,9 +79,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);
}
@Override

View File

@ -46,6 +46,10 @@ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationPa
private ConcurrentHashMap<Resource, Bundle> _resourceToBundle = new ConcurrentHashMap<Resource, Bundle>();
private ConcurrentHashMap<Bundle,URI> _bundleToUri = new ConcurrentHashMap<Bundle, URI>();
public AnnotationParser(int javaPlatform)
{
super(javaPlatform);
}
/**
* Keep track of a jetty URI Resource and its associated OSGi bundle.

View File

@ -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;
}