com.android.ide.common.res2
Class AssetSet

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

public class AssetSet
extends java.lang.Object

Represents a set of Assets.


Constructor Summary
AssetSet(java.lang.String configName)
          Creates an asset set with a given configName.
 
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  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.AssetFile createFileAndItems(java.io.File sourceFolder, java.io.File file, com.android.utils.ILogger logger)
           
protected  com.android.ide.common.res2.AssetFile createFileAndItems(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<com.android.ide.common.res2.AssetItem,com.android.ide.common.res2.AssetFile> 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 handleChangedFile(java.io.File sourceFolder, java.io.File changedFile)
           
protected  boolean handleNewFile(java.io.File sourceFolder, java.io.File file, com.android.utils.ILogger logger)
           
 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.
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.
 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

AssetSet

public AssetSet(java.lang.String configName)
Creates an asset set with a given configName. The name is used to identify the set across sessions.

Parameters:
configName - the name of the config this set is associated with.
Method Detail

createSet

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

createFileAndItems

protected com.android.ide.common.res2.AssetFile createFileAndItems(java.io.File sourceFolder,
                                                                   java.io.File file,
                                                                   com.android.utils.ILogger logger)

createFileAndItems

protected com.android.ide.common.res2.AssetFile createFileAndItems(@NonNull
                                                                   java.io.File file,
                                                                   @NonNull
                                                                   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)

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

isValidSourceFile

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

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

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

handleNewFile

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

processNewDataFile

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

handleChangedFile

protected boolean handleChangedFile(@NonNull
                                    java.io.File sourceFolder,
                                    @NonNull
                                    java.io.File changedFile)
                             throws MergingException
Throws:
MergingException

addItem

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

getDataFile

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

toString

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

checkFileForAndroidRes

protected 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