List of usage examples for org.apache.commons.io FilenameUtils separatorsToUnix
public static String separatorsToUnix(String path)
From source file:org.eclipse.wb.tests.designer.swt.model.property.ImagePropertyEditorTestWithManager.java
/** * Image creation using constructor with absolute file path. *//*from w w w.j a va 2s . c o m*/ public void test_textSource_absolutePath2() throws Exception { File file = createTempImage(); try { String path = FilenameUtils.separatorsToUnix(file.getCanonicalPath()); assert_getText_getClipboardSource_forSource2( "org.eclipse.wb.swt.SWTResourceManager.getImage(\"" + path + "\")", "File: " + path, "org.eclipse.wb.swt.SWTResourceManager.getImage(\"" + path + "\")"); } finally { file.delete(); } }
From source file:org.geotools.gce.imagecollection.ImageCollectionReaderTest.java
@Test public void testForbiddenPath() throws IllegalArgumentException, IOException, NoSuchAuthorityCodeException, CQLException { final File file = TestData.file(this, "sample"); final String absolutePath = FilenameUtils.separatorsToUnix(file.getAbsolutePath()); final String string = "PATH='" + absolutePath + "/folder1/../../forbiddenFolder/classifiedFile.tif'"; Filter filter = CQL.toFilter(string); final ImageCollectionReader reader = new ImageCollectionReader(file); final ParameterValue<Filter> ff = ImageCollectionFormat.FILTER.createValue(); ff.setValue(filter);//from ww w.j a v a 2s . co m GeneralParameterValue[] params = new GeneralParameterValue[] { ff }; if (reader != null) { // reading the coverage GridCoverage2D coverage = null; boolean exception = true; try { coverage = (GridCoverage2D) reader.read(params); exception = false; } catch (DataSourceException exc) { assertTrue(exception); } } }
From source file:org.geotools.gce.imagemosaic.CatalogManager.java
/** * Get the relative path from one file to another, specifying the directory separator. * If one of the provided resources does not exist, it is assumed to be a file unless it ends with '/' or * '\'./*from w w w . jav a 2 s.com*/ * * @param targetPath targetPath is calculated to this file * @param basePath basePath is calculated from this file * @param pathSeparator directory separator. The platform default is not assumed so that * we can test Unix behaviour when running on Windows (for example) * @return */ public static String getRelativePath(String targetPath, String basePath, String pathSeparator) { // Normalize the paths String normalizedTargetPath = FilenameUtils.normalizeNoEndSeparator(targetPath); String normalizedBasePath = FilenameUtils.normalizeNoEndSeparator(basePath); // Undo the changes to the separators made by normalization if (pathSeparator.equals("/")) { normalizedTargetPath = FilenameUtils.separatorsToUnix(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToUnix(normalizedBasePath); } else if (pathSeparator.equals("\\")) { normalizedTargetPath = FilenameUtils.separatorsToWindows(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToWindows(normalizedBasePath); } else { throw new IllegalArgumentException("Unrecognised dir separator '" + pathSeparator + "'"); } String[] base = normalizedBasePath.split(Pattern.quote(pathSeparator)); String[] target = normalizedTargetPath.split(Pattern.quote(pathSeparator)); // First get all the common elements. Store them as a string, // and also count how many of them there are. StringBuilder common = new StringBuilder(); int commonIndex = 0; while (commonIndex < target.length && commonIndex < base.length && target[commonIndex].equals(base[commonIndex])) { common.append(target[commonIndex] + pathSeparator); commonIndex++; } if (commonIndex == 0) { // No single common path element. This most // likely indicates differing drive letters, like C: and D:. // These paths cannot be relativized. throw new RuntimeException("No common path element found for '" + normalizedTargetPath + "' and '" + normalizedBasePath + "'"); } // The number of directories we have to backtrack depends on whether the base is a file or a dir // For example, the relative path from // // /foo/bar/baz/gg/ff to /foo/bar/baz // // ".." if ff is a file // "../.." if ff is a directory // // The following is a heuristic to figure out if the base refers to a file or dir. It's not perfect, because // the resource referred to by this path may not actually exist, but it's the best I can do boolean baseIsFile = true; File baseResource = new File(normalizedBasePath); if (baseResource.exists()) { baseIsFile = baseResource.isFile(); } else if (basePath.endsWith(pathSeparator)) { baseIsFile = false; } StringBuilder relative = new StringBuilder(); if (base.length != commonIndex) { int numDirsUp = baseIsFile ? base.length - commonIndex - 1 : base.length - commonIndex; for (int i = 0; i < numDirsUp; i++) { relative.append(".." + pathSeparator); } } relative.append(normalizedTargetPath.substring(common.length())); return relative.toString(); }
From source file:org.glassfish.tyrus.tests.qa.tools.GlassFishToolkit.java
private String getClazzCanonicalName(File clazz) { logger.log(Level.FINE, "getClazzCanonicalName:{0}", clazz.toString()); return FilenameUtils.removeExtension(FilenameUtils.separatorsToUnix(clazz.toString())) .replaceFirst("target/classes/", "").replace('/', '.'); }
From source file:org.glassfish.tyrus.tests.qa.tools.Misc.java
/** * Copy file set to the target directory. If the directory does not exist it * is created./*w w w . j ava2s .c o m*/ * * @param fileSet set of files to be copied * @param dstDirectory destination where the files are copied */ public static void copyFiles(Set<File> fileSet, File dstDirectory, String regex, String move) throws IOException { if (!dstDirectory.isDirectory()) { FileUtils.forceMkdir(dstDirectory); } for (File src : fileSet) { File srcParent = src.getParentFile(); String targetDir = FilenameUtils.separatorsToUnix(srcParent.toString()); if (regex != null) { if (move == null) { move = ""; } targetDir = targetDir.replaceFirst(regex, move); } File dst = new File(dstDirectory, targetDir); logger.log(Level.FINE, "copyFiles: {0} ---> {1}", new Object[] { src, dst }); FileUtils.copyFileToDirectory(src, dst); } }
From source file:org.gradle.api.tasks.ide.eclipse.EclipseClasspath.java
private void addLibs(Element root) { for (String path : EclipseUtil.getSortedStringList(getClasspathLibs())) { classpathEntry(root, LIB, FilenameUtils.separatorsToUnix(path)); }/*from w w w .ja va 2s . c om*/ }
From source file:org.gradle.api.tasks.ide.eclipse.EclipseClasspath.java
private void addTestSrcDirs(Element root) { for (String testSrcDir : existingRelativePaths(getTestSrcDirs())) { classpathEntry(root, SRC, testSrcDir).addAttribute(OUTPUT, FilenameUtils.separatorsToUnix(relativePath(getTestOutputDirectory()))); }//from w ww . j a va 2s . com }
From source file:org.gradle.api.tasks.ide.eclipse.EclipseUtil.java
static String relativePath(Project project, Object path) { return FilenameUtils.separatorsToUnix(project.relativePath(path).toString()); }
From source file:org.gradle.api.tasks.ide.eclipse.EclipseWtp.java
private void addLibs(Element wbModule) { for (String libPath : EclipseUtil.getSortedStringList(getWarLibs())) { wbModule.addElement("dependent-module").addAttribute("deploy-path", "/WEB-INF/lib") .addAttribute("handle", "module:/classpath/lib//" + FilenameUtils.separatorsToUnix(libPath)) .addElement("dependency-type").setText("uses"); }//from ww w . ja v a 2s. co m }
From source file:org.gradle.api.tasks.wrapper.internal.WrapperScriptGenerator.java
private void createUnixScript(String jarPath, File scriptFile, String wrapperPropertiesPath) throws IOException { String unixWrapperScriptHead = IOUtils .toString(getClass().getResourceAsStream("unixWrapperScriptHead.txt")); String unixWrapperScriptTail = IOUtils .toString(getClass().getResourceAsStream("unixWrapperScriptTail.txt")); String fillingUnix = "" + UNIX_NL + "STARTER_MAIN_CLASS=" + FULLY_QUALIFIED_WRAPPER_NAME + UNIX_NL + "CLASSPATH=" + CURRENT_DIR_UNIX + "/" + FilenameUtils.separatorsToUnix(jarPath) + UNIX_NL + "WRAPPER_PROPERTIES=" + CURRENT_DIR_UNIX + "/" + FilenameUtils.separatorsToUnix(wrapperPropertiesPath) + UNIX_NL; String unixScript = unixWrapperScriptHead + fillingUnix + unixWrapperScriptTail; File unixScriptFile = scriptFile; FileUtils.writeStringToFile(unixScriptFile, unixScript); createExecutablePermission(unixScriptFile); }