< prev index next >

test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageBase.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.nio.file.Files;
  25 import java.nio.file.Path;
  26 
  27 public abstract class JPackageCreateAppImageBase {
  28     private static final String appOutput = JPackagePath.getAppOutputFile();
  29     private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
  30 
  31     private static void validateResult(String[] result) throws Exception {
  32         if (result.length != 2) {
  33             throw new AssertionError(
  34                    "Unexpected number of lines: " + result.length);
  35         }
  36 
  37         if (!result[0].trim().endsWith("jpackage test application")) {
  38             throw new AssertionError("Unexpected result[0]: " + result[0]);
  39         }
  40 
  41         if (!result[1].trim().equals("args.length: 0")) {
  42             throw new AssertionError("Unexpected result[1]: " + result[1]);
  43         }
  44     }
  45 
  46     public static void validate(String app) throws Exception {
  47         Path outPath = Path.of(appWorkingDir, appOutput);
  48         int retVal = JPackageHelper.execute(null, app);
  49 
  50         if (outPath.toFile().exists()) {
  51              System.out.println("output contents: ");
  52              System.out.println(Files.readString(outPath) + "\n");
  53         } else {
  54              System.out.println("no output file: " + outPath
  55                    + " from command: " + app);
  56         }
  57 
  58         if (retVal != 0) {
  59             throw new AssertionError(
  60                 "Test application (" + app + ") exited with error: " + retVal);
  61         }
  62 
  63         if (!outPath.toFile().exists()) {
  64             throw new AssertionError(appOutput + " was not created");
  65         }
  66 
  67         String output = Files.readString(outPath);


   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.nio.file.Files;
  25 import java.nio.file.Path;
  26 
  27 public abstract class JPackageCreateAppImageBase {
  28     private static final String appOutput = JPackagePath.getAppOutputFile();

  29 
  30     private static void validateResult(String[] result) throws Exception {
  31         if (result.length != 2) {
  32             throw new AssertionError(
  33                    "Unexpected number of lines: " + result.length);
  34         }
  35 
  36         if (!result[0].trim().endsWith("jpackage test application")) {
  37             throw new AssertionError("Unexpected result[0]: " + result[0]);
  38         }
  39 
  40         if (!result[1].trim().equals("args.length: 0")) {
  41             throw new AssertionError("Unexpected result[1]: " + result[1]);
  42         }
  43     }
  44 
  45     public static void validate(String app) throws Exception {
  46         Path outPath = Path.of(appOutput);
  47         int retVal = JPackageHelper.execute(null, app);
  48 
  49         if (outPath.toFile().exists()) {
  50              System.out.println("output contents: ");
  51              System.out.println(Files.readString(outPath) + "\n");
  52         } else {
  53              System.out.println("no output file: " + outPath
  54                    + " from command: " + app);
  55         }
  56 
  57         if (retVal != 0) {
  58             throw new AssertionError(
  59                 "Test application (" + app + ") exited with error: " + retVal);
  60         }
  61 
  62         if (!outPath.toFile().exists()) {
  63             throw new AssertionError(appOutput + " was not created");
  64         }
  65 
  66         String output = Files.readString(outPath);
< prev index next >