@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);
    }
  }
  /**
   * 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 {
    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(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);
    }
  }
 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(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 {
    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(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);
  }
  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);
    }
  }
 @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();
    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);
      }
    }
  }
  /**
   * 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);
    }
  }
  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 WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
   if (warMetaData == null) {
     return;
   }
   String hostName = hostNameOfDeployment(warMetaData, defaultHost);
   processDeployment(warMetaData, deploymentUnit, phaseContext.getServiceTarget(), hostName);
 }
Example #17
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;
        }
      }
  }
  @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);
  }
Example #20
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);
    }
  /**
   * 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);
    }
  }
  @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);
  }
  @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);
          }
        }
      }
    }
  }
  /** {@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(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (deploymentUnit.hasAttachment(ClojureMetaData.ATTACHMENT_KEY)) {
      return;
    }

    Timer t = new Timer("parsing deployment descriptor");
    String deploymentName = deploymentUnit.getName();

    try {
      VirtualFile descriptor = getDescriptorFile(deploymentUnit);
      if (descriptor == null) {
        return;
      }

      ClojureMetaData appMetaData =
          new ClojureMetaData(deploymentName, ClojureMetaData.parse(descriptor.getPhysicalFile()));

      appMetaData.attachTo(deploymentUnit);

      File root = appMetaData.getRoot();

      if (root == null) {
        throw new DeploymentUnitProcessingException("No application root specified.");
      }

      if (!root.exists()) {
        throw new DeploymentUnitProcessingException(
            "Application root does not exist: " + root.getAbsolutePath());
      }

      VirtualFile virtualRoot = VFS.getChild(root.toURI());
      MountHandle mountHandle = null;

      if (!root.isDirectory()) {
        // Expand the referenced root if it's not a directory (ie .ima archive)
        mountHandle =
            new MountHandle(
                VFS.mountZipExpanded(virtualRoot, virtualRoot, TempFileProviderService.provider()));
      }

      deploymentUnit.putAttachment(
          Attachments.DEPLOYMENT_ROOT, new ResourceRoot(virtualRoot, mountHandle));
      deploymentUnit.putAttachment(ClojureMetaData.DESCRIPTOR_FILE, descriptor.getPhysicalFile());

    } catch (Exception e) {
      throw new DeploymentUnitProcessingException(e);
    }
    t.done();
  }
Example #26
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);
    }
 @Override
 public void getResourceValue(
     final ResolutionContext resolutionContext,
     final ServiceBuilder<?> serviceBuilder,
     final DeploymentPhaseContext phaseContext,
     final Injector<ManagedReferenceFactory> injector)
     throws DeploymentUnitProcessingException {
   final ClassLoader classLoader =
       phaseContext.getDeploymentUnit().getAttachment(Attachments.MODULE).getClassLoader();
   injector.inject(
       new ValueManagedReferenceFactory(
           new ImmediateValue<Object>(new LazyValidatorFactory(classLoader))));
 }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit parent =
        deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();

    final ModuleSpecification parentModuleSpec =
        parent.getAttachment(Attachments.MODULE_SPECIFICATION);

    final ModuleSpecification moduleSpec =
        deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader =
        deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
    final ModuleIdentifier moduleIdentifier =
        deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER);

    if (deploymentUnit.getParent() != null) {
      final ModuleIdentifier parentModule = parent.getAttachment(Attachments.MODULE_IDENTIFIER);
      if (parentModule != null) {
        // access to ear classes
        ModuleDependency moduleDependency =
            new ModuleDependency(moduleLoader, parentModule, false, false, true);
        moduleDependency.addImportFilter(PathFilters.acceptAll(), true);
        moduleSpec.addLocalDependency(moduleDependency);
      }
    }

    // If the sub deployments aren't isolated, then we need to set up dependencies between the sub
    // deployments
    if (!parentModuleSpec.isSubDeploymentModulesIsolated()) {
      final List<DeploymentUnit> subDeployments =
          parent.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
      final List<ModuleDependency> accessibleModules = new ArrayList<ModuleDependency>();
      for (DeploymentUnit subDeployment : subDeployments) {
        final ModuleSpecification subModule =
            subDeployment.getAttachment(Attachments.MODULE_SPECIFICATION);
        if (!subModule.isPrivateModule()) {
          ModuleIdentifier identifier = subDeployment.getAttachment(Attachments.MODULE_IDENTIFIER);
          ModuleDependency dependency =
              new ModuleDependency(moduleLoader, identifier, false, false, true);
          dependency.addImportFilter(PathFilters.acceptAll(), true);
          accessibleModules.add(dependency);
        }
      }
      for (ModuleDependency identifier : accessibleModules) {
        if (!identifier.equals(moduleIdentifier)) {
          moduleSpec.addLocalDependencies(accessibleModules);
        }
      }
    }
  }
  /**
   * Process a deployment for standard ra deployment files. Will parse the xml file and attach an
   * configuration discovered during processing.
   *
   * @param phaseContext the deployment unit context
   * @throws DeploymentUnitProcessingException
   */
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final VirtualFile deploymentRoot =
        phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();

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

    final String deploymentRootName = deploymentRoot.getLowerCaseName();
    if (!deploymentRootName.endsWith(".rar")) {
      return;
    }

    VirtualFile serviceXmlFile = deploymentRoot.getChild("/META-INF/ra.xml");

    InputStream xmlStream = null;
    Connector result = null;
    try {
      if (serviceXmlFile != null && serviceXmlFile.exists()) {

        xmlStream = serviceXmlFile.openStream();
        result = (new RaParser()).parse(xmlStream);
        if (result == null) throw MESSAGES.failedToParseServiceXml(serviceXmlFile);
      }
      File root = deploymentRoot.getPhysicalFile();
      URL url = root.toURI().toURL();
      String deploymentName = deploymentRootName.substring(0, deploymentRootName.indexOf(".rar"));
      ConnectorXmlDescriptor xmlDescriptor =
          new ConnectorXmlDescriptor(result, root, url, deploymentName);
      phaseContext
          .getDeploymentUnit()
          .putAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);

    } catch (Exception e) {
      throw MESSAGES.failedToParseServiceXml(e, serviceXmlFile);
    } finally {
      VFSUtils.safeClose(xmlStream);
    }
  }
 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;
 }