Skip to content
Permalink
Browse files

8239026: Support non-maven artifacts by JibArtifactManager

Reviewed-by: erikj
  • Loading branch information
lmesnik committed Feb 18, 2020
1 parent bf6c14f commit a6dbc71114821f332fa2b82b71c732ef43b72b81
@@ -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 static JibArtifactManager newInstance() throws ClassNotFoundException {
}
}

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 @@ private Path invokeInstallerMethod(String methodName, String jibVersion,

@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;

0 comments on commit a6dbc71

Please sign in to comment.