List of usage examples for java.nio.file Path resolve
default Path resolve(String other)
From source file:neembuu.uploader.zip.generator.NUZipFileGenerator.java
public NUZipFileGenerator(Environment env) { this.env = env; uploadersDirectories = new Path[env.modulesToCheckForExportibles().length]; Path gitDirectory = Paths.get(env.gitDirectory()); for (int i = 0; i < env.modulesToCheckForExportibles().length; i++) { String uploadermod = env.modulesToCheckForExportibles()[i]; uploadersDirectories[i] = gitDirectory.resolve("modules/" + uploadermod + "/build/"); }//from w ww . j av a 2 s. c o m this.outputDirectory = Paths.get(env.outputDirectory()); classLoader = l(env.sortedListOfModulesToCompile(), gitDirectory); index = new Index(this.outputDirectory.resolve("index.json"), env); }
From source file:com.liferay.blade.cli.command.InstallExtensionCommandTest.java
@Test public void testInstallCustomExtensionSubdirectory() throws Exception { Assume.assumeFalse(_isWindows());/* www .j a v a 2 s . c om*/ String[] args = { "extension", "install", _LINK_TO_DEPLOY_COMMAND }; BladeTestResults bladeTestResults = TestUtil.runBlade(_rootDir, _extensionsDir, false, args); String output = bladeTestResults.getOutput(); Assert.assertTrue("Expected output to contain \"successful\"\n" + output, output.contains(" successful")); Path rootPath = _rootDir.toPath(); Path extensionDirPath = rootPath.resolve(Paths.get(".blade", "extensions")); try (Stream<Path> extensionStream = Files.list(extensionDirPath)) { boolean pathExists = extensionStream.map(Path::getFileName).map(Object::toString) .anyMatch(fileNameString -> fileNameString.startsWith("maven-profile")); Assert.assertTrue("maven-profile extension jar does not exist", pathExists); } }
From source file:at.tfr.securefs.process.ProcessFilesTest.java
private void generateHierachyCopy(ProcessFiles pf, ProcessFilesData cfd) throws IOException { cfd.setFromRootPath(fromRoot.toString()).setToRootPath(toRoot.toString()).setAllowOverwriteExisting(false) .setUpdate(false).setProcessActive(true); // When: copy of fromRoot to toRoot pf.copy(fromRoot, toRoot, cp, newSecret, cfd); // Then: a target files are created in same hierarchy like sourceFiles: Path subDir = toRoot; Path someFile = toRoot;/*from ww w . j ava 2s .co m*/ for (int i = 0; i < MAX_DIR_DEPTH; i++) { subDir = Files.createDirectories(subDir.resolve(SUBDIR_PFX + i)); } someFile = generateSomeFile(toRoot); Assert.assertTrue("subpaths are not created: " + subDir, Files.exists(subDir)); Assert.assertTrue("target file not created: " + someFile, Files.exists(someFile)); // Then: the content of target file is decryptable with newSecret // and equals content of source file byte[] buf = someFile.getFileName().toString().getBytes(); try (InputStream is = cp.getDecrypter(someFile, newSecret)) { IOUtils.readFully(is, buf); } Assert.assertEquals("failed to decrypt data", someFile.getFileName().toString(), new String(buf)); }
From source file:io.undertow.server.handlers.file.FileHandlerSymlinksTestCase.java
@After public void deleteSymlinksScenario() throws IOException, URISyntaxException { Path rootPath = Paths.get(getClass().getResource("page.html").toURI()).getParent(); Path newSymlink = rootPath.resolve("newSymlink"); Path newDir = rootPath.resolve("newDir"); Path page = newDir.resolve("page.html"); Path innerDir = newDir.resolve("innerDir"); Path innerSymlink = newDir.resolve("innerSymlink"); Path innerPage = innerDir.resolve("page.html"); Files.deleteIfExists(innerSymlink); Files.deleteIfExists(newSymlink); Files.deleteIfExists(innerPage); Files.deleteIfExists(page);/*from w w w. j a v a 2s . com*/ Files.deleteIfExists(innerDir); Files.deleteIfExists(newDir); }
From source file:cn.edu.zjnu.acm.judge.core.Judger.java
private boolean compile(RunRecord runRecord) throws IOException { String source = runRecord.getSource(); if (StringUtils.isEmptyOrWhitespace(source)) { return false; }/*from ww w .jav a2 s .c o m*/ Path work = runRecord.getWorkDirectory(); final String main = "Main"; Files.createDirectories(work); Path sourceFile = work.resolve(main + "." + runRecord.getLanguage().getSourceExtension()); //??? Files.copy(new ByteArrayInputStream(source.getBytes(Platform.getCharset())), sourceFile, StandardCopyOption.REPLACE_EXISTING); String compileCommand = runRecord.getLanguage().getCompileCommand(); log.debug("Compile Command: {}", compileCommand); // if (StringUtils.isEmptyOrWhitespace(compileCommand)) { return true; } assert compileCommand != null; // // VC++? // G++? Path compileInfo = work.resolve("compileinfo.txt"); Process process = ProcessCreationHelper.execute(new ProcessBuilder(compileCommand.split("\\s+")) .directory(work.toFile()).redirectOutput(compileInfo.toFile()).redirectErrorStream(true)::start); process.getInputStream().close(); try { process.waitFor(45, TimeUnit.SECONDS); } catch (InterruptedException ex) { throw new InterruptedIOException(); } //? String errorInfo; if (process.isAlive()) { process.destroy(); try { process.waitFor(); } catch (InterruptedException ex) { throw new InterruptedIOException(); } errorInfo = "Compile timeout\nOutput:\n" + collectLines(compileInfo); } else { errorInfo = collectLines(compileInfo); } log.debug("errorInfo = {}", errorInfo); Path executable = work.resolve(main + "." + runRecord.getLanguage().getExecutableExtension()); //?? log.debug("executable = {}", executable); boolean compileOK = Files.exists(executable); // if (!compileOK) { submissionMapper.updateResult(runRecord.getSubmissionId(), ResultType.COMPILE_ERROR, 0, 0); submissionMapper.saveCompileInfo(runRecord.getSubmissionId(), errorInfo); updateSubmissionStatus(runRecord); } return compileOK; }
From source file:io.undertow.server.handlers.file.FileHandlerSymlinksTestCase.java
@Test public void testDefaultAccessSymlinkDenied() throws IOException, URISyntaxException { TestHttpClient client = new TestHttpClient(); Path rootPath = Paths.get(getClass().getResource("page.html").toURI()).getParent(); Path newSymlink = rootPath.resolve("newSymlink"); try {//from w w w . jav a 2s . com DefaultServer.setRootHandler(new CanonicalPathHandler().setNext(new PathHandler().addPrefixPath("/path", new ResourceHandler(new PathResourceManager(newSymlink, 10485760)) .setDirectoryListingEnabled(false).addWelcomeFiles("page.html")))); /** * This request should return a 404 error, as path contains a symbolic link and by default followLinks is false */ HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path/innerSymlink/"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode()); } finally { client.getConnectionManager().shutdown(); } }
From source file:io.undertow.server.handlers.file.FileHandlerSymlinksTestCase.java
@Test public void testExplicitAccessSymlinkDeniedForEmptySafePath() throws IOException, URISyntaxException { TestHttpClient client = new TestHttpClient(); Path rootPath = Paths.get(getClass().getResource("page.html").toURI()).getParent(); Path newSymlink = rootPath.resolve("newSymlink"); try {// w w w . j a va 2s . c om DefaultServer.setRootHandler(new CanonicalPathHandler().setNext(new PathHandler().addPrefixPath("/path", new ResourceHandler(new PathResourceManager(newSymlink, 10485760, true, "")) .setDirectoryListingEnabled(false).addWelcomeFiles("page.html")))); /** * This request should return a 404 error, followLinks is true, but empty "" safePaths forbids all symbolics paths inside base path */ HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path/innerSymlink/"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode()); } finally { client.getConnectionManager().shutdown(); } }
From source file:io.undertow.server.handlers.file.FileHandlerSymlinksTestCase.java
@Test public void testCreateSymlinks() throws IOException, URISyntaxException { Path rootPath = Paths.get(getClass().getResource("page.html").toURI()).getParent(); Path newDir = rootPath.resolve("newDir"); Assert.assertFalse(Files.isSymbolicLink(newDir)); Path innerDir = newDir.resolve("innerDir"); Assert.assertFalse(Files.isSymbolicLink(innerDir)); Path newSymlink = rootPath.resolve("newSymlink"); Assert.assertTrue(Files.isSymbolicLink(newSymlink)); Path innerSymlink = newSymlink.resolve("innerSymlink"); Assert.assertTrue(Files.isSymbolicLink(innerSymlink)); Path f = innerSymlink.getRoot(); for (int i = 0; i < innerSymlink.getNameCount(); i++) { f = f.resolve(innerSymlink.getName(i).toString()); System.out.println(f + " " + Files.isSymbolicLink(f)); }// www. ja v a2s . c o m f = f.resolve("."); System.out.println(f + " " + Files.isSymbolicLink(f)); }
From source file:io.undertow.server.handlers.file.FileHandlerSymlinksTestCase.java
@Test public void testExplicitAccessSymlinkDeniedUsingSpecificFilters() throws IOException, URISyntaxException { TestHttpClient client = new TestHttpClient(); Path rootPath = Paths.get(getClass().getResource("page.html").toURI()).getParent(); Path newSymlink = rootPath.resolve("newSymlink"); try {//w ww . ja v a 2s .c om DefaultServer.setRootHandler(new CanonicalPathHandler().setNext(new PathHandler().addPrefixPath("/path", new ResourceHandler(new PathResourceManager(newSymlink, 10485760, true, rootPath.toAbsolutePath().toString().concat("/otherDir"))) .setDirectoryListingEnabled(false).addWelcomeFiles("page.html")))); /** * This request should return a 404 code as rootPath + "/otherDir" doesnt match in rootPath + "/path/innerSymlink/page.html" */ HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path/innerSymlink/page.html"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode()); } finally { client.getConnectionManager().shutdown(); } }
From source file:io.undertow.server.handlers.file.FileHandlerSymlinksTestCase.java
@Test public void testExplicitAccessSymlinkDeniedUsingSameSymlinkName() throws IOException, URISyntaxException { TestHttpClient client = new TestHttpClient(); Path rootPath = Paths.get(getClass().getResource("page.html").toURI()).getParent(); Path newSymlink = rootPath.resolve("newSymlink"); try {/*from ww w .j av a 2 s . com*/ DefaultServer.setRootHandler(new CanonicalPathHandler().setNext(new PathHandler().addPrefixPath("/path", new ResourceHandler(new PathResourceManager(newSymlink, 10485760, true, rootPath.toAbsolutePath().toString().concat("/innerSymlink"))) .setDirectoryListingEnabled(false).addWelcomeFiles("page.html")))); /** * This request should return a 404 code as rootPath + "/innerSymlink" in safePaths will not match with canonical "/innerSymlink" */ HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path/innerSymlink/page.html"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode()); } finally { client.getConnectionManager().shutdown(); } }