Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/IndifiedClassesBuilder.java
41155 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 vm.mlvm.share;2425import jdk.test.lib.Utils;2627import java.io.File;28import java.io.IOException;29import java.nio.file.FileVisitResult;30import java.nio.file.Files;31import java.nio.file.Path;32import java.nio.file.Paths;33import java.nio.file.SimpleFileVisitor;34import java.nio.file.StandardCopyOption;35import java.nio.file.attribute.BasicFileAttributes;36import java.util.Arrays;37import java.util.stream.Stream;3839public class IndifiedClassesBuilder {40public static void main(String... args) {41Path[] targets;42if (args.length != 0) {43targets = Arrays.stream(args)44.map(Paths::get)45.toArray(Path[]::new);46for (Path path : targets) {47if (Files.notExists(path)) {48throw new Error(path + " doesn't exist");49}50if (!Files.isDirectory(path)) {51throw new Error(path + " isn't a directory");52}53}54} else {55targets = Arrays.stream(Utils.TEST_CLASS_PATH.split(File.pathSeparator))56.map(Paths::get)57.toArray(Path[]::new);58}59for (Path path : targets) {60if (!Files.isDirectory(path)) {61continue;62}63try (Stream<Path> files = Files.walk(path)) {64files.filter(65p -> {66String s = p.getFileName().toString();67return s.startsWith("INDIFY_") && s.endsWith(".class");68})69.forEach( p -> IndifiedClassesBuilder.indify(p, path));70} catch (IOException e) {71throw new Error("can't traverse path " + path);72}73}74}7576private static void indify(Path file, Path path) {77Path tmp = Paths.get("indify.tmp");78try {79Files.createDirectories(tmp);80} catch (IOException e) {81throw new Error("can't create dir " + tmp, e);82}83try {84vm.mlvm.tools.Indify.main(85"--all",86"--overwrite",87"--transitionalJSR292=no",88"--dest", tmp.toAbsolutePath().toString(),89file.toAbsolutePath().toString());9091// workaround for "nested" classpaths92if (Files.exists(tmp.resolve(path.relativize(file)))) {93Files.copy(tmp.resolve(path.relativize(file)), file, StandardCopyOption.REPLACE_EXISTING);94}9596delete(tmp);97} catch (IOException e) {98throw new Error("can't indify " + file, e);99}100}101102private static void delete(Path dir) throws IOException {103Files.walkFileTree(dir, new SimpleFileVisitor<>() {104@Override105public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {106FileVisitResult result = super.visitFile(file, attrs);107Files.delete(file);108return result;109}110111@Override112public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {113FileVisitResult result = super.postVisitDirectory(dir, exc);114Files.delete(dir);115return result;116}117});118}119}120121122