test/jdk/tools/jpackage/helpers/JPackageHelper.java
author herrick
Tue, 24 Sep 2019 14:05:49 -0400
branchJDK-8200758-branch
changeset 58305 d42b1f6960aa
parent 57438 4a31db8d42bd
child 58359 e065fd274bc1
permissions -rw-r--r--
8230651: Use version string from main module Submitted-by: almatvee Reviewed-by: herrick, 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;
57419
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
    37
import java.util.Arrays;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    38
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    39
import java.util.spi.ToolProvider;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    40
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    41
public class JPackageHelper {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    42
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    43
    private static final boolean VERBOSE = false;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    44
    private static final String OS = System.getProperty("os.name").toLowerCase();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    45
    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
    46
    public static final String TEST_SRC_ROOT;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    47
    public static final String TEST_SRC;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    48
    private static final Path BIN_DIR = Path.of(JAVA_HOME, "bin");
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    49
    private static final Path JPACKAGE;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    50
    private static final Path JAVAC;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    51
    private static final Path JAR;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    52
    private static final Path JLINK;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    53
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    54
    static {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    55
        if (OS.startsWith("win")) {
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    56
            JPACKAGE = BIN_DIR.resolve("jpackage.exe");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    57
            JAVAC = BIN_DIR.resolve("javac.exe");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    58
            JAR = BIN_DIR.resolve("jar.exe");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    59
            JLINK = BIN_DIR.resolve("jlink.exe");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    60
        } else {
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    61
            JPACKAGE = BIN_DIR.resolve("jpackage");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    62
            JAVAC = BIN_DIR.resolve("javac");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    63
            JAR = BIN_DIR.resolve("jar");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    64
            JLINK = BIN_DIR.resolve("jlink");
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    67
        // Figure out test src based on where we called
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    68
        TEST_SRC = System.getProperty("test.src");
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    69
        Path root = Path.of(TEST_SRC);
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    70
        Path apps = Path.of(TEST_SRC, "apps");
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    71
        if (apps.toFile().exists()) {
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    72
            // fine - test is at root
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    73
        } else {
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    74
             apps = Path.of(TEST_SRC, "..", "apps");
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    75
             if (apps.toFile().exists()) {
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    76
                 root = apps.getParent().normalize(); // test is 1 level down
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    77
             } else {
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    78
                 apps = Path.of(TEST_SRC, "..", "..", "apps");
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    79
                 if (apps.toFile().exists()) {
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    80
                     root = apps.getParent().normalize(); // 2 levels down
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    81
                 } else {
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    82
                     apps = Path.of(TEST_SRC, "..", "..", "..", "apps");
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    83
                     if (apps.toFile().exists()) {
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    84
                         root = apps.getParent().normalize(); // 3 levels down
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    85
                     } else {
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    86
                         // if we ever have tests more than three levels
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    87
                         // down we need to add code here
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    88
                         throw new RuntimeException("we should never get here");
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    89
                     }
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    90
                 }
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
        }
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
    93
        TEST_SRC_ROOT = root.toString();
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    94
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    95
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    96
    static final ToolProvider JPACKAGE_TOOL =
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    97
            ToolProvider.findFirst("jpackage").orElseThrow(
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    98
            () -> new RuntimeException("jpackage tool not found"));
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    99
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   100
    public static int execute(File out, String... command) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   101
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   102
            System.out.print("Execute command: ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   103
            for (String c : command) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   104
                System.out.print(c);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   105
                System.out.print(" ");
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
            System.out.println();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   108
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   109
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   110
        ProcessBuilder builder = new ProcessBuilder(command);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   111
        if (out != null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   112
            builder.redirectErrorStream(true);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   113
            builder.redirectOutput(out);
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
        Process process = builder.start();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   117
        return process.waitFor();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   118
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   119
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   120
    public static Process executeNoWait(File out, String... command) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   121
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   122
            System.out.print("Execute command: ");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   123
            for (String c : command) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   124
                System.out.print(c);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   125
                System.out.print(" ");
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
            System.out.println();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   128
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   129
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   130
        ProcessBuilder builder = new ProcessBuilder(command);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   131
        if (out != null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   132
            builder.redirectErrorStream(true);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   133
            builder.redirectOutput(out);
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
        return builder.start();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   137
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   138
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   139
    private static String[] getCommand(String... args) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   140
        String[] command;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   141
        if (args == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   142
            command = new String[1];
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   143
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   144
            command = new String[args.length + 1];
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   147
        int index = 0;
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   148
        command[index] = JPACKAGE.toString();
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   149
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   150
        if (args != null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   151
            for (String arg : args) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   152
                index++;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   153
                command[index] = arg;
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
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   156
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   157
        return command;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   158
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   159
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   160
    public static void deleteRecursive(File path) throws IOException {
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   161
        if (!path.exists()) {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   162
            return;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   163
        }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   164
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   165
        Path directory = path.toPath();
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   166
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   167
            @Override
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   168
            public FileVisitResult visitFile(Path file,
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   169
                    BasicFileAttributes attr) throws IOException {
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57419
diff changeset
   170
                file.toFile().setWritable(true);
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   171
                if (OS.startsWith("win")) {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   172
                    try {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   173
                        Files.setAttribute(file, "dos:readonly", false);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   174
                    } catch (Exception ioe) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   175
                        // just report and try to contune
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   176
                        System.err.println("IOException: " + ioe);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   177
                        ioe.printStackTrace(System.err);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   178
                    }
57241
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
                Files.delete(file);
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   181
                return FileVisitResult.CONTINUE;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   182
            }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   183
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   184
            @Override
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   185
            public FileVisitResult preVisitDirectory(Path dir,
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   186
                    BasicFileAttributes attr) throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   187
                if (OS.startsWith("win")) {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   188
                    Files.setAttribute(dir, "dos:readonly", false);
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
                return FileVisitResult.CONTINUE;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   191
            }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   192
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   193
            @Override
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   194
            public FileVisitResult postVisitDirectory(Path dir, IOException e)
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   195
                    throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   196
                Files.delete(dir);
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   197
                return FileVisitResult.CONTINUE;
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   198
            }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   199
        });
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   200
    }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   201
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   202
    public static void deleteOutputFolder(String output) throws IOException {
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   203
        File outputFolder = new File(output);
57405
539d8b3f9e1e 8224597: create automated tests for platform create-app-image options
herrick
parents: 57395
diff changeset
   204
        System.out.println("deleteOutputFolder: " + outputFolder.getAbsolutePath());
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   205
        try {
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
        } catch (IOException ioe) {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   208
            System.err.println("IOException: " + ioe);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   209
            ioe.printStackTrace(System.err);
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   210
            deleteRecursive(outputFolder);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57241
diff changeset
   211
        }
57241
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   212
    }
e11f3bf34083 8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents: 57151
diff changeset
   213
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   214
    public static String executeCLI(boolean retValZero, String... args) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   215
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   216
        File outfile = new File("output.log");
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57405
diff changeset
   217
        String[] command = getCommand(args);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   218
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   219
            retVal = execute(outfile, command);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   220
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   221
            if (outfile.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   222
                System.err.println(Files.readString(outfile.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   223
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   224
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   225
        }
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
        String output = Files.readString(outfile.toPath());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   228
        if (retValZero) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   229
            if (retVal != 0) {
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57405
diff changeset
   230
                System.err.println("command run:");
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57405
diff changeset
   231
                for (String s : command) { System.err.println(s); }
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57405
diff changeset
   232
                System.err.println("command output:");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   233
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   234
                throw new AssertionError("jpackage exited with error: " + retVal);
57031
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
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   237
            if (retVal == 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   238
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   239
                throw new AssertionError("jpackage exited without error: " + retVal);
57031
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
        }
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
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   244
            System.out.println("output =");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   245
            System.out.println(output);
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
        return output;
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   251
    public static String executeToolProvider(boolean retValZero, String... args) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   252
        StringWriter writer = new StringWriter();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   253
        PrintWriter pw = new PrintWriter(writer);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   254
        int retVal = JPACKAGE_TOOL.run(pw, pw, args);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   255
        String output = writer.toString();
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
        if (retValZero) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   258
            if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   259
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   260
                throw new AssertionError("jpackage exited with error: " + retVal);
57031
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
        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   263
            if (retVal == 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   264
                System.err.println(output);
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   265
                throw new AssertionError("jpackage exited without error");
57031
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
        }
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
        if (VERBOSE) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   270
            System.out.println("output =");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   271
            System.out.println(output);
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
        return output;
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   277
    public static boolean isWindows() {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   278
        return (OS.contains("win"));
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   281
    public static boolean isOSX() {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   282
        return (OS.contains("mac"));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   283
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   284
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   285
    public static boolean isLinux() {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   286
        return ((OS.contains("nix") || OS.contains("nux")));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   287
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   288
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   289
    public static void createHelloImageJar(String inputDir) throws Exception {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   290
        createJar(false, "Hello", "image", inputDir);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   291
    }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   292
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   293
    public static void createHelloImageJar() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   294
        createJar(false, "Hello", "image", "input");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   295
    }
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   296
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   297
    public static void createHelloImageJarWithMainClass() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   298
        createJar(true, "Hello", "image", "input");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   299
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   300
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   301
    public static void createHelloInstallerJar() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   302
        createJar(false, "Hello", "installer", "input");
57031
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
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   305
    public static void createHelloInstallerJarWithMainClass() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   306
        createJar(true, "Hello", "installer", "input");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   307
    }
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   308
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   309
    private static void createJar(boolean mainClassAttribute, String name,
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   310
        String testType, String inputDir) throws Exception {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   311
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   312
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   313
        File input = new File(inputDir);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   314
        if (!input.exists()) {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   315
            input.mkdirs();
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   316
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   317
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   318
        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
   319
                + File.separator + testType + File.separator + name + ".java");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   320
        Path dst = Path.of(name + ".java");
57405
539d8b3f9e1e 8224597: create automated tests for platform create-app-image options
herrick
parents: 57395
diff changeset
   321
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   322
        if (dst.toFile().exists()) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   323
            Files.delete(dst);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   324
        }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   325
        Files.copy(src, dst);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   326
57031
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
        File javacLog = new File("javac.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   329
        try {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   330
            retVal = execute(javacLog, JAVAC.toString(), name + ".java");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   331
        } catch (Exception ex) {
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 ex;
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
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   339
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   340
                System.err.println(Files.readString(javacLog.toPath()));
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
            throw new AssertionError("javac exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   343
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   344
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   345
        File jarLog = new File("jar.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   346
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   347
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   348
            args.add(JAR.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   349
            args.add("-c");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   350
            args.add("-v");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   351
            args.add("-f");
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   352
            args.add(inputDir + File.separator + name.toLowerCase() + ".jar");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   353
            if (mainClassAttribute) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   354
                args.add("-e");
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   355
                args.add(name);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   356
            }
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
   357
            args.add(name + ".class");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   358
            retVal = execute(jarLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   359
        } catch (Exception ex) {
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 ex;
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
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   367
            if (jarLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   368
                System.err.println(Files.readString(jarLog.toPath()));
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
            throw new AssertionError("jar exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   371
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   372
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   373
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   374
    public static void createHelloModule() throws Exception {
58305
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   375
        createModule("Hello.java", "input", "hello", null, true);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   376
    }
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   377
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   378
    public static void createHelloModule(String version) throws Exception {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   379
        createModule("Hello.java", "input", "hello", version, true);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   380
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   381
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   382
    public static void createOtherModule() throws Exception {
58305
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   383
        createModule("Other.java", "input-other", "other", null, false);
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   384
    }
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   385
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   386
    private static void createModule(String javaFile, String inputDir,
58305
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   387
            String aName, String version, boolean createModularJar) throws Exception {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   388
        int retVal;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   389
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   390
        File input = new File(inputDir);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   391
        if (!input.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   392
            input.mkdir();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   393
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   394
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   395
        File module = new File("module" + File.separator + "com." + aName);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   396
        if (!module.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   397
            module.mkdirs();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   398
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   399
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   400
        File javacLog = new File("javac.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   401
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   402
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   403
            args.add(JAVAC.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   404
            args.add("-d");
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   405
            args.add("module" + File.separator + "com." + aName);
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   406
            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
   407
                    + "com." + aName + File.separator + "module-info.java");
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   408
            args.add(TEST_SRC_ROOT + File.separator + "apps"
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   409
                    + File.separator + "com." + aName + File.separator + "com"
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57314
diff changeset
   410
                    + File.separator + aName + File.separator + javaFile);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   411
            retVal = execute(javacLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   412
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   413
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   414
                System.err.println(Files.readString(javacLog.toPath()));
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
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   417
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   418
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   419
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   420
            if (javacLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   421
                System.err.println(Files.readString(javacLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   422
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   423
            throw new AssertionError("javac exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   424
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   425
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   426
        if (createModularJar) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   427
            File jarLog = new File("jar.log");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   428
            try {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   429
                List<String> args = new ArrayList<>();
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   430
                args.add(JAR.toString());
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   431
                args.add("--create");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   432
                args.add("--file");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   433
                args.add(inputDir + File.separator + "com." + aName + ".jar");
58305
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   434
                if (version != null) {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   435
                    args.add("--module-version");
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   436
                    args.add(version);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents: 57438
diff changeset
   437
                }
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   438
                args.add("-C");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   439
                args.add("module" + File.separator + "com." + aName);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   440
                args.add(".");
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   441
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   442
                retVal = execute(jarLog, args.stream().toArray(String[]::new));
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   443
            } catch (Exception ex) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   444
                if (jarLog.exists()) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   445
                    System.err.println(Files.readString(jarLog.toPath()));
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   446
                }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   447
                throw ex;
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   448
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   449
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   450
            if (retVal != 0) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   451
                if (jarLog.exists()) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   452
                    System.err.println(Files.readString(jarLog.toPath()));
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   453
                }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   454
                throw new AssertionError("jar exited with error: " + retVal);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   455
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   456
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   457
    }
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
    public static void createRuntime() throws Exception {
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   460
        List<String> moreArgs = new ArrayList<>();
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   461
        createRuntime(moreArgs);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   462
    }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   463
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   464
    public static void createRuntime(List<String> moreArgs) throws Exception {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   465
        int retVal;
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
        File jlinkLog = new File("jlink.log");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   468
        try {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   469
            List<String> args = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   470
            args.add(JLINK.toString());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   471
            args.add("--output");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   472
            args.add("runtime");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   473
            args.add("--add-modules");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   474
            args.add("java.base");
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   475
            args.addAll(moreArgs);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   476
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   477
            retVal = execute(jlinkLog, args.stream().toArray(String[]::new));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   478
        } catch (Exception ex) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   479
            if (jlinkLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   480
                System.err.println(Files.readString(jlinkLog.toPath()));
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
            throw ex;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   483
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   484
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   485
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   486
            if (jlinkLog.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   487
                System.err.println(Files.readString(jlinkLog.toPath()));
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   488
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   489
            throw new AssertionError("jlink exited with error: " + retVal);
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   493
    public static String listToArgumentsMap(List<String> arguments, boolean toolProvider) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   494
        if (arguments.isEmpty()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   495
            return "";
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   498
        String argsStr = "";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   499
        for (int i = 0; i < arguments.size(); i++) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   500
            String arg = arguments.get(i);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   501
            argsStr += quote(arg, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   502
            if ((i + 1) != arguments.size()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   503
                argsStr += " ";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   504
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   505
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   506
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   507
        if (!toolProvider && isWindows()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   508
            if (argsStr.contains(" ")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   509
                if (argsStr.contains("\"")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   510
                    argsStr = escapeQuote(argsStr, toolProvider);
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
                argsStr = "\"" + argsStr + "\"";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   513
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   514
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   515
        return argsStr;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   516
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   517
57395
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   518
    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
   519
                throws IOException {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   520
        ArrayList<String> newAList = new ArrayList<>();
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   521
        String fileString = null;
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   522
        for (int i=0; i<cmd.length; i++) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   523
            if (i == ndx) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   524
                newAList.add("@argfile.cmds");
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   525
                fileString = cmd[i];
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   526
            } else if (i > ndx && i < ndx + len) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   527
                fileString += " " + cmd[i];
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   528
            } else {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   529
                newAList.add(cmd[i]);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   530
            }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   531
        }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   532
        if (fileString != null) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   533
            Path path = new File("argfile.cmds").toPath();
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   534
            try (BufferedWriter bw = Files.newBufferedWriter(path);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   535
                    PrintWriter out = new PrintWriter(bw)) {
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   536
                out.println(fileString);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   537
            }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   538
        }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   539
        return newAList.toArray(new String[0]);
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   540
    }
521c02b9eed0 8224130: create additional automated tests for create-app-image
herrick
parents: 57324
diff changeset
   541
57419
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   542
    public static String [] splitAndFilter(String output) {
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   543
        if (output == null) {
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   544
            return null;
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   545
        }
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   546
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   547
        String[] result = output.split("\n");
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   548
        if (result == null || result.length == 0) {
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   549
            return result;
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   550
        }
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   551
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   552
        List<String> origList = new ArrayList(Arrays.asList(result));
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   553
        List<String> newlist = new ArrayList();
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   554
        origList.stream().filter((str) ->
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   555
                (!str.startsWith("Picked up"))).forEachOrdered((str) -> {
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   556
            newlist.add(str);
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   557
        });
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   558
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   559
        return newlist.toArray(new String[newlist.size()]);
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   560
    }
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57414
diff changeset
   561
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   562
    private static String quote(String in, boolean toolProvider) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   563
        if (in == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   564
            return null;
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   567
        if (in.isEmpty()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   568
            return "";
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.contains("=")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   572
            // Not a property
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   573
            if (in.contains(" ")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   574
                in = escapeQuote(in, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   575
                return "\"" + in + "\"";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   576
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   577
            return in;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   578
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   579
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   580
        if (!in.contains(" ")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   581
            return in; // No need to quote
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   582
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   583
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   584
        int paramIndex = in.indexOf("=");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   585
        if (paramIndex <= 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   586
            return in; // Something wrong, just skip quoting
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   587
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   588
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   589
        String param = in.substring(0, paramIndex);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   590
        String value = in.substring(paramIndex + 1);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   591
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   592
        if (value.length() == 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   593
            return in; // No need to quote
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   594
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   595
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   596
        value = escapeQuote(value, toolProvider);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   597
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   598
        return param + "=" + "\"" + value + "\"";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   599
    }
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
    private static String escapeQuote(String in, boolean toolProvider) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   602
        if (in == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   603
            return null;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   604
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   605
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   606
        if (in.isEmpty()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   607
            return "";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   608
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   609
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   610
        if (in.contains("\"")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   611
            // Use code points to preserve non-ASCII chars
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   612
            StringBuilder sb = new StringBuilder();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   613
            int codeLen = in.codePointCount(0, in.length());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   614
            for (int i = 0; i < codeLen; i++) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   615
                int code = in.codePointAt(i);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   616
                // Note: No need to escape '\' on Linux or OS X
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   617
                // jpackage expects us to pass arguments and properties with
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   618
                // quotes and spaces as a map
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   619
                // with quotes being escaped with additional \ for
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   620
                // internal quotes.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   621
                // So if we want two properties below:
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   622
                // -Djnlp.Prop1=Some "Value" 1
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   623
                // -Djnlp.Prop2=Some Value 2
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   624
                // jpackage will need:
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   625
                // "-Djnlp.Prop1=\"Some \\"Value\\" 1\" -Djnlp.Prop2=\"Some Value 2\""
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
   626
                // 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
   627
                // 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
   628
                // "-Djnlp.Prop1=\\\"Some \\\\\\\"Value\\\\\\\" 1\\\" -Djnlp.Prop2=\\\"Some Value 2\\\""
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   629
                switch (code) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   630
                    case '"':
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   631
                        // " -> \" -> \\\"
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   632
                        if (i == 0 || in.codePointAt(i - 1) != '\\') {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   633
                            sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   634
                            sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   635
                        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   636
                        break;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   637
                    case '\\':
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   638
                        // We need to escape already escaped symbols as well
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   639
                        if ((i + 1) < codeLen) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   640
                            int nextCode = in.codePointAt(i + 1);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   641
                            if (nextCode == '"') {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   642
                                // \" -> \\\"
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   643
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   644
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   645
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   646
                                sb.appendCodePoint(nextCode);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   647
                            } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   648
                                sb.appendCodePoint('\\');
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   649
                                sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   650
                            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   651
                        } else {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   652
                            sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   653
                        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   654
                        break;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   655
                    default:
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   656
                        sb.appendCodePoint(code);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   657
                        break;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   658
                }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   659
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   660
            return sb.toString();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   661
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   662
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   663
        return in;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   664
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   665
}