8194901: remove interim code from javax.tools.ToolProvider
Reviewed-by: mchung
This commit is contained in:
parent
0110c9dc60
commit
9927f9eab3
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package javax.tools;
|
package javax.tools;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -101,17 +99,6 @@ public class ToolProvider {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean useLegacy;
|
|
||||||
|
|
||||||
static {
|
|
||||||
Class<?> c = null;
|
|
||||||
try {
|
|
||||||
c = Class.forName("java.lang.Module");
|
|
||||||
} catch (Throwable t) {
|
|
||||||
}
|
|
||||||
useLegacy = (c == null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an instance of a system tool using the service loader.
|
* Get an instance of a system tool using the service loader.
|
||||||
* @implNote By default, this returns the implementation in the specified module.
|
* @implNote By default, this returns the implementation in the specified module.
|
||||||
@ -126,14 +113,6 @@ public class ToolProvider {
|
|||||||
* @return the specified implementation of the tool
|
* @return the specified implementation of the tool
|
||||||
*/
|
*/
|
||||||
private static <T> T getSystemTool(Class<T> clazz, String moduleName, String className) {
|
private static <T> T getSystemTool(Class<T> clazz, String moduleName, String className) {
|
||||||
if (useLegacy) {
|
|
||||||
try {
|
|
||||||
return Class.forName(className, true, ClassLoader.getSystemClassLoader()).
|
|
||||||
asSubclass(clazz).getConstructor().newInstance();
|
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
throw new Error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ServiceLoader<T> sl = ServiceLoader.load(clazz, ClassLoader.getSystemClassLoader());
|
ServiceLoader<T> sl = ServiceLoader.load(clazz, ClassLoader.getSystemClassLoader());
|
||||||
@ -157,17 +136,9 @@ public class ToolProvider {
|
|||||||
*/
|
*/
|
||||||
private static <T> boolean matches(T tool, String moduleName) {
|
private static <T> boolean matches(T tool, String moduleName) {
|
||||||
PrivilegedAction<Boolean> pa = () -> {
|
PrivilegedAction<Boolean> pa = () -> {
|
||||||
// for now, use reflection to implement
|
Module toolModule = tool.getClass().getModule();
|
||||||
// return moduleName.equals(tool.getClass().getModule().getName());
|
String toolModuleName = toolModule.getName();
|
||||||
try {
|
return toolModuleName.equals(moduleName);
|
||||||
Method getModuleMethod = Class.class.getDeclaredMethod("getModule");
|
|
||||||
Object toolModule = getModuleMethod.invoke(tool.getClass());
|
|
||||||
Method getNameMethod = toolModule.getClass().getDeclaredMethod("getName");
|
|
||||||
String toolModuleName = (String) getNameMethod.invoke(toolModule);
|
|
||||||
return moduleName.equals(toolModuleName);
|
|
||||||
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return AccessController.doPrivileged(pa);
|
return AccessController.doPrivileged(pa);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user