• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ModuleDescriptor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中java.lang.module.ModuleDescriptor的典型用法代码示例。如果您正苦于以下问题:Java ModuleDescriptor类的具体用法?Java ModuleDescriptor怎么用?Java ModuleDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ModuleDescriptor类属于java.lang.module包,在下文中一共展示了ModuleDescriptor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testPackageSuppliedBySelfAndOther

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Test the scenario where a module contains a package p and reads
 * a module that exports package p.
 */
@Test(expectedExceptions = { ResolutionException.class })
public void testPackageSuppliedBySelfAndOther() {

    ModuleDescriptor descriptor1 = newBuilder("m1")
            .requires("m2")
            .packages(Set.of("p"))
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .exports("p")
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);

    // m1 contains package p, module m2 exports package p to m1
    resolve(finder, "m1");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ConfigurationTest.java


示例2: describeModule

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
Optional<ModuleDescriptor> describeModule(URI uri) {
  var path = load(uri);
  if (!path.isPresent()) {
    return Optional.empty();
  }
  try {
    debug("describeModule({0} -> {1})", uri, path);
    return describeModule(path.get(), true);
  } finally {
    try {
      Files.delete(path.get());
    } catch (Exception e) {
      debug("deleting temp file failed: {0}", e);
    }
  }
}
 
开发者ID:jodastephen,项目名称:jpms-module-names,代码行数:17,代码来源:Generator.java


示例3: testOpensToTargets

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
public void testOpensToTargets() {
    Set<String> targets = new HashSet<>();
    targets.add("bar");
    targets.add("gus");
    Opens o = ModuleDescriptor.newModule("foo")
            .opens("p", targets)
            .build()
            .opens()
            .iterator()
            .next();
    assertEquals(o, o);
    assertTrue(o.modifiers().isEmpty());
    assertEquals(o.source(), "p");
    assertTrue(o.isQualified());
    assertTrue(o.targets().size() == 2);
    assertTrue(o.targets().contains("bar"));
    assertTrue(o.targets().contains("gus"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ModuleDescriptorTest.java


示例4: main

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        final String MY_MODULE_NAME = "myModule";

        // Verify that JVMTI reports exactly the same info as Java regarding the named modules
        Asserts.assertEquals(ModuleLayer.boot().modules(), getModulesJVMTI());

        // Load a new named module
        ModuleDescriptor descriptor = ModuleDescriptor.newModule(MY_MODULE_NAME).build();
        ModuleFinder finder = finderOf(descriptor);
        ClassLoader loader = new ClassLoader() {};
        Configuration parent = ModuleLayer.boot().configuration();
        Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of(MY_MODULE_NAME));
        ModuleLayer my = ModuleLayer.boot().defineModules(cf, m -> loader);

        // Verify that the loaded module is indeed reported by JVMTI
        Set<Module> jvmtiModules = getModulesJVMTI();
        for (Module mod : my.modules()) {
            if (!jvmtiModules.contains(mod)) {
                throw new RuntimeException("JVMTI did not report the loaded named module: " + mod.getName());
            }
        }

    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:JvmtiGetAllModulesTest.java


示例5: checkModuleDescriptor

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
static void checkModuleDescriptor(ModuleDescriptor md, String... packages) throws IOException {
    String mainClass = md.name().replace('m', 'p') + ".Main";
    if (!md.mainClass().get().equals(mainClass)) {
        throw new RuntimeException(md.mainClass().toString());
    }

    // ModuleTarget attribute should be present
    if (!hasModuleTarget(md.name())) {
        throw new RuntimeException("ModuleTarget missing for " + md.name());
    }

    Set<String> pkgs = md.packages();
    if (!pkgs.equals(Set.of(packages))) {
        throw new RuntimeException(pkgs + " expected: " + Set.of(packages));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Main.java


示例6: testExportsToTargets

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
public void testExportsToTargets() {
    Set<String> targets = new HashSet<>();
    targets.add("bar");
    targets.add("gus");
    Exports e
        = ModuleDescriptor.newModule("foo")
            .exports("p", targets)
            .build()
            .exports()
            .iterator()
            .next();
    assertEquals(e, e);
    assertTrue(e.modifiers().isEmpty());
    assertEquals(e.source(), "p");
    assertTrue(e.isQualified());
    assertTrue(e.targets().size() == 2);
    assertTrue(e.targets().contains("bar"));
    assertTrue(e.targets().contains("gus"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ModuleDescriptorTest.java


示例7: testInConfiguration4

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Basic test to ensure that no automatic modules are resolved when
 * an automatic module is not a root or required by other modules.
 */
public void testInConfiguration4() throws IOException {
    ModuleDescriptor descriptor1
        = ModuleDescriptor.newModule("m1")
            .requires("java.base")
            .build();

    // automatic modules
    Path dir = Files.createTempDirectory(USER_DIR, "mods");
    createDummyJarFile(dir.resolve("auto1.jar"), "p1/C.class");
    createDummyJarFile(dir.resolve("auto2.jar"), "p2/C.class");
    createDummyJarFile(dir.resolve("auto3.jar"), "p3/C.class");

    // module finder locates m1 and the modules in the directory
    ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
    ModuleFinder finder2 =  ModuleFinder.of(dir);
    ModuleFinder finder = ModuleFinder.compose(finder1, finder2);

    Configuration parent = ModuleLayer.boot().configuration();
    Configuration cf = resolve(parent, finder, "m1");

    // ensure that no automatic module is resolved
    assertTrue(cf.modules().size() == 1);
    assertTrue(cf.findModule("m1").isPresent());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:AutomaticModulesTest.java


示例8: testContainsService2

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Test "uses p.S" where p is contained in a different module.
 */
@Test(expectedExceptions = { ResolutionException.class })
public void testContainsService2() {
    ModuleDescriptor descriptor1 = newBuilder("m1")
            .packages(Set.of("p"))
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .requires("m1")
            .uses("p.S")
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);

    // m2 does not read a module that exports p
    resolve(finder, "m2");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ConfigurationTest.java


示例9: sortedModuleDescriptors

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
@DataProvider(name = "sortedModuleDescriptors")
public Object[][] sortedModuleDescriptors() {
    return new Object[][]{

        { ModuleDescriptor.newModule("m2").build(),
          ModuleDescriptor.newModule("m1").build()
        },

        { ModuleDescriptor.newModule("m").version("2").build(),
          ModuleDescriptor.newModule("m").version("1").build()
        },

        { ModuleDescriptor.newModule("m").version("1").build(),
          ModuleDescriptor.newModule("m").build()
        },

        { ModuleDescriptor.newOpenModule("m").build(),
          ModuleDescriptor.newModule("m").build()
        },

    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ModuleDescriptorTest.java


示例10: testContainsSamePackageAsBootLayer

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
  * Exercise defineModules with a configuration with a module that
  * contains a package that is the same name as a non-exported package in
  * a parent layer.
  */
 public void testContainsSamePackageAsBootLayer() {

     // check assumption that java.base contains sun.launcher
     ModuleDescriptor base = Object.class.getModule().getDescriptor();
     assertTrue(base.packages().contains("sun.launcher"));

     ModuleDescriptor descriptor = newBuilder("m1")
            .requires("java.base")
            .packages(Set.of("sun.launcher"))
            .build();

     ModuleFinder finder = ModuleUtils.finderOf(descriptor);

     Configuration parent = ModuleLayer.boot().configuration();
     Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
     assertTrue(cf.modules().size() == 1);

     ClassLoader loader = new ClassLoader() { };
     ModuleLayer layer = ModuleLayer.boot().defineModules(cf, mn -> loader);
     assertTrue(layer.modules().size() == 1);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:BasicLayerTest.java


示例11: testPackageSuppliedByTwoOthers

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Test two modules exporting package p to a module that reads both.
 */
@Test(expectedExceptions = { ResolutionException.class })
public void testPackageSuppliedByTwoOthers() {

    ModuleDescriptor descriptor1 = newBuilder("m1")
            .requires("m2")
            .requires("m3")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .exports("p")
            .build();

    ModuleDescriptor descriptor3 = newBuilder("m3")
            .exports("p", Set.of("m1"))
            .build();

    ModuleFinder finder
        = ModuleUtils.finderOf(descriptor1, descriptor2, descriptor3);

    // m2 and m3 export package p to module m1
    resolve(finder, "m1");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ConfigurationTest.java


示例12: dedups

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
private void dedups(ModuleDescriptor md) {
    // exports
    for (Exports e : md.exports()) {
        dedupSetBuilder.stringSet(e.targets());
        dedupSetBuilder.exportsModifiers(e.modifiers());
    }

    // opens
    for (Opens opens : md.opens()) {
        dedupSetBuilder.stringSet(opens.targets());
        dedupSetBuilder.opensModifiers(opens.modifiers());
    }

    // requires
    for (Requires r : md.requires()) {
        dedupSetBuilder.requiresModifiers(r.modifiers());
    }

    // uses
    dedupSetBuilder.stringSet(md.uses());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:SystemModulesPlugin.java


示例13: testServiceProviderDependencyNotFound

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Service provider dependency not found
 */
@Test(expectedExceptions = { FindException.class })
public void testServiceProviderDependencyNotFound() {

    // service provider dependency (on m3) not found

    ModuleDescriptor descriptor1 = newBuilder("m1")
            .exports("p")
            .uses("p.S")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .requires("m1")
            .requires("m3")
            .provides("p.S", List.of("q.T"))
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);

    // should throw ResolutionException because m3 is not found
    Configuration cf = resolveAndBind(finder, "m1");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ConfigurationTest.java


示例14: analyzeDeps

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Apply transitive reduction on the resulting graph and reports
 * recommended requires.
 */
private void analyzeDeps() {
    printModuleDescriptor(log, root);

    ModuleDescriptor analyzedDescriptor = descriptor();
    if (!matches(root.descriptor(), analyzedDescriptor)) {
        log.format("  [Suggested module descriptor for %s]%n", root.name());
        analyzedDescriptor.requires()
            .stream()
            .sorted(Comparator.comparing(ModuleDescriptor.Requires::name))
            .forEach(req -> log.format("    requires %s;%n", req));
    }

    ModuleDescriptor reduced = reduced();
    if (!matches(root.descriptor(), reduced)) {
        log.format("  [Transitive reduced graph for %s]%n", root.name());
        reduced.requires()
            .stream()
            .sorted(Comparator.comparing(ModuleDescriptor.Requires::name))
            .forEach(req -> log.format("    requires %s;%n", req));
    }

    checkQualifiedExports();
    log.println();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ModuleAnalyzer.java


示例15: testAutomaticModule

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
public void testAutomaticModule() {
    ModuleDescriptor descriptor = ModuleDescriptor.newAutomaticModule("foo")
            .packages(Set.of("p"))
            .provides("p.Service", List.of("q.ServiceImpl"))
            .build();

    // modifiers
    assertTrue(descriptor.modifiers().contains(ModuleDescriptor.Modifier.AUTOMATIC));
    assertTrue(descriptor.isAutomatic());

    // requires
    assertTrue(descriptor.requires().size() == 1);
    Set<String> names = descriptor.requires()
            .stream()
            .map(Requires::name)
            .collect(Collectors.toSet());
    assertEquals(names, Set.of("java.base"));

    // packages
    assertEquals(descriptor.packages(), Set.of("p", "q"));
    assertTrue(descriptor.exports().isEmpty());
    assertTrue(descriptor.opens().isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ModuleDescriptorTest.java


示例16: testReadsWithPackageFinder

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Test ModuleDescriptor with a packager finder
 */
public void testReadsWithPackageFinder() throws Exception {
    ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
            .requires("java.base")
            .build();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ModuleInfoWriter.write(descriptor, baos);
    ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());

    descriptor = ModuleDescriptor.read(bb, () -> Set.of("p", "q"));

    assertTrue(descriptor.packages().size() == 2);
    assertTrue(descriptor.packages().contains("p"));
    assertTrue(descriptor.packages().contains("q"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ModuleDescriptorTest.java


示例17: Module

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Creates a new named Module. The resulting Module will be defined to the
 * VM but will not read any other modules, will not have any exports setup
 * and will not be registered in the service catalog.
 */
Module(ModuleLayer layer,
       ClassLoader loader,
       ModuleDescriptor descriptor,
       URI uri)
{
    this.layer = layer;
    this.name = descriptor.name();
    this.loader = loader;
    this.descriptor = descriptor;

    // define module to VM

    boolean isOpen = descriptor.isOpen() || descriptor.isAutomatic();
    Version version = descriptor.version().orElse(null);
    String vs = Objects.toString(version, null);
    String loc = Objects.toString(uri, null);
    String[] packages = descriptor.packages().toArray(new String[0]);
    defineModule0(this, isOpen, vs, loc, packages);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:Module.java


示例18: Loader

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Creates a {@code Loader} in a loader pool that loads classes/resources
 * from one module.
 */
public Loader(ResolvedModule resolvedModule,
              LoaderPool pool,
              ClassLoader parent)
{
    super("Loader-" + resolvedModule.name(), parent);

    this.pool = pool;
    this.parent = parent;

    ModuleReference mref = resolvedModule.reference();
    ModuleDescriptor descriptor = mref.descriptor();
    String mn = descriptor.name();
    this.nameToModule = Map.of(mn, mref);

    Map<String, LoadedModule> localPackageToModule = new HashMap<>();
    LoadedModule lm = new LoadedModule(mref);
    descriptor.packages().forEach(pn -> localPackageToModule.put(pn, lm));
    this.localPackageToModule = localPackageToModule;

    this.acc = AccessController.getContext();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:Loader.java


示例19: testServiceTypePackageNotExported2

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Test "provides p.S" where p is not exported to the module.
 */
@Test(expectedExceptions = { ResolutionException.class })
public void testServiceTypePackageNotExported2() {
    ModuleDescriptor descriptor1 = newBuilder("m1")
            .provides("p.S", List.of("q.T"))
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1);

    // m1 does not read a module that exports p
    resolve(finder, "m1");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ConfigurationTest.java


示例20: testQualifiedExports6

import java.lang.module.ModuleDescriptor; //导入依赖的package包/类
/**
 * Test layers with a qualified export. The module exporting the package
 * reads the target module in the parent layer (due to requires transitive).
 *
 * - Configuration/layer1: m1, m2 { requires transitive m1; }
 * - Configuration/layer2: m1, m3 { requires m2; exports p to m1; }
 */
public void testQualifiedExports6() {
    // create layer1 with m1 and m2
    ModuleDescriptor descriptor1 = newBuilder("m1").build();
    ModuleDescriptor descriptor2 = newBuilder("m2")
            .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
            .build();
    ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
    Configuration cf1 = resolve(finder1, "m2");
    ClassLoader loader1 = new ClassLoader() { };
    ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> loader1);
    assertTrue(layer1.modules().size() == 2);

    // create layer2 with m1 and m3
    ModuleDescriptor descriptor3 = newBuilder("m3")
            .requires("m2")
            .exports("p", Set.of("m1"))
            .build();
    ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor3);
    Configuration cf2 = resolve(cf1, finder2, "m1", "m3");
    ClassLoader loader2 = new ClassLoader() { };
    ModuleLayer layer2 = layer1.defineModules(cf2, mn -> loader2);
    assertTrue(layer2.modules().size() == 2);

    Module m1_v1 = layer1.findModule("m1").get();
    Module m2 = layer1.findModule("m2").get();

    Module m1_v2 = layer2.findModule("m1").get();
    Module m3 = layer2.findModule("m3").get();

    assertTrue(m3.canRead(m1_v1));
    assertFalse(m3.canRead(m1_v2));

    assertFalse(m3.isExported("p"));
    assertTrue(m3.isExported("p", m1_v1));
    assertFalse(m3.isExported("p", m1_v2));
    assertFalse(m3.isExported("p", m2));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:BasicLayerTest.java



注:本文中的java.lang.module.ModuleDescriptor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ITenant类代码示例发布时间:2022-05-23
下一篇:
Java JumblrClient类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap