@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 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);
      }
    }
  }
  /**
   * Add a ContextService for this module.
   *
   * @param phaseContext the deployment unit context
   * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
   */
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (isEarDeployment(deploymentUnit)) {
      return;
    }
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();

    final ServiceName moduleContextServiceName = ContextServiceNameBuilder.module(deploymentUnit);
    final RootContextService contextService = new RootContextService();
    serviceTarget.addService(moduleContextServiceName, contextService).install();

    final BinderService<String> moduleNameBinder =
        new BinderService<String>(
            "ModuleName", Values.immediateValue(getModuleName(deploymentUnit)));
    serviceTarget
        .addService(moduleContextServiceName.append("ModuleName"), moduleNameBinder)
        .addDependency(
            moduleContextServiceName, Context.class, moduleNameBinder.getContextInjector())
        .install();

    final ContextService envContextService = new ContextService("env");
    serviceTarget
        .addService(moduleContextServiceName.append("env"), envContextService)
        .addDependency(
            moduleContextServiceName, Context.class, envContextService.getParentContextInjector())
        .install();

    phaseContext
        .getDeploymentUnit()
        .putAttachment(
            Attachments.MODULE_CONTEXT_CONFIG, new NamingContextConfig(moduleContextServiceName));
  }
  @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(final DeploymentPhaseContext phaseContext)
     throws DeploymentUnitProcessingException {
   final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
   final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
   if (warMetaData == null) {
     return;
   }
   String hostName = hostNameOfDeployment(warMetaData, defaultHost);
   processDeployment(warMetaData, deploymentUnit, phaseContext.getServiceTarget(), hostName);
 }
  /** {@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);
        }
      }
    }
  }
  @Override
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription =
        deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);

    final DeploymentReflectionIndex deploymentReflectionIndex =
        deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);

    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    Boolean activate = deploymentUnit.getAttachment(AppClientAttachments.START_APP_CLIENT);
    if (activate == null || !activate) {
      return;
    }
    final Class<?> mainClass = deploymentUnit.getAttachment(AppClientAttachments.MAIN_CLASS);
    if (mainClass == null) {
      throw MESSAGES.cannotStartAppClient(deploymentUnit.getName());
    }
    final ApplicationClientComponentDescription component =
        deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_COMPONENT);

    ClassReflectionIndex<?> index = deploymentReflectionIndex.getClassIndex(mainClass);
    Method method = index.getMethod(void.class, "main", String[].class);
    if (method == null) {
      throw MESSAGES.cannotStartAppClient(deploymentUnit.getName(), mainClass);
    }
    final ApplicationClientStartService startService =
        new ApplicationClientStartService(
            method,
            parameters,
            hostUrl,
            moduleDescription.getNamespaceContextSelector(),
            module.getClassLoader());
    phaseContext
        .getServiceTarget()
        .addService(
            deploymentUnit.getServiceName().append(ApplicationClientStartService.SERVICE_NAME),
            startService)
        .addDependency(
            ApplicationClientDeploymentService.SERVICE_NAME,
            ApplicationClientDeploymentService.class,
            startService.getApplicationClientDeploymentServiceInjectedValue())
        .addDependency(
            component.getCreateServiceName(),
            Component.class,
            startService.getApplicationClientComponent())
        .install();
  }
 @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 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);
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    final CompositeIndex index =
        deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);

    for (final JaxrsAnnotations annotation : JaxrsAnnotations.values()) {
      if (!index.getAnnotations(annotation.getDotName()).isEmpty()) {
        JaxrsDeploymentMarker.mark(deploymentUnit);
        phaseContext.addToAttachmentList(
            Attachments.NEXT_PHASE_DEPS, Services.JBOSS_MODULE_INDEX_SERVICE);
        return;
      }
    }
  }
  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);
    }
  }
 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 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);
    }
  }
 @Override
 public void deploy(final DeploymentPhaseContext phaseContext)
     throws DeploymentUnitProcessingException {
   final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
   if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
     if (deploymentUnit.getParent() == null) {
       deploymentUnit.putAttachment(AppClientAttachments.START_APP_CLIENT, true);
     }
     return;
   }
   final List<DeploymentUnit> appClients = new ArrayList<DeploymentUnit>();
   for (DeploymentUnit subDeployment :
       deploymentUnit.getAttachmentList(
           org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS)) {
     if (DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, subDeployment)) {
       if (deploymentName != null && deploymentName.equals(subDeployment.getName())) {
         subDeployment.putAttachment(AppClientAttachments.START_APP_CLIENT, true);
         return;
       }
       appClients.add(subDeployment);
     }
   }
   if (deploymentName != null && !deploymentName.isEmpty()) {
     throw AppClientLogger.ROOT_LOGGER.cannotFindAppClient(deploymentName);
   }
   if (appClients.size() == 1) {
     appClients.get(0).putAttachment(AppClientAttachments.START_APP_CLIENT, true);
   } else if (appClients.isEmpty()) {
     throw AppClientLogger.ROOT_LOGGER.cannotFindAppClient();
   } else {
     throw AppClientLogger.ROOT_LOGGER.multipleAppClientsFound();
   }
 }
  @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
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.hasAttachment(Attachments.MODULE)) {
      BatchLogger.LOGGER.tracef("Processing deployment '%s' for batch.", deploymentUnit.getName());
      // Get the class loader
      final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
      final ClassLoader moduleClassLoader = module.getClassLoader();

      final ServiceTarget serviceTarget = phaseContext.getServiceTarget();

      final BatchEnvironmentService service = new BatchEnvironmentService();

      final ServiceBuilder<BatchEnvironment> serviceBuilder =
          serviceTarget.addService(
              BatchServiceNames.batchDeploymentServiceName(deploymentUnit), service);
      serviceBuilder.addDependency(
          BatchServiceNames.BATCH_PROPERTIES, Properties.class, service.getPropertiesInjector());
      serviceBuilder.addDependency(
          BatchServiceNames.BATCH_THREAD_POOL_NAME,
          ExecutorService.class,
          service.getExecutorServiceInjector());

      // Set the class loader
      service.getClassLoaderInjector().setValue(new ImmediateValue<>(moduleClassLoader));

      // Only add transactions and the BeanManager if this is a batch deployment
      if (isBatchDeployment(deploymentUnit)) {
        serviceBuilder.addDependency(
            TxnServices.JBOSS_TXN_USER_TRANSACTION,
            UserTransaction.class,
            service.getUserTransactionInjector());

        // Add the bean manager
        serviceBuilder.addDependency(
            BatchServiceNames.beanManagerServiceName(deploymentUnit),
            new CastingInjector<>(service.getBeanManagerInjector(), BeanManager.class));
      } else {
        BatchLogger.LOGGER.tracef(
            "Skipping UserTransaction and BeanManager service dependencies for deployment %s",
            deploymentUnit.getName());
      }

      serviceBuilder.install();
    }
  }
  /**
   * 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);
    }
  }
  /**
   * Process a deployment for jboss-service.xml files. Will parse the xml file and attach a
   * configuration discovered during processing.
   *
   * @param phaseContext the deployment unit context
   * @throws DeploymentUnitProcessingException
   */
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

    final VirtualFile deploymentRoot =
        phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();

    if (deploymentRoot == null || !deploymentRoot.exists()) return;

    VirtualFile serviceXmlFile = null;
    if (deploymentRoot.isDirectory()) {
      serviceXmlFile = deploymentRoot.getChild(SERVICE_DESCRIPTOR_PATH);
    } else if (deploymentRoot
        .getName()
        .toLowerCase(Locale.ENGLISH)
        .endsWith(SERVICE_DESCRIPTOR_SUFFIX)) {
      serviceXmlFile = deploymentRoot;
    }
    if (serviceXmlFile == null || !serviceXmlFile.exists()) return;

    final XMLMapper xmlMapper = XMLMapper.Factory.create();
    final JBossServiceXmlDescriptorParser jBossServiceXmlDescriptorParser =
        new JBossServiceXmlDescriptorParser(
            JBossDescriptorPropertyReplacement.propertyReplacer(phaseContext.getDeploymentUnit()));
    xmlMapper.registerRootElement(
        new QName("urn:jboss:service:7.0", "server"), jBossServiceXmlDescriptorParser);
    xmlMapper.registerRootElement(new QName(null, "server"), jBossServiceXmlDescriptorParser);

    InputStream xmlStream = null;
    try {
      xmlStream = serviceXmlFile.openStream();
      final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlStream);
      final ParseResult<JBossServiceXmlDescriptor> result =
          new ParseResult<JBossServiceXmlDescriptor>();
      xmlMapper.parseDocument(result, reader);
      final JBossServiceXmlDescriptor xmlDescriptor = result.getResult();
      if (xmlDescriptor != null)
        phaseContext
            .getDeploymentUnit()
            .putAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);
      else throw SarMessages.MESSAGES.failedXmlParsing(serviceXmlFile);
    } catch (Exception e) {
      throw SarMessages.MESSAGES.failedXmlParsing(e, serviceXmlFile);
    } finally {
      VFSUtils.safeClose(xmlStream);
    }
  }
  @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();
  }
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleSpecification moduleSpecification =
        deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);

    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addDependency(moduleSpecification, moduleLoader, APACHE_SCOUT);
    addDependency(moduleSpecification, moduleLoader, JBOSS_JAXR);
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit unit = phaseContext.getDeploymentUnit();
    List<RubyStompletMetaData> allMetaData =
        unit.getAttachmentList(RubyStompletMetaData.ATTACHMENTS_KEY);

    for (RubyStompletMetaData each : allMetaData) {
      deploy(phaseContext, each);
    }
  }
  @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);
          }
        }
      }
    }
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit unit = phaseContext.getDeploymentUnit();

    if (!unit.getName().endsWith(this.archiveSuffix)) {
      return;
    }

    ArchivedDeploymentMarker.applyMark(unit);
    // Tell AS to treat it as an archive and mount them exploded
    MountExplodedMarker.setMountExploded(unit);
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    // Next phase, need to detect if this is a Keycloak deployment.  If not, don't add the modules.

    final ModuleSpecification moduleSpecification =
        deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(moduleSpecification, moduleLoader);
  }
  @Override
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    // install the control point for the top level deployment no matter what
    if (RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) {
      if (deploymentUnit.getParent() == null) {
        ControlPointService.install(
            phaseContext.getServiceTarget(),
            deploymentUnit.getName(),
            UndertowExtension.SUBSYSTEM_NAME);
      }
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
      return;
    }
    String hostName = hostNameOfDeployment(warMetaData, defaultHost);
    processDeployment(warMetaData, deploymentUnit, phaseContext.getServiceTarget(), hostName);
  }
Example #26
0
  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;
        }
      }
  }
  /**
   * Process a deployment for KernelDeployment configuration. Will install a {@code MC bean} for
   * each configured bean.
   *
   * @param phaseContext the deployment unit context
   * @throws DeploymentUnitProcessingException
   */
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final KernelDeploymentXmlDescriptor kdXmlDescriptor =
        phaseContext
            .getDeploymentUnit()
            .getAttachment(KernelDeploymentXmlDescriptor.ATTACHMENT_KEY);
    if (kdXmlDescriptor == null) return;

    final Module module = phaseContext.getDeploymentUnit().getAttachment(Attachments.MODULE);
    if (module == null)
      throw new DeploymentUnitProcessingException(
          "Failed to get module attachment for " + phaseContext.getDeploymentUnit());

    final ClassLoader classLoader = module.getClassLoader();
    final Value<ClassLoader> classLoaderValue = Values.immediateValue(classLoader);

    final List<BeanMetaDataConfig> beanConfigs = kdXmlDescriptor.getBeans();
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    for (final BeanMetaDataConfig beanConfig : beanConfigs) {
      addBean(serviceTarget, beanConfig, classLoaderValue);
    }
  }
Example #28
0
    public void configure(
        final DeploymentPhaseContext context,
        final ComponentConfiguration componentConfiguration,
        final ViewDescription description,
        final ViewConfiguration configuration)
        throws DeploymentUnitProcessingException {
      // Create method indexes
      final DeploymentReflectionIndex reflectionIndex =
          context.getDeploymentUnit().getAttachment(REFLECTION_INDEX);
      final List<Method> methods = configuration.getProxyFactory().getCachedMethods();
      for (final Method method : methods) {
        MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
        Method componentMethod =
            ClassReflectionIndexUtil.findMethod(
                reflectionIndex, componentConfiguration.getComponentClass(), methodIdentifier);

        if (componentMethod == null
            && method.getDeclaringClass().isInterface()
            && (method.getModifiers() & (ABSTRACT | PUBLIC | STATIC)) == PUBLIC) {
          // no component method and the interface method is defaulted, so we really do want to
          // invoke on the interface method
          componentMethod = method;
        }
        if (componentMethod != null) {

          if ((BRIDGE & componentMethod.getModifiers()) != 0) {
            Method other =
                findRealMethodForBridgeMethod(
                    componentMethod, componentConfiguration, reflectionIndex, methodIdentifier);
            // try and find the non-bridge method to delegate to
            if (other != null) {
              componentMethod = other;
            }
          }

          configuration.addViewInterceptor(
              method,
              new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)),
              InterceptorOrder.View.COMPONENT_DISPATCHER);
          configuration.addClientInterceptor(
              method,
              CLIENT_DISPATCHER_INTERCEPTOR_FACTORY,
              InterceptorOrder.Client.CLIENT_DISPATCHER);
        }
      }

      configuration.addClientPostConstructInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
      configuration.addClientPreDestroyInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
    }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    if (deploymentHasPersistenceProvider(phaseContext.getDeploymentUnit())) {
      // finish registration of persistence provider
      PersistenceProviderHandler.finishDeploy(phaseContext);
    }

    // only install PUs with property Configuration.JPA_CONTAINER_CLASS_TRANSFORMER = false (since
    // they weren't started before)
    // this allows @DataSourceDefinition to work (which don't start until the Install phase)
    PersistenceUnitServiceHandler.deploy(phaseContext, false, platform);
  }
Example #30
0
    public void configure(
        final DeploymentPhaseContext context,
        final ComponentConfiguration componentConfiguration,
        final ViewDescription description,
        final ViewConfiguration configuration)
        throws DeploymentUnitProcessingException {
      // Create method indexes
      final DeploymentReflectionIndex reflectionIndex =
          context.getDeploymentUnit().getAttachment(REFLECTION_INDEX);
      final List<Method> methods = configuration.getProxyFactory().getCachedMethods();
      for (final Method method : methods) {
        MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
        Method componentMethod =
            ClassReflectionIndexUtil.findMethod(
                reflectionIndex, componentConfiguration.getComponentClass(), methodIdentifier);

        if (componentMethod != null) {

          if ((BRIDGE & componentMethod.getModifiers()) != 0) {
            Collection<Method> otherMethods =
                ClassReflectionIndexUtil.findMethods(
                    reflectionIndex,
                    reflectionIndex.getClassIndex(componentConfiguration.getComponentClass()),
                    methodIdentifier.getName(),
                    methodIdentifier.getParameterTypes());
            // try and find the non-bridge method to delegate to
            for (final Method other : otherMethods) {
              if ((BRIDGE & other.getModifiers()) == 0) {
                componentMethod = other;
                break;
              }
            }
          }

          configuration.addViewInterceptor(
              method,
              new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)),
              InterceptorOrder.View.COMPONENT_DISPATCHER);
          configuration.addClientInterceptor(
              method,
              CLIENT_DISPATCHER_INTERCEPTOR_FACTORY,
              InterceptorOrder.Client.CLIENT_DISPATCHER);
        }
      }

      configuration.addClientPostConstructInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
      configuration.addClientPreDestroyInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
    }