public static String getRelativePath(File basePath, File path) {\r
File exactBase = getExactFile(basePath);\r
File exactPath = getExactFile(path);\r
- return StringUtils.getRelativePath(exactBase.getPath(), exactPath.getPath());\r
+ if (exactPath.getPath().startsWith(exactBase.getPath())) {\r
+ // canonical base-path match\r
+ return StringUtils.getRelativePath(exactBase.getPath(), exactPath.getPath());\r
+ } else if (exactPath.getPath().startsWith(basePath.getAbsolutePath())) {\r
+ // mixed path match\r
+ return StringUtils.getRelativePath(basePath.getAbsolutePath(), exactPath.getPath());\r
+ } else if (path.getAbsolutePath().startsWith(exactBase.getPath())) {\r
+ // mixed path match\r
+ return StringUtils.getRelativePath(exactBase.getPath(), path.getAbsolutePath());\r
+ } else if (path.getAbsolutePath().startsWith(basePath.getAbsolutePath())) {\r
+ // absolute base-path match\r
+ return StringUtils.getRelativePath(basePath.getAbsolutePath(), path.getAbsolutePath());\r
+ }\r
+ // no relative relationship\r
+ return null;\r
}\r
\r
/**\r