Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.server.deployment;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jboss.as.server.ServerLogger;
import org.jboss.as.server.ServerMessages;
import org.jboss.as.server.deployment.module.FilterSpecification;
import org.jboss.as.server.deployment.module.MountHandle;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.as.server.deployment.module.TempFileProviderService;
import org.jboss.as.server.deploymentoverlay.service.ContentService;
import org.jboss.as.server.deploymentoverlay.service.DeploymentOverlayIndexService;
import org.jboss.as.server.deploymentoverlay.service.DeploymentOverlayService;
import org.jboss.vfs.VFS;
import org.jboss.vfs.VirtualFile;
/**
* Deployment unit processor that adds content overrides to the VFS filesystem
*
* @author Stuart Douglas
*/
public class ContentOverrideDeploymentUnitProcessor implements DeploymentUnitProcessor {
private final DeploymentOverlayIndexService indexService;
private static final AttachmentKey> MOUNTED_FILES = AttachmentKey.createList(Closeable.class);
public ContentOverrideDeploymentUnitProcessor(final DeploymentOverlayIndexService indexService) {
this.indexService = indexService;
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
//resource roots require special handling
final Map resourceRootMap = new HashMap();
final AttachmentList rootList = deploymentUnit.getAttachment(Attachments.RESOURCE_ROOTS);
if (rootList != null) {
for (ResourceRoot root : rootList) {
resourceRootMap.put(root.getRoot().getPathNameRelativeTo(deploymentRoot.getRoot()), root);
}
}
//exploded is true if this is a zip deployment that has been mounted exploded
final boolean exploded = MountExplodedMarker.isMountExploded(deploymentUnit) && !ExplodedDeploymentMarker.isExplodedDeployment(deploymentUnit);
final Set paths = new HashSet();
for (final DeploymentOverlayService deploymentOverlay : indexService.getOverrides(deploymentUnit.getName())) {
for (final ContentService override : deploymentOverlay.getContentServices()) {
try {
if (!paths.contains(override.getPath())) {
VirtualFile mountPoint = deploymentRoot.getRoot().getChild(override.getPath());
if (resourceRootMap.containsKey(override.getPath())) {
ResourceRoot existingRoot = resourceRootMap.get(override.getPath());
//unmount the existing root
close(existingRoot.getMountHandle());
//and remove it from the root list
if(rootList != null) {
rootList.remove(existingRoot);
}
//mount our override
Closeable handle = VFS.mountZip(override.getContentHash(), mountPoint, TempFileProviderService.provider());
deploymentUnit.addToAttachmentList(MOUNTED_FILES, handle);
//now recreate the root
ResourceRoot newRoot = new ResourceRoot(override.getContentHash().getName(), mountPoint, new MountHandle(handle));
for(AttachmentKey> key : existingRoot.attachmentKeys()) {
newRoot.putAttachment((AttachmentKey