8199352: The Jib artifact resolver in test lib needs to print better error messages
Reviewed-by: iignatyev, ihse
--- a/test/hotspot/jtreg/applications/jcstress/JcstressRunner.java Fri Mar 09 19:12:07 2018 +0100
+++ b/test/hotspot/jtreg/applications/jcstress/JcstressRunner.java Fri Mar 09 19:20:19 2018 +0100
@@ -26,11 +26,11 @@
import jdk.test.lib.Utils;
import jdk.test.lib.artifacts.Artifact;
import jdk.test.lib.artifacts.ArtifactResolver;
+import jdk.test.lib.artifacts.ArtifactResolverException;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import java.io.File;
-import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -51,7 +51,7 @@
Map<String, Path> artifacts;
try {
artifacts = ArtifactResolver.resolve(JcstressRunner.class);
- } catch (FileNotFoundException e) {
+ } catch (ArtifactResolverException e) {
throw new Error("TESTBUG: Can not resolve artifacts for "
+ JcstressRunner.class.getName(), e);
}
--- a/test/hotspot/jtreg/applications/scimark/Scimark.java Fri Mar 09 19:12:07 2018 +0100
+++ b/test/hotspot/jtreg/applications/scimark/Scimark.java Fri Mar 09 19:20:19 2018 +0100
@@ -31,13 +31,20 @@
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.artifacts.Artifact;
import jdk.test.lib.artifacts.ArtifactResolver;
+import jdk.test.lib.artifacts.ArtifactResolverException;
import java.nio.file.Path;
import java.util.Map;
@Artifact(organization = "gov.nist.math", name = "scimark", revision = "2.0", extension = "zip")
public class Scimark {
public static void main(String... args) throws Exception {
- Map<String, Path> artifacts = ArtifactResolver.resolve(Scimark.class);
+ Map<String, Path> artifacts;
+ try {
+ artifacts = ArtifactResolver.resolve(Scimark.class);
+ } catch (ArtifactResolverException e) {
+ throw new Error("TESTBUG: Can not resolve artifacts for "
+ + Scimark.class.getName(), e);
+ }
OutputAnalyzer output = new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(
"-cp", artifacts.get("gov.nist.math.scimark-2.0").toString(),
--- a/test/hotspot/jtreg/compiler/aot/AotCompiler.java Fri Mar 09 19:12:07 2018 +0100
+++ b/test/hotspot/jtreg/compiler/aot/AotCompiler.java Fri Mar 09 19:20:19 2018 +0100
@@ -26,9 +26,9 @@
import jdk.test.lib.Platform;
import jdk.test.lib.artifacts.Artifact;
import jdk.test.lib.artifacts.ArtifactResolver;
+import jdk.test.lib.artifacts.ArtifactResolverException;
import jdk.test.lib.process.OutputAnalyzer;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.nio.file.Files;
@@ -298,7 +298,7 @@
.resolve("ld");
}
}
- } catch (FileNotFoundException e) {
+ } catch (ArtifactResolverException e) {
System.err.println("artifact resolution error: " + e);
// let jaotc try to find linker
return null;
--- a/test/lib/jdk/test/lib/artifacts/ArtifactManager.java Fri Mar 09 19:12:07 2018 +0100
+++ b/test/lib/jdk/test/lib/artifacts/ArtifactManager.java Fri Mar 09 19:20:19 2018 +0100
@@ -27,5 +27,5 @@
import java.nio.file.Path;
public interface ArtifactManager {
- public Path resolve(Artifact artifact) throws FileNotFoundException;
+ public Path resolve(Artifact artifact) throws ArtifactResolverException;
}
--- a/test/lib/jdk/test/lib/artifacts/ArtifactResolver.java Fri Mar 09 19:12:07 2018 +0100
+++ b/test/lib/jdk/test/lib/artifacts/ArtifactResolver.java Fri Mar 09 19:20:19 2018 +0100
@@ -29,7 +29,7 @@
import java.util.Map;
public class ArtifactResolver {
- public static Map<String, Path> resolve(Class<?> klass) throws FileNotFoundException {
+ public static Map<String, Path> resolve(Class<?> klass) throws ArtifactResolverException {
ArtifactManager manager = new DefaultArtifactManager();
try {
String managerName = System.getProperty("jdk.test.lib.artifacts.artifactmanager");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/lib/jdk/test/lib/artifacts/ArtifactResolverException.java Fri Mar 09 19:20:19 2018 +0100
@@ -0,0 +1,15 @@
+package jdk.test.lib.artifacts;
+
+/**
+ * Thrown by the ArtifactResolver when failing to resolve an Artifact.
+ */
+public class ArtifactResolverException extends Exception {
+
+ public ArtifactResolverException(String message) {
+ super(message);
+ }
+
+ public ArtifactResolverException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
--- a/test/lib/jdk/test/lib/artifacts/DefaultArtifactManager.java Fri Mar 09 19:12:07 2018 +0100
+++ b/test/lib/jdk/test/lib/artifacts/DefaultArtifactManager.java Fri Mar 09 19:20:19 2018 +0100
@@ -29,12 +29,13 @@
public class DefaultArtifactManager implements ArtifactManager {
@Override
- public Path resolve(Artifact artifact) throws FileNotFoundException {
+ public Path resolve(Artifact artifact) throws ArtifactResolverException {
String name = artifact.name();
String location = System.getProperty(artifactProperty(name));
if (location == null) {
- throw new FileNotFoundException("Couldn't automatically resolve dependency for " + name + " , revision " + artifact.revision() + "\n" +
- "Please specify the location using " + artifactProperty(name));
+ throw new ArtifactResolverException("Couldn't automatically resolve dependency for " + name
+ + " , revision " + artifact.revision() + "\n" +
+ "Please specify the location using " + artifactProperty(name));
}
return Paths.get(location);
}
--- a/test/lib/jdk/test/lib/artifacts/JibArtifactManager.java Fri Mar 09 19:12:07 2018 +0100
+++ b/test/lib/jdk/test/lib/artifacts/JibArtifactManager.java Fri Mar 09 19:20:19 2018 +0100
@@ -30,6 +30,7 @@
import java.util.Map;
public class JibArtifactManager implements ArtifactManager {
+ private static final String JIB_SERVICE_FACTORY = "com.oracle.jib.api.JibServiceFactory";
private static String jibVersion = "1.0";
private Object installerObject;
@@ -39,11 +40,11 @@
public static JibArtifactManager newInstance() throws ClassNotFoundException {
try {
- Class jibServiceFactory = Class.forName("com.oracle.jib.api.JibServiceFactory");
+ Class jibServiceFactory = Class.forName(JIB_SERVICE_FACTORY);
Object jibArtifactInstaller = jibServiceFactory.getMethod("createJibArtifactInstaller").invoke(null);
return new JibArtifactManager(jibArtifactInstaller);
} catch (Exception e) {
- throw new ClassNotFoundException();
+ throw new ClassNotFoundException(JIB_SERVICE_FACTORY, e);
}
}
@@ -61,13 +62,13 @@
}
@Override
- public Path resolve(Artifact artifact) throws FileNotFoundException {
+ public Path resolve(Artifact artifact) throws ArtifactResolverException {
Path path;
// Use the DefaultArtifactManager to enable users to override locations
try {
ArtifactManager manager = new DefaultArtifactManager();
path = manager.resolve(artifact);
- } catch (FileNotFoundException e) {
+ } catch (ArtifactResolverException e) {
// Location hasn't been overridden, continue to automatically try to resolve the dependency
try {
HashMap<String, Object> artifactDescription = new HashMap<>();
@@ -83,8 +84,8 @@
if (artifact.unpack()) {
path = install(jibVersion, artifactDescription);
}
- } catch (Exception exception) {
- throw new FileNotFoundException("Failed to resolve the artifact " + artifact);
+ } catch (Exception e2) {
+ throw new ArtifactResolverException("Failed to resolve the artifact " + artifact, e2);
}
}
return path;