Author: dennisl
Date: Sat Jul 19 09:45:24 2008
New Revision: 678183
URL: http://svn.apache.org/viewvc?rev=678183&view=rev
Log:
o Change toRelative() to take a String parameter instead of a File. This was
necessary to be able to make the tests work across different operating systems.
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaMojoTestCase.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?rev=678183&r1=678182&r2=678183&view=diff
==============================================================================
---
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
Sat Jul 19 09:45:24 2008
@@ -210,26 +210,38 @@
* @param absolutePath The absolute path that must be translated to
relative path.
* @return relative Relative path of the parameter absolute path.
*/
- protected String toRelative( File basedir, String absolutePath )
+ protected String toRelative( String basedir, String absolutePath )
{
String relative;
- String convertedBasedirAbsolutePath = convertDriveLetter(
basedir.getAbsolutePath() );
+
+ // Convert drive letter
+ String convertedBasedir = convertDriveLetter( basedir );
String convertedAbsolutePath = convertDriveLetter( absolutePath );
- if ( convertedAbsolutePath.startsWith( convertedBasedirAbsolutePath )
- && convertedAbsolutePath.length() >
convertedBasedirAbsolutePath.length() )
+ // Normalize path separators
+ convertedBasedir = StringUtils.replace( convertedBasedir, "\\", "/" );
+ convertedAbsolutePath = StringUtils.replace( convertedAbsolutePath,
"\\", "/" );
+
+ // Strip trailing slash
+ if( convertedBasedir.endsWith( "/" ) )
+ {
+ convertedBasedir = convertedBasedir.substring( 0,
convertedBasedir.length() - 1 );
+ }
+ if( convertedAbsolutePath.endsWith( "/" ) )
+ {
+ convertedAbsolutePath = convertedAbsolutePath.substring( 0,
convertedAbsolutePath.length() - 1 );
+ }
+
+ if ( convertedAbsolutePath.startsWith( convertedBasedir )
+ && convertedAbsolutePath.length() > convertedBasedir.length() )
{
// Simple case, path starts with basepath
- relative = convertedAbsolutePath.substring(
convertedBasedirAbsolutePath.length() + 1 );
- relative = StringUtils.replace( relative, "\\", "/" );
+ relative = convertedAbsolutePath.substring(
convertedBasedir.length() + 1 );
}
else
{
// It's more complex...
- convertedAbsolutePath = StringUtils.replace(
convertedAbsolutePath, "\\", "/" );
- convertedBasedirAbsolutePath = StringUtils.replace(
convertedBasedirAbsolutePath, "\\", "/" );
-
- StringTokenizer baseTokens = new StringTokenizer(
convertedBasedirAbsolutePath, "/", false );
+ StringTokenizer baseTokens = new StringTokenizer(
convertedBasedir, "/", false );
int baseCount = baseTokens.countTokens();
List baseTokenList = new ArrayList( baseCount );
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java?rev=678183&r1=678182&r2=678183&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaModuleMojo.java
Sat Jul 19 09:45:24 2008
@@ -866,7 +866,7 @@
*/
private String getModuleFileUrl( File basedir, String path )
{
- return "file://$MODULE_DIR$/" + toRelative( basedir, path );
+ return "file://$MODULE_DIR$/" + toRelative( basedir.getAbsolutePath(),
path );
}
private String getModuleFileUrl( String file )
Modified:
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java?rev=678183&r1=678182&r2=678183&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
Sat Jul 19 09:45:24 2008
@@ -175,7 +175,7 @@
new File( executedProject.getBasedir(),
executedProject.getArtifactId() + ".iml"
).getAbsolutePath();
m.addAttribute( "filepath",
- "$PROJECT_DIR$/" + toRelative(
executedProject.getBasedir(), projectPath ) );
+ "$PROJECT_DIR$/" + toRelative(
executedProject.getBasedir().getAbsolutePath(), projectPath ) );
for ( Iterator i =
executedProject.getCollectedProjects().iterator(); i.hasNext(); )
{
@@ -184,7 +184,7 @@
m = createElement( modules, "module" );
String modulePath = new File( p.getBasedir(),
p.getArtifactId() + ".iml" ).getAbsolutePath();
m.addAttribute( "filepath",
- "$PROJECT_DIR$/" + toRelative(
executedProject.getBasedir(), modulePath ) );
+ "$PROJECT_DIR$/" + toRelative(
executedProject.getBasedir().getAbsolutePath(), modulePath ) );
}
}
else
@@ -193,7 +193,7 @@
String modulePath =
new File( executedProject.getBasedir(),
executedProject.getArtifactId() + ".iml"
).getAbsolutePath();
- m.addAttribute( "filepath", "$PROJECT_DIR$/" + toRelative(
executedProject.getBasedir(), modulePath ) );
+ m.addAttribute( "filepath", "$PROJECT_DIR$/" + toRelative(
executedProject.getBasedir().getAbsolutePath(), modulePath ) );
}
// add any PathMacros we've come across
Modified:
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaMojoTestCase.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaMojoTestCase.java?rev=678183&r1=678182&r2=678183&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaMojoTestCase.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaMojoTestCase.java
Sat Jul 19 09:45:24 2008
@@ -41,12 +41,36 @@
{
String relativePath;
- relativePath = mojo.toRelative( new File( "C:/dev/voca/gateway/" ),
-
"C:/dev/voca/gateway/parser/gateway-parser.iml" );
- assertEquals( "Test toRelative child", "parser/gateway-parser.iml",
relativePath );
-
- relativePath = mojo.toRelative( new File( "C:\\foo\\master " ),
- "C:\\foo\\child" );
- assertEquals( "Test toRelative sibling", "../child", relativePath );
+ relativePath = mojo.toRelative( "C:\\dev\\voca\\gateway",
+
"C:/dev/voca/gateway/parser/gateway-parser.iml" );
+ assertEquals( "Test toRelative child, backslash",
"parser/gateway-parser.iml", relativePath );
+
+ relativePath = mojo.toRelative( "C:\\dev\\voca\\gateway\\",
+
"C:/dev/voca/gateway/parser/gateway-parser.iml" );
+ assertEquals( "Test toRelative child, trailing backslash",
"parser/gateway-parser.iml", relativePath );
+
+ relativePath = mojo.toRelative( "C:/dev/voca/gateway",
+
"C:/dev/voca/gateway/parser/gateway-parser.iml" );
+ assertEquals( "Test toRelative child, slash",
"parser/gateway-parser.iml", relativePath );
+
+ relativePath = mojo.toRelative( "C:/dev/voca/gateway/",
+
"C:/dev/voca/gateway/parser/gateway-parser.iml" );
+ assertEquals( "Test toRelative child, trailing slash",
"parser/gateway-parser.iml", relativePath );
+
+ relativePath = mojo.toRelative( "C:\\foo\\master",
+ "C:\\foo\\child" );
+ assertEquals( "Test toRelative sibling, no trailing backspace",
"../child", relativePath );
+
+ relativePath = mojo.toRelative( "C:\\foo\\master\\",
+ "C:\\foo\\child" );
+ assertEquals( "Test toRelative sibling, first trailing backspace",
"../child", relativePath );
+
+ relativePath = mojo.toRelative( "C:\\foo\\master",
+ "C:\\foo\\child\\" );
+ assertEquals( "Test toRelative sibling, second trailing backspace",
"../child", relativePath );
+
+ relativePath = mojo.toRelative( "C:\\foo\\master\\",
+ "C:\\foo\\child\\" );
+ assertEquals( "Test toRelative sibling, both trailing backspace",
"../child", relativePath );
}
}
\ No newline at end of file