Repository: maven-archetype
Updated Branches:
  refs/heads/master 8763512e7 -> 9857d346b


[ARCHETYPE-509] RequiredProperty not set in batch mode
this closes #14
Signed-off-by: rfscholte <rfscho...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/maven-archetype/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-archetype/commit/9857d346
Tree: http://git-wip-us.apache.org/repos/asf/maven-archetype/tree/9857d346
Diff: http://git-wip-us.apache.org/repos/asf/maven-archetype/diff/9857d346

Branch: refs/heads/master
Commit: 9857d346b7ec300cd7834cd4e3e6248770b20a8d
Parents: 8763512
Author: Max Norris <mnor...@ancestry.com>
Authored: Tue Sep 13 23:20:17 2016 +0200
Committer: rfscholte <rfscho...@apache.org>
Committed: Tue Jan 24 20:19:41 2017 +0100

----------------------------------------------------------------------
 .../DefaultArchetypeGenerationConfigurator.java |   8 +-
 ...ultArchetypeGenerationConfigurator2Test.java | 102 +++++++++++++++++++
 2 files changed, 107 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/9857d346/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
----------------------------------------------------------------------
diff --git 
a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
 
b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
index cb0fb3a..bd35170 100644
--- 
a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
+++ 
b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
@@ -150,10 +150,10 @@ public class DefaultArchetypeGenerationConfigurator
             throw new ArchetypeGenerationConfigurationFailure( "The defined 
artifact is not an archetype" );
         }
 
+        Context context = new VelocityContext();
         if ( interactiveMode.booleanValue() )
         {
             boolean confirmed = false;
-            Context context = new VelocityContext();
             context.put( Constants.GROUP_ID, ad.getGroupId() );
             context.put( Constants.ARTIFACT_ID, ad.getArtifactId() );
             context.put( Constants.VERSION, ad.getVersion() );
@@ -253,8 +253,10 @@ public class DefaultArchetypeGenerationConfigurator
                     if ( !archetypeConfiguration.isConfigured( 
requiredProperty ) && (
                         archetypeConfiguration.getDefaultValue( 
requiredProperty ) != null ) )
                     {
-                        archetypeConfiguration.setProperty( requiredProperty, 
archetypeConfiguration.getDefaultValue(
-                            requiredProperty ) );
+                        String value = archetypeConfiguration.getDefaultValue( 
requiredProperty );
+                        value = getTransitiveDefaultValue( value, 
archetypeConfiguration, requiredProperty, context );
+                        archetypeConfiguration.setProperty( requiredProperty, 
value );
+                        context.put( requiredProperty, value );
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/9857d346/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator2Test.java
----------------------------------------------------------------------
diff --git 
a/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator2Test.java
 
b/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator2Test.java
new file mode 100644
index 0000000..9393414
--- /dev/null
+++ 
b/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator2Test.java
@@ -0,0 +1,102 @@
+package org.apache.maven.archetype.ui.generation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Properties;
+
+import org.apache.maven.archetype.ArchetypeGenerationRequest;
+import org.apache.maven.archetype.common.ArchetypeArtifactManager;
+import org.apache.maven.archetype.metadata.ArchetypeDescriptor;
+import org.apache.maven.archetype.metadata.RequiredProperty;
+import org.codehaus.plexus.PlexusTestCase;
+import org.easymock.MockControl;
+
+/**
+ * Tests the ability to use variables in default fields in batch mode
+ */
+public class DefaultArchetypeGenerationConfigurator2Test
+    extends PlexusTestCase
+{
+    private DefaultArchetypeGenerationConfigurator configurator;
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        configurator = (DefaultArchetypeGenerationConfigurator) lookup( 
ArchetypeGenerationConfigurator.ROLE );
+
+        MockControl control = MockControl.createControl( 
ArchetypeArtifactManager.class );
+        control.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+
+        ArchetypeArtifactManager manager = (ArchetypeArtifactManager) 
control.getMock();
+        manager.exists( "archetypeGroupId", "archetypeArtifactId", 
"archetypeVersion", null, null, null );
+        control.setReturnValue( true );
+        manager.isFileSetArchetype( "archetypeGroupId", "archetypeArtifactId", 
"archetypeVersion", null, null, null );
+        control.setReturnValue( true );
+        manager.isOldArchetype( "archetypeGroupId", "archetypeArtifactId", 
"archetypeVersion", null, null, null );
+        control.setReturnValue( false );
+        manager.getFileSetArchetypeDescriptor( "archetypeGroupId", 
"archetypeArtifactId", "archetypeVersion", null,
+                                               null, null );
+        ArchetypeDescriptor descriptor = new ArchetypeDescriptor();
+        RequiredProperty groupId = new RequiredProperty();
+        groupId.setKey( "groupId" );
+        groupId.setDefaultValue( "com.example.${groupName}" );
+        RequiredProperty artifactId = new RequiredProperty();
+        artifactId.setKey( "artifactId" );
+        artifactId.setDefaultValue( "${serviceName}" );
+        RequiredProperty thePackage = new RequiredProperty();
+        thePackage.setKey( "package" );
+        thePackage.setDefaultValue( "com.example.${groupName}" );
+        RequiredProperty groupName = new RequiredProperty();
+        groupName.setKey( "groupName" );
+        groupName.setDefaultValue( null );
+        RequiredProperty serviceName = new RequiredProperty();
+        serviceName.setKey( "serviceName" );
+        serviceName.setDefaultValue( null );
+        descriptor.addRequiredProperty( groupId );
+        descriptor.addRequiredProperty( artifactId );
+        descriptor.addRequiredProperty( thePackage );
+        descriptor.addRequiredProperty( groupName );
+        descriptor.addRequiredProperty( serviceName );
+        control.setReturnValue( descriptor );
+        control.replay();
+        configurator.setArchetypeArtifactManager( manager );
+    }
+    
+    public void testJIRA_509_FileSetArchetypeDefaultsWithVariables() throws 
Exception
+    {
+        ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
+        request.setArchetypeGroupId( "archetypeGroupId" );
+        request.setArchetypeArtifactId( "archetypeArtifactId" );
+        request.setArchetypeVersion( "archetypeVersion" );
+        Properties properties = new Properties();
+        properties.setProperty( "groupName", "myGroupName" );
+        properties.setProperty( "serviceName", "myServiceName" );
+        
+        configurator.configureArchetype( request, Boolean.FALSE, properties );
+        
+        assertEquals( "com.example.myGroupName", request.getGroupId() );
+        assertEquals( "myServiceName", request.getArtifactId() );
+        assertEquals( "1.0-SNAPSHOT", request.getVersion() );
+        assertEquals( "com.example.myGroupName", request.getPackage() );
+    }
+          
+}
\ No newline at end of file

Reply via email to