# HG changeset patch # User ctornqvi # Date 1489168601 18000 # Node ID 822ca950ddaa02b74fc4be274a92db5d8123955a # Parent 2b1a95acc04381fcfba5971e0de744e7fd7b5737 8175300: Enable artifact resolution for jtreg tests Reviewed-by: ihse, gtriantafill diff -r 2b1a95acc043 -r 822ca950ddaa common/autoconf/configure.ac --- a/common/autoconf/configure.ac Tue Mar 07 11:28:09 2017 -0500 +++ b/common/autoconf/configure.ac Fri Mar 10 12:56:41 2017 -0500 @@ -187,6 +187,9 @@ # 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. diff -r 2b1a95acc043 -r 822ca950ddaa common/autoconf/generated-configure.sh --- a/common/autoconf/generated-configure.sh Tue Mar 07 11:28:09 2017 -0500 +++ b/common/autoconf/generated-configure.sh Fri Mar 10 12:56:41 2017 -0500 @@ -786,6 +786,7 @@ 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_toolchain_version with_build_devkit with_jtreg +with_jib with_abi_profile enable_warnings_as_errors with_native_debug_symbols @@ -2108,6 +2110,7 @@ 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 @@ # -# 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 @@ # 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 @@ #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 @@ +# 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 diff -r 2b1a95acc043 -r 822ca950ddaa common/autoconf/spec.gmk.in --- a/common/autoconf/spec.gmk.in Tue Mar 07 11:28:09 2017 -0500 +++ b/common/autoconf/spec.gmk.in Fri Mar 10 12:56:41 2017 -0500 @@ -671,6 +671,7 @@ XATTR:=@XATTR@ JT_HOME:=@JT_HOME@ JTREGEXE:=@JTREGEXE@ +JIB_JAR:=@JIB_JAR@ XCODEBUILD=@XCODEBUILD@ DTRACE := @DTRACE@ FIXPATH:=@FIXPATH@ diff -r 2b1a95acc043 -r 822ca950ddaa common/autoconf/toolchain.m4 --- a/common/autoconf/toolchain.m4 Tue Mar 07 11:28:09 2017 -0500 +++ b/common/autoconf/toolchain.m4 Fri Mar 10 12:56:41 2017 -0500 @@ -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_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) +]) diff -r 2b1a95acc043 -r 822ca950ddaa common/conf/jib-profiles.js --- a/common/conf/jib-profiles.js Tue Mar 07 11:28:09 2017 -0500 +++ b/common/conf/jib-profiles.js Fri Mar 10 12:56:41 2017 -0500 @@ -236,7 +236,7 @@ // 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 @@ "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 @@ "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 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 @@ 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 diff -r 2b1a95acc043 -r 822ca950ddaa make/MainSupport.gmk --- a/make/MainSupport.gmk Tue Mar 07 11:28:09 2017 -0500 +++ b/make/MainSupport.gmk Fri Mar 10 12:56:41 2017 -0500 @@ -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 @@ 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 diff -r 2b1a95acc043 -r 822ca950ddaa test/TestCommon.gmk --- a/test/TestCommon.gmk Tue Mar 07 11:28:09 2017 -0500 +++ b/test/TestCommon.gmk Fri Mar 10 12:56:41 2017 -0500 @@ -375,7 +375,9 @@ 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) diff -r 2b1a95acc043 -r 822ca950ddaa test/lib/jdk/test/lib/artifacts/Artifact.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/lib/jdk/test/lib/artifacts/Artifact.java Fri Mar 10 12:56:41 2017 -0500 @@ -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(); +} diff -r 2b1a95acc043 -r 822ca950ddaa test/lib/jdk/test/lib/artifacts/ArtifactManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/lib/jdk/test/lib/artifacts/ArtifactManager.java Fri Mar 10 12:56:41 2017 -0500 @@ -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; +} diff -r 2b1a95acc043 -r 822ca950ddaa test/lib/jdk/test/lib/artifacts/ArtifactResolver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/lib/jdk/test/lib/artifacts/ArtifactResolver.java Fri Mar 10 12:56:41 2017 -0500 @@ -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 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 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 .-(-) + String name = String.format("%s.%s-%s", artifact.organization(), artifact.name(), artifact.revision()); + if (artifact.classifier().length() != 0) { + name = name +"-" + artifact.classifier(); + } + return name; + } +} diff -r 2b1a95acc043 -r 822ca950ddaa test/lib/jdk/test/lib/artifacts/DefaultArtifactManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/lib/jdk/test/lib/artifacts/DefaultArtifactManager.java Fri Mar 10 12:56:41 2017 -0500 @@ -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; + } +} diff -r 2b1a95acc043 -r 822ca950ddaa test/lib/jdk/test/lib/artifacts/JibArtifactManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/lib/jdk/test/lib/artifacts/JibArtifactManager.java Fri Mar 10 12:56:41 2017 -0500 @@ -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 artifactDescription) throws Exception { + return invokeInstallerMethod("download", jibVersion, artifactDescription); + } + + private Path install(String jibVersion, HashMap artifactDescription) throws Exception { + return invokeInstallerMethod("install", jibVersion, artifactDescription); + } + + private Path invokeInstallerMethod(String methodName, String jibVersion, HashMap 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 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; + } +}