Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/BuildJar.java
41161 views
/*1* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package vm.runtime.defmeth.shared;2425import jdk.test.lib.JDKToolLauncher;26import jdk.test.lib.Utils;27import jdk.test.lib.process.ProcessTools;28import jdk.test.lib.util.JarUtils;2930import java.io.File;31import java.nio.file.Files;32import java.nio.file.Path;33import java.nio.file.Paths;34import java.util.Arrays;3536/**37* Build {@code retransform.jar} in current directory using38* {@code vm/runtime/defmeth/shared/retransform.mf} and classes from39* {@code vm.runtime.defmeth.shared} package.40*/41public class BuildJar {42public static void main(String[] args) {43Path manifest = Paths.get(Utils.TEST_ROOT)44.resolve("vmTestbase")45.resolve("vm")46.resolve("runtime")47.resolve("defmeth")48.resolve("shared")49.resolve("retransform.mf")50.toAbsolutePath();51if (Files.notExists(manifest)) {52throw new Error("can't find manifest file: " + manifest);53}5455Path file = foundInClassPath(Util.Transformer.class).toAbsolutePath();56// Util$Transformer.class is in vm/runtime/defmeth/shared57Path dir = file.getParent()58.getParent()59.getParent()60.getParent()61.getParent()62.toAbsolutePath();6364JDKToolLauncher jar = JDKToolLauncher.create("jar")65.addToolArg("cmf")66.addToolArg(manifest.toString())67.addToolArg("retransform.jar")68.addToolArg("-C")69.addToolArg(dir.toString())70.addToolArg(dir.relativize(file).toString());71String[] command = jar.getCommand();72try {73ProcessTools.executeCommand(command)74.shouldHaveExitValue(0);75} catch (Error | RuntimeException e) {76throw e;77} catch (Throwable e) {78throw new Error("execution of jar [" + Arrays.toString(command) + "] failed", e);79}80}8182private static Path foundInClassPath(Class<?> aClass) {83Path file = Paths.get(aClass.getName()84.replace(".", File.separator) + ".class");85for (String dir : Utils.TEST_CLASS_PATH.split(File.pathSeparator)) {86Path result = Paths.get(dir).resolve(file);87if (Files.exists(result)) {88return result;89}90}91throw new Error("can't find " + file + " in " + Utils.TEST_CLASS_PATH);92}93}94959697