public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) { return; } final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT); final VirtualFile deploymentFile = deploymentRoot.getRoot(); final VirtualFile applicationXmlFile = deploymentFile.getChild(JBOSS_APP_XML); if (!applicationXmlFile.exists()) { return; } InputStream inputStream = null; try { inputStream = applicationXmlFile.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXmlResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream); final JBossAppMetaData appMetaData = JBossAppMetaDataParser.parse(xmlReader); if (appMetaData != null) { final EarMetaData earMetaData = deploymentUnit.getAttachment(Attachments.EAR_METADATA); if (earMetaData != null) { JBossAppMetaDataMerger.merge(appMetaData, null, earMetaData); } deploymentUnit.putAttachment(Attachments.JBOSS_APP_METADATA, appMetaData); } } catch (Exception e) { throw new DeploymentUnitProcessingException("Failed to parse " + applicationXmlFile, e); } finally { VFSUtils.safeClose(inputStream); } }
/** {@inheritDoc} */ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit); if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) { return; } final DeploymentUnit parent = deploymentUnit.getParent(); final DeploymentUnit topLevelDeployment = parent == null ? deploymentUnit : parent; final VirtualFile toplevelRoot = topLevelDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot(); final ExternalModuleService externalModuleService = topLevelDeployment.getAttachment(Attachments.EXTERNAL_MODULE_SERVICE); final Map<VirtualFile, ResourceRoot> files = new HashMap<VirtualFile, ResourceRoot>(); for (ResourceRoot resourceRoot : resourceRoots) { files.put(resourceRoot.getRoot(), resourceRoot); } final Deque<ResourceRoot> libResourceRoots = new ArrayDeque<ResourceRoot>(); // scan /lib entries for class-path items for (ResourceRoot resourceRoot : resourceRoots) { if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) { libResourceRoots.add(resourceRoot); } } while (!libResourceRoots.isEmpty()) { final ResourceRoot resourceRoot = libResourceRoots.pop(); final String[] items = getClassPathEntries(resourceRoot); for (String item : items) { final VirtualFile classPathFile = resourceRoot.getRoot().getParent().getChild(item); if (!classPathFile.exists()) { log.warnf("Class Path entry %s in %s not found. ", item, resourceRoot.getRoot()); } else if (isInside(classPathFile, toplevelRoot)) { if (!files.containsKey(classPathFile)) { log.warnf( "Class Path entry %s in %s does not point to a valid jar for a Class-Path reference.", item, resourceRoot.getRoot()); } else { final ResourceRoot target = files.get(classPathFile); if (SubDeploymentMarker.isSubDeployment(target)) { // for now we do not allow ear Class-Path references to subdeployments log.warnf( "Class Path entry in " + resourceRoot.getRoot() + " may not point to a sub deployment."); } else if (!ModuleRootMarker.isModuleRoot(target)) { // otherwise just add it to the lib dir ModuleRootMarker.mark(target); libResourceRoots.push(target); log.debugf( "Resource %s added to logical lib directory due to Class-Path entry in %s", classPathFile, target.getRoot()); } // otherwise it is already part of lib, so we leave it alone for now } } else if (item.startsWith("/")) { ModuleIdentifier moduleIdentifier = externalModuleService.addExternalModule(item); deploymentUnit.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, moduleIdentifier); log.debugf("Resource %s added as external jar %s", classPathFile, resourceRoot.getRoot()); } else { // this is a dep on another deployment deploymentUnit.addToAttachmentList( Attachments.CLASS_PATH_ENTRIES, ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + classPathFile.getName())); } } } }