Example usage for java.nio.file Path isAbsolute

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

Introduction

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

Prototype

boolean isAbsolute();

Source Link

Document

Tells whether or not this path is absolute.

Usage

From source file:org.darkware.wpman.config.WordpressConfigData.java

/**
 * Set the path to the WordPress content directory.
 *
 * @param contentDir The path to the content directory.
 *//*from w  w  w  .  j a  va2  s. c  o  m*/
@JsonProperty("contentDir")
public void setContentDir(final Path contentDir) {
    this.contentDir = (contentDir.isAbsolute()) ? contentDir : this.getBasePath().resolve(contentDir);
}

From source file:org.codice.ddf.security.sts.claims.property.UsersAttributesFileClaimsHandler.java

/**
 * @throws IllegalStateException when the users attributes file cannot be read or when the
 *     contents do meet assumptions. See the documentation section "Updating System Users" for
 *     details about the contents of the users attribute file.
 *//* www  .j  a  va2 s  .c o  m*/
public void init() {
    Path path = Paths.get(usersAttributesFileLocation);
    if (!path.isAbsolute()) {
        path = DDF_HOME_PATH.resolve(path);
    }

    final Map<String, Map<String, Object>> usersAttributesFileContents;
    final Type type = new TypeToken<Map<String, Map<String, Object>>>() {
    }.getType();
    try (final Reader reader = Files.newBufferedReader(path)) {
        usersAttributesFileContents = new Gson().fromJson(reader, type);
    } catch (NoSuchFileException e) {
        final String errorMessage = createErrorMessage("Cannot find file");
        LOGGER.error(errorMessage, e);
        throw new IllegalStateException(e);
    } catch (JsonIOException | IOException e) {
        final String errorMessage = createErrorMessage("Error reading file");
        LOGGER.error(errorMessage, e);
        throw new IllegalStateException(e);
    } catch (JsonSyntaxException e) {
        final String errorMessage = createErrorMessage(
                "File does not contain expected the expected json format");
        LOGGER.error(errorMessage, e);
        throw new IllegalStateException(e);
    }

    final Map<String, Map<String, Set<String>>> newJson = new HashMap<>();
    for (Map.Entry<String, Map<String, Object>> userToAttributesMap : usersAttributesFileContents.entrySet()) {
        final Map<String, Set<String>> attributes = new HashMap<>();
        for (Map.Entry<String, Object> attributesToValuesMap : userToAttributesMap.getValue().entrySet()) {
            attributes.put(attributesToValuesMap.getKey(),
                    convertToSetOfStrings(attributesToValuesMap.getValue()));
        }
        newJson.put(userToAttributesMap.getKey(), attributes);
    }
    json = newJson;

    setSupportedClaimTypes();
    setSystemHighUserAttributes();
}

From source file:org.apache.archiva.indexer.GenericIndexManager.java

private Path getIndexPath(Repository repo) throws IOException {
    IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
    Path repoDir = repo.getLocalPath();
    URI indexDir = icf.getIndexPath();
    Path indexDirectory = null;
    if (!StringUtils.isEmpty(indexDir.toString())) {

        indexDirectory = PathUtil.getPathFromUri(indexDir);
        // not absolute so create it in repository directory
        if (!indexDirectory.isAbsolute()) {
            indexDirectory = repoDir.resolve(indexDirectory);
        }/*w ww. j a  v a  2 s .  c  om*/
    } else {
        indexDirectory = repoDir.resolve(DEFAULT_INDEXER_DIR);
    }

    if (!Files.exists(indexDirectory)) {
        Files.createDirectories(indexDirectory);
    }
    return indexDirectory;
}

From source file:org.codice.ddf.configuration.migration.SystemConfigurationMigration.java

private Collection<MigrationWarning> checkIfPathIsMigratable(String propertyName, Path path) {
    Collection<MigrationWarning> migrationWarnings = new ArrayList<>();
    try {//  www.  ja va  2  s.c  om
        if (path.isAbsolute()) {
            String message = String.format(ABSOLUTE_PATH_WARNING, propertyName, path.toString());
            LOGGER.debug(message);
            migrationWarnings.add(new MigrationWarning(message));
        } else if (!getRealPath(ddfHome.resolve(path)).startsWith(ddfHome)) {
            String message = String.format(OUTSIDE_PATH_WARNING, propertyName, path.toString(),
                    ddfHome.toString());
            LOGGER.debug(message);
            migrationWarnings.add(new MigrationWarning(message));
        }
    } catch (MigrationException e) {
        String message = String.format(UNREAL_PATH_WARNING, propertyName, path.toString());
        LOGGER.debug(message);
        migrationWarnings.add(new MigrationWarning(message));
    }
    return migrationWarnings;
}

From source file:org.kie.workbench.common.migration.cli.MigrationApp.java

private Path promptForOutputPath() {
    final Path rawPath = Paths
            .get(system.console().readLine("Enter location for migrated repository output: "));
    if (rawPath.isAbsolute()) {
        return rawPath;
    } else {// w  ww  .j  ava 2 s  . c o m
        return system.currentWorkingDirectory().resolve(rawPath).normalize();
    }
}

From source file:org.codice.ddf.migration.util.MigratableUtil.java

private boolean isSourceMigratable(Path source, Function<String, PathMigrationWarning> pathWarningBuilder,
        Collection<MigrationWarning> warnings) {

    if (source.isAbsolute()) {
        warnings.add(pathWarningBuilder.apply("is absolute"));
        return false;
    }/*from w w w .  ja va2 s  . c om*/

    if (Files.isSymbolicLink(source)) {
        warnings.add(pathWarningBuilder.apply("contains a symbolic link"));
        return false;
    }

    try {
        if (!ddfHome.resolve(source).toRealPath().startsWith(ddfHome.toRealPath())) {
            warnings.add(pathWarningBuilder.apply(String.format("is outside [%s]", ddfHome)));
            return false;
        }
    } catch (IOException e) {
        warnings.add(pathWarningBuilder.apply("does not exist or cannot be read"));
        return false;
    }

    return true;
}

From source file:org.jmingo.query.watch.QuerySetWatchService.java

/**
 * Register watcher for specified path./*www.  j  a v a2s  .  c  o  m*/
 * If path references to a file then the parent folder of this file is registered.
 *
 * @param path the path to file or folder to watch
 */
public void regiser(Path path) {
    Validate.notNull(path, "path to watch cannot be null");
    try {
        lock.lock();
        if (!path.isAbsolute()) {
            path = path.toAbsolutePath();
        }
        Path dir = path;
        // check if specified path is referencing to file
        if (Files.isRegularFile(path)) {
            dir = path.getParent();//takes parent dir to register in watch service
        }
        if (needToRegister(path)) {
            LOGGER.debug("create watcher for dir: {}", dir);
            Watcher watcher = new Watcher(watchService, watchEventHandler, dir);
            executorService.submit(watcher);
        } else {
            LOGGER.debug("a watcher for dir: {} is already created", dir);
        }
        // add path to the registered collection event if this path wasn't registered in watchService
        // because we need to know for which files the new event should be posted in event bus and filter altered files properly
        registered.add(path);
    } finally {
        lock.unlock();
    }
}

From source file:org.codice.ddf.configuration.migration.PathUtilsTest.java

@Test
public void testResolveAgainstDDFHomeWhenPathIsRelative() throws Exception {
    final Path relativePath = Paths.get("etc/test.cfg");

    final Path path = pathUtils.resolveAgainstDDFHome(relativePath);

    Assert.assertThat(path.isAbsolute(), Matchers.equalTo(true));
    Assert.assertThat(path, Matchers.equalTo(ddfHome.resolve(relativePath)));
}

From source file:org.codice.ddf.configuration.migration.PathUtilsTest.java

@Test
public void testResolveAgainstDDFHomeWhenPathIsAbsolute() throws Exception {
    // resolving against DDF_HOME ensures that on Windows the absolute path gets the same drive as
    // DDF_HOME/*from  w  w w  .  j  a v  a  2 s . co  m*/
    final Path absolutePath = ddfHome.resolve(Paths.get("/etc", "test.cfg"));

    final Path path = pathUtils.resolveAgainstDDFHome(absolutePath);

    Assert.assertThat(path.isAbsolute(), Matchers.equalTo(true));
    Assert.assertThat(path, Matchers.sameInstance(absolutePath));
}

From source file:org.codice.ddf.configuration.migration.PathUtilsTest.java

@Test
public void testResolveAgainstDDFHomeWithStringWhenPathIsRelative() throws Exception {
    final Path relativePath = Paths.get("test/script.sh");

    final Path path = pathUtils.resolveAgainstDDFHome(relativePath.toString());

    Assert.assertThat(path.isAbsolute(), Matchers.equalTo(true));
    Assert.assertThat(path, Matchers.equalTo(ddfHome.resolve(relativePath)));
}