You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2007/08/19 19:29:21 UTC

svn commit: r567438 - in /maven/shared/trunk/maven-model-converter/src: main/java/org/apache/maven/model/converter/ test/java/org/apache/maven/model/converter/

Author: dennisl
Date: Sun Aug 19 10:29:20 2007
New Revision: 567438

URL: http://svn.apache.org/viewvc?view=rev&rev=567438
Log:
[MONE-22] Sort the build and reporting plugins in the generated pom.xml

Added:
    maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/PluginComparator.java   (with props)
    maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/ReportPluginComparator.java   (with props)
    maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/PluginComparatorTest.java   (with props)
    maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/ReportPluginComparatorTest.java   (with props)
Modified:
    maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/Maven1Converter.java

Modified: maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/Maven1Converter.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/Maven1Converter.java?view=diff&rev=567438&r1=567437&r2=567438
==============================================================================
--- maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/Maven1Converter.java (original)
+++ maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/Maven1Converter.java Sun Aug 19 10:29:20 2007
@@ -40,6 +40,7 @@
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
@@ -139,6 +140,16 @@
             pluginRelocator = (PluginRelocator) iterator.next();
             pluginRelocator.addListeners( listeners );
             pluginRelocator.relocate( v4Model );
+        }
+
+        // Sort the plugins
+        if ( v4Model.getBuild() != null )
+        {
+            Collections.sort( v4Model.getBuild().getPlugins(), new PluginComparator() );
+        }
+        if ( v4Model.getReporting() != null )
+        {
+            Collections.sort( v4Model.getReporting().getPlugins(), new ReportPluginComparator() );
         }
 
         try

Added: maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/PluginComparator.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/PluginComparator.java?view=auto&rev=567438
==============================================================================
--- maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/PluginComparator.java (added)
+++ maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/PluginComparator.java Sun Aug 19 10:29:20 2007
@@ -0,0 +1,109 @@
+package org.apache.maven.model.converter;
+
+/*
+ * 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 org.apache.maven.model.Plugin;
+
+import java.util.Comparator;
+
+/**
+ * A comparator for <code>Plugin</code>s. It compares the plugins' groupIds and
+ * artifactIds.
+ *
+ * @author Dennis Lundberg
+ * @version $Id$
+ */
+public class PluginComparator
+    implements Comparator
+{
+    public int compare( Object o1, Object o2 )
+    {
+        // Check for null objects
+        if ( o1 == null && o2 == null )
+        {
+            return 0;
+        }
+        if ( o1 == null )
+        {
+            return -1;
+        }
+        if ( o2 == null )
+        {
+            return 1;
+        }
+
+        // Check classes
+        if ( !( o1 instanceof Plugin ) && !( o2 instanceof Plugin ) )
+        {
+            return 0;
+        }
+        if ( !( o1 instanceof Plugin ) )
+        {
+            return -1;
+        }
+        if ( !( o2 instanceof Plugin ) )
+        {
+            return 1;
+        }
+        Plugin plugin1 = (Plugin) o1;
+        Plugin plugin2 = (Plugin) o2;
+
+        // Check for null values
+        if ( plugin1.getGroupId() == null && plugin2.getGroupId() == null )
+        {
+            return compareArtifactId( plugin1, plugin2 );
+        }
+        if ( plugin1.getGroupId() == null )
+        {
+            return -1;
+        }
+        if ( plugin2.getGroupId() == null )
+        {
+            return 1;
+        }
+
+        // Compare values
+        int answer;
+        answer = plugin1.getGroupId().compareTo( plugin2.getGroupId() );
+        if( answer == 0)
+        {
+            answer = compareArtifactId( plugin1, plugin2 );
+        }
+
+        return answer;
+    }
+
+    private int compareArtifactId( Plugin plugin1, Plugin plugin2 )
+    {
+        if ( plugin1.getArtifactId() == null && plugin2.getArtifactId() == null )
+        {
+            return 0;
+        }
+        if ( plugin1.getArtifactId() == null )
+        {
+            return -1;
+        }
+        if ( plugin2.getArtifactId() == null )
+        {
+            return 1;
+        }
+        return plugin1.getArtifactId().compareTo( plugin2.getArtifactId() );
+    }
+}

Propchange: maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/PluginComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/PluginComparator.java
------------------------------------------------------------------------------
    svn:keywords = Date Id

Added: maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/ReportPluginComparator.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/ReportPluginComparator.java?view=auto&rev=567438
==============================================================================
--- maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/ReportPluginComparator.java (added)
+++ maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/ReportPluginComparator.java Sun Aug 19 10:29:20 2007
@@ -0,0 +1,109 @@
+package org.apache.maven.model.converter;
+
+/*
+ * 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 org.apache.maven.model.ReportPlugin;
+
+import java.util.Comparator;
+
+/**
+ * A comparator for <code>ReportPlugin</code>s. It compares the reportplugins'
+ * groupIds and artifactIds.
+ *
+ * @author Dennis Lundberg
+ * @version $Id$
+ */
+public class ReportPluginComparator
+    implements Comparator
+{
+    public int compare( Object o1, Object o2 )
+    {
+        // Check for null objects
+        if ( o1 == null && o2 == null )
+        {
+            return 0;
+        }
+        if ( o1 == null )
+        {
+            return -1;
+        }
+        if ( o2 == null )
+        {
+            return 1;
+        }
+
+        // Check classes
+        if ( !( o1 instanceof ReportPlugin ) && !( o2 instanceof ReportPlugin ) )
+        {
+            return 0;
+        }
+        if ( !( o1 instanceof ReportPlugin ) )
+        {
+            return -1;
+        }
+        if ( !( o2 instanceof ReportPlugin ) )
+        {
+            return 1;
+        }
+        ReportPlugin plugin1 = (ReportPlugin) o1;
+        ReportPlugin plugin2 = (ReportPlugin) o2;
+
+        // Check for null values
+        if ( plugin1.getGroupId() == null && plugin2.getGroupId() == null )
+        {
+            return compareArtifactId( plugin1, plugin2 );
+        }
+        if ( plugin1.getGroupId() == null )
+        {
+            return -1;
+        }
+        if ( plugin2.getGroupId() == null )
+        {
+            return 1;
+        }
+
+        // Compare values
+        int answer;
+        answer = plugin1.getGroupId().compareTo( plugin2.getGroupId() );
+        if( answer == 0)
+        {
+            answer = compareArtifactId( plugin1, plugin2 );
+        }
+
+        return answer;
+    }
+
+    private int compareArtifactId( ReportPlugin plugin1, ReportPlugin plugin2 )
+    {
+        if ( plugin1.getArtifactId() == null && plugin2.getArtifactId() == null )
+        {
+            return 0;
+        }
+        if ( plugin1.getArtifactId() == null )
+        {
+            return -1;
+        }
+        if ( plugin2.getArtifactId() == null )
+        {
+            return 1;
+        }
+        return plugin1.getArtifactId().compareTo( plugin2.getArtifactId() );
+    }
+}

Propchange: maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/ReportPluginComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-model-converter/src/main/java/org/apache/maven/model/converter/ReportPluginComparator.java
------------------------------------------------------------------------------
    svn:keywords = Date Id

Added: maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/PluginComparatorTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/PluginComparatorTest.java?view=auto&rev=567438
==============================================================================
--- maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/PluginComparatorTest.java (added)
+++ maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/PluginComparatorTest.java Sun Aug 19 10:29:20 2007
@@ -0,0 +1,123 @@
+package org.apache.maven.model.converter;
+
+/*
+ * 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 org.apache.maven.model.Plugin;
+
+/**
+ * @author Dennis Lundberg
+ * @version $Id$
+ */
+public class PluginComparatorTest
+    extends TestCase
+{
+    Object object1;
+    Object object2;
+    Object object3;
+    Object object4;
+    Plugin plugin1;
+    Plugin plugin2;
+    Plugin plugin3;
+    Plugin plugin4;
+    Plugin plugin5;
+    Plugin plugin6;
+    Plugin plugin7;
+    Plugin plugin8;
+    Plugin plugin9;
+    Plugin plugin10;
+    PluginComparator comparator;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        object3 = new Object();
+        object4 = new Object();
+        plugin1 = new Plugin();
+        plugin1.setGroupId( null );
+        plugin1.setArtifactId( null );
+        plugin2 = new Plugin();
+        plugin2.setGroupId( null );
+        plugin2.setArtifactId( null );
+        plugin3 = new Plugin();
+        plugin3.setGroupId( "a" );
+        plugin3.setArtifactId( "d" );
+        plugin4 = new Plugin();
+        plugin4.setGroupId( "a" );
+        plugin4.setArtifactId( "d" );
+        plugin5 = new Plugin();
+        plugin5.setGroupId( "a" );
+        plugin5.setArtifactId( "c" );
+        plugin6 = new Plugin();
+        plugin6.setGroupId( "a" );
+        plugin6.setArtifactId( "e" );
+        plugin7 = new Plugin();
+        plugin7.setGroupId( "b" );
+        plugin7.setArtifactId( "b" );
+        plugin8 = new Plugin();
+        plugin8.setGroupId( "b" );
+        plugin8.setArtifactId( "e" );
+        plugin9 = new Plugin();
+        plugin9.setGroupId( null );
+        plugin9.setArtifactId( "e" );
+        plugin10 = new Plugin();
+        plugin10.setGroupId( "a" );
+        plugin10.setArtifactId( null );
+        comparator = new PluginComparator();
+    }
+
+    public void testClass()
+    {
+        assertEquals( "Test class", 0, comparator.compare( object3, object4 ) );
+        assertEquals( "Test class", 1, comparator.compare( plugin1, object4 ) );
+        assertEquals( "Test class", -1, comparator.compare( object3, plugin2 ) );
+    }
+
+    public void testNullObjects()
+    {
+        assertEquals( "Test null objects", 0, comparator.compare( object1, object2 ) );
+        assertEquals( "Test null objects", -1, comparator.compare( object1, object3 ) );
+        assertEquals( "Test null objects", 1, comparator.compare( object3, object2 ) );
+    }
+
+    public void testNullValues()
+    {
+        assertEquals( "Test null values", -1, comparator.compare( plugin1, plugin3 ) );
+        assertEquals( "Test null values", 1, comparator.compare( plugin3, plugin1 ) );
+        assertEquals( "Test null values", -1, comparator.compare( plugin1, plugin9 ) );
+        assertEquals( "Test null values", 1, comparator.compare( plugin9, plugin1 ) );
+        assertEquals( "Test null values", -1, comparator.compare( plugin1, plugin10 ) );
+        assertEquals( "Test null values", 1, comparator.compare( plugin10, plugin1 ) );
+        assertEquals( "Test null values", -1, comparator.compare( plugin9, plugin10 ) );
+        assertEquals( "Test null values", 1, comparator.compare( plugin10, plugin9 ) );
+    }
+
+    public void testValues()
+    {
+        assertEquals( "Test values", 0, comparator.compare( plugin3, plugin4 ) );
+        assertEquals( "Test values", 1, comparator.compare( plugin3, plugin5 ) );
+        assertEquals( "Test values", -1, comparator.compare( plugin5, plugin3 ) );
+        assertEquals( "Test values", -1, comparator.compare( plugin3, plugin6 ) );
+        assertEquals( "Test values", 1, comparator.compare( plugin6, plugin3 ) );
+        assertEquals( "Test values", -1, comparator.compare( plugin3, plugin7 ) );
+        assertEquals( "Test values", 1, comparator.compare( plugin7, plugin3 ) );
+    }
+}

Propchange: maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/PluginComparatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/PluginComparatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Id

Added: maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/ReportPluginComparatorTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/ReportPluginComparatorTest.java?view=auto&rev=567438
==============================================================================
--- maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/ReportPluginComparatorTest.java (added)
+++ maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/ReportPluginComparatorTest.java Sun Aug 19 10:29:20 2007
@@ -0,0 +1,123 @@
+package org.apache.maven.model.converter;
+
+/*
+ * 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 org.apache.maven.model.ReportPlugin;
+
+/**
+ * @author Dennis Lundberg
+ * @version $Id$
+ */
+public class ReportPluginComparatorTest
+    extends TestCase
+{
+    Object object1;
+    Object object2;
+    Object object3;
+    Object object4;
+    ReportPlugin plugin1;
+    ReportPlugin plugin2;
+    ReportPlugin plugin3;
+    ReportPlugin plugin4;
+    ReportPlugin plugin5;
+    ReportPlugin plugin6;
+    ReportPlugin plugin7;
+    ReportPlugin plugin8;
+    ReportPlugin plugin9;
+    ReportPlugin plugin10;
+    ReportPluginComparator comparator;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        object3 = new Object();
+        object4 = new Object();
+        plugin1 = new ReportPlugin();
+        plugin1.setGroupId( null );
+        plugin1.setArtifactId( null );
+        plugin2 = new ReportPlugin();
+        plugin2.setGroupId( null );
+        plugin2.setArtifactId( null );
+        plugin3 = new ReportPlugin();
+        plugin3.setGroupId( "a" );
+        plugin3.setArtifactId( "d" );
+        plugin4 = new ReportPlugin();
+        plugin4.setGroupId( "a" );
+        plugin4.setArtifactId( "d" );
+        plugin5 = new ReportPlugin();
+        plugin5.setGroupId( "a" );
+        plugin5.setArtifactId( "c" );
+        plugin6 = new ReportPlugin();
+        plugin6.setGroupId( "a" );
+        plugin6.setArtifactId( "e" );
+        plugin7 = new ReportPlugin();
+        plugin7.setGroupId( "b" );
+        plugin7.setArtifactId( "b" );
+        plugin8 = new ReportPlugin();
+        plugin8.setGroupId( "b" );
+        plugin8.setArtifactId( "e" );
+        plugin9 = new ReportPlugin();
+        plugin9.setGroupId( null );
+        plugin9.setArtifactId( "e" );
+        plugin10 = new ReportPlugin();
+        plugin10.setGroupId( "a" );
+        plugin10.setArtifactId( null );
+        comparator = new ReportPluginComparator();
+    }
+
+    public void testClass()
+    {
+        assertEquals( "Test class", 0, comparator.compare( object3, object4 ) );
+        assertEquals( "Test class", 1, comparator.compare( plugin1, object4 ) );
+        assertEquals( "Test class", -1, comparator.compare( object3, plugin2 ) );
+    }
+
+    public void testNullObjects()
+    {
+        assertEquals( "Test null objects", 0, comparator.compare( object1, object2 ) );
+        assertEquals( "Test null objects", -1, comparator.compare( object1, object3 ) );
+        assertEquals( "Test null objects", 1, comparator.compare( object3, object2 ) );
+    }
+
+    public void testNullValues()
+    {
+        assertEquals( "Test null values", -1, comparator.compare( plugin1, plugin3 ) );
+        assertEquals( "Test null values", 1, comparator.compare( plugin3, plugin1 ) );
+        assertEquals( "Test null values", -1, comparator.compare( plugin1, plugin9 ) );
+        assertEquals( "Test null values", 1, comparator.compare( plugin9, plugin1 ) );
+        assertEquals( "Test null values", -1, comparator.compare( plugin1, plugin10 ) );
+        assertEquals( "Test null values", 1, comparator.compare( plugin10, plugin1 ) );
+        assertEquals( "Test null values", -1, comparator.compare( plugin9, plugin10 ) );
+        assertEquals( "Test null values", 1, comparator.compare( plugin10, plugin9 ) );
+    }
+
+    public void testValues()
+    {
+        assertEquals( "Test values", 0, comparator.compare( plugin3, plugin4 ) );
+        assertEquals( "Test values", 1, comparator.compare( plugin3, plugin5 ) );
+        assertEquals( "Test values", -1, comparator.compare( plugin5, plugin3 ) );
+        assertEquals( "Test values", -1, comparator.compare( plugin3, plugin6 ) );
+        assertEquals( "Test values", 1, comparator.compare( plugin6, plugin3 ) );
+        assertEquals( "Test values", -1, comparator.compare( plugin3, plugin7 ) );
+        assertEquals( "Test values", 1, comparator.compare( plugin7, plugin3 ) );
+    }
+}

Propchange: maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/ReportPluginComparatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-model-converter/src/test/java/org/apache/maven/model/converter/ReportPluginComparatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Id