You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/07/06 15:47:26 UTC

[GitHub] [maven-archetype] elharo commented on a change in pull request #64: [ARCHETYPE-406][ARCHETYPE-558][ARCHETYPE-562] Support full Velocity default value expressions for required properties; properly handle ordering among same

elharo commented on a change in pull request #64:
URL: https://github.com/apache/maven-archetype/pull/64#discussion_r664676528



##########
File path: maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
##########
@@ -313,46 +311,23 @@ else if ( !archetypeGenerationQueryer.confirmConfiguration( archetypeConfigurati
         request.setProperties( properties );
     }
 
-    private String getTransitiveDefaultValue( String defaultValue, ArchetypeConfiguration archetypeConfiguration,
-                                              String requiredProperty, Context context )
+    private String getTransitiveDefaultValue( String defaultValue, String requiredProperty, Context context )
     {
-        String result = defaultValue;
-        if ( null == result )
+        if ( StringUtils.contains( defaultValue, "${" ) )
         {
-            return null;
-        }
-        for ( String property : archetypeConfiguration.getRequiredProperties() )
-        {
-            if ( result.indexOf( "${" + property + "}" ) >= 0 )
+            try ( StringWriter stringWriter = new StringWriter() )
             {
-
-                result = StringUtils.replace( result, "${" + property + "}",
-                                              archetypeConfiguration.getProperty( property ) );
+                Velocity.evaluate( context, stringWriter, requiredProperty, defaultValue );
+                return stringWriter.toString();
+            }
+            catch ( IOException ex )
+            {
+                // closing StringWriter shouldn't actually generate any exception

Review comment:
       Yes, but wrap in a runtime exception just in case. 

##########
File path: maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
##########
@@ -313,46 +311,23 @@ else if ( !archetypeGenerationQueryer.confirmConfiguration( archetypeConfigurati
         request.setProperties( properties );
     }
 
-    private String getTransitiveDefaultValue( String defaultValue, ArchetypeConfiguration archetypeConfiguration,
-                                              String requiredProperty, Context context )
+    private String getTransitiveDefaultValue( String defaultValue, String requiredProperty, Context context )
     {
-        String result = defaultValue;
-        if ( null == result )
+        if ( StringUtils.contains( defaultValue, "${" ) )
         {
-            return null;
-        }
-        for ( String property : archetypeConfiguration.getRequiredProperties() )
-        {
-            if ( result.indexOf( "${" + property + "}" ) >= 0 )
+            try ( StringWriter stringWriter = new StringWriter() )
             {
-
-                result = StringUtils.replace( result, "${" + property + "}",
-                                              archetypeConfiguration.getProperty( property ) );
+                Velocity.evaluate( context, stringWriter, requiredProperty, defaultValue );

Review comment:
       is defaultValue correctly named? This looks like a template, not a default value, but I'm not a velocity expert. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org