< prev index next >

test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageJavaOptionsBase.java

Print this page




   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.util.ArrayList;
  27 import java.util.List;
  28 
  29 public class JPackageCreateImageJavaOptionsBase {
  30 
  31     private static final String app = JPackagePath.getApp();
  32     private static final String appOutput = JPackagePath.getAppOutputFile();
  33     private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
  34 
  35     private static final String ARGUMENT1 = "-Dparam1=Some Param 1";
  36     private static final String ARGUMENT2 = "-Dparam2=Some \"Param\" 2";
  37     private static final String ARGUMENT3 =
  38             "-Dparam3=Some \"Param\" with \" 3";
  39 
  40     private static final List<String> arguments = new ArrayList<>();
  41 
  42     private static void initArguments(boolean toolProvider, String [] cmd) {
  43         if (arguments.isEmpty()) {
  44             arguments.add(ARGUMENT1);
  45             arguments.add(ARGUMENT2);
  46             arguments.add(ARGUMENT3);
  47         }
  48 
  49         String argumentsMap = JPackageHelper.listToArgumentsMap(arguments,


 106         }
 107     }
 108 
 109     private static void validate(List<String> expectedArgs) throws Exception {
 110         int retVal = JPackageHelper.execute(null, app);
 111         if (retVal != 0) {
 112             throw new AssertionError("Test application exited with error: "
 113                     + retVal);
 114         }
 115 
 116         File outfile = new File(appWorkingDir + File.separator + appOutput);
 117         if (!outfile.exists()) {
 118             throw new AssertionError(appOutput + " was not created");
 119         }
 120 
 121         String output = Files.readString(outfile.toPath());
 122         String[] result = output.split("\n");
 123         validateResult(result, expectedArgs);
 124     }
 125 
 126     public static void testCreateImageJavaOptions(String [] cmd) throws Exception {
 127         initArguments(false, cmd);
 128         JPackageHelper.executeCLI(true, cmd);
 129         validate(arguments);
 130     }
 131 
 132     public static void testCreateImageJavaOptionsToolProvider(String [] cmd) throws Exception {
 133         initArguments(true, cmd);
 134         JPackageHelper.executeToolProvider(true, cmd);
 135         validate(arguments);
 136     }
 137 
 138     public static void testCreateImageJavaOptions2(String [] cmd) throws Exception {
 139         initArguments2(false, cmd);
 140         JPackageHelper.executeCLI(true, cmd);
 141         validate(arguments);
 142     }
 143 
 144     public static void testCreateImageJavaOptions2ToolProvider(String [] cmd) throws Exception {
 145         initArguments2(true, cmd);
 146         JPackageHelper.executeToolProvider(true, cmd);
 147         validate(arguments);
 148     }
 149 }


   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.util.ArrayList;
  27 import java.util.List;
  28 
  29 public class JPackageCreateAppImageJavaOptionsBase {
  30 
  31     private static final String app = JPackagePath.getApp();
  32     private static final String appOutput = JPackagePath.getAppOutputFile();
  33     private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
  34 
  35     private static final String ARGUMENT1 = "-Dparam1=Some Param 1";
  36     private static final String ARGUMENT2 = "-Dparam2=Some \"Param\" 2";
  37     private static final String ARGUMENT3 =
  38             "-Dparam3=Some \"Param\" with \" 3";
  39 
  40     private static final List<String> arguments = new ArrayList<>();
  41 
  42     private static void initArguments(boolean toolProvider, String [] cmd) {
  43         if (arguments.isEmpty()) {
  44             arguments.add(ARGUMENT1);
  45             arguments.add(ARGUMENT2);
  46             arguments.add(ARGUMENT3);
  47         }
  48 
  49         String argumentsMap = JPackageHelper.listToArgumentsMap(arguments,


 106         }
 107     }
 108 
 109     private static void validate(List<String> expectedArgs) throws Exception {
 110         int retVal = JPackageHelper.execute(null, app);
 111         if (retVal != 0) {
 112             throw new AssertionError("Test application exited with error: "
 113                     + retVal);
 114         }
 115 
 116         File outfile = new File(appWorkingDir + File.separator + appOutput);
 117         if (!outfile.exists()) {
 118             throw new AssertionError(appOutput + " was not created");
 119         }
 120 
 121         String output = Files.readString(outfile.toPath());
 122         String[] result = output.split("\n");
 123         validateResult(result, expectedArgs);
 124     }
 125 
 126     public static void testCreateAppImageJavaOptions(String [] cmd) throws Exception {
 127         initArguments(false, cmd);
 128         JPackageHelper.executeCLI(true, cmd);
 129         validate(arguments);
 130     }
 131 
 132     public static void testCreateAppImageJavaOptionsToolProvider(String [] cmd) throws Exception {
 133         initArguments(true, cmd);
 134         JPackageHelper.executeToolProvider(true, cmd);
 135         validate(arguments);
 136     }
 137 
 138     public static void testCreateAppImageJavaOptions2(String [] cmd) throws Exception {
 139         initArguments2(false, cmd);
 140         JPackageHelper.executeCLI(true, cmd);
 141         validate(arguments);
 142     }
 143 
 144     public static void testCreateAppImageJavaOptions2ToolProvider(String [] cmd) throws Exception {
 145         initArguments2(true, cmd);
 146         JPackageHelper.executeToolProvider(true, cmd);
 147         validate(arguments);
 148     }
 149 }
< prev index next >