Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x
This commit is contained in:
commit
6b0736f263
|
@ -29,12 +29,12 @@ import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.JavaVersion;
|
import org.eclipse.jetty.util.JavaVersion;
|
||||||
import org.eclipse.jetty.util.Loader;
|
import org.eclipse.jetty.util.Loader;
|
||||||
import org.eclipse.jetty.util.ManifestUtils;
|
|
||||||
import org.eclipse.jetty.util.MultiException;
|
import org.eclipse.jetty.util.MultiException;
|
||||||
import org.eclipse.jetty.util.MultiReleaseJarFile;
|
import org.eclipse.jetty.util.MultiReleaseJarFile;
|
||||||
import org.eclipse.jetty.util.StringUtil;
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
|
@ -70,8 +70,7 @@ import org.slf4j.LoggerFactory;
|
||||||
public class AnnotationParser
|
public class AnnotationParser
|
||||||
{
|
{
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AnnotationParser.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AnnotationParser.class);
|
||||||
private static final int ASM_OPCODE_VERSION = Opcodes.ASM9; //compatibility of api
|
private static final int ASM_VERSION = asmVersion();
|
||||||
private static final String ASM_OPCODE_VERSION_STR = "ASM9";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of classnames scanned and the first location from which scan occurred
|
* Map of classnames scanned and the first location from which scan occurred
|
||||||
|
@ -83,67 +82,39 @@ public class AnnotationParser
|
||||||
/**
|
/**
|
||||||
* Determine the runtime version of asm.
|
* Determine the runtime version of asm.
|
||||||
*
|
*
|
||||||
* @return the org.objectweb.asm.Opcode matching the runtime version of asm.
|
* @return the {@link org.objectweb.asm.Opcodes} ASM value matching the runtime version of asm.
|
||||||
*/
|
*/
|
||||||
public static int asmVersion()
|
private static int asmVersion()
|
||||||
{
|
{
|
||||||
int asmVersion = ASM_OPCODE_VERSION;
|
// Find the highest available ASM version on the runtime/classpath, because
|
||||||
String version = ManifestUtils.getVersion(Opcodes.class).orElse(null);
|
// if we run with a lower than available ASM version, against a class with
|
||||||
if (version == null)
|
// new language features we'll get an UnsupportedOperationException, even if
|
||||||
|
// the ASM version supports the new language features.
|
||||||
|
// Also, if we run with a higher than available ASM version, we'll get
|
||||||
|
// an IllegalArgumentException from org.objectweb.asm.ClassVisitor.
|
||||||
|
// So must find exactly the maximum ASM api version available.
|
||||||
|
|
||||||
|
Optional<Integer> asmVersion = Arrays.stream(Opcodes.class.getFields()).sequential()
|
||||||
|
.filter((f) -> f.getName().matches("ASM[0-9]+"))
|
||||||
|
.map((f) -> f.getName().substring(3))
|
||||||
|
.map(Integer::parseInt)
|
||||||
|
.max(Integer::compareTo);
|
||||||
|
|
||||||
|
if (!asmVersion.isPresent())
|
||||||
|
throw new IllegalStateException("Invalid " + Opcodes.class.getName());
|
||||||
|
|
||||||
|
int asmFieldId = asmVersion.get();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
LOG.warn("Unknown ASM version, assuming {}", ASM_OPCODE_VERSION_STR);
|
String fieldName = "ASM" + asmFieldId;
|
||||||
|
if (LOG.isDebugEnabled())
|
||||||
|
LOG.debug("Using ASM API from {}.{}", Opcodes.class.getName(), fieldName);
|
||||||
|
return (int)Opcodes.class.getField(fieldName).get(null);
|
||||||
}
|
}
|
||||||
else
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
int dot = version.indexOf('.');
|
throw new IllegalStateException(e);
|
||||||
version = version.substring(0, (dot < 0 ? version.length() : dot)).trim();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int v = Integer.parseInt(version);
|
|
||||||
switch (v)
|
|
||||||
{
|
|
||||||
case 4:
|
|
||||||
{
|
|
||||||
asmVersion = Opcodes.ASM4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 5:
|
|
||||||
{
|
|
||||||
asmVersion = Opcodes.ASM5;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 6:
|
|
||||||
{
|
|
||||||
asmVersion = Opcodes.ASM6;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 7:
|
|
||||||
{
|
|
||||||
asmVersion = Opcodes.ASM7;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 8:
|
|
||||||
{
|
|
||||||
asmVersion = Opcodes.ASM8;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 9:
|
|
||||||
{
|
|
||||||
asmVersion = Opcodes.ASM9;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
LOG.warn("Unrecognized ASM version, assuming {}", ASM_OPCODE_VERSION_STR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (NumberFormatException e)
|
|
||||||
{
|
|
||||||
LOG.warn("Unable to parse ASM version, assuming {}", ASM_OPCODE_VERSION_STR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return asmVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -489,7 +460,7 @@ public class AnnotationParser
|
||||||
*/
|
*/
|
||||||
public static class MyClassVisitor extends ClassVisitor
|
public static class MyClassVisitor extends ClassVisitor
|
||||||
{
|
{
|
||||||
int _asmVersion;
|
final int _asmVersion;
|
||||||
final Resource _containingResource;
|
final Resource _containingResource;
|
||||||
final Set<? extends Handler> _handlers;
|
final Set<? extends Handler> _handlers;
|
||||||
ClassInfo _ci;
|
ClassInfo _ci;
|
||||||
|
@ -568,7 +539,7 @@ public class AnnotationParser
|
||||||
*/
|
*/
|
||||||
public AnnotationParser(int javaPlatform)
|
public AnnotationParser(int javaPlatform)
|
||||||
{
|
{
|
||||||
_asmVersion = asmVersion();
|
_asmVersion = ASM_VERSION;
|
||||||
if (javaPlatform == 0)
|
if (javaPlatform == 0)
|
||||||
javaPlatform = JavaVersion.VERSION.getPlatform();
|
javaPlatform = JavaVersion.VERSION.getPlatform();
|
||||||
_javaPlatform = javaPlatform;
|
_javaPlatform = javaPlatform;
|
||||||
|
@ -580,7 +551,7 @@ public class AnnotationParser
|
||||||
javaPlatform = JavaVersion.VERSION.getPlatform();
|
javaPlatform = JavaVersion.VERSION.getPlatform();
|
||||||
_javaPlatform = javaPlatform;
|
_javaPlatform = javaPlatform;
|
||||||
if (asmVersion == 0)
|
if (asmVersion == 0)
|
||||||
asmVersion = ASM_OPCODE_VERSION;
|
asmVersion = ASM_VERSION;
|
||||||
_asmVersion = asmVersion;
|
_asmVersion = asmVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue