test/jdk/tools/jpackage/share/AppVersionModuleTest.java
author herrick
Thu, 26 Sep 2019 10:37:37 -0400
branchJDK-8200758-branch
changeset 58360 fd45b7e2c027
parent 58305 d42b1f6960aa
permissions -rw-r--r--
8231382: Use main class from main module if available Submitted-by: almatvee Reviewed-by: herrick, asemenyuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58305
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
     1
/*
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
     4
 *
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
     8
 *
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    13
 * accompanied this code).
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    14
 *
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    18
 *
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    21
 * questions.
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    22
 */
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    23
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    24
import java.io.File;
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    25
import java.nio.file.Files;
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    26
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    27
/*
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    28
 * @test
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    29
 * @summary jpackage create image using version from main module
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    30
 * @library ../helpers
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    31
 * @build JPackageHelper
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    32
 * @build JPackagePath
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    33
 * @modules jdk.jpackage
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    34
 * @run main/othervm -Xmx512m AppVersionModuleTest
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    35
 */
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    36
public class AppVersionModuleTest {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    37
    private static final String OUTPUT = "output";
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    38
    private static final String appCfg = JPackagePath.getAppCfg();
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    39
    private static final String MODULE_VERSION = "2.7";
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    40
    private static final String CLI_VERSION = "3.5";
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    41
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    42
    private static final String[] CMD_MODULE_VERSION = {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    43
        "--package-type", "app-image",
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    44
        "--input", "input",
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    45
        "--dest", OUTPUT,
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    46
        "--name", "test",
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    47
        "--module", "com.hello/com.hello.Hello",
58360
fd45b7e2c027 8231382: Use main class from main module if available
herrick
parents: 58305
diff changeset
    48
        "--module-path", "input"
fd45b7e2c027 8231382: Use main class from main module if available
herrick
parents: 58305
diff changeset
    49
    };
58305
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    50
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    51
    private static final String[] CMD_CLI_VERSION = {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    52
        "--package-type", "app-image",
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    53
        "--input", "input",
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    54
        "--dest", OUTPUT,
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    55
        "--name", "test",
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    56
        "--module", "com.hello/com.hello.Hello",
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    57
        "--module-path", "input",
58360
fd45b7e2c027 8231382: Use main class from main module if available
herrick
parents: 58305
diff changeset
    58
        "--app-version", CLI_VERSION
fd45b7e2c027 8231382: Use main class from main module if available
herrick
parents: 58305
diff changeset
    59
    };
58305
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    60
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    61
    private static void validate(String version)
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    62
            throws Exception {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    63
        File outfile = new File(appCfg);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    64
        if (!outfile.exists()) {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    65
            throw new AssertionError(appCfg + " was not created");
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    66
        }
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    67
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    68
        String output = Files.readString(outfile.toPath());
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    69
        if (version == null) {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    70
            version = MODULE_VERSION;
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    71
        }
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    72
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    73
        String expected = "app.version=" + version;
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    74
        if (!output.contains(expected)) {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    75
            System.err.println("Expected: " + expected);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    76
            throw new AssertionError("Cannot find expected entry in config file");
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    77
        }
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    78
    }
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    79
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    80
    private static void testVersion() throws Exception {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    81
        JPackageHelper.executeCLI(true, CMD_MODULE_VERSION);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    82
        validate(null);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    83
        JPackageHelper.deleteOutputFolder(OUTPUT);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    84
        JPackageHelper.executeCLI(true, CMD_CLI_VERSION);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    85
        validate(CLI_VERSION);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    86
    }
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    87
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    88
    private static void testVersionToolProvider() throws Exception {
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    89
        JPackageHelper.deleteOutputFolder(OUTPUT);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    90
        JPackageHelper.executeToolProvider(true, CMD_MODULE_VERSION);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    91
        validate(null);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    92
        JPackageHelper.deleteOutputFolder(OUTPUT);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    93
        JPackageHelper.executeToolProvider(true, CMD_CLI_VERSION);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    94
        validate(CLI_VERSION);
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    95
    }
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    96
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
    97
    public static void main(String[] args) throws Exception {
58360
fd45b7e2c027 8231382: Use main class from main module if available
herrick
parents: 58305
diff changeset
    98
        JPackageHelper.createHelloModule(
fd45b7e2c027 8231382: Use main class from main module if available
herrick
parents: 58305
diff changeset
    99
                new JPackageHelper.ModuleArgs(MODULE_VERSION, null));
58305
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
   100
        testVersion();
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
   101
        testVersionToolProvider();
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
   102
    }
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
   103
d42b1f6960aa 8230651: Use version string from main module
herrick
parents:
diff changeset
   104
}