test/jdk/jdk/modules/etc/JdkQualifiedExportTest.java
author kvn
Mon, 06 May 2019 20:05:19 -0700
changeset 54732 2d012a75d35c
parent 47598 92aab488afdc
child 57521 d0c2e34bae88
permissions -rw-r--r--
8223332: Update JVMCI Reviewed-by: never, dnsimon
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44162
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
     1
/*
54732
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 47598
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
44162
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
     4
 *
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
     8
 *
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    13
 * accompanied this code).
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    14
 *
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    18
 *
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    21
 * questions.
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    22
 */
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    23
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    24
/**
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    25
 * @test
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    26
 * @bug 8176537
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    27
 * @summary Check JDK modules have no qualified export to any upgradeable module
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.module
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    29
 * @run main JdkQualifiedExportTest
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    30
 */
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    31
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    32
import jdk.internal.module.ModuleHashes;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    33
import jdk.internal.module.ModuleInfo;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    34
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    35
import java.io.IOException;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    36
import java.io.InputStream;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    37
import java.io.UncheckedIOException;
44840
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
    38
import java.lang.module.Configuration;
44162
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    39
import java.lang.module.ModuleDescriptor;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    40
import java.lang.module.ModuleDescriptor.Exports;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    41
import java.lang.module.ModuleDescriptor.Opens;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    42
import java.lang.module.ModuleFinder;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    43
import java.lang.module.ModuleReference;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    44
import java.util.Collections;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    45
import java.util.Comparator;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    46
import java.util.HashMap;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    47
import java.util.HashSet;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    48
import java.util.Map;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    49
import java.util.Set;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    50
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    51
public class JdkQualifiedExportTest {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    52
    public static void main(String... args) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    53
        // check all system modules
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    54
        ModuleFinder.ofSystem().findAll()
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    55
                    .stream()
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    56
                    .map(ModuleReference::descriptor)
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    57
                    .sorted(Comparator.comparing(ModuleDescriptor::name))
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    58
                    .forEach(JdkQualifiedExportTest::check);
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    59
    }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    60
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    61
    static void check(ModuleDescriptor md) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    62
        // skip checking if this is an upgradeable module
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    63
        if (!HashedModules.contains(md.name())) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    64
            return;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    65
        }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    66
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    67
        checkExports(md);
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    68
        checkOpens(md);
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    69
    }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    70
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    71
    static Set<String> KNOWN_EXCEPTIONS =
45656
5fa8775b3184 8176508: Update JAX-WS RI integration to latest version
aefimov
parents: 44840
diff changeset
    72
        Set.of("jdk.internal.vm.ci/jdk.vm.ci.services",
47598
92aab488afdc 8188776: jdk.internal.vm.ci can't export package to upgradeable modules
kvn
parents: 47216
diff changeset
    73
               "jdk.internal.vm.ci/jdk.vm.ci.runtime",
54732
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 47598
diff changeset
    74
               "jdk.internal.vm.ci/jdk.vm.ci.hotspot",
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 47598
diff changeset
    75
               "jdk.internal.vm.ci/jdk.vm.ci.meta",
2d012a75d35c 8223332: Update JVMCI
kvn
parents: 47598
diff changeset
    76
               "jdk.internal.vm.ci/jdk.vm.ci.code",
44162
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    77
               "jdk.jsobject/jdk.internal.netscape.javascript.spi");
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    78
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    79
    static void checkExports(ModuleDescriptor md) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    80
        // build a map of upgradeable module to Exports that are qualified to it
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    81
        // skip the qualified exports
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    82
        Map<String, Set<Exports>> targetToExports = new HashMap<>();
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    83
        md.exports().stream()
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    84
          .filter(Exports::isQualified)
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    85
          .forEach(e -> e.targets().stream()
44840
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
    86
                         .filter(mn -> accept(md, mn))
44162
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    87
                         .forEach(t -> targetToExports.computeIfAbsent(t, _k -> new HashSet<>())
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    88
                                                      .add(e)));
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    89
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    90
        if (targetToExports.size() > 0) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    91
            String mn = md.name();
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    92
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    93
            System.err.println(mn);
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    94
            targetToExports.entrySet().stream()
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    95
                .sorted(Map.Entry.comparingByKey())
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    96
                .forEach(e -> {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    97
                    e.getValue().stream()
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    98
                     .forEach(exp -> System.err.format("    exports %s to %s%n",
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
    99
                                                       exp.source(), e.getKey()));
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   100
                });
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   101
44840
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   102
            // no qualified exports to upgradeable modules are expected
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   103
            // except the known exception cases
44162
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   104
            if (targetToExports.entrySet().stream()
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   105
                    .flatMap(e -> e.getValue().stream())
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   106
                    .anyMatch(e -> !KNOWN_EXCEPTIONS.contains(mn + "/" + e.source()))) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   107
                throw new RuntimeException(mn + " can't export package to upgradeable modules");
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   108
            }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   109
        }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   110
    }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   111
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   112
    static void checkOpens(ModuleDescriptor md) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   113
        // build a map of upgradeable module to Exports that are qualified to it
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   114
        // skip the qualified exports
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   115
        Map<String, Set<Opens>> targetToOpens = new HashMap<>();
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   116
        md.opens().stream()
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   117
            .filter(Opens::isQualified)
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   118
            .forEach(e -> e.targets().stream()
44840
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   119
                           .filter(mn -> accept(md, mn))
44162
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   120
                           .forEach(t -> targetToOpens.computeIfAbsent(t, _k -> new HashSet<>())
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   121
                                                      .add(e)));
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   122
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   123
        if (targetToOpens.size() > 0) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   124
            String mn = md.name();
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   125
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   126
            System.err.println(mn);
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   127
            targetToOpens.entrySet().stream()
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   128
                .sorted(Map.Entry.comparingByKey())
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   129
                .forEach(e -> {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   130
                    e.getValue().stream()
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   131
                     .forEach(exp -> System.err.format("    opens %s to %s%n",
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   132
                                                       exp.source(), e.getKey()));
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   133
                });
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   134
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   135
            throw new RuntimeException(mn + " can't open package to upgradeable modules");
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   136
        }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   137
    }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   138
44840
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   139
    /**
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   140
     * Returns true if target is an upgradeable module but not required
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   141
     * by the source module directly and indirectly.
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   142
     */
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   143
    private static boolean accept(ModuleDescriptor source, String target) {
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   144
        if (HashedModules.contains(target))
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   145
            return false;
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   146
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   147
        if (!ModuleFinder.ofSystem().find(target).isPresent())
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   148
            return false;
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   149
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   150
        Configuration cf = Configuration.empty().resolve(ModuleFinder.of(),
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   151
                                                         ModuleFinder.ofSystem(),
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   152
                                                         Set.of(source.name()));
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   153
        return !cf.findModule(target).isPresent();
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   154
    }
2761d60c363f 8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents: 44545
diff changeset
   155
44162
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   156
    private static class HashedModules {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   157
        static Set<String> HASHED_MODULES = hashedModules();
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   158
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   159
        static Set<String> hashedModules() {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   160
            Module javaBase = Object.class.getModule();
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   161
            try (InputStream in = javaBase.getResourceAsStream("module-info.class")) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   162
                ModuleInfo.Attributes attrs = ModuleInfo.read(in, null);
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   163
                ModuleHashes hashes = attrs.recordedHashes();
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   164
                if (hashes == null)
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   165
                    return Collections.emptySet();
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   166
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   167
                Set<String> names = new HashSet<>(hashes.names());
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   168
                names.add(javaBase.getName());
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   169
                return names;
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   170
            } catch (IOException e) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   171
                throw new UncheckedIOException(e);
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   172
            }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   173
        }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   174
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   175
        /*
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   176
         * Returns true if the named module is tied with java.base,
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   177
         * i.e. non-upgradeable
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   178
         */
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   179
        static boolean contains(String mn) {
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   180
            return HASHED_MODULES.contains(mn);
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   181
        }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   182
    }
725cbaef3403 8176537: Add test to check JDK modules to have no qualifed exports to upgradeable modules
mchung
parents:
diff changeset
   183
}