use of java.lang.Module in project openj9 by eclipse.
the class Test_Class method test_forName.
/**
* @tests java.lang.Class#forName(java.lang.String)
* @tests java.lang.Class#forName(java.lang.Module, java.lang.String)
*/
@Test
public void test_forName() {
try {
// package java.rmi exported by module java.rmi
Class<?> jrAccessExceptionClz = Class.forName("java.rmi.AccessException");
AssertJUnit.assertNotNull(jrAccessExceptionClz);
if (!jrAccessExceptionClz.getProtectionDomain().implies(ALL_PERMISSION)) {
AssertJUnit.fail("java.rmi.AccessException should have all permission!");
}
Module jrModule = jrAccessExceptionClz.getModule();
Class<?> jrAlreadyBoundExceptionClz = Class.forName(jrModule, "java.rmi.AlreadyBoundException");
if ((jrAlreadyBoundExceptionClz == null) || !jrAlreadyBoundExceptionClz.getProtectionDomain().implies(ALL_PERMISSION)) {
AssertJUnit.fail("java.rmi.AlreadyBoundException should have all permission as well!");
}
} catch (ClassNotFoundException e) {
AssertJUnit.fail("Unexpected ClassNotFoundException: " + e.getMessage());
}
}
use of java.lang.Module in project jboss-modules by jboss-modules.
the class JDKModuleFinder method findModule.
public ModuleSpec findModule(final String name, final ModuleLoader delegateLoader) {
final Set<String> packages;
final Module module;
if ("org.jboss.modules".equals(name)) {
module = getClass().getModule();
if (module.isNamed()) {
packages = module.getPackages();
} else {
packages = Set.of("org.jboss.modules", "org.jboss.modules.filter", "org.jboss.modules.log", "org.jboss.modules.management", "org.jboss.modules.maven", "org.jboss.modules.ref", "org.jboss.modules.security", "org.jboss.modules.xml");
}
} else {
final Optional<Module> moduleOptional = layer.findModule(name);
if (!moduleOptional.isPresent()) {
return null;
}
module = moduleOptional.get();
packages = module.getPackages();
}
final ModuleSpec.Builder builder = ModuleSpec.build(name);
final ModuleDescriptor descriptor = module.getDescriptor();
if (descriptor != null) {
final Optional<String> version = descriptor.rawVersion();
if (version.isPresent())
builder.setVersion(Version.parse(version.get()));
for (ModuleDescriptor.Requires require : descriptor.requires()) {
final Set<ModuleDescriptor.Requires.Modifier> modifiers = require.modifiers();
builder.addDependency(new ModuleDependencySpecBuilder().setName(require.name()).setExport(modifiers.contains(ModuleDescriptor.Requires.Modifier.TRANSITIVE)).setOptional(modifiers.contains(ModuleDescriptor.Requires.Modifier.STATIC)).build());
}
}
final Set<String> paths = new HashSet<>(packages.size());
for (String pkg : packages) {
paths.add(pkg.replace('.', '/'));
}
final LocalDependencySpecBuilder depBuilder = new LocalDependencySpecBuilder();
depBuilder.setLoaderPaths(paths);
depBuilder.setExport(true);
depBuilder.setLocalLoader(new JDKModuleLoader(module, packages));
builder.addDependency(depBuilder.build());
return builder.create();
}
use of java.lang.Module in project openj9 by eclipse.
the class MyLoader method dumpModules.
private void dumpModules() {
HashSet<Option> opts = new HashSet<>(Arrays.asList(new Option[] { Option.RETAIN_CLASS_REFERENCE, Option.SHOW_HIDDEN_FRAMES, Option.SHOW_REFLECT_FRAMES }));
List<StackFrame> frameList = (StackWalker.getInstance(opts)).walk(s -> s.collect(Collectors.toList()));
for (StackFrame f : frameList) {
Module frameModule = f.getDeclaringClass().getModule();
if ((null != frameModule)) {
ModuleDescriptor d = frameModule.getDescriptor();
if (null != d) {
StackTraceElement e = f.toStackTraceElement();
String modName = d.name();
if (null != modName) {
assertEquals(modName, e.getModuleName(), "Wrong module name");
}
Optional<Version> modVersion = d.version();
if (modVersion.isPresent()) {
assertEquals(modVersion.get(), e.getModuleVersion(), "Wrong module version");
}
if (f.getDeclaringClass() == Thread.class) {
assertEquals("java.base", e.getModuleName(), "Wrong module name");
}
}
}
}
}
use of java.lang.Module in project jboss-modules by jboss-modules.
the class JDKModuleFinder method iterateModules.
public Iterator<String> iterateModules(final String baseName, final boolean recursive) {
final Set<Module> moduleSet = layer.modules();
final ArrayList<String> nameList = new ArrayList<>(moduleSet.size() + 1);
final Module ourModule = getClass().getModule();
boolean foundUs = false;
for (Module module : moduleSet) {
if (module == ourModule) {
foundUs = true;
}
nameList.add(module.getName());
}
if (!foundUs) {
nameList.add("org.jboss.modules");
}
return nameList.iterator();
}
Aggregations