Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ConnectorsJarBuilder.java
40948 views
/*1* Copyright (c) 2018, 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 nsk.jdi;2425import jdk.test.lib.JDKToolLauncher;26import jdk.test.lib.Utils;27import jdk.test.lib.process.ProcessTools;2829import java.io.IOException;30import java.nio.file.Files;31import java.nio.file.Path;32import java.nio.file.Paths;33import java.util.Arrays;34import java.util.stream.Stream;3536public class ConnectorsJarBuilder {37public static void main(String[] args) {38Path src = Paths.get(Utils.TEST_SRC)39.resolve("connectors")40.toAbsolutePath();41if (Files.notExists(src)) {42throw new Error("connectors dir [" + src + "] doesn't exist");43}44Path classes = Paths.get("connectors","classes")45.toAbsolutePath();46try {47Files.createDirectories(classes);48} catch (IOException e) {49throw new Error("can't create dir " + classes, e);50}51compile(src, classes);52Path target = Paths.get("jars", "connectors.jar")53.toAbsolutePath();54buildJar(classes, target);55addMetaInf(src, target);56}5758private static void compile(Path src, Path classes) {59JDKToolLauncher javac = JDKToolLauncher.create("javac")60.addToolArg("-d")61.addToolArg(classes.toString())62.addToolArg("-cp")63.addToolArg(Utils.TEST_CLASS_PATH);64try (Stream<Path> stream = Files.walk(src)) {65stream.map(Path::toAbsolutePath)66.map(Path::toString)67.filter(s -> s.endsWith(".java"))68.forEach(javac::addToolArg);69} catch (IOException e) {70throw new Error("traverse dir " + src, e);71}7273executeTool(javac);74}7576private static void buildJar(Path classes, Path target) {77try {78Files.createDirectories(target.getParent());79} catch (IOException e) {80throw new Error("can't create dir " + target.getParent(), e);81}82JDKToolLauncher jar = JDKToolLauncher.create("jar")83.addToolArg("cf")84.addToolArg(target.toString())85.addToolArg("-C")86.addToolArg(classes.toString())87.addToolArg(".");88executeTool(jar);89}9091private static void addMetaInf(Path src, Path jarFile) {92Path metaInf = src.resolve("META-INF");93if (Files.exists(metaInf)) {94JDKToolLauncher jar = JDKToolLauncher.create("jar")95.addToolArg("uf")96.addToolArg(jarFile.toString())97.addToolArg("-C")98.addToolArg(src.toString())99.addToolArg("META-INF");100executeTool(jar);101}102}103104private static void executeTool(JDKToolLauncher tool) {105String[] command = tool.getCommand();106try {107ProcessTools.executeCommand(command)108.shouldHaveExitValue(0);109} catch (Error | RuntimeException e) {110throw e;111} catch (Throwable e) {112throw new Error("execution of " + Arrays.toString(command) + " failed", e);113}114}115}116117118