public class ResourceMerger
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected javax.xml.parsers.DocumentBuilderFactory |
mFactory |
protected java.util.Map<java.lang.String,java.util.Map<java.lang.String,ResourceItem>> |
mMergedItems
Map of items that are purely results of merges (ie item that made up of several
original items).
|
| Constructor and Description |
|---|
ResourceMerger(int minSdk)
Creates a new resource merger.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDataSet(ResourceSet resourceSet)
adds a new
DataSet and overlays it on top of the existing DataSet. |
boolean |
checkValidUpdate(java.util.List<S> dataSets)
Checks that a loaded merger can be updated with a given list of DataSet.
|
void |
cleanBlob(java.io.File blobRootFolder) |
protected void |
createDir(java.io.File folder) |
protected ResourceSet |
createFromXml(org.w3c.dom.Node node)
Reads the
ResourceSet from the blob XML. |
protected boolean |
filterAccept(ResourceItem dataItem)
Method that implements data filters.
|
FileValidity<S> |
findDataSetContaining(java.io.File file)
Finds the
DataSet that contains the given file. |
FileValidity<S> |
findDataSetContaining(java.io.File file,
FileValidity<S> fileValidity)
Finds the
DataSet that contains the given file. |
protected java.lang.String |
getAdditionalDataTagName() |
com.google.common.collect.ListMultimap<java.lang.String,I> |
getDataMap()
Returns a map of the data items.
|
java.util.List<S> |
getDataSets()
Returns the list of ResourceSet objects.
|
protected void |
loadAdditionalData(org.w3c.dom.Node mergedItemsNode,
boolean incrementalState) |
boolean |
loadFromBlob(java.io.File blobRootFolder,
boolean incrementalState)
Loads the merger state from a blob file.
|
void |
mergeData(MergeConsumer<ResourceItem> consumer,
boolean doCleanUp)
Merges the data into a given consumer.
|
protected void |
mergeItems(java.lang.String dataItemKey,
java.util.List<ResourceItem> items,
MergeConsumer<ResourceItem> consumer)
Merge items together, and register the merged items with the given consumer.
|
protected boolean |
requiresMerge(java.lang.String dataItemKey) |
int |
size()
Returns the number of items.
|
java.lang.String |
toString() |
protected void |
writeAdditionalData(org.w3c.dom.Document document,
org.w3c.dom.Node rootNode) |
void |
writeBlobTo(java.io.File blobRootFolder,
MergeConsumer<I> consumer,
boolean includeTimestamps)
Writes a single blob file to store all that the DataMerger knows about.
|
void |
writeBlobToWithTimestamps(java.io.File blobRootFolder,
MergeConsumer<I> consumer)
Writes a single blob file to store all that the DataMerger knows about, and tag file entries
with lastModified timestamps.
|
protected final java.util.Map<java.lang.String,java.util.Map<java.lang.String,ResourceItem>> mMergedItems
@NonNull protected final javax.xml.parsers.DocumentBuilderFactory mFactory
public ResourceMerger(int minSdk)
minSdk - the minimum SDK, used for filtering.protected ResourceSet createFromXml(org.w3c.dom.Node node) throws MergingException
ResourceSet from the blob XML. ResourceMerger deals with two kinds
of sets - GeneratedResourceSet and "plain" ResourceSet . Instances of the
former are marked with generated="true" attribute. Instances of the latter have a
generated-set attribute that references the corresponding generated set by name.
For any variant, the generated set has a lower priority, so it comes in the XML first. This
means we will find it by name at this stage.MergingExceptionprotected boolean requiresMerge(@NonNull
java.lang.String dataItemKey)
protected void mergeItems(@NonNull
java.lang.String dataItemKey,
@NonNull
java.util.List<ResourceItem> items,
@NonNull
MergeConsumer<ResourceItem> consumer)
throws MergingException
dataItemKey - the key for the itemsitems - the items, from lower priority to higher priority.consumer - the consumer to receive the merged items.MergingException@NonNull protected java.lang.String getAdditionalDataTagName()
protected void loadAdditionalData(@NonNull
org.w3c.dom.Node mergedItemsNode,
boolean incrementalState)
throws MergingException
MergingExceptionprotected void writeAdditionalData(org.w3c.dom.Document document,
org.w3c.dom.Node rootNode)
public void addDataSet(ResourceSet resourceSet)
DataSet and overlays it on top of the existing DataSet.resourceSet - the ResourceSet to add.public void mergeData(@NonNull
MergeConsumer<ResourceItem> consumer,
boolean doCleanUp)
throws MergingException
consumer - the consumer of the merge.doCleanUp - clean up the state to be able to do further incremental merges. If this
is a one-shot merge, this can be false to improve performance.MergingException - such as a DuplicateDataException or a
MergeConsumer.ConsumerException if something goes wrongprotected boolean filterAccept(@NonNull
ResourceItem dataItem)
dataItem - the data item to filter@NonNull public java.util.List<S> getDataSets()
public int size()
DataMap@NonNull public com.google.common.collect.ListMultimap<java.lang.String,I> getDataMap()
DataMappublic void writeBlobTo(@NonNull
java.io.File blobRootFolder,
@NonNull
MergeConsumer<I> consumer,
boolean includeTimestamps)
throws MergingException
blobRootFolder - the root folder where blobs are store.consumer - the merge consumer that was used by the merge.includeTimestamps - true if the files should be tagged with lastModified timestampsMergingException - if something goes wrongloadFromBlob(File, boolean)public void writeBlobToWithTimestamps(@NonNull
java.io.File blobRootFolder,
@NonNull
MergeConsumer<I> consumer)
throws MergingException
blobRootFolder - the root folder where blobs are store.consumer - the merge consumer that was used by the merge.MergingException - if something goes wrongloadFromBlob(File, boolean)public boolean loadFromBlob(@NonNull
java.io.File blobRootFolder,
boolean incrementalState)
throws MergingException
This can be loaded into two different ways that differ only by the state on
the DataItem objects.
If incrementalState is true then the items that are on disk are
marked as written (DataItem.isWritten() returning true. This is to be
used by MergeWriter to update a merged res folder.
If false, the items are marked as touched, and this can be used to feed a new
AbstractResourceRepository object.
blobRootFolder - the folder containing the blob.incrementalState - whether to load into an incremental state or a new state.MergingException - if something goes wrongwriteBlobTo(File, MergeConsumer, boolean)public void cleanBlob(@NonNull
java.io.File blobRootFolder)
public boolean checkValidUpdate(java.util.List<S> dataSets)
dataSets - the resource sets.public FileValidity<S> findDataSetContaining(@NonNull java.io.File file)
DataSet that contains the given file.
This methods will also performs some checks to make sure the given file is a valid file
in the data set.
All the information is set in a FileValidity object that is returned.
FileValidity contains information about the changed file including:
- is it from an known set, is it an ignored file, or is it unknown?
- what data set does it belong to
- what source folder in the data set does it belong to.
"belong" means that the DataSet has a source file/folder that is the root folder
of this file. The folder and/or file doesn't have to exist.file - the file to checkpublic FileValidity<S> findDataSetContaining(@NonNull java.io.File file, @Nullable FileValidity<S> fileValidity)
DataSet that contains the given file.
This methods will also performs some checks to make sure the given file is a valid file
in the data set.
All the information is set in a FileValidity object that is returned. If an instance
is passed, then this object is filled instead, and returned.
FileValidity contains information about the changed file including:
- is it from an known set, is it an ignored file, or is it unknown?
- what data set does it belong to
- what source folder in the data set does it belong to.
"belong" means that the DataSet has a source file/folder that is the root folder
of this file. The folder and/or file doesn't have to exist.file - the file to checkfileValidity - an optional FileValidity to fill. If null a new one is returned.protected void createDir(java.io.File folder)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Object