8211037: Load jib jars dynamically from JibArtifactManager
Reviewed-by: ihse
This commit is contained in:
parent
6d9cf91bf0
commit
e5b9edac53
@ -531,8 +531,8 @@ define SetupRunJtregTestBody
|
|||||||
$1_JTREG_BASIC_OPTIONS += $$(addprefix -exclude:, $$($1_JTREG_PROBLEM_LIST))
|
$1_JTREG_BASIC_OPTIONS += $$(addprefix -exclude:, $$($1_JTREG_PROBLEM_LIST))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($$(JIB_JAR), )
|
ifneq ($$(JIB_HOME), )
|
||||||
$1_JTREG_BASIC_OPTIONS += -cpa:$$(JIB_JAR)
|
$1_JTREG_BASIC_OPTIONS += -e:JIB_HOME=$$(JIB_HOME)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$1_JTREG_BASIC_OPTIONS += -e:TEST_IMAGE_GRAAL_DIR=${TEST_IMAGE_DIR}/hotspot/jtreg/graal
|
$1_JTREG_BASIC_OPTIONS += -e:TEST_IMAGE_GRAAL_DIR=${TEST_IMAGE_DIR}/hotspot/jtreg/graal
|
||||||
|
@ -723,7 +723,7 @@ SETFILE:=@SETFILE@
|
|||||||
XATTR:=@XATTR@
|
XATTR:=@XATTR@
|
||||||
JT_HOME:=@JT_HOME@
|
JT_HOME:=@JT_HOME@
|
||||||
JTREGEXE:=@JTREGEXE@
|
JTREGEXE:=@JTREGEXE@
|
||||||
JIB_JAR:=@JIB_JAR@
|
JIB_HOME:=@JIB_HOME@
|
||||||
XCODEBUILD=@XCODEBUILD@
|
XCODEBUILD=@XCODEBUILD@
|
||||||
DTRACE := @DTRACE@
|
DTRACE := @DTRACE@
|
||||||
FIXPATH:=@FIXPATH@
|
FIXPATH:=@FIXPATH@
|
||||||
|
@ -1144,5 +1144,5 @@ AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JIB],
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_SUBST(JIB_JAR)
|
AC_SUBST(JIB_HOME)
|
||||||
])
|
])
|
||||||
|
@ -961,9 +961,9 @@ var getJibProfilesDependencies = function (input, common) {
|
|||||||
ext: "zip",
|
ext: "zip",
|
||||||
classifier: "distribution",
|
classifier: "distribution",
|
||||||
revision: "3.0-SNAPSHOT",
|
revision: "3.0-SNAPSHOT",
|
||||||
environment_name: "JIB_JAR",
|
environment_name: "JIB_HOME",
|
||||||
environment_value: input.get("jib", "install_path")
|
environment_value: input.get("jib", "install_path")
|
||||||
+ "/jib-3.0-SNAPSHOT-distribution/lib/jib-3.0-SNAPSHOT.jar"
|
+ "/jib-3.0-SNAPSHOT-distribution"
|
||||||
},
|
},
|
||||||
|
|
||||||
ant: {
|
ant: {
|
||||||
|
@ -453,8 +453,8 @@ JTREG_BASIC_OPTIONS += -e:TEST_IMAGE_GRAAL_DIR=${TEST_IMAGE_DIR}/hotspot/jtreg/g
|
|||||||
|
|
||||||
# Set other vm and test options
|
# Set other vm and test options
|
||||||
JTREG_TEST_OPTIONS += $(JAVA_ARGS:%=-javaoptions:%) $(JAVA_VM_ARGS:%=-vmoption:%)
|
JTREG_TEST_OPTIONS += $(JAVA_ARGS:%=-javaoptions:%) $(JAVA_VM_ARGS:%=-vmoption:%)
|
||||||
ifneq ($(JIB_JAR), )
|
ifneq ($(JIB_HOME), )
|
||||||
JTREG_BASIC_OPTIONS += -cpa:$(shell $(GETMIXEDPATH) "$(JIB_JAR)")
|
JTREG_BASIC_OPTIONS += -e:JIB_HOME=$(shell $(GETMIXEDPATH) "$(JIB_HOME)")
|
||||||
endif
|
endif
|
||||||
ifeq ($(IGNORE_MARKED_TESTS), true)
|
ifeq ($(IGNORE_MARKED_TESTS), true)
|
||||||
# Option to tell jtreg to not run tests marked with "ignore"
|
# Option to tell jtreg to not run tests marked with "ignore"
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
package jdk.test.lib.artifacts;
|
package jdk.test.lib.artifacts;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -35,7 +34,7 @@ public class ArtifactResolver {
|
|||||||
String managerName = System.getProperty("jdk.test.lib.artifacts.artifactmanager");
|
String managerName = System.getProperty("jdk.test.lib.artifacts.artifactmanager");
|
||||||
if (managerName != null) {
|
if (managerName != null) {
|
||||||
manager = (ArtifactManager) Class.forName(managerName).newInstance();
|
manager = (ArtifactManager) Class.forName(managerName).newInstance();
|
||||||
} else {
|
} else if (System.getenv().containsKey(JibArtifactManager.JIB_HOME_ENV_NAME)) {
|
||||||
manager = JibArtifactManager.newInstance();
|
manager = JibArtifactManager.newInstance();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -23,26 +23,66 @@
|
|||||||
|
|
||||||
package jdk.test.lib.artifacts;
|
package jdk.test.lib.artifacts;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.UncheckedIOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class JibArtifactManager implements ArtifactManager {
|
public class JibArtifactManager implements ArtifactManager {
|
||||||
private static final String JIB_SERVICE_FACTORY = "com.oracle.jib.api.JibServiceFactory";
|
private static final String JIB_SERVICE_FACTORY = "com.oracle.jib.api.JibServiceFactory";
|
||||||
|
public static final String JIB_HOME_ENV_NAME = "JIB_HOME";
|
||||||
private static String jibVersion = "1.0";
|
private static String jibVersion = "1.0";
|
||||||
private Object installerObject;
|
|
||||||
|
|
||||||
private JibArtifactManager(Object o) {
|
private Object installerObject;
|
||||||
installerObject = o;
|
private ClassLoader classLoader;
|
||||||
|
|
||||||
|
private JibArtifactManager(Object installerObject, ClassLoader classLoader) {
|
||||||
|
this.installerObject = installerObject;
|
||||||
|
this.classLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JibArtifactManager newInstance() throws ClassNotFoundException {
|
public static JibArtifactManager newInstance() throws ClassNotFoundException {
|
||||||
|
Path jibInstallDir = Paths.get(System.getenv(JIB_HOME_ENV_NAME));
|
||||||
|
Path libDir = jibInstallDir.resolve("lib");
|
||||||
|
if (!Files.isDirectory(libDir)) {
|
||||||
|
throw new ClassNotFoundException(JIB_SERVICE_FACTORY);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
URL[] jarUrls;
|
||||||
|
try (Stream<Path> files = Files.list(libDir)) {
|
||||||
|
jarUrls = files.filter(path -> path.toString().endsWith(".jar"))
|
||||||
|
.map(path -> {
|
||||||
|
try {
|
||||||
|
return path.toUri().toURL();
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new UncheckedIOException(e);
|
||||||
|
}
|
||||||
|
}).toArray(URL[]::new);
|
||||||
|
}
|
||||||
|
// Create a class loader using all those jars and set the parent to the
|
||||||
|
// current class loader's parent.
|
||||||
|
ClassLoader classLoader = new URLClassLoader(jarUrls, JibArtifactManager.class.getClassLoader().getParent());
|
||||||
|
|
||||||
|
// Temporarily replace the context classLoader
|
||||||
|
Thread currentThread = Thread.currentThread();
|
||||||
|
ClassLoader oldContextLoader = currentThread.getContextClassLoader();
|
||||||
|
currentThread.setContextClassLoader(classLoader);
|
||||||
|
|
||||||
|
Class jibServiceFactory = classLoader.loadClass(JIB_SERVICE_FACTORY);
|
||||||
try {
|
try {
|
||||||
Class jibServiceFactory = Class.forName(JIB_SERVICE_FACTORY);
|
|
||||||
Object jibArtifactInstaller = jibServiceFactory.getMethod("createJibArtifactInstaller").invoke(null);
|
Object jibArtifactInstaller = jibServiceFactory.getMethod("createJibArtifactInstaller").invoke(null);
|
||||||
return new JibArtifactManager(jibArtifactInstaller);
|
return new JibArtifactManager(jibArtifactInstaller, classLoader);
|
||||||
|
} finally {
|
||||||
|
currentThread.setContextClassLoader(oldContextLoader);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ClassNotFoundException(JIB_SERVICE_FACTORY, e);
|
throw new ClassNotFoundException(JIB_SERVICE_FACTORY, e);
|
||||||
}
|
}
|
||||||
@ -56,9 +96,19 @@ public class JibArtifactManager implements ArtifactManager {
|
|||||||
return invokeInstallerMethod("install", jibVersion, artifactDescription);
|
return invokeInstallerMethod("install", jibVersion, artifactDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path invokeInstallerMethod(String methodName, String jibVersion, HashMap<String, Object> artifactDescription) throws Exception {
|
private Path invokeInstallerMethod(String methodName, String jibVersion,
|
||||||
Method m = Class.forName("com.oracle.jib.api.JibArtifactInstaller").getMethod(methodName, String.class, Map.class);
|
HashMap<String, Object> artifactDescription) throws Exception {
|
||||||
|
// Temporarily replace the context classLoader
|
||||||
|
Thread currentThread = Thread.currentThread();
|
||||||
|
ClassLoader oldContextLoader = currentThread.getContextClassLoader();
|
||||||
|
currentThread.setContextClassLoader(classLoader);
|
||||||
|
try {
|
||||||
|
Method m = classLoader.loadClass("com.oracle.jib.api.JibArtifactInstaller")
|
||||||
|
.getMethod(methodName, String.class, Map.class);
|
||||||
return (Path) m.invoke(installerObject, jibVersion, artifactDescription);
|
return (Path) m.invoke(installerObject, jibVersion, artifactDescription);
|
||||||
|
} finally {
|
||||||
|
currentThread.setContextClassLoader(oldContextLoader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user