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