use of org.jboss.modules.ModuleClassLoader in project wildfly by wildfly.
the class PersistenceUnitServiceHandler method lookupProvider.
/**
* Look up the persistence provider
*
*
* @param pu
* @param deploymentUnit
* @return
*/
private static PersistenceProvider lookupProvider(PersistenceUnitMetadata pu, PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
/**
* check if the deployment is already associated with the specified persistence provider
*/
List<PersistenceProvider> providerList = persistenceProviderDeploymentHolder != null ? persistenceProviderDeploymentHolder.getProviders() : null;
if (providerList != null) {
for (PersistenceProvider persistenceProvider : providerList) {
if (persistenceProvider.getClass().getName().equals(pu.getPersistenceProviderClassName())) {
ROOT_LOGGER.tracef("deployment %s is using %s", deploymentUnit.getName(), pu.getPersistenceProviderClassName());
return persistenceProvider;
}
}
}
String configuredPersistenceProviderModule = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE);
String persistenceProviderClassName = pu.getPersistenceProviderClassName();
if (persistenceProviderClassName == null) {
persistenceProviderClassName = Configuration.PROVIDER_CLASS_DEFAULT;
}
/**
* locate persistence provider in specified static module
*/
if (configuredPersistenceProviderModule != null) {
List<PersistenceProvider> providers;
if (Configuration.PROVIDER_MODULE_APPLICATION_SUPPLIED.equals(configuredPersistenceProviderModule)) {
try {
// load the persistence provider from the application deployment
final ModuleClassLoader classLoader = deploymentUnit.getAttachment(Attachments.MODULE).getClassLoader();
PersistenceProvider provider = PersistenceProviderLoader.loadProviderFromDeployment(classLoader, persistenceProviderClassName);
providers = new ArrayList<>();
providers.add(provider);
PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
return provider;
} catch (ClassNotFoundException e) {
throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
} catch (InstantiationException e) {
throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
} catch (IllegalAccessException e) {
throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
}
} else {
try {
providers = PersistenceProviderLoader.loadProviderModuleByName(configuredPersistenceProviderModule);
PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
PersistenceProvider provider = getProviderByName(pu, providers);
if (provider != null) {
return provider;
}
} catch (ModuleLoadException e) {
throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, configuredPersistenceProviderModule, persistenceProviderClassName);
}
}
}
// try to determine the static module name based on the persistence provider class name
String providerNameDerivedFromClassName = Configuration.getProviderModuleNameFromProviderClassName(persistenceProviderClassName);
// see if the providerNameDerivedFromClassName has been loaded yet
PersistenceProvider provider = getProviderByName(pu);
// if we haven't loaded the provider yet, try loading now
if (provider == null && providerNameDerivedFromClassName != null) {
try {
List<PersistenceProvider> providers = PersistenceProviderLoader.loadProviderModuleByName(providerNameDerivedFromClassName);
PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
provider = getProviderByName(pu, providers);
} catch (ModuleLoadException e) {
throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, providerNameDerivedFromClassName, persistenceProviderClassName);
}
}
if (provider == null)
throw JpaLogger.ROOT_LOGGER.persistenceProviderNotFound(persistenceProviderClassName);
return provider;
}
use of org.jboss.modules.ModuleClassLoader in project wildfly by wildfly.
the class JSFSharedTldsProcessor method init.
private void init() {
JSFModuleIdFactory moduleFactory = JSFModuleIdFactory.getInstance();
List<String> jsfSlotNames = moduleFactory.getActiveJSFVersions();
for (String slot : jsfSlotNames) {
final List<TldMetaData> jsfTlds = new ArrayList<TldMetaData>();
try {
ModuleClassLoader jsf = Module.getModuleFromCallerModuleLoader(moduleFactory.getImplModId(slot)).getClassLoader();
for (String tld : JSF_TAGLIBS) {
InputStream is = jsf.getResourceAsStream("META-INF/" + tld);
if (is != null) {
TldMetaData tldMetaData = parseTLD(is);
jsfTlds.add(tldMetaData);
}
}
} catch (ModuleLoadException e) {
// Ignore
} catch (Exception e) {
// Ignore
}
jsfTldMap.put(slot, jsfTlds);
}
}
use of org.jboss.modules.ModuleClassLoader in project wildfly by wildfly.
the class JarResourceListingTestCase method doTestJARResourceRetrieval.
private void doTestJARResourceRetrieval(boolean recursive, String rootDir) {
ModuleClassLoader classLoader = (ModuleClassLoader) getClass().getClassLoader();
List<String> foundResources = ResourceListingUtils.listResources(classLoader, rootDir, recursive);
// only resources in JAR library should be listed
List<String> resourcesInDeployment = new ArrayList<>();
resourcesInDeployment.add(ResourceListingUtils.classToPath(JarResourceListingTestCase.class));
resourcesInDeployment.add(ResourceListingUtils.classToPath(ResourceListingUtils.class));
resourcesInDeployment.add("META-INF/example.txt");
resourcesInDeployment.add("META-INF/properties/nested.properties");
resourcesInDeployment.add("META-INF/MANIFEST.MF");
resourcesInDeployment.add("example2.txt");
resourcesInDeployment.add("TextFile1.txt");
ResourceListingUtils.filterResources(resourcesInDeployment, rootDir, !recursive);
Collections.sort(foundResources);
Collections.sort(resourcesInDeployment);
log.trace("List of expected resources:");
for (String expectedResource : resourcesInDeployment) {
log.trace(expectedResource);
}
log.trace("List of found resources: ");
for (String foundResource : foundResources) {
log.trace(foundResource);
}
Assert.assertArrayEquals("Not all resources from JAR archive are correctly listed", resourcesInDeployment.toArray(), foundResources.toArray());
}
use of org.jboss.modules.ModuleClassLoader in project wildfly by wildfly.
the class WarResourceListingTestCase method doTestResourceRetrieval.
/**
* Based on provided parameters it filters which resources should be available and which not and tests if the retrieved resources matches this list
* @param recursive also a nested/recursive resources are counted
* @param rootDir represents the filtering by root directory (only resources in the specified root dir are taken into account
*/
private void doTestResourceRetrieval(boolean recursive, String rootDir) {
ModuleClassLoader classLoader = (ModuleClassLoader) getClass().getClassLoader();
List<String> resourcesInDeployment = getActualResourcesInWar(recursive, rootDir);
List<String> foundResources = ResourceListingUtils.listResources(classLoader, rootDir, recursive);
Collections.sort(foundResources);
log.trace("List of expected resources:");
for (String expectedResource : resourcesInDeployment) {
log.trace(expectedResource);
}
log.trace("List of found resources: ");
for (String foundResource : foundResources) {
log.trace(foundResource);
}
Assert.assertArrayEquals("Not all resources from WAR archive are correctly listed", resourcesInDeployment.toArray(), foundResources.toArray());
}
use of org.jboss.modules.ModuleClassLoader in project wildfly by wildfly.
the class DriverProcessor method deploy.
/** {@inheritDoc} */
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ServicesAttachment servicesAttachment = deploymentUnit.getAttachment(Attachments.SERVICES);
if (module != null && servicesAttachment != null) {
final ModuleClassLoader classLoader = module.getClassLoader();
final List<String> driverNames = servicesAttachment.getServiceImplementations(Driver.class.getName());
for (String driverClassName : driverNames) {
try {
final Class<? extends Driver> driverClass = classLoader.loadClass(driverClassName).asSubclass(Driver.class);
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
final Driver driver = constructor.newInstance();
final int majorVersion = driver.getMajorVersion();
final int minorVersion = driver.getMinorVersion();
final boolean compliant = driver.jdbcCompliant();
if (compliant) {
DEPLOYER_JDBC_LOGGER.deployingCompliantJdbcDriver(driverClass, Integer.valueOf(majorVersion), Integer.valueOf(minorVersion));
} else {
DEPLOYER_JDBC_LOGGER.deployingNonCompliantJdbcDriver(driverClass, Integer.valueOf(majorVersion), Integer.valueOf(minorVersion));
}
String driverName = deploymentUnit.getName();
if ((driverName.contains(".") && !driverName.endsWith(".jar")) || driverNames.size() != 1) {
driverName += "_" + driverClassName + "_" + majorVersion + "_" + minorVersion;
}
InstalledDriver driverMetadata = new InstalledDriver(driverName, driverClass.getName(), null, null, majorVersion, minorVersion, compliant);
DriverService driverService = new DriverService(driverMetadata, driver);
phaseContext.getServiceTarget().addService(ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")), driverService).addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, driverService.getDriverRegistryServiceInjector()).setInitialMode(Mode.ACTIVE).install();
} catch (Throwable e) {
DEPLOYER_JDBC_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
}
}
}
}
Aggregations