mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8239026: Support non-maven artifacts by JibArtifactManager
Reviewed-by: erikj
This commit is contained in:
parent
bf6c14f034
commit
a6dbc71114
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,23 +23,23 @@
|
||||
|
||||
package jdk.test.lib.artifacts;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class DefaultArtifactManager implements ArtifactManager {
|
||||
@Override
|
||||
public Path resolve(Artifact artifact) throws ArtifactResolverException {
|
||||
String name = artifact.name();
|
||||
return resolve(artifact.name());
|
||||
}
|
||||
|
||||
public Path resolve(String name) throws ArtifactResolverException {
|
||||
String location = System.getProperty(artifactProperty(name));
|
||||
if (location == null) {
|
||||
throw new ArtifactResolverException("Couldn't automatically resolve dependency for " + name
|
||||
+ " , revision " + artifact.revision() + "\n" +
|
||||
throw new ArtifactResolverException("Couldn't automatically resolve dependency for " + name + "\n" +
|
||||
"Please specify the location using " + artifactProperty(name));
|
||||
}
|
||||
return Paths.get(location);
|
||||
}
|
||||
|
||||
private static String artifactProperty(String name) {
|
||||
return "jdk.test.lib.artifacts." + name;
|
||||
}
|
||||
|
||||
@ -88,16 +88,16 @@ public class JibArtifactManager implements ArtifactManager {
|
||||
}
|
||||
}
|
||||
|
||||
private Path download(String jibVersion, HashMap<String, Object> artifactDescription) throws Exception {
|
||||
private Path download(String jibVersion, Map<String, Object> artifactDescription) throws Exception {
|
||||
return invokeInstallerMethod("download", jibVersion, artifactDescription);
|
||||
}
|
||||
|
||||
private Path install(String jibVersion, HashMap<String, Object> artifactDescription) throws Exception {
|
||||
private Path install(String jibVersion, Map<String, Object> artifactDescription) throws Exception {
|
||||
return invokeInstallerMethod("install", jibVersion, artifactDescription);
|
||||
}
|
||||
|
||||
private Path invokeInstallerMethod(String methodName, String jibVersion,
|
||||
HashMap<String, Object> artifactDescription) throws Exception {
|
||||
Map<String, Object> artifactDescription) throws Exception {
|
||||
// Temporarily replace the context classLoader
|
||||
Thread currentThread = Thread.currentThread();
|
||||
ClassLoader oldContextLoader = currentThread.getContextClassLoader();
|
||||
@ -113,29 +113,33 @@ public class JibArtifactManager implements ArtifactManager {
|
||||
|
||||
@Override
|
||||
public Path resolve(Artifact artifact) throws ArtifactResolverException {
|
||||
HashMap<String, Object> artifactDescription = new HashMap<>();
|
||||
artifactDescription.put("module", artifact.name());
|
||||
artifactDescription.put("organization", artifact.organization());
|
||||
artifactDescription.put("ext", artifact.extension());
|
||||
artifactDescription.put("revision", artifact.revision());
|
||||
if (artifact.classifier().length() > 0) {
|
||||
artifactDescription.put("classifier", artifact.classifier());
|
||||
}
|
||||
return resolve(artifact.name(), artifactDescription, artifact.unpack());
|
||||
}
|
||||
|
||||
public Path resolve(String name, Map<String, Object> artifactDescription, boolean unpack)
|
||||
throws ArtifactResolverException {
|
||||
Path path;
|
||||
// Use the DefaultArtifactManager to enable users to override locations
|
||||
try {
|
||||
ArtifactManager manager = new DefaultArtifactManager();
|
||||
path = manager.resolve(artifact);
|
||||
DefaultArtifactManager manager = new DefaultArtifactManager();
|
||||
path = manager.resolve(name);
|
||||
} catch (ArtifactResolverException e) {
|
||||
// Location hasn't been overridden, continue to automatically try to resolve the dependency
|
||||
try {
|
||||
HashMap<String, Object> artifactDescription = new HashMap<>();
|
||||
artifactDescription.put("module", artifact.name());
|
||||
artifactDescription.put("organization", artifact.organization());
|
||||
artifactDescription.put("ext", artifact.extension());
|
||||
artifactDescription.put("revision", artifact.revision());
|
||||
if (artifact.classifier().length() > 0) {
|
||||
artifactDescription.put("classifier", artifact.classifier());
|
||||
}
|
||||
|
||||
path = download(jibVersion, artifactDescription);
|
||||
if (artifact.unpack()) {
|
||||
if (unpack) {
|
||||
path = install(jibVersion, artifactDescription);
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
throw new ArtifactResolverException("Failed to resolve the artifact " + artifact, e2);
|
||||
throw new ArtifactResolverException("Failed to resolve the artifact " + name, e2);
|
||||
}
|
||||
}
|
||||
return path;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user