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.BufferedWriter; 25 import java.io.File; 26 import java.io.FileWriter; 27 import java.io.PrintWriter; 28 29 /* 30 * @test 31 * @summary jpackager create image input/files test 32 * @build JPackagerHelper 33 * @modules jdk.jpackager 34 * @run main/othervm -Xmx512m JPackagerCreateImageInputFilesTest 35 */ 36 public class JPackagerCreateImageInputFilesTest { 37 private static final String inputFile = 38 "input" + File.separator + "input.txt"; 39 private static final String jarFile = 40 "input" + File.separator + "input.txt"; 41 private static final String appOutputPath; 42 private static final String appInputFilePath; 43 private static final String appJarFilePath; 44 45 static { 46 if (JPackagerHelper.isOSX()) { 47 appOutputPath = "output" + File.separator + "test.app" 48 + File.separator + "Contents" + File.separator + "Java"; 49 appInputFilePath = "output" + File.separator + "test.app" 50 + File.separator + "Contents" + File.separator + "Java" 51 + File.separator + "input.txt"; 52 appJarFilePath = "output" + File.separator + "test.app" 53 + File.separator + "Contents" + File.separator + "Java" 54 + File.separator + "hello.jar"; 55 } else { 56 appOutputPath = "output" + File.separator + "test" 57 + File.separator + "app"; 58 appInputFilePath = "output" + File.separator + "test" 59 + File.separator + "app" + File.separator + "input.txt"; 60 appJarFilePath = "output" + File.separator + "test" 61 + File.separator + "app" + File.separator + "hello.jar"; 62 } 63 } 64 65 private static final String [] CMD_1 = { 66 "create-image", 67 "--input", "input", 68 "--output", "output", 69 "--name", "test", 70 "--main-jar", "hello.jar", 71 "--force", 72 "--class", "Hello"}; 73 74 private static final String [] CMD_2 = { 75 "create-image", 76 "--input", "input", 77 "--output", "output", 78 "--name", "test", 79 "--main-jar", "hello.jar", 80 "--class", "Hello", 81 "--force", 82 "--files", "hello.jar"}; 83 84 private static void validate1() throws Exception { 85 File input = new File(appInputFilePath); 86 if (!input.exists()) { 87 throw new AssertionError("Unexpected file does not exist: " 88 + input.getAbsolutePath()); 89 } 90 91 File jar = new File(appJarFilePath); 92 if (!jar.exists()) { 93 throw new AssertionError("Unexpected file does not exist: " 94 + jar.getAbsolutePath()); 95 } 96 } 97 98 private static void validate2() throws Exception { 99 File input = new File(appInputFilePath); 100 if (input.exists()) { 101 throw new AssertionError("Unexpected file exist: " 102 + input.getAbsolutePath()); 103 } 104 105 File jar = new File(appJarFilePath); 106 if (!jar.exists()) { 107 throw new AssertionError("Unexpected file does not exist: " 108 + jar.getAbsolutePath()); 109 } 110 } 111 112 private static void testCreateImage() throws Exception { 113 JPackagerHelper.executeCLI(true, CMD_1); 114 validate1(); 115 116 JPackagerHelper.executeCLI(true, CMD_2); 117 validate2(); 118 } 119 120 private static void testCreateImageToolProvider() throws Exception { 121 JPackagerHelper.executeToolProvider(true, CMD_1); 122 validate1(); 123 124 JPackagerHelper.executeToolProvider(true, CMD_2); 125 validate2(); 126 } 127 128 private static void createInputFile() throws Exception { 129 try (PrintWriter out = new PrintWriter( 130 new BufferedWriter(new FileWriter(inputFile)))) { 131 out.println("jpackgaer resource file"); 132 } 133 } 134 135 private static void initCMD() { 136 File input = new File(inputFile); 137 File jar = new File(jarFile); 138 139 String inputPath = input.getAbsolutePath(); 140 String jarPath = jar.getAbsolutePath(); 141 } 142 143 public static void main(String[] args) throws Exception { 144 JPackagerHelper.createHelloJar(); 145 146 createInputFile(); 147 initCMD(); 148 149 testCreateImage(); 150 testCreateImageToolProvider(); 151 } 152 153 }