Class ThemeBuilderUtils
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddExtensionToPatterns(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 patternstatic 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 nullstatic 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 existstatic StringcalculatePathToFile(File fromFile, File toFile) Calculates the path from the first file to the secondstatic voidcopyDirectory(String sourceDirectoryPath, String targetDirectoryPath) Copies all the contents from the directory given by the source path to the directory given by the target pathstatic voidcopyMissingContent(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 contentstatic voidcopyProperty(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 propertiesprotected static booleanfileMatchesPath(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 existsgetDirectoryContents(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 patternsgetDirectoryFileNames(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 patternsgetDirectoryFiles(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 patternsstatic 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)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 StringgetRelativePath(File parentDirectory, File file) Returns the path of the given file relative to the parent directorygetRelativePaths(File parentDirectory, List<File> files) Builds a list of strings that hold the path from each given file relative to the parent directorygetSubDirectories(File baseDirectory, List<String> subDirectoryNames) Get the sub directories of the given directory that have the given namesstatic booleaninExcludeList(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 excludedstatic booleaninIncludeList(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 includedstatic booleanIndicates whether the base name for the given file (name without path and the extension) matches the given patternmatchFiles(List<File> filesToMatch, String pattern) Iterates through the list of files and returns those files whose names matches the given patternorderFiles(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 patternsstatic PropertiesretrieveThemeProperties(String themeDirectory) Retrieve thePropertiesobject loaded from the theme.properties file found in the given theme directorystatic voidstoreThemeProperties(String themeDirectory, Properties themeProperties) Stores the given properties object in a file namedtheme-derived.propertieswithin the given theme directorystatic voidvalidateFileExistence(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
-
Constructor Details
-
ThemeBuilderUtils
public ThemeBuilderUtils()
-
-
Method Details
-
retrieveThemeProperties
Retrieve thePropertiesobject loaded from the theme.properties file found in the given theme directory- Parameters:
themeDirectory- directory for the theme to pull properties file from- Returns:
- Properties object loaded with the theme configuration, or null if the properties file does not exist
- Throws:
IOException
-
storeThemeProperties
public static void storeThemeProperties(String themeDirectory, Properties themeProperties) throws IOException Stores the given properties object in a file namedtheme-derived.propertieswithin the given theme directory- Parameters:
themeDirectory- directory the properties file should be created inthemeProperties- properties that should be written to the properties file- Throws:
IOException
-
getPropertyValueAsList
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)- Parameters:
key- key for the property to retrieveproperties- properties object to pull property from- Returns:
- list of strings parsed from the property value
-
getPropertyValueAsArray
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)- Parameters:
key- key for the property to retrieveproperties- properties object to pull property from- Returns:
- array of strings parsed from the property value
-
copyProperty
public 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- Parameters:
propertyKey- key of the property to copysourceProperties- properties to pull the property fromtargetProperties- properties to copy the property to
-
validateFileExistence
Iterates through each file in the given list and verifies the file exists, if not a runtime exception is thrown with the provided message- Parameters:
filesToValidate- list of files to check existence forexceptionMessage- message for runtime exception if a file is found that does not exist
-
getDirectoryFiles
public 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- Parameters:
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 patterns- Returns:
- list of files within the directory that match all given patterns
-
getDirectoryFileNames
public 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- Parameters:
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 patterns- Returns:
- list of file names within the directory that match all given patterns
-
getSubDirectories
Get the sub directories of the given directory that have the given names- Parameters:
baseDirectory- directory containing the sub directoriessubDirectoryNames- list of sub directory names to return- Returns:
- list of Files pointing to the sub directories
-
getDirectoryContents
public 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- Parameters:
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 patterns- Returns:
- list of files within the directory that match all given patterns
-
copyDirectory
public static void copyDirectory(String sourceDirectoryPath, String targetDirectoryPath) throws IOException Copies all the contents from the directory given by the source path to the directory given by the target pathIf 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
- Parameters:
sourceDirectoryPath- absolute path to the source directorytargetDirectoryPath- absolute path to the target directory- Throws:
IOException
-
copyMissingContent
public static void copyMissingContent(File sourceDirectory, File targetDirectory, List<String> sourceExcludes) throws IOException 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 contentFiles from the source directory can be excluded from the copying by setting one or more patterns in the source excludes list
- Parameters:
sourceDirectory- directory to copy content fromtargetDirectory- directory to copy content tosourceExcludes- list of patterns to match on for source exclusions- Throws:
IOException
-
inIncludeList
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- Parameters:
name- string to matchincludes- list of string patterns to match on- Returns:
- true if the name is a match, false if not
-
inExcludeList
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- Parameters:
name- string to matchexcludes- list of string patterns to match on- Returns:
- true if the name is a match, false if not
-
addExtensionToPatterns
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- Parameters:
patterns- array of patterns to check and append to if necessaryextension- string extension to check for and append if necessary
-
getRelativePaths
Builds a list of strings that hold the path from each given file relative to the parent directory- Parameters:
parentDirectory- directory to build path fromfiles- list of files to build relative paths for- Returns:
- list of strings containing the relative paths
-
getRelativePath
Returns the path of the given file relative to the parent directory- Parameters:
parentDirectory- directory to build path fromfile- file to build relative paths for- Returns:
- string containing the relative path
-
calculatePathToFile
Calculates the path from the first file to the secondAssumes 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
- Parameters:
fromFile- file whose path is the starting pointtoFile- file whose path is the ending point- Returns:
- string containing the path
-
fileMatchesPath
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- Parameters:
path- path to check forfile- file whose path should be checked- Returns:
- true if the file is contained in the path, false if not
-
orderFiles
public 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- Parameters:
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 files- Returns:
- list containing all of the given plugin and sub directory files ordered by the given patterns
-
matchFiles
Iterates through the list of files and returns those files whose names matches the given pattern- Parameters:
filesToMatch- list of files to matchpattern- pattern to match on- Returns:
- list of files whose name that match the pattern
-
isMatch
Indicates whether the base name for the given file (name without path and the extension) matches the given pattern- Parameters:
file- file to matchpattern- pattern to match on- Returns:
- true if the file name matches the pattern, false if not
-
addToArray
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- Parameters:
array- string array to add tostringToAdd- string to add- Returns:
- array containing all the original array elements plus the string
-
addToArray
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 existNote: 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
- Parameters:
array- array to add toarrayToAdd- array to add- Returns:
- array containing all the strings from both arrays
-