-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add property resolution for provided dependencies
- Loading branch information
Showing
4 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...ps-mta/src/main/java/org/cloudfoundry/multiapps/mta/resolvers/ProvidesValuesResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.cloudfoundry.multiapps.mta.resolvers; | ||
|
||
import static java.text.MessageFormat.format; | ||
|
||
import java.util.Map; | ||
|
||
import org.cloudfoundry.multiapps.common.ContentException; | ||
import org.cloudfoundry.multiapps.mta.Messages; | ||
import org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorHandler; | ||
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor; | ||
import org.cloudfoundry.multiapps.mta.model.RequiredDependency; | ||
import org.cloudfoundry.multiapps.mta.model.Resource; | ||
|
||
public class ProvidesValuesResolver implements ProvidedValuesResolver { | ||
|
||
private DescriptorHandler handler; | ||
private String consumerName; | ||
private DeploymentDescriptor descriptor; | ||
|
||
public ProvidesValuesResolver(String consumerName, DescriptorHandler handler, DeploymentDescriptor descriptor) { | ||
|
||
this.handler = handler; | ||
this.consumerName = consumerName; | ||
this.descriptor = descriptor; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> resolveProvidedValues(String dependencyName) throws ContentException { | ||
assertRequiredDependencyExists(dependencyName); | ||
Resource resource = handler.findResource(descriptor, dependencyName); | ||
return resource.getProperties(); | ||
} | ||
|
||
protected void assertRequiredDependencyExists(String dependencyName) { | ||
RequiredDependency requiredDependency = handler.findRequiredDependency(descriptor, consumerName, dependencyName); | ||
if (requiredDependency == null) { | ||
throw new ContentException(format(Messages.ILLEGAL_REFERENCES_DETECTED, consumerName, dependencyName)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...java/org/cloudfoundry/multiapps/mta/resolvers/v3/ProvidedDependencyReferenceResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.cloudfoundry.multiapps.mta.resolvers.v3; | ||
|
||
import static org.cloudfoundry.multiapps.mta.resolvers.ReferencePattern.FULLY_QUALIFIED; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.cloudfoundry.multiapps.common.ContentException; | ||
import org.cloudfoundry.multiapps.mta.handlers.v2.DescriptorHandler; | ||
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor; | ||
import org.cloudfoundry.multiapps.mta.model.NamedElement; | ||
import org.cloudfoundry.multiapps.mta.model.ProvidedDependency; | ||
import org.cloudfoundry.multiapps.mta.resolvers.ProvidedValuesResolver; | ||
import org.cloudfoundry.multiapps.mta.resolvers.ProvidesValuesResolver; | ||
import org.cloudfoundry.multiapps.mta.resolvers.ReferenceResolver; | ||
import org.cloudfoundry.multiapps.mta.resolvers.ResolverBuilder; | ||
|
||
public class ProvidedDependencyReferenceResolver extends ReferenceResolver<ProvidedDependency> { | ||
|
||
protected final ProvidedDependency dependency; | ||
protected final ResolverBuilder propertiesResolverBuilder; | ||
private DescriptorHandler handler; | ||
private DeploymentDescriptor descriptor; | ||
private String consumerName; | ||
|
||
public ProvidedDependencyReferenceResolver(DeploymentDescriptor descriptor, NamedElement container, ProvidedDependency dependency, | ||
String prefix, ResolverBuilder propertiesResolverBuilder, | ||
Set<String> dynamicResolvableParameters) { | ||
this(descriptor, container, dependency, prefix, new DescriptorHandler(), propertiesResolverBuilder, dynamicResolvableParameters); | ||
} | ||
|
||
public ProvidedDependencyReferenceResolver(DeploymentDescriptor descriptor, NamedElement container, ProvidedDependency dependency, | ||
String prefix, DescriptorHandler handler, ResolverBuilder propertiesResolverBuilder, | ||
Set<String> dynamicResolvableParameters) { | ||
super(dependency.getName(), prefix, handler, descriptor, container.getName(), FULLY_QUALIFIED, dynamicResolvableParameters); | ||
this.dependency = dependency; | ||
this.propertiesResolverBuilder = propertiesResolverBuilder; | ||
this.handler = handler; | ||
this.consumerName = container.getName(); | ||
this.descriptor = descriptor; | ||
} | ||
|
||
@Override | ||
public ProvidedDependency resolve() throws ContentException { | ||
Map<String, Object> resolvedProperties = resolve(dependency.getProperties(), Collections.emptyMap(), true); | ||
Map<String, Object> resolvedParameters = resolve(dependency.getParameters(), Collections.emptyMap(), true); | ||
dependency.setProperties(resolvedProperties); | ||
dependency.setParameters(resolvedParameters); | ||
return dependency; | ||
} | ||
|
||
@Override | ||
protected Map<String, Object> resolve(Map<String, Object> properties, final Map<String, Object> propertyValues, Boolean isStrict) { | ||
ProvidedValuesResolver valuesResolver = new ProvidesValuesResolver(consumerName, handler, descriptor); | ||
return propertiesResolverBuilder.build(properties, valuesResolver, patternToMatch, prefix, isStrict, dynamicResolvableParameters) | ||
.resolve(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters