Search in sources :

Example 41 with VirtualFile

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

the class JSFManagedBeanProcessor method processXmlManagedBeans.

/**
     * Parse the faces config files looking for managed bean classes. The parser is quite
     * simplistic as the only information we need is the managed-bean-class element
     */
private void processXmlManagedBeans(final DeploymentUnit deploymentUnit, final Set<String> managedBeanClasses) {
    for (final VirtualFile facesConfig : getConfigurationFiles(deploymentUnit)) {
        InputStream is = null;
        try {
            is = facesConfig.openStream();
            final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            inputFactory.setXMLResolver(NoopXMLResolver.create());
            XMLStreamReader parser = inputFactory.createXMLStreamReader(is);
            StringBuilder className = null;
            int indent = 0;
            boolean managedBean = false;
            boolean managedBeanClass = false;
            while (true) {
                int event = parser.next();
                if (event == XMLStreamConstants.END_DOCUMENT) {
                    parser.close();
                    break;
                }
                if (event == XMLStreamConstants.START_ELEMENT) {
                    indent++;
                    if (indent == 2) {
                        if (parser.getLocalName().equals(MANAGED_BEAN)) {
                            managedBean = true;
                        }
                    } else if (indent == 3 && managedBean) {
                        if (parser.getLocalName().equals(MANAGED_BEAN_CLASS)) {
                            managedBeanClass = true;
                            className = new StringBuilder();
                        }
                    }
                } else if (event == XMLStreamConstants.END_ELEMENT) {
                    indent--;
                    managedBeanClass = false;
                    if (indent == 1) {
                        managedBean = false;
                    }
                    if (className != null) {
                        managedBeanClasses.add(className.toString().trim());
                        className = null;
                    }
                } else if (managedBeanClass && event == XMLStreamConstants.CHARACTERS) {
                    className.append(parser.getText());
                }
            }
        } catch (Exception e) {
            JSFLogger.ROOT_LOGGER.managedBeansConfigParseFailed(facesConfig);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) XMLInputFactory(javax.xml.stream.XMLInputFactory) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException)

Example 42 with VirtualFile

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

the class ServiceDeploymentParsingProcessor method deploy.

/**
     * Process a deployment for jboss-service.xml files. Will parse the xml file and attach a configuration discovered
     * during processing.
     *
     * @param phaseContext the deployment unit context
     * @throws DeploymentUnitProcessingException
     */
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final VirtualFile deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    if (deploymentRoot == null || !deploymentRoot.exists())
        return;
    VirtualFile serviceXmlFile = null;
    if (deploymentRoot.isDirectory()) {
        serviceXmlFile = deploymentRoot.getChild(SERVICE_DESCRIPTOR_PATH);
    } else if (deploymentRoot.getName().toLowerCase(Locale.ENGLISH).endsWith(SERVICE_DESCRIPTOR_SUFFIX)) {
        serviceXmlFile = deploymentRoot;
    }
    if (serviceXmlFile == null || !serviceXmlFile.exists())
        return;
    final XMLMapper xmlMapper = XMLMapper.Factory.create();
    final JBossServiceXmlDescriptorParser jBossServiceXmlDescriptorParser = new JBossServiceXmlDescriptorParser(JBossDescriptorPropertyReplacement.propertyReplacer(phaseContext.getDeploymentUnit()));
    xmlMapper.registerRootElement(new QName("urn:jboss:service:7.0", "server"), jBossServiceXmlDescriptorParser);
    xmlMapper.registerRootElement(new QName(null, "server"), jBossServiceXmlDescriptorParser);
    InputStream xmlStream = null;
    try {
        xmlStream = serviceXmlFile.openStream();
        final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlStream);
        final ParseResult<JBossServiceXmlDescriptor> result = new ParseResult<JBossServiceXmlDescriptor>();
        xmlMapper.parseDocument(result, reader);
        final JBossServiceXmlDescriptor xmlDescriptor = result.getResult();
        if (xmlDescriptor != null)
            phaseContext.getDeploymentUnit().putAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);
        else
            throw SarLogger.ROOT_LOGGER.failedXmlParsing(serviceXmlFile);
    } catch (Exception e) {
        throw SarLogger.ROOT_LOGGER.failedXmlParsing(e, serviceXmlFile);
    } finally {
        VFSUtils.safeClose(xmlStream);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLMapper(org.jboss.staxmapper.XMLMapper) JBossServiceXmlDescriptor(org.jboss.as.service.descriptor.JBossServiceXmlDescriptor) XMLStreamReader(javax.xml.stream.XMLStreamReader) ParseResult(org.jboss.as.service.descriptor.ParseResult) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) JBossServiceXmlDescriptorParser(org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 43 with VirtualFile

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

the class BeanDeploymentTestCase method initializeDeployment.

private VirtualFile initializeDeployment(final String path) throws Exception {
    final VirtualFile virtualFile = VFS.getChild(getResource(BeanDeploymentTestCase.class, path));
    copyResource(BeanDeploymentTestCase.class, "/org/jboss/as/mc/LegacyBean.class", path, "org/jboss/as/mc");
    return virtualFile;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile)

Example 44 with VirtualFile

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

the class VirtualFileSystemArchiveDescriptor method processVirtualFile.

private void processVirtualFile(VirtualFile virtualFile, String path, ArchiveContext archiveContext) {
    if (path == null) {
        path = "";
    } else {
        if (!path.endsWith("/'")) {
            path = path + "/";
        }
    }
    for (VirtualFile child : virtualFile.getChildren()) {
        if (!child.exists()) {
            // should never happen conceptually, but...
            continue;
        }
        if (child.isDirectory()) {
            processVirtualFile(child, path + child.getName(), archiveContext);
            continue;
        }
        final String name = child.getPathName();
        final String relativeName = path + child.getName();
        final InputStreamAccess inputStreamAccess = new VirtualFileInputStreamAccess(name, child);
        final ArchiveEntry entry = new ArchiveEntry() {

            @Override
            public String getName() {
                return name;
            }

            @Override
            public String getNameWithinArchive() {
                return relativeName;
            }

            @Override
            public InputStreamAccess getStreamAccess() {
                return inputStreamAccess;
            }
        };
        archiveContext.obtainArchiveEntryHandler(entry).handleEntry(entry, archiveContext);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) InputStreamAccess(org.hibernate.boot.archive.spi.InputStreamAccess) ArchiveEntry(org.hibernate.boot.archive.spi.ArchiveEntry)

Example 45 with VirtualFile

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

the class PersistenceUnitSearch method getPersistenceUnit.

private static PersistenceUnitMetadata getPersistenceUnit(DeploymentUnit current, final String absolutePath, String puName) {
    final String path;
    if (absolutePath.startsWith("../")) {
        path = absolutePath.substring(3);
    } else {
        path = absolutePath;
    }
    final VirtualFile parent = current.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot().getParent();
    final VirtualFile resolvedPath = parent.getChild(path);
    List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(DeploymentUtils.getTopDeploymentUnit(current));
    for (ResourceRoot resourceRoot : resourceRoots) {
        if (resourceRoot.getRoot().equals(resolvedPath)) {
            PersistenceUnitMetadataHolder holder = resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
            if (holder != null) {
                for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
                    if (traceEnabled) {
                        ROOT_LOGGER.tracef("getPersistenceUnit check '%s' against pu '%s'", puName, pu.getPersistenceUnitName());
                    }
                    if (pu.getPersistenceUnitName().equals(puName)) {
                        if (traceEnabled) {
                            ROOT_LOGGER.tracef("getPersistenceUnit matched '%s' against pu '%s'", puName, pu.getPersistenceUnitName());
                        }
                        return pu;
                    }
                }
            }
        }
    }
    throw JpaLogger.ROOT_LOGGER.persistenceUnitNotFound(absolutePath, puName, current);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

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