com.android.sdklib.internal.project
Class ProjectProperties

java.lang.Object
  extended by com.android.sdklib.internal.project.ProjectProperties
All Implemented Interfaces:
IPropertySource
Direct Known Subclasses:
ProjectPropertiesWorkingCopy

public class ProjectProperties
extends java.lang.Object
implements IPropertySource

Class representing project properties for both ADT and Ant-based build.

The class is associated to a ProjectProperties.PropertyType that indicate which of the project property file is represented.

To load an existing file, use load(IAbstractFolder, PropertyType).

The class is meant to be always in sync (or at least not newer) than the file it represents. Once created, it can only be updated through reload()

The make modification or make new file, use a ProjectPropertiesWorkingCopy instance, either through create(IAbstractFolder, PropertyType) or through makeWorkingCopy().


Nested Class Summary
static class ProjectProperties.PropertyType
           
 
Field Summary
protected  com.android.io.IAbstractFolder mProjectFolder
           
protected  java.util.Map<java.lang.String,java.lang.String> mProperties
           
protected  ProjectProperties.PropertyType mType
           
protected static java.util.regex.Pattern PATTERN_PROP
           
static java.lang.String PROPERTY_BUILD_OUT_DIR
           
static java.lang.String PROPERTY_BUILD_SOURCE_DIR
           
static java.lang.String PROPERTY_BUILD_TOOLS
          The version of the build tools to use to compile
static java.lang.String PROPERTY_KEY_ALIAS
           
static java.lang.String PROPERTY_KEY_STORE
           
static java.lang.String PROPERTY_LIB_REF
           
static java.lang.String PROPERTY_LIBRARY
           
static java.lang.String PROPERTY_PACKAGE
           
static java.lang.String PROPERTY_PROGUARD_CONFIG
           
static java.lang.String PROPERTY_PROJECTS
           
static java.lang.String PROPERTY_RS_TARGET
          The property name for the renderscript build target
static java.lang.String PROPERTY_RULES_PATH
           
static java.lang.String PROPERTY_SDK
           
static java.lang.String PROPERTY_SPLIT_BY_ABI
           
static java.lang.String PROPERTY_SPLIT_BY_DENSITY
           
static java.lang.String PROPERTY_SPLIT_BY_LOCALE
           
static java.lang.String PROPERTY_TARGET
          The property name for the project target
static java.lang.String PROPERTY_TESTED_PROJECT
           
static java.lang.String PROPERTY_VERSIONCODE
           
 
Constructor Summary
protected ProjectProperties(com.android.io.IAbstractFolder projectFolder, java.util.Map<java.lang.String,java.lang.String> map, ProjectProperties.PropertyType type)
          Private constructor.
 
Method Summary
static ProjectPropertiesWorkingCopy create(com.android.io.IAbstractFolder projectFolder, ProjectProperties.PropertyType type)
          Creates a new project properties object, with no properties.
static ProjectPropertiesWorkingCopy create(java.lang.String projectFolderOsPath, ProjectProperties.PropertyType type)
          Creates a new project properties object, with no properties.
static ProjectProperties createEmpty(com.android.io.IAbstractFolder projectFolder, ProjectProperties.PropertyType type)
          Creates a new project properties object, with no properties.
static ProjectProperties createEmpty(java.lang.String projectFolderOsPath, ProjectProperties.PropertyType type)
          Creates a new project properties object, with no properties.
 void debugPrint()
           
static boolean delete(com.android.io.IAbstractFolder projectFolder, ProjectProperties.PropertyType type)
          Deletes a project properties file.
static boolean delete(java.lang.String projectFolderOsPath, ProjectProperties.PropertyType type)
          Deletes a project properties file.
protected static java.lang.String escape(java.lang.String value)
           
 com.android.io.IAbstractFile getFile()
          Returns the location of this property file.
 java.lang.String getProperty(java.lang.String name)
          Returns the value of a property.
 ProjectProperties.PropertyType getType()
          Returns the type of the property file.
 java.util.Set<java.lang.String> keySet()
          Returns a set of the property keys.
static ProjectProperties load(com.android.io.IAbstractFolder projectFolder, ProjectProperties.PropertyType type)
          Loads a project properties file and return a ProjectProperties object containing the properties.
static ProjectProperties load(java.lang.String projectFolderOsPath, ProjectProperties.PropertyType type)
          Loads a project properties file and return a ProjectProperties object containing the properties.
 ProjectPropertiesWorkingCopy makeWorkingCopy()
          Creates and returns a copy of the current properties as a ProjectPropertiesWorkingCopy that can be modified and saved.
 ProjectPropertiesWorkingCopy makeWorkingCopy(ProjectProperties.PropertyType type)
          Creates and returns a copy of the current properties as a ProjectPropertiesWorkingCopy that can be modified and saved.
static java.util.Map<java.lang.String,java.lang.String> parsePropertyFile(com.android.io.IAbstractFile propFile, com.android.utils.ILogger log)
          Parses a property file (using UTF-8 encoding) and returns a map of the content.
 void reload()
          Reloads the properties from the underlying file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATTERN_PROP

protected static final java.util.regex.Pattern PATTERN_PROP

PROPERTY_TARGET

public static final java.lang.String PROPERTY_TARGET
The property name for the project target

See Also:
Constant Field Values

PROPERTY_RS_TARGET

public static final java.lang.String PROPERTY_RS_TARGET
The property name for the renderscript build target

See Also:
Constant Field Values

PROPERTY_BUILD_TOOLS

public static final java.lang.String PROPERTY_BUILD_TOOLS
The version of the build tools to use to compile

See Also:
Constant Field Values

PROPERTY_LIBRARY

public static final java.lang.String PROPERTY_LIBRARY
See Also:
Constant Field Values

PROPERTY_LIB_REF

public static final java.lang.String PROPERTY_LIB_REF
See Also:
Constant Field Values

PROPERTY_PROGUARD_CONFIG

public static final java.lang.String PROPERTY_PROGUARD_CONFIG
See Also:
Constant Field Values

PROPERTY_RULES_PATH

public static final java.lang.String PROPERTY_RULES_PATH
See Also:
Constant Field Values

PROPERTY_SDK

public static final java.lang.String PROPERTY_SDK
See Also:
Constant Field Values

PROPERTY_SPLIT_BY_DENSITY

public static final java.lang.String PROPERTY_SPLIT_BY_DENSITY
See Also:
Constant Field Values

PROPERTY_SPLIT_BY_ABI

public static final java.lang.String PROPERTY_SPLIT_BY_ABI
See Also:
Constant Field Values

PROPERTY_SPLIT_BY_LOCALE

public static final java.lang.String PROPERTY_SPLIT_BY_LOCALE
See Also:
Constant Field Values

PROPERTY_TESTED_PROJECT

public static final java.lang.String PROPERTY_TESTED_PROJECT
See Also:
Constant Field Values

PROPERTY_BUILD_SOURCE_DIR

public static final java.lang.String PROPERTY_BUILD_SOURCE_DIR
See Also:
Constant Field Values

PROPERTY_BUILD_OUT_DIR

public static final java.lang.String PROPERTY_BUILD_OUT_DIR
See Also:
Constant Field Values

PROPERTY_PACKAGE

public static final java.lang.String PROPERTY_PACKAGE
See Also:
Constant Field Values

PROPERTY_VERSIONCODE

public static final java.lang.String PROPERTY_VERSIONCODE
See Also:
Constant Field Values

PROPERTY_PROJECTS

public static final java.lang.String PROPERTY_PROJECTS
See Also:
Constant Field Values

PROPERTY_KEY_STORE

public static final java.lang.String PROPERTY_KEY_STORE
See Also:
Constant Field Values

PROPERTY_KEY_ALIAS

public static final java.lang.String PROPERTY_KEY_ALIAS
See Also:
Constant Field Values

mProjectFolder

protected final com.android.io.IAbstractFolder mProjectFolder

mProperties

protected final java.util.Map<java.lang.String,java.lang.String> mProperties

mType

protected final ProjectProperties.PropertyType mType
Constructor Detail

ProjectProperties

protected ProjectProperties(@NonNull
                            com.android.io.IAbstractFolder projectFolder,
                            @NonNull
                            java.util.Map<java.lang.String,java.lang.String> map,
                            @NonNull
                            ProjectProperties.PropertyType type)
Private constructor.

Use load(String, PropertyType) or create(String, PropertyType) to instantiate.

Method Detail

load

public static ProjectProperties load(java.lang.String projectFolderOsPath,
                                     ProjectProperties.PropertyType type)
Loads a project properties file and return a ProjectProperties object containing the properties.

Parameters:
projectFolderOsPath - the project folder.
type - One the possible ProjectProperties.PropertyTypes.

load

public static ProjectProperties load(com.android.io.IAbstractFolder projectFolder,
                                     ProjectProperties.PropertyType type)
Loads a project properties file and return a ProjectProperties object containing the properties.

Parameters:
projectFolder - the project folder.
type - One the possible ProjectProperties.PropertyTypes.

delete

public static boolean delete(com.android.io.IAbstractFolder projectFolder,
                             ProjectProperties.PropertyType type)
Deletes a project properties file.

Parameters:
projectFolder - the project folder.
type - One the possible ProjectProperties.PropertyTypes.
Returns:
true if success.

delete

public static boolean delete(java.lang.String projectFolderOsPath,
                             ProjectProperties.PropertyType type)
Deletes a project properties file.

Parameters:
projectFolderOsPath - the project folder.
type - One the possible ProjectProperties.PropertyTypes.
Returns:
true if success.

create

public static ProjectPropertiesWorkingCopy create(@NonNull
                                                  java.lang.String projectFolderOsPath,
                                                  @NonNull
                                                  ProjectProperties.PropertyType type)
Creates a new project properties object, with no properties.

The file is not created until ProjectPropertiesWorkingCopy.save() is called.

Parameters:
projectFolderOsPath - the project folder.
type - the type of property file to create
See Also:
createEmpty(String, PropertyType)

create

public static ProjectPropertiesWorkingCopy create(@NonNull
                                                  com.android.io.IAbstractFolder projectFolder,
                                                  @NonNull
                                                  ProjectProperties.PropertyType type)
Creates a new project properties object, with no properties.

The file is not created until ProjectPropertiesWorkingCopy.save() is called.

Parameters:
projectFolder - the project folder.
type - the type of property file to create
See Also:
createEmpty(IAbstractFolder, PropertyType)

createEmpty

public static ProjectProperties createEmpty(@NonNull
                                            java.lang.String projectFolderOsPath,
                                            @NonNull
                                            ProjectProperties.PropertyType type)
Creates a new project properties object, with no properties.

Nothing can be added to it, unless a ProjectPropertiesWorkingCopy is created first with makeWorkingCopy().

Parameters:
projectFolderOsPath - the project folder.
type - the type of property file to create
See Also:
create(String, PropertyType)

createEmpty

public static ProjectProperties createEmpty(@NonNull
                                            com.android.io.IAbstractFolder projectFolder,
                                            @NonNull
                                            ProjectProperties.PropertyType type)
Creates a new project properties object, with no properties.

Nothing can be added to it, unless a ProjectPropertiesWorkingCopy is created first with makeWorkingCopy().

Parameters:
projectFolder - the project folder.
type - the type of property file to create
See Also:
create(IAbstractFolder, PropertyType)

getFile

public com.android.io.IAbstractFile getFile()
Returns the location of this property file.


makeWorkingCopy

public ProjectPropertiesWorkingCopy makeWorkingCopy()
Creates and returns a copy of the current properties as a ProjectPropertiesWorkingCopy that can be modified and saved.

Returns:
a new instance of ProjectPropertiesWorkingCopy

makeWorkingCopy

public ProjectPropertiesWorkingCopy makeWorkingCopy(ProjectProperties.PropertyType type)
Creates and returns a copy of the current properties as a ProjectPropertiesWorkingCopy that can be modified and saved. This also allows converting to a new type, by specifying a different ProjectProperties.PropertyType.

Parameters:
type - the ProjectProperties.PropertyType of the prop file to save.
Returns:
a new instance of ProjectPropertiesWorkingCopy

getType

public ProjectProperties.PropertyType getType()
Returns the type of the property file.

See Also:
ProjectProperties.PropertyType

getProperty

public java.lang.String getProperty(java.lang.String name)
Returns the value of a property.

Specified by:
getProperty in interface IPropertySource
Parameters:
name - the name of the property.
Returns:
the property value or null if the property is not set.

keySet

public java.util.Set<java.lang.String> keySet()
Returns a set of the property keys. Unlike Map.keySet() this is not a view of the map keys. Modifying the returned Set will not impact the underlying Map.


reload

public void reload()
Reloads the properties from the underlying file.


parsePropertyFile

public static java.util.Map<java.lang.String,java.lang.String> parsePropertyFile(@NonNull
                                                                                 com.android.io.IAbstractFile propFile,
                                                                                 @Nullable
                                                                                 com.android.utils.ILogger log)
Parses a property file (using UTF-8 encoding) and returns a map of the content.

If the file is not present, null is returned with no error messages sent to the log.

IMPORTANT: This method is now unfortunately used in multiple places to parse random property files. This is NOT a safe practice since there is no corresponding method to write property files unless you use ProjectPropertiesWorkingCopy.save(). Code that writes INI or properties without at least using escape(String) will certainly not load back correct data.
Unless there's a strong legacy need to support existing files, new callers should probably just use Java's Properties which has well defined semantics. It's also a mistake to write/read property files using this code and expect it to work with Java's Properties or external tools (e.g. ant) since there can be differences in escaping and in character encoding.

Parameters:
propFile - the property file to parse
log - the ILogger object receiving warning/error from the parsing.
Returns:
the map of (key,value) pairs, or null if the parsing failed.

escape

protected static java.lang.String escape(java.lang.String value)

debugPrint

public void debugPrint()
Specified by:
debugPrint in interface IPropertySource