Search in sources :

Example 96 with FileSystem

use of java.nio.file.FileSystem in project jetty.project by eclipse.

the class PathMatchers method getMatcher.

public static PathMatcher getMatcher(final String rawpattern) {
    FileSystem fs = FileSystems.getDefault();
    String pattern = rawpattern;
    // Strip trailing slash (if present)
    int lastchar = pattern.charAt(pattern.length() - 1);
    if (lastchar == '/' || lastchar == '\\') {
        pattern = pattern.substring(0, pattern.length() - 1);
    }
    // use FileSystem default pattern behavior
    if (pattern.startsWith("glob:") || pattern.startsWith("regex:")) {
        StartLog.debug("Using Standard " + fs.getClass().getName() + " pattern: " + pattern);
        return fs.getPathMatcher(pattern);
    }
    // be a full system path
    if (isAbsolute(pattern)) {
        String pat = "glob:" + pattern;
        StartLog.debug("Using absolute path pattern: " + pat);
        return fs.getPathMatcher(pat);
    }
    // Doesn't start with filesystem root, then assume the pattern
    // is a relative file path pattern.
    String pat = "glob:**/" + pattern;
    StartLog.debug("Using relative path pattern: " + pat);
    return fs.getPathMatcher(pat);
}
Also used : FileSystem(java.nio.file.FileSystem)

Example 97 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class DefaultJavaLibraryIntegrationTest method testBuildJavaLibraryWithoutSrcsAndVerifyAbi.

@Test
public void testBuildJavaLibraryWithoutSrcsAndVerifyAbi() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "abi", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    // Run `buck build`.
    BuildTarget target = BuildTargetFactory.newInstance("//:no_srcs");
    ProcessResult buildResult = workspace.runBuckCommand("build", target.getFullyQualifiedName());
    buildResult.assertSuccess("Successful build should exit with 0.");
    Path outputPath = BuildTargets.getGenPath(filesystem, target, "lib__%s__output/" + target.getShortName() + ".jar");
    Path outputFile = workspace.getPath(outputPath);
    assertTrue(Files.exists(outputFile));
    // TODO(bolinfest): When we produce byte-for-byte identical JAR files across builds, do:
    //
    //   HashCode hashOfOriginalJar = Files.hash(outputFile, Hashing.sha1());
    //
    // And then compare that to the output when //:no_srcs is built again with --no-cache.
    long sizeOfOriginalJar = Files.size(outputFile);
    // This verifies that the ABI key was written correctly.
    workspace.verify();
    // Verify the build cache.
    Path buildCache = workspace.getPath(filesystem.getBuckPaths().getCacheDir());
    assertTrue(Files.isDirectory(buildCache));
    ArtifactCache dirCache = TestArtifactCaches.createDirCacheForTest(workspace.getDestPath(), buildCache);
    int totalArtifactsCount = DirArtifactCacheTestUtil.getAllFilesInCache(dirCache).size();
    assertEquals("There should be two entries (a zip and metadata) in the build cache.", 2, totalArtifactsCount);
    // Run `buck clean`.
    ProcessResult cleanResult = workspace.runBuckCommand("clean");
    cleanResult.assertSuccess("Successful clean should exit with 0.");
    totalArtifactsCount = getAllFilesInPath(buildCache).size();
    assertEquals("The build cache should still exist.", 2, totalArtifactsCount);
    // Corrupt the build cache!
    File artifactZip = FluentIterable.from(ImmutableList.copyOf(DirArtifactCacheTestUtil.getAllFilesInCache(dirCache))).toSortedList(Ordering.natural()).get(0).toFile();
    FileSystem zipFs = FileSystems.newFileSystem(artifactZip.toPath(), /* loader */
    null);
    Path outputInZip = zipFs.getPath("/" + outputPath.toString());
    Files.write(outputInZip, "Hello world!".getBytes(), WRITE);
    zipFs.close();
    // Run `buck build` again.
    ProcessResult buildResult2 = workspace.runBuckCommand("build", target.getFullyQualifiedName());
    buildResult2.assertSuccess("Successful build should exit with 0.");
    assertTrue(Files.isRegularFile(outputFile));
    assertEquals("The content of the output file will be 'Hello World!' if it is read from the build cache.", "Hello world!", new String(Files.readAllBytes(outputFile), UTF_8));
    // Run `buck clean` followed by `buck build` yet again, but this time, specify `--no-cache`.
    ProcessResult cleanResult2 = workspace.runBuckCommand("clean");
    cleanResult2.assertSuccess("Successful clean should exit with 0.");
    ProcessResult buildResult3 = workspace.runBuckCommand("build", "--no-cache", target.getFullyQualifiedName());
    buildResult3.assertSuccess();
    assertNotEquals("The contents of the file should no longer be pulled from the corrupted build cache.", "Hello world!", new String(Files.readAllBytes(outputFile), UTF_8));
    assertEquals("We cannot do a byte-for-byte comparision with the original JAR because timestamps might " + "have changed, but we verify that they are the same size, as a proxy.", sizeOfOriginalJar, Files.size(outputFile));
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) FileSystem(java.nio.file.FileSystem) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ZipFile(java.util.zip.ZipFile) File(java.io.File) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Example 98 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class DefaultCellPathResolverTest method transitiveMappingForCycle.

@Test
public void transitiveMappingForCycle() throws Exception {
    FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
    Path root = vfs.getPath("/opt/local/");
    Path cell1Root = root.resolve("repo1");
    Files.createDirectories(cell1Root);
    Path cell2Root = root.resolve("repo2");
    Files.createDirectories(cell2Root);
    Path cell3Root = root.resolve("repo3");
    Files.createDirectories(cell3Root);
    DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(cell1Root, ConfigBuilder.createFromText(REPOSITORIES_SECTION, " simple = " + cell2Root.toString()));
    Files.write(cell2Root.resolve(".buckconfig"), ImmutableList.of(REPOSITORIES_SECTION, " three = " + cell3Root.toString()), StandardCharsets.UTF_8);
    Files.write(cell3Root.resolve(".buckconfig"), ImmutableList.of(REPOSITORIES_SECTION, " cycle = " + cell1Root.toString()), StandardCharsets.UTF_8);
    assertThat(cellPathResolver.getTransitivePathMapping(), Matchers.equalTo(ImmutableMap.of(RelativeCellName.ROOT_CELL_NAME, cell1Root, RelativeCellName.of(ImmutableList.of("simple")), cell2Root, RelativeCellName.of(ImmutableList.of("simple", "three")), cell3Root)));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 99 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class DefaultCellPathResolverTest method transtiveMappingForSimpleSetup.

@Test
public void transtiveMappingForSimpleSetup() throws Exception {
    FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
    Path root = vfs.getPath("/opt/local/");
    Path cell1Root = root.resolve("repo1");
    Files.createDirectories(cell1Root);
    Path cell2Root = root.resolve("repo2");
    Files.createDirectories(cell2Root);
    DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(cell1Root, ConfigBuilder.createFromText(REPOSITORIES_SECTION, " simple = " + cell2Root.toString()));
    assertThat(cellPathResolver.getTransitivePathMapping(), Matchers.equalTo(ImmutableMap.of(RelativeCellName.ROOT_CELL_NAME, cell1Root, RelativeCellName.of(ImmutableList.of("simple")), cell2Root)));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 100 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class AppleSdkDiscoveryTest method shouldNotCrashOnBrokenSymlink.

@Test
public void shouldNotCrashOnBrokenSymlink() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "sdk-discovery-symlink", temp);
    workspace.setUp();
    Path root = workspace.getPath("");
    FileSystem fileSystem = root.getFileSystem();
    Path sdksDir = root.resolve("Platforms/MacOSX.platform/Developer/SDKs");
    Files.createDirectories(sdksDir);
    Files.createSymbolicLink(sdksDir.resolve("MacOSX.sdk"), fileSystem.getPath("does_not_exist"));
    ImmutableMap<String, AppleToolchain> toolchains = ImmutableMap.of("com.apple.dt.toolchain.XcodeDefault", getDefaultToolchain(root));
    ImmutableMap<AppleSdk, AppleSdkPaths> actual = AppleSdkDiscovery.discoverAppleSdkPaths(Optional.of(root), ImmutableList.of(root), toolchains, new FakeAppleConfig());
    assertThat(actual.size(), is(0));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Aggregations

FileSystem (java.nio.file.FileSystem)156 Path (java.nio.file.Path)109 Test (org.junit.Test)66 IOException (java.io.IOException)25 File (java.io.File)17 ArrayList (java.util.ArrayList)14 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)13 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 URI (java.net.URI)10 FileStore (java.nio.file.FileStore)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 HashMap (java.util.HashMap)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)5 WindowsFS (org.apache.lucene.mockfile.WindowsFS)5 FSDirectory (org.apache.lucene.store.FSDirectory)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4