Beispiel #1
0
 @Test
 public void relativizeWithDotDotPathDoesNotAddExtraDotDotPath() {
   // Ensure workaround for bug JDK-6925169 for ".." case.
   Path p1 = Paths.get("a/../b");
   Path p2 = Paths.get("c/d/e");
   assertThat(MorePaths.relativize(p1, p2), equalTo(Paths.get("../c/d/e")));
 }
Beispiel #2
0
 @Test
 public void relativeWithEmptyPath() {
   // Ensure workaround for Windows Path relativize bug
   Path p1 = Paths.get("");
   Path p2 = Paths.get("foo");
   assertThat(MorePaths.relativize(p1, p2), equalTo(Paths.get("foo")));
 }
Beispiel #3
0
 /**
  * @param path Absolute path or path relative to the project root.
  * @return If {@code path} is relative, it is returned. If it is absolute and is inside the
  *     project root, it is relativized to the project root and returned. Otherwise an absent value
  *     is returned.
  */
 public Optional<Path> getPathRelativeToProjectRoot(Path path) {
   path = path.normalize();
   if (path.isAbsolute()) {
     if (path.startsWith(projectRoot)) {
       return Optional.of(MorePaths.relativize(projectRoot, path));
     } else {
       return Optional.absent();
     }
   } else {
     return Optional.of(path);
   }
 }