Java Code Examples for java.nio.file.Path#toAbsolutePath()
The following examples show how to use
java.nio.file.Path#toAbsolutePath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JDKToolFinder.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static String getTool(String tool, String property) throws FileNotFoundException { String jdkPath = System.getProperty(property); if (jdkPath == null) { throw new RuntimeException( "System property '" + property + "' not set. This property is normally set by jtreg. " + "When running test separately, set this property using '-D" + property + "=/path/to/jdk'."); } Path toolName = Paths.get("bin", tool + (Platform.isWindows() ? ".exe" : "")); Path jdkTool = Paths.get(jdkPath, toolName.toString()); if (!jdkTool.toFile().exists()) { throw new FileNotFoundException("Could not find file " + jdkTool.toAbsolutePath()); } return jdkTool.toAbsolutePath().toString(); }
Example 2
Source File: PathFileObject.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Create a PathFileObject whose binary name might be inferred from its * position on a search path. */ static PathFileObject createSimplePathFileObject(JavacPathFileManager fileManager, final Path path) { return new PathFileObject(fileManager, path) { @Override String inferBinaryName(Iterable<? extends Path> paths) { Path absPath = path.toAbsolutePath(); for (Path p: paths) { Path ap = p.toAbsolutePath(); if (absPath.startsWith(ap)) { try { Path rp = ap.relativize(absPath); if (rp != null) // maybe null if absPath same as ap return toBinaryName(rp); } catch (IllegalArgumentException e) { // ignore this p if cannot relativize path to p } } } return null; } }; }
Example 3
Source File: ResultsAggregator.java From benchmarks with Apache License 2.0 | 6 votes |
public ResultsAggregator(final Path directory, final double reportOutputScalingRatio) { if (!exists(directory)) { throw new IllegalArgumentException("directory does not exist: " + directory.toAbsolutePath()); } if (!isDirectory(directory)) { throw new IllegalArgumentException(directory.toAbsolutePath() + " is not a directory!"); } if (isNaN(reportOutputScalingRatio) || compare(reportOutputScalingRatio, 0.0) <= 0) { throw new IllegalArgumentException( "report output value scale ratio must a positive number, got: " + reportOutputScalingRatio); } this.directory = directory; this.reportOutputScalingRatio = reportOutputScalingRatio; }
Example 4
Source File: MCRTransferPackageCommands.java From mycore with GNU General Public License v3.0 | 6 votes |
@MCRCommand(help = "Imports a transfer package located at {0}. Where {0} is the absolute path to the tar file. " + "The parameter {1} is optional and can be omitted. You can specify a mycore id where the first object of " + "import.xml should be attached.", syntax = "import transfer package from tar {0} to {1}") public static List<String> importTransferPackageFromTar(String pathToTar, String mycoreTargetId) throws Exception { Path tar = Paths.get(pathToTar); if (!Files.exists(tar)) { throw new FileNotFoundException(tar.toAbsolutePath() + " does not exist."); } Path targetDirectory = MCRTransferPackageUtil.getTargetDirectory(tar); List<String> commands = new ArrayList<>(); commands.add("_import transfer package untar " + pathToTar); commands.add("_import transfer package from directory " + targetDirectory + " to " + mycoreTargetId); commands.add("_import transfer package clean up " + targetDirectory); return commands; }
Example 5
Source File: ModContainer.java From fabric-loader with Apache License 2.0 | 6 votes |
void setupRootPath() { if (root != null) { throw new RuntimeException("Not allowed to setup mod root path twice!"); } try { Path holder = UrlUtil.asPath(originUrl).toAbsolutePath(); if (Files.isDirectory(holder)) { root = holder.toAbsolutePath(); } else /* JAR */ { FileSystemUtil.FileSystemDelegate delegate = FileSystemUtil.getJarFileSystem(holder, false); if (delegate.get() == null) { throw new RuntimeException("Could not open JAR file " + holder.getFileName() + " for NIO reading!"); } root = delegate.get().getRootDirectories().iterator().next(); // We never close here. It's fine. getJarFileSystem() will handle it gracefully, and so should mods } } catch (IOException | UrlConversionException e) { throw new RuntimeException("Failed to find root directory for mod '" + info.getId() + "'!", e); } }
Example 6
Source File: InfrastructurePlanGenerator.java From testgrid with Apache License 2.0 | 6 votes |
private void validate(Path templatePath, Map<String, String> inputParams, Path output) { if (!Files.exists(templatePath)) { throw new IllegalArgumentException("Provided template path '" + templatePath + "' does not exist."); } output = output.toAbsolutePath(); Path outputParent = output.getParent(); if (outputParent != null && !Files.exists(outputParent)) { throw new IllegalArgumentException("Output cannot be created, its parent folder does not exist'" + output.getParent()); } else if (Files.exists(output)) { logger.warn("Output path exists already. It will be overwritten: " + output); } }
Example 7
Source File: JDKToolFinder.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private static String getTool(String tool, String property) throws FileNotFoundException { String jdkPath = System.getProperty(property); if (jdkPath == null) { throw new RuntimeException( "System property '" + property + "' not set. This property is normally set by jtreg. " + "When running test separately, set this property using '-D" + property + "=/path/to/jdk'."); } Path toolName = Paths.get("bin", tool + (Platform.isWindows() ? ".exe" : "")); Path jdkTool = Paths.get(jdkPath, toolName.toString()); if (!jdkTool.toFile().exists()) { throw new FileNotFoundException("Could not find file " + jdkTool.toAbsolutePath()); } return jdkTool.toAbsolutePath().toString(); }
Example 8
Source File: JDKToolFinder.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static String getTool(String tool, String property) throws FileNotFoundException { String jdkPath = System.getProperty(property); if (jdkPath == null) { throw new RuntimeException( "System property '" + property + "' not set. This property is normally set by jtreg. " + "When running test separately, set this property using '-D" + property + "=/path/to/jdk'."); } Path toolName = Paths.get("bin", tool + (Platform.isWindows() ? ".exe" : "")); Path jdkTool = Paths.get(jdkPath, toolName.toString()); if (!jdkTool.toFile().exists()) { throw new FileNotFoundException("Could not find file " + jdkTool.toAbsolutePath()); } return jdkTool.toAbsolutePath().toString(); }
Example 9
Source File: DossierFileSystem.java From js-dossier with Apache License 2.0 | 5 votes |
/** * Returns the path of the given source file relative to the common input source directory. * * @throws IllegalArgumentException if the given file is not under the common source directory. */ public Path getSourceRelativePath(Path sourceFile) { if (sourcePrefix.isAbsolute()) { sourceFile = sourceFile.toAbsolutePath(); } checkArgument( sourceFile.startsWith(sourcePrefix), "The requested path is not a recognized source file: %s", sourceFile); return sourcePrefix.relativize(sourceFile.normalize()); }
Example 10
Source File: IjSourceRootSimplifier.java From buck with Apache License 2.0 | 5 votes |
public BottomUpPathMerger( Iterable<IjFolder> foldersToWalk, int limit, Path moduleLocation, PackagePathCache packagePathCache, ImmutableSet<Path> traversalBoundaryPaths) { this.tree = new MutableDirectedGraph<>(); this.packagePathCache = packagePathCache; this.mergePathsMap = new HashMap<>(); this.moduleLocation = moduleLocation.toAbsolutePath(); for (IjFolder folder : foldersToWalk) { Path path = folder.getPath(); mergePathsMap.put(path, folder); while (getPathNameCount(path) > limit) { Path parent = this.moduleLocation.resolve(path).getParent(); if (parent == null) { break; } parent = this.moduleLocation.relativize(parent); boolean isParentAndGrandParentAlreadyInTree = tree.containsNode(parent); tree.addEdge(parent, path); if (isParentAndGrandParentAlreadyInTree) { break; } path = parent; } } topLevels = findTopLevels(foldersToWalk, traversalBoundaryPaths); }
Example 11
Source File: GoldenMasterProviderImpl.java From recheck with GNU Affero General Public License v3.0 | 5 votes |
private Path getStates( final Path projectRoot, final String filePath ) { if ( projectRoot != null && filePath != null ) { logger.debug( "Looking for Golden Master files in '{}'.", projectRoot ); final Path statePath = Paths.get( projectRoot.toAbsolutePath().toString(), filePath ); if ( statePath.toFile().exists() ) { return statePath.toAbsolutePath(); } } return null; }
Example 12
Source File: FileKeyStore.java From orion with Apache License 2.0 | 5 votes |
private List<String> readPasswords(final Path passwords) throws IOException { try { return Files.readAllLines(passwords); } catch (final IOException ex) { throw new IOException("Failed to read password list '" + passwords.toAbsolutePath() + "'", ex); } }
Example 13
Source File: Pubber.java From daq with Apache License 2.0 | 5 votes |
private byte[] getFileBytes(String dataFile) { Path dataPath = Paths.get(dataFile); try { return Files.readAllBytes(dataPath); } catch (Exception e) { throw new RuntimeException("While getting data from " + dataPath.toAbsolutePath(), e); } }
Example 14
Source File: KnativeUtils.java From module-ballerina-kubernetes with Apache License 2.0 | 5 votes |
/** * Deletes a given directory. * * @param path path to directory * @throws KubernetesPluginException if an error occurs while deleting */ public static void deleteDirectory(Path path) throws KubernetesPluginException { Path pathToBeDeleted = path.toAbsolutePath(); if (!Files.exists(pathToBeDeleted)) { return; } try { Files.walk(pathToBeDeleted) .sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } catch (IOException e) { throw new KubernetesPluginException("unable to delete directory: " + path, e); } }
Example 15
Source File: LiveSource.java From clarity with BSD 3-Clause "New" or "Revised" License | 5 votes |
public LiveSource(Path filePath, long timeout, TimeUnit timeUnit) { this.timeout = timeout; this.timeUnit = timeUnit; this.filePath = filePath.toAbsolutePath(); resetLastTick(); handleFileChange(); final Thread watcherThread = new Thread(this::watcherThread); watcherThread.setName("clarity-livesource-watcher"); watcherThread.setDaemon(true); watcherThread.start(); }
Example 16
Source File: PathDemos.java From Advanced_Java with MIT License | 5 votes |
public static void main(String[] args) { // Using Paths.get(...) to create a Path Path dictionary = Paths.get("/", "usr", "share", "dict", "web2"); System.out.println(dictionary); Path home = Paths.get("/Users/kousen"); System.out.println(home); // Using resolve to find nested paths Path docs = home.resolve("Documents"); System.out.println(docs); // Can resolve siblings as well Path downloads = docs.resolveSibling("Downloads"); System.out.println(downloads); // Project directory Path project = Paths.get("."); System.out.println(project); System.out.println(project.toAbsolutePath()); System.out.println("As a URI: " + project.toUri()); // Normalize a path Path p = Paths.get("/Users/kousen/Documents/./IntelliJ/..").normalize(); System.out.println("Normalized: " + p); System.out.println("parent: " + project.toAbsolutePath().getParent()); System.out.println("file name: " + project.toAbsolutePath().getFileName()); System.out.println("root: " + project.toAbsolutePath().getRoot()); for (Path path : project.toAbsolutePath()) { System.out.println(path); } File localDir = new File(".."); System.out.println(localDir); System.out.println(localDir.toPath().toAbsolutePath().normalize()); }
Example 17
Source File: BlackBoxTestContext.java From bazel with Apache License 2.0 | 5 votes |
/** * Take the value from environment variable and assert that it is a path, and the file or * directory, specified by this path, exists. * * @param name name of the environment variable * @return Path to the file where the value of environment variable points */ private static Path getPathFromEnv(String name) { String pathStr = System.getenv(name); assertThat(pathStr).isNotNull(); Path path = Paths.get(pathStr); assertThat(Files.exists(path)).isTrue(); return path.toAbsolutePath(); }
Example 18
Source File: Kontalk.java From desktopclient-java with GNU General Public License v3.0 | 4 votes |
Kontalk(Path appDir) { mAppDir = appDir.toAbsolutePath(); }
Example 19
Source File: Errors.java From galleon with Apache License 2.0 | 4 votes |
static String deleteFile(Path p) { return "Failed to delete " + p.toAbsolutePath(); }
Example 20
Source File: UnixDescriptor.java From libreveris with GNU Lesser General Public License v3.0 | 4 votes |
@Override public String getDeleteCommand (Path file) { return "rm -v -f \"" + file.toAbsolutePath() + "\""; }