com.android.ide.common.res2
Class PreprocessDataSet

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

public class PreprocessDataSet
extends java.lang.Object

DataSet used to combine the "merged" resources directory with resources generated for preprocessing.


Nested Class Summary
static class PreprocessDataSet.ResourcesDirectory
           
 
Constructor Summary
PreprocessDataSet(java.lang.String configName, PreprocessDataSet.ResourcesDirectory resourcesDirectory)
          Creates a DataSet 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 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  PreprocessDataFile createFileAndItems(java.io.File sourceFolder, java.io.File file, com.android.utils.ILogger logger)
           
protected  PreprocessDataFile 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<PreprocessDataItem,PreprocessDataFile> 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.io.File getGeneratedResDirectory()
           
 java.io.File getMergedResDirectory()
           
 PreprocessDataSet.ResourcesDirectory getResourcesDirectory()
           
 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)
           
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.
 void setGeneratedFiles(com.google.common.collect.SetMultimap<java.io.File,java.io.File> generatedFiles)
           
 void setGeneratedResDirectory(java.io.File generatedResDirectory)
           
 void setMergedResDirectory(java.io.File mergedResDirectory)
           
 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

PreprocessDataSet

public PreprocessDataSet(java.lang.String configName,
                         PreprocessDataSet.ResourcesDirectory resourcesDirectory)
Creates a DataSet 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

setGeneratedFiles

public void setGeneratedFiles(com.google.common.collect.SetMultimap<java.io.File,java.io.File> generatedFiles)

createSet

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

createFileAndItems

protected PreprocessDataFile 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

createFileAndItems

@Nullable
protected PreprocessDataFile createFileAndItems(java.io.File sourceFolder,
                                                         java.io.File file,
                                                         com.android.utils.ILogger logger)
                                         throws MergingException
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

getGeneratedResDirectory

public java.io.File getGeneratedResDirectory()

setGeneratedResDirectory

public void setGeneratedResDirectory(java.io.File generatedResDirectory)

getMergedResDirectory

public java.io.File getMergedResDirectory()

setMergedResDirectory

public void setMergedResDirectory(java.io.File mergedResDirectory)

getResourcesDirectory

public PreprocessDataSet.ResourcesDirectory getResourcesDirectory()

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

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

processNewDataFile

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

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