Issue #1797 use platform for MR jars

This commit is contained in:
Greg Wilkins 2017-10-18 12:19:33 +11:00
parent 87a3fd147b
commit c12ba01014
5 changed files with 44 additions and 17 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;
@ -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<ParserTask>();
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);
}
/**

View File

@ -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<String, List<String>> _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

View File

@ -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);
}
/**

View File

@ -48,6 +48,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;
}