Search in sources :

Example 56 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class MessagingXmlParsingDeploymentUnitProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Set<VirtualFile> files = messageDestinations(deploymentUnit);
    final XMLMapper mapper = XMLMapper.Factory.create();
    final MessagingDeploymentParser_1_0 messagingDeploymentParser_1_0 = new MessagingDeploymentParser_1_0(JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
    mapper.registerRootElement(ROOT_1_0, messagingDeploymentParser_1_0);
    mapper.registerRootElement(ROOT_NO_NAMESPACE, messagingDeploymentParser_1_0);
    for (final VirtualFile file : files) {
        InputStream xmlStream = null;
        try {
            final File f = file.getPhysicalFile();
            xmlStream = new FileInputStream(f);
            try {
                final XMLInputFactory inputFactory = INPUT_FACTORY;
                setIfSupported(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
                setIfSupported(inputFactory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
                final XMLStreamReader streamReader = inputFactory.createXMLStreamReader(xmlStream);
                final ParseResult result = new ParseResult();
                try {
                    mapper.parseDocument(result, streamReader);
                    deploymentUnit.addToAttachmentList(MessagingAttachments.PARSE_RESULT, result);
                } finally {
                    safeClose(streamReader, f.getAbsolutePath());
                }
            } catch (XMLStreamException e) {
                throw MessagingLogger.ROOT_LOGGER.couldNotParseDeployment(f.getPath(), e);
            }
        } catch (Exception e) {
            throw new DeploymentUnitProcessingException(e.getMessage(), e);
        } finally {
            VFSUtils.safeClose(xmlStream);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLMapper(org.jboss.staxmapper.XMLMapper) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) File(java.io.File) VirtualFile(org.jboss.vfs.VirtualFile) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 57 with VirtualFile

use of org.jboss.vfs.VirtualFile 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 58 with VirtualFile

use of org.jboss.vfs.VirtualFile 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 59 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class EarMetaDataParsingProcessor method handleJbossMetadata.

private JBossAppMetaData handleJbossMetadata(VirtualFile deploymentFile, final PropertyReplacer propertyReplacer, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    final VirtualFile applicationXmlFile = deploymentFile.getChild(JBOSS_APP_XML);
    if (!applicationXmlFile.exists()) {
        //may have been in jboss-all.xml
        return deploymentUnit.getAttachment(AppJBossAllParser.ATTACHMENT_KEY);
    }
    InputStream inputStream = null;
    try {
        inputStream = applicationXmlFile.openStream();
        final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        inputFactory.setXMLResolver(NoopXMLResolver.create());
        XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream);
        return JBossAppMetaDataParser.INSTANCE.parse(xmlReader, propertyReplacer);
    } catch (Exception e) {
        throw EeLogger.ROOT_LOGGER.failedToParse(e, applicationXmlFile);
    } finally {
        VFSUtils.safeClose(inputStream);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) XMLInputFactory(javax.xml.stream.XMLInputFactory) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 60 with VirtualFile

use of org.jboss.vfs.VirtualFile 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)

Aggregations

VirtualFile (org.jboss.vfs.VirtualFile)93 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)36 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)29 InputStream (java.io.InputStream)28 IOException (java.io.IOException)23 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)22 Test (org.junit.Test)18 File (java.io.File)16 Closeable (java.io.Closeable)12 URI (java.net.URI)10 HashSet (java.util.HashSet)10 XMLStreamReader (javax.xml.stream.XMLStreamReader)10 Index (org.jboss.jandex.Index)10 SuffixMatchFilter (org.jboss.vfs.util.SuffixMatchFilter)10 ArrayList (java.util.ArrayList)9 XMLStreamException (javax.xml.stream.XMLStreamException)9 WarMetaData (org.jboss.as.web.common.WarMetaData)9 Indexer (org.jboss.jandex.Indexer)8 AnnotationRepository (org.jboss.jca.common.spi.annotations.repository.AnnotationRepository)8 XMLInputFactory (javax.xml.stream.XMLInputFactory)7