8199352: The Jib artifact resolver in test lib needs to print better error messages
Reviewed-by: iignatyev, ihse
This commit is contained in:
parent
b86d96a381
commit
1926d24306
test
hotspot/jtreg
lib/jdk/test/lib/artifacts
@ -26,11 +26,11 @@ package applications.jcstress;
|
||||
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 @@ public class JcstressRunner {
|
||||
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);
|
||||
}
|
||||
|
@ -31,13 +31,20 @@ import jdk.test.lib.process.ProcessTools;
|
||||
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(),
|
||||
|
@ -26,9 +26,9 @@ package compiler.aot;
|
||||
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 @@ public class AotCompiler {
|
||||
.resolve("ld");
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (ArtifactResolverException e) {
|
||||
System.err.println("artifact resolution error: " + e);
|
||||
// let jaotc try to find linker
|
||||
return null;
|
||||
|
@ -27,5 +27,5 @@ import java.io.FileNotFoundException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface ArtifactManager {
|
||||
public Path resolve(Artifact artifact) throws FileNotFoundException;
|
||||
public Path resolve(Artifact artifact) throws ArtifactResolverException;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import java.util.HashMap;
|
||||
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");
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -29,12 +29,13 @@ import java.nio.file.Paths;
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import java.util.HashMap;
|
||||
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 class JibArtifactManager implements ArtifactManager {
|
||||
|
||||
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 @@ public class JibArtifactManager implements ArtifactManager {
|
||||
}
|
||||
|
||||
@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 @@ public class JibArtifactManager implements ArtifactManager {
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user