8175300: Enable artifact resolution for jtreg tests
Reviewed-by: ihse, gtriantafill
This commit is contained in:
parent
e0ddba9b92
commit
a200f792bf
@ -187,6 +187,9 @@ TOOLCHAIN_MISC_CHECKS
|
||||
# Setup the JTReg Regression Test Harness.
|
||||
TOOLCHAIN_SETUP_JTREG
|
||||
|
||||
# Setup Jib dependency tool
|
||||
TOOLCHAIN_SETUP_JIB
|
||||
|
||||
FLAGS_SETUP_INIT_FLAGS
|
||||
|
||||
# Now we can test some aspects on the target using configure macros.
|
||||
|
@ -786,6 +786,7 @@ ARFLAGS
|
||||
COMPILER_BINDCMD_FILE_FLAG
|
||||
COMPILER_COMMAND_FILE_FLAG
|
||||
COMPILER_TARGET_BITS_FLAG
|
||||
JIB_JAR
|
||||
JT_HOME
|
||||
JTREGEXE
|
||||
HOTSPOT_TOOLCHAIN_TYPE
|
||||
@ -1172,6 +1173,7 @@ with_extra_ldflags
|
||||
with_toolchain_version
|
||||
with_build_devkit
|
||||
with_jtreg
|
||||
with_jib
|
||||
with_abi_profile
|
||||
enable_warnings_as_errors
|
||||
with_native_debug_symbols
|
||||
@ -2108,6 +2110,7 @@ Optional Packages:
|
||||
dependent]
|
||||
--with-build-devkit Devkit to use for the build platform toolchain
|
||||
--with-jtreg Regression Test Harness [probed]
|
||||
--with-jib Jib dependency management tool [not used]
|
||||
--with-abi-profile specify ABI profile for ARM builds
|
||||
(arm-vfp-sflt,arm-vfp-hflt,arm-sflt,
|
||||
armv5-vfp-sflt,armv6-vfp-hflt,arm64,aarch64)
|
||||
@ -4894,7 +4897,7 @@ VALID_JVM_VARIANTS="server client minimal core zero zeroshark custom"
|
||||
|
||||
|
||||
#
|
||||
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2011, 2017, 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
|
||||
@ -5025,6 +5028,9 @@ TOOLCHAIN_MINIMUM_VERSION_xlc=""
|
||||
# Setup the JTReg Regression Test Harness.
|
||||
|
||||
|
||||
# Setup the JIB dependency resolver
|
||||
|
||||
|
||||
#
|
||||
# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
@ -5126,7 +5132,7 @@ VS_SDK_PLATFORM_NAME_2013=
|
||||
#CUSTOM_AUTOCONF_INCLUDE
|
||||
|
||||
# Do not change or remove the following line, it is needed for consistency checks:
|
||||
DATE_WHEN_GENERATED=1487957473
|
||||
DATE_WHEN_GENERATED=1489070933
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
@ -48223,6 +48229,41 @@ $as_echo "$tool_specified" >&6; }
|
||||
|
||||
|
||||
|
||||
# Setup Jib dependency tool
|
||||
|
||||
|
||||
# Check whether --with-jib was given.
|
||||
if test "${with_jib+set}" = set; then :
|
||||
withval=$with_jib;
|
||||
fi
|
||||
|
||||
|
||||
if test "x$with_jib" = xno || test "x$with_jib" = x; then
|
||||
# jib disabled
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for jib" >&5
|
||||
$as_echo_n "checking for jib... " >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
elif test "x$with_jib" = xyes; then
|
||||
as_fn_error $? "Must supply a value to --with-jib" "$LINENO" 5
|
||||
else
|
||||
JIB_HOME="${with_jib}"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for jib" >&5
|
||||
$as_echo_n "checking for jib... " >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${JIB_HOME}" >&5
|
||||
$as_echo "${JIB_HOME}" >&6; }
|
||||
if test ! -d "${JIB_HOME}"; then
|
||||
as_fn_error $? "--with-jib must be a directory" "$LINENO" 5
|
||||
fi
|
||||
JIB_JAR=$(ls ${JIB_HOME}/lib/jib-*.jar)
|
||||
if test ! -f "${JIB_JAR}"; then
|
||||
as_fn_error $? "Could not find jib jar file in ${JIB_HOME}" "$LINENO" 5
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# COMPILER_TARGET_BITS_FLAG : option for selecting 32- or 64-bit output
|
||||
# COMPILER_COMMAND_FILE_FLAG : option for passing a command file to the compiler
|
||||
|
@ -671,6 +671,7 @@ SETFILE:=@SETFILE@
|
||||
XATTR:=@XATTR@
|
||||
JT_HOME:=@JT_HOME@
|
||||
JTREGEXE:=@JTREGEXE@
|
||||
JIB_JAR:=@JIB_JAR@
|
||||
XCODEBUILD=@XCODEBUILD@
|
||||
DTRACE := @DTRACE@
|
||||
FIXPATH:=@FIXPATH@
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2011, 2017, 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
|
||||
@ -964,3 +964,31 @@ AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG],
|
||||
AC_SUBST(JT_HOME)
|
||||
AC_SUBST(JTREGEXE)
|
||||
])
|
||||
|
||||
# Setup the JIB dependency resolver
|
||||
AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JIB],
|
||||
[
|
||||
AC_ARG_WITH(jib, [AS_HELP_STRING([--with-jib],
|
||||
[Jib dependency management tool @<:@not used@:>@])])
|
||||
|
||||
if test "x$with_jib" = xno || test "x$with_jib" = x; then
|
||||
# jib disabled
|
||||
AC_MSG_CHECKING([for jib])
|
||||
AC_MSG_RESULT(no)
|
||||
elif test "x$with_jib" = xyes; then
|
||||
AC_MSG_ERROR([Must supply a value to --with-jib])
|
||||
else
|
||||
JIB_HOME="${with_jib}"
|
||||
AC_MSG_CHECKING([for jib])
|
||||
AC_MSG_RESULT(${JIB_HOME})
|
||||
if test ! -d "${JIB_HOME}"; then
|
||||
AC_MSG_ERROR([--with-jib must be a directory])
|
||||
fi
|
||||
JIB_JAR=$(ls ${JIB_HOME}/lib/jib-*.jar)
|
||||
if test ! -f "${JIB_JAR}"; then
|
||||
AC_MSG_ERROR([Could not find jib jar file in ${JIB_HOME}])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_SUBST(JIB_JAR)
|
||||
])
|
||||
|
@ -236,7 +236,7 @@ var getJibProfilesCommon = function (input, data) {
|
||||
|
||||
// These are the base setttings for all the main build profiles.
|
||||
common.main_profile_base = {
|
||||
dependencies: ["boot_jdk", "gnumake", "jtreg"],
|
||||
dependencies: ["boot_jdk", "gnumake", "jtreg", "jib"],
|
||||
default_make_targets: ["product-bundles", "test-bundles"],
|
||||
configure_args: [
|
||||
"--with-version-opt=" + common.build_id,
|
||||
@ -555,7 +555,7 @@ var getJibProfilesProfiles = function (input, common, data) {
|
||||
"run-test-jprt": {
|
||||
target_os: input.build_os,
|
||||
target_cpu: input.build_cpu,
|
||||
dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit" ],
|
||||
dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
|
||||
labels: "test",
|
||||
environment: {
|
||||
"JT_JAVA": common.boot_jdk_home
|
||||
@ -565,7 +565,7 @@ var getJibProfilesProfiles = function (input, common, data) {
|
||||
"run-test": {
|
||||
target_os: input.build_os,
|
||||
target_cpu: input.build_cpu,
|
||||
dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit" ],
|
||||
dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
|
||||
labels: "test",
|
||||
environment: {
|
||||
"JT_JAVA": common.boot_jdk_home
|
||||
@ -582,7 +582,7 @@ var getJibProfilesProfiles = function (input, common, data) {
|
||||
var testOnlyProfilesPrebuilt = {
|
||||
"run-test-prebuilt": {
|
||||
src: "src.conf",
|
||||
dependencies: [ "jtreg", "gnumake", testedProfile + ".jdk",
|
||||
dependencies: [ "jtreg", "gnumake", "jib", testedProfile + ".jdk",
|
||||
testedProfile + ".test", "src.full"
|
||||
],
|
||||
work_dir: input.get("src.full", "install_path") + "/test",
|
||||
@ -913,7 +913,18 @@ var getJibProfilesDependencies = function (input, common) {
|
||||
ext: "tar.gz",
|
||||
revision: "2.3.4+1.0",
|
||||
module: "freetype-" + input.target_platform
|
||||
}
|
||||
},
|
||||
|
||||
// This adds java jib as a dependency for the test artifacts resolver
|
||||
jib: {
|
||||
organization: "com.oracle.java.jib",
|
||||
ext: "zip",
|
||||
classifier: "distribution",
|
||||
revision: "3.0-SNAPSHOT",
|
||||
environment_name: "JIB_JAR",
|
||||
environment_value: input.get("jib", "install_path")
|
||||
+ "/jib-3.0-SNAPSHOT-distribution/lib/jib-3.0-SNAPSHOT.jar"
|
||||
}
|
||||
};
|
||||
|
||||
// Need to add a value for the Visual Studio tools variable to make
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2011, 2017, 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
|
||||
@ -37,7 +37,7 @@ define RunTests
|
||||
JT_HOME=$(JT_HOME) PRODUCT_HOME=$(strip $2) \
|
||||
TEST_IMAGE_DIR=$(TEST_IMAGE_DIR) \
|
||||
ALT_OUTPUTDIR=$(OUTPUT_ROOT) TEST_JOBS=$(TEST_JOBS) \
|
||||
JT_JAVA=$(BOOT_JDK) \
|
||||
JT_JAVA=$(BOOT_JDK) JIB_JAR=$(JIB_JAR) \
|
||||
JOBS=$(JOBS) $1) || true
|
||||
endef
|
||||
|
||||
|
@ -375,7 +375,9 @@ ifneq ($(VS120COMNTOOLS), )
|
||||
endif
|
||||
# Set other vm and test options
|
||||
JTREG_TEST_OPTIONS += $(JAVA_ARGS:%=-javaoptions:%) $(JAVA_OPTIONS:%=-vmoption:%) $(JAVA_VM_ARGS:%=-vmoption:%)
|
||||
|
||||
ifneq ($(JIB_JAR), )
|
||||
JTREG_BASIC_OPTIONS += -cpa:$(shell $(GETMIXEDPATH) "$(JIB_JAR)")
|
||||
endif
|
||||
ifeq ($(IGNORE_MARKED_TESTS), true)
|
||||
# Option to tell jtreg to not run tests marked with "ignore"
|
||||
ifeq ($(PLATFORM), windows)
|
||||
|
44
test/lib/jdk/test/lib/artifacts/Artifact.java
Normal file
44
test/lib/jdk/test/lib/artifacts/Artifact.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.test.lib.artifacts;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Repeatable(ArtifactContainer.class)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Artifact {
|
||||
String organization();
|
||||
String name();
|
||||
String revision();
|
||||
String extension();
|
||||
String classifier() default "";
|
||||
boolean unpack() default true;
|
||||
}
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface ArtifactContainer {
|
||||
Artifact[] value();
|
||||
}
|
31
test/lib/jdk/test/lib/artifacts/ArtifactManager.java
Normal file
31
test/lib/jdk/test/lib/artifacts/ArtifactManager.java
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.test.lib.artifacts;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface ArtifactManager {
|
||||
public Path resolve(Artifact artifact) throws FileNotFoundException;
|
||||
}
|
68
test/lib/jdk/test/lib/artifacts/ArtifactResolver.java
Normal file
68
test/lib/jdk/test/lib/artifacts/ArtifactResolver.java
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.test.lib.artifacts;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ArtifactResolver {
|
||||
public static HashMap<String, Path> resolve(Class klass) throws FileNotFoundException {
|
||||
ArtifactManager manager = new DefaultArtifactManager();
|
||||
try {
|
||||
String managerName = System.getProperty("jdk.test.lib.artifacts.artifactmanager");
|
||||
if (managerName != null) {
|
||||
manager = (ArtifactManager) Class.forName(managerName).newInstance();
|
||||
} else {
|
||||
manager = JibArtifactManager.newInstance();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// If we end up here, we'll use the DefaultArtifactManager
|
||||
}
|
||||
|
||||
ArtifactContainer artifactContainer = (ArtifactContainer) klass.getAnnotation(ArtifactContainer.class);
|
||||
HashMap<String, Path> locations = new HashMap<>();
|
||||
Artifact[] artifacts;
|
||||
|
||||
if (artifactContainer == null) {
|
||||
artifacts = new Artifact[]{(Artifact) klass.getAnnotation(Artifact.class)};
|
||||
} else {
|
||||
artifacts = artifactContainer.value();
|
||||
}
|
||||
for (Artifact artifact : artifacts) {
|
||||
locations.put(artifactName(artifact), manager.resolve(artifact));
|
||||
}
|
||||
|
||||
return locations;
|
||||
}
|
||||
|
||||
private static String artifactName(Artifact artifact) {
|
||||
// Format of the artifact name is <organization>.<name>-<revision>(-<classifier>)
|
||||
String name = String.format("%s.%s-%s", artifact.organization(), artifact.name(), artifact.revision());
|
||||
if (artifact.classifier().length() != 0) {
|
||||
name = name +"-" + artifact.classifier();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
45
test/lib/jdk/test/lib/artifacts/DefaultArtifactManager.java
Normal file
45
test/lib/jdk/test/lib/artifacts/DefaultArtifactManager.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
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 FileNotFoundException {
|
||||
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));
|
||||
}
|
||||
return Paths.get(location);
|
||||
}
|
||||
|
||||
private static String artifactProperty(String name) {
|
||||
return "jdk.test.lib.artifacts." + name;
|
||||
}
|
||||
}
|
92
test/lib/jdk/test/lib/artifacts/JibArtifactManager.java
Normal file
92
test/lib/jdk/test/lib/artifacts/JibArtifactManager.java
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.test.lib.artifacts;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JibArtifactManager implements ArtifactManager {
|
||||
private static String jibVersion = "1.0";
|
||||
private Object installerObject;
|
||||
|
||||
private JibArtifactManager(Object o) {
|
||||
installerObject = o;
|
||||
}
|
||||
|
||||
public static JibArtifactManager newInstance() throws ClassNotFoundException {
|
||||
try {
|
||||
Class jibServiceFactory = Class.forName("com.oracle.jib.api.JibServiceFactory");
|
||||
Object jibArtifactInstaller = jibServiceFactory.getMethod("createJibArtifactInstaller").invoke(null);
|
||||
return new JibArtifactManager(jibArtifactInstaller);
|
||||
} catch (Exception e) {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
private Path download(String jibVersion, HashMap<String, Object> artifactDescription) throws Exception {
|
||||
return invokeInstallerMethod("download", jibVersion, artifactDescription);
|
||||
}
|
||||
|
||||
private Path install(String jibVersion, HashMap<String, Object> artifactDescription) throws Exception {
|
||||
return invokeInstallerMethod("install", jibVersion, artifactDescription);
|
||||
}
|
||||
|
||||
private Path invokeInstallerMethod(String methodName, String jibVersion, HashMap<String, Object> artifactDescription) throws Exception {
|
||||
Method m = Class.forName("com.oracle.jib.api.JibArtifactInstaller").getMethod(methodName, String.class, Map.class);
|
||||
return (Path)m.invoke(installerObject, jibVersion, artifactDescription);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path resolve(Artifact artifact) throws FileNotFoundException {
|
||||
Path path;
|
||||
// Use the DefaultArtifactManager to enable users to override locations
|
||||
try {
|
||||
ArtifactManager manager = new DefaultArtifactManager();
|
||||
path = manager.resolve(artifact);
|
||||
} catch (FileNotFoundException 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()) {
|
||||
path = install(jibVersion, artifactDescription);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
throw new FileNotFoundException("Failed to resolve the artifact " + artifact);
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user