test/jdk/tools/jpackage/helpers/JPackageHelper.java
author herrick
Fri, 01 Mar 2019 08:27:51 -0500
branchJDK-8200758-branch
changeset 57241 e11f3bf34083
parent 57151 38d0b67617e3
child 57314 23da9e6f446f
permissions -rw-r--r--
8219889: Update jpackage tests for JDK-8219678 changes Submitten-by: almatvee Reviewed-by: kbr, herrick
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;
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
    28
import java.nio.file.FileVisitResult;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    29
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    30
import java.nio.file.Files;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    31
import java.nio.file.Path;
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
    32
import java.nio.file.SimpleFileVisitor;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
    33
import java.nio.file.attribute.BasicFileAttributes;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    34
import java.util.ArrayList;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    35
import java.util.List;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    36
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    37
import java.util.spi.ToolProvider;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    38
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    39
public class JPackageHelper {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    40
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    41
    private static final boolean VERBOSE = false;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    42
    private static final String OS = System.getProperty("os.name").toLowerCase();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    43
    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
    44
    public static final String TEST_SRC_ROOT;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    45
    public static final String TEST_SRC;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    46
    private static final Path BIN_DIR = Path.of(JAVA_HOME, "bin");
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    47
    private static final Path JPACKAGE;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    48
    private static final Path JAVAC;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    49
    private static final Path JAR;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    50
    private static final Path JLINK;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    51
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    52
    static {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    53
        if (OS.startsWith("win")) {
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    54
            JPACKAGE = BIN_DIR.resolve("jpackage.exe");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    55
            JAVAC = BIN_DIR.resolve("javac.exe");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    56
            JAR = BIN_DIR.resolve("jar.exe");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    57
            JLINK = BIN_DIR.resolve("jlink.exe");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    58
        } else {
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    59
            JPACKAGE = BIN_DIR.resolve("jpackage");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    60
            JAVAC = BIN_DIR.resolve("javac");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    61
            JAR = BIN_DIR.resolve("jar");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    62
            JLINK = BIN_DIR.resolve("jlink");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    63
        }
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
        // Figure out test src based on where we called
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    66
        File testSrc = new File(System.getProperty("test.src") + File.separator + ".."
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    67
                + File.separator + "apps");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    68
        if (testSrc.exists()) {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    69
            TEST_SRC_ROOT = System.getProperty("test.src") + File.separator + "..";
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    70
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    71
            testSrc = new File(System.getProperty("test.src") + File.separator
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    72
                    + ".." + File.separator + ".." + File.separator + "apps");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    73
            if (testSrc.exists()) {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    74
                TEST_SRC_ROOT = System.getProperty("test.src") + File.separator + ".."
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    75
                        + File.separator + "..";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    76
            } else {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    77
                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
    78
                        + ".." + File.separator + ".."  + File.separator + ".."
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    79
                        + File.separator + "apps");
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    80
                if (testSrc.exists()) {
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    81
                    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
    82
                            + File.separator + ".." + File.separator + "..";
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    83
                } else {
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    84
                    TEST_SRC_ROOT = System.getProperty("test.src");
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    85
                }
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    86
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    87
        }
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    88
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    89
        TEST_SRC = System.getProperty("test.src");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    90
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    91
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    92
    static final ToolProvider JPACKAGE_TOOL =
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    93
            ToolProvider.findFirst("jpackage").orElseThrow(
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    94
            () -> new RuntimeException("jpackage tool not found"));
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    95
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    96
    public static int execute(File out, String... command) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    97
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    98
            System.out.print("Execute command: ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    99
            for (String c : command) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   100
                System.out.print(c);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   101
                System.out.print(" ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   102
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   103
            System.out.println();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   104
        }
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
        ProcessBuilder builder = new ProcessBuilder(command);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   107
        if (out != null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   108
            builder.redirectErrorStream(true);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   109
            builder.redirectOutput(out);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   110
        }
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
        Process process = builder.start();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   113
        return process.waitFor();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   114
    }
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
    public static Process executeNoWait(File out, String... command) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   117
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   118
            System.out.print("Execute command: ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   119
            for (String c : command) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   120
                System.out.print(c);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   121
                System.out.print(" ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   122
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   123
            System.out.println();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   124
        }
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
        ProcessBuilder builder = new ProcessBuilder(command);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   127
        if (out != null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   128
            builder.redirectErrorStream(true);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   129
            builder.redirectOutput(out);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   130
        }
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
        return builder.start();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   133
    }
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
    private static String[] getCommand(String... args) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   136
        String[] command;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   137
        if (args == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   138
            command = new String[1];
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   139
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   140
            command = new String[args.length + 1];
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   141
        }
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
        int index = 0;
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   144
        command[index] = JPACKAGE.toString();
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   145
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   146
        if (args != null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   147
            for (String arg : args) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   148
                index++;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   149
                command[index] = arg;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   150
            }
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
        return command;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   154
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   155
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   156
    private static void deleteRecursive(File path) throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   157
        if (!path.exists()) {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   158
            return;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   159
        }
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
        Path directory = path.toPath();
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   162
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   163
            @Override
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   164
            public FileVisitResult visitFile(Path file,
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   165
                    BasicFileAttributes attr) throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   166
                if (OS.startsWith("win")) {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   167
                    Files.setAttribute(file, "dos:readonly", false);
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   168
                }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   169
                Files.delete(file);
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   170
                return FileVisitResult.CONTINUE;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   171
            }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   172
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   173
            @Override
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   174
            public FileVisitResult preVisitDirectory(Path dir,
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   175
                    BasicFileAttributes attr) throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   176
                if (OS.startsWith("win")) {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   177
                    Files.setAttribute(dir, "dos:readonly", false);
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
                return FileVisitResult.CONTINUE;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   180
            }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   181
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   182
            @Override
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   183
            public FileVisitResult postVisitDirectory(Path dir, IOException e)
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   184
                    throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   185
                Files.delete(dir);
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
    }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   190
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   191
    public static void deleteOutputFolder(String output) throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   192
        File outputFolder = new File(output);
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   193
        System.out.println("AMDEBUG output: " + outputFolder.getAbsolutePath());
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   194
        deleteRecursive(outputFolder);
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
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   197
    public static String executeCLI(boolean retValZero, String... args) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   198
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   199
        File outfile = new File("output.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   200
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   201
            String[] command = getCommand(args);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   202
            retVal = execute(outfile, command);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   203
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   204
            if (outfile.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   205
                System.err.println(Files.readString(outfile.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   206
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   207
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   208
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   209
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   210
        String output = Files.readString(outfile.toPath());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   211
        if (retValZero) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   212
            if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   213
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   214
                throw new AssertionError("jpackage exited with error: " + retVal);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   215
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   216
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   217
            if (retVal == 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   218
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   219
                throw new AssertionError("jpackage exited without error: " + retVal);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   220
            }
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
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   224
            System.out.println("output =");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   225
            System.out.println(output);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   226
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   227
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   228
        return output;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   229
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   230
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   231
    public static String executeToolProvider(boolean retValZero, String... args) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   232
        StringWriter writer = new StringWriter();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   233
        PrintWriter pw = new PrintWriter(writer);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   234
        int retVal = JPACKAGE_TOOL.run(pw, pw, args);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   235
        String output = writer.toString();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   236
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   237
        if (retValZero) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   238
            if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   239
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   240
                throw new AssertionError("jpackage exited with error: " + retVal);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   241
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   242
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   243
            if (retVal == 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   244
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   245
                throw new AssertionError("jpackage exited without error");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   246
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   247
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   248
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   249
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   250
            System.out.println("output =");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   251
            System.out.println(output);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   252
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   253
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   254
        return output;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   255
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   256
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   257
    public static boolean isWindows() {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   258
        return (OS.contains("win"));
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
    public static boolean isOSX() {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   262
        return (OS.contains("mac"));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   263
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   264
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   265
    public static boolean isLinux() {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   266
        return ((OS.contains("nix") || OS.contains("nux")));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   267
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   268
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   269
    public static void createHelloImageJar() throws Exception {
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   270
        createJar(false, "Hello", "image");
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   271
    }
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   272
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   273
    public static void createHelloImageJarWithMainClass() throws Exception {
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   274
        createJar(true, "Hello", "image");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   275
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   276
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   277
    public static void createHelloInstallerJar() throws Exception {
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   278
        createJar(false, "Hello", "installer");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   279
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   280
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   281
    public static void createHelloInstallerJarWithMainClass() throws Exception {
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   282
        createJar(true, "Hello", "installer");
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   283
    }
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   284
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   285
    private static void createJar(boolean mainClassAttribute, String name,
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   286
                                  String testType) throws Exception {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   287
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   288
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   289
        File input = new File("input");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   290
        if (!input.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   291
            input.mkdir();
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
        Files.copy(Path.of(TEST_SRC_ROOT + File.separator + "apps" + File.separator
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   295
                + testType + File.separator + name + ".java"), Path.of(name + ".java"));
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
        File javacLog = new File("javac.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   298
        try {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   299
            retVal = execute(javacLog, JAVAC.toString(), name + ".java");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   300
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   301
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   302
                System.err.println(Files.readString(javacLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   303
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   304
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   305
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   306
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   307
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   308
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   309
                System.err.println(Files.readString(javacLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   310
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   311
            throw new AssertionError("javac exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   312
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   313
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   314
        File jarLog = new File("jar.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   315
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   316
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   317
            args.add(JAR.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   318
            args.add("-c");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   319
            args.add("-v");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   320
            args.add("-f");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   321
            args.add("input" + File.separator + name.toLowerCase() + ".jar");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   322
            if (mainClassAttribute) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   323
                args.add("-e");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   324
                args.add(name);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   325
            }
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   326
            args.add(name + ".class");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   327
            retVal = execute(jarLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   328
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   329
            if (jarLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   330
                System.err.println(Files.readString(jarLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   331
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   332
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   333
        }
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
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   336
            if (jarLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   337
                System.err.println(Files.readString(jarLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   338
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   339
            throw new AssertionError("jar exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   340
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   341
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   342
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   343
    public static void createHelloModule() throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   344
        createModule("Hello.java");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   345
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   346
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   347
    private static void createModule(String javaFile) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   348
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   349
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   350
        File input = new File("input");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   351
        if (!input.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   352
            input.mkdir();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   353
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   354
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   355
        File module = new File("module" + File.separator + "com.hello");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   356
        if (!module.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   357
            module.mkdirs();
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   360
        File javacLog = new File("javac.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   361
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   362
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   363
            args.add(JAVAC.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   364
            args.add("-d");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   365
            args.add("module" + File.separator + "com.hello");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   366
            args.add(TEST_SRC_ROOT + File.separator + "apps" + File.separator + "com.hello"
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   367
                    + File.separator + "module-info.java");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   368
            args.add(TEST_SRC_ROOT + File.separator + "apps" + File.separator + "com.hello"
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   369
                    + File.separator + "com" + File.separator + "hello" + File.separator
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   370
                    + javaFile);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   371
            retVal = execute(javacLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   372
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   373
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   374
                System.err.println(Files.readString(javacLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   375
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   376
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   377
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   378
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   379
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   380
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   381
                System.err.println(Files.readString(javacLog.toPath()));
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
            throw new AssertionError("javac exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   384
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   385
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   386
        File jarLog = new File("jar.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   387
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   388
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   389
            args.add(JAR.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   390
            args.add("--create");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   391
            args.add("--file");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   392
            args.add("input" + File.separator + "com.hello.jar");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   393
            args.add("-C");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   394
            args.add("module" + File.separator + "com.hello");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   395
            args.add(".");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   396
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   397
            retVal = execute(jarLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   398
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   399
            if (jarLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   400
                System.err.println(Files.readString(jarLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   401
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   402
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   403
        }
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
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   406
            if (jarLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   407
                System.err.println(Files.readString(jarLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   408
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   409
            throw new AssertionError("jar exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   410
        }
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   413
    public static void createRuntime() throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   414
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   415
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   416
        File jlinkLog = new File("jlink.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   417
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   418
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   419
            args.add(JLINK.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   420
            args.add("--output");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   421
            args.add("runtime");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   422
            args.add("--add-modules");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   423
            args.add("java.base");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   424
            retVal = execute(jlinkLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   425
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   426
            if (jlinkLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   427
                System.err.println(Files.readString(jlinkLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   428
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   429
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   430
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   431
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   432
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   433
            if (jlinkLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   434
                System.err.println(Files.readString(jlinkLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   435
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   436
            throw new AssertionError("jlink exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   437
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   438
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   439
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   440
    public static String listToArgumentsMap(List<String> arguments, boolean toolProvider) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   441
        if (arguments.isEmpty()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   442
            return "";
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   445
        String argsStr = "";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   446
        for (int i = 0; i < arguments.size(); i++) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   447
            String arg = arguments.get(i);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   448
            argsStr += quote(arg, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   449
            if ((i + 1) != arguments.size()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   450
                argsStr += " ";
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
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   453
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   454
        if (!toolProvider && isWindows()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   455
            if (argsStr.contains(" ")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   456
                if (argsStr.contains("\"")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   457
                    argsStr = escapeQuote(argsStr, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   458
                }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   459
                argsStr = "\"" + argsStr + "\"";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   460
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   461
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   462
        return argsStr;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   463
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   464
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   465
    private static String quote(String in, boolean toolProvider) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   466
        if (in == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   467
            return null;
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 (in.isEmpty()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   471
            return "";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   472
        }
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
        if (!in.contains("=")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   475
            // Not a property
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   476
            if (in.contains(" ")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   477
                in = escapeQuote(in, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   478
                return "\"" + in + "\"";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   479
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   480
            return in;
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
        if (!in.contains(" ")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   484
            return in; // No need to quote
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   485
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   486
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   487
        int paramIndex = in.indexOf("=");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   488
        if (paramIndex <= 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   489
            return in; // Something wrong, just skip quoting
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
        String param = in.substring(0, paramIndex);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   493
        String value = in.substring(paramIndex + 1);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   494
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   495
        if (value.length() == 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   496
            return in; // No need to quote
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   497
        }
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
        value = escapeQuote(value, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   500
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   501
        return param + "=" + "\"" + value + "\"";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   502
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   503
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   504
    private static String escapeQuote(String in, boolean toolProvider) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   505
        if (in == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   506
            return null;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   507
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   508
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   509
        if (in.isEmpty()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   510
            return "";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   511
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   512
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   513
        if (in.contains("\"")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   514
            // Use code points to preserve non-ASCII chars
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   515
            StringBuilder sb = new StringBuilder();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   516
            int codeLen = in.codePointCount(0, in.length());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   517
            for (int i = 0; i < codeLen; i++) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   518
                int code = in.codePointAt(i);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   519
                // Note: No need to escape '\' on Linux or OS X
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   520
                // jpackage expects us to pass arguments and properties with
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   521
                // quotes and spaces as a map
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   522
                // with quotes being escaped with additional \ for
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   523
                // internal quotes.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   524
                // So if we want two properties below:
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   525
                // -Djnlp.Prop1=Some "Value" 1
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   526
                // -Djnlp.Prop2=Some Value 2
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   527
                // jpackage will need:
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   528
                // "-Djnlp.Prop1=\"Some \\"Value\\" 1\" -Djnlp.Prop2=\"Some Value 2\""
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   529
                // 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
   530
                // 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
   531
                // "-Djnlp.Prop1=\\\"Some \\\\\\\"Value\\\\\\\" 1\\\" -Djnlp.Prop2=\\\"Some Value 2\\\""
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   532
                switch (code) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   533
                    case '"':
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
                        if (i == 0 || in.codePointAt(i - 1) != '\\') {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   536
                            sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   537
                            sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   538
                        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   539
                        break;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   540
                    case '\\':
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   541
                        // We need to escape already escaped symbols as well
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   542
                        if ((i + 1) < codeLen) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   543
                            int nextCode = in.codePointAt(i + 1);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   544
                            if (nextCode == '"') {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   545
                                // \" -> \\\"
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   546
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   547
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   548
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   549
                                sb.appendCodePoint(nextCode);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   550
                            } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   551
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   552
                                sb.appendCodePoint(code);
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
                        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   555
                            sb.appendCodePoint(code);
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
                        break;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   558
                    default:
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   559
                        sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   560
                        break;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   561
                }
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 sb.toString();
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
        return in;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   567
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   568
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   569
}