maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r658214 - in /maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers: EclipseClasspathWriter.java EclipseProjectWriter.java
Date Tue, 20 May 2008 12:02:38 GMT
Author: nicolas
Date: Tue May 20 05:02:38 2008
New Revision: 658214

URL: http://svn.apache.org/viewvc?rev=658214&view=rev
Log:
MECLIPSE-397 : avoid duplicate entries in eclipse project references when same artifact is
used as dependency with multuple classifiers / types

Modified:
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java?rev=658214&r1=658213&r2=658214&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
(original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
Tue May 20 05:02:38 2008
@@ -45,7 +45,7 @@
 
 /**
  * Writes eclipse .classpath file.
- * 
+ *
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @author <a href="mailto:kenney@neonics.com">Kenney Westerhof</a>
  * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
@@ -328,7 +328,7 @@
         // TODO if (..magic property equals orderDependencies..)
 
 		// ----------------------------------------------------------------------
-        // Java API dependencies that may complete the classpath container so must 
+        // Java API dependencies that may complete the classpath container so must
 		// be declared BEFORE so that container access rules don't fail
         // ----------------------------------------------------------------------
         IdeDependency[] depsToWrite = config.getDepsOrdered();
@@ -337,13 +337,15 @@
             IdeDependency dep = depsToWrite[j];
 			if ( dep.isJavaApi() )
 			{
-				String depId =
-                    dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getClassifier()
+ ":" + dep.getVersion();
-				addDependency( writer, dep );
-				addedDependencies.add( depId );
+				String depId = getDependencyId( dep );
+				if ( !addedDependencies.contains( depId ) )
+                {
+				    addDependency( writer, dep );
+	                addedDependencies.add( depId );
+                }
 			}
 		}
-		
+
         // ----------------------------------------------------------------------
         // Container classpath entries
         // ----------------------------------------------------------------------
@@ -365,12 +367,11 @@
 
             if ( dep.isAddedToClasspath() )
             {
-                String depId =
-                    dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getClassifier()
+ ":" + dep.getVersion();
-                /* avoid duplicates in the classpath for artifacts with different types (like
ejbs) */
+                String depId = getDependencyId( dep );
+                /* avoid duplicates in the classpath for artifacts with different types (like
ejbs or test-jars) */
                 if ( !addedDependencies.contains( depId ) )
                 {
-                    addDependency( writer, dep );
+	                addDependency( writer, dep );
                     addedDependencies.add( depId );
                 }
             }
@@ -382,6 +383,19 @@
 
     }
 
+    private String getDependencyId( IdeDependency dep )
+    {
+        String depId =
+            dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getClassifier() + ":"
+ dep.getVersion();
+
+        if ( dep.isReferencedProject() )
+        {
+            // This dependency will be refered as an eclipse project
+            depId = dep.getEclipseProjectName();
+        }
+        return depId;
+    }
+
     protected void addDependency( XMLWriter writer, IdeDependency dep )
         throws MojoExecutionException
     {

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java?rev=658214&r1=658213&r2=658214&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java
(original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java
Tue May 20 05:02:38 2008
@@ -26,6 +26,7 @@
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -47,7 +48,7 @@
 
 /**
  * Writes eclipse .project file.
- * 
+ *
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @author <a href="mailto:kenney@neonics.com">Kenney Westerhof</a>
  * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
@@ -188,14 +189,18 @@
         // referenced projects should not be added for plugins
         if ( !config.isPde() )
         {
+            List duplicates = new ArrayList();
             for ( int j = 0; j < config.getDepsOrdered().length; j++ )
             {
                 IdeDependency dep = config.getDepsOrdered()[j];
-                if ( dep.isReferencedProject() )
+                // Avoid duplicates entries when same project is refered using multiple types
+                // (ejb, test-jar ...)
+                if ( dep.isReferencedProject() && ! duplicates.contains( dep.getEclipseProjectName()
))
                 {
                     writer.startElement( "project" ); //$NON-NLS-1$
                     writer.writeText( dep.getEclipseProjectName() );
                     writer.endElement();
+                    duplicates.add( dep.getEclipseProjectName() );
                 }
             }
         }



Mime
View raw message