private void loadIds(String moduleRootDir, Map<String, ModuleIdentifier> idMap, String moduleName) { StringBuilder baseDirBuilder = new StringBuilder(moduleRootDir); baseDirBuilder.append(File.separator); baseDirBuilder.append(moduleName.replace(".", File.separator)); File moduleBaseDir = new File(baseDirBuilder.toString()); File[] slots = moduleBaseDir.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.isDirectory(); } }); if (slots == null) return; for (File slot : slots) { if (!new File(slot, "module.xml").exists()) continue; // make sure directory represents a real module String slotName = slot.getName(); allVersions.add(slotName); idMap.put(slotName, ModuleIdentifier.create(moduleName, slotName)); } }
public List<TldMetaData> getSharedTlds(DeploymentUnit deploymentUnit) { final List<TldMetaData> metadata = new ArrayList<TldMetaData>(); try { ModuleClassLoader jstl = Module.getModuleFromCallerModuleLoader(ModuleIdentifier.create("javax.servlet.jstl.api")).getClassLoader(); for (String tld : JSTL_TAGLIBS) { InputStream is = jstl.getResourceAsStream("META-INF/" + tld); if (is != null) { TldMetaData tldMetaData = parseTLD(is); metadata.add(tldMetaData); } } } catch (ModuleLoadException e) { // Ignore } catch (Exception e) { // Ignore } List<TldMetaData> additionalSharedTlds = deploymentUnit.getAttachment(ATTACHMENT_KEY); if (additionalSharedTlds != null) { metadata.addAll(additionalSharedTlds); } return metadata; }
public Main(final String mId, final String mainClass, final List<File> watchDirs, final File... cp) throws Exception { this.mainClass = mainClass; loader = AppModuleLoader.build(mId, cp); this.mId = ModuleIdentifier.create(mId); this.watchDirs = toPath(watchDirs); this.executor = Executors.newSingleThreadExecutor(task -> new Thread(task, "Hotswap")); this.scanner = new Watcher(this::onChange, this.watchDirs); includes("**/*.class" + File.pathSeparator + "**/*.conf" + File.pathSeparator + "**/*.properties" + packageJson(cp)); excludes(""); }
module = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.jboss.as.ee")); } catch (Throwable e) { throw new IOException(e);
/** {@inheritDoc} */ public Class<?> resolveClass(final Unmarshaller unmarshaller, final String className, final long serialVersionUID) throws IOException, ClassNotFoundException { final String name = (String) unmarshaller.readObject(); if (name == null) { return Class.forName(className, false, MODULE_CLASS_LOADER); } final String slot = (String) unmarshaller.readObject(); final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot); try { final ClassLoader classLoader; final Module module = moduleLoader.loadModule(identifier); if (System.getSecurityManager() == null) { classLoader = module.getClassLoader(); } else { classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return module.getClassLoader(); } }); } return Class.forName(className, false, classLoader); } catch (ModuleLoadException e) { final InvalidClassException ce = new InvalidClassException(className, "Module load failed"); ce.initCause(e); throw ce; } }
public static List<GlobalModule> createModuleList(final OperationContext context, final ModelNode globalMods) throws OperationFailedException { final List<GlobalModule> ret = new ArrayList<>(); if (globalMods.isDefined()) { for (final ModelNode module : globalMods.asList()) { String name = NAME_AD.resolveModelAttribute(context, module).asString(); String slot = SLOT_AD.resolveModelAttribute(context, module).asString(); boolean annotations = ANNOTATIONS_AD.resolveModelAttribute(context, module).asBoolean(); boolean services = SERVICES_AD.resolveModelAttribute(context, module).asBoolean(); boolean metaInf = META_INF_AD.resolveModelAttribute(context, module).asBoolean(); ret.add(new GlobalModule(ModuleIdentifier.create(name, slot), annotations, services, metaInf)); } } return ret; }
/** {@inheritDoc} */ public Class<?> resolveProxyClass(final Unmarshaller unmarshaller, final String[] names) throws IOException, ClassNotFoundException { final String name = (String) unmarshaller.readObject(); final ClassLoader classLoader; if (name == null) { classLoader = MODULE_CLASS_LOADER; } else { final String slot = (String) unmarshaller.readObject(); final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot); final Module module; try { module = moduleLoader.loadModule(identifier); } catch (ModuleLoadException e) { final InvalidClassException ce = new InvalidClassException("Module load failed"); ce.initCause(e); throw ce; } classLoader = module.getClassLoader(); } final int len = names.length; final Class<?>[] interfaces = new Class<?>[len]; for (int i = 0; i < len; i ++) { interfaces[i] = Class.forName(names[i], false, classLoader); } return Proxy.getProxyClass(classLoader, interfaces); } }
} else { final String slot = (String) unmarshaller.readObject(); final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot); className = (String) unmarshaller.readObject(); try { } else { final String slot = (String) unmarshaller.readObject(); final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot); final Module module; try {
ModuleIdentifier moduleId = ModuleIdentifier.create(moduleName, slot); module = Module.getCallerModuleLoader().loadModule(moduleId); } catch (ModuleNotFoundException e) {
moduleId = ModuleIdentifier.create(moduleName, slot); module = Module.getCallerModuleLoader().loadModule(moduleId); } catch (ModuleNotFoundException e) {
/** * Add the EE APIs as a dependency to all deployments * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException * */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final ModuleLoader moduleLoader = Module.getBootModuleLoader(); //add jboss-invocation classes needed by the proxies ModuleDependency invocation = new ModuleDependency(moduleLoader, JBOSS_INVOCATION_ID, false, false, false, false); invocation.addImportFilter(PathFilters.is("org/jboss/invocation/proxy/classloading"), true); invocation.addImportFilter(PathFilters.acceptAll(), false); moduleSpecification.addSystemDependency(invocation); ModuleDependency ee = new ModuleDependency(moduleLoader, JBOSS_AS_EE, false, false, false, false); ee.addImportFilter(PathFilters.is("org/jboss/as/ee/component/serialization"), true); ee.addImportFilter(PathFilters.is("org/jboss/as/ee/concurrent"), true); ee.addImportFilter(PathFilters.is("org/jboss/as/ee/concurrent/handle"), true); ee.addImportFilter(PathFilters.acceptAll(), false); moduleSpecification.addSystemDependency(ee); // add dep for naming permission moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.create("org.wildfly.naming"), false, false, false, false)); //we always add all Java EE API modules, as the platform spec requires them to always be available //we do not just add the javaee.api module, as this breaks excludes for (final ModuleIdentifier moduleIdentifier : JAVA_EE_API_MODULES) { moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, true, false, true, false)); } }
/** * Creates a new module identifier using the specified name. * * @param name the name of the module * @return the identifier */ public static ModuleIdentifier create(String name) { return create(name, null); } }
public static ModuleIdentifier createModuleIdentifier(final String deploymentUnitName, final ResourceRoot deploymentRoot, final DeploymentUnit topLevelDeployment, final VirtualFile toplevelRoot, final boolean topLevel) { // generate the module identifier for the deployment final ModuleIdentifier moduleIdentifier; if (topLevel) { moduleIdentifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + deploymentUnitName); } else { String relativePath = deploymentRoot.getRoot().getPathNameRelativeTo(toplevelRoot); moduleIdentifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + topLevelDeployment.getName() + '.' + relativePath.replace('/', '.')); } return moduleIdentifier; }
public static ModuleIdentifier createModuleIdentifier(final String deploymentUnitName, final ResourceRoot deploymentRoot, final DeploymentUnit topLevelDeployment, final VirtualFile toplevelRoot, final boolean topLevel) { // generate the module identifier for the deployment final ModuleIdentifier moduleIdentifier; if (topLevel) { moduleIdentifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + deploymentUnitName); } else { String relativePath = deploymentRoot.getRoot().getPathNameRelativeTo(toplevelRoot); moduleIdentifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + topLevelDeployment.getName() + '.' + relativePath.replace('/', '.')); } return moduleIdentifier; }
public ModuleIdentifier addExternalModule(String externalModule) { ModuleIdentifier identifier = ModuleIdentifier.create(EXTERNAL_MODULE_PREFIX + externalModule); ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier); ServiceController<?> controller = serviceContainer.getService(serviceName); if (controller == null) { ExternalModuleSpecService service = new ExternalModuleSpecService(identifier, new File(externalModule)); serviceContainer.addService(serviceName, service).setInitialMode(Mode.ON_DEMAND).install(); } return identifier; }
public ModuleIdentifier addExternalModule(String externalModule) { ModuleIdentifier identifier = ModuleIdentifier.create(EXTERNAL_MODULE_PREFIX + externalModule); ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier); ServiceController<?> controller = serviceContainer.getService(serviceName); if (controller == null) { ExternalModuleSpecService service = new ExternalModuleSpecService(identifier, new File(externalModule)); serviceContainer.addService(serviceName, service).setInitialMode(Mode.ON_DEMAND).install(); } return identifier; }
public ModuleIdentifier addExternalModule(String externalModule) { ModuleIdentifier identifier = ModuleIdentifier.create(EXTERNAL_MODULE_PREFIX + externalModule); ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier); ServiceController<?> controller = serviceContainer.getService(serviceName); if (controller == null) { ExternalModuleSpecService service = new ExternalModuleSpecService(identifier, new File(externalModule)); serviceContainer.addService(serviceName, service).setInitialMode(Mode.ON_DEMAND).install(); } return identifier; }
private ModuleIdentifier createAdditionalModule(final ResourceRoot resourceRoot, final DeploymentUnit topLevelDeployment, final VirtualFile topLevelRoot, final Map<VirtualFile, AdditionalModuleSpecification> additionalModules, final VirtualFile classPathFile, final ArrayDeque<RootEntry> resourceRoots) throws DeploymentUnitProcessingException { final ResourceRoot root = createResourceRoot(classPathFile, topLevelDeployment, topLevelRoot); final String pathName = root.getRoot().getPathNameRelativeTo(topLevelRoot); ModuleIdentifier identifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + topLevelDeployment.getName() + "." + pathName); AdditionalModuleSpecification module = new AdditionalModuleSpecification(identifier, root); topLevelDeployment.addToAttachmentList(Attachments.ADDITIONAL_MODULES, module); additionalModules.put(classPathFile, module); resourceRoot.addToAttachmentList(Attachments.CLASS_PATH_RESOURCE_ROOTS, root); //add this to the list of roots to be processed, so transitive class path entries will be respected resourceRoots.add(new RootEntry(module, root)); return identifier; }
private ModuleIdentifier createAdditionalModule(final ResourceRoot resourceRoot, final DeploymentUnit topLevelDeployment, final VirtualFile topLevelRoot, final Map<VirtualFile, AdditionalModuleSpecification> additionalModules, final VirtualFile classPathFile, final ArrayDeque<RootEntry> resourceRoots) throws DeploymentUnitProcessingException { final ResourceRoot root = createResourceRoot(classPathFile, topLevelDeployment, topLevelRoot); final String pathName = root.getRoot().getPathNameRelativeTo(topLevelRoot); ModuleIdentifier identifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + topLevelDeployment.getName() + "." + pathName); AdditionalModuleSpecification module = new AdditionalModuleSpecification(identifier, root); topLevelDeployment.addToAttachmentList(Attachments.ADDITIONAL_MODULES, module); additionalModules.put(classPathFile, module); resourceRoot.addToAttachmentList(Attachments.CLASS_PATH_RESOURCE_ROOTS, root); //add this to the list of roots to be processed, so transitive class path entries will be respected resourceRoots.add(new RootEntry(module, root)); return identifier; }