Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARCHETYPE-688] Allow hyphen in requiredProperty #230

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}