Example usage for org.apache.commons.io FilenameUtils normalize

List of usage examples for org.apache.commons.io FilenameUtils normalize

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils normalize.

Prototype

public static String normalize(String filename, boolean unixSeparator) 

Source Link

Document

Normalizes a path, removing double and single dot path steps.

Usage

From source file:org.sonar.api.batch.fs.internal.AbsolutePathPredicate.java

AbsolutePathPredicate(String path) {
    this.path = FilenameUtils.normalize(path, true);
}

From source file:org.sonar.api.batch.fs.internal.RelativePathPredicate.java

RelativePathPredicate(String path) {
    this.path = FilenameUtils.normalize(path, true);
}

From source file:org.sonar.api.utils.PathUtils.java

/**
 * Normalize path and replace file separators by forward slash
 *//*  w  ww .  ja v a 2  s.  co m*/
@CheckForNull
public static String sanitize(@Nullable String path) {
    return FilenameUtils.normalize(path, true);
}

From source file:org.sonar.application.AppTest.java

@Test
public void starPath() throws IOException {
    File homeDir = temp.newFolder();
    String startPath = App.starPath(homeDir, "lib/search");
    assertThat(FilenameUtils.normalize(startPath, true)).endsWith("*")
            .startsWith(FilenameUtils.normalize(homeDir.getAbsolutePath(), true));
}

From source file:org.sonar.batch.scan.filesystem.InputFileBuilder.java

private void fillDeprecatedData(DeprecatedDefaultInputFile inputFile) {
    List<File> sourceDirs = InputFile.Type.MAIN == inputFile.type() ? fs.sourceDirs() : fs.testDirs();
    for (File sourceDir : sourceDirs) {
        String sourceRelativePath = pathResolver.relativePath(sourceDir, inputFile.file());
        if (sourceRelativePath != null) {
            inputFile.setPathRelativeToSourceDir(sourceRelativePath);
            inputFile.setSourceDirAbsolutePath(FilenameUtils.normalize(sourceDir.getAbsolutePath(), true));

            if ("java".equals(inputFile.language())) {
                inputFile.setDeprecatedKey(new StringBuilder().append(moduleKey).append(":")
                        .append(DeprecatedKeyUtils.getJavaFileDeprecatedKey(sourceRelativePath)).toString());
            } else {
                inputFile.setDeprecatedKey(new StringBuilder().append(moduleKey).append(":")
                        .append(sourceRelativePath).toString());
            }/*from w w  w  .  ja  v  a  2 s  .  com*/
        }
    }
}

From source file:org.sonatype.nexus.repository.httpbridge.internal.RepositoryPath.java

private static String validateAndExtractPath(final String input) {
    String path = input.substring(input.indexOf('/', 1), input.length());
    path = FilenameUtils.normalize(path, true); //unixSeparator:true is necessary to make this work on Windows.
    if (path == null) {
        throw new BadRequestException("Repository path must not contain a relative token");
    }/*w  w  w. j a v  a  2 s.  c o  m*/
    return path;
}

From source file:org.walkmod.util.FileResource.java

@Override
public Iterator<File> iterator() {
    String fileNormalized = FilenameUtils.normalize(file.getAbsolutePath(), true);
    if (includes != null) {
        for (int i = 0; i < includes.length; i++) {

            if (!includes[i].startsWith(fileNormalized)) {

                includes[i] = fileNormalized + "/" + includes[i];

            }/*from  w ww.j  av a2  s .c om*/
            if (includes[i].endsWith("**")) {
                includes[i] = includes[i].substring(0, includes[i].length() - 3);
            }
        }
    }
    if (excludes != null) {
        for (int i = 0; i < excludes.length; i++) {

            if (!excludes[i].startsWith(fileNormalized)) {
                excludes[i] = fileNormalized + "/" + excludes[i];

            }
            if (excludes[i].endsWith("**")) {
                excludes[i] = excludes[i].substring(0, excludes[i].length() - 3);
            }
        }
    }

    if (file.isDirectory()) {

        IOFileFilter filter = null;

        IOFileFilter directoryFilter = TrueFileFilter.INSTANCE;
        if (excludes != null || includes != null) {

            directoryFilter = new IOFileFilter() {

                @Override
                public boolean accept(File dir, String name) {

                    boolean excludesEval = false;
                    boolean includesEval = false;
                    String aux = FilenameUtils.normalize(name, true);
                    if (excludes != null) {
                        for (int i = 0; i < excludes.length && !excludesEval; i++) {
                            excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i])
                                    || dir.getAbsolutePath().startsWith(excludes[i]));
                        }
                    }
                    if (includes != null) {
                        for (int i = 0; i < includes.length && !includesEval; i++) {
                            includesEval = matches(aux, includes[i]);
                        }
                    } else {
                        includesEval = true;
                    }
                    return (includesEval && !excludesEval) || (includes == null && excludes == null);

                }

                @Override
                public boolean accept(File file) {
                    boolean excludesEval = false;
                    boolean includesEval = false;

                    String aux = FilenameUtils.normalize(file.getAbsolutePath(), true);
                    if (excludes != null) {

                        for (int i = 0; i < excludes.length && !excludesEval; i++) {
                            excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i])
                                    || file.getParentFile().getAbsolutePath().startsWith(excludes[i]));
                        }
                    }
                    if (includes != null) {
                        for (int i = 0; i < includes.length && !includesEval; i++) {
                            includesEval = matches(aux, includes[i]);
                        }
                    } else {
                        includesEval = true;
                    }
                    boolean result = (includesEval && !excludesEval) || (includes == null && excludes == null);

                    return result;

                }
            };
            if (extensions == null) {
                filter = directoryFilter;

            } else {
                String[] suffixes = toSuffixes(extensions);
                filter = new SuffixFileFilter(suffixes);
            }

        } else {
            if (extensions == null) {
                filter = TrueFileFilter.INSTANCE;
            } else {
                String[] suffixes = toSuffixes(extensions);
                filter = new SuffixFileFilter(suffixes);
            }
        }

        return FileUtils.listFiles(file, filter, directoryFilter).iterator();
    }
    Collection<File> aux = new LinkedList<File>();
    if (extensions == null) {
        aux.add(file);
    }
    return aux.iterator();
}

From source file:org.walkmod.util.FileResource.java

public void setIncludes(String[] includes) {
    if (includes != null && System.getProperty("os.name").toLowerCase().contains("windows")) {
        for (int i = 0; i < includes.length; i++) {
            includes[i] = FilenameUtils.normalize(includes[i], true);
        }/*w ww .j  a  va  2 s  .c  om*/
    }
    this.includes = includes;

}

From source file:org.walkmod.util.FileResource.java

public void setExcludes(String[] excludes) {
    if (excludes != null && System.getProperty("os.name").toLowerCase().contains("windows")) {
        for (int i = 0; i < excludes.length; i++) {
            excludes[i] = FilenameUtils.normalize(excludes[i], true);
        }/*w w w.  j a  v  a  2s.co m*/
    }
    this.excludes = excludes;
}

From source file:org.walkmod.writers.AbstractFileWriter.java

public void setOutputDirectory(String outputDirectory) {
    this.outputDirectory = new File(outputDirectory);
    if (!this.outputDirectory.exists()) {
        this.outputDirectory.mkdir();
    }/*from  ww w  .  ja  v a  2 s.c om*/
    normalizedOutputDirectory = FilenameUtils.normalize(this.outputDirectory.getAbsolutePath(), true);
}