@Override public Path getRoot() { return delegate.getRoot(); }
/** * Resolves this path against another relative path (by the name elements of {@code * relativePath}). * * @param relativePath the relative path to resolve against * @return a new {@link AbsoluteUnixPath} representing the resolved path */ public AbsoluteUnixPath resolve(Path relativePath) { Preconditions.checkArgument( relativePath.getRoot() == null, "Cannot resolve against absolute Path: " + relativePath); return AbsoluteUnixPath.fromPath(Paths.get(unixPath).resolve(relativePath)); }
protected static String calculateDefaultOutputDirectory(Path currentPath) { Path currentAbsolutePath = currentPath.toAbsolutePath(); Path parent = currentAbsolutePath.getParent(); if (currentAbsolutePath.getRoot().equals(parent)) { return parent.toString(); } else { Path currentNormalizedPath = currentAbsolutePath.normalize(); return "../" + currentNormalizedPath.getFileName().toString(); } }
private static Path searchPath(final Path path, final int globIndex) { Path root = path.getRoot(); Path subpath = path.subpath(0, globIndex); if (root == null) { return subpath; } return Paths.get(root.toString(), subpath.toString()); }
/** * Gets a new {@link AbsoluteUnixPath} from a {@link Path}. The {@code path} must be absolute * (indicated by a non-null {@link Path#getRoot}). * * @param path the absolute {@link Path} to convert to an {@link AbsoluteUnixPath}. * @return a new {@link AbsoluteUnixPath} */ public static AbsoluteUnixPath fromPath(Path path) { Preconditions.checkArgument( path.getRoot() != null, "Cannot create AbsoluteUnixPath from non-absolute Path: " + path); ImmutableList.Builder<String> pathComponents = ImmutableList.builderWithExpectedSize(path.getNameCount()); for (Path pathComponent : path) { pathComponents.add(pathComponent.toString()); } return new AbsoluteUnixPath(pathComponents.build()); }
/** * Searches for a parent directory containing the natives directory * * @param startPath path to start from * @param maxDepth max directory levels to search * @return the adjusted path containing the natives directory or null if not found */ private Path findNativesHome(Path startPath, int maxDepth) { int levelsToSearch = maxDepth; Path checkedPath = startPath; while (levelsToSearch > 0) { File dirToTest = new File(checkedPath.toFile(), NATIVES_DIR); if (dirToTest.exists()) { System.out.println("Found the natives dir: " + dirToTest); return checkedPath; } checkedPath = checkedPath.getParent(); if (checkedPath.equals(startPath.getRoot())) { System.out.println("Uh oh, reached the root path, giving up"); return null; } levelsToSearch--; } System.out.println("Failed to find the natives dir within " + maxDepth + " levels of " + startPath); return null; }
/** * Adds a {@link TarArchiveEntry} if its extraction path does not exist yet. Also adds all of * the parent directories on the extraction path. * * @param tarArchiveEntry the {@link TarArchiveEntry} */ private void add(TarArchiveEntry tarArchiveEntry) { if (names.contains(tarArchiveEntry.getName())) { return; } // Adds all directories along extraction paths to explicitly set permissions for those // directories. Path namePath = Paths.get(tarArchiveEntry.getName()); if (namePath.getParent() != namePath.getRoot()) { add(new TarArchiveEntry(DIRECTORY_FILE, namePath.getParent().toString())); } entries.add(tarArchiveEntry); names.add(tarArchiveEntry.getName()); }
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") void npe6() throws IOException{ use(PATH.getRoot().getNameCount()); }
rootPath.resolve( urlPath.getRoot().relativize( urlPath ) ).normalize().toAbsolutePath();
Path built; if (dirNormalized.isAbsolute()) { built = dirNormalized.getRoot(); } else { built = Paths.get("");
assertNotNull("Files are not equal: Expected file is " + expectedFile + ", actual file is null.", actualFile); Path root = Paths.get(actualFile.getAbsolutePath()).getRoot(); FileVersionComparator fileVersionComparator = new FileVersionComparator(root.toFile(), "SHA1");
Path root = path.getRoot(); if (root != null)
private Path getGuestPath(Path guest, Path hostKid) { Path ret = guest.getRoot(); for ( Path el : hostKid ) { ret = ret.resolve(el.toString()); } return ret; }
private File findSourceRoot(String packageName, Path sourcePath) throws IOException { int packageSections = Math.toIntExact(packageName.codePoints().filter(ch -> ch =='.').count()) + 1 ; packageSections++;//increment to include actual filename return sourcePath.getRoot().resolve(sourcePath.subpath(0, sourcePath.getNameCount()-packageSections)).toFile(); }
@Test @Category( { Windows.class, RootComponent.class } ) public void testWindowsNoRootComponentGetRootHasNoRootComponent() { assertThat( FS.getPath( "\\foo" ).getRoot() ).isEqualTo( FS.getPath( "\\" ) ); }
static void info(Path p) { show("toString", p); show("Exists", Files.exists(p)); show("RegularFile", Files.isRegularFile(p)); show("Directory", Files.isDirectory(p)); show("Absolute", p.isAbsolute()); show("FileName", p.getFileName()); show("Parent", p.getParent()); show("Root", p.getRoot()); System.out.println("******************"); } public static void main(String[] args) {
@Test public void getPathRootFromEmptyString() { final Path path = fileSystem.getPath(""); Assert.assertNull("Root path of empty string should be null", path.getRoot()); }
@Test public void getRoot() { final Path path = fileSystem.getPath("/someNode"); final Path root = path.getRoot(); Assert.assertEquals("Did not return correct root", root.toString(), "/"); }
@Test public void getRootFromRelative() { final Path path = fileSystem.getPath("someNode"); final Path root = path.getRoot(); Assert.assertNull("Relative path should have null root", root); }