From b380d0e2d4b8914fe68b4da0eaed658a98175498 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 26 Aug 2005 08:05:47 +0000 Subject: [PATCH] make the ordering predictable by sorting the key set. Switched the key to be the simpler eclipse source root link name. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@240187 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/eclipse/EclipseWriter.java | 29 +++++++++++-------- .../src/test/projects/project-4/project | 18 ++++++------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWriter.java b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWriter.java index c53ad080c7..c9dd1304b1 100644 --- a/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWriter.java +++ b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWriter.java @@ -32,7 +32,9 @@ import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -357,9 +359,11 @@ public class EclipseWriter if ( new File( sourceRoot ).isDirectory() ) { + String eclipseSourceRoot = toRelative( projectBaseDir, sourceRoot ); + // Don't add the same sourceroots twice. No include/exclude // patterns possible in maven for (test|script|)source directories. - if ( addedSourceRoots.containsKey( sourceRoot ) ) + if ( addedSourceRoots.containsKey( eclipseSourceRoot ) ) { continue; } @@ -368,14 +372,12 @@ public class EclipseWriter writer.addAttribute( "kind", "src" ); - String eclipseSourceRoot = toRelative( projectBaseDir, sourceRoot ); - if (!projectBaseDir.equals(basedir)) { eclipseSourceRoot = eclipseSourceRoot.replaceAll( "/", "-" ); } - addedSourceRoots.put( sourceRoot, eclipseSourceRoot ); + addedSourceRoots.put( eclipseSourceRoot, sourceRoot ); writer.addAttribute( "path", eclipseSourceRoot ); @@ -419,21 +421,21 @@ public class EclipseWriter String resourceDir = resource.getDirectory(); + String eclipseResourceDir = toRelative( projectBaseDir, resourceDir ); + // don't add the same sourceroot twice; eclipse can't handle // that, even with mutual exclusive include/exclude patterns. - if ( addedSourceRoots.containsKey( resourceDir ) ) + if ( addedSourceRoots.containsKey( eclipseResourceDir ) ) { continue; } - String eclipseResourceDir = toRelative( projectBaseDir, resourceDir ); - if ( ! projectBaseDir.equals( basedir ) ) { eclipseResourceDir = eclipseResourceDir.replaceAll( "/", "-" ); } - addedSourceRoots.put( resourceDir, eclipseResourceDir ); + addedSourceRoots.put( eclipseResourceDir, resourceDir ); writer.startElement( "classpathentry" ); @@ -472,13 +474,16 @@ public class EclipseWriter private void addSourceLinks( XMLWriter writer, File projectBaseDir, File basedir, Map sourceRoots ) { - for ( Iterator it = sourceRoots.keySet().iterator(); it.hasNext(); ) + List roots = new ArrayList( sourceRoots.keySet() ); + Collections.sort( roots ); + + for ( Iterator it = roots.iterator(); it.hasNext(); ) { - String sourceRoot = (String) it.next(); + String linkName = (String) it.next(); - String linkName = (String) sourceRoots.get( sourceRoot ); + String sourceRoot = (String) sourceRoots.get( linkName ); - sourceRoot = sourceRoot.replaceAll("\\\\", "/"); + sourceRoot = sourceRoot.replace('\\', '/'); log.debug( "Adding link '" + linkName + "' to '" + sourceRoot + "'" ); diff --git a/maven-plugins/maven-eclipse-plugin/src/test/projects/project-4/project b/maven-plugins/maven-eclipse-plugin/src/test/projects/project-4/project index c74783adcc..86dec68c03 100644 --- a/maven-plugins/maven-eclipse-plugin/src/test/projects/project-4/project +++ b/maven-plugins/maven-eclipse-plugin/src/test/projects/project-4/project @@ -18,14 +18,9 @@ ${basedir}/src/test/projects/project-4/project.xml - src-test-resources + src-main-java 2 - ${basedir}/src/test/projects/project-4/src/test/resources - - - src-test-java - 2 - ${basedir}/src/test/projects/project-4/src/test/java + ${basedir}/src/test/projects/project-4/src/main/java src-main-resources @@ -33,9 +28,14 @@ ${basedir}/src/test/projects/project-4/src/main/resources - src-main-java + src-test-java 2 - ${basedir}/src/test/projects/project-4/src/main/java + ${basedir}/src/test/projects/project-4/src/test/java + + + src-test-resources + 2 + ${basedir}/src/test/projects/project-4/src/test/resources