Index: src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java =================================================================== --- src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java (revision 559855) +++ src/main/java/org/apache/maven/plugin/idea/AbstractIdeaMojo.java (working copy) @@ -50,14 +50,7 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * @author Edwin Punzalan @@ -218,15 +211,103 @@ if ( convertedAbsolutePath.startsWith( convertedBasedirAbsolutePath ) && convertedAbsolutePath.length() > convertedBasedirAbsolutePath.length() ) { + // simple case, path starts with basepath relative = convertedAbsolutePath.substring( convertedBasedirAbsolutePath.length() + 1 ); + relative = StringUtils.replace( relative, "\\", "/" ); } else { - relative = convertedAbsolutePath; + // it's more complex... + convertedAbsolutePath = StringUtils.replace( convertedAbsolutePath, "\\", "/" ); + convertedBasedirAbsolutePath = StringUtils.replace( convertedBasedirAbsolutePath, "\\", "/" ); + + StringTokenizer baseTokens=new StringTokenizer(convertedBasedirAbsolutePath,"/",false); + + int baseCount=baseTokens.countTokens(); + List baseTokenList=new ArrayList(baseCount); + while(baseTokens.hasMoreTokens()) + { + baseTokenList.add(baseTokens.nextToken()); + } + + StringTokenizer pathTokens=new StringTokenizer(convertedAbsolutePath,"/",false); + + int pathCount=pathTokens.countTokens(); + List pathTokenList=new ArrayList(pathCount); + while(pathTokens.hasMoreTokens()) + { + pathTokenList.add(pathTokens.nextToken()); + } + + int maxCount=Math.max(baseTokenList.size(), pathTokenList.size()); + int differIndex=-1; + for(int i=0;i=pathTokenList.size() || i>=baseTokenList.size()) + { + differIndex=i; + break; + } + String basePart=(String) baseTokenList.get(i); + String pathPart=(String) pathTokenList.get(i); + if(!basePart.equals(pathPart)) + { + differIndex=i; + break; + } + } + /* + if ( getLog().isDebugEnabled() ) + { + getLog().debug( "Construction of relative path... differIndex="+differIndex); + } + */ + if(differIndex<1) + { + // paths are either equal or completely different + relative=convertedAbsolutePath; + } + else + { + StringBuffer result=new StringBuffer(); + int parentCount=baseTokenList.size()-differIndex; + /* + if ( getLog().isDebugEnabled() ) + { + getLog().debug( "parentCount="+parentCount); + } + */ + boolean isFirst=true; + for(int i=0;i " + relative );