Search in sources :

Example 31 with VirtualFile

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

the class UrlScanner method handleBeansXml.

public boolean handleBeansXml(final URL url, final List<String> discoveredClasses) {
    String urlPath = url.toExternalForm();
    // determin resource type (eg: jar, file, bundle)
    String urlType = "file";
    int colonIndex = urlPath.indexOf(":");
    if (colonIndex != -1) {
        urlType = urlPath.substring(0, colonIndex);
    }
    // Extra built-in support for simple file-based resources
    if ("file".equals(urlType) || "jar".equals(urlType)) {
        // switch to using getPath() instead of toExternalForm()
        urlPath = url.getPath();
        if (urlPath.indexOf('!') > 0) {
            urlPath = urlPath.substring(0, urlPath.indexOf('!'));
        } else {
            // hack for /META-INF/beans.xml
            File dirOrArchive = new File(urlPath);
            dirOrArchive = dirOrArchive.getParentFile();
            urlPath = dirOrArchive.getParent();
        }
        try {
            urlPath = URLDecoder.decode(urlPath, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            throw new RuntimeException(ex);
        }
        handle(urlPath, discoveredClasses);
        return true;
    } else if ("vfs".equals(urlType)) {
        try {
            VirtualFile vfsRoot = VFS.getChild(url).getParent().getParent();
            handle(vfsRoot, discoveredClasses);
            return true;
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    } else {
        WeldLogger.DEPLOYMENT_LOGGER.doNotUnderstandProtocol(url);
        return false;
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) ZipFile(java.util.zip.ZipFile) VirtualFile(org.jboss.vfs.VirtualFile)

Example 32 with VirtualFile

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

the class BeansXmlProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    Map<ResourceRoot, ExplicitBeanArchiveMetadata> beanArchiveMetadata = new HashMap<ResourceRoot, ExplicitBeanArchiveMetadata>();
    ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (deploymentRoot == null) {
        return;
    }
    PropertyReplacingBeansXmlParser parser = new PropertyReplacingBeansXmlParser(deploymentUnit);
    ResourceRoot classesRoot = null;
    List<ResourceRoot> structure = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
    for (ResourceRoot resourceRoot : structure) {
        if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) {
            if (resourceRoot.getRootName().equals("classes")) {
                // hack for dealing with war modules
                classesRoot = resourceRoot;
                deploymentUnit.putAttachment(WeldAttachments.CLASSES_RESOURCE_ROOT, resourceRoot);
            } else {
                VirtualFile beansXml = resourceRoot.getRoot().getChild(META_INF_BEANS_XML);
                if (beansXml.exists() && beansXml.isFile()) {
                    WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml.toString());
                    beanArchiveMetadata.put(resourceRoot, new ExplicitBeanArchiveMetadata(beansXml, resourceRoot, parseBeansXml(beansXml, parser, deploymentUnit), false));
                }
            }
        }
    }
    if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(WEB_INF_BEANS_XML);
        final boolean rootBeansXmlPresent = rootBeansXml.exists() && rootBeansXml.isFile();
        VirtualFile beansXml = null;
        if (classesRoot != null) {
            beansXml = classesRoot.getRoot().getChild(META_INF_BEANS_XML);
        }
        final boolean beansXmlPresent = beansXml != null && beansXml.exists() && beansXml.isFile();
        if (rootBeansXmlPresent) {
            if (beansXmlPresent) {
                // warn that it is not portable to use both locations at the same time
                WeldLogger.DEPLOYMENT_LOGGER.duplicateBeansXml();
                beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(rootBeansXml, beansXml, classesRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true));
            } else {
                WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml);
                beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(rootBeansXml, classesRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true));
            }
        } else if (beansXmlPresent) {
            WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml);
            beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(beansXml, classesRoot, parseBeansXml(beansXml, parser, deploymentUnit), true));
        }
    } else if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(META_INF_BEANS_XML);
        if (rootBeansXml.exists() && rootBeansXml.isFile()) {
            WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml.toString());
            beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(rootBeansXml, deploymentRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true));
        }
    }
    if (!beanArchiveMetadata.isEmpty()) {
        ExplicitBeanArchiveMetadataContainer deploymentMetadata = new ExplicitBeanArchiveMetadataContainer(beanArchiveMetadata);
        deploymentUnit.putAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY, deploymentMetadata);
        for (Iterator<Entry<ResourceRoot, ExplicitBeanArchiveMetadata>> iterator = beanArchiveMetadata.entrySet().iterator(); iterator.hasNext(); ) {
            if (BeanDiscoveryMode.NONE != iterator.next().getValue().getBeansXml().getBeanDiscoveryMode()) {
                // mark the deployment as requiring CDI integration as long as it contains at least one bean archive with bean-discovery-mode other than "none"
                WeldDeploymentMarker.mark(deploymentUnit);
                break;
            }
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) ExplicitBeanArchiveMetadata(org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadata) PropertyReplacingBeansXmlParser(org.jboss.as.weld.deployment.PropertyReplacingBeansXmlParser) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ExplicitBeanArchiveMetadataContainer(org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadataContainer)

Example 33 with VirtualFile

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

the class ApplicationClientStructureProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    String deploymentUnitName = deploymentUnit.getName().toLowerCase(Locale.ENGLISH);
    if (deploymentUnitName.endsWith(".ear")) {
        final Map<VirtualFile, ResourceRoot> existing = new HashMap<VirtualFile, ResourceRoot>();
        for (final ResourceRoot additional : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) {
            existing.put(additional.getRoot(), additional);
        }
        final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        final VirtualFile appClientRoot = root.getRoot().getChild(deployment);
        if (appClientRoot.exists()) {
            if (existing.containsKey(appClientRoot)) {
                final ResourceRoot existingRoot = existing.get(appClientRoot);
                SubDeploymentMarker.mark(existingRoot);
                ModuleRootMarker.mark(existingRoot);
            } else {
                final Closeable closable = appClientRoot.isFile() ? mount(appClientRoot, false) : null;
                final MountHandle mountHandle = new MountHandle(closable);
                final ResourceRoot childResource = new ResourceRoot(appClientRoot, mountHandle);
                ModuleRootMarker.mark(childResource);
                SubDeploymentMarker.mark(childResource);
                deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
            }
        } else {
            throw AppClientLogger.ROOT_LOGGER.cannotFindAppClient(deployment);
        }
    } else if (deploymentUnit.getParent() != null && deploymentUnitName.endsWith(".jar")) {
        final ResourceRoot parentRoot = deploymentUnit.getParent().getAttachment(Attachments.DEPLOYMENT_ROOT);
        final VirtualFile appClientRoot = parentRoot.getRoot().getChild(deployment);
        final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        if (appClientRoot.equals(root.getRoot())) {
            DeploymentTypeMarker.setType(DeploymentType.APPLICATION_CLIENT, deploymentUnit);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) HashMap(java.util.HashMap) MountHandle(org.jboss.as.server.deployment.module.MountHandle) Closeable(java.io.Closeable) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 34 with VirtualFile

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

the class ApplicationClientParsingDeploymentProcessor method parseAppClient.

private ApplicationClientMetaData parseAppClient(DeploymentUnit deploymentUnit, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR);
    // Locate the descriptor
    final VirtualFile descriptor;
    if (alternateDescriptor != null) {
        descriptor = alternateDescriptor;
    } else {
        descriptor = deploymentRoot.getRoot().getChild(APP_XML);
    }
    if (descriptor.exists()) {
        InputStream is = null;
        try {
            is = descriptor.openStream();
            ApplicationClientMetaData data = new ApplicationClientMetaDataParser().parse(getXMLStreamReader(is), propertyReplacer);
            return data;
        } catch (XMLStreamException e) {
            throw AppClientLogger.ROOT_LOGGER.failedToParseXml(e, descriptor, e.getLocation().getLineNumber(), e.getLocation().getColumnNumber());
        } catch (IOException e) {
            throw new DeploymentUnitProcessingException("Failed to parse " + descriptor, e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    } else {
        return null;
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) IOException(java.io.IOException) ApplicationClientMetaDataParser(org.jboss.metadata.appclient.parser.spec.ApplicationClientMetaDataParser)

Example 35 with VirtualFile

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

the class RaNativeProcessor method deploy.

/**
     * Process a deployment for standard ra deployment files. Will parse the xml
     * file and attach a configuration discovered during processing.
     * @param phaseContext the deployment unit context
     * @throws DeploymentUnitProcessingException
     */
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final VirtualFile deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    process(deploymentRoot);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile)

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