Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/ExtraClassesBuilder.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.share;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 ExtraClassesBuilder {37public static void main(String[] args) {38String[] javacOpts = Arrays.stream(args)39.takeWhile(s -> s.startsWith("-"))40.toArray(String[]::new);4142Arrays.stream(args)43.dropWhile(s -> s.startsWith("-"))44.forEach(s -> ExtraClassesBuilder.compile(s, javacOpts));45}4647private static void compile(String name, String[] args) {48Path src = Paths.get(Utils.TEST_SRC)49.resolve(name)50.toAbsolutePath();51if (Files.notExists(src)) {52throw new Error(src + " doesn't exist");53}54Path dst = Paths.get("bin")55.resolve(Paths.get(name).getFileName())56.toAbsolutePath();57try {58Files.createDirectories(dst);59} catch (IOException e) {60throw new Error("can't create dir " + dst, e);61}62JDKToolLauncher javac = JDKToolLauncher.create("javac")63.addToolArg("-d")64.addToolArg(dst.toString())65.addToolArg("-cp")66.addToolArg(Utils.TEST_CLASS_PATH);6768for (String arg : args) {69javac.addToolArg(arg);70}7172try (Stream<Path> stream = Files.walk(src)) {73stream.map(Path::toAbsolutePath)74.map(Path::toString)75.filter(s -> s.endsWith(".java"))76.forEach(javac::addToolArg);77} catch (IOException e) {78throw new Error("traverse dir " + src, e);79}8081executeTool(javac);82}8384private static void executeTool(JDKToolLauncher tool) {85String[] command = tool.getCommand();86try {87ProcessTools.executeCommand(command)88.shouldHaveExitValue(0);89} catch (Error | RuntimeException e) {90throw e;91} catch (Throwable e) {92throw new Error("execution of " + Arrays.toString(command) + " failed", e);93}94}95}969798