com.android.ide.common.res2
Class ResourceSet

java.lang.Object
  extended by com.android.ide.common.res2.ResourceSet
All Implemented Interfaces:
SourceSet
Direct Known Subclasses:
GeneratedResourceSet

public class ResourceSet
extends java.lang.Object

Implementation of DataSet for ResourceItem and ResourceFile. This is able to detect duplicates from the same source folders (same resource coming from the values folder in same or different files).


Constructor Summary
ResourceSet(java.lang.String name)
           
ResourceSet(java.lang.String name, boolean validateEnabled)
           
 
Method Summary
protected  void addItem(I item, java.lang.String key)
           
 void addSource(java.io.File file)
          Adds a new source file
 void addSources(java.util.Collection<java.io.File> files)
          Adds a collection of source files.
protected static boolean checkFileForAndroidRes(java.io.File file)
          Checks a file to make sure it is a valid file in the android res/asset folders.
protected  void checkItems()
          Checks for duplicate items across all source files.
protected  ResourceFile createFileAndItems(java.io.File sourceFolder, java.io.File file, com.android.utils.ILogger logger)
           
protected  ResourceFile createFileAndItemsFromXml(java.io.File file, org.w3c.dom.Node fileNode)
          Creates a DataFile and associated DataItems from an XML node from a file created with DataSet.appendToXml(org.w3c.dom.Node, org.w3c.dom.Document, MergeConsumer)
protected  com.android.ide.common.res2.DataSet<ResourceItem,ResourceFile> createSet(java.lang.String name)
           
 java.io.File findMatchingSourceFile(java.io.File file)
          Returns a matching Source file that contains a given file.
 java.lang.String getConfigName()
          Returns the config name.
protected  F getDataFile(java.io.File file)
           
 com.google.common.collect.ListMultimap<java.lang.String,I> getDataMap()
          Returns a map of the items.
 java.util.List<java.io.File> getSourceFiles()
          Get the list of source files.
protected  boolean getValidateEnabled()
           
protected  boolean handleChangedFile(java.io.File sourceFolder, java.io.File changedFile, com.android.utils.ILogger logger)
           
protected  boolean handleNewFile(java.io.File sourceFolder, java.io.File file, com.android.utils.ILogger logger)
           
protected  boolean handleRemovedFile(java.io.File removedFile)
           
 boolean isEmpty()
          Returns whether the set is empty of items.
 boolean isFromDependency()
           
static boolean isIgnored(java.io.File file)
          Returns whether the given file should be ignored.
protected  boolean isValidSourceFile(java.io.File sourceFolder, java.io.File file)
           
 void loadFromFiles(com.android.utils.ILogger logger)
          Loads the DataSet from the files its source folders contain.
protected  void processNewDataFile(java.io.File sourceFolder, F dataFile, boolean setTouched)
           
protected  void readSourceFolder(java.io.File sourceFolder, com.android.utils.ILogger logger)
          Reads the content of a data folders and loads the DataItem.
 void setFromDependency(boolean fromDependency)
           
 void setGeneratedSet(ResourceSet generatedSet)
           
 void setPreprocessor(ResourcePreprocessor preprocessor)
           
 int size()
          Returns the number of items.
 java.lang.String toString()
           
 boolean updateWith(java.io.File sourceFolder, java.io.File changedFile, FileStatus fileStatus, com.android.utils.ILogger logger)
          Update the DataSet with a given file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceSet

public ResourceSet(java.lang.String name)

ResourceSet

public ResourceSet(java.lang.String name,
                   boolean validateEnabled)
Method Detail

setGeneratedSet

public void setGeneratedSet(ResourceSet generatedSet)

setPreprocessor

public void setPreprocessor(@NonNull
                            ResourcePreprocessor preprocessor)

createSet

protected com.android.ide.common.res2.DataSet<ResourceItem,ResourceFile> createSet(java.lang.String name)

createFileAndItems

protected ResourceFile createFileAndItems(java.io.File sourceFolder,
                                          java.io.File file,
                                          com.android.utils.ILogger logger)
                                   throws MergingException
Throws:
MergingException

createFileAndItemsFromXml

protected ResourceFile createFileAndItemsFromXml(@NonNull
                                                 java.io.File file,
                                                 @NonNull
                                                 org.w3c.dom.Node fileNode)
                                          throws MergingException
Creates a DataFile and associated DataItems from an XML node from a file created with DataSet.appendToXml(org.w3c.dom.Node, org.w3c.dom.Document, MergeConsumer)

Parameters:
file - the file represented by the DataFile
fileNode - the XML node.
Returns:
a DataFile
Throws:
MergingException

readSourceFolder

protected void readSourceFolder(java.io.File sourceFolder,
                                com.android.utils.ILogger logger)
                         throws MergingException
Reads the content of a data folders and loads the DataItem. This should generate DataFiles, and process them with processNewDataFile(java.io.File, DataFile, boolean).

Parameters:
sourceFolder - the source folder to load the resources from.
Throws:
MergingException - if something goes wrong

isValidSourceFile

protected boolean isValidSourceFile(@NonNull
                                    java.io.File sourceFolder,
                                    @NonNull
                                    java.io.File file)

handleNewFile

protected boolean handleNewFile(java.io.File sourceFolder,
                                java.io.File file,
                                com.android.utils.ILogger logger)
                         throws MergingException
Throws:
MergingException

handleRemovedFile

protected boolean handleRemovedFile(java.io.File removedFile)

handleChangedFile

protected boolean handleChangedFile(@NonNull
                                    java.io.File sourceFolder,
                                    @NonNull
                                    java.io.File changedFile,
                                    @NonNull
                                    com.android.utils.ILogger logger)
                             throws MergingException
Throws:
MergingException

isFromDependency

public boolean isFromDependency()

setFromDependency

public void setFromDependency(boolean fromDependency)

addSources

public void addSources(java.util.Collection<java.io.File> files)
Adds a collection of source files.

Parameters:
files - the source files to add.

addSource

public void addSource(java.io.File file)
Adds a new source file

Parameters:
file - the source file.

getSourceFiles

@NonNull
public java.util.List<java.io.File> getSourceFiles()
Get the list of source files.

Specified by:
getSourceFiles in interface SourceSet
Returns:
the source files.

getConfigName

public java.lang.String getConfigName()
Returns the config name.

Returns:
the config name.

findMatchingSourceFile

public java.io.File findMatchingSourceFile(java.io.File file)
Returns a matching Source file that contains a given file. "contains" means that the source file/folder is the root folder of this file. The folder and/or file doesn't have to exist.

Specified by:
findMatchingSourceFile in interface SourceSet
Parameters:
file - the file to search for
Returns:
the Source file or null if no match is found.

size

public int size()
Returns the number of items.

Returns:
the number of items.
See Also:
DataMap

isEmpty

public boolean isEmpty()
Returns whether the set is empty of items.

Returns:
true if the set contains no items.

getDataMap

@NonNull
public com.google.common.collect.ListMultimap<java.lang.String,I> getDataMap()
Returns a map of the items.

Returns:
a map of items.
See Also:
DataMap

loadFromFiles

public void loadFromFiles(com.android.utils.ILogger logger)
                   throws MergingException
Loads the DataSet from the files its source folders contain. All loaded items are set to TOUCHED. This is so that after loading the resources from the files, they can be written directly (since touched force them to be written). This also checks for duplicates items.

Throws:
MergingException - if something goes wrong

checkItems

protected void checkItems()
                   throws DuplicateDataException
Checks for duplicate items across all source files.

Throws:
DuplicateDataException - if a duplicated item is found.

updateWith

public boolean updateWith(java.io.File sourceFolder,
                          java.io.File changedFile,
                          FileStatus fileStatus,
                          com.android.utils.ILogger logger)
                   throws MergingException
Update the DataSet with a given file.

Parameters:
sourceFolder - the sourceFile containing the changedFile
changedFile - The changed file
fileStatus - the change state
Returns:
true if the set was properly updated, false otherwise
Throws:
MergingException - if something goes wrong

processNewDataFile

protected void processNewDataFile(@NonNull
                                  java.io.File sourceFolder,
                                  @NonNull
                                  F dataFile,
                                  boolean setTouched)
                           throws MergingException
Throws:
MergingException

addItem

protected void addItem(@NonNull
                       I item,
                       @Nullable
                       java.lang.String key)
                throws MergingException
Throws:
MergingException

getDataFile

protected F getDataFile(@NonNull
                        java.io.File file)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

checkFileForAndroidRes

protected static boolean checkFileForAndroidRes(@NonNull
                                                java.io.File file)
Checks a file to make sure it is a valid file in the android res/asset folders.

Parameters:
file - the file to check
Returns:
true if it is a valid file, false if it should be ignored.

isIgnored

public static boolean isIgnored(@NonNull
                                java.io.File file)
Returns whether the given file should be ignored.

Parameters:
file - the file to check
Returns:
true if the file is hidden

getValidateEnabled

protected boolean getValidateEnabled()