use of org.jboss.metadata.ear.spec.ModuleMetaData in project wildfly by wildfly.
the class EarStructureProcessor method deploy.
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
final ResourceRoot deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile virtualFile = deploymentRoot.getRoot();
// Make sure we don't index or add this as a module root
deploymentRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
ModuleRootMarker.mark(deploymentRoot, false);
String libDirName = DEFAULT_LIB_DIR;
// its possible that the ear metadata could come for jboss-app.xml
final boolean appXmlPresent = deploymentRoot.getRoot().getChild("META-INF/application.xml").exists();
final EarMetaData earMetaData = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
if (earMetaData != null) {
final String xmlLibDirName = earMetaData.getLibraryDirectory();
if (xmlLibDirName != null) {
if (xmlLibDirName.length() == 1 && xmlLibDirName.charAt(0) == '/') {
throw EeLogger.ROOT_LOGGER.rootAsLibraryDirectory();
}
libDirName = xmlLibDirName;
}
}
// Process all the children
Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
try {
final VirtualFile libDir;
// process the lib directory
if (!libDirName.isEmpty()) {
libDir = virtualFile.getChild(libDirName);
if (libDir.exists()) {
List<VirtualFile> libArchives = libDir.getChildren(CHILD_ARCHIVE_FILTER);
for (final VirtualFile child : libArchives) {
String relativeName = child.getPathNameRelativeTo(deploymentRoot.getRoot());
MountedDeploymentOverlay overlay = overlays.get(relativeName);
final MountHandle mountHandle;
if (overlay != null) {
overlay.remountAsZip(false);
mountHandle = new MountHandle(null);
} else {
final Closeable closable = child.isFile() ? mount(child, false) : null;
mountHandle = new MountHandle(closable);
}
final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
if (child.getName().toLowerCase(Locale.ENGLISH).endsWith(JAR_EXTENSION)) {
ModuleRootMarker.mark(childResource);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
}
}
}
} else {
libDir = null;
}
// scan the ear looking for wars and jars
final List<VirtualFile> childArchives = new ArrayList<VirtualFile>(virtualFile.getChildren(new SuffixMatchFilter(CHILD_ARCHIVE_EXTENSIONS, new VisitorAttributes() {
@Override
public boolean isLeavesOnly() {
return false;
}
@Override
public boolean isRecurse(VirtualFile file) {
// don't recurse into /lib
if (file.equals(libDir)) {
return false;
}
for (String suffix : CHILD_ARCHIVE_EXTENSIONS) {
if (file.getName().endsWith(suffix)) {
// don't recurse into sub deployments
return false;
}
}
return true;
}
})));
// if there is no application.xml then look in the ear root for modules
if (!appXmlPresent) {
for (final VirtualFile child : childArchives) {
final boolean isWarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(WAR_EXTENSION);
final boolean isRarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(RAR_EXTENSION);
this.createResourceRoot(deploymentUnit, child, isWarFile || isRarFile, isWarFile);
}
} else {
final Set<VirtualFile> subDeploymentFiles = new HashSet<VirtualFile>();
// otherwise read from application.xml
for (final ModuleMetaData module : earMetaData.getModules()) {
if (module.getFileName().endsWith(".xml")) {
throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
}
final VirtualFile moduleFile = virtualFile.getChild(module.getFileName());
if (!moduleFile.exists()) {
throw EeLogger.ROOT_LOGGER.cannotProcessEarModule(virtualFile, module.getFileName());
}
if (libDir != null) {
VirtualFile moduleParentFile = moduleFile.getParent();
if (moduleParentFile != null && libDir.equals(moduleParentFile)) {
throw EeLogger.ROOT_LOGGER.earModuleChildOfLibraryDirectory(libDirName, module.getFileName());
}
}
// maintain this in a collection of subdeployment virtual files, to be used later
subDeploymentFiles.add(moduleFile);
final boolean webArchive = module.getType() == ModuleType.Web;
final ResourceRoot childResource = this.createResourceRoot(deploymentUnit, moduleFile, true, webArchive);
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.MODULE_META_DATA, module);
if (!webArchive) {
ModuleRootMarker.mark(childResource);
}
final String alternativeDD = module.getAlternativeDD();
if (alternativeDD != null && alternativeDD.trim().length() > 0) {
final VirtualFile alternateDeploymentDescriptor = deploymentRoot.getRoot().getChild(alternativeDD);
if (!alternateDeploymentDescriptor.exists()) {
throw EeLogger.ROOT_LOGGER.alternateDeploymentDescriptor(alternateDeploymentDescriptor, moduleFile);
}
switch(module.getType()) {
case Client:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Connector:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CONNECTOR_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Ejb:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Web:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_WEB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Service:
throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
}
}
}
// now check the rest of the archive for any other jar/sar files
for (final VirtualFile child : childArchives) {
if (subDeploymentFiles.contains(child)) {
continue;
}
final String fileName = child.getName().toLowerCase(Locale.ENGLISH);
if (fileName.endsWith(SAR_EXTENSION) || fileName.endsWith(JAR_EXTENSION)) {
this.createResourceRoot(deploymentUnit, child, false, false);
}
}
}
} catch (IOException e) {
throw EeLogger.ROOT_LOGGER.failedToProcessChild(e, virtualFile);
}
}
use of org.jboss.metadata.ear.spec.ModuleMetaData in project wildfly by wildfly.
the class ASHelper method getContextRoot.
/**
* Returns context root associated with webservice deployment.
*
* If there's application.xml descriptor provided defining nested web module, then context root defined there will be
* returned. Otherwise context root defined in jboss-web.xml will be returned.
*
* @param dep webservice deployment
* @param jbossWebMD jboss web meta data
* @return context root
*/
public static String getContextRoot(final Deployment dep, final JBossWebMetaData jbossWebMD) {
final DeploymentUnit unit = WSHelper.getRequiredAttachment(dep, DeploymentUnit.class);
final JBossAppMetaData jbossAppMD = unit.getParent() == null ? null : ASHelper.getOptionalAttachment(unit.getParent(), WSAttachmentKeys.JBOSS_APP_METADATA_KEY);
String contextRoot = null;
// prefer context root defined in application.xml over one defined in jboss-web.xml
if (jbossAppMD != null) {
final ModuleMetaData moduleMD = jbossAppMD.getModules().get(dep.getSimpleName());
if (moduleMD != null) {
final WebModuleMetaData webModuleMD = (WebModuleMetaData) moduleMD.getValue();
contextRoot = webModuleMD.getContextRoot();
}
}
if (contextRoot == null) {
contextRoot = jbossWebMD != null ? jbossWebMD.getContextRoot() : null;
}
return contextRoot;
}
use of org.jboss.metadata.ear.spec.ModuleMetaData in project wildfly by wildfly.
the class JPADependencyProcessor method addPersistenceProviderModuleDependencies.
private void addPersistenceProviderModuleDependencies(DeploymentPhaseContext phaseContext, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
int defaultProviderCount = 0;
Set<String> moduleDependencies = new HashSet<String>();
// get the number of persistence units that use the default persistence provider module.
// Dependencies for other persistence provider will be added to the passed
// 'moduleDependencies' collection. Each persistence provider module that is found, will be injected into the
// passed moduleSpecification (for the current deployment unit).
PersistenceUnitsInApplication persistenceUnitsInApplication = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION);
for (PersistenceUnitMetadataHolder holder : persistenceUnitsInApplication.getPersistenceUnitHolders()) {
defaultProviderCount += loadPersistenceUnits(moduleSpecification, moduleLoader, deploymentUnit, moduleDependencies, holder);
}
// add dependencies for the default persistence provider module
if (defaultProviderCount > 0) {
moduleDependencies.add(Configuration.getDefaultProviderModuleName());
ROOT_LOGGER.debugf("added (default provider) %s dependency to %s (since %d PU(s) didn't specify %s", Configuration.getDefaultProviderModuleName(), deploymentUnit.getName(), defaultProviderCount, Configuration.PROVIDER_MODULE + ")");
}
// add persistence provider dependency
for (String dependency : moduleDependencies) {
addDependency(moduleSpecification, moduleLoader, deploymentUnit, ModuleIdentifier.fromString(dependency));
}
// add the PU service as a dependency to all EE components in this scope
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final Collection<ComponentDescription> components = eeModuleDescription.getComponentDescriptions();
boolean earSubDeploymentsAreInitializedInCustomOrder = false;
EarMetaData earConfig = null;
earConfig = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
earSubDeploymentsAreInitializedInCustomOrder = earConfig != null && earConfig.getInitializeInOrder() && earConfig.getModules().size() > 1;
// persistence units in the same sub-deployment (and top level deployment)
if (earSubDeploymentsAreInitializedInCustomOrder) {
if (deploymentUnit.getParent() != null) {
// add persistence units defined in current (sub) deployment unit to EE components
// also in current deployment unit.
List<PersistenceUnitMetadata> collectPersistenceUnitsForCurrentDeploymentUnit = new ArrayList<>();
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final ModuleMetaData moduleMetaData = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.MODULE_META_DATA);
for (PersistenceUnitMetadataHolder holder : persistenceUnitsInApplication.getPersistenceUnitHolders()) {
if (holder != null && holder.getPersistenceUnits() != null) {
for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
String moduleName = pu.getContainingModuleName().get(pu.getContainingModuleName().size() - 1);
if (moduleName.equals(moduleMetaData.getFileName())) {
ROOT_LOGGER.tracef("Jakarta EE components in %s will depend on persistence unit %s", moduleName, pu.getScopedPersistenceUnitName());
collectPersistenceUnitsForCurrentDeploymentUnit.add(pu);
}
}
}
}
if (!collectPersistenceUnitsForCurrentDeploymentUnit.isEmpty()) {
addPUServiceDependencyToComponents(components, new PersistenceUnitMetadataHolder(collectPersistenceUnitsForCurrentDeploymentUnit));
}
} else {
// WFLY-14923
// add Jakarta EE component dependencies on all persistence units in top level deployment unit.
List<ResourceRoot> resourceRoots = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
// look at resources that aren't subdeployments
if (!SubDeploymentMarker.isSubDeployment(resourceRoot)) {
addPUServiceDependencyToComponents(components, resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS));
}
}
}
// end of earSubDeploymentsAreInitializedInCustomOrder handling
} else {
// no `initialize-in-order` ordering configuration was specified (this is the default).
for (PersistenceUnitMetadataHolder holder : persistenceUnitsInApplication.getPersistenceUnitHolders()) {
addPUServiceDependencyToComponents(components, holder);
}
}
}
use of org.jboss.metadata.ear.spec.ModuleMetaData in project wildfly by wildfly.
the class InitializeInOrderProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit parent = deploymentUnit.getParent();
if (parent == null) {
return;
}
final EarMetaData earConfig = parent.getAttachment(Attachments.EAR_METADATA);
if (earConfig != null) {
final boolean inOrder = earConfig.getInitializeInOrder();
if (inOrder && earConfig.getModules().size() > 1) {
final Map<String, DeploymentUnit> deploymentUnitMap = new HashMap<String, DeploymentUnit>();
for (final DeploymentUnit subDeployment : parent.getAttachment(org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS)) {
final ResourceRoot deploymentRoot = subDeployment.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final ModuleMetaData moduleMetaData = deploymentRoot.getAttachment(Attachments.MODULE_META_DATA);
if (moduleMetaData != null) {
deploymentUnitMap.put(moduleMetaData.getFileName(), subDeployment);
}
}
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final ModuleMetaData thisModulesMetadata = deploymentRoot.getAttachment(Attachments.MODULE_META_DATA);
if (thisModulesMetadata != null && thisModulesMetadata.getType() != ModuleMetaData.ModuleType.Client) {
ModuleMetaData previous = null;
boolean found = false;
for (ModuleMetaData module : earConfig.getModules()) {
if (module.getType() != ModuleMetaData.ModuleType.Client) {
if (module.getFileName().equals(thisModulesMetadata.getFileName())) {
found = true;
break;
}
previous = module;
}
}
if (previous != null && found) {
// now we know the previous module we can setup the service dependencies
// we setup one on the deployment service, and also one on every component
final ServiceName serviceName = Services.deploymentUnitName(parent.getName(), previous.getFileName());
phaseContext.addToAttachmentList(org.jboss.as.server.deployment.Attachments.NEXT_PHASE_DEPS, serviceName.append(Phase.INSTALL.name()));
final DeploymentUnit prevDeployment = deploymentUnitMap.get(previous.getFileName());
phaseContext.addToAttachmentList(org.jboss.as.server.deployment.Attachments.NEXT_PHASE_DEPS, DeploymentCompleteServiceProcessor.serviceName(prevDeployment.getServiceName()));
}
}
}
}
}
use of org.jboss.metadata.ear.spec.ModuleMetaData in project wildfly by wildfly.
the class ApplicationClientDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
List<ResourceRoot> potentialSubDeployments = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : potentialSubDeployments) {
if (ModuleRootMarker.isModuleRoot(resourceRoot)) {
// module roots cannot be ejb jars
continue;
}
VirtualFile appclientClientXml = resourceRoot.getRoot().getChild(META_INF_APPLICATION_CLIENT_XML);
if (appclientClientXml.exists()) {
SubDeploymentMarker.mark(resourceRoot);
ModuleRootMarker.mark(resourceRoot);
} else {
final Manifest manifest = resourceRoot.getAttachment(Attachments.MANIFEST);
if (manifest != null) {
Attributes main = manifest.getMainAttributes();
if (main != null) {
String mainClass = main.getValue("Main-Class");
if (mainClass != null && !mainClass.isEmpty()) {
SubDeploymentMarker.mark(resourceRoot);
ModuleRootMarker.mark(resourceRoot);
}
}
}
}
}
} else if (deploymentUnit.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final ModuleMetaData md = root.getAttachment(org.jboss.as.ee.structure.Attachments.MODULE_META_DATA);
if (md != null) {
if (md.getType() == ModuleMetaData.ModuleType.Client) {
DeploymentTypeMarker.setType(DeploymentType.APPLICATION_CLIENT, deploymentUnit);
}
} else {
VirtualFile appclientClientXml = root.getRoot().getChild(META_INF_APPLICATION_CLIENT_XML);
if (appclientClientXml.exists()) {
DeploymentTypeMarker.setType(DeploymentType.APPLICATION_CLIENT, deploymentUnit);
} else {
final Manifest manifest = root.getAttachment(Attachments.MANIFEST);
if (manifest != null) {
Attributes main = manifest.getMainAttributes();
if (main != null) {
String mainClass = main.getValue("Main-Class");
if (mainClass != null && !mainClass.isEmpty()) {
DeploymentTypeMarker.setType(DeploymentType.APPLICATION_CLIENT, deploymentUnit);
}
}
}
}
}
}
}
Aggregations