Path: blob/master/test/jdk/tools/jlink/NativeTest.java
41144 views
/*1* Copyright (c) 2015, 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*/2223/*24* @test25* @summary Test config, cmd and lib directories of jmod.26* @author Andrei Eremeev27* @library ../lib28* @modules java.base/jdk.internal.jimage29* jdk.jdeps/com.sun.tools.classfile30* jdk.jlink/jdk.tools.jlink.internal31* jdk.jlink/jdk.tools.jmod32* jdk.jlink/jdk.tools.jimage33* jdk.compiler34* @build tests.*35* @run main NativeTest36*/3738import java.io.File;39import java.io.IOException;40import java.nio.file.Files;41import java.nio.file.Path;42import java.util.Arrays;4344import tests.Helper;45import tests.JImageGenerator;4647public class NativeTest {4849private final Helper helper;5051public NativeTest(Helper helper) {52this.helper = helper;53}5455public static void main(String[] args) throws IOException {56Helper helper = Helper.newHelper();57if (helper == null) {58System.err.println("Not run");59return;60}61new NativeTest(helper).test();62}6364public void test() throws IOException {65String moduleName = "native_library";66Path classesDir = helper.generateModuleCompiledClasses(67helper.getJmodSrcDir(), helper.getJmodClassesDir(), moduleName);68Path libsDir = helper.getJmodDir().resolve("lib").resolve(moduleName);69Path configDir = helper.getJmodDir().resolve("config").resolve(moduleName);70Path cmdDir = helper.getJmodDir().resolve("cmd").resolve(moduleName);7172Path config = writeFile(configDir.resolve("config.txt"), "AAAA\nBBBB");73Path cmd = writeFile(cmdDir.resolve("ls.sh"), "ls");74Path lib = writeFile(libsDir.resolve("native.so"), "native library");7576JImageGenerator.getJModTask()77.addClassPath(classesDir)78.addNativeLibraries(libsDir)79.addCmds(cmdDir)80.addConfig(configDir)81.jmod(helper.createNewJmodFile(moduleName))82.create()83.assertSuccess();8485String[] expectedFiles = new String[] {86"bin" + File.separator + cmd.getFileName(),87"conf" + File.separator + config.getFileName(),88"lib" + File.separator + lib.getFileName()89};90Path image = JImageGenerator.getJLinkTask()91.modulePath(helper.defaultModulePath())92.addMods(moduleName)93.output(helper.createNewImageDir(moduleName))94.call().assertSuccess();95helper.checkImage(image, moduleName, null, null, expectedFiles);96}9798private Path writeFile(Path path, String content) throws IOException {99if (path.getParent() != null) {100Files.createDirectories(path.getParent());101}102Files.write(path, Arrays.asList(content.split("\n")));103return path;104}105}106107108