@Test public void testCalculatePathToFile() { File fromFile = new File("/basedir/subDir1/foo.css"); File toFile = new File("/basedir/subDir2/foo.css"); String path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile); Assert.assertEquals("Path incorrect for up one dir", "../subDir2/", path); fromFile = new File("/basedir/subDir1/foo.css"); toFile = new File("/basedir/subDir1/foo.css"); path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile); Assert.assertEquals("Path incorrect for same dir", "", path); fromFile = new File("/basedir/dir1/subDir1/foo.css"); toFile = new File("/basedir/dir2/subDir2/foo.css"); path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile); Assert.assertEquals("Path incorrect for up two dir", "../../dir2/subDir2/", path); fromFile = new File("/basedir/subDir1/foo.css"); toFile = new File("/basedir/subDir1/moreDir/foo.css"); path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile); Assert.assertEquals("Path incorrect for sub dir", "moreDir/", path); }
public static String calculatePathToFile(File fromFile, File toFile) { String pathToFile = ""; int directoriesUp = 0; String parentPath = fromFile.getParent(); while ((parentPath != null) && !fileMatchesPath(parentPath, toFile)) { File parent = new File(parentPath); parentPath = parent.getParent(); directoriesUp += 1; } if (parentPath != null) { for (int i = 0; i < directoriesUp; i++) { pathToFile += "../"; } String remainingPath = toFile.getPath().replace(parentPath, ""); if (remainingPath.startsWith(File.separator)) { remainingPath = remainingPath.substring(1); } remainingPath = remainingPath.replaceAll("\\\\", "/"); if (remainingPath.contains("/")) { int separatorIndex = remainingPath.lastIndexOf("/"); remainingPath = remainingPath.substring(0, separatorIndex + 1); } else { remainingPath = null; } if (remainingPath != null) { pathToFile += remainingPath; } } return pathToFile; }
ThemeBuilderUtils { public static String calculatePathToFile(File fromFile, File toFile) { String pathToFile = ""; int directoriesUp = 0; String parentPath = fromFile.getParent(); while ((parentPath != null) && !fileMatchesPath(parentPath, toFile)) { File parent = new File(parentPath); parentPath = parent.getParent(); directoriesUp += 1; } if (parentPath != null) { for (int i = 0; i < directoriesUp; i++) { pathToFile += "../"; } String remainingPath = toFile.getPath().replace(parentPath, ""); if (remainingPath.startsWith(File.separator)) { remainingPath = remainingPath.substring(1); } remainingPath = remainingPath.replaceAll("\\\\", "/"); if (remainingPath.contains("/")) { int separatorIndex = remainingPath.lastIndexOf("/"); remainingPath = remainingPath.substring(0, separatorIndex + 1); } else { remainingPath = null; } if (remainingPath != null) { pathToFile += remainingPath; } } return pathToFile; } }
ThemeBuilderUtils { public static String calculatePathToFile(File fromFile, File toFile) { String pathToFile = ""; int directoriesUp = 0; String parentPath = fromFile.getParent(); while ((parentPath != null) && !fileMatchesPath(parentPath, toFile)) { File parent = new File(parentPath); parentPath = parent.getParent(); directoriesUp += 1; } if (parentPath != null) { for (int i = 0; i < directoriesUp; i++) { pathToFile += "../"; } String remainingPath = toFile.getPath().replace(parentPath, ""); if (remainingPath.startsWith(File.separator)) { remainingPath = remainingPath.substring(1); } remainingPath = remainingPath.replaceAll("\\\\", "/"); if (remainingPath.contains("/")) { int separatorIndex = remainingPath.lastIndexOf("/"); remainingPath = remainingPath.substring(0, separatorIndex + 1); } else { remainingPath = null; } if (remainingPath != null) { pathToFile += remainingPath; } } return pathToFile; }  }
ThemeBuilderUtils { public static String calculatePathToFile(File fromFile, File toFile) { String pathToFile = ""; int directoriesUp = 0; String parentPath = fromFile.getParent(); while ((parentPath != null) && !fileMatchesPath(parentPath, toFile)) { File parent = new File(parentPath); parentPath = parent.getParent(); directoriesUp += 1; } if (parentPath != null) { for (int i = 0; i < directoriesUp; i++) { pathToFile += "../"; } String remainingPath = toFile.getPath().replace(parentPath, ""); if (remainingPath.startsWith(File.separator)) { remainingPath = remainingPath.substring(1); } remainingPath = remainingPath.replaceAll("\\\\", "/"); if (remainingPath.contains("/")) { int separatorIndex = remainingPath.lastIndexOf("/"); remainingPath = remainingPath.substring(0, separatorIndex + 1); } else { remainingPath = null; } if (remainingPath != null) { pathToFile += remainingPath; } } return pathToFile; }  static Properties retrieveThemeProperties(String themeDirectory); static void storeThemeProperties(String themeDirectory, Properties themeProperties); static List<String> getPropertyValueAsList(String key, Properties properties); static String[] getPropertyValueAsArray(String key, Properties properties); static void copyProperty(String propertyKey, Properties sourceProperties, Properties targetProperties); static void validateFileExistence(List<File> filesToValidate, String exceptionMessage); static boolean directoryContainsFile(File directory, String fileName); static List<File> getDirectoryFiles(File baseDirectory, String[] includes, String[] excludes); static List<String> getDirectoryFileNames(File baseDirectory, String[] includes, String[] excludes); static List<File> getSubDirectories(File baseDirectory, List<String> subDirectoryNames); static List<String> getDirectoryContents(File baseDirectory, String[] includes, String[] excludes); static void copyDirectory(String sourceDirectoryPath, String targetDirectoryPath); static void copyMissingContent(File sourceDirectory, File targetDirectory, List<String> sourceExcludes); static boolean inIncludeList(String name, String[] includes); static boolean inExcludeList(String name, String[] excludes); static void addExtensionToPatterns(String[] patterns, String extension); static List<String> getRelativePaths(File parentDirectory, List<File> files); static String getRelativePath(File parentDirectory, File file); static String calculatePathToFile(File fromFile, File toFile); static List<File> orderFiles(List<File> pluginFiles, List<File> subDirFiles, List<String> loadFirstPatterns,
            List<String> loadLastPatterns, List<String> pluginLoadOrder, List<String> subDirLoadOrder); static List<File> matchFiles(List<File> filesToMatch, String pattern); static boolean isMatch(File file, String pattern); static List<File> getContainedFiles(List<File> files, List<File> directories); static String[] addToArray(String[] array, String stringToAdd); static String[] addToArray(String[] array, String[] arrayToAdd); static String joinFileList(List<File> list); }
ThemeBuilderUtils { public static String calculatePathToFile(File fromFile, File toFile) { String pathToFile = ""; int directoriesUp = 0; String parentPath = fromFile.getParent(); while ((parentPath != null) && !fileMatchesPath(parentPath, toFile)) { File parent = new File(parentPath); parentPath = parent.getParent(); directoriesUp += 1; } if (parentPath != null) { for (int i = 0; i < directoriesUp; i++) { pathToFile += "../"; } String remainingPath = toFile.getPath().replace(parentPath, ""); if (remainingPath.startsWith(File.separator)) { remainingPath = remainingPath.substring(1); } remainingPath = remainingPath.replaceAll("\\\\", "/"); if (remainingPath.contains("/")) { int separatorIndex = remainingPath.lastIndexOf("/"); remainingPath = remainingPath.substring(0, separatorIndex + 1); } else { remainingPath = null; } if (remainingPath != null) { pathToFile += remainingPath; } } return pathToFile; }  static Properties retrieveThemeProperties(String themeDirectory); static void storeThemeProperties(String themeDirectory, Properties themeProperties); static List<String> getPropertyValueAsList(String key, Properties properties); static String[] getPropertyValueAsArray(String key, Properties properties); static void copyProperty(String propertyKey, Properties sourceProperties, Properties targetProperties); static void validateFileExistence(List<File> filesToValidate, String exceptionMessage); static boolean directoryContainsFile(File directory, String fileName); static List<File> getDirectoryFiles(File baseDirectory, String[] includes, String[] excludes); static List<String> getDirectoryFileNames(File baseDirectory, String[] includes, String[] excludes); static List<File> getSubDirectories(File baseDirectory, List<String> subDirectoryNames); static List<String> getDirectoryContents(File baseDirectory, String[] includes, String[] excludes); static void copyDirectory(String sourceDirectoryPath, String targetDirectoryPath); static void copyMissingContent(File sourceDirectory, File targetDirectory, List<String> sourceExcludes); static boolean inIncludeList(String name, String[] includes); static boolean inExcludeList(String name, String[] excludes); static void addExtensionToPatterns(String[] patterns, String extension); static List<String> getRelativePaths(File parentDirectory, List<File> files); static String getRelativePath(File parentDirectory, File file); static String calculatePathToFile(File fromFile, File toFile); static List<File> orderFiles(List<File> pluginFiles, List<File> subDirFiles, List<String> loadFirstPatterns,
            List<String> loadLastPatterns, List<String> pluginLoadOrder, List<String> subDirLoadOrder); static List<File> matchFiles(List<File> filesToMatch, String pattern); static boolean isMatch(File file, String pattern); static List<File> getContainedFiles(List<File> files, List<File> directories); static String[] addToArray(String[] array, String stringToAdd); static String[] addToArray(String[] array, String[] arrayToAdd); static String joinFileList(List<File> list);  }