aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-12-05 13:13:56 -0800
committerGerrit Code Review <noreply-gerritcodereview@google.com>2012-12-05 13:13:57 -0800
commit6ecf7a13a0dc2dbdfce71c83d86328ec6c80b6e3 (patch)
treecdc2831e9f4ed14f08aae925fdef0444908a8016 /eclipse
parentcb7a3df75e1fbef2f4de805f65008e0bbd085217 (diff)
parent131459f779b1a98bf354663298637589a2860fff (diff)
downloadsdk-6ecf7a13a0dc2dbdfce71c83d86328ec6c80b6e3.zip
sdk-6ecf7a13a0dc2dbdfce71c83d86328ec6c80b6e3.tar.gz
sdk-6ecf7a13a0dc2dbdfce71c83d86328ec6c80b6e3.tar.bz2
Merge "Support package conflicts between app and libs."
Diffstat (limited to 'eclipse')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java93
1 files changed, 81 insertions, 12 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java
index 25b16e4..ba23c95 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java
@@ -56,6 +56,8 @@ import com.android.utils.ILogger;
import com.android.utils.Pair;
import com.android.xml.AndroidManifest;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -78,6 +80,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
@@ -1156,18 +1159,71 @@ public class PreCompilerBuilder extends BaseBuilder {
File rFile = new File(outputFolder, SdkConstants.FN_RESOURCE_TEXT);
// if the project has no resources, the file could not exist.
if (rFile.isFile()) {
- SymbolLoader symbolValues = new SymbolLoader(rFile);
- symbolValues.load();
-
- for (Pair<File, String> libData : libRFiles) {
- File libRFile = libData.getFirst();
- if (libRFile.isFile()) {
- SymbolLoader symbols = new SymbolLoader(libRFile);
- symbols.load();
-
- SymbolWriter writer = new SymbolWriter(osOutputPath,
- libData.getSecond(), symbols, symbolValues);
- writer.write();
+ // Load the full symbols from the full R.txt file.
+ SymbolLoader fullSymbols = new SymbolLoader(rFile);
+ fullSymbols.load();
+
+ // simpler case of a single library
+ if (libRFiles.size() == 1) {
+ Pair<File, String> lib = libRFiles.get(0);
+ createRClass(fullSymbols, lib.getFirst(), lib.getSecond(), osOutputPath);
+
+ } else {
+ Map<String, File> libPackages = Maps.newHashMapWithExpectedSize(
+ libRFiles.size());
+ Set<String> duplicatePackages = Sets.newHashSet();
+
+ // preprocessing to figure out if there are dups in the package names of
+ // the libraries
+ for (Pair<File, String> lib : libRFiles) {
+ String libPackage = lib.getSecond();
+ File existingPkg = libPackages.get(libPackage);
+ if (existingPkg != null) {
+ // record the dup package and keep going, in case there are all
+ // the same
+ duplicatePackages.add(libPackage);
+ continue;
+ }
+
+ libPackages.put(libPackage, lib.getFirst());
+ }
+
+ // check if we have duplicate but all files are the same.
+ if (duplicatePackages.size() > 0) {
+ // possible conflict!
+ // detect case of all libraries == same package.
+ if (duplicatePackages.size() == 1 && libPackages.size() == 1 &&
+ duplicatePackages.iterator().next().equals(libPackages.keySet().iterator().next())) {
+ // this is ok, all libraries have the same package.
+ // Make a copy of the full R class.
+ SymbolWriter writer = new SymbolWriter(osOutputPath,
+ duplicatePackages.iterator().next(),
+ fullSymbols, fullSymbols);
+ writer.write();
+ } else {
+ StringBuilder sb = new StringBuilder();
+ sb.append("The following packages have been found to be used by two or more libraries:");
+ for (String pkg : duplicatePackages) {
+ sb.append("\n\t").append(pkg);
+ }
+ sb.append("\nNo libraries must share the same package, unless all libraries share the same packages.");
+
+ String msg = sb.toString();
+ markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
+
+ AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, project,
+ msg);
+
+ throw new AbortBuildException();
+ }
+ } else {
+ // no dups, all libraries have different packages.
+ // Conflicts with the main package have been removed already.
+ // Just process all the libraries.
+ for (Pair<File, String> lib : libRFiles) {
+ createRClass(fullSymbols, lib.getFirst(), lib.getSecond(),
+ osOutputPath);
+ }
}
}
}
@@ -1227,6 +1283,19 @@ public class PreCompilerBuilder extends BaseBuilder {
}
}
+ private void createRClass(SymbolLoader fullSymbols, File libRTxtFile, String libPackage,
+ String osOutputPath) throws IOException {
+ if (libRTxtFile.isFile()) {
+ SymbolLoader libSymbols = new SymbolLoader(libRTxtFile);
+ libSymbols.load();
+
+ SymbolWriter writer = new SymbolWriter(osOutputPath, libPackage, libSymbols,
+ fullSymbols);
+ writer.write();
+ }
+ }
+
+
/**
* Creates a relative {@link IPath} from a java package.
* @param javaPackageName the java package.