List of usage examples for org.apache.commons.io FilenameUtils separatorsToUnix
public static String separatorsToUnix(String path)
From source file:org.skb.util.io.dirwalker.FindPackageDirectories.java
protected boolean handleDirectory(File directory, int depth, Collection results) { String fn = new String(); try {// www. j a v a 2s .co m fn = FilenameUtils.separatorsToUnix(directory.getCanonicalPath()); } catch (Exception e) { System.err.println(e); } if (StringUtils.indexOfAny(fn, new String[] { "/core", "/dist", "/" + this.site_id }) != -1) results.add(fn); return true; }
From source file:org.sonar.api.scan.filesystem.internal.DefaultInputFile.java
private DefaultInputFile(File file, String path, Map<String, String> attributes) { this.absolutePath = PathUtils.canonicalPath(file); this.path = FilenameUtils.separatorsToUnix(path); this.attributes = attributes; }
From source file:org.sonar.api.scan.filesystem.internal.DefaultInputFileTest.java
@Test public void test_file() throws Exception { File sourceDir = temp.newFolder(); File file = temp.newFile("Foo.java"); InputFile input = new InputFileBuilder(file, "src/main/java/Foo.java").sourceDir(sourceDir).build(); assertThat(input.name()).isEqualTo("Foo.java"); assertThat(input.file()).isEqualTo(file); assertThat(input.attribute(InputFile.ATTRIBUTE_SOURCEDIR_PATH)) .isEqualTo(FilenameUtils.separatorsToUnix(sourceDir.getAbsolutePath())); assertThat(input.path()).isEqualTo("src/main/java/Foo.java"); assertThat(input.absolutePath()).isEqualTo(PathUtils.canonicalPath(file)); }
From source file:org.sonar.api.scan.filesystem.PathResolverTest.java
@Test public void get_file_by_relative_path() throws IOException { PathResolver resolver = new PathResolver(); File rootDir = temp.newFolder(); File file = resolver.relativeFile(rootDir, "org/foo/Bar.java"); assertThat(file.getName()).isEqualTo("Bar.java"); assertThat(FilenameUtils.separatorsToUnix(file.getCanonicalPath())).endsWith("org/foo/Bar.java"); assertThat(file.getParentFile().getParentFile().getParentFile().getCanonicalPath()) .isEqualTo(rootDir.getCanonicalPath()); }
From source file:org.sonar.api.scan.filesystem.PathResolverTest.java
@Test public void get_file_by_absolute_path() throws IOException { PathResolver resolver = new PathResolver(); File rootDir = temp.newFolder(); File file = resolver.relativeFile(rootDir, new File(rootDir, "org/foo/Bar.java").getAbsolutePath()); assertThat(file.getName()).isEqualTo("Bar.java"); assertThat(FilenameUtils.separatorsToUnix(file.getCanonicalPath())).endsWith("org/foo/Bar.java"); assertThat(file.getParentFile().getParentFile().getParentFile().getCanonicalPath()) .isEqualTo(rootDir.getCanonicalPath()); }
From source file:org.sonar.api.utils.PathUtils.java
/** * Get canonical path and replace file separators by forward slash. This * method does not throw boring checked exception. *//*from w w w . j a v a2 s . c o m*/ @CheckForNull public static String canonicalPath(@Nullable File file) { if (file == null) { return null; } try { return FilenameUtils.separatorsToUnix(file.getCanonicalPath()); } catch (IOException e) { throw new IllegalStateException("Fail to get the canonical path of " + file.getAbsolutePath(), e); } }
From source file:org.sonar.api.utils.PathUtilsTest.java
@Test public void test_canonicalPath() throws Exception { File file = temp.newFile();/*w w w . j av a2 s. c om*/ String path = PathUtils.canonicalPath(file); assertThat(path).isEqualTo(FilenameUtils.separatorsToUnix(file.getCanonicalPath())); }
From source file:org.sonar.batch.scan.filesystem.DeprecatedFileFiltersTest.java
@Test public void at_least_one_filter() throws Exception { DeprecatedFileFilters filters = new DeprecatedFileFilters(new FileSystemFilter[] { filter }); File basedir = temp.newFolder(); File file = new File(basedir, "src/main/java/Foo.java"); InputFile inputFile = new DefaultInputFile("foo", "src/main/java/Foo.java") .setModuleBaseDir(basedir.toPath()).setType(InputFile.Type.MAIN); when(filter.accept(eq(file), any(DeprecatedFileFilters.DeprecatedContext.class))).thenReturn(false); assertThat(filters.accept(inputFile)).isFalse(); ArgumentCaptor<DeprecatedFileFilters.DeprecatedContext> argument = ArgumentCaptor .forClass(DeprecatedFileFilters.DeprecatedContext.class); verify(filter).accept(eq(file), argument.capture()); DeprecatedFileFilters.DeprecatedContext context = argument.getValue(); assertThat(context.canonicalPath()).isEqualTo(FilenameUtils.separatorsToUnix(file.getAbsolutePath())); assertThat(context.relativePath()).isEqualTo("src/main/java/Foo.java"); assertThat(context.type()).isEqualTo(FileType.MAIN); }
From source file:org.sonar.batch.scan.filesystem.FileFilterContext.java
FileFilterContext setCanonicalPath(String s) { this.fileCanonicalPath = FilenameUtils.separatorsToUnix(s); return this; }
From source file:org.sonar.batch.scan.filesystem.ModuleFileSystemInitializerTest.java
private String path(File f) throws IOException { return FilenameUtils.separatorsToUnix(f.getCanonicalPath()); }