Search in sources :

Example 36 with FileSystem

use of java.nio.file.FileSystem in project wire by square.

the class WireCompilerTest method invokeCompiler.

private void invokeCompiler(String[] sources, String... extraArgs) throws Exception {
    List<String> args = new ArrayList<>();
    args.add("--proto_path=../wire-runtime/src/test/proto");
    args.add("--java_out=" + testDir.getAbsolutePath());
    Collections.addAll(args, extraArgs);
    Collections.addAll(args, sources);
    logger = new StringWireLogger();
    FileSystem fs = FileSystems.getDefault();
    WireCompiler compiler = WireCompiler.forArgs(fs, logger, args.toArray(new String[args.size()]));
    compiler.compile();
}
Also used : FileSystem(java.nio.file.FileSystem) ArrayList(java.util.ArrayList)

Example 37 with FileSystem

use of java.nio.file.FileSystem in project bazel by bazelbuild.

the class AndroidDataDeserializer method read.

/**
   * Reads the serialized {@link DataKey} and {@link DataValue} to the {@link KeyValueConsumers}.
   *
   * @param inPath The path to the serialized protocol buffer.
   * @param consumers The {@link KeyValueConsumers} for the entries {@link DataKey} -&gt;
   *     {@link DataValue}.
   * @throws DeserializationException Raised for an IOException or when the inPath is not a valid
   *     proto buffer.
   */
public void read(Path inPath, KeyValueConsumers consumers) {
    Stopwatch timer = Stopwatch.createStarted();
    try (InputStream in = Files.newInputStream(inPath, StandardOpenOption.READ)) {
        FileSystem currentFileSystem = inPath.getFileSystem();
        Header header = Header.parseDelimitedFrom(in);
        if (header == null) {
            throw new DeserializationException("No Header found in " + inPath);
        }
        readEntriesSegment(consumers, in, currentFileSystem, header);
    } catch (IOException e) {
        throw new DeserializationException(e);
    } finally {
        logger.fine(String.format("Deserialized in merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
    }
}
Also used : Header(com.google.devtools.build.android.proto.SerializeFormat.Header) InputStream(java.io.InputStream) FileSystem(java.nio.file.FileSystem) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException)

Example 38 with FileSystem

use of java.nio.file.FileSystem in project error-prone by google.

the class ErrorProneJavacPluginTest method hello.

@Test
public void hello() throws IOException {
    FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
    Path source = fileSystem.getPath("Test.java");
    Files.write(source, ImmutableList.of("import java.util.HashSet;", "import java.util.Set;", "class Test {", "  public static void main(String[] args) {", "    Set<Short> s = new HashSet<>();", "    for (short i = 0; i < 100; i++) {", "      s.add(i);", "      s.remove(i - 1);", "    }", "    System.out.println(s.size());", "  }", "}"), UTF_8);
    JavacFileManager fileManager = new JavacFileManager(new Context(), false, UTF_8);
    DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
    JavacTask task = JavacTool.create().getTask(null, fileManager, diagnosticCollector, ImmutableList.of("-Xplugin:ErrorProne"), ImmutableList.of(), fileManager.getJavaFileObjects(source));
    assertThat(task.call()).isFalse();
    Diagnostic<? extends JavaFileObject> diagnostic = diagnosticCollector.getDiagnostics().stream().filter(d -> d.getKind() == Diagnostic.Kind.ERROR).collect(onlyElement());
    assertThat(diagnostic.getMessage(ENGLISH)).contains("[CollectionIncompatibleType]");
}
Also used : Path(java.nio.file.Path) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) Context(com.sun.tools.javac.util.Context) Configuration(com.google.common.jimfs.Configuration) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) JavacTask(com.sun.source.util.JavacTask) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) RunWith(org.junit.runner.RunWith) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) FileSystem(java.nio.file.FileSystem) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) JavaFileObject(javax.tools.JavaFileObject) ImmutableList(com.google.common.collect.ImmutableList) JavacTool(com.sun.tools.javac.api.JavacTool) Jimfs(com.google.common.jimfs.Jimfs) Diagnostic(javax.tools.Diagnostic) Context(com.sun.tools.javac.util.Context) ENGLISH(java.util.Locale.ENGLISH) Path(java.nio.file.Path) DiagnosticCollector(javax.tools.DiagnosticCollector) JavaFileObject(javax.tools.JavaFileObject) FileSystem(java.nio.file.FileSystem) DiagnosticCollector(javax.tools.DiagnosticCollector) JavacTask(com.sun.source.util.JavacTask) Test(org.junit.Test)

Example 39 with FileSystem

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

the class AppleSdkDiscoveryTest method shouldScanRealDirectoryOnlyOnce.

@Test
public void shouldScanRealDirectoryOnlyOnce() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "sdk-discovery-symlink", temp);
    workspace.setUp();
    Path root = workspace.getPath("");
    FileSystem fileSystem = root.getFileSystem();
    Path actualSdkPath = root.resolve("MacOSX10.9.sdk");
    Path sdksDir = root.resolve("Platforms/MacOSX.platform/Developer/SDKs");
    Files.createDirectories(sdksDir);
    // create relative symlink
    Files.createSymbolicLink(sdksDir.resolve("MacOSX10.9.sdk"), fileSystem.getPath("MacOSX.sdk"));
    // create absolute symlink
    Files.createSymbolicLink(sdksDir.resolve("MacOSX.sdk"), actualSdkPath);
    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());
    // if both symlinks were to be visited, exception would have been thrown during discovery
    assertThat(actual.size(), is(2));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 40 with FileSystem

use of java.nio.file.FileSystem in project cryptomator by cryptomator.

the class Vault method unlock.

public synchronized void unlock(CharSequence passphrase) {
    try {
        FileSystem fs = getCryptoFileSystem(passphrase);
        if (!server.isRunning()) {
            server.start();
        }
        servlet = server.createWebDavServlet(fs.getPath("/"), vaultSettings.getId() + "/" + vaultSettings.mountName().get());
        servlet.start();
        Platform.runLater(() -> {
            unlocked.set(true);
        });
    } catch (IOException e) {
        LOG.error("Unable to provide filesystem", e);
    }
}
Also used : CryptoFileSystem(org.cryptomator.cryptofs.CryptoFileSystem) FileSystem(java.nio.file.FileSystem) IOException(java.io.IOException)

Aggregations

FileSystem (java.nio.file.FileSystem)159 Path (java.nio.file.Path)112 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 URI (java.net.URI)11 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)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