public class PropertiesUtils extends Object
Util Properties methods which have come from refactoring test generation using freemarker, providing overriding of file properties from System Properties as well as setting file properties as System Properties, as well as turning numbered properties to a List.
Constructor and Description |
---|
PropertiesUtils() |
Modifier and Type | Method and Description |
---|---|
Properties |
loadProperties(InputStream inputStream)
Plain load Properties from the given inputStream.
|
Properties |
loadProperties(String location)
Read Properties from given Loaction
|
Properties |
loadProperties(String fileLocation,
String resourceLocation)
Deprecated.
|
Properties |
loadPropertiesWithSystemAndOverrides(String location) |
Properties |
loadPropertiesWithSystemAndOverridesIntoSystem(String location)
Beware of classloader/timing issues! Sometimes properties get added to the System properties after the point
you might expect.
|
Properties |
loadPropertiesWithSystemOverrides(InputStream inputStream)
Read the properties from an inputStream overridding keys defined as JVM arguments.
|
Properties |
loadPropertiesWithSystemOverrides(String location) |
Properties |
loadPropertiesWithSystemOverridesAndNumberedPropertiesToList(InputStream inputStream)
Read the properties from an inputStream overridding keys defined as JVM arguments and transforming numbered keys
into a list.
|
String |
removeNumber(String numberedKey)
Given a key that ends in a number, remove the number.
|
Properties |
systemPropertiesAndOverride(Properties props) |
Properties |
systemPropertiesAndOverride(Properties props,
String arg)
In addition to overriding file properties from System Properties, System properties are added to the returned
Properties.
|
Properties |
systemPropertiesOverride(Properties props)
Override the given Properties with JVM argument
-Dkey=value . |
Properties |
systemPropertiesOverride(Properties props,
String arg)
Override the given Properties with JVM argument
-Darg.key=value . |
Properties |
transformNumberedPropertiesToList(Properties props)
Transform the given Properties keys which end in numbers to a List placed in a Map with the map key being the unumbered
part of the Properties key with an s appended to it.
|
public PropertiesUtils()
public Properties loadProperties(InputStream inputStream) throws IOException
Plain load Properties from the given inputStream.
inputStream
- to read properties fromIOException
public Properties loadProperties(String fileLocation, String resourceLocation) throws IOException
loadProperties(String)
Read Properties from given Inputstream or Resource Loaction if the InputStream is null.
If a FileNotFoundException is thrown opening the InputStream an attempt will be made to read as a resource.
fileLocation
- null means use resourceLocationresourceLocation
- load resource as a stream getClass().getClassLoader().getResourceAsStream(resourceLocation);
IOException
public Properties loadProperties(String location) throws IOException
Read Properties from given Loaction
If a FileNotFoundException is thrown opening the InputStream an attempt will be made to read as a resource.
location
- IOException
public Properties loadPropertiesWithSystemAndOverrides(String location) throws IOException
IOException
public Properties loadPropertiesWithSystemAndOverridesIntoSystem(String location) throws IOException
Beware of classloader/timing issues! Sometimes properties get added to the System properties after the point you might expect. Resulting in the System property not really being set for when you expected, such as with settign statics. Looks like WebDriverLegacyITBase has this going on with public.remote.url
location
- file or resource to load properties from, file is attempted firstIOException
public Properties loadPropertiesWithSystemOverrides(String location) throws IOException
IOException
public Properties loadPropertiesWithSystemOverrides(InputStream inputStream) throws IOException
Read the properties from an inputStream overridding keys defined as JVM arguments.
inputStream
- to read properties fromIOException
public Properties loadPropertiesWithSystemOverridesAndNumberedPropertiesToList(InputStream inputStream) throws IOException
Read the properties from an inputStream overridding keys defined as JVM arguments and transforming numbered keys into a list.
systemPropertiesOverride(java.util.Properties)
transformNumberedPropertiesToList(java.util.Properties)
inputStream
- IOException
public String removeNumber(String numberedKey)
Given a key that ends in a number, remove the number.
numberedKey
- in the form of some.key.numberpublic Properties systemPropertiesAndOverride(Properties props)
public Properties systemPropertiesOverride(Properties props)
Override the given Properties with JVM argument -Dkey=value
.
props
- properties to update with System.getProperty overrides.public Properties systemPropertiesAndOverride(Properties props, String arg)
In addition to overriding file properties from System Properties, System properties are added to the returned Properties.
props
- Properties with System Properties added and Overriding file propertiesarg
- filter System Properties added to Properties by the Property key starting with argpublic Properties systemPropertiesOverride(Properties props, String arg)
Override the given Properties with JVM argument -Darg.key=value
.
-Dkey.propertyname= to override the property value for propertyname.
props
- properties to update with System.getProperty overrides.arg
- optional value that the property names will be appended to.public Properties transformNumberedPropertiesToList(Properties props)
Transform the given Properties keys which end in numbers to a List placed in a Map with the map key being the unumbered part of the Properties key with an s appended to it.
props
- Properties to have keys ending inCopyright © 2005–2014 The Kuali Foundation. All rights reserved.