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

Java ModuleReference类代码示例

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

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



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

示例1: isAutomaticModuleNameAttributeAvailable

import java.lang.module.ModuleReference; //导入依赖的package包/类
boolean isAutomaticModuleNameAttributeAvailable(ModuleReference moduleReference) {
  try (var moduleReader = moduleReference.open()) {
    var manifestString =
        moduleReader
            .read("META-INF/MANIFEST.MF")
            .map(StandardCharsets.UTF_8::decode)
            .map(Object::toString)
            .orElse("");
    if (manifestString.contains("Automatic-Module-Name")) {
      return true;
    }
  } catch (Exception e) {
    debug("reading manifest failed: {0}", e);
  }
  return false;
}
 
开发者ID:jodastephen,项目名称:jpms-module-names,代码行数:17,代码来源:Generator.java


示例2: add

import java.lang.module.ModuleReference; //导入依赖的package包/类
void add(ModuleDescriptor... descriptors) {
    for (ModuleDescriptor descriptor: descriptors) {
        String name = descriptor.name();
        if (!namesToReference.containsKey(name)) {
            //modules.add(descriptor);

            URI uri = URI.create("module:/" + descriptor.name());

            ModuleReference mref = new ModuleReference(descriptor, uri) {
                @Override
                public ModuleReader open() {
                    throw new UnsupportedOperationException();
                }
            };

            namesToReference.put(name, mref);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ModuleLibrary.java


示例3: javaSE

import java.lang.module.ModuleReference; //导入依赖的package包/类
private static Set<String> javaSE() {
    String root = "java.se.ee";
    ModuleFinder system = ModuleFinder.ofSystem();
    if (system.find(root).isPresent()) {
        return Stream.concat(Stream.of(root),
                             Configuration.empty().resolve(system,
                                                           ModuleFinder.of(),
                                                           Set.of(root))
                                          .findModule(root).get()
                                          .reads().stream()
                                          .map(ResolvedModule::name))
                     .collect(toSet());
    } else {
        // approximation
        return system.findAll().stream()
            .map(ModuleReference::descriptor)
            .map(ModuleDescriptor::name)
            .filter(name -> name.startsWith("java.") &&
                                !name.equals("java.smartcardio"))
            .collect(Collectors.toSet());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ModuleDotGraph.java


示例4: toModule

import java.lang.module.ModuleReference; //导入依赖的package包/类
public Module toModule(ModuleReference mref) {
    try {
        String mn = mref.descriptor().name();
        URI location = mref.location().orElseThrow(FileNotFoundException::new);
        ModuleDescriptor md = mref.descriptor();
        Module.Builder builder = new Module.Builder(md, system.find(mn).isPresent());

        final ClassFileReader reader;
        if (location.getScheme().equals("jrt")) {
            reader = system.getClassReader(mn);
        } else {
            reader = ClassFileReader.newInstance(Paths.get(location), version);
        }

        builder.classes(reader);
        builder.location(location);

        return builder.build();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:JdepsConfiguration.java


示例5: main

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

        if (args.length != 1) {
            System.err.println("Usage AddPackagesAttribute exploded-java-home");
            System.exit(-1);
        }

        String home = args[0];
        Path dir = Paths.get(home, "modules");

        ModuleFinder finder = ModuleFinder.of(dir);

        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
            for (Path entry : stream) {
                Path mi = entry.resolve("module-info.class");
                if (Files.isRegularFile(mi)) {
                    String mn = entry.getFileName().toString();
                    Optional<ModuleReference> omref = finder.find(mn);
                    if (omref.isPresent()) {
                        Set<String> packages = omref.get().descriptor().packages();
                        addPackagesAttribute(mi, packages);
                    }
                }
            }
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:AddPackagesAttribute.java


示例6: testMissingMainClassPackage

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Test that a JAR file with a Main-Class attribute that is not in the module
 */
public void testMissingMainClassPackage() throws IOException {
    Manifest man = new Manifest();
    Attributes attrs = man.getMainAttributes();
    attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
    attrs.put(Attributes.Name.MAIN_CLASS, "p.Main");

    Path dir = Files.createTempDirectory(USER_DIR, "mods");
    createDummyJarFile(dir.resolve("m.jar"), man);

    // Main-Class should be ignored because package p is not in module
    Optional<ModuleReference> omref = ModuleFinder.of(dir).find("m");
    assertTrue(omref.isPresent());
    ModuleDescriptor descriptor = omref.get().descriptor();
    assertFalse(descriptor.mainClass().isPresent());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:AutomaticModulesTest.java


示例7: Loader

import java.lang.module.ModuleReference; //导入依赖的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


示例8: loadModule

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Register a module this class loader. This has the effect of making the
 * types in the module visible.
 */
public void loadModule(ModuleReference mref) {
    String mn = mref.descriptor().name();
    if (nameToModule.putIfAbsent(mn, mref) != null) {
        throw new InternalError(mn + " already defined to this loader");
    }

    LoadedModule loadedModule = new LoadedModule(this, mref);
    for (String pn : mref.descriptor().packages()) {
        LoadedModule other = packageToModule.putIfAbsent(pn, loadedModule);
        if (other != null) {
            throw new InternalError(pn + " in modules " + mn + " and "
                                    + other.mref().descriptor().name());
        }
    }

    // clear resources cache if VM is already initialized
    if (VM.isModuleSystemInited() && resourceCache != null) {
        resourceCache = null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:BuiltinClassLoader.java


示例9: findResource

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Returns a URL to a resource of the given name in a module defined to
 * this class loader.
 */
@Override
public URL findResource(String mn, String name) throws IOException {
    URL url = null;

    if (mn != null) {
        // find in module
        ModuleReference mref = nameToModule.get(mn);
        if (mref != null) {
            url = findResource(mref, name);
        }
    } else {
        // find on class path
        url = findResourceOnClassPath(name);
    }

    return checkURL(url);  // check access before returning
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:BuiltinClassLoader.java


示例10: findResourceAsStream

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Returns an input stream to a resource of the given name in a module
 * defined to this class loader.
 */
public InputStream findResourceAsStream(String mn, String name)
    throws IOException
{
    // Need URL to resource when running with a security manager so that
    // the right permission check is done.
    if (System.getSecurityManager() != null || mn == null) {
        URL url = findResource(mn, name);
        return (url != null) ? url.openStream() : null;
    }

    // find in module defined to this loader, no security manager
    ModuleReference mref = nameToModule.get(mn);
    if (mref != null) {
        return moduleReaderFor(mref).open(name).orElse(null);
    } else {
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:BuiltinClassLoader.java


示例11: moduleReaderFor

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Returns the ModuleReader for the given module, creating it if needed
 */
private ModuleReader moduleReaderFor(ModuleReference mref) {
    ModuleReader reader = moduleToReader.get(mref);
    if (reader == null) {
        // avoid method reference during startup
        Function<ModuleReference, ModuleReader> create = new Function<>() {
            public ModuleReader apply(ModuleReference moduleReference) {
                try {
                    return mref.open();
                } catch (IOException e) {
                    // Return a null module reader to avoid a future class
                    // load attempting to open the module again.
                    return new NullModuleReader();
                }
            }
        };
        reader = moduleToReader.computeIfAbsent(mref, create);
    }
    return reader;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:BuiltinClassLoader.java


示例12: newModule

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Creates a ModuleReference to a possibly-patched module
 */
private static ModuleReference newModule(ModuleInfo.Attributes attrs,
                                         URI uri,
                                         Supplier<ModuleReader> supplier,
                                         ModulePatcher patcher,
                                         HashSupplier hasher) {
    ModuleReference mref = new ModuleReferenceImpl(attrs.descriptor(),
                                                   uri,
                                                   supplier,
                                                   null,
                                                   attrs.target(),
                                                   attrs.recordedHashes(),
                                                   hasher,
                                                   attrs.moduleResolution());
    if (patcher != null)
        mref = patcher.patchIfNeeded(mref);

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


示例13: checkIncubatingStatus

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Checks incubating status of modules in the configuration
 */
private static void checkIncubatingStatus(Configuration cf) {
    String incubating = null;
    for (ResolvedModule resolvedModule : cf.modules()) {
        ModuleReference mref = resolvedModule.reference();

        // emit warning if the WARN_INCUBATING module resolution bit set
        if (ModuleResolution.hasIncubatingWarning(mref)) {
            String mn = mref.descriptor().name();
            if (incubating == null) {
                incubating = mn;
            } else {
                incubating += ", " + mn;
            }
        }
    }
    if (incubating != null)
        warn("Using incubator modules: " + incubating);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ModuleBootstrap.java


示例14: find

import java.lang.module.ModuleReference; //导入依赖的package包/类
@Override
public Optional<ModuleReference> find(String name) {
    Objects.requireNonNull(name);

    // try cached modules
    ModuleReference m = cachedModules.get(name);
    if (m != null)
        return Optional.of(m);

    // the module may not have been encountered yet
    while (hasNextEntry()) {
        scanNextEntry();
        m = cachedModules.get(name);
        if (m != null)
            return Optional.of(m);
    }
    return Optional.empty();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ModulePath.java


示例15: scanNextEntry

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Scans the next entry on the module path. A no-op if all entries have
 * already been scanned.
 *
 * @throws FindException if an error occurs scanning the next entry
 */
private void scanNextEntry() {
    if (hasNextEntry()) {

        long t0 = System.nanoTime();

        Path entry = entries[next];
        Map<String, ModuleReference> modules = scan(entry);
        next++;

        // update cache, ignoring duplicates
        int initialSize = cachedModules.size();
        for (Map.Entry<String, ModuleReference> e : modules.entrySet()) {
            cachedModules.putIfAbsent(e.getKey(), e.getValue());
        }

        // update counters
        int added = cachedModules.size() - initialSize;
        moduleCount.add(added);

        scanTime.addElapsedTimeFrom(t0);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ModulePath.java


示例16: testBadServicesNames

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Test JAR file with META-INF/services configuration file with bad
 * values or names.
 */
@Test(dataProvider = "badservices")
public void testBadServicesNames(String service, String provider)
    throws IOException
{
    Path tmpdir = Files.createTempDirectory(USER_DIR, "tmp");
    Path services = tmpdir.resolve("META-INF").resolve("services");
    Files.createDirectories(services);
    Files.write(services.resolve(service), Set.of(provider));
    Path dir = Files.createTempDirectory(USER_DIR, "mods");
    JarUtils.createJarFile(dir.resolve("m.jar"), tmpdir);

    Optional<ModuleReference> omref = ModuleFinder.of(dir).find("m");
    assertTrue(omref.isPresent());
    ModuleDescriptor descriptor = omref.get().descriptor();
    assertTrue(descriptor.provides().isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:AutomaticModulesTest.java


示例17: PatchedModuleReader

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Creates the ModuleReader to reads resources in a patched module.
 */
PatchedModuleReader(List<Path> patches, ModuleReference mref) {
    List<ResourceFinder> finders = new ArrayList<>();
    boolean initialized = false;
    try {
        for (Path file : patches) {
            if (Files.isRegularFile(file)) {
                finders.add(new JarResourceFinder(file));
            } else {
                finders.add(new ExplodedResourceFinder(file));
            }
        }
        initialized = true;
    } catch (IOException ioe) {
        throw new UncheckedIOException(ioe);
    } finally {
        // close all ResourceFinder in the event of an error
        if (!initialized) closeAll(finders);
    }

    this.finders = finders;
    this.mref = mref;
    this.delegateCodeSourceURL = codeSourceURL(mref);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ModulePatcher.java


示例18: process

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Prints the module location and name, checks if the module is
 * shadowed by a previously seen module, and finally checks for
 * package conflicts with previously seen modules.
 */
void process(ModuleReference mref) {
    printModule(mref);

    String name = mref.descriptor().name();
    ModuleReference previous = nameToModule.putIfAbsent(name, mref);
    if (previous != null) {
        ostream.print(INDENT + "shadowed by ");
        printModule(previous);
    } else {
        // check for package conflicts when not shadowed
        for (String pkg :  mref.descriptor().packages()) {
            previous = packageToModule.putIfAbsent(pkg, mref);
            if (previous != null) {
                String mn = previous.descriptor().name();
                ostream.println(INDENT + "contains " + pkg
                                + " conflicts with module " + mn);
                errorFound = true;
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:LauncherHelper.java


示例19: scanModule

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Scan a JAR file or exploded module.
 */
private Optional<ModuleReference> scanModule(Path entry) {
    ModuleFinder finder = ModuleFinder.of(entry);
    try {
        return finder.findAll().stream().findFirst();
    } catch (FindException e) {
        ostream.println(entry);
        ostream.println(INDENT + e.getMessage());
        Throwable cause = e.getCause();
        if (cause != null) {
            ostream.println(INDENT + cause);
        }
        errorFound = true;
        return Optional.empty();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:LauncherHelper.java


示例20: testBadPackage

import java.lang.module.ModuleReference; //导入依赖的package包/类
/**
 * Test class files in JAR file where the entry does not correspond to a
 * legal package name.
 */
public void testBadPackage() throws IOException {
    Path dir = Files.createTempDirectory(USER_DIR, "mods");
    createDummyJarFile(dir.resolve("m.jar"), "p/C1.class", "p-/C2.class");

    ModuleFinder finder = ModuleFinder.of(dir);
    Optional<ModuleReference> mref = finder.find("m");
    assertTrue(mref.isPresent(), "m not found");

    ModuleDescriptor descriptor = mref.get().descriptor();
    assertTrue(descriptor.isAutomatic());

    assertTrue(descriptor.packages().size() == 1);
    assertTrue(descriptor.packages().contains("p"));

    assertTrue(descriptor.exports().isEmpty());
    assertTrue(descriptor.opens().isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:AutomaticModulesTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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