1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.File; 25 import java.nio.file.Files; 26 import java.nio.file.Path; 27 import java.nio.file.Paths; 28 import java.util.List; 29 import java.util.stream.Collectors; 30 31 /* 32 * @test 33 * @summary jpackager create image with --strip-native-commands test 34 * @build JPackagerHelper 35 * @modules jdk.jpackager 36 * @run main/othervm -Xmx512m JPackagerCreateImageStripNativeCommandsTest 37 */ 38 public class JPackagerCreateImageStripNativeCommandsTest { 39 private static final String runtimeBinPath; 40 41 private static final String [] CMD = { 42 "create-image", 43 "--input", "input", 44 "--output", "output", 45 "--name", "test", 46 "--main-jar", "hello.jar", 47 "--class", "Hello", 48 "--files", "hello.jar", 49 "--force", 50 "--strip-native-commands"}; 51 52 static { 53 if (JPackagerHelper.isWindows()) { 54 runtimeBinPath = "output" + File.separator + "test" 55 + File.separator + "runtime" + File.separator + "bin"; 56 } else if (JPackagerHelper.isOSX()) { 57 runtimeBinPath = "output" + File.separator + "test.app" 58 + File.separator + "Contents" 59 + File.separator + "PlugIns" + File.separator 60 + "Java.runtime" + File.separator 61 + "Contents" + File.separator 62 + "Home" + File.separator + "bin"; 63 } else { 64 runtimeBinPath = "output" + File.separator + "test" 65 + File.separator + "runtime" + File.separator + "bin"; 66 } 67 } 68 69 private static void validate() throws Exception { 70 if (JPackagerHelper.isWindows()) { 71 Path binPath = Paths.get(runtimeBinPath).toAbsolutePath(); 72 List<Path> files = Files.walk(binPath).collect(Collectors.toList()); 73 files.forEach((f) -> { 74 if (f.toString().endsWith(".exe")) { 75 throw new AssertionError( 76 "Found executable file in runtime bin folder: " 77 + f.toString()); 78 } 79 }); 80 } else { 81 File binFolder = new File(runtimeBinPath); 82 if (binFolder.exists()) { 83 throw new AssertionError("Found bin folder in runtime: " 84 + binFolder.toString()); 85 } 86 } 87 } 88 89 private static void testCreateImage() throws Exception { 90 JPackagerHelper.executeCLI(true, CMD); 91 validate(); 92 } 93 94 private static void testCreateImageToolProvider() throws Exception { 95 JPackagerHelper.executeToolProvider(true, CMD); 96 validate(); 97 } 98 99 public static void main(String[] args) throws Exception { 100 JPackagerHelper.createHelloJar(); 101 testCreateImage(); 102 testCreateImageToolProvider(); 103 } 104 105 }