org.jboss.modules.ModuleLoader Java Examples

The following examples show how to use org.jboss.modules.ModuleLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextCreateHandlerRegistryIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testHandlerRegistry() throws Exception {
    ContextCreateHandlerRegistry handlerRegistry = ServiceLocator.getRequiredService(CamelConstants.CONTEXT_CREATE_HANDLER_REGISTRY_SERVICE_NAME, ContextCreateHandlerRegistry.class);
    ModuleLoader moduleLoader = Module.getCallerModuleLoader();

    deployer.deploy(CAMEL_TEST_JAR);

    Module module = moduleLoader.loadModule(ModuleIdentifier.create("deployment.camel-test.jar"));
    ClassLoader classLoader = module.getClassLoader();

    // Registry should have classloader key after deploy
    Assert.assertTrue(handlerRegistry.containsKey(classLoader));

    deployer.undeploy(CAMEL_TEST_JAR);

    // Registry should have removed classloader key after undeploy
    Assert.assertFalse("Expected registry to not contain key: " + classLoader, handlerRegistry.containsKey(classLoader));
}
 
Example #2
Source File: BootableJar.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private BootableJar(Path jbossHome, Arguments arguments, ModuleLoader loader, long unzipTime) throws Exception {
    this.jbossHome = jbossHome;
    this.arguments = arguments;
    this.loader = loader;
    startServerArgs.addAll(arguments.getServerArguments());
    startServerArgs.add(CommandLineConstants.READ_ONLY_SERVER_CONFIG + "=" + STANDALONE_CONFIG);

    // logging needs to be configured before other components have a chance to initialize a logger
    configureLogger();
    long t = System.currentTimeMillis();
    if (arguments.getDeployment() != null) {
        setupDeployment(arguments.getDeployment());
    }

    log.advertiseInstall(jbossHome, unzipTime + (System.currentTimeMillis() - t));
}
 
Example #3
Source File: BootableJar.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Modular entry point.
 *
 * @param jbossHome Server home directory.
 * @param args User provided arguments.
 * @param moduleLoader JBoss modules loader.
 * @param moduleClassLoader Bootable jar module classloader
 * @param unzipTime Time spent to unzip the server.
 * @throws Exception
 */
public static void run(Path jbossHome, List<String> args, ModuleLoader moduleLoader, ModuleClassLoader moduleClassLoader, Long unzipTime) throws Exception {
    setTccl(moduleClassLoader);
    Arguments arguments;
    try {
        arguments = Arguments.parseArguments(args);
    } catch (Throwable ex) {
        System.err.println(ex);
        CmdUsage.printUsage(System.out);
        return;
    }
    if (arguments.isHelp()) {
        CmdUsage.printUsage(System.out);
        return;
    }
    BootableJar bootableJar = new BootableJar(jbossHome, arguments, moduleLoader, unzipTime);
    bootableJar.run();
}
 
Example #4
Source File: Main.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void runBootableJar(Path jbossHome, List<String> arguments, Long unzipTime) throws Exception {
    final String modulePath = jbossHome.resolve(JBOSS_MODULES_DIR_NAME).toAbsolutePath().toString();
    ModuleLoader moduleLoader = setupModuleLoader(modulePath);
    final Module bootableJarModule;
    try {
        bootableJarModule = moduleLoader.loadModule(MODULE_ID_JAR_RUNTIME);
    } catch (final ModuleLoadException mle) {
        throw new Exception(mle);
    }

    final ModuleClassLoader moduleCL = bootableJarModule.getClassLoader();
    final Class<?> bjFactoryClass;
    try {
        bjFactoryClass = moduleCL.loadClass(BOOTABLE_JAR);
    } catch (final ClassNotFoundException cnfe) {
        throw new Exception(cnfe);
    }
    Method runMethod;
    try {
        runMethod = bjFactoryClass.getMethod(BOOTABLE_JAR_RUN_METHOD, Path.class, List.class, ModuleLoader.class, ModuleClassLoader.class, Long.class);
    } catch (final NoSuchMethodException nsme) {
        throw new Exception(nsme);
    }
    runMethod.invoke(null, jbossHome, arguments, moduleLoader, moduleCL, unzipTime);
}
 
Example #5
Source File: KeycloakProviderDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    KeycloakAdapterConfigService config = KeycloakAdapterConfigService.INSTANCE;
    String deploymentName = deploymentUnit.getName();

    if (config.isKeycloakServerDeployment(deploymentName)) {
        return;
    }

    KeycloakDeploymentInfo info = getKeycloakProviderDeploymentInfo(deploymentUnit);
    if (info.hasServices()) {
        final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
        final ModuleLoader moduleLoader = Module.getBootModuleLoader();
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_COMMON, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_CORE, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_SERVER_SPI, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_SERVER_SPI_PRIVATE, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JAXRS, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, RESTEASY, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, APACHE, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_JPA, false, false, false, false));
    }
}
 
Example #6
Source File: PermissionsParser.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static List<PermissionFactory> parse(final XMLStreamReader reader, final ModuleLoader loader, final ModuleIdentifier identifier)
        throws XMLStreamException {

    reader.require(XMLStreamConstants.START_DOCUMENT, null, null);

    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.START_ELEMENT: {
                Element element = Element.forName(reader.getLocalName());
                switch (element) {
                    case PERMISSIONS: {
                        return parsePermissions(reader, loader, identifier);
                    }
                    default: {
                        throw unexpectedElement(reader);
                    }
                }
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw unexpectedEndOfDocument(reader);
}
 
Example #7
Source File: LoggingDependencyDeploymentProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    // Add the logging modules
    for (String moduleId : DUP_INJECTED_LOGGING_MODULES) {
        try {
            LoggingLogger.ROOT_LOGGER.tracef("Adding module '%s' to deployment '%s'", moduleId, deploymentUnit.getName());
            moduleLoader.loadModule(moduleId);
            moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleId, false, false, false, false));
        } catch (ModuleLoadException ex) {
            LoggingLogger.ROOT_LOGGER.debugf("Module not found: %s", moduleId);
        }
    }
}
 
Example #8
Source File: JBossDeploymentStructureParser10.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void parseDependencies(final XMLStreamReader reader, final ModuleStructureSpec specBuilder,
                                      ModuleLoader moduleLoader) throws XMLStreamException {
    // xsd:choice
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case MODULE:
                        parseModuleDependency(reader, specBuilder, moduleLoader);
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw endOfDocument(reader.getLocation());
}
 
Example #9
Source File: DaemonServiceActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public void start(StartContext context) throws StartException {
    try {
        final String artifactName = System.getProperty(BootstrapProperties.APP_ARTIFACT);
        if (artifactName == null) {
            throw new StartException("Failed to find artifact name under " + BootstrapProperties.APP_ARTIFACT);
        }

        final ModuleLoader serviceLoader = this.serviceLoader.getValue();
        final String moduleName = "deployment." + artifactName;
        final Module module = serviceLoader.loadModule(ModuleIdentifier.create(moduleName));
        if (module == null) {
            throw new StartException("Failed to find deployment module under " + moduleName);
        }

        //TODO: allow overriding the default port?
        this.server = Server.create("localhost", 12345, module.getClassLoader());
        this.server.start();
    } catch (ModuleLoadException | ServerLifecycleException e) {
        throw new StartException(e);
    }
}
 
Example #10
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!KeycloakAdapterConfigService.getInstance().isSecureDeployment(deploymentUnit)) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK")) return;
    }

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(phaseContext, moduleSpecification, moduleLoader);
}
 
Example #11
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (Configuration.INSTANCE.getSecureDeployment(deploymentUnit) == null) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK-SAML")) return;
    }

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(moduleSpecification, moduleLoader);
}
 
Example #12
Source File: ModuleSpecProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void installAliases(final ModuleSpecification moduleSpecification, final ModuleIdentifier moduleIdentifier, final DeploymentUnit deploymentUnit, final DeploymentPhaseContext phaseContext) {

        ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
        for (final ModuleIdentifier alias : moduleSpecification.getAliases()) {
            final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(alias);
            final ModuleSpec spec = ModuleSpec.buildAlias(alias, moduleIdentifier).create();

            HashSet<ModuleDependency> dependencies = new HashSet<>(moduleSpecification.getAllDependencies());
            //we need to add the module we are aliasing as a dependency, to make sure that it will be resolved
            dependencies.add(new ModuleDependency(moduleLoader, moduleIdentifier, false, false, false, false));
            ModuleDefinition moduleDefinition = new ModuleDefinition(alias, dependencies, spec);

            final ValueService<ModuleDefinition> moduleSpecService = new ValueService<>(new ImmediateValue<>(moduleDefinition));
            final ServiceBuilder sb = phaseContext.getServiceTarget().addService(moduleSpecServiceName, moduleSpecService);
            sb.requires(deploymentUnit.getServiceName());
            sb.requires(phaseContext.getPhaseServiceName());
            sb.setInitialMode(Mode.ON_DEMAND);
            sb.install();

            ModuleLoadService.installAliases(phaseContext.getServiceTarget(), alias, Collections.singletonList(moduleIdentifier));

            ModuleResolvePhaseService.installService(phaseContext.getServiceTarget(), moduleDefinition);
        }
    }
 
Example #13
Source File: Util.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static Class<?> loadClass(final String fqn, final String module) {
   try {
      Class<?> passwdClass = AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
          @Override
          public Class<?> run() throws Exception {
              if (fqn == null || fqn.isEmpty()) {
                  throw PicketBoxMessages.MESSAGES.loadingNullorEmptyClass();
              } else if (module == null ) {
                  ClassLoader cl = Thread.currentThread().getContextClassLoader();
                  return cl.loadClass(fqn);
              } else {
                  ModuleLoader loader = Module.getCallerModuleLoader();
                  final Module pwdClassModule = loader.loadModule(ModuleIdentifier.fromString(module));
                  return pwdClassModule.getClassLoader().loadClass(fqn);
              }
          }
      });
      return passwdClass;
  } catch (PrivilegedActionException e) {
      throw PicketBoxMessages.MESSAGES.unableToLoadPasswordClass(e.getCause(), fqn);
  }
}
 
Example #14
Source File: EmbeddedProcessFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Create an embedded standalone server with an already established module loader.
 *
 * @param moduleLoader the module loader. Cannot be {@code null}
 * @param jbossHomeDir the location of the root of server installation. Cannot be {@code null} or empty.
 * @param cmdargs      any additional arguments to pass to the embedded server (e.g. -b=192.168.100.10)
 * @return the running embedded server. Will not be {@code null}
 */
public static StandaloneServer createStandaloneServer(ModuleLoader moduleLoader, File jbossHomeDir, String... cmdargs) {
    return createStandaloneServer(
            Configuration.Builder.of(jbossHomeDir)
                    .setCommandArguments(cmdargs)
                    .setModuleLoader(moduleLoader)
                    .build()
    );
}
 
Example #15
Source File: Configuration.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new immutable configuration.
 *
 * @return the configuration
 */
public Configuration build() {
    final Path jbossHome = this.jbossHome;
    final LoggerHint loggerHint = this.loggerHint == null ? LoggerHint.DEFAULT : this.loggerHint;
    configureLogging(loggerHint);
    final String[] cmdArgs = this.cmdArgs.toArray(new String[0]);
    final String[] systemPackages = this.systemPackages.toArray(new String[0]);
    final ModuleLoader moduleLoader;
    if (this.moduleLoader == null) {
        final String modulePath;
        if (this.modulePath == null) {
            modulePath = SecurityActions.getPropertyPrivileged(SYSPROP_KEY_MODULE_PATH,
                    jbossHome.resolve(JBOSS_MODULES_DIR_NAME).toAbsolutePath().toString());
        } else {
            modulePath = this.modulePath;
        }
        moduleLoader = setupModuleLoader(modulePath, systemPackages);
        MODULE_LOADER_CONFIGURED.set(true);
    } else {
        moduleLoader = this.moduleLoader;
    }
    return new Configuration() {
        @Override
        public Path getJBossHome() {
            return jbossHome;
        }

        @Override
        public ModuleLoader getModuleLoader() {
            return moduleLoader;
        }

        @Override
        public String[] getCommandArguments() {
            return Arrays.copyOf(cmdArgs, cmdArgs.length);
        }
    };
}
 
Example #16
Source File: HostXml.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public HostXml(String defaultHostControllerName, RunningMode runningMode, boolean isCachedDC, final ModuleLoader loader,
               final ExecutorService executorService, final ExtensionRegistry extensionRegistry) {
    this.defaultHostControllerName = defaultHostControllerName;
    this.runningMode = runningMode;
    this.isCachedDc = isCachedDC;
    this.extensionRegistry = extensionRegistry;
    extensionXml = new ExtensionXml(loader, executorService, extensionRegistry);
}
 
Example #17
Source File: Server.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static Server newSever(Path jbossHome, String[] cmdargs, ModuleLoader moduleLoader, ShutdownHandler shutdownHandler) {
    setPropertyPrivileged(ServerEnvironment.HOME_DIR, jbossHome.toString());
    setupVfsModule(moduleLoader);
    Properties sysprops = getSystemPropertiesPrivileged();
    Map<String, String> sysenv = getSystemEnvironmentPrivileged();
    return new Server(cmdargs, sysprops, sysenv, moduleLoader, shutdownHandler);
}
 
Example #18
Source File: JBossModuleLoader.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
private JBossModuleLoader(final SortedMap<ModuleIdentifier, ModuleSpec> moduleSpecs) {
    // create a finder that is backed by the local module spec map
    super(new ModuleFinder[] { new ModuleFinder() {
        @Override
        public ModuleSpec findModule(ModuleIdentifier revisionId, ModuleLoader delegateLoader) throws ModuleLoadException {
            return moduleSpecs.get(revisionId);
        }
    }});
    this.moduleSpecs = Objects.requireNonNull(moduleSpecs);
}
 
Example #19
Source File: EmbeddedHostControllerFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static HostController create(final File jbossHomeDir, final ModuleLoader moduleLoader, final Properties systemProps, final Map<String, String> systemEnv, final String[] cmdargs, ClassLoader embeddedModuleCL) {
    if (jbossHomeDir == null)
        throw EmbeddedLogger.ROOT_LOGGER.nullVar("jbossHomeDir");
    if (moduleLoader == null)
        throw EmbeddedLogger.ROOT_LOGGER.nullVar("moduleLoader");
    if (systemProps == null)
        throw EmbeddedLogger.ROOT_LOGGER.nullVar("systemProps");
    if (systemEnv == null)
        throw EmbeddedLogger.ROOT_LOGGER.nullVar("systemEnv");
    if (cmdargs == null)
        throw EmbeddedLogger.ROOT_LOGGER.nullVar("cmdargs");

    setupCleanDirectories(jbossHomeDir, systemProps);
    return new HostControllerImpl(jbossHomeDir, cmdargs, systemProps, systemEnv, moduleLoader, embeddedModuleCL);
}
 
Example #20
Source File: Swarm.java    From thorntail with Apache License 2.0 5 votes vote down vote up
/**
 * Installs the Module MBeanServer.
 */
private void installModuleMBeanServer() {
    try {
        Method method = ModuleLoader.class.getDeclaredMethod("installMBeanServer");
        method.setAccessible(true);
        method.invoke(null);
    } catch (Exception e) {
        SwarmMessages.MESSAGES.moduleMBeanServerNotInstalled(e);
    }
}
 
Example #21
Source File: Main.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static ModuleLoader setupModuleLoader(final String modulePath) {
    assert modulePath != null : "modulePath not null";

    // verify the first element of the supplied modules path exists, and if it does not, stop and allow the user to correct.
    // Once modules are initialized and loaded we can't change Module.BOOT_MODULE_LOADER (yet).
    final Path moduleDir = Paths.get(trimPathToModulesDir(modulePath));
    if (Files.notExists(moduleDir) || !Files.isDirectory(moduleDir)) {
        throw new RuntimeException("The first directory of the specified module path " + modulePath + " is invalid or does not exist.");
    }

    final String classPath = System.getProperty(SYSPROP_KEY_CLASS_PATH);
    try {
        // Set up sysprop env
        System.clearProperty(SYSPROP_KEY_CLASS_PATH);
        System.setProperty(SYSPROP_KEY_MODULE_PATH, modulePath);

        final StringBuilder packages = new StringBuilder("org.jboss.modules");
        String custompackages = System.getProperty(SYSPROP_KEY_SYSTEM_MODULES);
        if (custompackages != null) {
            packages.append(",").append(custompackages);
        }
        System.setProperty(SYSPROP_KEY_SYSTEM_MODULES, packages.toString());

        // Get the module loader
        return Module.getBootModuleLoader();
    } finally {
        // Return to previous state for classpath prop
        if (classPath != null) {
            System.setProperty(SYSPROP_KEY_CLASS_PATH, classPath);
        }
    }
}
 
Example #22
Source File: CXFResourcesTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccessFromCamelComponentModule() throws Exception {
    ModuleLoader moduleLoader = Module.getCallerModuleLoader();
    ModuleIdentifier modid = ModuleIdentifier.create("org.apache.camel.component");
    ModuleClassLoader classLoader = moduleLoader.loadModule(modid).getClassLoader();
    URL resurl = classLoader.getResource("META-INF/cxf/cxf.xml");
    Assert.assertNotNull("URL not null", resurl);
}
 
Example #23
Source File: ModuleLoadingResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void storeRepoRoots(final ModelNode list) throws NoSuchFieldException, IllegalAccessException {
    // TODO get a formal API from jboss-modules to replace this reflection
    ModuleLoader loader = Module.getBootModuleLoader();
    if (loader instanceof LocalModuleLoader) {
        LocalModuleLoader lml = (LocalModuleLoader) loader;
        Field findersField = ModuleLoader.class.getDeclaredField("finders");
        Field repoRootsField = null;
        findersField.setAccessible(true);
        try {
            Object[] finders = (Object[]) findersField.get(lml);
            if (finders.length > 0 && finders[0] instanceof LocalModuleFinder) {
                LocalModuleFinder lmf = (LocalModuleFinder) finders[0];
                repoRootsField = LocalModuleFinder.class.getDeclaredField("repoRoots") ;
                repoRootsField.setAccessible(true);
                File[] repoRoots = (File[]) repoRootsField.get(lmf);
                for (File file : repoRoots) {
                    list.add(file.getAbsolutePath());
                }
            }
        } finally {
            findersField.setAccessible(false);
            if (repoRootsField != null) {
                repoRootsField.setAccessible(false);
            }
        }
    }

}
 
Example #24
Source File: Seam2Processor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Lookup Seam integration resource loader.
 * @return the Seam integration resource loader
 * @throws DeploymentUnitProcessingException for any error
 */
protected synchronized ResourceRoot getSeamIntResourceRoot() throws DeploymentUnitProcessingException {
    try {
        if (seamIntResourceRoot == null) {
            final ModuleLoader moduleLoader = Module.getBootModuleLoader();
            Module extModule = moduleLoader.loadModule(EXT_CONTENT_MODULE);
            URL url = extModule.getExportedResource(SEAM_INT_JAR);
            if (url == null)
                throw ServerLogger.ROOT_LOGGER.noSeamIntegrationJarPresent(extModule);

            File file = new File(url.toURI());
            VirtualFile vf = VFS.getChild(file.toURI());
            final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider());
            Service<Closeable> mountHandleService = new Service<Closeable>() {
                public void start(StartContext startContext) throws StartException {
                }

                public void stop(StopContext stopContext) {
                    VFSUtils.safeClose(mountHandle);
                }

                public Closeable getValue() throws IllegalStateException, IllegalArgumentException {
                    return mountHandle;
                }
            };
            ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SEAM_INT_JAR),
                    mountHandleService);
            builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
            serviceTarget = null; // our cleanup service install work is done

            MountHandle dummy = MountHandle.create(null); // actual close is done by the MSC service above
            seamIntResourceRoot = new ResourceRoot(vf, dummy);
        }
        return seamIntResourceRoot;
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
 
Example #25
Source File: Seam2Processor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.getParent() != null) {
        return;
    }

    final List<DeploymentUnit> deploymentUnits = new ArrayList<DeploymentUnit>();
    deploymentUnits.add(deploymentUnit);
    deploymentUnits.addAll(deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS));

    for (DeploymentUnit unit : deploymentUnits) {

        final ResourceRoot mainRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        if (mainRoot == null)
            continue;

        VirtualFile root = mainRoot.getRoot();
        for (String path : SEAM_FILES) {
            if (root.getChild(path).exists()) {
                final ModuleSpecification moduleSpecification = deploymentUnit
                        .getAttachment(Attachments.MODULE_SPECIFICATION);
                final ModuleLoader moduleLoader = Module.getBootModuleLoader();
                moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, VFS_MODULE, false, false, false,
                        false)); // for VFS scanner

                try {
                    ResourceLoader resourceLoader = ResourceLoaders.createJarResourceLoader(SEAM_INT_JAR, new JarFile(
                            getSeamIntResourceRoot().getRoot().getPathName()));
                    moduleSpecification.addResourceLoader(ResourceLoaderSpec.createResourceLoaderSpec(resourceLoader));
                } catch (Exception e) {
                    throw new DeploymentUnitProcessingException(e);
                }

                unit.addToAttachmentList(Attachments.RESOURCE_ROOTS, getSeamIntResourceRoot());
                return;
            }
        }
    }
}
 
Example #26
Source File: ModuleDependencyProcessor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void addSystemDependencies(ModuleLoader moduleLoader, final ModuleSpecification moduleSpecification) {
  addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_PROCESS_ENGINE);
  addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_XML_MODEL);
  addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_BPMN_MODEL);
  addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_CMMN_MODEL);
  addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_DMN_MODEL);
  addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_SPIN);
  addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_CONNECT);
  addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_ENGINE_DMN);
}
 
Example #27
Source File: SecurityActions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static <T> T internalLoadAndInstantiateFromModule(String moduleId, final Class<T> iface, final String name) throws Exception {
    ModuleLoader loader = Module.getCallerModuleLoader();
    final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleId));
    ClassLoader cl = WildFlySecurityManager.isChecking() ? doPrivileged(new GetModuleClassLoaderAction(module)) : module.getClassLoader();
    Class<?> clazz = cl.loadClass(name);
    return iface.cast(clazz.newInstance());
}
 
Example #28
Source File: JBossDeploymentStructureParser11.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parseDependencies(final XMLStreamReader reader, final ModuleStructureSpec specBuilder,
                                      final ModuleLoader moduleLoader) throws XMLStreamException {
    // xsd:choice
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case MODULE:
                        parseModuleDependency(reader, specBuilder, moduleLoader);
                        break;
                    case SYSTEM:
                        parseSystemDependency(reader, specBuilder);
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw endOfDocument(reader.getLocation());
}
 
Example #29
Source File: JBossDeploymentStructureParser12.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parseDependencies(final XMLStreamReader reader, final ModuleStructureSpec specBuilder,
                                      final ModuleLoader moduleLoader) throws XMLStreamException {
    // xsd:choice
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case MODULE:
                        parseModuleDependency(reader, specBuilder, moduleLoader);
                        break;
                    case SYSTEM:
                        parseSystemDependency(reader, specBuilder);
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw endOfDocument(reader.getLocation());
}
 
Example #30
Source File: CXFResourcesTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccessFromCXFComponentModule() throws Exception {
    ModuleLoader moduleLoader = Module.getCallerModuleLoader();
    ModuleIdentifier modid = ModuleIdentifier.create("org.apache.camel.component.cxf");
    ModuleClassLoader classLoader = moduleLoader.loadModule(modid).getClassLoader();
    URL resurl = classLoader.getResource("META-INF/cxf/cxf.xml");
    Assert.assertNotNull("URL not null", resurl);
}