Example usage for java.nio.file Path normalize

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

Introduction

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

Prototype

Path normalize();

Source Link

Document

Returns a path that is this path with redundant name elements eliminated.

Usage

From source file:com.dianping.resource.io.PathResource.java

/**
 * Create a new PathResource from a Path handle.
 * <p>Note: Unlike {@link FileSystemResource}, when building relative resources
 * via {@link #createRelative}, the relative path will be built <i>underneath</i> the
 * given root:/*w w w . ja v  a2 s  .  c o  m*/
 * e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"!
 * @param path a Path handle
 */
public PathResource(Path path) {
    Assert.notNull(path, "Path must not be null");
    this.path = path.normalize();
}

From source file:org.sakuli.javaDSL.AbstractSakuliTest.java

protected String getTestSuiteRootFolder() {
    Path resourcePath = resolveResource(this.getClass(), "/");
    if (Files.exists(resourcePath)) {
        return resourcePath.normalize().toAbsolutePath().toString();
    }//  www .  j a  v  a2 s .  co  m
    throw new SakuliRuntimeException(
            "Cannot load test suites root folder! Should be at normal test 'src/test/resources'");
}

From source file:org.sakuli.javaDSL.AbstractSakuliTest.java

/**
 * @return the matching resource folder of the package of the current class!
 *//*w  w  w  . j  a v a 2s .c o m*/
protected String getTestSuiteFolder() {
    Path suiteFolder = resolveResource(this.getClass(), ".");
    if (Files.exists(suiteFolder)) {
        return suiteFolder.normalize().toAbsolutePath().toString();
    }
    throw new SakuliRuntimeException(String.format(
            "Cannot load test suite folder from classpath! Should be at normal test 'src/test/resources/%s'",
            StringUtils.replace(this.getClass().getCanonicalName(), ".", "/")));
}

From source file:server.tools.ServerRecovery.java

/**
 * Constructor for server recovery.//from   w ww .  ja v  a 2  s  .  c  om
 * 
 * @param filesPath
 *            the path to the client file directory on the server.
 */
public ServerRecovery(Path filesPath) {
    if ((filesPath == null) || !Files.isDirectory(filesPath)) {
        throw new IllegalArgumentException("filesPath must be an existing directory!");
    }

    this.filesPath = filesPath.normalize();
}

From source file:org.eclipse.swt.snippets.SnippetExplorer.java

/**
 * Load Snippet metadata from the Java source file found at the given path.
 *
 * @param sourceFile the source file to load
 * @return the gathered Snippet metadata or <code>null</code> if failed
 * @throws IOException            on errors loading the source file
 * @throws ClassNotFoundException if loading the Snippets corresponding class
 *                                file failed
 */// ww  w .  j a  va  2 s .  c o m
private static Snippet snippetFromSource(Path sourceFile) throws IOException, ClassNotFoundException {
    final Pattern snippetNamePattern = Pattern.compile("Snippet([0-9]+)", Pattern.CASE_INSENSITIVE);
    sourceFile = sourceFile.normalize();
    final String filename = sourceFile.getFileName().toString();
    final String snippetName = filename.substring(0, filename.lastIndexOf('.'));
    final Class<?> snippeClass = Class.forName(SnippetsConfig.SNIPPETS_PACKAGE + "." + snippetName, false,
            SnippetExplorer.class.getClassLoader());
    int snippetNum = Integer.MIN_VALUE;
    final Matcher snippetNameMatcher = snippetNamePattern.matcher(snippetName);
    if (snippetNameMatcher.matches()) {
        try {
            snippetNum = Integer.parseInt(snippetNameMatcher.group(1), 10);
        } catch (NumberFormatException e) {
        }
    }

    // do not load snippets without number yet
    if (snippetNum < 0) {
        return null;
    }

    final String src = getSnippetSource(sourceFile);
    final String description = extractSnippetDescription(src);
    final String[] arguments = SnippetsConfig.getSnippetArguments(snippetNum);
    return new Snippet(snippetNum, snippetName, snippeClass, src, description, arguments);
}

From source file:org.sakuli.javaDSL.AbstractSakuliTest.java

/**
 * Override this method to specify a custom Sahi installation folder!
 *
 * @return the installation folder of Sahi
 *//* w  ww  .ja va  2s.c  o  m*/
protected String getSahiFolder() {
    String packageName = "/sahi";
    Path sahHomeFolder = resolveResource(AbstractSakuliTest.class, packageName);
    if (Files.exists(sahHomeFolder)) {
        return sahHomeFolder.normalize().toAbsolutePath().toString();
    }
    throw new SakuliRuntimeException(
            "Cannot load SAHI_HOME folder! Should be normally under 'target/classes/" + packageName + "'");
}

From source file:org.craftercms.studio.impl.v1.deployment.PreviewDeployerImpl.java

private String getCreateTargetRequestBody(String site) {
    CreateTargetRequestBody requestBody = new CreateTargetRequestBody();
    requestBody.setEnvironment("preview");
    requestBody.setSiteName(site);//from   w  w  w  .  j  av  a  2 s. c om
    requestBody.setReplace(Boolean.parseBoolean(studioConfiguration.getProperty(PREVIEW_REPLACE)));
    requestBody.setDisableDeployCron(
            Boolean.parseBoolean(studioConfiguration.getProperty(PREVIEW_DISABLE_DEPLOY_CRON)));
    requestBody.setTemplateName(studioConfiguration.getProperty(PREVIEW_TEMPLATE_NAME));
    String repoUrl = studioConfiguration.getProperty(PREVIEW_REPO_URL)
            .replaceAll(StudioConstants.CONFIG_SITENAME_VARIABLE, site);
    Path repoUrlPath = Paths.get(repoUrl);
    repoUrl = repoUrlPath.normalize().toAbsolutePath().toString();
    requestBody.setRepoUrl(repoUrl);
    requestBody.setEngineUrl(studioConfiguration.getProperty(PREVIEW_ENGINE_URL));
    return requestBody.toJson();
}

From source file:org.sakuli.javaDSL.AbstractSakuliTest.java

protected String getSakuliHomeFolder() {
    String packageName = "/org/sakuli/common";
    Path sakuliHomeFolder = resolveResource(AbstractSakuliTest.class, packageName);
    if (Files.exists(sakuliHomeFolder)) {
        return sakuliHomeFolder.normalize().toAbsolutePath().toString();
    }//w  ww .  j ava2  s  .c om
    throw new SakuliRuntimeException(
            "Cannot load SAKULI_HOME folder! Should be normally under 'target/classes/" + packageName + "'");
}

From source file:ws.michalski.velogen.VeloGenManager.java

public void writeOutputFile(String fileName, String content, boolean replace) throws VeloGenException {

    Path target = Paths.get(getOutputPath(), fileName);

    if (!replace && Files.exists(target, LinkOption.NOFOLLOW_LINKS)) {
        throw new VeloGenException(target.normalize().toString() + " exist. Use option -ov for overwrite.");
    }//from  w  ww.  j av a2 s  .  c o m

    try (FileOutputStream fos = new FileOutputStream(target.toFile(), false)) {
        try (BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(fos))) {
            bwr.write(content);
            bwr.flush();
        }

        fos.flush();

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitBranchDeployer.java

private void addWorkAreaRemote(String site, Repository envStoreRepo) {
    envStoreRepo.getRemoteName("work-area");
    Git git = new Git(envStoreRepo);
    StoredConfig config = git.getRepository().getConfig();
    Path siteRepoPath = Paths.get(rootPath, "sites", site, ".git");
    config.setString("remote", "work-area", "url", siteRepoPath.normalize().toAbsolutePath().toString());
    try {//  w  w  w.j  av a 2s  . c  o m
        config.save();
    } catch (IOException e) {
        logger.error("Error adding work area as remote for environment store.", e);
    }
}