1 /* 2 * Copyright (c) 2018, 2019, 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 jpackage create image input/files test 32 * @library ../helpers 33 * @build JPackageHelper 34 * @build JPackagePath 35 * @modules jdk.jpackage 36 * @run main/othervm -Xmx512m JPackageCreateImageInputFilesTest 37 */ 38 public class JPackageCreateImageInputFilesTest { 39 private static final String inputFile = 40 "input" + File.separator + "input.txt"; 41 private static final String jarFile = 42 "input" + File.separator + "hello.jar"; 43 private static final String appInputFilePath; 44 private static final String appJarFilePath; 45 46 static { 47 appInputFilePath = JPackagePath.getAppWorkingDir() + File.separator + "input.txt"; 48 appJarFilePath = JPackagePath.getAppWorkingDir() + File.separator + "hello.jar"; 49 } 50 51 private static final String [] CMD_1 = { 52 "create-image", 53 "--input", "input", 54 "--output", "output", 55 "--name", "test", 56 "--main-jar", "hello.jar", 57 "--overwrite", 58 "--main-class", "Hello"}; 59 60 private static final String [] CMD_2 = { 61 "create-image", 62 "--input", "input", 63 "--output", "output", 64 "--name", "test", 65 "--main-jar", "hello.jar", 66 "--main-class", "Hello", 67 "--overwrite", 68 "--files", "hello.jar"}; 69 70 private static void validate1() throws Exception { 71 File input = new File(appInputFilePath); 72 if (!input.exists()) { 73 throw new AssertionError("Unexpected file does not exist: " 74 + input.getAbsolutePath()); 75 } 76 77 File jar = new File(appJarFilePath); 78 if (!jar.exists()) { 79 throw new AssertionError("Unexpected file does not exist: " 80 + jar.getAbsolutePath()); 81 } 82 } 83 84 private static void validate2() throws Exception { 85 File input = new File(appInputFilePath); 86 if (input.exists()) { 87 throw new AssertionError("Unexpected file 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 testCreateImage() throws Exception { 99 JPackageHelper.executeCLI(true, CMD_1); 100 validate1(); 101 102 JPackageHelper.executeCLI(true, CMD_2); 103 validate2(); 104 } 105 106 private static void testCreateImageToolProvider() throws Exception { 107 JPackageHelper.executeToolProvider(true, CMD_1); 108 validate1(); 109 110 JPackageHelper.executeToolProvider(true, CMD_2); 111 validate2(); 112 } 113 114 private static void createInputFile() throws Exception { 115 try (PrintWriter out = new PrintWriter( 116 new BufferedWriter(new FileWriter(inputFile)))) { 117 out.println("jpackgaer resource file"); 118 } 119 } 120 121 public static void main(String[] args) throws Exception { 122 JPackageHelper.createHelloImageJar(); 123 124 createInputFile(); 125 126 testCreateImage(); 127 testCreateImageToolProvider(); 128 } 129 130 }