FileNameUtil { public static String getParentPath(String fileName) { if (fileName.startsWith(FileSystemUtil.CLASSPATH_PREFIX)) { int lastIndex = fileName.lastIndexOf('/'); return fileName.substring(0, lastIndex + 1); } else { File file = new File(fileName); try { return new File(file.getCanonicalPath()).getParent() + File.separator; } catch (IOException e) { throw new IllegalArgumentException(e); } } } private  FileNameUtil(); static List<File> identifyFiles(Map parameters); static boolean isIncluded(String name, Map parameters); static boolean matches(String name, List<String> patterns, boolean defaultValue); static boolean matches(String name, String pattern); static String getParentPath(String fileName); static String getCanonicalPath(String path);  }
@Test public void testGetBasePath() { assertThat(FileNameUtil.getParentPath("classpath:/visualization/DOT.stg"), Matchers.is("classpath:/visualization/")); assertThat(FileNameUtil.getParentPath("classpath:/application.properties"), Matchers.is("classpath:/")); assertThat(FileNameUtil.getParentPath("/home/user/project/x.txt"), endsWith("home" + File.separator + "user" + File.separator + "project" + File.separator)); assertThat(FileNameUtil.getParentPath("build.gradle"), endsWith(File.separator)); }