Example usage for java.nio.file Path resolve

List of usage examples for java.nio.file Path resolve

Introduction

In this page you can find the example usage for java.nio.file Path resolve.

Prototype

default Path resolve(String other) 

Source Link

Document

Converts a given path string to a Path and resolves it against this Path in exactly the manner specified by the #resolve(Path) resolve method.

Usage

From source file:com.google.devtools.build.android.PackedResourceTarExpander.java

@Override
public ImmutableList<Path> modify(ImmutableList<Path> resourceRoots) {
    final Builder<Path> outDirs = ImmutableList.builder();
    for (final Path unresolvedRoot : resourceRoots) {
        Path root = unresolvedRoot.toAbsolutePath();
        try {//from   w w w  .j a v a2  s  .  c o m
            final Path packedResources = root.resolve("raw/blaze_internal_packed_resources.tar");
            if (Files.exists(packedResources)) {
                Preconditions.checkArgument(root.startsWith(workingDirectory), "%s is not under %s", root,
                        workingDirectory);
                final Path resourcePrefix = workingDirectory.relativize(root);
                final Path targetDirectory = out.resolve(resourcePrefix);
                outDirs.add(targetDirectory);
                copyRemainingResources(root, packedResources);
                // Group the unpacked resource by the path they came from.
                final Path tarOut = out.resolve("blaze_internal_packed_resources").resolve(resourcePrefix);
                unTarPackedResources(tarOut, packedResources);
                outDirs.add(tarOut);
            } else {
                outDirs.add(root);
            }
        } catch (IOException e) {
            Throwables.propagate(e);
        }
    }
    return outDirs.build();
}

From source file:com.github.harti2006.neo4j.StartNeo4jServerMojo.java

private void startNeo4jServer() throws MojoExecutionException {
    final Log log = getLog();
    try {/*  www . ja  v a 2  s  . c  o  m*/
        final Path serverLocation = getServerLocation();
        final String[] neo4jCommand = new String[] {
                serverLocation.resolve(Paths.get("bin", "neo4j")).toString(), "start" };
        final File workingDir = serverLocation.toFile();

        final Process neo4jStartProcess = Runtime.getRuntime().exec(neo4jCommand, null, workingDir);
        try (BufferedReader br = new BufferedReader(
                new InputStreamReader(neo4jStartProcess.getInputStream()))) {
            String line;
            while ((line = br.readLine()) != null) {
                log.info("NEO4J SERVER > " + line);
            }
        }

        if (neo4jStartProcess.waitFor(5, SECONDS) && neo4jStartProcess.exitValue() == 0) {
            log.info("Started Neo4j server");
        } else {
            throw new MojoExecutionException("Neo4j server did not start up properly");
        }
    } catch (IOException | InterruptedException e) {
        throw new MojoExecutionException("Could not start neo4j server", e);
    }
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.helm.HelmArtifactCredentialsTest.java

@Test
void downloadWithBasicAuthFromFile(@TempDirectory.TempDir Path tempDir,
        @WiremockResolver.Wiremock WireMockServer server) throws IOException {
    Path authFile = tempDir.resolve("auth-file");
    Files.write(authFile, "someuser:somepassw0rd!".getBytes());

    HelmArtifactAccount account = new HelmArtifactAccount();
    account.setRepository(server.baseUrl() + "/" + REPOSITORY);
    account.setName("my-helm-account");
    account.setUsernamePasswordFile(authFile.toAbsolutePath().toString());

    runTestCase(server, account, m -> m.withBasicAuth("someuser", "somepassw0rd!"));
}

From source file:com.liferay.sync.engine.util.FileUtilTest.java

@Test
public void testMoveFile() throws Exception {
    Path sourceFilePath = Files.createTempFile("test", null);

    Assert.assertTrue(FileUtil.exists(sourceFilePath));

    Path targetDirectoryFilePath = Files.createTempDirectory("test");

    Path targetFilePath = targetDirectoryFilePath.resolve(sourceFilePath.getFileName());

    FileUtil.moveFile(sourceFilePath, targetFilePath);

    Assert.assertTrue(FileUtil.notExists(sourceFilePath));
    Assert.assertTrue(FileUtil.exists(targetFilePath));
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.github.GithubArtifactCredentialsTest.java

@Test
void downloadWithTokenFromFile(@TempDirectory.TempDir Path tempDir,
        @WiremockResolver.Wiremock WireMockServer server) throws IOException {
    Path authFile = tempDir.resolve("auth-file");
    Files.write(authFile, "zzz".getBytes());

    GitHubArtifactAccount account = new GitHubArtifactAccount();
    account.setName("my-github-account");
    account.setTokenFile(authFile.toAbsolutePath().toString());

    runTestCase(server, account, m -> m.withHeader("Authorization", equalTo("token zzz")));
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.github.GithubArtifactCredentialsTest.java

@Test
void downloadWithBasicAuthFromFile(@TempDirectory.TempDir Path tempDir,
        @WiremockResolver.Wiremock WireMockServer server) throws IOException {
    Path authFile = tempDir.resolve("auth-file");
    Files.write(authFile, "someuser:somepassw0rd!".getBytes());

    GitHubArtifactAccount account = new GitHubArtifactAccount();
    account.setName("my-github-account");
    account.setUsernamePasswordFile(authFile.toAbsolutePath().toString());

    runTestCase(server, account, m -> m.withBasicAuth("someuser", "somepassw0rd!"));
}

From source file:org.bonitasoft.web.designer.workspace.WorkspaceTest.java

@Test
public void should_not_copy_widget_file_if_it_is_already_in_widget_repository_folder() throws Exception {
    mockWidgetsBasePath(temporaryFolder.toPath().resolve("widgets"));

    //We create the widget files
    Path labelDir = temporaryFolder.newFolderPath("widgets", "pbLabel");
    Path labelFile = labelDir.resolve("pbLabel.json");
    byte[] fileContent = "{\"id\":\"pbLabel\", \"template\": \"<div>Hello</div>\"}"
            .getBytes(StandardCharsets.UTF_8);
    write(labelFile, fileContent, StandardOpenOption.CREATE);

    workspace.initialize();/*from ww w .  j a  v a 2s.com*/

    assertThat(readAllBytes(labelFile)).isEqualTo(fileContent);
    assertThat(pathResolver.getWidgetsRepositoryPath().resolve("pbLabel/pbLabel.json")).exists();
}

From source file:org.bonitasoft.web.designer.repository.WidgetLoaderTest.java

private void addToDirectory(Path directory, Widget... widgets) throws Exception {
    for (Widget widget : widgets) {
        Path widgetDir = createDirectory(directory.resolve(widget.getId()));
        writeWidgetMetadataInFile(widget, widgetDir.resolve(widget.getId() + ".json"));
    }/*from w  w  w. j  a v a 2s.co  m*/
}

From source file:at.ac.tuwien.infosys.repository.LocalComponentRepository.java

@Override
public Component get(String name, Version version) throws NotFoundException {
    Path versionedComponentPath = resolve(name, version);

    Path artifactsPath = versionedComponentPath.resolve(artifactFolder);
    Path scriptsPath = versionedComponentPath.resolve(scriptFolder);

    // get available artifacts
    List<Path> foundArtifacts = list(artifactsPath);

    // get available scripts
    List<Path> foundScripts = list(scriptsPath);

    return new Component(name, version, createResources(foundArtifacts), createResources(foundScripts));
}

From source file:org.fcrepo.importexport.integration.BagItIT.java

@Test
public void testExportBag() throws Exception {
    final String exampleID = UUID.randomUUID().toString();
    final URI uri = URI.create(serverAddress + exampleID);

    final FcrepoResponse response = create(uri);
    assertEquals(SC_CREATED, response.getStatusCode());
    assertEquals(uri, response.getLocation());

    final Config config = new Config();
    config.setMode("export");
    config.setBaseDirectory(TARGET_DIR + File.separator + exampleID);
    config.setIncludeBinaries(true);/*from w  w  w  .  j  a  va 2  s  . c o  m*/
    config.setResource(uri);
    config.setPredicates(new String[] { CONTAINS.toString() });
    config.setRdfExtension(DEFAULT_RDF_EXT);
    config.setRdfLanguage(DEFAULT_RDF_LANG);
    config.setUsername(USERNAME);
    config.setPassword(PASSWORD);
    config.setBagProfile(DEFAULT_BAG_PROFILE);
    config.setBagConfigPath("src/test/resources/configs/bagit-config.yml");
    new Exporter(config, clientBuilder).run();

    final Path target = Paths.get(TARGET_DIR, exampleID);
    assertTrue(target.resolve("bagit.txt").toFile().exists());
    assertTrue(target.resolve("manifest-sha1.txt").toFile().exists());

    final Path dataDir = target.resolve("data");
    assertTrue(dataDir.toFile().exists());
    assertTrue(dataDir.toFile().isDirectory());

    final Path resourceFile = Paths.get(dataDir.toString(), uri.getPath() + DEFAULT_RDF_EXT);
    assertTrue(resourceFile.toFile().exists());

    final FcrepoResponse response1 = clientBuilder.build().get(uri).perform();
    final MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
    final byte[] buf = new byte[8192];
    int read = 0;
    while ((read = response1.getBody().read(buf)) != -1) {
        sha1.update(buf, 0, read);
    }

    final String checksum = new String(encodeHex(sha1.digest()));
    final BufferedReader reader = new BufferedReader(
            new FileReader(target.resolve("manifest-sha1.txt").toFile()));
    final String checksumLine = reader.readLine();
    reader.close();
    assertEquals(checksum, checksumLine.split(" ")[0]);
}