@Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { // Check if we already have an OSGi deployment final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); Deployment deployment = OSGiDeploymentAttachment.getDeployment(deploymentUnit); ServiceRegistry serviceRegistry = phaseContext.getServiceRegistry(); String location = DeploymentHolderService.getLocation(serviceRegistry, deploymentUnit.getName()); VirtualFile virtualFile = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot(); // Check for attached BundleInfo BundleInfo info = BundleInfoAttachment.getBundleInfo(deploymentUnit); if (deployment == null && info != null) { deployment = DeploymentFactory.createDeployment(info); deployment.addAttachment(BundleInfo.class, info); OSGiDeploymentAttachment.attachDeployment(deploymentUnit, deployment); } // Check for attached OSGiMetaData OSGiMetaData metadata = OSGiMetaDataAttachment.getOSGiMetaData(deploymentUnit); if (deployment == null && metadata != null) { String symbolicName = metadata.getBundleSymbolicName(); Version version = metadata.getBundleVersion(); deployment = DeploymentFactory.createDeployment( AbstractVFS.adapt(virtualFile), location, symbolicName, version); deployment.addAttachment(OSGiMetaData.class, metadata); OSGiDeploymentAttachment.attachDeployment(deploymentUnit, deployment); } // Check for attached XModule XModule resModule = XModuleAttachment.getXModuleAttachment(deploymentUnit); if (deployment == null && resModule != null) { String symbolicName = resModule.getName(); Version version = resModule.getVersion(); deployment = DeploymentFactory.createDeployment( AbstractVFS.adapt(virtualFile), location, symbolicName, version); deployment.addAttachment(XModule.class, resModule); OSGiDeploymentAttachment.attachDeployment(deploymentUnit, deployment); } // Create the {@link OSGiDeploymentService} if (deployment != null) { // Prevent garbage collection of the MountHandle which will close the file MountHandle mount = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getMountHandle(); deployment.addAttachment(MountHandle.class, mount); // Mark the bundle to start automatically deployment.setAutoStart(true); OSGiDeploymentService.addService(phaseContext); } }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final CompositeIndex index = deploymentUnit.getAttachment( org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX); final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION); // @PersistenceContext List<AnnotationInstance> persistenceContexts = index.getAnnotations(PERSISTENCE_CONTEXT_ANNOTATION_NAME); // create binding and injection configurations out of the @PersistenceContext annotations this.processPersistenceAnnotations( deploymentUnit, eeModuleDescription, persistenceContexts, applicationClasses); // @PersistenceUnit List<AnnotationInstance> persistenceUnits = index.getAnnotations(PERSISTENCE_UNIT_ANNOTATION_NAME); // create binding and injection configurations out of the @PersistenceUnit annotaitons this.processPersistenceAnnotations( deploymentUnit, eeModuleDescription, persistenceUnits, applicationClasses); // if we found any @PersistenceContext or @PersistenceUnit annotations then mark this as a JPA // deployment if (!persistenceContexts.isEmpty() || !persistenceUnits.isEmpty()) { JPADeploymentMarker.mark(deploymentUnit); } }
@Before public void init() { when(phaseContext.getDeploymentUnit()).thenReturn(deploymentUnit); when(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_TYPE)).thenReturn(DeploymentType.WAR); WarMetaData metadata = mock(WarMetaData.class); when(deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY)).thenReturn(metadata); }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit du = phaseContext.getDeploymentUnit(); if (GateInConfiguration.isGateInArchive(du)) { log.info("Module is on GateIn Extension modules list"); final GateInConfiguration config = du.getAttachment(GateInConfigurationKey.KEY); final ServiceName initSvcName = GateInExtension.deploymentUnitName(config.getGateInEarModule(), "gatein", "init"); final ServiceTarget target = phaseContext.getServiceTarget(); if (du.getAttachment(GateInEarKey.KEY) != null) { // Install InitService with dependency on all the deployment modules reaching POST_MODULE // TODO: we are starting up InitService before child modules (jboss.deployment.subunit.*) // have gone through POST_MODULE final ServiceBuilder<InitService> builder = target .addService(initSvcName, new InitService(config)) .addDependency( GateInExtension.deploymentUnitName( config.getGateInEarModule(), Phase.POST_MODULE)); for (ModuleIdentifier module : config.getGateInExtModules()) { builder.addDependency(GateInExtension.deploymentUnitName(module, Phase.POST_MODULE)); } builder.install(); log.info("Installed " + initSvcName); } // all gatein deployment modules use InitService as barrier on POST_MODULE to ensure // they are all available on the classpath when init time resource loading takes place phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, initSvcName); log.info("Added NEXT_PHASE_DEP on " + initSvcName); } }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); ClojureMetaData metaData = deploymentUnit.getAttachment(ClojureMetaData.ATTACHMENT_KEY); if (metaData == null) { return; } Timer t = new Timer("reading full app config"); ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); File root; File descriptor = deploymentUnit.getAttachment(ClojureMetaData.DESCRIPTOR_FILE); try { root = resourceRoot.getRoot().getPhysicalFile(); metaData.setConfig(ApplicationBootstrapUtils.readFullAppConfig(descriptor, root)); deploymentUnit.putAttachment( ClojureMetaData.FULL_APP_CONFIG, ApplicationBootstrapUtils.readFullAppConfigAsString(descriptor, root)); deploymentUnit.putAttachment( ClojureMetaData.LEIN_PROJECT, ApplicationBootstrapUtils.readProjectAsString(descriptor, root)); } catch (Exception e) { throw new DeploymentUnitProcessingException(e); } t.done(); }
@Override protected boolean canHandle(DeploymentUnit deploymentUnit) { if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) { return false; } final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY); if (warMetaData == null) { return false; // Nothing we can do without WarMetaData } final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT); if (deploymentRoot == null) { return false; // We don't have a root to work with } final DeploymentUnit parent = deploymentUnit.getParent(); if (parent == null || !DeploymentTypeMarker.isType(DeploymentType.EAR, parent)) { return false; // Only care if this war is nested in an EAR } final EarMetaData earMetaData = parent.getAttachment(Attachments.EAR_METADATA); if (earMetaData == null) { return false; // Nothing to see here } return true; }
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); } }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if (!KeycloakAdapterConfigService.getInstance().isSecureDeployment(deploymentUnit)) { WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY); if (warMetaData == null) { return; } JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData(); if (webMetaData == null) { return; } LoginConfigMetaData loginConfig = webMetaData.getLoginConfig(); if (loginConfig == null) return; if (loginConfig.getAuthMethod() == null) return; if (!loginConfig.getAuthMethod().equals("KEYCLOAK")) return; } final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final ModuleLoader moduleLoader = Module.getBootModuleLoader(); addCommonModules(moduleSpecification, moduleLoader); addPlatformSpecificModules(moduleSpecification, moduleLoader); }
private static void processWSFeatures( final DeploymentUnit unit, final Set<ResourceInjectionTargetMetaData> injectionTargets, final UnifiedServiceRefMetaData serviceRefUMDM) throws DeploymentUnitProcessingException { if (injectionTargets == null || injectionTargets.size() == 0) return; if (injectionTargets.size() > 1) { // TODO: We should validate all the injection targets whether they're compatible. // This means all the injection targets must be assignable or equivalent. // If there are @Addressing, @RespectBinding or @MTOM annotations present on injection // targets, // these annotations must be equivalent for all the injection targets. } final Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); final DeploymentReflectionIndex deploymentReflectionIndex = unit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX); final ResourceInjectionTargetMetaData injectionTarget = injectionTargets.iterator().next(); final String injectionTargetClassName = injectionTarget.getInjectionTargetClass(); final String injectionTargetName = injectionTarget.getInjectionTargetName(); final AccessibleObject fieldOrMethod = getInjectionTarget( injectionTargetClassName, injectionTargetName, module.getClassLoader(), deploymentReflectionIndex); processAnnotatedElement(fieldOrMethod, serviceRefUMDM); }
@Override protected void processDeployment( final DeploymentPhaseContext phaseContext, final DeploymentUnit deploymentUnit, final ResourceRoot root) throws DeploymentUnitProcessingException { final List<DeploymentUnit> subDeployments = getSubDeployments(deploymentUnit); final String loggingProfile = findLoggingProfile(root); if (loggingProfile != null) { // Get the profile logging context final LoggingProfileContextSelector loggingProfileContext = LoggingProfileContextSelector.getInstance(); if (loggingProfileContext.exists(loggingProfile)) { // Get the module final Module module = deploymentUnit.getAttachment(Attachments.MODULE); final LogContext logContext = loggingProfileContext.get(loggingProfile); LoggingLogger.ROOT_LOGGER.tracef( "Registering log context '%s' on '%s' for profile '%s'", logContext, root, loggingProfile); registerLogContext(deploymentUnit, module, logContext); // Process sub-deployments for (DeploymentUnit subDeployment : subDeployments) { // A sub-deployment must have a module to process if (subDeployment.hasAttachment(Attachments.MODULE)) { // Set the result to true if a logging profile was found if (subDeployment.hasAttachment(Attachments.DEPLOYMENT_ROOT)) { processDeployment( phaseContext, subDeployment, subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT)); } if (!hasRegisteredLogContext(subDeployment)) { final Module subDeploymentModule = subDeployment.getAttachment(Attachments.MODULE); LoggingLogger.ROOT_LOGGER.tracef( "Registering log context '%s' on '%s' for profile '%s'", logContext, subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT), loggingProfile); registerLogContext(subDeployment, subDeploymentModule, logContext); } } } } else { LoggingLogger.ROOT_LOGGER.loggingProfileNotFound(loggingProfile, root); } } else { // No logging profile found, but the sub-deployments should be checked for logging profiles for (DeploymentUnit subDeployment : subDeployments) { // A sub-deployment must have a root resource and a module to process if (subDeployment.hasAttachment(Attachments.MODULE) && subDeployment.hasAttachment(Attachments.DEPLOYMENT_ROOT)) { processDeployment( phaseContext, subDeployment, subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT)); } } } }
/** * Check the deployment annotation index for all classes with the @ManagedBean annotation. For * each class with the annotation, collect all the required information to create a managed bean * instance, and attach it to the context. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); final String applicationName = moduleDescription.getAppName(); final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); if (compositeIndex == null) { return; } final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME); if (instances == null || instances.isEmpty()) { return; } for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); if (!(target instanceof ClassInfo)) { throw new DeploymentUnitProcessingException( "The ManagedBean annotation is only allowed at the class level: " + target); } final ClassInfo classInfo = (ClassInfo) target; final String beanClassName = classInfo.name().toString(); // Get the managed bean name from the annotation final AnnotationValue nameValue = instance.value(); final String beanName = nameValue == null || nameValue.asString().isEmpty() ? beanClassName : nameValue.asString(); final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription( beanName, beanClassName, moduleDescription.getModuleName(), applicationName); final ServiceName baseName = deploymentUnit.getServiceName().append("component").append(beanName); // Add the view componentDescription.getViewClassNames().add(beanClassName); // Bind the view to its two JNDI locations // TODO - this should be a bit more elegant final BindingDescription moduleBinding = new BindingDescription(); moduleBinding.setAbsoluteBinding(true); moduleBinding.setBindingName("java:module/" + beanName); moduleBinding.setBindingType(beanClassName); moduleBinding.setReferenceSourceDescription( new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName))); componentDescription.getBindings().add(moduleBinding); final BindingDescription appBinding = new BindingDescription(); appBinding.setAbsoluteBinding(true); appBinding.setBindingName("java:app/" + moduleDescription.getModuleName() + "/" + beanName); appBinding.setBindingType(beanClassName); appBinding.setReferenceSourceDescription( new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName))); componentDescription.getBindings().add(appBinding); moduleDescription.addComponent(componentDescription); } }
@Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); if (eeModuleDescription == null) { return; } final Collection<ComponentDescription> componentConfigurations = eeModuleDescription.getComponentDescriptions(); final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX); final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION); for (ComponentDescription componentConfiguration : componentConfigurations) { if (componentConfiguration instanceof SessionBeanComponentDescription) { try { processComponentConfig( deploymentUnit, applicationClasses, module, deploymentReflectionIndex, (SessionBeanComponentDescription) componentConfiguration); } catch (Exception e) { throw MESSAGES.failToMergeData(componentConfiguration.getComponentName(), e); } } } if (appclient) { for (ComponentDescription componentDescription : deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) { if (componentDescription instanceof SessionBeanComponentDescription) { try { processComponentConfig( deploymentUnit, applicationClasses, module, deploymentReflectionIndex, (SessionBeanComponentDescription) componentDescription); } catch (Exception e) { throw MESSAGES.failToMergeData(componentDescription.getComponentName(), e); } } } } }
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY); if (warMetaData == null) { return; // Nothing we can do without WarMetaData } final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT); if (deploymentRoot == null) { return; // We don't have a root to work with } final DeploymentUnit parent = deploymentUnit.getParent(); if (parent == null || !DeploymentTypeMarker.isType(DeploymentType.EAR, parent)) { return; // Only care if this war is nested in an EAR } final EarMetaData earMetaData = parent.getAttachment(Attachments.EAR_METADATA); if (earMetaData == null) { return; // Nothing to see here } final ModulesMetaData modulesMetaData = earMetaData.getModules(); if (modulesMetaData != null) for (ModuleMetaData moduleMetaData : modulesMetaData) { if (Web.equals(moduleMetaData.getType()) && moduleMetaData.getFileName().equals(deploymentRoot.getRootName())) { String contextRoot = WebModuleMetaData.class.cast(moduleMetaData.getValue()).getContextRoot(); if (contextRoot == null && (warMetaData.getJbossWebMetaData() == null || warMetaData.getJbossWebMetaData().getContextRoot() == null)) { contextRoot = "/" + parent.getName().substring(0, parent.getName().length() - 4) + "/" + deploymentUnit.getName().substring(0, deploymentUnit.getName().length() - 4); } if (contextRoot != null) { JBossWebMetaData jBossWebMetaData = warMetaData.getJbossWebMetaData(); if (jBossWebMetaData == null) { jBossWebMetaData = new JBoss70WebMetaData(); warMetaData.setJbossWebMetaData(jBossWebMetaData); } jBossWebMetaData.setContextRoot(contextRoot); } return; } } }
/** {@inheritDoc} */ @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final Module module = deploymentUnit.getAttachment(Attachments.MODULE); final ServicesAttachment servicesAttachment = deploymentUnit.getAttachment(Attachments.SERVICES); if (module != null && servicesAttachment != null) { final ModuleClassLoader classLoader = module.getClassLoader(); final List<String> driverNames = servicesAttachment.getServiceImplementations(Driver.class.getName()); for (String driverClassName : driverNames) { try { final Class<? extends Driver> driverClass = classLoader.loadClass(driverClassName).asSubclass(Driver.class); final Constructor<? extends Driver> constructor = driverClass.getConstructor(); final Driver driver = constructor.newInstance(); final int majorVersion = driver.getMajorVersion(); final int minorVersion = driver.getMinorVersion(); final boolean compliant = driver.jdbcCompliant(); if (compliant) { log.infof( "Deploying JDBC-compliant driver %s (version %d.%d)", driverClass, Integer.valueOf(majorVersion), Integer.valueOf(minorVersion)); } else { log.infof( "Deploying non-JDBC-compliant driver %s (version %d.%d)", driverClass, Integer.valueOf(majorVersion), Integer.valueOf(minorVersion)); } String driverName = deploymentUnit.getName(); InstalledDriver driverMetadata = new InstalledDriver( driverName, driverClass.getName(), null, majorVersion, minorVersion, compliant); DriverService driverService = new DriverService(driverMetadata, driver); phaseContext .getServiceTarget() .addService( ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll(".", "_")), driverService) .addDependency( ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, driverService.getDriverRegistryServiceInjector()) .setInitialMode(Mode.ACTIVE) .install(); } catch (Exception e) { log.warnf("Unable to instantiate driver class \"%s\": %s", driverClassName, e); } } } }
private Set<ViewDescription> getViews(final DeploymentPhaseContext phaseContext) { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEApplicationDescription applicationDescription = deploymentUnit.getAttachment(EE_APPLICATION_DESCRIPTION); final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); final Set<ViewDescription> componentsForViewName; if (beanName != null) { componentsForViewName = applicationDescription.getComponents(beanName, typeName, deploymentRoot.getRoot()); } else { componentsForViewName = applicationDescription.getComponentsForViewName(typeName); } return componentsForViewName; }
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final Map<Class<? extends Annotation>, Set<Class<?>>> instances = new HashMap<Class<? extends Annotation>, Set<Class<?>>>(); final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); if (compositeIndex == null) { return; // Can not continue without index } final Module module = deploymentUnit.getAttachment(Attachments.MODULE); if (module == null) { return; // Can not continue without module } final ClassLoader classLoader = module.getClassLoader(); for (FacesAnnotation annotation : FacesAnnotation.values()) { final List<AnnotationInstance> annotationInstances = compositeIndex.getAnnotations(annotation.indexName); if (annotationInstances == null || annotationInstances.isEmpty()) { continue; } final Set<Class<?>> discoveredClasses = new HashSet<Class<?>>(); instances.put(annotation.annotationClass, discoveredClasses); for (AnnotationInstance annotationInstance : annotationInstances) { final AnnotationTarget target = annotationInstance.target(); if (target instanceof ClassInfo) { final DotName className = ClassInfo.class.cast(target).name(); final Class<?> annotatedClass; try { annotatedClass = classLoader.loadClass(className.toString()); } catch (ClassNotFoundException e) { throw new DeploymentUnitProcessingException( JSFMessages.MESSAGES.classLoadingFailed(className)); } discoveredClasses.add(annotatedClass); } else { throw new DeploymentUnitProcessingException( JSFMessages.MESSAGES.invalidAnnotationLocation(annotation, target)); } } } deploymentUnit.addToAttachmentList( ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances)); }
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final String deploymentUnitName = deploymentUnit.getName(); final String moduleName; if (deploymentUnitName.endsWith(".war") || deploymentUnitName.endsWith(".wab") || deploymentUnitName.endsWith(".jar") || deploymentUnitName.endsWith(".ear") || deploymentUnitName.endsWith(".rar")) { moduleName = deploymentUnitName.substring(0, deploymentUnitName.length() - 4); } else { moduleName = deploymentUnitName; } final String appName; final String earApplicationName = deploymentUnit.getAttachment(Attachments.EAR_APPLICATION_NAME); // the ear application name takes into account the name set in application.xml // if this is non-null this is always the one we want to use if (earApplicationName != null) { appName = earApplicationName; } else { // an appname of null means use the module name appName = null; } deploymentUnit.putAttachment( Attachments.EE_MODULE_DESCRIPTION, new EEModuleDescription(appName, moduleName, earApplicationName, appClient)); }
@Override public Set<String> getUpdatedResources( final String deploymentName, final Map<String, Long> updatedResources) { final ModuleIdentifier moduleId = getModuleIdentifier(deploymentName); final ModuleClassLoader loader = loadersByModuleIdentifier.get(moduleId); if (loader == null) { return Collections.emptySet(); } final DeploymentUnit deploymentUnit = (DeploymentUnit) CurrentServiceRegistry.getServiceRegistry() .getRequiredService(Services.deploymentUnitName(deploymentName)) .getValue(); final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); final Set<String> resources = new HashSet<String>(); for (final Map.Entry<String, Long> entry : updatedResources.entrySet()) { final VirtualFile file = root.getRoot().getChild(entry.getKey()); if (file.exists()) { long last = file.getLastModified(); if (entry.getValue() > last) { resources.add(entry.getKey()); } } } return resources; }
@Override public void updateResource( final String archiveName, final Map<String, byte[]> replacedResources) { final ModuleIdentifier moduleId = getModuleIdentifier(archiveName); final ModuleClassLoader loader = loadersByModuleIdentifier.get(moduleId); if (loader == null) { return; } final DeploymentUnit deploymentUnit = (DeploymentUnit) CurrentServiceRegistry.getServiceRegistry() .getRequiredService(Services.deploymentUnitName(archiveName)) .getValue(); final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); for (final Map.Entry<String, byte[]> entry : replacedResources.entrySet()) { final VirtualFile file = root.getRoot().getChild(entry.getKey()); try { final FileOutputStream stream = new FileOutputStream(file.getPhysicalFile(), false); try { stream.write(entry.getValue()); } finally { stream.close(); } } catch (IOException e) { e.printStackTrace(); } } }
protected VirtualFile getFile(DeploymentUnit unit) throws DeploymentUnitProcessingException, IOException { List<VirtualFile> matches = new ArrayList<VirtualFile>(); ResourceRoot resourceRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT); if (resourceRoot == null) { return null; } VirtualFile root = resourceRoot.getRoot(); if (this.knobFilter.accepts(root)) { return root; } matches = root.getChildren(this.knobFilter); if (matches.size() > 1) { throw new DeploymentUnitProcessingException("Multiple Immutant descriptors found in " + root); } VirtualFile file = null; if (matches.size() == 1) { file = matches.get(0); } return file; }
/** * Gets list of JAXWS POJOs meta data. * * @param unit deployment unit * @return list of JAXWS POJOs meta data */ public static List<POJOEndpoint> getJaxwsPojos(final DeploymentUnit unit) { final JAXWSDeployment jaxwsDeployment = unit.getAttachment(WSAttachmentKeys.JAXWS_ENDPOINTS_KEY); return jaxwsDeployment != null ? jaxwsDeployment.getPojoEndpoints() : Collections.<POJOEndpoint>emptyList(); }
public static String pathNameOfDeployment( final DeploymentUnit deploymentUnit, final JBossWebMetaData metaData) { String pathName; if (metaData.getContextRoot() == null) { final EEModuleDescription description = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); if (description != null) { // if there is a EEModuleDescription we need to take into account that the module name // may have been overridden pathName = "/" + description.getModuleName(); } else { pathName = "/" + deploymentUnit.getName().substring(0, deploymentUnit.getName().length() - 4); } } else { pathName = metaData.getContextRoot(); if ("/".equals(pathName)) { pathName = ""; } else if (pathName.length() > 0 && pathName.charAt(0) != '/') { pathName = "/" + pathName; } } return pathName; }
private HashMap<String, TagLibraryInfo> createTldsInfo( final DeploymentUnit deploymentUnit, final DeploymentClassIndex classReflectionIndex, final ComponentRegistry components, final DeploymentInfo d) throws ClassNotFoundException { TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY); final HashMap<String, TagLibraryInfo> ret = new HashMap<>(); if (tldsMetaData != null) { if (tldsMetaData.getTlds() != null) { for (Map.Entry<String, TldMetaData> tld : tldsMetaData.getTlds().entrySet()) { createTldInfo(tld.getKey(), tld.getValue(), ret, classReflectionIndex, components, d); } } List<TldMetaData> sharedTlds = tldsMetaData.getSharedTlds(deploymentUnit); if (sharedTlds != null) { for (TldMetaData metaData : sharedTlds) { createTldInfo(null, metaData, ret, classReflectionIndex, components, d); } } } return ret; }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); if (moduleDescription == null) { return; } final ServiceTarget serviceTarget = phaseContext.getServiceTarget(); // if this is a war we need to bind to the modules comp namespace if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit) || DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit)) { final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule( moduleDescription.getApplicationName(), moduleDescription.getModuleName()); bindServices(deploymentUnit, serviceTarget, moduleContextServiceName); } for (ComponentDescription component : moduleDescription.getComponentDescriptions()) { if (component.getNamingMode() == ComponentNamingMode.CREATE) { final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent( moduleDescription.getApplicationName(), moduleDescription.getModuleName(), component.getComponentName()); bindServices(deploymentUnit, serviceTarget, compContextServiceName); } } }
public static WSReferences getWSRefRegistry(final DeploymentUnit unit) { WSReferences refRegistry = unit.getAttachment(WSAttachmentKeys.WS_REFERENCES); if (refRegistry == null) { refRegistry = WSReferences.newInstance(); unit.putAttachment(WSAttachmentKeys.WS_REFERENCES, refRegistry); } return refRegistry; }
/** * Returns required attachment value from deployment unit. * * @param <A> expected value * @param unit deployment unit * @param key attachment key * @return required attachment * @throws IllegalStateException if attachment value is null */ public static <A> A getRequiredAttachment(final DeploymentUnit unit, final AttachmentKey<A> key) { final A value = unit.getAttachment(key); if (value == null) { throw new IllegalStateException(); } return value; }
public static JAXWSDeployment getJaxwsDeployment(final DeploymentUnit unit) { JAXWSDeployment wsDeployment = unit.getAttachment(JAXWS_ENDPOINTS_KEY); if (wsDeployment == null) { wsDeployment = new JAXWSDeployment(); unit.putAttachment(JAXWS_ENDPOINTS_KEY, wsDeployment); } return wsDeployment; }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if (!JaxrsDeploymentMarker.isJaxrsDeployment(deploymentUnit)) { return; } final DeploymentUnit parent = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent(); final Map<ModuleIdentifier, ResteasyDeploymentData> deploymentData; if (deploymentUnit.getParent() == null) { deploymentData = Collections.synchronizedMap(new HashMap<ModuleIdentifier, ResteasyDeploymentData>()); deploymentUnit.putAttachment( JaxrsAttachments.ADDITIONAL_RESTEASY_DEPLOYMENT_DATA, deploymentData); } else { deploymentData = parent.getAttachment(JaxrsAttachments.ADDITIONAL_RESTEASY_DEPLOYMENT_DATA); } final ModuleIdentifier moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER); ResteasyDeploymentData resteasyDeploymentData = new ResteasyDeploymentData(); final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY); final Module module = deploymentUnit.getAttachment(Attachments.MODULE); try { if (warMetaData == null) { resteasyDeploymentData.setScanAll(true); scan(deploymentUnit, module.getClassLoader(), resteasyDeploymentData); deploymentData.put(moduleIdentifier, resteasyDeploymentData); } else { scanWebDeployment( deploymentUnit, warMetaData.getMergedJBossWebMetaData(), module.getClassLoader(), resteasyDeploymentData); scan(deploymentUnit, module.getClassLoader(), resteasyDeploymentData); } deploymentUnit.putAttachment( JaxrsAttachments.RESTEASY_DEPLOYMENT_DATA, resteasyDeploymentData); } catch (ModuleLoadException e) { throw new DeploymentUnitProcessingException(e); } }
@Override public void deploy(DeploymentPhaseContext context) { DeploymentUnit unit = context.getDeploymentUnit(); final ServiceName name = unit.getServiceName(); EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); if (moduleDescription == null) { return; } final ServiceTarget target = context.getServiceTarget(); @SuppressWarnings("rawtypes") final InjectedValue<CacheFactoryBuilderRegistry> registry = new InjectedValue<>(); Service<Void> service = new AbstractService<Void>() { @Override public void start(StartContext context) { // Install dependencies for each registered cache factory builder Collection<CacheFactoryBuilder<?, ?>> builders = registry.getValue().getBuilders(); for (CacheFactoryBuilder<?, ?> builder : builders) { builder.installDeploymentUnitDependencies(target, name); } } }; target .addService(name.append("cache-dependencies-installer"), service) .addDependency( CacheFactoryBuilderRegistryService.SERVICE_NAME, CacheFactoryBuilderRegistry.class, registry) .install(); // Install versioned marshalling configuration InjectedValue<ModuleDeployment> deployment = new InjectedValue<>(); Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); Value<ModuleLoader> moduleLoader = new ImmediateValue<>(module.getModuleLoader()); target .addService( VersionedMarshallingConfigurationService.getServiceName(name), new VersionedMarshallingConfigurationService(deployment, moduleLoader)) .addDependency( name.append(ModuleDeployment.SERVICE_NAME), ModuleDeployment.class, deployment) .setInitialMode(ServiceController.Mode.ON_DEMAND) .install(); }
/** * Returns required attachment value from deployment unit. * * @param <A> expected value * @param unit deployment unit * @param key attachment key * @return required attachment * @throws IllegalStateException if attachment value is null */ public static <A> A getRequiredAttachment(final DeploymentUnit unit, final AttachmentKey<A> key) { final A value = unit.getAttachment(key); if (value == null) { ASHelper.LOGGER.error("Cannot find attachment in deployment unit: " + key); throw new IllegalStateException(); } return value; }