test/jdk/tools/jar/modularJar/src/bar/jdk/test/bar/Bar.java
author mchung
Tue, 06 Nov 2018 10:01:16 -0800
changeset 52427 3c6aa484536c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8211122: Reduce the number of internal classes made accessible to jdk.unsupported Reviewed-by: alanb, dfuchs, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
     7
 * published by the Free Software Foundation.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
package jdk.test.bar;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.lang.module.ModuleDescriptor;
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    27
import java.lang.module.ModuleDescriptor.Exports;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38468
diff changeset
    28
import java.lang.module.ModuleDescriptor.Provides;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    29
import java.lang.module.ModuleReference;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    30
import java.lang.module.ResolvedModule;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.Optional;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.StringJoiner;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38468
diff changeset
    33
import java.util.HashSet;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38468
diff changeset
    34
import java.util.Set;
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 47216
diff changeset
    35
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    36
import jdk.internal.module.ModuleHashes;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    37
import jdk.internal.module.ModuleReferenceImpl;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import jdk.test.bar.internal.Message;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
public class Bar {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
        System.out.println("message:" + Message.get());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
        ModuleDescriptor md = Bar.class.getModule().getDescriptor();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
        System.out.println("nameAndVersion:" + md.toNameAndVersion());
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    46
        md.mainClass().ifPresent(mc -> System.out.println("mainClass:" + mc));
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    47
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    48
        StringJoiner sj = new StringJoiner(",");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    49
        md.requires().stream().map(ModuleDescriptor.Requires::name).sorted().forEach(sj::add);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    50
        System.out.println("requires:" + sj.toString());
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    51
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    52
        sj = new StringJoiner(",");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    53
        md.exports().stream().map(ModuleDescriptor.Exports::source).sorted().forEach(sj::add);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    54
        if (!sj.toString().equals(""))
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    55
            System.out.println("exports:" + sj.toString());
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    56
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    57
        sj = new StringJoiner(",");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    58
        md.uses().stream().sorted().forEach(sj::add);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    59
        if (!sj.toString().equals(""))
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    60
            System.out.println("uses:" + sj.toString());
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    61
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    62
        sj = new StringJoiner(",");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38468
diff changeset
    63
        md.provides().stream().map(Provides::service).sorted().forEach(sj::add);
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    64
        if (!sj.toString().equals(""))
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    65
            System.out.println("provides:" + sj.toString());
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    66
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    67
        sj = new StringJoiner(",");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38468
diff changeset
    68
        Set<String> concealed = new HashSet<>(md.packages());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38468
diff changeset
    69
        md.exports().stream().map(Exports::source).forEach(concealed::remove);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38468
diff changeset
    70
        concealed.forEach(sj::add);
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    71
        if (!sj.toString().equals(""))
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38468
diff changeset
    72
            System.out.println("contains:" + sj.toString());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    74
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    75
        Module foo = jdk.test.foo.Foo.class.getModule();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    76
        Optional<ResolvedModule> om = foo.getLayer().configuration().findModule(foo.getName());
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    77
        assert om.isPresent();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    78
        ModuleReference mref = om.get().reference();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    79
        assert mref instanceof ModuleReferenceImpl;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    80
        ModuleHashes hashes = ((ModuleReferenceImpl) mref).recordedHashes();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    81
        assert hashes != null;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    82
        System.out.println("hashes:" + hashes.hashFor("bar"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
}