List of usage examples for java.nio.file Path resolve
default Path resolve(String other)
From source file:net.daboross.bukkitdev.skywars.commands.setupstuff.SetupData.java
public SkyArenaConfig convertToArenaConfig() { Path arenaFolder = plugin.getConfiguration().getArenaFolder(); int additionToName = 0; String finalArenaName = arenaName; while (Files.exists(arenaFolder.resolve(finalArenaName + ".yml"))) { finalArenaName = arenaName + ++additionToName; }//ww w. ja v a 2 s. c o m if (!finalArenaName.equals(arenaName)) { plugin.getLogger().log(Level.INFO, String.format("New arena `%s` saved as `%s` (to avoid conflict with `%s`).", arenaName, finalArenaName, arenaName)); } Path saveFile = arenaFolder.resolve(finalArenaName + ".yml"); setOriginBoundaries(); if (originRange == null) { throw new IllegalStateException("Origin not defined."); } SkyBoundariesConfig boundaries = new SkyBoundariesConfig(originRange); List<SkyPlayerLocation> processedSpawns = new ArrayList<>(); for (SkyPlayerLocation spawn : spawns) { spawn = spawn.subtract(originRange.min); spawn = new SkyPlayerLocation(Math.round(spawn.x - 0.5) + 0.5, Math.round(spawn.y), Math.round(spawn.z - 0.5) + 0.5, spawn.yaw, spawn.pitch, null); processedSpawns.add(spawn); } SkyArenaConfig config = new SkyArenaConfig(finalArenaName, processedSpawns, spawns.size(), // Number of teams 1, // Team size 2, // min players 20, // Placement Y boundaries, null); config.setFile(saveFile); return config; }
From source file:com.facebook.buck.zip.ZipStepTest.java
@Test public void willRecurseIntoSubdirectories() throws IOException { Path parent = tmp.newFolder("zipstep"); Path out = parent.resolve("output.zip"); Path toZip = tmp.newFolder("zipdir"); Files.createFile(toZip.resolve("file1.txt")); Files.createDirectories(toZip.resolve("child")); Files.createFile(toZip.resolve("child/file2.txt")); ZipStep step = new ZipStep(filesystem, Paths.get("zipstep/output.zip"), ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir")); assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode()); // Make sure we have the right attributes. try (ZipFile zip = new ZipFile(out.toFile())) { ZipArchiveEntry entry = zip.getEntry("child/"); assertNotEquals(entry.getUnixMode() & MoreFiles.S_IFDIR, 0); }/*from w w w.ja v a 2s.c o m*/ try (Zip zip = new Zip(out, false)) { assertEquals(ImmutableSet.of("file1.txt", "child/file2.txt"), zip.getFileNames()); } }
From source file:io.fabric8.profiles.ProfilesTest.java
@Test public void basicTest() throws IOException { Path target = PROJECT_BASE_DIR.resolve("target/test-data/materialize1"); recusiveDeleteIfExists(target);//from ww w. j a v a 2s . co m Files.createDirectories(target); Path repository = PROJECT_BASE_DIR.resolve("src/test/profiles"); new Profiles(repository).materialize(target, "d"); Assert.assertEquals("d", readTextFile(target.resolve("test.txt"))); Properties properties = readPropertiesFile(target.resolve("test.properties")); Assert.assertEquals("d", properties.getProperty("name")); Assert.assertEquals("a", readTextFile(target.resolve("a.txt"))); Assert.assertEquals("b", readTextFile(target.resolve("b.txt"))); Assert.assertEquals("c", readTextFile(target.resolve("c.txt"))); Assert.assertEquals("d", readTextFile(target.resolve("d.txt"))); JsonNode jsonNode = readYamlFile(target.resolve("test.yml")); Assert.assertEquals("d", jsonNode.get("name").textValue()); Assert.assertEquals("maybe", jsonNode.get("attributes").get("awesome").textValue()); Assert.assertEquals(4, jsonNode.get("pods").size()); }
From source file:com.facebook.buck.zip.ZipStepTest.java
@Test public void mustIncludeTheContentsOfFilesThatAreSymlinked() throws IOException { // Symlinks on Windows are _hard_. Let's go shopping. assumeTrue(Platform.detect() != Platform.WINDOWS); Path parent = tmp.newFolder("zipstep"); Path out = parent.resolve("output.zip"); Path target = parent.resolve("target"); Files.write(target, "example content".getBytes(UTF_8)); Path toZip = tmp.newFolder("zipdir"); Path path = toZip.resolve("file.txt"); Files.createSymbolicLink(path, target); ZipStep step = new ZipStep(filesystem, Paths.get("zipstep/output.zip"), ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir")); assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode()); try (Zip zip = new Zip(out, false)) { assertEquals(ImmutableSet.of("file.txt"), zip.getFileNames()); byte[] contents = zip.readFully("file.txt"); assertArrayEquals("example content".getBytes(), contents); }/*from w ww . j a va 2s . c o m*/ }
From source file:com.facebook.buck.zip.ZipStepTest.java
@Test public void zipWithEmptyDir() throws IOException { Path parent = tmp.newFolder("zipstep"); Path out = parent.resolve("output.zip"); tmp.newFolder("zipdir"); tmp.newFolder("zipdir/foo/"); tmp.newFolder("zipdir/bar/"); ZipStep step = new ZipStep(filesystem, Paths.get("zipstep/output.zip"), ImmutableSet.of(), true, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir")); assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode()); try (Zip zip = new Zip(out, false)) { assertEquals(ImmutableSet.of("", "foo/", "bar/"), zip.getDirNames()); }/* w ww . j av a2 s.c om*/ // Directories should be stored, not deflated as this sometimes causes issues // (e.g. installing an .ipa over the air in iOS 9.1) try (ZipInputStream is = new ZipInputStream(new FileInputStream(out.toFile()))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertEquals(entry.getName(), ZipEntry.STORED, entry.getMethod()); } } }
From source file:com.facebook.buck.util.unarchive.UnzipTest.java
@Test public void testDirectoryPathsOverwriteFiles() throws InterruptedException, IOException { try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) { // It seems very unlikely that a zip file would contain ".." paths, but handle it anyways. zip.putArchiveEntry(new ZipArchiveEntry("foo/bar")); zip.closeArchiveEntry();/* ww w .j av a 2s.c o m*/ } Path extractFolder = tmpFolder.newFolder(); Files.write(extractFolder.resolve("foo"), ImmutableList.of("whatever")); ArchiveFormat.ZIP.getUnarchiver().extractArchive(new DefaultProjectFilesystemFactory(), zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(), ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES); assertTrue(Files.exists(extractFolder.toAbsolutePath().resolve("foo"))); assertTrue(Files.exists(extractFolder.toAbsolutePath().resolve("foo/bar"))); }
From source file:com.google.cloud.runtimes.builder.buildsteps.docker.StageDockerArtifactBuildStep.java
private Path getArtifact(Path directory, Map<String, String> metadata) throws ArtifactNotFoundException, IOException, TooManyArtifactsException { // if the artifact path has been overridden, use that value if (artifactPathOverride != null) { return directory.resolve(artifactPathOverride); } else if (metadata.containsKey(BuildStepMetadataConstants.BUILD_ARTIFACT_PATH)) { // if the artifact path is found in the metadata String buildArtifactPath = metadata.get(BuildStepMetadataConstants.BUILD_ARTIFACT_PATH); Path buildOutputDir = directory.resolve(buildArtifactPath); return searchForArtifactInDir(buildOutputDir); } else {// w w w .j a v a 2 s . c o m // otherwise, search for an artifact in the workspace root return searchForArtifactInDir(directory); } }
From source file:io.fabric8.profiles.Profiles.java
private void collectProfileNames(ArrayList<String> target, String profileName) throws IOException { if (target.contains(profileName)) { return;/*from w w w . ja va2 s .com*/ } Path path = getProfilePath(profileName); if (!Files.exists(path)) { throw new IOException("Profile directory does not exists: " + path); } Properties props = new Properties(); Path agentProperties = path.resolve("io.fabric8.agent.properties"); if (Files.exists(agentProperties)) { props = readPropertiesFile(agentProperties); } String parents = props.getProperty("attribute.parents", "default".equals(profileName) ? "" : "default"); for (String parent : parents.split(",")) { parent = parent.trim(); if (!parent.isEmpty()) { collectProfileNames(target, parent); } } target.add(profileName); }
From source file:it.tidalwave.bluemarine2.downloader.impl.SimpleHttpCacheStorage.java
/******************************************************************************************************************* * * {@inheritDoc}//from w ww . ja v a 2s .c o m * ******************************************************************************************************************/ @Override public void putEntry(final @Nonnull String key, final @Nonnull HttpCacheEntry entry) throws IOException { try { log.debug("putEntry({}, {})", key, entry); final Path cachePath = getCacheItemPath(new URL(key)); createDirectories(cachePath); final Path cacheHeadersPath = cachePath.resolve(PATH_HEADERS); final Path cacheContentPath = cachePath.resolve(PATH_CONTENT); @Cleanup final OutputStream os = newOutputStream(cacheHeadersPath, CREATE); final SessionOutputBufferImpl sob = sessionOutputBufferFrom(os); final DefaultHttpResponseWriter writer = new DefaultHttpResponseWriter(sob); writer.write(responseFrom(entry)); sob.flush(); if (entry.getResource().length() > 0) { copy(entry.getResource().getInputStream(), cacheContentPath, REPLACE_EXISTING); } } catch (HttpException e) { throw new IOException(e); } }
From source file:com.facebook.buck.zip.ZipStepTest.java
/** * Tests a couple bugs://from ww w .j a v a 2 s .c om * 1) {@link com.facebook.buck.zip.OverwritingZipOutputStream} was writing uncompressed zip * entries incorrectly. * 2) {@link ZipStep} wasn't setting the output size when writing uncompressed entries. */ @Test public void minCompressionWritesCorrectZipFile() throws IOException { Path parent = tmp.newFolder("zipstep"); Path out = parent.resolve("output.zip"); Path toZip = tmp.newFolder("zipdir"); byte[] contents = "hello world".getBytes(); Files.write(toZip.resolve("file1.txt"), contents); Files.write(toZip.resolve("file2.txt"), contents); Files.write(toZip.resolve("file3.txt"), contents); ZipStep step = new ZipStep(filesystem, Paths.get("zipstep/output.zip"), ImmutableSet.of(), false, ZipCompressionLevel.MIN_COMPRESSION_LEVEL, Paths.get("zipdir")); assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode()); // Use apache's common-compress to parse the zip file, since it reads the central // directory and will verify it's valid. try (ZipFile zip = new ZipFile(out.toFile())) { Enumeration<ZipArchiveEntry> entries = zip.getEntries(); ZipArchiveEntry entry1 = entries.nextElement(); assertArrayEquals(contents, ByteStreams.toByteArray(zip.getInputStream(entry1))); ZipArchiveEntry entry2 = entries.nextElement(); assertArrayEquals(contents, ByteStreams.toByteArray(zip.getInputStream(entry2))); ZipArchiveEntry entry3 = entries.nextElement(); assertArrayEquals(contents, ByteStreams.toByteArray(zip.getInputStream(entry3))); } }