public class ThemeBuilderUtils extends Object
Constructor and Description |
---|
ThemeBuilderUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addExtensionToPatterns(String[] patterns,
String extension)
Iterates through the given list of patterns and checks whether the pattern ends with the given
extension or a wildcard, if not the extension is appended to the pattern
|
static String[] |
addToArray(String[] array,
String stringToAdd)
Adds the string to the end of the array of strings, or creates a new array containing the string
if the array parameter is null
|
static String[] |
addToArray(String[] array,
String[] arrayToAdd)
Adds the second array of strings to the end of the first array of strings, or creates a new array
containing the second array elements if the first does not exist
|
static String |
calculatePathToFile(File fromFile,
File toFile)
Calculates the path from the first file to the second
|
static void |
copyDirectory(String sourceDirectoryPath,
String targetDirectoryPath)
Copies all the contents from the directory given by the source path to the directory given by the
target path
|
static void |
copyMissingContent(File sourceDirectory,
File targetDirectory,
List<String> sourceExcludes)
Copies all content (files and directories) from the source directory to the target directory, except content
that already exists in the target directory (same name and path), in other words it does not override any
existing content
|
static void |
copyProperty(String propertyKey,
Properties sourceProperties,
Properties targetProperties)
Copies the property key/value from the source properties to the target properties if a property with the
same key does not exist in the target properties
|
static boolean |
directoryContainsFile(File directory,
String fileName)
Indicates whether there is a file with the given name within the given directory
|
protected static boolean |
fileMatchesPath(String path,
File file)
Indicates whether the given file is withing the given path (file's path starts with the given path), note
this does not check whether the file exists
|
static List<File> |
getContainedFiles(List<File> files,
List<File> directories)
Returns a list of files from the given list of files, that are contained within one of the given
list of directories
|
static List<String> |
getDirectoryContents(File baseDirectory,
String[] includes,
String[] excludes)
Retrieves a list of files and directories that are in the given directory, possibly filtered by the
list of include patterns or exclude patterns
|
static List<String> |
getDirectoryFileNames(File baseDirectory,
String[] includes,
String[] excludes)
Retrieves a list of file names that are in the given directory, possibly filtered by the list of include
patterns or exclude patterns
|
static List<File> |
getDirectoryFiles(File baseDirectory,
String[] includes,
String[] excludes)
Retrieves a list of files that are in the given directory, possibly filtered by the list of include
patterns or exclude patterns
|
static String[] |
getPropertyValueAsArray(String key,
Properties properties)
Retrieves the value for the property with the given key from the properties object, as an array of
strings (by splitting the value on commas)
|
static List<String> |
getPropertyValueAsList(String key,
Properties properties)
Retrieves the value for the property with the given key from the properties object, as a list of
strings (by splitting the value on commas)
|
static String |
getRelativePath(File parentDirectory,
File file)
Returns the path of the given file relative to the parent directory
|
static List<String> |
getRelativePaths(File parentDirectory,
List<File> files)
Builds a list of strings that hold the path from each given file relative to the parent
directory
|
static List<File> |
getSubDirectories(File baseDirectory,
List<String> subDirectoryNames)
Get the sub directories of the given directory that have the given names
|
static boolean |
inExcludeList(String name,
String[] excludes)
Determines if one of the given patterns matches the given name, or if the exclude list is null
or empty the file will not be excluded
|
static boolean |
inIncludeList(String name,
String[] includes)
Determines if one of the given patterns matches the given name, or if the include list is null
or empty the file will be included
|
static boolean |
isMatch(File file,
String pattern)
Indicates whether the base name for the given file (name without path and the extension) matches
the given pattern
|
static String |
joinFileList(List<File> list)
Builds a string formed with the name for each file in the list delimited by commas
|
static List<File> |
matchFiles(List<File> filesToMatch,
String pattern)
Iterates through the list of files and returns those files whose names matches the given pattern
|
static List<File> |
orderFiles(List<File> pluginFiles,
List<File> subDirFiles,
List<String> loadFirstPatterns,
List<String> loadLastPatterns,
List<String> pluginLoadOrder,
List<String> subDirLoadOrder)
Orders the list of plugin files and sub directory files according to the given patterns
|
static Properties |
retrieveThemeProperties(String themeDirectory)
Retrieve the
Properties object loaded from the theme.properties file found in the given
theme directory |
static void |
storeThemeProperties(String themeDirectory,
Properties themeProperties)
Stores the given properties object in a file named
theme-derived.properties within the
given theme directory |
static void |
validateFileExistence(List<File> filesToValidate,
String exceptionMessage)
Iterates through each file in the given list and verifies the file exists, if not a runtime
exception is thrown with the provided message
|
public ThemeBuilderUtils()
public static Properties retrieveThemeProperties(String themeDirectory) throws IOException
Properties
object loaded from the theme.properties file found in the given
theme directorythemeDirectory
- directory for the theme to pull properties file fromIOException
public static void storeThemeProperties(String themeDirectory, Properties themeProperties) throws IOException
theme-derived.properties
within the
given theme directorythemeDirectory
- directory the properties file should be created inthemeProperties
- properties that should be written to the properties fileIOException
public static List<String> getPropertyValueAsList(String key, Properties properties)
key
- key for the property to retrieveproperties
- properties object to pull property frompublic static String[] getPropertyValueAsArray(String key, Properties properties)
key
- key for the property to retrieveproperties
- properties object to pull property frompublic static void copyProperty(String propertyKey, Properties sourceProperties, Properties targetProperties)
propertyKey
- key of the property to copysourceProperties
- properties to pull the property fromtargetProperties
- properties to copy the property topublic static void validateFileExistence(List<File> filesToValidate, String exceptionMessage)
filesToValidate
- list of files to check existence forexceptionMessage
- message for runtime exception if a file is found that does not existpublic static boolean directoryContainsFile(File directory, String fileName)
directory
- directory to check for filefileName
- name of the file to check forpublic static List<File> getDirectoryFiles(File baseDirectory, String[] includes, String[] excludes)
baseDirectory
- directory to retrieve files fromincludes
- list of patterns to match against for files to include, can include Ant patternsexcludes
- list of patterns to match for excluded files, can include Ant patternspublic static List<String> getDirectoryFileNames(File baseDirectory, String[] includes, String[] excludes)
baseDirectory
- directory to retrieve file names fromincludes
- list of patterns to match against for file names to include, can include Ant patternsexcludes
- list of patterns to match for excluded file names, can include Ant patternspublic static List<File> getSubDirectories(File baseDirectory, List<String> subDirectoryNames)
baseDirectory
- directory containing the sub directoriessubDirectoryNames
- list of sub directory names to returnpublic static List<String> getDirectoryContents(File baseDirectory, String[] includes, String[] excludes)
baseDirectory
- directory to retrieve files and directories fromincludes
- list of patterns to match against for files to include, can include Ant patternsexcludes
- list of patterns to match for excluded files, can include Ant patternspublic static void copyDirectory(String sourceDirectoryPath, String targetDirectoryPath) throws IOException
If source directory does not exist nothing is performed. The target directory will be created if it does not exist. Any hidden directories (directory names that start with ".") will be deleted from the target directory
sourceDirectoryPath
- absolute path to the source directorytargetDirectoryPath
- absolute path to the target directoryIOException
public static void copyMissingContent(File sourceDirectory, File targetDirectory, List<String> sourceExcludes) throws IOException
Files from the source directory can be excluded from the copying by setting one or more patterns in the source excludes list
sourceDirectory
- directory to copy content fromtargetDirectory
- directory to copy content tosourceExcludes
- list of patterns to match on for source exclusionsIOException
public static boolean inIncludeList(String name, String[] includes)
name
- string to matchincludes
- list of string patterns to match onpublic static boolean inExcludeList(String name, String[] excludes)
name
- string to matchexcludes
- list of string patterns to match onpublic static void addExtensionToPatterns(String[] patterns, String extension)
patterns
- array of patterns to check and append to if necessaryextension
- string extension to check for and append if necessarypublic static List<String> getRelativePaths(File parentDirectory, List<File> files)
parentDirectory
- directory to build path fromfiles
- list of files to build relative paths forpublic static String getRelativePath(File parentDirectory, File file)
parentDirectory
- directory to build path fromfile
- file to build relative paths forpublic static String calculatePathToFile(File fromFile, File toFile)
Assumes there is a common base directory somewhere in the path of both files. Once it finds that base directory, builds the path starting at the from file to it, then adds the path from the base directory to the target file
fromFile
- file whose path is the starting pointtoFile
- file whose path is the ending pointprotected static boolean fileMatchesPath(String path, File file)
path
- path to check forfile
- file whose path should be checkedpublic static List<File> orderFiles(List<File> pluginFiles, List<File> subDirFiles, List<String> loadFirstPatterns, List<String> loadLastPatterns, List<String> pluginLoadOrder, List<String> subDirLoadOrder)
pluginFiles
- list of plugin files to ordersubDirFiles
- list of sub directory files to orderloadFirstPatterns
- list of patterns for files that should be ordered firstloadLastPatterns
- list of patterns for files that should be ordered lastpluginLoadOrder
- list of patterns for ordering the plugin filessubDirLoadOrder
- list of patterns for ordering the sub directory filespublic static List<File> matchFiles(List<File> filesToMatch, String pattern)
filesToMatch
- list of files to matchpattern
- pattern to match onpublic static boolean isMatch(File file, String pattern)
file
- file to matchpattern
- pattern to match onpublic static List<File> getContainedFiles(List<File> files, List<File> directories)
files
- list of files to filterdirectories
- list of directories to filter bypublic static String[] addToArray(String[] array, String stringToAdd)
array
- string array to add tostringToAdd
- string to addpublic static String[] addToArray(String[] array, String[] arrayToAdd)
Note: Can't use org.apache.commons.lang.ArrayUtils#addAll(java.lang.Object[], java.lang.Object[]) because it doesn't allow String arrays to be passed in. Latest version of ArrayUtils uses generics and does
array
- array to add toarrayToAdd
- array to addpublic static String joinFileList(List<File> list)
list
- list to join names forCopyright © 2005–2016 The Kuali Foundation. All rights reserved.