diff options
author | Josiah Gaskin <josiahgaskin@google.com> | 2011-08-18 11:39:50 -0700 |
---|---|---|
committer | Josiah Gaskin <josiahgaskin@google.com> | 2011-08-18 14:25:45 -0700 |
commit | 882e673462566249a538d72b16917bc6cac8315d (patch) | |
tree | 27f9ccafc1515ebd94cc11f61a9b5ddb4b2bc9f6 /ide_common/src/com/android/ide/common/resources/MultiResourceFile.java | |
parent | 15e9f6bbf0819aae5248337b313492b5cf6241ae (diff) | |
download | sdk-882e673462566249a538d72b16917bc6cac8315d.zip sdk-882e673462566249a538d72b16917bc6cac8315d.tar.gz sdk-882e673462566249a538d72b16917bc6cac8315d.tar.bz2 |
Precompilation only executes AAPT when necessary
This change adds resource tracking to the ResourceManager.
Each ResourceRepository now has new methods:
void markForIdRefresh() to set the repository as "dirty"
boolean needsIdRefresh() to check whether the repository is dirty
void setIdsRefreshed() to set the repository as "clean"
During the precompilation step, the PreCompiler will query the
ResourceManager to see if any of the repositories included in the build
are marked as dirty. AAPT will only be run if one or more dirty repositories
are found.
Repositories are marked as clean when R.java is regenerated and IDs are
set in ProjectResources.
Change-Id: I575ab819702508eacd247b282c3de8979f2f0ab9
Diffstat (limited to 'ide_common/src/com/android/ide/common/resources/MultiResourceFile.java')
-rw-r--r-- | ide_common/src/com/android/ide/common/resources/MultiResourceFile.java | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/ide_common/src/com/android/ide/common/resources/MultiResourceFile.java b/ide_common/src/com/android/ide/common/resources/MultiResourceFile.java index 6d8ca0a..b3e35d9 100644 --- a/ide_common/src/com/android/ide/common/resources/MultiResourceFile.java +++ b/ide_common/src/com/android/ide/common/resources/MultiResourceFile.java @@ -54,6 +54,10 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou super(file, folder); } + // Boolean flag to track whether a named element has been added or removed, thus requiring + // a new ID table to be generated + private boolean mNeedIdRefresh; + @Override protected void load() { // need to parse the file and find the content. @@ -62,14 +66,21 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou // create new ResourceItems for the new content. mResourceTypeList = Collections.unmodifiableCollection(mResourceItems.keySet()); + // We need an ID generation step + mNeedIdRefresh = true; + // create/update the resource items. updateResourceItems(); } @Override protected void update() { - // remove this file from all existing ResourceItem. - getFolder().getRepository().removeFile(mResourceTypeList, this); + // Reset the ID generation flag + mNeedIdRefresh = false; + + // Copy the previous version of our list of ResourceItems and types + Map<ResourceType, Map<String, ResourceValue>> oldResourceItems + = new EnumMap<ResourceType, Map<String, ResourceValue>>(mResourceItems); // reset current content. mResourceItems.clear(); @@ -80,14 +91,34 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou // create new ResourceItems for the new content. mResourceTypeList = Collections.unmodifiableCollection(mResourceItems.keySet()); + // Check to see if any names have changed. If so, mark the flag so updateResourceItems + // can notify the ResourceRepository that an ID refresh is needed + if (oldResourceItems.keySet().equals(mResourceItems.keySet())) { + for (ResourceType type : mResourceTypeList) { + // We just need to check the names of the items. + // If there are new or removed names then we'll have to regenerate IDs + if (mResourceItems.get(type).keySet() + .equals(oldResourceItems.get(type).keySet()) == false) { + mNeedIdRefresh = true; + } + } + } else { + // If our type list is different, obviously the names will be different + mNeedIdRefresh = true; + } // create/update the resource items. updateResourceItems(); } @Override protected void dispose() { + ResourceRepository repository = getRepository(); + // only remove this file from all existing ResourceItem. - getFolder().getRepository().removeFile(mResourceTypeList, this); + repository.removeFile(mResourceTypeList, this); + + // We'll need an ID refresh because we deleted items + repository.markForIdRefresh(); // don't need to touch the content, it'll get reclaimed as this objects disappear. // In the mean time other objects may need to access it. @@ -106,6 +137,10 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou private void updateResourceItems() { ResourceRepository repository = getRepository(); + + // remove this file from all existing ResourceItem. + repository.removeFile(mResourceTypeList, this); + for (ResourceType type : mResourceTypeList) { Map<String, ResourceValue> list = mResourceItems.get(type); @@ -119,6 +154,11 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou } } } + + // If we need an ID refresh, ask the repository for that now + if (mNeedIdRefresh) { + repository.markForIdRefresh(); + } } /** |