this.deployment = deployment;
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (deploymentUnit.getName().toLowerCase(Locale.ENGLISH).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 MESSAGES.cannotFindAppClient(deployment);
}
} else if (deploymentUnit.getParent() != null && deploymentUnit.getName().toLowerCase(Locale.ENGLISH).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);
}
}