aboutsummaryrefslogtreecommitdiff
path: root/builder
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-09-26 14:23:54 -0700
committerXavier Ducrohet <xav@android.com>2012-09-26 18:25:13 -0700
commit59b62773a64172945792b25c2fdbe5e91a412364 (patch)
treeef842972f6a13ad258d25b342a5157039c011633 /builder
parentc64e7aae3d9bfd2436777f6923b71c05e27b7807 (diff)
downloadbuild-59b62773a64172945792b25c2fdbe5e91a412364.tar.gz
Only package libraries that have been processed.
Before dex would be given the whole classpath of the JavaCompile task. Now it gets the list of AndroidDependency and JarDependency that has been build from looking at the compile dependency graph. This allows us to filter some artifacts, like the android.jar artifact and its dependencies. Change-Id: I90cd911451a0df0df2873eda152a69eda715d239
Diffstat (limited to 'builder')
-rw-r--r--builder/src/main/java/com/android/builder/AndroidBuilder.java29
-rw-r--r--builder/src/main/java/com/android/builder/BuildConfigGenerator.java12
-rw-r--r--builder/src/main/java/com/android/builder/TemplateProcessor.java10
-rw-r--r--builder/src/main/java/com/android/builder/VariantConfiguration.java36
-rw-r--r--builder/src/main/java/com/android/builder/packaging/Packager.java4
-rw-r--r--builder/src/main/java/com/android/builder/signing/DebugKeyHelper.java2
6 files changed, 61 insertions, 32 deletions
diff --git a/builder/src/main/java/com/android/builder/AndroidBuilder.java b/builder/src/main/java/com/android/builder/AndroidBuilder.java
index fd5cd28..2747e7f 100644
--- a/builder/src/main/java/com/android/builder/AndroidBuilder.java
+++ b/builder/src/main/java/com/android/builder/AndroidBuilder.java
@@ -657,19 +657,30 @@ public class AndroidBuilder {
// but only if the current project is not a library.
if (mVariant.getType() != VariantConfiguration.Type.LIBRARY &&
fullLibs != null && !fullLibs.isEmpty()) {
- SymbolLoader symbolValues = new SymbolLoader(new File(symbolOutputDir, "R.txt"));
- symbolValues.load();
+ SymbolLoader symbolValues = null;
for (AndroidDependency lib : fullLibs) {
- SymbolLoader symbols = new SymbolLoader(new File(lib.getFolder(), "R.txt"));
- symbols.load();
+ File rFile = new File(lib.getFolder(), "R.txt");
+ // if the library has no resource, this file won't exist.
+ if (rFile.isFile()) {
+ // load the values if that's not already been done.
+ // Doing it lazily allow us to support the case where there's no
+ // resources anywhere.
+ if (symbolValues == null) {
+ symbolValues = new SymbolLoader(new File(symbolOutputDir, "R.txt"));
+ symbolValues.load();
+ }
+
+ SymbolLoader symbols = new SymbolLoader(rFile);
+ symbols.load();
- String packageName = VariantConfiguration.sManifestParser.getPackage(
- new File(lib.getFolder(), SdkConstants.FN_ANDROID_MANIFEST_XML));
+ String packageName = VariantConfiguration.sManifestParser.getPackage(
+ new File(lib.getFolder(), SdkConstants.FN_ANDROID_MANIFEST_XML));
- SymbolWriter writer = new SymbolWriter(sourceOutputDir, packageName,
- symbols, symbolValues);
- writer.write();
+ SymbolWriter writer = new SymbolWriter(sourceOutputDir, packageName,
+ symbols, symbolValues);
+ writer.write();
+ }
}
}
}
diff --git a/builder/src/main/java/com/android/builder/BuildConfigGenerator.java b/builder/src/main/java/com/android/builder/BuildConfigGenerator.java
index eb2868c..c232022 100644
--- a/builder/src/main/java/com/android/builder/BuildConfigGenerator.java
+++ b/builder/src/main/java/com/android/builder/BuildConfigGenerator.java
@@ -15,6 +15,7 @@
*/
package com.android.builder;
+import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.google.common.collect.Maps;
@@ -23,13 +24,15 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Class able to generate a BuildConfig class in Android project.
* The BuildConfig class contains constants related to the build target.
*/
class BuildConfigGenerator {
- private final static String TEMPLATE = "BuildConfig.template";
+ private final static String TEMPLATE = "/com/android/builder/BuildConfig.template";
private final static String PH_PACKAGE = "#PACKAGE#";
private final static String PH_DEBUG = "#DEBUG#";
private final static String PH_LINES = "#ADDITIONAL_LINES#";
@@ -46,9 +49,10 @@ class BuildConfigGenerator {
* @param appPackage the application package
* @param debug whether it's a debug build
*/
- public BuildConfigGenerator(String genFolder, String appPackage, boolean debug) {
- mGenFolder = genFolder;
- mAppPackage = appPackage;
+ public BuildConfigGenerator(@NonNull String genFolder, @NonNull String appPackage,
+ boolean debug) {
+ mGenFolder = checkNotNull(genFolder);
+ mAppPackage = checkNotNull(appPackage);
mDebug = debug;
}
diff --git a/builder/src/main/java/com/android/builder/TemplateProcessor.java b/builder/src/main/java/com/android/builder/TemplateProcessor.java
index 85a6068..edda1a3 100644
--- a/builder/src/main/java/com/android/builder/TemplateProcessor.java
+++ b/builder/src/main/java/com/android/builder/TemplateProcessor.java
@@ -16,6 +16,7 @@
package com.android.builder;
+import com.android.annotations.NonNull;
import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import com.google.common.io.Files;
@@ -27,6 +28,8 @@ import java.io.InputStreamReader;
import java.util.Map;
import java.util.Map.Entry;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Processes a template to generate a file somewhere.
*/
@@ -40,9 +43,10 @@ class TemplateProcessor {
* @param templateStream the stream to read the template file from
* @param placeHolderMap
*/
- public TemplateProcessor(InputStream templateStream, Map<String, String> placeHolderMap) {
- mTemplateStream = templateStream;
- mPlaceHolderMap = placeHolderMap;
+ public TemplateProcessor(@NonNull InputStream templateStream,
+ @NonNull Map<String, String> placeHolderMap) {
+ mTemplateStream = checkNotNull(templateStream);
+ mPlaceHolderMap = checkNotNull(placeHolderMap);
}
/**
diff --git a/builder/src/main/java/com/android/builder/VariantConfiguration.java b/builder/src/main/java/com/android/builder/VariantConfiguration.java
index 531f5a2..b2760d2 100644
--- a/builder/src/main/java/com/android/builder/VariantConfiguration.java
+++ b/builder/src/main/java/com/android/builder/VariantConfiguration.java
@@ -55,7 +55,7 @@ public class VariantConfiguration {
private ProductFlavor mMergedFlavor;
- private List<JarDependency> mJars;
+ private final List<JarDependency> mJars = Lists.newArrayList();
/** List of direct library dependencies. Each object defines its own dependencies. */
private final List<AndroidDependency> mDirectLibraries = Lists.newArrayList();
@@ -154,7 +154,7 @@ public class VariantConfiguration {
}
public void setJarDependencies(List<JarDependency> jars) {
- mJars = jars;
+ mJars.addAll(jars);
}
public List<JarDependency> getJars() {
@@ -231,6 +231,26 @@ public class VariantConfiguration {
return mFlatLibraries;
}
+ public List<File> getPackagedJars() {
+ List<File> jars = Lists.newArrayListWithCapacity(mJars.size() + mFlatLibraries.size());
+
+ for (JarDependency jar : mJars) {
+ File jarFile = new File(jar.getLocation());
+ if (jarFile.exists()) {
+ jars.add(jarFile);
+ }
+ }
+
+ for (AndroidDependency androidDependency : mFlatLibraries) {
+ File libJar = androidDependency.getJarFile();
+ if (libJar.exists()) {
+ jars.add(libJar);
+ }
+ }
+
+ return jars;
+ }
+
public Type getType() {
return mType;
}
@@ -341,7 +361,6 @@ public class VariantConfiguration {
/**
* Reads the package name from the manifest.
- * @return
*/
public String getPackageFromManifest() {
File manifestLocation = mDefaultSourceSet.getAndroidManifest();
@@ -351,7 +370,6 @@ public class VariantConfiguration {
/**
* Returns a list of object that represents the configuration. This can be used to compare
* 2 different list of config objects to know whether the build is up to date or not.
- * @return
*/
public Iterable<Object> getConfigObjects() {
List<Object> list = Lists.newArrayListWithExpectedSize(mFlavorConfigs.size() + 2);
@@ -437,8 +455,6 @@ public class VariantConfiguration {
/**
* Returns all the aidl import folder that are outside of the current project.
- *
- * @return
*/
public List<File> getAidlImports() {
List<File> list = Lists.newArrayList();
@@ -456,7 +472,6 @@ public class VariantConfiguration {
/**
* Returns the compile classpath for this config. If the config tests a library, this
* will include the classpath of the tested config
- * @return
*/
public Set<File> getCompileClasspath() {
Set<File> classpath = Sets.newHashSet();
@@ -481,12 +496,7 @@ public class VariantConfiguration {
classpath.add(lib.getJarFile());
}
- if (mType == Type.TEST && mTestedConfig.mType == Type.LIBRARY) {
- // the tested library is added to the main app so we need its compile classpath as well.
- // which starts with its output
- classpath.add(mTestedConfig.mOutput.getJarFile());
- classpath.addAll(mTestedConfig.getCompileClasspath());
- }
+ // TODO: add jar list when we move to our own sourceset
return classpath;
}
diff --git a/builder/src/main/java/com/android/builder/packaging/Packager.java b/builder/src/main/java/com/android/builder/packaging/Packager.java
index ca4219f..2a02916 100644
--- a/builder/src/main/java/com/android/builder/packaging/Packager.java
+++ b/builder/src/main/java/com/android/builder/packaging/Packager.java
@@ -217,7 +217,7 @@ public final class Packager implements IArchiveBuilder {
* @param resLocation the file representing the packaged resource file.
* @param dexLocation the file representing the dex file. This can be null for apk with no code.
* @param signingInfo the signing information used to sign the package. Optional the OS path to the debug keystore, if needed or null.
- * @param ILogger the logger.
+ * @param logger the logger.
* @throws PackagerException
*/
public Packager(
@@ -399,7 +399,7 @@ public final class Packager implements IArchiveBuilder {
* @throws DuplicateFileException if a file conflicts with another already added to the APK
* at the same location inside the APK archive.
*
- * @see #setDebugMode(boolean)
+ * @see #setDebugJniMode(boolean)
*/
public void addNativeLibraries(String jniLibLocation)
throws PackagerException, SealedPackageException, DuplicateFileException {
diff --git a/builder/src/main/java/com/android/builder/signing/DebugKeyHelper.java b/builder/src/main/java/com/android/builder/signing/DebugKeyHelper.java
index 6f26c54..2080599 100644
--- a/builder/src/main/java/com/android/builder/signing/DebugKeyHelper.java
+++ b/builder/src/main/java/com/android/builder/signing/DebugKeyHelper.java
@@ -50,7 +50,7 @@ public class DebugKeyHelper {
/**
* Creates a new store
- * @param osKeyStorePath the location of the store
+ * @param keyStoreLocation the location of the store
* @param storeType an optional keystore type, or <code>null</code> if the default is to
* be used.
* @param logger a logger object to receive the log of the creation.