test/jdk/tools/jpackage/share/RuntimePackageTest.java
author herrick
Wed, 23 Oct 2019 10:37:54 -0400
branchJDK-8200758-branch
changeset 58762 0fe62353385b
parent 58761 88e2753a2334
child 58994 b09ba68c6a19
permissions -rw-r--r--
8232281: jpackage is not always reporting an error when no main class specified Reviewed-by: asemenyuk, asemenuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     1
/*
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     4
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     8
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    13
 * accompanied this code).
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    14
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    18
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    21
 * questions.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    22
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    23
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    24
import java.io.IOException;
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    25
import java.nio.file.Files;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents: 58113
diff changeset
    26
import java.nio.file.Path;
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    27
import java.util.HashSet;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents: 58113
diff changeset
    28
import java.util.Optional;
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    29
import java.util.Set;
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    30
import java.util.stream.Collectors;
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    31
import jdk.jpackage.test.*;
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    32
import jdk.jpackage.test.Annotations.Test;
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    33
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    34
/**
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    35
 * Test --runtime-image parameter.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    36
 * Output of the test should be RuntimePackageTest*.* installer.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    37
 * The installer should install Java Runtime without an application.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    38
 * Installation directory should not have "app" subfolder and should not have
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    39
 * an application launcher.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    40
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    41
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    42
 * Windows:
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    43
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    44
 * Java runtime should be installed in %ProgramFiles%\RuntimePackageTest directory.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    45
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    46
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    47
/*
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    48
 * @test
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    49
 * @summary jpackage with --runtime-image
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    50
 * @library ../helpers
58761
88e2753a2334 8231972: Build a stable list of jpackager tests for SQE
herrick
parents: 58696
diff changeset
    51
 * @key jpackagePlatformPackage
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    52
 * @build jdk.jpackage.test.*
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    53
 * @comment Temporary disable for Linux and OSX until functionality implemented
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents: 58113
diff changeset
    54
 * @requires (os.family != "mac")
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    55
 * @modules jdk.jpackage/jdk.jpackage.internal
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    56
 * @compile RuntimePackageTest.java
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    57
 * @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    58
 *  --jpt-run=RuntimePackageTest
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    59
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    60
public class RuntimePackageTest {
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    61
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    62
    @Test
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    63
    public static void test() {
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    64
        new PackageTest()
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    65
        .addInitializer(cmd -> {
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    66
            cmd.addArguments("--runtime-image", Optional.ofNullable(
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    67
                    JPackageCommand.DEFAULT_RUNTIME_IMAGE).orElse(Path.of(
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    68
                            System.getProperty("java.home"))));
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    69
            // Remove --input parameter from jpackage command line as we don't
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    70
            // create input directory in the test and jpackage fails
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    71
            // if --input references non existant directory.
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    72
            cmd.removeArgumentWithValue("--input");
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    73
        })
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    74
        .addInstallVerifier(cmd -> {
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    75
            Set<Path> srcRuntime = listFiles(Path.of(cmd.getArgumentValue("--runtime-image")));
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    76
            Set<Path> dstRuntime = listFiles(cmd.appRuntimeDirectory());
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    77
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    78
            Set<Path> intersection = new HashSet<>(srcRuntime);
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    79
            intersection.retainAll(dstRuntime);
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    80
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    81
            srcRuntime.removeAll(intersection);
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    82
            dstRuntime.removeAll(intersection);
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    83
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    84
            assertFileListEmpty(srcRuntime, "Missing");
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    85
            assertFileListEmpty(dstRuntime, "Unexpected");
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    86
        })
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    87
        .run();
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    88
    }
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    89
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    90
    private static Set<Path> listFiles(Path root) throws IOException {
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    91
        try (var files = Files.walk(root)) {
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    92
            return files.map(root::relativize).collect(Collectors.toSet());
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    93
        }
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    94
    }
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    95
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    96
    private static void assertFileListEmpty(Set<Path> paths, String msg) {
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    97
        TKit.assertTrue(paths.isEmpty(), String.format(
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    98
                "Check there are no %s files in installed image",
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
    99
                msg.toLowerCase()), () -> {
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
   100
            String msg2 = String.format("%s %d files", msg, paths.size());
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
   101
            TKit.trace(msg2 + ":");
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
   102
            paths.stream().map(Path::toString).sorted().forEachOrdered(
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
   103
                    TKit::trace);
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58761
diff changeset
   104
            TKit.trace("Done");
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents: 58113
diff changeset
   105
        });
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
   106
    }
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
   107
}