public class ResourceSet
extends java.lang.Object
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).Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ATTR_FROM_DEPENDENCY |
static java.lang.String |
ATTR_GENERATED_SET |
Constructor and Description |
---|
ResourceSet(java.lang.String name,
boolean validateEnabled) |
ResourceSet(java.lang.String name,
java.lang.String libraryName) |
ResourceSet(java.lang.String name,
java.lang.String libraryName,
boolean validateEnabled) |
Modifier and Type | Method and Description |
---|---|
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 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(Node, Document, MergeConsumer, boolean) |
protected com.android.ide.common.res2.DataSet<ResourceItem,ResourceFile> |
createSet(java.lang.String name) |
java.io.File |
findMatchingSourceFile(java.io.File file)
Returns the longest path 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.lang.String |
getLibraryName() |
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 ResourceFile |
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() |
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) |
F |
loadFile(java.io.File sourceFolder,
java.io.File dataFile,
com.android.utils.ILogger logger)
Loads a single dataFile from the given source folder (rather than load / parse from all source folders).
|
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 |
setDontNormalizeQualifiers(boolean dontNormalizeQualifiers) |
void |
setFromDependency(boolean fromDependency) |
void |
setGeneratedSet(ResourceSet generatedSet) |
void |
setIgnoredPatterns(java.lang.String aaptStylePattern) |
void |
setPreprocessor(ResourcePreprocessor preprocessor) |
void |
setShouldParseResourceIds(boolean shouldParse) |
void |
setTrackSourcePositions(boolean shouldTrack) |
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.
|
public static final java.lang.String ATTR_GENERATED_SET
public static final java.lang.String ATTR_FROM_DEPENDENCY
public ResourceSet(java.lang.String name, java.lang.String libraryName)
public ResourceSet(java.lang.String name, boolean validateEnabled)
public ResourceSet(java.lang.String name, java.lang.String libraryName, boolean validateEnabled)
public java.lang.String getLibraryName()
public void setGeneratedSet(ResourceSet generatedSet)
public void setPreprocessor(@NonNull ResourcePreprocessor preprocessor)
public void setShouldParseResourceIds(boolean shouldParse)
public void setDontNormalizeQualifiers(boolean dontNormalizeQualifiers)
public void setTrackSourcePositions(boolean shouldTrack)
protected com.android.ide.common.res2.DataSet<ResourceItem,ResourceFile> createSet(java.lang.String name)
protected ResourceFile createFileAndItems(java.io.File sourceFolder, java.io.File file, com.android.utils.ILogger logger) throws MergingException
MergingException
protected ResourceFile createFileAndItemsFromXml(@NonNull java.io.File file, @NonNull org.w3c.dom.Node fileNode) throws MergingException
DataSet.appendToXml(Node, Document, MergeConsumer, boolean)
file
- the file represented by the DataFilefileNode
- the XML node.MergingException
protected void readSourceFolder(java.io.File sourceFolder, com.android.utils.ILogger logger) throws MergingException
processNewDataFile(java.io.File, DataFile, boolean)
.sourceFolder
- the source folder to load the resources from.MergingException
- if something goes wrongprotected boolean isValidSourceFile(@NonNull java.io.File sourceFolder, @NonNull java.io.File file)
@Nullable protected ResourceFile handleNewFile(java.io.File sourceFolder, java.io.File file, com.android.utils.ILogger logger) throws MergingException
MergingException
protected boolean handleRemovedFile(java.io.File removedFile)
protected boolean handleChangedFile(@NonNull java.io.File sourceFolder, @NonNull java.io.File changedFile, @NonNull com.android.utils.ILogger logger) throws MergingException
MergingException
public boolean isFromDependency()
public void setFromDependency(boolean fromDependency)
public void addSources(java.util.Collection<java.io.File> files)
files
- the source files to add.public void addSource(java.io.File file)
file
- the source file.@NonNull public java.util.List<java.io.File> getSourceFiles()
getSourceFiles
in interface SourceSet
public java.lang.String getConfigName()
public java.io.File findMatchingSourceFile(java.io.File file)
findMatchingSourceFile
in interface SourceSet
file
- the file to search forpublic int size()
DataMap
public boolean isEmpty()
@NonNull public com.google.common.collect.ListMultimap<java.lang.String,I> getDataMap()
DataMap
public void loadFromFiles(com.android.utils.ILogger logger) throws MergingException
MergingException
- if something goes wrong@Nullable public F loadFile(@NonNull java.io.File sourceFolder, @NonNull java.io.File dataFile, @NonNull com.android.utils.ILogger logger) throws MergingException
sourceFolder
- the source folderdataFile
- the data file within source folderlogger
- logs errorsMergingException
protected void checkItems() throws DuplicateDataException
DuplicateDataException
- if a duplicated item is found.public boolean updateWith(java.io.File sourceFolder, java.io.File changedFile, FileStatus fileStatus, com.android.utils.ILogger logger) throws MergingException
sourceFolder
- the sourceFile containing the changedFilechangedFile
- The changed filefileStatus
- the change stateMergingException
- if something goes wrongprotected void processNewDataFile(@NonNull java.io.File sourceFolder, @NonNull F dataFile, boolean setTouched) throws MergingException
MergingException
protected void addItem(@NonNull I item, @Nullable java.lang.String key) throws MergingException
MergingException
protected F getDataFile(@NonNull java.io.File file)
public java.lang.String toString()
toString
in class java.lang.Object
protected boolean checkFileForAndroidRes(@NonNull java.io.File file)
file
- the file to checkpublic void setIgnoredPatterns(java.lang.String aaptStylePattern)
public boolean isIgnored(@NonNull java.io.File file)
file
- the file to checkprotected boolean getValidateEnabled()