Search in sources :

Example 51 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot 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()));
                }
            }
        }
    }
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) HashMap(java.util.HashMap) ServiceName(org.jboss.msc.service.ServiceName) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) ModuleMetaData(org.jboss.metadata.ear.spec.ModuleMetaData)

Example 52 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.

the class DeploymentPropertiesProcessor method deploy.

public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.hasAttachment(Attachments.DEPLOYMENT_PROPERTIES)) {
        return;
    }
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
    final VirtualFile deploymentFile = deploymentRoot.getRoot();
    final VirtualFile propertiesFile = deploymentFile.getChild(DEPLOYMENT_PROPERTIES);
    if (!propertiesFile.exists()) {
        return;
    }
    Properties properties = new Properties();
    InputStream propertyFileStream = null;
    try {
        propertyFileStream = propertiesFile.openStream();
        properties.load(propertyFileStream);
    } catch (IOException e) {
        throw EeLogger.ROOT_LOGGER.failedToLoadJbossProperties(e);
    } finally {
        VFSUtils.safeClose(propertyFileStream);
    }
    deploymentUnit.putAttachment(Attachments.DEPLOYMENT_PROPERTIES, properties);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 53 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot 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);
                        }
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ModuleMetaData(org.jboss.metadata.ear.spec.ModuleMetaData)

Example 54 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.

the class EarMetaDataParsingProcessor 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 = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
    final VirtualFile deploymentFile = deploymentRoot.getRoot();
    EarMetaData earMetaData = handleSpecMetadata(deploymentFile, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
    JBossAppMetaData jbossMetaData = handleJbossMetadata(deploymentFile, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit), deploymentUnit);
    if (earMetaData == null && jbossMetaData == null) {
        return;
    }
    // the jboss-app.xml has a distinct-name configured then attach it to the deployment unit
    if (jbossMetaData != null && jbossMetaData.getDistinctName() != null) {
        deploymentUnit.putAttachment(Attachments.DISTINCT_NAME, jbossMetaData.getDistinctName());
    }
    JBossAppMetaData merged;
    if (earMetaData != null) {
        merged = new JBossAppMetaData(earMetaData.getEarVersion());
    } else {
        merged = new JBossAppMetaData();
    }
    JBossAppMetaDataMerger.merge(merged, jbossMetaData, earMetaData);
    deploymentUnit.putAttachment(Attachments.EAR_METADATA, merged);
    if (merged.getEarEnvironmentRefsGroup() != null) {
        final DeploymentDescriptorEnvironment bindings = new DeploymentDescriptorEnvironment("java:app/env/", merged.getEarEnvironmentRefsGroup());
        deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.MODULE_DEPLOYMENT_DESCRIPTOR_ENVIRONMENT, bindings);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) JBossAppMetaData(org.jboss.metadata.ear.jboss.JBossAppMetaData) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData)

Example 55 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.

the class JpaDependenciesProvider method getDependencies.

@Override
public Set<ServiceName> getDependencies(DeploymentUnit deploymentUnit) {
    Set<ServiceName> dependencies = new HashSet<>();
    for (ResourceRoot root : DeploymentUtils.allResourceRoots(deploymentUnit)) {
        final PersistenceUnitMetadataHolder persistenceUnits = root.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
        if (persistenceUnits != null && persistenceUnits.getPersistenceUnits() != null) {
            for (final PersistenceUnitMetadata pu : persistenceUnits.getPersistenceUnits()) {
                final Properties properties = pu.getProperties();
                final String jpaContainerManaged = properties.getProperty(Configuration.JPA_CONTAINER_MANAGED);
                final boolean deployPU = (jpaContainerManaged == null || Boolean.parseBoolean(jpaContainerManaged));
                if (deployPU) {
                    final ServiceName serviceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
                    dependencies.add(serviceName);
                }
            }
        }
    }
    return dependencies;
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) ServiceName(org.jboss.msc.service.ServiceName) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) Properties(java.util.Properties) HashSet(java.util.HashSet)

Aggregations

ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)71 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)49 VirtualFile (org.jboss.vfs.VirtualFile)37 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)12 HashMap (java.util.HashMap)10 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)10 WarMetaData (org.jboss.as.web.common.WarMetaData)10 MountHandle (org.jboss.as.server.deployment.module.MountHandle)9 Index (org.jboss.jandex.Index)8 Closeable (java.io.Closeable)7 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Module (org.jboss.modules.Module)7 InputStream (java.io.InputStream)6 EarMetaData (org.jboss.metadata.ear.spec.EarMetaData)6 ServiceName (org.jboss.msc.service.ServiceName)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 EEApplicationDescription (org.jboss.as.ee.component.EEApplicationDescription)5