List of usage examples for java.nio.file Path resolve
default Path resolve(String other)
From source file:com.facebook.buck.jvm.java.JarDirectoryStepTest.java
@Test public void shouldNotifyEventBusWhenDuplicateClassesAreFound() throws IOException { Path jarDirectory = folder.newFolder("jarDir"); Path first = createZip(jarDirectory.resolve("a.jar"), "com/example/Main.class", "com/example/common/Helper.class"); Path second = createZip(jarDirectory.resolve("b.jar"), "com/example/common/Helper.class"); final Path outputPath = Paths.get("output.jar"); JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(jarDirectory), outputPath, ImmutableSortedSet.of(first.getFileName(), second.getFileName()), "com.example.Main", /* manifest file */ null); ExecutionContext context = TestExecutionContext.newInstance(); final BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener(); context.getBuckEventBus().register(listener); step.execute(context);//from w ww. j a v a 2 s . c o m final String expectedMessage = String.format( "Duplicate found when adding 'com/example/common/Helper.class' to '%s' from '%s'", outputPath.toAbsolutePath(), second.toAbsolutePath()); assertThat(listener.getLogMessages(), hasItem(expectedMessage)); }
From source file:com.gitpitch.services.OfflineService.java
private void fetchFixedDependencies(PitchParams pp, Path zipRoot) throws java.io.IOException { Path destPath = diskService.ensure(zipRoot.resolve(ZIP_ASSETS_DIR)); if (env.isProd()) { Path jarPath = prodModeDependenciesJar(); if (jarPath.toFile().exists()) { diskService.copyDirectoryFromJar(jarPath, FIXED_ASSETS, destPath); } else {//ww w . j ava2 s . co m log.warn("fetchFixedDependencies: [ prod ] jar " + "not found={}", jarPath); } } else { Path fixedAssetsPath = devModeFixedDependencies(); if (fixedAssetsPath.toFile().exists()) { diskService.copyDirectory(fixedAssetsPath, destPath); } else { log.debug("fetchFixedDependencies: [ dev ] fixed assets " + "not found={}", fixedAssetsPath); } } }
From source file:org.elasticsearch.xpack.core.ssl.SSLConfigurationReloaderTests.java
/** * Tests the reloading of a keystore when there is an exception during reloading. An exception is caused by truncating the keystore * that is being monitored//from w ww .j a va 2 s . c o m */ public void testReloadingKeyStoreException() throws Exception { Path tempDir = createTempDir(); Path keystorePath = tempDir.resolve("testnode.jks"); Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks"), keystorePath); MockSecureSettings secureSettings = new MockSecureSettings(); secureSettings.setString("xpack.ssl.keystore.secure_password", "testnode"); Settings settings = Settings.builder().put("xpack.ssl.keystore.path", keystorePath) .setSecureSettings(secureSettings).put("path.home", createTempDir()).build(); Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings); final SSLService sslService = new SSLService(settings, env); final SSLConfiguration config = sslService.sslConfiguration(Settings.EMPTY); new SSLConfigurationReloader(settings, env, sslService, resourceWatcherService) { @Override void reloadSSLContext(SSLConfiguration configuration) { fail("reload should not be called! [keystore reload exception]"); } }; final SSLContext context = sslService.sslContextHolder(config).sslContext(); // truncate the keystore try (OutputStream out = Files.newOutputStream(keystorePath, StandardOpenOption.TRUNCATE_EXISTING)) { } // we intentionally don't wait here as we rely on concurrency to catch a failure assertThat(sslService.sslContextHolder(config).sslContext(), sameInstance(context)); }
From source file:com.gitpitch.services.OfflineService.java
private void fetchOnlineAssets(PitchParams pp, Path zipRoot) { List<String> assetUrls = null; Path mdOnlinePath = zipRoot.resolve(PITCHME_ONLINE_PATH); File mdOnlineFile = mdOnlinePath.toFile(); if (mdOnlineFile.exists()) { MarkdownModel markdownModel = (MarkdownModel) markdownModelFactory.create(null); try (Stream<String> stream = Files.lines(mdOnlinePath)) { assetUrls = stream.map(md -> { return markdownModel.offlineAssets(md); }).collect(Collectors.toList()); log.debug("fetchOnlineAssets: assetUrls={}", assetUrls); Path zipMdAssetsPath = zipRoot.resolve(ZIP_MD_ASSETS_DIR); zipMdAssetsPath = diskService.ensure(zipMdAssetsPath); List<String> fetched = new ArrayList<String>(); for (String assetUrl : assetUrls) { if (assetUrl != null && !fetched.contains(assetUrl)) { diskService.download(pp, zipMdAssetsPath, assetUrl, FilenameUtils.getName(assetUrl), grsManager.get(pp).getHeaders()); fetched.add(assetUrl); }// ww w .j a va 2s. c o m } } catch (Exception mex) { log.warn("fetchOnlineAssets: ex={}", mex); } } else { log.warn("fetchOnlineAssets: mdOnline not found={}", mdOnlineFile); } }
From source file:org.elasticsearch.xpack.core.ssl.SSLConfigurationReloaderTests.java
/** * Tests the reloading of a key config backed by pem files when there is an exception during reloading. An exception is caused by * truncating the key file that is being monitored *///from w w w . j av a 2s. c o m public void testReloadingPEMKeyConfigException() throws Exception { Path tempDir = createTempDir(); Path keyPath = tempDir.resolve("testnode.pem"); Path certPath = tempDir.resolve("testnode.crt"); Path clientCertPath = tempDir.resolve("testclient.crt"); Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem"), keyPath); Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt"), certPath); Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.crt"), clientCertPath); MockSecureSettings secureSettings = new MockSecureSettings(); secureSettings.setString("xpack.ssl.secure_key_passphrase", "testnode"); Settings settings = Settings.builder().put("xpack.ssl.key", keyPath).put("xpack.ssl.certificate", certPath) .putList("xpack.ssl.certificate_authorities", certPath.toString(), clientCertPath.toString()) .put("path.home", createTempDir()).setSecureSettings(secureSettings).build(); Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings); final SSLService sslService = new SSLService(settings, env); final SSLConfiguration config = sslService.sslConfiguration(Settings.EMPTY); new SSLConfigurationReloader(settings, env, sslService, resourceWatcherService) { @Override void reloadSSLContext(SSLConfiguration configuration) { fail("reload should not be called! [pem key reload exception]"); } }; final SSLContext context = sslService.sslContextHolder(config).sslContext(); // truncate the file try (OutputStream os = Files.newOutputStream(keyPath, StandardOpenOption.TRUNCATE_EXISTING)) { } // we intentionally don't wait here as we rely on concurrency to catch a failure assertThat(sslService.sslContextHolder(config).sslContext(), sameInstance(context)); }
From source file:org.elasticsearch.xpack.core.ssl.SSLConfigurationReloaderTests.java
/** * Tests the reloading of a truststore when there is an exception during reloading. An exception is caused by truncating the truststore * that is being monitored// w ww.jav a 2 s.c om */ public void testTrustStoreReloadException() throws Exception { Path tempDir = createTempDir(); Path trustStorePath = tempDir.resolve("testnode.jks"); Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks"), trustStorePath); MockSecureSettings secureSettings = new MockSecureSettings(); secureSettings.setString("xpack.ssl.truststore.secure_password", "testnode"); Settings settings = Settings.builder().put("xpack.ssl.truststore.path", trustStorePath) .put("path.home", createTempDir()).setSecureSettings(secureSettings).build(); Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings); final SSLService sslService = new SSLService(settings, env); final SSLConfiguration config = sslService.sslConfiguration(Settings.EMPTY); new SSLConfigurationReloader(settings, env, sslService, resourceWatcherService) { @Override void reloadSSLContext(SSLConfiguration configuration) { fail("reload should not be called! [truststore reload exception]"); } }; final SSLContext context = sslService.sslContextHolder(config).sslContext(); // truncate the truststore try (OutputStream os = Files.newOutputStream(trustStorePath, StandardOpenOption.TRUNCATE_EXISTING)) { } // we intentionally don't wait here as we rely on concurrency to catch a failure assertThat(sslService.sslContextHolder(config).sslContext(), sameInstance(context)); }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.Converter.java
/** * This will save the HTML markup + css file to a specified folder * * @param tempFilepath the temp folder where * @return/*w w w .j a v a2 s .c o m*/ */ private Path exportMarkup(Path tempFilepath) { Path resultPath; if (outputPath != null) { resultPath = outputPath; } else { resultPath = workingDirectory; } Path markupDir = resultPath.resolve(title + "-markup"); try { try { Files.createDirectory(markupDir); } catch (FileAlreadyExistsException e) { // do nothing } Path tempDirPath = tempFilepath.getParent(); File tempDir = tempDirPath.toFile(); // Copy all files from temp folder to the markup output folder String[] files = tempDir.list(FileFileFilter.FILE); for (int i = 0; i < files.length; i++) { Files.copy(tempDirPath.resolve(files[i]), markupDir.resolve(files[i]), StandardCopyOption.REPLACE_EXISTING); } logger.info("Exported markup to folder: " + markupDir.toAbsolutePath().toString()); } catch (IOException e) { logger.error("Error saving markup files: " + e.getMessage(), e); return null; } return markupDir; }
From source file:org.elasticsearch.xpack.core.ssl.SSLConfigurationReloaderTests.java
/** * Tests the reloading of a trust config backed by pem files when there is an exception during reloading. An exception is caused by * truncating the certificate file that is being monitored */// w w w .ja v a 2s .c om public void testPEMTrustReloadException() throws Exception { Path tempDir = createTempDir(); Path clientCertPath = tempDir.resolve("testclient.crt"); Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.crt"), clientCertPath); Settings settings = Settings.builder() .putList("xpack.ssl.certificate_authorities", clientCertPath.toString()) .put("path.home", createTempDir()).build(); Environment env = randomBoolean() ? null : TestEnvironment.newEnvironment(settings); final SSLService sslService = new SSLService(settings, env); final SSLConfiguration config = sslService.sslConfiguration(Settings.EMPTY); new SSLConfigurationReloader(settings, env, sslService, resourceWatcherService) { @Override void reloadSSLContext(SSLConfiguration configuration) { fail("reload should not be called! [pem trust reload exception]"); } }; final SSLContext context = sslService.sslContextHolder(config).sslContext(); // write bad file Path updatedCert = tempDir.resolve("updated.crt"); try (OutputStream os = Files.newOutputStream(updatedCert)) { os.write(randomByte()); } atomicMoveIfPossible(updatedCert, clientCertPath); // we intentionally don't wait here as we rely on concurrency to catch a failure assertThat(sslService.sslContextHolder(config).sslContext(), sameInstance(context)); }
From source file:at.tfr.securefs.process.ProcessFilesTest.java
private void generateFileHierarchy(Path root, int startIdx, int maxIdx, CrypterProvider cp, BigInteger secret) throws Exception { IntStream.range(startIdx, maxIdx).forEach((dirIdx) -> { try {/*w w w.jav a 2 s . c om*/ Path subDir = Files.createDirectories(root.resolve(SUBDIR_PFX + dirIdx)); IntStream.range(startIdx, MAX_FILE_COUNT).forEach((fIdx) -> { try { String name = FILE_PFX + dirIdx + "_" + fIdx + FILE_END; Path filePath = subDir.resolve(name); try (OutputStream os = cp.getEncrypter(filePath, secret)) { os.write(name.getBytes()); } try (InputStream is = cp.getDecrypter(filePath, secret)) { byte[] content = name.getBytes(); IOUtils.readFully(is, content); Assert.assertTrue("failed to correctly generate file hierarchy", Arrays.equals(content, name.getBytes())); } } catch (Exception e) { throw new RuntimeException(e); } }); if (startIdx < maxIdx) { generateFileHierarchy(subDir, startIdx + 1, maxIdx, cp, secret); } } catch (Exception e) { throw new RuntimeException(e); } }); }
From source file:com.facebook.buck.android.ResourcesFilter.java
private ImmutableList<Path> getRawResDirectories() { Path resDestinationBasePath = BuildTargetPaths.getScratchPath(getProjectFilesystem(), getBuildTarget(), "__filtered__%s__"); return IntStream.range(0, resDirectories.size()) .mapToObj(count -> resDestinationBasePath.resolve(String.valueOf(count))) .collect(ImmutableList.toImmutableList()); }