test/jdk/tools/jpackage/share/ModuleMainClassErrorTest.java
author herrick
Sun, 15 Sep 2019 07:34:39 -0400
branchJDK-8200758-branch
changeset 58147 45a9084fe981
parent 58114 42df7de58e39
permissions -rw-r--r--
8230521: rename --output/-o option and add default value (".") Submitted-by: almatvee Reviewed-by: herrick, asemenyuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     1
/*
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     4
 *
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     8
 *
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    13
 * accompanied this code).
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    14
 *
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    18
 *
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    21
 * questions.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    22
 */
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    23
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    24
import java.io.File;
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    25
import java.nio.file.Files;
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    26
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    27
/*
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    28
 * @test
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    29
 * @summary jpackage create image with no main class arguments and with main-class attribute
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    30
 * @library ../helpers
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    31
 * @build JPackageHelper
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    32
 * @build JPackagePath
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    33
 * @modules jdk.jpackage
57446
5a5b85f00a63 8226891: rename and re-layout jpackage tests.
herrick
parents: 57445
diff changeset
    34
 * @run main/othervm -Xmx512m ModuleMainClassErrorTest
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    35
 */
57446
5a5b85f00a63 8226891: rename and re-layout jpackage tests.
herrick
parents: 57445
diff changeset
    36
public class ModuleMainClassErrorTest {
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    37
    private static final String OUTPUT = "output";
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    38
    private static final String app = JPackagePath.getApp();
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    39
    private static final String appOutput = JPackagePath.getAppOutputFile();
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    40
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    41
    private static final String [] CMD1 = {
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57446
diff changeset
    42
        "--package-type", "app-image",
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58114
diff changeset
    43
        "--dest", OUTPUT,
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    44
        "--name", "test",
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    45
        "--module", "com.hello",
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    46
        "--module-path", "input"};
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    47
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    48
    private static final String [] CMD2 = {
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57446
diff changeset
    49
        "--package-type", "app-image",
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58114
diff changeset
    50
        "--dest", OUTPUT,
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    51
        "--name", "test",
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    52
        "--module", "com.hello/com.hello.Hello",
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    53
        "--module-path", "input"};
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    54
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    55
    private static void validate(String buildOutput) throws Exception {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    56
57445
405ddd80496e 8226904: current working directory wrong running jpackage app
herrick
parents: 57414
diff changeset
    57
        File outfile = new File(appOutput);
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    58
        int retVal = JPackageHelper.execute(outfile, app);
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    59
        if (retVal != 0) {
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    60
            throw new AssertionError(
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    61
                   "Test application exited with error: ");
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    62
        }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    63
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    64
        if (!outfile.exists()) {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    65
            throw new AssertionError(appOutput + " was not created");
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    66
        }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    67
        String output = Files.readString(outfile.toPath());
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    68
        String[] result = output.split("\n");
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    69
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    70
        if (!result[0].trim().equals("jpackage test application")) {
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    71
            throw new AssertionError("Unexpected result[0]: " + result[0]);
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    72
        }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    73
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    74
        if (!result[1].trim().equals("args.length: 0")) {
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    75
            throw new AssertionError("Unexpected result[1]: " + result[1]);
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    76
        }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    77
    }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    78
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    79
    public static void main(String[] args) throws Exception {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    80
        JPackageHelper.createHelloModule();
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    81
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    82
        JPackageHelper.deleteOutputFolder(OUTPUT);
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    83
        JPackageHelper.executeCLI(false, CMD1);
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    84
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    85
        JPackageHelper.deleteOutputFolder(OUTPUT);
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    86
        JPackageHelper.executeToolProvider(false, CMD1);
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    87
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    88
        JPackageHelper.deleteOutputFolder(OUTPUT);
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    89
        validate(JPackageHelper.executeCLI(true, CMD2));
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    90
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    91
        JPackageHelper.deleteOutputFolder(OUTPUT);
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57314
diff changeset
    92
        validate(JPackageHelper.executeToolProvider(true, CMD2));
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    93
    }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    94
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    95
}