Search in sources :

Example 81 with VirtualFile

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

the class WildFlyJobXmlResolver method create.

private static WildFlyJobXmlResolver create(final ClassLoader classLoader, final List<ResourceRoot> resources) throws DeploymentUnitProcessingException {
    final Map<String, VirtualFile> foundJobXmlFiles = new LinkedHashMap<>();
    for (ResourceRoot r : resources) {
        final VirtualFile root = r.getRoot();
        try {
            addJobXmlFiles(foundJobXmlFiles, root.getChild(DEFAULT_PATH));
        } catch (IOException e) {
            throw BatchLogger.LOGGER.errorProcessingBatchJobsDir(e);
        }
    }
    final WildFlyJobXmlResolver jobXmlResolver = new WildFlyJobXmlResolver(foundJobXmlFiles);
    // Initialize this instance
    jobXmlResolver.init(classLoader);
    return jobXmlResolver;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 82 with VirtualFile

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

the class WildFlyJobXmlResolver method init.

/**
     * Initializes the state of an instance
     */
private void init(final ClassLoader classLoader) {
    // Load the user defined resolvers
    for (JobXmlResolver resolver : ServiceLoader.load(JobXmlResolver.class, classLoader)) {
        jobXmlResolvers.add(resolver);
        for (String jobXml : resolver.getJobXmlNames(classLoader)) {
            addJob(jobXml, resolver.resolveJobName(jobXml, classLoader));
        }
    }
    // Load the default names
    for (Map.Entry<String, VirtualFile> entry : jobXmlFiles.entrySet()) {
        try {
            // Parsing the entire job XML seems excessive to just get the job name. There are two reasons for this:
            //  1) If an error occurs during parsing there's no real need to consider this a valid job
            //  2) Using the implementation parser seems less error prone for future-proofing
            final Job job = JobParser.parseJob(entry.getValue().openStream(), classLoader, new XMLResolver() {

                // this is essentially what JBeret does, but it's ugly. JBeret might need an API to handle this
                @Override
                public Object resolveEntity(final String publicID, final String systemID, final String baseURI, final String namespace) throws XMLStreamException {
                    try {
                        return (jobXmlFiles.containsKey(systemID) ? jobXmlFiles.get(systemID).openStream() : null);
                    } catch (IOException e) {
                        throw new XMLStreamException(e);
                    }
                }
            });
            addJob(entry.getKey(), job.getId());
        } catch (XMLStreamException | IOException e) {
            // Report the possible error as we don't want to fail the deployment. The job may never be run.
            BatchLogger.LOGGER.invalidJobXmlFile(entry.getKey());
        }
    }
}
Also used : JobXmlResolver(org.jberet.spi.JobXmlResolver) VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamException(javax.xml.stream.XMLStreamException) XMLResolver(javax.xml.stream.XMLResolver) IOException(java.io.IOException) Job(org.jberet.job.model.Job) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 83 with VirtualFile

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

the class EjbJarParsingDeploymentUnitProcessor method parseEjbJarXml.

private static EjbJarMetaData parseEjbJarXml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR);
    //this is a bit tri
    // Locate the descriptor
    final VirtualFile descriptor;
    if (alternateDescriptor != null) {
        descriptor = alternateDescriptor;
    } else {
        descriptor = getDescriptor(deploymentRoot.getRoot(), EJB_JAR_XML);
    }
    if (descriptor == null) {
        // no descriptor found, nothing to do!
        return null;
    }
    // get the XMLStreamReader and parse the descriptor
    MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
    InputStream stream = open(descriptor);
    try {
        XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
        EjbJarMetaData ejbJarMetaData = EjbJarMetaDataParser.parse(reader, dtdInfo, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
        return ejbJarMetaData;
    } catch (XMLStreamException xmlse) {
        throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, "ejb-jar.xml: " + descriptor.getPathName());
    } finally {
        try {
            stream.close();
        } catch (IOException ioe) {
            EjbLogger.DEPLOYMENT_LOGGER.failToCloseFile(ioe);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) MetaDataElementParser(org.jboss.metadata.parser.util.MetaDataElementParser) IOException(java.io.IOException)

Example 84 with VirtualFile

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

the class EjbJarParsingDeploymentUnitProcessor method parseJBossEjb3Xml.

private static EjbJarMetaData parseJBossEjb3Xml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    // Locate the descriptor
    final VirtualFile descriptor = getDescriptor(deploymentRoot, JBOSS_EJB3_XML);
    if (descriptor == null) {
        //but there may have been an ejb-jar element in jboss-all.xml
        return deploymentUnit.getAttachment(EjbJarJBossAllParser.ATTACHMENT_KEY);
    }
    // get the XMLStreamReader and parse the descriptor
    MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
    InputStream stream = open(descriptor);
    try {
        XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
        final JBossEjb3MetaDataParser parser = new JBossEjb3MetaDataParser(createJbossEjbJarParsers());
        final EjbJarMetaData ejbJarMetaData = parser.parse(reader, dtdInfo, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
        return ejbJarMetaData;
    } catch (XMLStreamException xmlse) {
        throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, JBOSS_EJB3_XML + ": " + descriptor.getPathName());
    } finally {
        try {
            stream.close();
        } catch (IOException ioe) {
            EjbLogger.DEPLOYMENT_LOGGER.failToCloseFile(ioe);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) MetaDataElementParser(org.jboss.metadata.parser.util.MetaDataElementParser) IOException(java.io.IOException) JBossEjb3MetaDataParser(org.jboss.metadata.ejb.parser.jboss.ejb3.JBossEjb3MetaDataParser)

Example 85 with VirtualFile

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

the class SarStructureProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (resourceRoot == null) {
        return;
    }
    final VirtualFile deploymentRoot = resourceRoot.getRoot();
    if (deploymentRoot == null || !deploymentRoot.exists()) {
        return;
    }
    final String deploymentRootName = deploymentRoot.getName().toLowerCase(Locale.ENGLISH);
    if (!deploymentRootName.endsWith(SAR_EXTENSION)) {
        return;
    }
    ModuleRootMarker.mark(resourceRoot, true);
    Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
    try {
        final List<VirtualFile> childArchives = deploymentRoot.getChildren(CHILD_ARCHIVE_FILTER);
        for (final VirtualFile child : childArchives) {
            String relativeName = child.getPathNameRelativeTo(deploymentRoot);
            MountedDeploymentOverlay overlay = overlays.get(relativeName);
            Closeable closable = NO_OP_CLOSEABLE;
            if (overlay != null) {
                overlay.remountAsZip(false);
            } else if (child.isFile()) {
                closable = VFS.mountZip(child, child, TempFileProviderService.provider());
            }
            final MountHandle mountHandle = new MountHandle(closable);
            final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
            ModuleRootMarker.mark(childResource);
            deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
            resourceRoot.addToAttachmentList(Attachments.INDEX_IGNORE_PATHS, child.getPathNameRelativeTo(deploymentRoot));
        }
    } catch (IOException e) {
        throw SarLogger.ROOT_LOGGER.failedToProcessSarChild(e, deploymentRoot);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) MountedDeploymentOverlay(org.jboss.as.server.deployment.MountedDeploymentOverlay) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) MountHandle(org.jboss.as.server.deployment.module.MountHandle) Closeable(java.io.Closeable) IOException(java.io.IOException) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

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