com.android.ide.common.res2
Class GeneratedResourceSet

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

public class GeneratedResourceSet
extends ResourceSet

A ResourceSet that contains only generated files (e.g. PNGs generated from a vector drawable XML). It is always a mirror of a normal ResourceSet which delegates to this set when it encounters a file that needs to be replaced by generated files.


Constructor Summary
GeneratedResourceSet(ResourceSet originalSet)
           
GeneratedResourceSet(java.lang.String name)
           
 
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  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()
           
 boolean isEmpty()
          Returns whether the set is empty of items.
static boolean isIgnored(java.io.File file)
          Returns whether the given file should be ignored.
 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)
           
 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 com.android.ide.common.res2.ResourceSet
createFileAndItems, createFileAndItemsFromXml, handleChangedFile, handleNewFile, handleRemovedFile, isFromDependency, isValidSourceFile, readSourceFolder, setFromDependency, setGeneratedSet, setPreprocessor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeneratedResourceSet

public GeneratedResourceSet(ResourceSet originalSet)

GeneratedResourceSet

public GeneratedResourceSet(java.lang.String name)
Method Detail

createSet

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

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

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.

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.

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

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()