test/jdk/tools/jlink/ModuleNamesOrderTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 42690 jdk/test/tools/jlink/ModuleNamesOrderTest.java@93d0411bd67d
child 48206 8b967e200e35
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42471
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
     1
/*
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
     4
 *
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
     8
 *
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    13
 * accompanied this code).
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    14
 *
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    18
 *
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    21
 * questions.
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    22
 */
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    23
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    24
import java.io.File;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    25
import java.io.FileReader;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    26
import java.io.IOException;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    27
import java.io.PrintWriter;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    28
import java.io.StringWriter;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    29
import java.nio.file.Path;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    30
import java.util.Properties;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    31
import java.util.spi.ToolProvider;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    32
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    33
import tests.Helper;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    34
import tests.JImageGenerator;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    35
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    36
/*
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    37
 * @test
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    38
 * @bug 8168925
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    39
 * @summary MODULES property should be topologically ordered and space-separated list
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    40
 * @library ../lib
42690
93d0411bd67d 8171070: Test ModuleNamesOrderTest.java fails
sundar
parents: 42471
diff changeset
    41
 * @modules java.base/jdk.internal.jimage
93d0411bd67d 8171070: Test ModuleNamesOrderTest.java fails
sundar
parents: 42471
diff changeset
    42
 *          jdk.jdeps/com.sun.tools.classfile
93d0411bd67d 8171070: Test ModuleNamesOrderTest.java fails
sundar
parents: 42471
diff changeset
    43
 *          jdk.jlink/jdk.tools.jlink.internal
93d0411bd67d 8171070: Test ModuleNamesOrderTest.java fails
sundar
parents: 42471
diff changeset
    44
 *          jdk.jlink/jdk.tools.jmod
93d0411bd67d 8171070: Test ModuleNamesOrderTest.java fails
sundar
parents: 42471
diff changeset
    45
 *          jdk.jlink/jdk.tools.jimage
93d0411bd67d 8171070: Test ModuleNamesOrderTest.java fails
sundar
parents: 42471
diff changeset
    46
 *          jdk.compiler
42471
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    47
 * @build tests.*
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    48
 * @run main ModuleNamesOrderTest
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    49
 */
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    50
public class ModuleNamesOrderTest {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    51
    static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    52
        .orElseThrow(() ->
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    53
            new RuntimeException("jlink tool not found")
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    54
        );
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    55
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    56
    public static void main(String[] args) throws Exception {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    57
        Helper helper = Helper.newHelper();
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    58
        if (helper == null) {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    59
            System.err.println("Test not run");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    60
            return;
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    61
        }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    62
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    63
        Path outputDir = helper.createNewImageDir("image8168925");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    64
        JImageGenerator.getJLinkTask()
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    65
                .modulePath(helper.defaultModulePath())
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    66
                .output(outputDir)
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    67
                .addMods("jdk.scripting.nashorn")
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    68
                .call().assertSuccess();
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    69
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    70
        File release = new File(outputDir.toString(), "release");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    71
        if (!release.exists()) {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    72
            throw new AssertionError("release not generated");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    73
        }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    74
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    75
        Properties props = new Properties();
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    76
        try (FileReader reader = new FileReader(release)) {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    77
            props.load(reader);
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    78
        }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    79
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    80
        String modules = props.getProperty("MODULES");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    81
        if (!modules.startsWith("\"java.base ")) {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    82
            throw new AssertionError("MODULES should start with 'java.base'");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    83
        }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    84
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    85
        if (!modules.endsWith(" jdk.scripting.nashorn\"")) {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    86
            throw new AssertionError("MODULES end with 'jdk.scripting.nashorn'");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    87
        }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    88
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    89
        checkDependency(modules, "java.logging", "java.base");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    90
        checkDependency(modules, "jdk.dynalink", "java.logging");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    91
        checkDependency(modules, "java.scripting", "java.base");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    92
        checkDependency(modules, "jdk.scripting.nashorn", "java.logging");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    93
        checkDependency(modules, "jdk.scripting.nashorn", "jdk.dynalink");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    94
        checkDependency(modules, "jdk.scripting.nashorn", "java.scripting");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    95
    }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    96
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    97
    private static void checkDependency(String modules, String fromMod, String toMod) {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    98
        int fromModIdx = modules.indexOf(fromMod);
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
    99
        if (fromModIdx == -1) {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   100
            throw new AssertionError(fromMod + " is missing in MODULES");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   101
        }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   102
        int toModIdx = modules.indexOf(toMod);
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   103
        if (toModIdx == -1) {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   104
            throw new AssertionError(toMod + " is missing in MODULES");
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   105
        }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   106
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   107
        if (toModIdx > fromModIdx) {
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   108
            throw new AssertionError("in MODULES, " + fromMod + " should appear after " + toMod);
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   109
        }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   110
    }
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff changeset
   111
}