Search in sources :

Example 1 with CompositePropertyResolver

use of org.jboss.metadata.property.CompositePropertyResolver in project wildfly by wildfly.

the class DeploymentPropertyResolverProcessor method deploy.

public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    DeploymentUnit current = deploymentUnit;
    final List<PropertyResolver> propertyResolvers = new ArrayList<PropertyResolver>();
    do {
        final Properties deploymentProperties = current.getAttachment(Attachments.DEPLOYMENT_PROPERTIES);
        if (deploymentProperties != null) {
            propertyResolvers.add(new PropertiesPropertyResolver(deploymentProperties));
        }
        current = current.getParent();
    } while (current != null);
    if (!propertyResolvers.isEmpty()) {
        deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_PROPERTY_RESOLVERS, new CompositePropertyResolver(propertyResolvers));
    }
}
Also used : PropertiesPropertyResolver(org.jboss.metadata.property.PropertiesPropertyResolver) ArrayList(java.util.ArrayList) PropertyResolver(org.jboss.metadata.property.PropertyResolver) PropertiesPropertyResolver(org.jboss.metadata.property.PropertiesPropertyResolver) CompositePropertyResolver(org.jboss.metadata.property.CompositePropertyResolver) Properties(java.util.Properties) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CompositePropertyResolver(org.jboss.metadata.property.CompositePropertyResolver)

Example 2 with CompositePropertyResolver

use of org.jboss.metadata.property.CompositePropertyResolver in project wildfly by wildfly.

the class FunctionalResolverProcessor method deploy.

public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final List<Function<String, String>> functions = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_EXPRESSION_RESOLVERS);
    if (functions != null) {
        SimpleExpressionResolver[] sers = new SimpleExpressionResolver[functions.size()];
        for (int i = 0; i < functions.size(); i++) {
            Function<String, String> funct = functions.get(i);
            sers[i] = expressionContent -> {
                String input = "${" + expressionContent + "}";
                String resolved = funct.apply(input);
                return resolved == null ? null : new SimpleExpressionResolver.ResolutionResult(resolved, false);
            };
        }
        deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_PROPERTY_RESOLVERS, new CompositePropertyResolver(sers));
    }
}
Also used : Function(java.util.function.Function) SimpleExpressionResolver(org.jboss.metadata.property.SimpleExpressionResolver) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CompositePropertyResolver(org.jboss.metadata.property.CompositePropertyResolver)

Example 3 with CompositePropertyResolver

use of org.jboss.metadata.property.CompositePropertyResolver in project wildfly by wildfly.

the class PropertyResolverProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final CompositePropertyResolver propertyResolver = new CompositePropertyResolver(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_PROPERTY_RESOLVERS));
    final PropertyReplacer propertyReplacer = PropertyReplacers.resolvingExpressionReplacer(propertyResolver);
    // We pass a function basically to be used by wildfly-core which does not the dependencies used to instantiate a PropertyReplacer
    final Function<String, String> functionExpand = (value) -> propertyReplacer.replaceProperties(value);
    // setup the expression expand function for spec descriptors, if property expansion is enabled for them. If it does not exist, then by default we assume they are enabled.
    final Boolean specDescriptorPropReplacement = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT);
    if (specDescriptorPropReplacement == null || specDescriptorPropReplacement) {
        deploymentUnit.putAttachment(org.jboss.as.server.deployment.Attachments.SPEC_DESCRIPTOR_EXPR_EXPAND_FUNCTION, functionExpand);
    }
    // setup the expression expand function for JBoss/WildFly descriptors, if property expansion is enabled for them
    final Boolean jbossDescriptorPropReplacement = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT);
    if (jbossDescriptorPropReplacement == null || jbossDescriptorPropReplacement) {
        deploymentUnit.putAttachment(org.jboss.as.server.deployment.Attachments.WFLY_DESCRIPTOR_EXPR_EXPAND_FUNCTION, functionExpand);
    }
    deploymentUnit.putAttachment(Attachments.FINAL_PROPERTY_RESOLVER, propertyResolver);
    deploymentUnit.putAttachment(Attachments.FINAL_PROPERTY_REPLACER, propertyReplacer);
}
Also used : PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) CompositePropertyResolver(org.jboss.metadata.property.CompositePropertyResolver) DeploymentUnitProcessor(org.jboss.as.server.deployment.DeploymentUnitProcessor) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) PropertyReplacers(org.jboss.metadata.property.PropertyReplacers) Function(java.util.function.Function) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CompositePropertyResolver(org.jboss.metadata.property.CompositePropertyResolver)

Aggregations

DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 CompositePropertyResolver (org.jboss.metadata.property.CompositePropertyResolver)3 Function (java.util.function.Function)2 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 DeploymentUnitProcessor (org.jboss.as.server.deployment.DeploymentUnitProcessor)1 PropertiesPropertyResolver (org.jboss.metadata.property.PropertiesPropertyResolver)1 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)1 PropertyReplacers (org.jboss.metadata.property.PropertyReplacers)1 PropertyResolver (org.jboss.metadata.property.PropertyResolver)1 SimpleExpressionResolver (org.jboss.metadata.property.SimpleExpressionResolver)1