test/jdk/tools/jpackage/helpers/JPackageHelper.java
author herrick
Thu, 13 Jun 2019 19:34:44 -0400
branchJDK-8200758-branch
changeset 57405 539d8b3f9e1e
parent 57395 521c02b9eed0
child 57414 6eda749d3117
permissions -rw-r--r--
8224597: create automated tests for platform create-app-image options Submitted-by: almatvee Reviewed-by: asemenyuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     1
/*
57106
ea870b9ce89a 8216492: Update copyright of all new jpackage fils to 2019
kcr
parents: 57079
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     4
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     8
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    13
 * accompanied this code).
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    14
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    18
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    21
 * questions.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    22
 */
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    23
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    24
import java.io.File;
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
    25
import java.io.IOException;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    26
import java.io.PrintWriter;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    27
import java.io.StringWriter;
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
    28
import java.io.BufferedWriter;
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
    29
import java.nio.file.FileVisitResult;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    30
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    31
import java.nio.file.Files;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    32
import java.nio.file.Path;
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
    33
import java.nio.file.SimpleFileVisitor;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
    34
import java.nio.file.attribute.BasicFileAttributes;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    35
import java.util.ArrayList;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    36
import java.util.List;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    37
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    38
import java.util.spi.ToolProvider;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    39
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    40
public class JPackageHelper {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    41
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    42
    private static final boolean VERBOSE = false;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    43
    private static final String OS = System.getProperty("os.name").toLowerCase();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    44
    private static final String JAVA_HOME = System.getProperty("java.home");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    45
    public static final String TEST_SRC_ROOT;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    46
    public static final String TEST_SRC;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    47
    private static final Path BIN_DIR = Path.of(JAVA_HOME, "bin");
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    48
    private static final Path JPACKAGE;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    49
    private static final Path JAVAC;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    50
    private static final Path JAR;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    51
    private static final Path JLINK;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    52
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    53
    static {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    54
        if (OS.startsWith("win")) {
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    55
            JPACKAGE = BIN_DIR.resolve("jpackage.exe");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    56
            JAVAC = BIN_DIR.resolve("javac.exe");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    57
            JAR = BIN_DIR.resolve("jar.exe");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    58
            JLINK = BIN_DIR.resolve("jlink.exe");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    59
        } else {
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    60
            JPACKAGE = BIN_DIR.resolve("jpackage");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    61
            JAVAC = BIN_DIR.resolve("javac");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    62
            JAR = BIN_DIR.resolve("jar");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    63
            JLINK = BIN_DIR.resolve("jlink");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    64
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    65
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    66
        // Figure out test src based on where we called
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    67
        File testSrc = new File(System.getProperty("test.src") + File.separator + ".."
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    68
                + File.separator + "apps");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    69
        if (testSrc.exists()) {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    70
            TEST_SRC_ROOT = System.getProperty("test.src") + File.separator + "..";
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    71
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    72
            testSrc = new File(System.getProperty("test.src") + File.separator
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    73
                    + ".." + File.separator + ".." + File.separator + "apps");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    74
            if (testSrc.exists()) {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    75
                TEST_SRC_ROOT = System.getProperty("test.src") + File.separator + ".."
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    76
                        + File.separator + "..";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    77
            } else {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    78
                testSrc = new File(System.getProperty("test.src") + File.separator
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    79
                        + ".." + File.separator + ".."  + File.separator + ".."
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    80
                        + File.separator + "apps");
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    81
                if (testSrc.exists()) {
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    82
                    TEST_SRC_ROOT = System.getProperty("test.src") + File.separator + ".."
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    83
                            + File.separator + ".." + File.separator + "..";
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    84
                } else {
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    85
                    TEST_SRC_ROOT = System.getProperty("test.src");
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    86
                }
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    87
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    88
        }
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    89
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    90
        TEST_SRC = System.getProperty("test.src");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    91
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    92
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    93
    static final ToolProvider JPACKAGE_TOOL =
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    94
            ToolProvider.findFirst("jpackage").orElseThrow(
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    95
            () -> new RuntimeException("jpackage tool not found"));
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    96
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    97
    public static int execute(File out, String... command) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    98
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    99
            System.out.print("Execute command: ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   100
            for (String c : command) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   101
                System.out.print(c);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   102
                System.out.print(" ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   103
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   104
            System.out.println();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   105
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   106
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   107
        ProcessBuilder builder = new ProcessBuilder(command);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   108
        if (out != null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   109
            builder.redirectErrorStream(true);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   110
            builder.redirectOutput(out);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   111
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   112
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   113
        Process process = builder.start();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   114
        return process.waitFor();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   115
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   116
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   117
    public static Process executeNoWait(File out, String... command) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   118
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   119
            System.out.print("Execute command: ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   120
            for (String c : command) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   121
                System.out.print(c);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   122
                System.out.print(" ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   123
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   124
            System.out.println();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   125
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   126
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   127
        ProcessBuilder builder = new ProcessBuilder(command);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   128
        if (out != null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   129
            builder.redirectErrorStream(true);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   130
            builder.redirectOutput(out);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   131
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   132
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   133
        return builder.start();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   134
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   135
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   136
    private static String[] getCommand(String... args) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   137
        String[] command;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   138
        if (args == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   139
            command = new String[1];
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   140
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   141
            command = new String[args.length + 1];
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   142
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   143
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   144
        int index = 0;
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   145
        command[index] = JPACKAGE.toString();
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   146
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   147
        if (args != null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   148
            for (String arg : args) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   149
                index++;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   150
                command[index] = arg;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   151
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   152
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   153
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   154
        return command;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   155
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   156
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   157
    public static void deleteRecursive(File path) throws IOException {
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   158
        if (!path.exists()) {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   159
            return;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   160
        }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   161
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   162
        Path directory = path.toPath();
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   163
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   164
            @Override
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   165
            public FileVisitResult visitFile(Path file,
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   166
                    BasicFileAttributes attr) throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   167
                if (OS.startsWith("win")) {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   168
                    try {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   169
                        Files.setAttribute(file, "dos:readonly", false);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   170
                    } catch (Exception ioe) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   171
                        // just report and try to contune
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   172
                        System.err.println("IOException: " + ioe);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   173
                        ioe.printStackTrace(System.err);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   174
                    }
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   175
                }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   176
                Files.delete(file);
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   177
                return FileVisitResult.CONTINUE;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   178
            }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   179
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   180
            @Override
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   181
            public FileVisitResult preVisitDirectory(Path dir,
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   182
                    BasicFileAttributes attr) throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   183
                if (OS.startsWith("win")) {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   184
                    Files.setAttribute(dir, "dos:readonly", false);
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   185
                }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   186
                return FileVisitResult.CONTINUE;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   187
            }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   188
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   189
            @Override
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   190
            public FileVisitResult postVisitDirectory(Path dir, IOException e)
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   191
                    throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   192
                Files.delete(dir);
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   193
                return FileVisitResult.CONTINUE;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   194
            }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   195
        });
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   196
    }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   197
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   198
    public static void deleteOutputFolder(String output) throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   199
        File outputFolder = new File(output);
57405
539d8b3f9e1e 8224597: create automated tests for platform create-app-image options
herrick
parents: 57395
diff changeset
   200
        System.out.println("deleteOutputFolder: " + outputFolder.getAbsolutePath());
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   201
        try {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   202
            deleteRecursive(outputFolder);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   203
        } catch (IOException ioe) {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   204
            System.err.println("IOException: " + ioe);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   205
            ioe.printStackTrace(System.err);
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   206
            deleteRecursive(outputFolder);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   207
        }
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   208
    }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   209
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   210
    public static String executeCLI(boolean retValZero, String... args) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   211
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   212
        File outfile = new File("output.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   213
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   214
            String[] command = getCommand(args);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   215
            retVal = execute(outfile, command);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   216
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   217
            if (outfile.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   218
                System.err.println(Files.readString(outfile.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   219
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   220
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   221
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   222
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   223
        String output = Files.readString(outfile.toPath());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   224
        if (retValZero) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   225
            if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   226
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   227
                throw new AssertionError("jpackage exited with error: " + retVal);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   228
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   229
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   230
            if (retVal == 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   231
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   232
                throw new AssertionError("jpackage exited without error: " + retVal);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   233
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   234
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   235
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   236
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   237
            System.out.println("output =");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   238
            System.out.println(output);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   239
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   240
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   241
        return output;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   242
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   243
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   244
    public static String executeToolProvider(boolean retValZero, String... args) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   245
        StringWriter writer = new StringWriter();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   246
        PrintWriter pw = new PrintWriter(writer);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   247
        int retVal = JPACKAGE_TOOL.run(pw, pw, args);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   248
        String output = writer.toString();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   249
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   250
        if (retValZero) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   251
            if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   252
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   253
                throw new AssertionError("jpackage exited with error: " + retVal);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   254
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   255
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   256
            if (retVal == 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   257
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   258
                throw new AssertionError("jpackage exited without error");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   259
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   260
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   261
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   262
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   263
            System.out.println("output =");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   264
            System.out.println(output);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   265
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   266
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   267
        return output;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   268
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   269
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   270
    public static boolean isWindows() {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   271
        return (OS.contains("win"));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   272
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   273
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   274
    public static boolean isOSX() {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   275
        return (OS.contains("mac"));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   276
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   277
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   278
    public static boolean isLinux() {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   279
        return ((OS.contains("nix") || OS.contains("nux")));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   280
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   281
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   282
    public static void createHelloImageJar(String inputDir) throws Exception {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   283
        createJar(false, "Hello", "image", inputDir);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   284
    }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   285
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   286
    public static void createHelloImageJar() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   287
        createJar(false, "Hello", "image", "input");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   288
    }
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   289
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   290
    public static void createHelloImageJarWithMainClass() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   291
        createJar(true, "Hello", "image", "input");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   292
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   293
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   294
    public static void createHelloInstallerJar() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   295
        createJar(false, "Hello", "installer", "input");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   296
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   297
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   298
    public static void createHelloInstallerJarWithMainClass() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   299
        createJar(true, "Hello", "installer", "input");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   300
    }
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   301
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   302
    private static void createJar(boolean mainClassAttribute, String name,
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   303
        String testType, String inputDir) throws Exception {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   304
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   305
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   306
        File input = new File(inputDir);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   307
        if (!input.exists()) {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   308
            input.mkdirs();
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   309
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   310
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   311
        Path src = Path.of(TEST_SRC_ROOT + File.separator + "apps"
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   312
                + File.separator + testType + File.separator + name + ".java");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   313
        Path dst = Path.of(name + ".java");
57405
539d8b3f9e1e 8224597: create automated tests for platform create-app-image options
herrick
parents: 57395
diff changeset
   314
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   315
        if (dst.toFile().exists()) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   316
            Files.delete(dst);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   317
        }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   318
        Files.copy(src, dst);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   319
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   320
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   321
        File javacLog = new File("javac.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   322
        try {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   323
            retVal = execute(javacLog, JAVAC.toString(), name + ".java");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   324
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   325
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   326
                System.err.println(Files.readString(javacLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   327
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   328
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   329
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   330
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   331
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   332
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   333
                System.err.println(Files.readString(javacLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   334
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   335
            throw new AssertionError("javac exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   336
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   337
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   338
        File jarLog = new File("jar.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   339
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   340
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   341
            args.add(JAR.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   342
            args.add("-c");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   343
            args.add("-v");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   344
            args.add("-f");
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   345
            args.add(inputDir + File.separator + name.toLowerCase() + ".jar");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   346
            if (mainClassAttribute) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   347
                args.add("-e");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   348
                args.add(name);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   349
            }
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   350
            args.add(name + ".class");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   351
            retVal = execute(jarLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   352
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   353
            if (jarLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   354
                System.err.println(Files.readString(jarLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   355
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   356
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   357
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   358
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   359
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   360
            if (jarLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   361
                System.err.println(Files.readString(jarLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   362
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   363
            throw new AssertionError("jar exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   364
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   365
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   366
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   367
    public static void createHelloModule() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   368
        createModule("Hello.java", "input", "hello", true);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   369
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   370
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   371
    public static void createOtherModule() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   372
        createModule("Other.java", "input-other", "other", false);
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   373
    }
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   374
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   375
    private static void createModule(String javaFile, String inputDir,
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   376
            String aName, boolean createModularJar) throws Exception {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   377
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   378
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   379
        File input = new File(inputDir);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   380
        if (!input.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   381
            input.mkdir();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   382
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   383
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   384
        File module = new File("module" + File.separator + "com." + aName);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   385
        if (!module.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   386
            module.mkdirs();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   387
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   388
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   389
        File javacLog = new File("javac.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   390
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   391
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   392
            args.add(JAVAC.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   393
            args.add("-d");
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   394
            args.add("module" + File.separator + "com." + aName);
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   395
            args.add(TEST_SRC_ROOT + File.separator + "apps" + File.separator
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   396
                    + "com." + aName + File.separator + "module-info.java");
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   397
            args.add(TEST_SRC_ROOT + File.separator + "apps"
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   398
                    + File.separator + "com." + aName + File.separator + "com"
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   399
                    + File.separator + aName + File.separator + javaFile);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   400
            retVal = execute(javacLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   401
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   402
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   403
                System.err.println(Files.readString(javacLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   404
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   405
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   406
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   407
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   408
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   409
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   410
                System.err.println(Files.readString(javacLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   411
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   412
            throw new AssertionError("javac exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   413
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   414
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   415
        if (createModularJar) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   416
            File jarLog = new File("jar.log");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   417
            try {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   418
                List<String> args = new ArrayList<>();
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   419
                args.add(JAR.toString());
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   420
                args.add("--create");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   421
                args.add("--file");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   422
                args.add(inputDir + File.separator + "com." + aName + ".jar");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   423
                args.add("-C");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   424
                args.add("module" + File.separator + "com." + aName);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   425
                args.add(".");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   426
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   427
                retVal = execute(jarLog, args.stream().toArray(String[]::new));
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   428
            } catch (Exception ex) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   429
                if (jarLog.exists()) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   430
                    System.err.println(Files.readString(jarLog.toPath()));
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   431
                }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   432
                throw ex;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   433
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   434
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   435
            if (retVal != 0) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   436
                if (jarLog.exists()) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   437
                    System.err.println(Files.readString(jarLog.toPath()));
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   438
                }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   439
                throw new AssertionError("jar exited with error: " + retVal);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   440
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   441
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   442
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   443
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   444
    public static void createRuntime() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   445
        List<String> moreArgs = new ArrayList<>();
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   446
        createRuntime(moreArgs);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   447
    }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   448
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   449
    public static void createRuntime(List<String> moreArgs) throws Exception {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   450
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   451
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   452
        File jlinkLog = new File("jlink.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   453
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   454
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   455
            args.add(JLINK.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   456
            args.add("--output");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   457
            args.add("runtime");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   458
            args.add("--add-modules");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   459
            args.add("java.base");
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   460
            args.addAll(moreArgs);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   461
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   462
            retVal = execute(jlinkLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   463
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   464
            if (jlinkLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   465
                System.err.println(Files.readString(jlinkLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   466
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   467
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   468
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   469
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   470
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   471
            if (jlinkLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   472
                System.err.println(Files.readString(jlinkLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   473
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   474
            throw new AssertionError("jlink exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   475
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   476
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   477
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   478
    public static String listToArgumentsMap(List<String> arguments, boolean toolProvider) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   479
        if (arguments.isEmpty()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   480
            return "";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   481
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   482
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   483
        String argsStr = "";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   484
        for (int i = 0; i < arguments.size(); i++) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   485
            String arg = arguments.get(i);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   486
            argsStr += quote(arg, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   487
            if ((i + 1) != arguments.size()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   488
                argsStr += " ";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   489
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   490
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   491
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   492
        if (!toolProvider && isWindows()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   493
            if (argsStr.contains(" ")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   494
                if (argsStr.contains("\"")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   495
                    argsStr = escapeQuote(argsStr, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   496
                }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   497
                argsStr = "\"" + argsStr + "\"";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   498
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   499
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   500
        return argsStr;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   501
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   502
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   503
    public static String[] cmdWithAtFilename(String [] cmd, int ndx, int len)
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   504
                throws IOException {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   505
        ArrayList<String> newAList = new ArrayList<>();
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   506
        String fileString = null;
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   507
        for (int i=0; i<cmd.length; i++) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   508
            if (i == ndx) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   509
                newAList.add("@argfile.cmds");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   510
                fileString = cmd[i];
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   511
            } else if (i > ndx && i < ndx + len) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   512
                fileString += " " + cmd[i];
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   513
            } else {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   514
                newAList.add(cmd[i]);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   515
            }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   516
        }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   517
        if (fileString != null) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   518
            Path path = new File("argfile.cmds").toPath();
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   519
            try (BufferedWriter bw = Files.newBufferedWriter(path);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   520
                    PrintWriter out = new PrintWriter(bw)) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   521
                out.println(fileString);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   522
            }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   523
        }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   524
        return newAList.toArray(new String[0]);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   525
    }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   526
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   527
    private static String quote(String in, boolean toolProvider) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   528
        if (in == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   529
            return null;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   530
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   531
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   532
        if (in.isEmpty()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   533
            return "";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   534
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   535
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   536
        if (!in.contains("=")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   537
            // Not a property
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   538
            if (in.contains(" ")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   539
                in = escapeQuote(in, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   540
                return "\"" + in + "\"";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   541
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   542
            return in;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   543
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   544
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   545
        if (!in.contains(" ")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   546
            return in; // No need to quote
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   547
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   548
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   549
        int paramIndex = in.indexOf("=");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   550
        if (paramIndex <= 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   551
            return in; // Something wrong, just skip quoting
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   552
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   553
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   554
        String param = in.substring(0, paramIndex);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   555
        String value = in.substring(paramIndex + 1);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   556
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   557
        if (value.length() == 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   558
            return in; // No need to quote
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   559
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   560
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   561
        value = escapeQuote(value, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   562
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   563
        return param + "=" + "\"" + value + "\"";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   564
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   565
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   566
    private static String escapeQuote(String in, boolean toolProvider) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   567
        if (in == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   568
            return null;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   569
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   570
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   571
        if (in.isEmpty()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   572
            return "";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   573
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   574
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   575
        if (in.contains("\"")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   576
            // Use code points to preserve non-ASCII chars
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   577
            StringBuilder sb = new StringBuilder();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   578
            int codeLen = in.codePointCount(0, in.length());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   579
            for (int i = 0; i < codeLen; i++) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   580
                int code = in.codePointAt(i);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   581
                // Note: No need to escape '\' on Linux or OS X
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   582
                // jpackage expects us to pass arguments and properties with
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   583
                // quotes and spaces as a map
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   584
                // with quotes being escaped with additional \ for
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   585
                // internal quotes.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   586
                // So if we want two properties below:
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   587
                // -Djnlp.Prop1=Some "Value" 1
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   588
                // -Djnlp.Prop2=Some Value 2
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   589
                // jpackage will need:
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   590
                // "-Djnlp.Prop1=\"Some \\"Value\\" 1\" -Djnlp.Prop2=\"Some Value 2\""
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   591
                // but since we using ProcessBuilder to run jpackage we will need to escape
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   592
                // our escape symbols as well, so we will need to pass string below to ProcessBuilder:
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   593
                // "-Djnlp.Prop1=\\\"Some \\\\\\\"Value\\\\\\\" 1\\\" -Djnlp.Prop2=\\\"Some Value 2\\\""
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   594
                switch (code) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   595
                    case '"':
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   596
                        // " -> \" -> \\\"
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   597
                        if (i == 0 || in.codePointAt(i - 1) != '\\') {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   598
                            sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   599
                            sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   600
                        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   601
                        break;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   602
                    case '\\':
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   603
                        // We need to escape already escaped symbols as well
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   604
                        if ((i + 1) < codeLen) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   605
                            int nextCode = in.codePointAt(i + 1);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   606
                            if (nextCode == '"') {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   607
                                // \" -> \\\"
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   608
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   609
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   610
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   611
                                sb.appendCodePoint(nextCode);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   612
                            } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   613
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   614
                                sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   615
                            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   616
                        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   617
                            sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   618
                        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   619
                        break;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   620
                    default:
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   621
                        sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   622
                        break;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   623
                }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   624
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   625
            return sb.toString();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   626
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   627
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   628
        return in;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   629
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   630
}