本文整理汇总了Java中java.lang.module.ModuleReference类的典型用法代码示例。如果您正苦于以下问题:Java ModuleReference类的具体用法?Java ModuleReference怎么用?Java ModuleReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModuleReference类属于java.lang.module包,在下文中一共展示了ModuleReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
}
}
}
示例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());
}
示例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();
}
示例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;
}
}
示例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
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
}