List of usage examples for java.nio.file Path resolve
default Path resolve(String other)
From source file:com.surevine.gateway.scm.git.jgit.TestUtility.java
public static LocalRepoBean createTestRepoMultipleBranches() throws Exception { final String projectKey = "test_" + UUID.randomUUID().toString(); final String repoSlug = "testRepo"; final String remoteURL = "ssh://fake_url"; final Path repoPath = Paths.get(PropertyUtil.getGitDir(), "local_scm", projectKey, repoSlug); Files.createDirectories(repoPath); final Repository repo = new FileRepository(repoPath.resolve(".git").toFile()); repo.create();//from ww w . j av a 2 s. co m final StoredConfig config = repo.getConfig(); config.setString("remote", "origin", "url", remoteURL); config.save(); final LocalRepoBean repoBean = new LocalRepoBean(); repoBean.setProjectKey(projectKey); repoBean.setSlug(repoSlug); repoBean.setLocalBare(false); final Git git = new Git(repo); // add some files to some branches for (int i = 0; i < 3; i++) { final String filename = "newfile" + i + ".txt"; Files.write(repoPath.resolve(filename), Arrays.asList("Hello World"), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND); git.add().addFilepattern(filename).call(); git.commit().setMessage("Added " + filename).call(); } git.checkout().setName("branch1").setCreateBranch(true).call(); for (int i = 0; i < 3; i++) { final String filename = "branch1" + i + ".txt"; Files.write(repoPath.resolve(filename), Arrays.asList("Hello World"), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND); git.add().addFilepattern(filename).call(); git.commit().setMessage("Added " + filename).call(); } git.checkout().setName("master").call(); git.checkout().setName("branch2").setCreateBranch(true).call(); for (int i = 0; i < 3; i++) { final String filename = "branch2" + i + ".txt"; Files.write(repoPath.resolve(filename), Arrays.asList("Hello World"), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND); git.add().addFilepattern(filename).call(); git.commit().setMessage("Added " + filename).call(); } repo.close(); return repoBean; }
From source file:com.blackducksoftware.integration.hub.detect.util.DetectZipUtil.java
public static void unzip(File zip, File dest, Charset charset) throws IOException { Path destPath = dest.toPath(); try (ZipFile zipFile = new ZipFile(zip, ZipFile.OPEN_READ, charset)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); Path entryPath = destPath.resolve(entry.getName()); if (!entryPath.normalize().startsWith(dest.toPath())) throw new IOException("Zip entry contained path traversal"); if (entry.isDirectory()) { Files.createDirectories(entryPath); } else { Files.createDirectories(entryPath.getParent()); try (InputStream in = zipFile.getInputStream(entry)) { try (OutputStream out = new FileOutputStream(entryPath.toFile())) { IOUtils.copy(in, out); }/*from w w w. j av a2s . c om*/ } } } } }
From source file:de.teamgrit.grit.preprocess.fetch.SvnFetcher.java
/** * Checks whether the specified directory already contains a svn * repository.//from w w w . j a va 2 s . co m * * @param targetDirectory * the directory which will contain a repository * @return true if there is a repository, false otherwise */ private static boolean isDataSourceInitialized(Path targetDirectory) { return (targetDirectory != null) && Files.exists(targetDirectory.resolve(".svn/"), LinkOption.NOFOLLOW_LINKS); }
From source file:fr.inria.atlanmod.neoemf.benchmarks.datastore.helper.BackendHelper.java
private static File extractEntryFromZip(ZipInputStream inputStream, ZipEntry entry, Path outputDir) throws IOException { File outputFile = outputDir.resolve(new File(entry.getName()).getName()).toFile(); if (outputFile.exists()) { log.info("Already extracted resource {}", outputFile); return outputFile; }//from ww w . ja v a 2s . c o m IOUtils.copy(inputStream, new FileOutputStream(outputFile)); return outputFile; }
From source file:com.asakusafw.testdriver.DirectIoUtil.java
private static <T> DataModelSourceFactory load0(DataModelDefinition<T> definition, HadoopFileFormat<? super T> format, URL source) throws IOException, InterruptedException { List<String> segments = Arrays.stream(source.getPath().split("/")) //$NON-NLS-1$ .map(String::trim).filter(s -> s.isEmpty() == false).collect(Collectors.toList()); String name;//from w ww. j ava 2 s. co m if (segments.isEmpty()) { name = "testing.file"; //$NON-NLS-1$ } else { name = segments.get(segments.size() - 1); } Path tmpdir = Files.createTempDirectory("asakusa-"); //$NON-NLS-1$ try (InputStream in = source.openStream()) { Path target = tmpdir.resolve(name); Files.copy(in, target); return load0(definition, format, target.toFile()); } finally { File dir = tmpdir.toFile(); if (FileUtils.deleteQuietly(dir) == false && dir.exists()) { LOG.warn(MessageFormat.format("failed to delete a temporary file: {0}", tmpdir)); } } }
From source file:neembuu.uploader.zip.generator.NUZipFileGenerator.java
private static URLClassLoader l(String[] modules, Path pth) { try {/*from www. ja va 2 s . c o m*/ URL[] u = new URL[modules.length]; for (int i = 0; i < u.length; i++) { u[i] = pth.resolve("modules/" + modules[i] + "/build/").toUri().toURL(); } return new URLClassLoader(u); } catch (Exception a) { throw new IllegalStateException(a); } }
From source file:edu.cwru.jpdg.Javac.java
/** * Compiles the java.// w w w . j a v a 2s . co m */ public static List<String> javac(String basepath, String name, String s) { Path dir = Paths.get(cwd).resolve(basepath); if (Files.notExists(dir)) { create_dir(dir); } Path java = dir.resolve(name + ".java"); Path build = dir.resolve("build"); if (!Files.notExists(build)) { try { FileUtils.deleteDirectory(build.toFile()); } catch (IOException e) { throw new RuntimeException("Couldn't rm -r build dir"); } } create_dir(build); byte[] bytes = s.getBytes(); try { Files.write(java, bytes); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } try { Process p = Runtime.getRuntime() .exec(new String[] { "javac", "-d", build.toString(), java.toString() }); String line; BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); List<String> stdout_lines = new ArrayList<String>(); line = stdout.readLine(); while (line != null) { stdout_lines.add(line); line = stdout.readLine(); } BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); List<String> stderr_lines = new ArrayList<String>(); line = stderr.readLine(); while (line != null) { stderr_lines.add(line); line = stderr.readLine(); } if (p.waitFor() != 0) { System.err.println(StringUtils.join(stdout_lines, "\n")); System.err.println("-------------------------------------"); System.err.println(StringUtils.join(stderr_lines, "\n")); throw new RuntimeException("javac failed"); } } catch (InterruptedException e) { throw new RuntimeException(e.getMessage()); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return abs_paths(find_classes(build.toString())); }
From source file:io.webfolder.cdp.ChromiumDownloader.java
public static Path getExecutable(ChromiumVersion version) { Path destinationRoot = getChromiumPath(version); Path executable = destinationRoot.resolve("chrome.exe"); if (LINUX) {/*w ww .jav a 2 s . co m*/ executable = destinationRoot.resolve("chrome"); } else if (MAC) { executable = destinationRoot.resolve("Chromium.app/Contents/MacOS/Chromium"); } return executable; }
From source file:eu.itesla_project.modules.validation.OverloadValidationTool.java
private static void writeCsv(Set<String> contingencyIds, Map<String, Map<String, OverloadStatus>> statusPerContingencyPerCase, Path outputDir) throws IOException { try (BufferedWriter writer = Files.newBufferedWriter(outputDir.resolve("comparison.csv"), StandardCharsets.UTF_8)) { writer.write("base case"); for (String contingencyId : contingencyIds) { writer.write(CSV_SEPARATOR); writer.write(contingencyId + " load flow"); writer.write(CSV_SEPARATOR); writer.write(contingencyId + " offline rule"); }//from www. j av a2 s. com writer.newLine(); for (Map.Entry<String, Map<String, OverloadStatus>> e : statusPerContingencyPerCase.entrySet()) { String baseCaseName = e.getKey(); Map<String, OverloadStatus> statusPerContingency = e.getValue(); writer.write(baseCaseName); for (String contingencyId : contingencyIds) { OverloadStatus overloadStatus = statusPerContingency.get(contingencyId); writer.write(CSV_SEPARATOR); writer.write(Boolean.toString(overloadStatus.isLfOk())); writer.write(CSV_SEPARATOR); writer.write(Boolean.toString(overloadStatus.isOfflineRuleOk())); } writer.newLine(); } } List<String> categories = Arrays.asList("OK_OK", "NOK_NOK", "OK_NOK", "NOK_OK"); Map<String, Map<String, AtomicInteger>> synthesisPerContingency = new HashMap<>(); for (String contingencyId : contingencyIds) { synthesisPerContingency.put(contingencyId, categories.stream().collect(Collectors.toMap(Function.identity(), e -> new AtomicInteger()))); } for (Map.Entry<String, Map<String, OverloadStatus>> e : statusPerContingencyPerCase.entrySet()) { Map<String, OverloadStatus> statusPerContingency = e.getValue(); for (String contingencyId : contingencyIds) { OverloadStatus overloadStatus = statusPerContingency.get(contingencyId); synthesisPerContingency.get(contingencyId).get( okToString(overloadStatus.isLfOk()) + "_" + okToString(overloadStatus.isOfflineRuleOk())) .incrementAndGet(); } } try (BufferedWriter writer = Files.newBufferedWriter(outputDir.resolve("synthesis.csv"), StandardCharsets.UTF_8)) { writer.write("contingency"); for (String c : categories) { writer.write(CSV_SEPARATOR); writer.write(c); } writer.newLine(); for (Map.Entry<String, Map<String, AtomicInteger>> e : synthesisPerContingency.entrySet()) { String contingencyId = e.getKey(); Map<String, AtomicInteger> count = e.getValue(); writer.write(contingencyId); for (String c : categories) { writer.write(CSV_SEPARATOR); writer.write(Integer.toString(count.get(c).get())); } writer.newLine(); } } }
From source file:com.github.anba.es6draft.mozilla.MozillaJSTest.java
/** * Returns an {@link Iterable} of 'shell.js'-{@link Path}s *///from w w w . ja v a 2s.c o m private static Iterable<Path> shellJS(MozTest test) { // Add 'shell.js' files from each directory List<Path> files = new ArrayList<>(); Path testDir = test.getBaseDir(); Path dir = Paths.get(""); for (Iterator<Path> iterator = test.getScript().iterator(); iterator .hasNext(); dir = dir.resolve(iterator.next())) { Path f = testDir.resolve(dir.resolve("shell.js")); if (Files.exists(f)) { files.add(f); } } return files; }