Path: blob/master/test/jdk/tools/jlink/ExplodedModuleNameTest.java
41145 views
/*1* Copyright (c) 2017, 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*/2223import java.io.IOException;24import java.nio.file.attribute.BasicFileAttributes;25import java.nio.file.Files;26import java.nio.file.FileVisitResult;27import java.nio.file.Path;28import java.nio.file.SimpleFileVisitor;29import java.util.spi.ToolProvider;3031import tests.Helper;32import tests.JImageGenerator;33import tests.Result;3435/*36* @test37* @bug 819298638* @summary Inconsistent handling of exploded modules in jlink39* @library ../lib40* @modules java.base/jdk.internal.jimage41* jdk.jdeps/com.sun.tools.classfile42* jdk.jlink/jdk.tools.jlink.internal43* jdk.jlink/jdk.tools.jmod44* jdk.jlink/jdk.tools.jimage45* jdk.compiler46* @build tests.*47* @run main ExplodedModuleNameTest48*/49public class ExplodedModuleNameTest {50static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")51.orElseThrow(() ->52new RuntimeException("jlink tool not found")53);5455public static void main(String[] args) throws Exception {56Helper helper = Helper.newHelper();57if (helper == null) {58System.err.println("Test not run");59return;60}6162// generate a new exploded module63String modName = "mod8192986";64Path modDir = helper.generateDefaultExplodedModule(modName).getFile();65// rename the module containing directory66Path renamedModDir = modDir.resolveSibling("modified_mod8192986");67// copy the content from original directory to modified name directory68copyDir(modDir, renamedModDir);6970Path outputDir = helper.createNewImageDir("image8192986");71JImageGenerator.getJLinkTask()72.modulePath(renamedModDir.toAbsolutePath().toString())73.output(outputDir)74.addMods(modName)75.launcher(modName + "=" + modName + "/" + modName +".Main")76.call().assertSuccess();77}7879private static void copyDir(Path srcDir, Path destDir) throws IOException {80Files.walkFileTree(srcDir, new SimpleFileVisitor<Path>() {81@Override82public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {83Path target = destDir.resolve(srcDir.relativize(dir));84Files.createDirectory(target);85return FileVisitResult.CONTINUE;86}8788@Override89public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {90Files.copy(file, destDir.resolve(srcDir.relativize(file)));91return FileVisitResult.CONTINUE;92}93});94}95}969798