< prev index next >

test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageRuntimeBase.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 
  27  public class JPackageCreateAppImageRuntimeBase {
  28     private static final String app = JPackagePath.getApp();
  29     private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
  30     private static final String runtimeJava = JPackagePath.getRuntimeJava();
  31     private static final String runtimeJavaOutput = "javaOutput.txt";
  32     private static final String appOutput = JPackagePath.getAppOutputFile();
  33 
  34     private static void validateResult(String[] result) throws Exception {
  35         if (result.length != 2) {
  36             throw new AssertionError("Unexpected number of lines: " + result.length);
  37         }
  38 
  39         if (!result[0].trim().equals("jpackage test application")) {
  40             throw new AssertionError("Unexpected result[0]: " + result[0]);
  41         }
  42 
  43         if (!result[1].trim().equals("args.length: 0")) {
  44             throw new AssertionError("Unexpected result[1]: " + result[1]);
  45         }
  46     }
  47 
  48     private static void validate() throws Exception {
  49         int retVal = JPackageHelper.execute(null, app);
  50         if (retVal != 0) {
  51             throw new AssertionError("Test application exited with error: " + retVal);
  52         }
  53 
  54         File outfile = new File(appWorkingDir + File.separator + appOutput);
  55         if (!outfile.exists()) {
  56             throw new AssertionError(appOutput + " was not created");
  57         }
  58 
  59         String output = Files.readString(outfile.toPath());
  60         String[] result = JPackageHelper.splitAndFilter(output);
  61         validateResult(result);
  62     }
  63 
  64     private static void validateRuntime() throws Exception {
  65         int retVal = JPackageHelper.execute(new File(runtimeJavaOutput), runtimeJava, "--list-modules");
  66         if (retVal != 0) {
  67             throw new AssertionError("Test application exited with error: " + retVal);
  68         }
  69 
  70         File outfile = new File(runtimeJavaOutput);
  71         if (!outfile.exists()) {
  72             throw new AssertionError(runtimeJavaOutput + " was not created");
  73         }
  74 
  75         String output = Files.readString(outfile.toPath());
  76         String[] result = JPackageHelper.splitAndFilter(output);
  77         if (result.length != 1) {
  78             throw new AssertionError("Unexpected number of lines: " + result.length);
  79         }
  80 
  81         if (!result[0].startsWith("java.base")) {
  82             throw new AssertionError("Unexpected result: " + result[0]);
  83         }
  84     }
  85 
  86     public static void testCreateAppImage(String [] cmd) throws Exception {

  87         JPackageHelper.executeCLI(true, cmd);

  88         validate();
  89         validateRuntime();
  90     }
  91 
  92     public static void testCreateAppImageToolProvider(String [] cmd) throws Exception {

  93         JPackageHelper.executeToolProvider(true, cmd);

  94         validate();
  95         validateRuntime();
  96     }
  97 
  98 }


   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 
  27  public class JPackageCreateAppImageRuntimeBase {
  28     private static final String app = JPackagePath.getApp();

  29     private static final String runtimeJava = JPackagePath.getRuntimeJava();
  30     private static final String runtimeJavaOutput = "javaOutput.txt";
  31     private static final String appOutput = JPackagePath.getAppOutputFile();
  32 
  33     private static void validateResult(String[] result) throws Exception {
  34         if (result.length != 2) {
  35             throw new AssertionError("Unexpected number of lines: " + result.length);
  36         }
  37 
  38         if (!result[0].trim().equals("jpackage test application")) {
  39             throw new AssertionError("Unexpected result[0]: " + result[0]);
  40         }
  41 
  42         if (!result[1].trim().equals("args.length: 0")) {
  43             throw new AssertionError("Unexpected result[1]: " + result[1]);
  44         }
  45     }
  46 
  47     private static void validate() throws Exception {
  48         int retVal = JPackageHelper.execute(null, app);
  49         if (retVal != 0) {
  50             throw new AssertionError("Test application exited with error: " + retVal);
  51         }
  52 
  53         File outfile = new File(appOutput);
  54         if (!outfile.exists()) {
  55             throw new AssertionError(appOutput + " was not created");
  56         }
  57 
  58         String output = Files.readString(outfile.toPath());
  59         String[] result = JPackageHelper.splitAndFilter(output);
  60         validateResult(result);
  61     }
  62 
  63     private static void validateRuntime() throws Exception {
  64         int retVal = JPackageHelper.execute(new File(runtimeJavaOutput), runtimeJava, "--list-modules");
  65         if (retVal != 0) {
  66             throw new AssertionError("Test application exited with error: " + retVal);
  67         }
  68 
  69         File outfile = new File(runtimeJavaOutput);
  70         if (!outfile.exists()) {
  71             throw new AssertionError(runtimeJavaOutput + " was not created");
  72         }
  73 
  74         String output = Files.readString(outfile.toPath());
  75         String[] result = JPackageHelper.splitAndFilter(output);
  76         if (result.length != 1) {
  77             throw new AssertionError("Unexpected number of lines: " + result.length);
  78         }
  79 
  80         if (!result[0].startsWith("java.base")) {
  81             throw new AssertionError("Unexpected result: " + result[0]);
  82         }
  83     }
  84 
  85     public static void testCreateAppImage(String [] cmd) throws Exception {
  86 System.out.println("----- current dir = " + System.getProperty("user.dir"));
  87         JPackageHelper.executeCLI(true, cmd);
  88 System.out.println("----- current dir = " + System.getProperty("user.dir"));
  89         validate();
  90         validateRuntime();
  91     }
  92 
  93     public static void testCreateAppImageToolProvider(String [] cmd) throws Exception {
  94 System.out.println("----- ToolProvider current dir = " + System.getProperty("user.dir"));
  95         JPackageHelper.executeToolProvider(true, cmd);
  96 System.out.println("----- ToolProvider current dir = " + System.getProperty("user.dir"));
  97         validate();
  98         validateRuntime();
  99     }
 100 
 101 }
< prev index next >