aboutsummaryrefslogtreecommitdiffstats
path: root/ide_common/src/com/android/ide/common
diff options
context:
space:
mode:
authorJosiah Gaskin <josiahgaskin@google.com>2011-08-18 11:39:50 -0700
committerJosiah Gaskin <josiahgaskin@google.com>2011-08-18 14:25:45 -0700
commit882e673462566249a538d72b16917bc6cac8315d (patch)
tree27f9ccafc1515ebd94cc11f61a9b5ddb4b2bc9f6 /ide_common/src/com/android/ide/common
parent15e9f6bbf0819aae5248337b313492b5cf6241ae (diff)
downloadsdk-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')
-rw-r--r--ide_common/src/com/android/ide/common/resources/IdGeneratingResourceFile.java24
-rw-r--r--ide_common/src/com/android/ide/common/resources/MultiResourceFile.java46
-rw-r--r--ide_common/src/com/android/ide/common/resources/ResourceRepository.java24
-rw-r--r--ide_common/src/com/android/ide/common/resources/SingleResourceFile.java10
4 files changed, 94 insertions, 10 deletions
diff --git a/ide_common/src/com/android/ide/common/resources/IdGeneratingResourceFile.java b/ide_common/src/com/android/ide/common/resources/IdGeneratingResourceFile.java
index fa8d0e7..6706715 100644
--- a/ide_common/src/com/android/ide/common/resources/IdGeneratingResourceFile.java
+++ b/ide_common/src/com/android/ide/common/resources/IdGeneratingResourceFile.java
@@ -31,6 +31,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -88,8 +89,8 @@ public final class IdGeneratingResourceFile extends ResourceFile
@Override
protected void update() {
- // remove this file from all existing ResourceItem.
- getFolder().getRepository().removeFile(mResourceTypeList, this);
+ // Copy the previous list of ID names
+ Set<String> oldIdNames = mIdResources.keySet();
// reset current content.
mIdResources.clear();
@@ -97,14 +98,21 @@ public final class IdGeneratingResourceFile extends ResourceFile
// need to parse the file and find the IDs.
parseFileForIds();
- // Notify the repository about any changes
- updateResourceItems();
+ // We only need to update the repository if our IDs have changed
+ if (oldIdNames.equals(mIdResources.keySet()) == false) {
+ updateResourceItems();
+ }
}
@Override
protected void dispose() {
+ ResourceRepository repository = getRepository();
+
// Remove declarations from this file from the repository
- getFolder().getRepository().removeFile(mResourceTypeList, this);
+ repository.removeFile(mResourceTypeList, this);
+
+ // Ask for an ID refresh since we'll be taking away ID generating items
+ repository.markForIdRefresh();
}
@Override
@@ -155,6 +163,9 @@ public final class IdGeneratingResourceFile extends ResourceFile
private void updateResourceItems() {
ResourceRepository repository = getRepository();
+ // remove this file from all existing ResourceItem.
+ repository.removeFile(mResourceTypeList, this);
+
// First add this as a layout file
ResourceItem item = repository.getResourceItem(mFileType, mFileName);
item.add(this);
@@ -165,6 +176,9 @@ public final class IdGeneratingResourceFile extends ResourceFile
// add this file to the list of files generating ID resources.
item.add(this);
}
+
+ // Ask the repository for an ID refresh
+ repository.markForIdRefresh();
}
/**
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();
+ }
}
/**
diff --git a/ide_common/src/com/android/ide/common/resources/ResourceRepository.java b/ide_common/src/com/android/ide/common/resources/ResourceRepository.java
index fa533cb..4af4a1a 100644
--- a/ide_common/src/com/android/ide/common/resources/ResourceRepository.java
+++ b/ide_common/src/com/android/ide/common/resources/ResourceRepository.java
@@ -68,6 +68,7 @@ public abstract class ResourceRepository {
protected final IntArrayWrapper mWrapper = new IntArrayWrapper(null);
+ private boolean mNeedsIdRefresh;
/**
* Makes a resource repository
@@ -195,6 +196,29 @@ public abstract class ResourceRepository {
protected abstract ResourceItem createResourceItem(String name);
/**
+ * Sets a flag which determines whether aapt needs to be run to regenerate resource IDs
+ */
+ protected void markForIdRefresh() {
+ mNeedsIdRefresh = true;
+ }
+
+ /**
+ * Returns whether this repository has been marked as "dirty"; if one or more of the constituent
+ * files have declared that the resource item names that they provide have changed.
+ */
+ public boolean needsIdRefresh() {
+ return mNeedsIdRefresh;
+ }
+
+ /**
+ * Indicates that the resources IDs have been regenerated, so the repository is now in a clean
+ * state
+ */
+ public void setIdsRefreshed() {
+ mNeedsIdRefresh = false;
+ }
+
+ /**
* Processes a folder and adds it to the list of existing folders.
* @param folder the folder to process
* @return the ResourceFolder created from this folder, or null if the process failed.
diff --git a/ide_common/src/com/android/ide/common/resources/SingleResourceFile.java b/ide_common/src/com/android/ide/common/resources/SingleResourceFile.java
index 9c8977e..b589b35 100644
--- a/ide_common/src/com/android/ide/common/resources/SingleResourceFile.java
+++ b/ide_common/src/com/android/ide/common/resources/SingleResourceFile.java
@@ -41,8 +41,8 @@ public class SingleResourceFile extends ResourceFile {
sParserFactory.setNamespaceAware(true);
}
- private String mResourceName;
- private ResourceType mType;
+ private final String mResourceName;
+ private final ResourceType mType;
private ResourceValue mValue;
public SingleResourceFile(IAbstractFile file, ResourceFolder folder) {
@@ -79,6 +79,9 @@ public class SingleResourceFile extends ResourceFile {
// add this file to the list of files generating this resource item.
item.add(this);
+
+ // Ask for an ID refresh since we're adding an item that will generate an ID
+ getRepository().markForIdRefresh();
}
@Override
@@ -92,6 +95,9 @@ public class SingleResourceFile extends ResourceFile {
// only remove this file from the existing ResourceItem.
getFolder().getRepository().removeFile(mType, this);
+ // Ask for an ID refresh since we're removing an item that previously generated an ID
+ getRepository().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.
}