aboutsummaryrefslogtreecommitdiff
path: root/builder
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-11-05 15:22:34 -0800
committerXavier Ducrohet <xav@android.com>2012-11-09 11:20:08 -0800
commit3aefe028a57edc41ada24f5cc5a07de881fc7f93 (patch)
tree1329218e1171f4d8ff85546121de8829f9ee3fb8 /builder
parentf6d881b932302bbdd4347a71bf58deda816c99b9 (diff)
downloadbuild-3aefe028a57edc41ada24f5cc5a07de881fc7f93.tar.gz
Continue support for build variant API.
Change-Id: Iec8b33ae0410932aca14ef75f56afe8aff01efdf
Diffstat (limited to 'builder')
-rw-r--r--builder/build.gradle23
-rw-r--r--builder/src/main/java/com/android/builder/AndroidBuilder.java8
-rw-r--r--builder/src/main/java/com/android/builder/BuildType.java18
-rw-r--r--builder/src/main/java/com/android/builder/ProductFlavor.java74
-rw-r--r--builder/src/main/java/com/android/builder/VariantConfiguration.java76
-rw-r--r--builder/src/main/java/com/android/builder/internal/signing/SignedJarBuilder.java6
6 files changed, 150 insertions, 55 deletions
diff --git a/builder/build.gradle b/builder/build.gradle
index 411f706..9156c4f 100644
--- a/builder/build.gradle
+++ b/builder/build.gradle
@@ -94,20 +94,27 @@ uploadArchives {
// custom tasks for creating source/javadoc jars
task sourcesJar(type: Jar, dependsOn:classes) {
- classifier = 'sources'
- from sourceSets.main.allSource
+ classifier = 'sources'
+ from sourceSets.main.allSource
}
-
+
+javadoc {
+ exclude "**/internal/**"
+ options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
+
+ title "Android Builder"
+}
+
task javadocJar(type: Jar, dependsOn:javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
+ classifier 'javadoc'
+ from javadoc.destinationDir
}
// add javadoc/source jar tasks as artifacts
artifacts {
- archives jar
- archives sourcesJar
- archives javadocJar
+ archives jar
+ archives sourcesJar
+ archives javadocJar
}
signing {
diff --git a/builder/src/main/java/com/android/builder/AndroidBuilder.java b/builder/src/main/java/com/android/builder/AndroidBuilder.java
index ddc77af..1ceccdc 100644
--- a/builder/src/main/java/com/android/builder/AndroidBuilder.java
+++ b/builder/src/main/java/com/android/builder/AndroidBuilder.java
@@ -192,8 +192,8 @@ public class AndroidBuilder {
}
/**
- * Pre-process resources. This crunches images and process 9-patches before they can
- * be packaged.
+ * Process the images. This optimize the bitmaps and pre-processes the 9-patch files before
+ * they can be packaged.
* This is incremental.
*
* @param resOutputDir where the processed resources are stored.
@@ -201,7 +201,7 @@ public class AndroidBuilder {
* @throws IOException
* @throws InterruptedException
*/
- public void preprocessResources(@NonNull String resOutputDir, List<File> inputs)
+ public void processImages(@NonNull String resOutputDir, List<File> inputs)
throws IOException, InterruptedException {
checkState(mTarget != null, "Target not set.");
checkNotNull(resOutputDir, "resOutputDir cannot be null.");
@@ -239,7 +239,7 @@ public class AndroidBuilder {
command.add("-C");
command.add(resOutputDir);
- mLogger.info("crunch command: %s", command.toString());
+ mLogger.info("processImages command: %s", command.toString());
mCmdLineRunner.runCmdLine(command);
}
diff --git a/builder/src/main/java/com/android/builder/BuildType.java b/builder/src/main/java/com/android/builder/BuildType.java
index 5a34f3a..b506d6e 100644
--- a/builder/src/main/java/com/android/builder/BuildType.java
+++ b/builder/src/main/java/com/android/builder/BuildType.java
@@ -61,48 +61,54 @@ public class BuildType extends BuildConfig {
return mName;
}
- public void setDebuggable(boolean debuggable) {
+ public BuildType setDebuggable(boolean debuggable) {
mDebuggable = debuggable;
+ return this;
}
public boolean isDebuggable() {
return mDebuggable;
}
- public void setDebugJniBuild(boolean debugJniBuild) {
+ public BuildType setDebugJniBuild(boolean debugJniBuild) {
mDebugJniBuild = debugJniBuild;
+ return this;
}
public boolean isDebugJniBuild() {
return mDebugJniBuild;
}
- public void setDebugSigned(boolean debugSigned) {
+ public BuildType setDebugSigned(boolean debugSigned) {
mDebugSigned = debugSigned;
+ return this;
}
public boolean isDebugSigned() {
return mDebugSigned;
}
- public void setPackageNameSuffix(@Nullable String packageNameSuffix) {
+ public BuildType setPackageNameSuffix(@Nullable String packageNameSuffix) {
mPackageNameSuffix = packageNameSuffix;
+ return this;
}
@Nullable public String getPackageNameSuffix() {
return mPackageNameSuffix;
}
- public void setRunProguard(boolean runProguard) {
+ public BuildType setRunProguard(boolean runProguard) {
mRunProguard = runProguard;
+ return this;
}
public boolean isRunProguard() {
return mRunProguard;
}
- public void setZipAlign(boolean zipAlign) {
+ public BuildType setZipAlign(boolean zipAlign) {
mZipAlign = zipAlign;
+ return this;
}
public boolean isZipAlign() {
diff --git a/builder/src/main/java/com/android/builder/ProductFlavor.java b/builder/src/main/java/com/android/builder/ProductFlavor.java
index ca0930f..e926e17 100644
--- a/builder/src/main/java/com/android/builder/ProductFlavor.java
+++ b/builder/src/main/java/com/android/builder/ProductFlavor.java
@@ -19,9 +19,20 @@ package com.android.builder;
import com.android.annotations.NonNull;
import com.google.common.base.Objects;
+/**
+ * The configuration of a product flavor.
+ *
+ * This is also used to describe the default configuration of all builds, even those that
+ * do not contain any flavors.
+ */
public class ProductFlavor extends BuildConfig {
private static final long serialVersionUID = 1L;
+ /**
+ * The name of the default config.
+ */
+ public static final String MAIN = "main";
+
private final String mName;
private int mMinSdkVersion = -1;
private int mTargetSdkVersion = -1;
@@ -36,6 +47,14 @@ public class ProductFlavor extends BuildConfig {
private String mSigningKeyAlias = null;
private String mSigningKeyPassword = null;
+ /**
+ * Creates a ProductFlavor with a given name.
+ *
+ * Names can be important when dealing with flavor groups.
+ * @param name the name of the flavor.
+ *
+ * @see #MAIN
+ */
public ProductFlavor(String name) {
mName = name;
}
@@ -44,56 +63,81 @@ public class ProductFlavor extends BuildConfig {
return mName;
}
- public void setPackageName(String packageName) {
+ /**
+ * Sets the package name.
+ *
+ * @param packageName the package name
+ * @return the flavor object
+ */
+ public ProductFlavor setPackageName(String packageName) {
mPackageName = packageName;
+ return this;
}
public String getPackageName() {
return mPackageName;
}
- public void setVersionCode(int versionCode) {
+ /**
+ * Sets the version code. If the value is -1, it is considered not set.
+ *
+ * @param versionCode the version code
+ * @return the flavor object
+ */
+ public ProductFlavor setVersionCode(int versionCode) {
mVersionCode = versionCode;
+ return this;
}
public int getVersionCode() {
return mVersionCode;
}
- public void setVersionName(String versionName) {
+ /**
+ * Sets the version name.
+ *
+ * @param versionName the version name
+ * @return the flavor object
+ */
+ public ProductFlavor setVersionName(String versionName) {
mVersionName = versionName;
+ return this;
}
public String getVersionName() {
return mVersionName;
}
- public void setMinSdkVersion(int minSdkVersion) {
- mMinSdkVersion = minSdkVersion;
+ public ProductFlavor setMinSdkVersion(int minSdkVersion) {
+ mMinSdkVersion = minSdkVersion;
+ return this;
}
public int getMinSdkVersion() {
return mMinSdkVersion;
}
- public void setTargetSdkVersion(int targetSdkVersion) {
- mTargetSdkVersion = targetSdkVersion;
+ public ProductFlavor setTargetSdkVersion(int targetSdkVersion) {
+ mTargetSdkVersion = targetSdkVersion;
+ return this;
}
public int getTargetSdkVersion() {
return mTargetSdkVersion;
}
- public void setTestPackageName(String testPackageName) {
+ public ProductFlavor setTestPackageName(String testPackageName) {
mTestPackageName = testPackageName;
+ return this;
}
public String getTestPackageName() {
return mTestPackageName;
}
- public void setTestInstrumentationRunner(String testInstrumentationRunner) {
+ public ProductFlavor setTestInstrumentationRunner(String testInstrumentationRunner) {
mTestInstrumentationRunner = testInstrumentationRunner;
+ return this;
}
public String getTestInstrumentationRunner() {
@@ -104,32 +148,36 @@ public class ProductFlavor extends BuildConfig {
return mSigningStoreLocation;
}
- public void setSigningStoreLocation(String signingStoreLocation) {
+ public ProductFlavor setSigningStoreLocation(String signingStoreLocation) {
mSigningStoreLocation = signingStoreLocation;
+ return this;
}
public String getSigningStorePassword() {
return mSigningStorePassword;
}
- public void setSigningStorePassword(String signingStorePassword) {
+ public ProductFlavor setSigningStorePassword(String signingStorePassword) {
mSigningStorePassword = signingStorePassword;
+ return this;
}
public String getSigningKeyAlias() {
return mSigningKeyAlias;
}
- public void setSigningKeyAlias(String signingKeyAlias) {
+ public ProductFlavor setSigningKeyAlias(String signingKeyAlias) {
mSigningKeyAlias = signingKeyAlias;
+ return this;
}
public String getSigningKeyPassword() {
return mSigningKeyPassword;
}
- public void setSigningKeyPassword(String signingKeyPassword) {
+ public ProductFlavor setSigningKeyPassword(String signingKeyPassword) {
mSigningKeyPassword = signingKeyPassword;
+ return this;
}
public boolean isSigningReady() {
diff --git a/builder/src/main/java/com/android/builder/VariantConfiguration.java b/builder/src/main/java/com/android/builder/VariantConfiguration.java
index c82c1d2..7088f6c 100644
--- a/builder/src/main/java/com/android/builder/VariantConfiguration.java
+++ b/builder/src/main/java/com/android/builder/VariantConfiguration.java
@@ -71,14 +71,14 @@ public class VariantConfiguration {
}
/**
- * Creates the configuration with the base source set.
+ * Creates the configuration with the base source sets.
*
* This creates a config with a {@link Type#DEFAULT} type.
*
- * @param defaultConfig
- * @param defaultSourceProvider
- * @param buildType
- * @param buildTypeSourceProvider
+ * @param defaultConfig the default configuration. Required.
+ * @param defaultSourceProvider the default source provider. Required
+ * @param buildType the build type for this variant. Required.
+ * @param buildTypeSourceProvider the source provider for the build type. Required.
*/
public VariantConfiguration(
@NonNull ProductFlavor defaultConfig, @NonNull SourceProvider defaultSourceProvider,
@@ -89,13 +89,13 @@ public class VariantConfiguration {
}
/**
- * Creates the configuration with the base source set for a given {@link Type}.
+ * Creates the configuration with the base source sets for a given {@link Type}.
*
- * @param defaultConfig
- * @param defaultSourceProvider
- * @param buildType
- * @param buildTypeSourceProvider
- * @param type
+ * @param defaultConfig the default configuration. Required.
+ * @param defaultSourceProvider the default source provider. Required
+ * @param buildType the build type for this variant. Required.
+ * @param buildTypeSourceProvider the source provider for the build type. Required.
+ * @param type the type of the project.
*/
public VariantConfiguration(
@NonNull ProductFlavor defaultConfig, @NonNull SourceProvider defaultSourceProvider,
@@ -107,13 +107,14 @@ public class VariantConfiguration {
}
/**
- * Creates the configuration with the base source set, and whether it is a library.
- * @param defaultConfig
- * @param defaultSourceProvider
- * @param buildType
- * @param buildTypeSourceProvider
- * @param type
- * @param testedConfig
+ * Creates the configuration with the base source sets, and an optional tested variant.
+ *
+ * @param defaultConfig the default configuration. Required.
+ * @param defaultSourceProvider the default source provider. Required
+ * @param buildType the build type for this variant. Required.
+ * @param buildTypeSourceProvider the source provider for the build type. Required.
+ * @param type the type of the project.
+ * @param testedConfig the reference to the tested project. Required if type is Type.TEST
*/
public VariantConfiguration(
@NonNull ProductFlavor defaultConfig, @NonNull SourceProvider defaultSourceProvider,
@@ -146,18 +147,33 @@ public class VariantConfiguration {
* latter added ones).
*
* @param sourceProvider the configured product flavor
+ * @return the config object
*/
- public void addProductFlavor(@NonNull ProductFlavor productFlavor,
+ public VariantConfiguration addProductFlavor(@NonNull ProductFlavor productFlavor,
@NonNull SourceProvider sourceProvider) {
mFlavorConfigs.add(productFlavor);
mFlavorSourceProviders.add(sourceProvider);
mMergedFlavor = productFlavor.mergeOver(mMergedFlavor);
+
+ return this;
}
- public void setJarDependencies(List<JarDependency> jars) {
+ /**
+ * Sets the library dependencies.
+ *
+ * @param jars list of jar dependency. This should include the jar dependencies of Android
+ * projects.
+ * @return the config object
+ */
+ public VariantConfiguration setJarDependencies(List<JarDependency> jars) {
mJars.addAll(jars);
+ return this;
}
+ /**
+ * Returns the list of jar dependencies
+ * @return a non null collection of Jar dependencies.
+ */
public Collection<JarDependency> getJars() {
return mJars;
}
@@ -165,18 +181,32 @@ public class VariantConfiguration {
/**
* Set the Library Project dependencies.
* @param directLibraries list of direct dependencies. Each library object should contain
- * its own dependencies.
+ * its own dependencies. This is actually a dependency graph.
+ * @return the config object
*/
- public void setAndroidDependencies(@NonNull List<AndroidDependency> directLibraries) {
+ public VariantConfiguration setAndroidDependencies(
+ @NonNull List<AndroidDependency> directLibraries) {
if (directLibraries != null) {
mDirectLibraries.addAll(directLibraries);
}
resolveIndirectLibraryDependencies(mDirectLibraries, mFlatLibraries);
+
+ return this;
}
- public void setOutput(AndroidDependency output) {
+ /**
+ * Sets the output of this variant. This is required when the variant is a library so that
+ * the variant that tests this library can properly include the tested library in its own
+ * package.
+ *
+ * @param output the output of the library as an AndroidDependency that will provides the
+ * location of all the created items.
+ * @return the config object
+ */
+ public VariantConfiguration setOutput(AndroidDependency output) {
mOutput = output;
+ return this;
}
public ProductFlavor getDefaultConfig() {
diff --git a/builder/src/main/java/com/android/builder/internal/signing/SignedJarBuilder.java b/builder/src/main/java/com/android/builder/internal/signing/SignedJarBuilder.java
index fd4a2d5..21b385f 100644
--- a/builder/src/main/java/com/android/builder/internal/signing/SignedJarBuilder.java
+++ b/builder/src/main/java/com/android/builder/internal/signing/SignedJarBuilder.java
@@ -259,11 +259,15 @@ public class SignedJarBuilder {
Signature signature = Signature.getInstance("SHA1with" + mKey.getAlgorithm());
signature.initSign(mKey);
mOutputJar.putNextEntry(new JarEntry("META-INF/CERT.SF"));
- writeSignatureFile(new SignatureOutputStream(mOutputJar, signature));
+ SignatureOutputStream out = new SignatureOutputStream(mOutputJar, signature);
+ writeSignatureFile(out);
// CERT.*
mOutputJar.putNextEntry(new JarEntry("META-INF/CERT." + mKey.getAlgorithm()));
writeSignatureBlock(signature, mCertificate, mKey);
+
+ // close this last since it will also close mOutputJar
+ out.close();
}
mOutputJar.close();