Search in sources :

Example 1 with MountedDeploymentOverlay

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

the class EarStructureProcessor 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 = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile virtualFile = deploymentRoot.getRoot();
    // Make sure we don't index or add this as a module root
    deploymentRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
    ModuleRootMarker.mark(deploymentRoot, false);
    String libDirName = DEFAULT_LIB_DIR;
    // its possible that the ear metadata could come for jboss-app.xml
    final boolean appXmlPresent = deploymentRoot.getRoot().getChild("META-INF/application.xml").exists();
    final EarMetaData earMetaData = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
    if (earMetaData != null) {
        final String xmlLibDirName = earMetaData.getLibraryDirectory();
        if (xmlLibDirName != null) {
            if (xmlLibDirName.length() == 1 && xmlLibDirName.charAt(0) == '/') {
                throw EeLogger.ROOT_LOGGER.rootAsLibraryDirectory();
            }
            libDirName = xmlLibDirName;
        }
    }
    // Process all the children
    Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
    try {
        final VirtualFile libDir;
        // process the lib directory
        if (!libDirName.isEmpty()) {
            libDir = virtualFile.getChild(libDirName);
            if (libDir.exists()) {
                List<VirtualFile> libArchives = libDir.getChildren(CHILD_ARCHIVE_FILTER);
                for (final VirtualFile child : libArchives) {
                    String relativeName = child.getPathNameRelativeTo(deploymentRoot.getRoot());
                    MountedDeploymentOverlay overlay = overlays.get(relativeName);
                    final MountHandle mountHandle;
                    if (overlay != null) {
                        overlay.remountAsZip(false);
                        mountHandle = new MountHandle(null);
                    } else {
                        final Closeable closable = child.isFile() ? mount(child, false) : null;
                        mountHandle = new MountHandle(closable);
                    }
                    final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
                    if (child.getName().toLowerCase(Locale.ENGLISH).endsWith(JAR_EXTENSION)) {
                        ModuleRootMarker.mark(childResource);
                        deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
                    }
                }
            }
        } else {
            libDir = null;
        }
        // scan the ear looking for wars and jars
        final List<VirtualFile> childArchives = new ArrayList<VirtualFile>(virtualFile.getChildren(new SuffixMatchFilter(CHILD_ARCHIVE_EXTENSIONS, new VisitorAttributes() {

            @Override
            public boolean isLeavesOnly() {
                return false;
            }

            @Override
            public boolean isRecurse(VirtualFile file) {
                // don't recurse into /lib
                if (file.equals(libDir)) {
                    return false;
                }
                for (String suffix : CHILD_ARCHIVE_EXTENSIONS) {
                    if (file.getName().endsWith(suffix)) {
                        // don't recurse into sub deployments
                        return false;
                    }
                }
                return true;
            }
        })));
        // if there is no application.xml then look in the ear root for modules
        if (!appXmlPresent) {
            for (final VirtualFile child : childArchives) {
                final boolean isWarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(WAR_EXTENSION);
                final boolean isRarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(RAR_EXTENSION);
                this.createResourceRoot(deploymentUnit, child, isWarFile || isRarFile, isWarFile);
            }
        } else {
            final Set<VirtualFile> subDeploymentFiles = new HashSet<VirtualFile>();
            // otherwise read from application.xml
            for (final ModuleMetaData module : earMetaData.getModules()) {
                if (module.getFileName().endsWith(".xml")) {
                    throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
                }
                final VirtualFile moduleFile = virtualFile.getChild(module.getFileName());
                if (!moduleFile.exists()) {
                    throw EeLogger.ROOT_LOGGER.cannotProcessEarModule(virtualFile, module.getFileName());
                }
                if (libDir != null) {
                    VirtualFile moduleParentFile = moduleFile.getParent();
                    if (moduleParentFile != null && libDir.equals(moduleParentFile)) {
                        throw EeLogger.ROOT_LOGGER.earModuleChildOfLibraryDirectory(libDirName, module.getFileName());
                    }
                }
                // maintain this in a collection of subdeployment virtual files, to be used later
                subDeploymentFiles.add(moduleFile);
                final boolean webArchive = module.getType() == ModuleType.Web;
                final ResourceRoot childResource = this.createResourceRoot(deploymentUnit, moduleFile, true, webArchive);
                childResource.putAttachment(org.jboss.as.ee.structure.Attachments.MODULE_META_DATA, module);
                if (!webArchive) {
                    ModuleRootMarker.mark(childResource);
                }
                final String alternativeDD = module.getAlternativeDD();
                if (alternativeDD != null && alternativeDD.trim().length() > 0) {
                    final VirtualFile alternateDeploymentDescriptor = deploymentRoot.getRoot().getChild(alternativeDD);
                    if (!alternateDeploymentDescriptor.exists()) {
                        throw EeLogger.ROOT_LOGGER.alternateDeploymentDescriptor(alternateDeploymentDescriptor, moduleFile);
                    }
                    switch(module.getType()) {
                        case Client:
                            childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
                            break;
                        case Connector:
                            childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CONNECTOR_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
                            break;
                        case Ejb:
                            childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
                            break;
                        case Web:
                            childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_WEB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
                            break;
                        case Service:
                            throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
                    }
                }
            }
            // now check the rest of the archive for any other jar/sar files
            for (final VirtualFile child : childArchives) {
                if (subDeploymentFiles.contains(child)) {
                    continue;
                }
                final String fileName = child.getName().toLowerCase(Locale.ENGLISH);
                if (fileName.endsWith(SAR_EXTENSION) || fileName.endsWith(JAR_EXTENSION)) {
                    this.createResourceRoot(deploymentUnit, child, false, false);
                }
            }
        }
    } catch (IOException e) {
        throw EeLogger.ROOT_LOGGER.failedToProcessChild(e, virtualFile);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) MountedDeploymentOverlay(org.jboss.as.server.deployment.MountedDeploymentOverlay) MountHandle(org.jboss.as.server.deployment.module.MountHandle) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VisitorAttributes(org.jboss.vfs.VisitorAttributes) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet) ModuleMetaData(org.jboss.metadata.ear.spec.ModuleMetaData)

Example 2 with MountedDeploymentOverlay

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

the class RaStructureProcessor method deploy.

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(RAR_EXTENSION)) {
        return;
    }
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    moduleSpecification.setPublicModule(true);
    // this violates the spec, but everyone expects it to work
    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 ConnectorLogger.ROOT_LOGGER.failedToProcessRaChild(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) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) Closeable(java.io.Closeable) IOException(java.io.IOException) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 3 with MountedDeploymentOverlay

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

the class WarStructureDeploymentProcessor method createResourceRoots.

/**
 * Create the resource roots for a .war deployment
 *
 * @param deploymentRoot the deployment root
 * @return the resource roots
 * @throws java.io.IOException for any error
 */
private List<ResourceRoot> createResourceRoots(final VirtualFile deploymentRoot, final DeploymentUnit deploymentUnit) throws IOException, DeploymentUnitProcessingException {
    final List<ResourceRoot> entries = new ArrayList<ResourceRoot>();
    // WEB-INF classes
    final VirtualFile webinfClasses = deploymentRoot.getChild(WEB_INF_CLASSES);
    if (webinfClasses.exists()) {
        final ResourceRoot webInfClassesRoot = new ResourceRoot(webinfClasses.getName(), webinfClasses, null);
        ModuleRootMarker.mark(webInfClassesRoot);
        entries.add(webInfClassesRoot);
    }
    // WEB-INF lib
    Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
    final VirtualFile webinfLib = deploymentRoot.getChild(WEB_INF_LIB);
    if (webinfLib.exists()) {
        final List<VirtualFile> archives = webinfLib.getChildren(DEFAULT_WEB_INF_LIB_FILTER);
        for (final VirtualFile archive : archives) {
            try {
                String relativeName = archive.getPathNameRelativeTo(deploymentRoot);
                MountedDeploymentOverlay overlay = overlays.get(relativeName);
                Closeable closable = null;
                if (overlay != null) {
                    overlay.remountAsZip(false);
                } else if (archive.isFile()) {
                    closable = VFS.mountZip(archive, archive, TempFileProviderService.provider());
                } else {
                    closable = null;
                }
                final ResourceRoot webInfArchiveRoot = new ResourceRoot(archive.getName(), archive, new MountHandle(closable));
                ModuleRootMarker.mark(webInfArchiveRoot);
                entries.add(webInfArchiveRoot);
            } catch (IOException e) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToProcessWebInfLib(archive), e);
            }
        }
    }
    return entries;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) MountedDeploymentOverlay(org.jboss.as.server.deployment.MountedDeploymentOverlay) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) MountHandle(org.jboss.as.server.deployment.module.MountHandle) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 4 with MountedDeploymentOverlay

use of org.jboss.as.server.deployment.MountedDeploymentOverlay 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

Closeable (java.io.Closeable)4 IOException (java.io.IOException)4 MountedDeploymentOverlay (org.jboss.as.server.deployment.MountedDeploymentOverlay)4 MountHandle (org.jboss.as.server.deployment.module.MountHandle)4 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)4 VirtualFile (org.jboss.vfs.VirtualFile)4 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)1 EarMetaData (org.jboss.metadata.ear.spec.EarMetaData)1 ModuleMetaData (org.jboss.metadata.ear.spec.ModuleMetaData)1 VisitorAttributes (org.jboss.vfs.VisitorAttributes)1 SuffixMatchFilter (org.jboss.vfs.util.SuffixMatchFilter)1