public class PropertyUtils extends Object
Modifier and Type | Method and Description |
---|---|
static PropertyProvider |
fixedPropertyProvider(Map<String,String> defs)
Create a trivial property producer using only a fixed list of property definitions.
|
static EditableProperties |
getGlobalProperties()
Load global properties defined by the IDE in the user directory.
|
static String |
getUsablePropertyName(String name)
Returns name usable as Ant property which is based on the given
name.
|
static PropertyProvider |
globalPropertyProvider()
Create a property evaluator based on
PropertyUtils.getGlobalProperties()
and PropertyUtils.putGlobalProperties(org.netbeans.spi.project.support.ant.EditableProperties) . |
static boolean |
isUsablePropertyName(String name)
Checks whether the name is usable as Ant property name.
|
static PropertyProvider |
propertiesFilePropertyProvider(File propertiesFile)
Create a property provider based on a properties file.
|
static void |
putGlobalProperties(EditableProperties properties)
Edit global properties defined by the IDE in the user directory.
|
static String |
relativizeFile(File basedir,
File file)
Produce a machine-independent relativized version of a filename from a basedir.
|
static File |
resolveFile(File basedir,
String filename)
Find an absolute file path from a possibly relative path.
|
static PropertyEvaluator |
sequentialPropertyEvaluator(PropertyProvider preprovider,
PropertyProvider... providers)
Create a property evaluator based on a series of definitions.
|
static String[] |
tokenizePath(String path)
Split an Ant-style path specification into components.
|
static PropertyProvider |
userPropertiesProvider(PropertyEvaluator findUserPropertiesFile,
String propertyName,
File basedir)
Creates a property provider similar to
PropertyUtils.globalPropertyProvider()
but which can use a different global properties file. |
public static EditableProperties getGlobalProperties()
Acquires read access.
To listen to changes use PropertyUtils.globalPropertyProvider()
.
public static void putGlobalProperties(EditableProperties properties) throws IOException
Acquires write access.
properties
- user properties to setIOException
- if they could not be storedPropertyUtils.getGlobalProperties()
public static PropertyProvider globalPropertyProvider()
PropertyUtils.getGlobalProperties()
and PropertyUtils.putGlobalProperties(org.netbeans.spi.project.support.ant.EditableProperties)
.
It will supply global properties and fire changes when this file
is changed.public static PropertyProvider propertiesFilePropertyProvider(File propertiesFile)
propertiesFile
- a path to a (possibly nonexistent) *.properties fileProperties.load(java.io.Reader)
public static File resolveFile(File basedir, String filename) throws IllegalArgumentException
basedir
- base file for relative filename resolving; must be an absolute pathfilename
- a pathname which may be relative or absolute and may
use / or \ as the path separatorIllegalArgumentException
- if basedir is not absolute@CheckForNull public static String relativizeFile(File basedir, File file)
URI.relativize(java.net.URI)
this will produce "../" sequences as needed.basedir
- a directory to resolve relative to (need not exist on disk)file
- a file or directory to find a relative path forIllegalArgumentException
- if the basedir is known to be a file and not a directorypublic static String[] tokenizePath(String path)
:
and ;
, paying
attention to DOS-style components such as C:\FOO.
Also removes any empty components.path
- an Ant-style path (elements arbitrary) using DOS or Unix separatorspublic static boolean isUsablePropertyName(String name)
name
- name to check for usability as Ant propertypublic static String getUsablePropertyName(String name)
name
- name to use as base for Ant property namepublic static PropertyProvider fixedPropertyProvider(Map<String,String> defs)
defs
- a map from property names to values (it is illegal to modify this map
after passing it to this method)public static PropertyEvaluator sequentialPropertyEvaluator(PropertyProvider preprovider, PropertyProvider... providers)
Each batch of definitions can refer to properties within itself (so long as there is no cycle) or any previous batch. However the special first provider cannot refer to properties within itself.
This implementation acquires ProjectManager.mutex()
for all operations, in read mode,
and fires changes synchronously. It also expects changes to be fired from property
providers in read (or write) access.
preprovider
- an initial context (may be null)providers
- a sequential list of property groupspublic static PropertyProvider userPropertiesProvider(PropertyEvaluator findUserPropertiesFile, String propertyName, File basedir)
PropertyUtils.globalPropertyProvider()
but which can use a different global properties file.
If a specific file is pointed to, that is loaded; otherwise behaves like PropertyUtils.globalPropertyProvider()
.
Permits behavior similar to command-line Ant where not erroneous, but using the IDE's
default global properties for projects which do not yet have this property registered.findUserPropertiesFile
- an evaluator in which to look up propertyName
propertyName
- a property pointing to the global properties file (typically "user.properties.file"
)basedir
- a base directory to use when resolving the path to the global properties file, if relative