Skip to content

Commit

Permalink
[ARCHETYPE-688] Allow hyphen in requiredProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Oct 11, 2024
1 parent a7b91d8 commit b96cb78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;
import org.apache.velocity.context.InternalContextAdapterImpl;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.RuntimeSingleton;
import org.apache.velocity.runtime.RuntimeInstance;
import org.apache.velocity.runtime.parser.ParseException;
import org.apache.velocity.runtime.parser.node.ASTNegateNode;
import org.apache.velocity.runtime.parser.node.ASTReference;
Expand Down Expand Up @@ -326,7 +325,10 @@ private Map<String, Set<String>> computePropertyReferences() {
final InternalContextAdapterImpl velocityContextAdapter =
new InternalContextAdapterImpl(new VelocityContext());

final RuntimeServices velocityRuntime = RuntimeSingleton.getRuntimeServices();
final RuntimeInstance velocityRuntime = new RuntimeInstance();
Properties properties = new Properties();
properties.put("parser.allow_hyphen_in_identifiers", true);
velocityRuntime.setProperties(properties);

for (String propertyName : requiredProperties) {
final Set<String> referencedPropertyNames = new LinkedHashSet<>();
Expand All @@ -336,7 +338,7 @@ private Map<String, Set<String>> computePropertyReferences() {
try {
Template template = new Template();
template.setName(propertyName + ".default");
SimpleNode node = RuntimeSingleton.parse(new StringReader(defaultValue), template);
SimpleNode node = velocityRuntime.parse(new StringReader(defaultValue), template);

node.init(velocityContextAdapter, velocityRuntime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,17 @@ public void testTransitivePropertyReferences() {
requiredProperties.sort(requiredPropertyComparator);
assertEquals(Arrays.asList("baz", "bar", "foo"), requiredProperties);
}

@Test
public void testPropertiesWithHyphen() {
archetypeConfiguration.addRequiredProperty("description");
archetypeConfiguration.setDefaultProperty("description", "${acronym-app} project-arch: ${component-name}");
archetypeConfiguration.addRequiredProperty("component-name");
archetypeConfiguration.addRequiredProperty("acronym-app");

List<String> requiredProperties = archetypeConfiguration.getRequiredProperties();
assertEquals(Arrays.asList("description", "component-name", "acronym-app"), requiredProperties);
requiredProperties.sort(requiredPropertyComparator);
assertEquals(Arrays.asList("component-name", "acronym-app", "description"), requiredProperties);
}
}

0 comments on commit b96cb78

Please sign in to comment.