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/07/15 21:14:42 UTC

svn commit: r556436 - /maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java

Author: dennisl
Date: Sun Jul 15 12:14:41 2007
New Revision: 556436

URL: http://svn.apache.org/viewvc?view=rev&rev=556436
Log:
[MIDEA-98] Module filepath is generated incorrectly

Always converting the drive letter to upper case before calculating the relative path, solved the problem.

Modified:
    maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java

Modified: maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java?view=diff&rev=556436&r1=556435&r2=556436
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java (original)
+++ maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java Sun Jul 15 12:14:41 2007
@@ -212,20 +212,49 @@
     protected String toRelative( File basedir, String absolutePath )
     {
         String relative;
+        String convertedBasedirAbsolutePath = convertDriveLetter( basedir.getAbsolutePath() );
+        String convertedAbsolutePath = convertDriveLetter( absolutePath );
 
-        if ( absolutePath.startsWith( basedir.getAbsolutePath() )
-            && absolutePath.length() > basedir.getAbsolutePath().length() )
+        if ( convertedAbsolutePath.startsWith( convertedBasedirAbsolutePath )
+            && convertedAbsolutePath.length() > convertedBasedirAbsolutePath.length() )
         {
-            relative = absolutePath.substring( basedir.getAbsolutePath().length() + 1 );
+            relative = convertedAbsolutePath.substring( convertedBasedirAbsolutePath.length() + 1 );
         }
         else
         {
-            relative = absolutePath;
+            relative = convertedAbsolutePath;
         }
 
         relative = StringUtils.replace( relative, "\\", "/" );
 
+        if ( getLog().isDebugEnabled() )
+        {
+            getLog().debug( "toRelative(" + basedir + ", " + absolutePath + ") => " + relative );
+        }
+
         return relative;
+    }
+
+    /**
+     * Convert the drive letter, if there is one, to upper case. This is done
+     * to avoid case mismatch when running cygwin on Windows.
+     *
+     * @param absolutePath The path to convert
+     * @return The path that came in with its drive letter converted to upper case
+     */
+    private String convertDriveLetter( String absolutePath )
+    {
+        if ( absolutePath != null && absolutePath.length() >= 3 && !absolutePath.startsWith( "/" ) )
+        {
+            // See if the path starts with "?:\", where ? must be a letter
+            if ( Character.isLetter( absolutePath.substring( 0, 1 ).charAt( 0 ) )
+                && absolutePath.substring( 1, 3 ).equals( ":\\" ) )
+            {
+                // In that case we convert the first character to upper case
+                return absolutePath.substring( 0, 1 ).toUpperCase() + absolutePath.substring( 1 );
+            }
+        }
+        return absolutePath;
     }
 
     /**