Search in sources :

Example 1 with ModuleIdentifier

use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.

the class JPADependencyProcessor method addDependency.

private void addDependency(ModuleSpecification moduleSpecification, ModuleLoader moduleLoader, DeploymentUnit deploymentUnit, ModuleIdentifier... moduleIdentifiers) {
    for (ModuleIdentifier moduleIdentifier : moduleIdentifiers) {
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, false, false, true, false));
        ROOT_LOGGER.debugf("added %s dependency to %s", moduleIdentifier, deploymentUnit.getName());
    }
}
Also used : ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) ModuleIdentifier(org.jboss.modules.ModuleIdentifier)

Example 2 with ModuleIdentifier

use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.

the class NamingBindingAdd method createObjectFactory.

private ObjectFactory createObjectFactory(OperationContext context, ModelNode model) throws OperationFailedException {
    final ModuleIdentifier moduleID = ModuleIdentifier.fromString(NamingBindingResourceDefinition.MODULE.resolveModelAttribute(context, model).asString());
    final String className = NamingBindingResourceDefinition.CLASS.resolveModelAttribute(context, model).asString();
    final Module module;
    try {
        module = Module.getBootModuleLoader().loadModule(moduleID);
    } catch (ModuleLoadException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotLoadModule(moduleID);
    }
    final ObjectFactory objectFactoryClassInstance;
    final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
        final Class<?> clazz = module.getClassLoader().loadClass(className);
        objectFactoryClassInstance = (ObjectFactory) clazz.newInstance();
    } catch (ClassNotFoundException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotLoadClassFromModule(className, moduleID);
    } catch (InstantiationException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
    } catch (IllegalAccessException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
    } catch (ClassCastException e) {
        throw NamingLogger.ROOT_LOGGER.notAnInstanceOfObjectFactory(className, moduleID);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
    }
    return objectFactoryClassInstance;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ObjectFactory(javax.naming.spi.ObjectFactory) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module)

Example 3 with ModuleIdentifier

use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.

the class HibernateSearchProcessor method addSearchDependency.

private void addSearchDependency(ModuleSpecification moduleSpecification, ModuleLoader moduleLoader, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    String searchModuleName = null;
    PersistenceUnitsInApplication persistenceUnitsInApplication = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION);
    for (PersistenceUnitMetadataHolder holder : persistenceUnitsInApplication.getPersistenceUnitHolders()) {
        for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
            String providerModule = pu.getProperties().getProperty(Configuration.HIBERNATE_SEARCH_MODULE);
            if (providerModule != null) {
                // one persistence unit specifying the Hibernate search module is allowed
                if (searchModuleName == null) {
                    searchModuleName = providerModule;
                } else // more than one persistence unit specifying different Hibernate search module names is not allowed
                if (!providerModule.equals(searchModuleName)) {
                    throw JpaLogger.ROOT_LOGGER.differentSearchModuleDependencies(deploymentUnit.getName(), searchModuleName, providerModule);
                }
            }
        }
    }
    if (NONE.equals(searchModuleName)) {
        // Hibernate Search module will not be added to deployment
        ROOT_LOGGER.debugf("Not adding Hibernate Search dependency to deployment %s", deploymentUnit.getName());
        return;
    }
    // use Search module name specified in persistence unit definition
    if (searchModuleName != null && !IGNORE.equals(searchModuleName)) {
        ModuleIdentifier moduleIdentifier = ModuleIdentifier.fromString(searchModuleName);
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, false, true, true, false));
        ROOT_LOGGER.debugf("added %s dependency to %s", moduleIdentifier, deploymentUnit.getName());
    } else {
        // add Hibernate Search module dependency if application is using the Hibernate Search Indexed annotation
        final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
        List<AnnotationInstance> annotations = index.getAnnotations(SEARCH_INDEXED_ANNOTATION_NAME);
        if (annotations != null && annotations.size() > 0) {
            moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, defaultSearchModule, false, true, true, false));
            ROOT_LOGGER.debugf("deployment %s contains %s annotation, added %s dependency", deploymentUnit.getName(), SEARCH_INDEXED_ANNOTATION_NAME, defaultSearchModule);
        }
    }
}
Also used : ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) PersistenceUnitsInApplication(org.jboss.as.jpa.config.PersistenceUnitsInApplication) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 4 with ModuleIdentifier

use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.

the class JPADependencyProcessor method addOptionalDependency.

private void addOptionalDependency(ModuleSpecification moduleSpecification, ModuleLoader moduleLoader, DeploymentUnit deploymentUnit, ModuleIdentifier... moduleIdentifiers) {
    for (ModuleIdentifier moduleIdentifier : moduleIdentifiers) {
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, true, false, false, false));
        ROOT_LOGGER.debugf("added %s dependency to %s", moduleIdentifier, deploymentUnit.getName());
    }
}
Also used : ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) ModuleIdentifier(org.jboss.modules.ModuleIdentifier)

Example 5 with ModuleIdentifier

use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.

the class JSFDependencyProcessor method addJSFImpl.

// Is JSF spec greater than 1.1?  If we add JSF 1.1 support we'll need this to keep from calling addJSFInjection()
/*  private boolean isJSFSpecOver1_1(ModuleIdentifier jsfModule, ModuleDependency jsfAPI) throws DeploymentUnitProcessingException {
        try {
            return (jsfAPI.getModuleLoader().loadModule(jsfModule).getClassLoader().getResource("/javax/faces/component/ActionSource2.class") != null);
        } catch (ModuleLoadException e) {
            throw new DeploymentUnitProcessingException(e);
        }
    } */
private void addJSFImpl(String jsfVersion, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) {
    if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL))
        return;
    ModuleIdentifier jsfModule = moduleIdFactory.getImplModId(jsfVersion);
    ModuleDependency jsfImpl = new ModuleDependency(moduleLoader, jsfModule, false, false, true, false);
    jsfImpl.addImportFilter(PathFilters.getMetaInfFilter(), true);
    moduleSpecification.addSystemDependency(jsfImpl);
}
Also used : ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) ModuleIdentifier(org.jboss.modules.ModuleIdentifier)

Aggregations

ModuleIdentifier (org.jboss.modules.ModuleIdentifier)22 ModuleDependency (org.jboss.as.server.deployment.module.ModuleDependency)12 Module (org.jboss.modules.Module)10 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)8 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)6 ModuleLoadException (org.jboss.modules.ModuleLoadException)6 ArrayList (java.util.ArrayList)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)4 ModuleLoader (org.jboss.modules.ModuleLoader)4 ServiceTarget (org.jboss.msc.service.ServiceTarget)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)3 WarMetaData (org.jboss.as.web.common.WarMetaData)3 ServiceName (org.jboss.msc.service.ServiceName)3 IOException (java.io.IOException)2 Driver (java.sql.Driver)2 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)2 Index (org.jboss.jandex.Index)2 Closeable (java.io.Closeable)1