You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2011/08/30 23:02:14 UTC

svn commit: r1163381 - in /maven/archetype/trunk/maven-archetype-plugin/src: main/java/org/apache/maven/archetype/ui/generation/ test/java/org/apache/maven/archetype/ui/generation/

Author: hboutemy
Date: Tue Aug 30 21:02:14 2011
New Revision: 1163381

URL: http://svn.apache.org/viewvc?rev=1163381&view=rev
Log:
[ARCHETYPE-362] fixed faulty ordering when a property referenced has no default value
Submitted by: Maarten Winkels
applied with formatting and content improvements

Added:
    maven/archetype/trunk/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/RequiredPropertyComparatorTest.java   (with props)
Modified:
    maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java

Modified: maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java?rev=1163381&r1=1163380&r2=1163381&view=diff
==============================================================================
--- maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java (original)
+++ maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java Tue Aug 30 21:02:14 2011
@@ -330,7 +330,8 @@ public class DefaultArchetypeGenerationC
         }
     }
 
-    public static class RequiredPropertyComparator implements Comparator<String>
+    public static class RequiredPropertyComparator
+        implements Comparator<String>
     {
         private final ArchetypeConfiguration archetypeConfiguration;
 
@@ -342,23 +343,20 @@ public class DefaultArchetypeGenerationC
         public int compare( String left, String right )
         {
             String leftDefault = archetypeConfiguration.getDefaultValue( left );
-            String rightDefault = archetypeConfiguration.getDefaultValue( right );
-            if ( null == leftDefault || null == rightDefault )
-            {
-                return comparePropertyName( (String) left, (String) right );
-            }
-            else if ( leftDefault.indexOf( "${" + right + "}" ) >= 0 )
+
+            if ( ( leftDefault != null ) && leftDefault.indexOf( "${" + right + "}" ) >= 0 )
             { //left contains right
                 return 1;
             }
-            else if ( rightDefault.indexOf( "${" + left + "}" ) >= 0 )
+
+            String rightDefault = archetypeConfiguration.getDefaultValue( right );
+
+            if ( ( rightDefault != null ) && rightDefault.indexOf( "${" + left + "}" ) >= 0 )
             { //right contains left
                 return -1;
             }
-            else
-            {
-                return comparePropertyName( left, right );
-            }
+
+            return comparePropertyName( left, right );
         }
 
         private int comparePropertyName( String left, String right )

Added: maven/archetype/trunk/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/RequiredPropertyComparatorTest.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/RequiredPropertyComparatorTest.java?rev=1163381&view=auto
==============================================================================
--- maven/archetype/trunk/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/RequiredPropertyComparatorTest.java (added)
+++ maven/archetype/trunk/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/RequiredPropertyComparatorTest.java Tue Aug 30 21:02:14 2011
@@ -0,0 +1,70 @@
+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 junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.archetype.ui.ArchetypeConfiguration;
+
+public class RequiredPropertyComparatorTest
+    extends TestCase
+{
+    private DefaultArchetypeGenerationConfigurator.RequiredPropertyComparator requiredPropertyComparator;
+
+    private ArchetypeConfiguration archetypeConfiguration;
+
+    @Override
+    public void setUp()
+        throws Exception
+    {
+        archetypeConfiguration = new ArchetypeConfiguration();
+        requiredPropertyComparator =
+            new DefaultArchetypeGenerationConfigurator.RequiredPropertyComparator( archetypeConfiguration );
+    }
+
+    public void testShouldOrderPropertiesWhenReferringEachOther()
+    {
+        archetypeConfiguration.addRequiredProperty( "prop1" );
+        archetypeConfiguration.setDefaultProperty( "prop1", "${prop2}" );
+        archetypeConfiguration.addRequiredProperty( "prop2" );
+        archetypeConfiguration.setDefaultProperty( "prop2", "prop2 default value" );
+
+        List<String> requiredProperties = archetypeConfiguration.getRequiredProperties();
+        assertEquals( Arrays.asList( "prop1", "prop2" ), requiredProperties );
+        Collections.sort( requiredProperties, requiredPropertyComparator );
+        assertEquals( Arrays.asList( "prop2", "prop1" ), requiredProperties );
+    }
+
+    public void testShouldOrderPropertiesWhenReferringEachOther2()
+    {
+        archetypeConfiguration.addRequiredProperty( "prop1" );
+        archetypeConfiguration.setDefaultProperty( "prop1", "${prop2}" );
+        archetypeConfiguration.addRequiredProperty( "prop2" );
+
+        List<String> requiredProperties = archetypeConfiguration.getRequiredProperties();
+        assertEquals( Arrays.asList( "prop1", "prop2" ), requiredProperties );
+        Collections.sort( requiredProperties, requiredPropertyComparator );
+        assertEquals( Arrays.asList( "prop2", "prop1" ), requiredProperties );
+    }
+}

Propchange: maven/archetype/trunk/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/RequiredPropertyComparatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archetype/trunk/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/RequiredPropertyComparatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/archetype/trunk/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/RequiredPropertyComparatorTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain