diff options
author | Xavier Ducrohet <xav@android.com> | 2012-09-13 16:29:53 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-09-14 14:56:57 -0700 |
commit | 245a289cfe6c819789f7a2ced6d8fc02b4c622b6 (patch) | |
tree | 52fa4bf9e854d718f3bdb46c03df1e94e7c1ff5e /builder | |
parent | b6ecf1576d62adc8dee0288956c0ff019a621b2c (diff) | |
download | build-245a289cfe6c819789f7a2ced6d8fc02b4c622b6.tar.gz |
Some clean up.
Create a default implementation of AndroidDependency for standard bundle
layout.
Also use guava in some places mostly around lists and maps creation,
and preconditions.
Change-Id: Ifbd7f60e2290bbc546ee29521466b6f62851c017
Diffstat (limited to 'builder')
12 files changed, 208 insertions, 137 deletions
diff --git a/builder/build.gradle b/builder/build.gradle index 2731804..db5fa21 100644 --- a/builder/build.gradle +++ b/builder/build.gradle @@ -7,7 +7,7 @@ dependencies { // this is temporary compile fileTree(dir: 'prebuilts', include: '*.jar') - compile 'com.google.guava:guava:11.0.2' + compile 'com.google.guava:guava:13.0.1' testCompile 'junit:junit:3.8.1' } diff --git a/builder/src/main/java/com/android/builder/AndroidBuilder.java b/builder/src/main/java/com/android/builder/AndroidBuilder.java index 65153e3..a9feb95 100644 --- a/builder/src/main/java/com/android/builder/AndroidBuilder.java +++ b/builder/src/main/java/com/android/builder/AndroidBuilder.java @@ -37,6 +37,7 @@ import com.android.sdklib.IAndroidTarget; import com.android.sdklib.IAndroidTarget.IOptionalLibrary; import com.android.sdklib.io.FileOp; import com.android.utils.ILogger; +import com.google.common.collect.Lists; import java.io.File; import java.io.FileNotFoundException; @@ -45,6 +46,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + /** * This is the main builder class. It is given all the data to process the build (such as * {@link ProductFlavor}s, {@link BuildType} and dependencies) and use them when doing specific @@ -90,9 +95,12 @@ public class AndroidBuilder { * @param logger * @param verboseExec */ - public AndroidBuilder(@NonNull SdkParser sdkParser, ILogger logger, boolean verboseExec) { - mSdkParser = sdkParser; - mLogger = logger; + public AndroidBuilder( + @NonNull SdkParser sdkParser, + @NonNull ILogger logger, + boolean verboseExec) { + mSdkParser = checkNotNull(sdkParser); + mLogger = checkNotNull(logger); mVerboseExec = verboseExec; mCmdLineRunner = new CommandLineRunner(mLogger); } @@ -100,14 +108,13 @@ public class AndroidBuilder { @VisibleForTesting AndroidBuilder( @NonNull SdkParser sdkParser, - @NonNull ManifestParser manifestParser, @NonNull CommandLineRunner cmdLineRunner, @NonNull ILogger logger, boolean verboseExec) { - mSdkParser = sdkParser; - mLogger = logger; + mSdkParser = checkNotNull(sdkParser); + mCmdLineRunner = checkNotNull(cmdLineRunner); + mLogger = checkNotNull(logger); mVerboseExec = verboseExec; - mCmdLineRunner = cmdLineRunner; } /** @@ -118,9 +125,8 @@ public class AndroidBuilder { * @see IAndroidTarget#hashString() */ public void setTarget(@NonNull String target) { - if (target == null) { - throw new RuntimeException("Compilation target not set!"); - } + checkNotNull(target, "target cannot be null."); + mTarget = mSdkParser.resolveTarget(target, mLogger); if (mTarget == null) { @@ -135,18 +141,16 @@ public class AndroidBuilder { * */ public void setVariantConfig(@NonNull VariantConfiguration variant) { - mVariant = variant; + mVariant = checkNotNull(variant, "variant cannot be null."); } /** * Returns the runtime classpath to be used during compilation. */ public List<String> getRuntimeClasspath() { - if (mTarget == null) { - throw new IllegalArgumentException("Target not set."); - } + checkState(mTarget != null, "Target not set."); - List<String> classpath = new ArrayList<String>(); + List<String> classpath = Lists.newArrayList(); classpath.add(mTarget.getPath(IAndroidTarget.ANDROID_JAR)); @@ -176,12 +180,8 @@ public class AndroidBuilder { public void generateBuildConfig( @NonNull String sourceOutputDir, @Nullable List<String> additionalLines) throws IOException { - if (mVariant == null) { - throw new IllegalArgumentException("No Variant Configuration has been set."); - } - if (mTarget == null) { - throw new IllegalArgumentException("Target not set."); - } + checkState(mVariant != null, "No Variant Configuration has been set."); + checkState(mTarget != null, "Target not set."); String packageName; if (mVariant.getType() == VariantConfiguration.Type.TEST) { @@ -210,8 +210,9 @@ public class AndroidBuilder { */ public void preprocessResources(@NonNull String resOutputDir) throws IOException, InterruptedException { - List<File> inputs = mVariant.getResourceInputs(); + checkState(mVariant != null, "No Variant Configuration has been set."); + List<File> inputs = mVariant.getResourceInputs(); preprocessResources(resOutputDir, inputs); } /** @@ -224,21 +225,18 @@ public class AndroidBuilder { * @throws IOException * @throws InterruptedException */ - public void preprocessResources(@NonNull String resOutputDir, @NonNull List<File> inputs) + public void preprocessResources(@NonNull String resOutputDir, List<File> inputs) throws IOException, InterruptedException { - if (mVariant == null) { - throw new IllegalArgumentException("No Variant Configuration has been set."); - } - if (mTarget == null) { - throw new IllegalArgumentException("Target not set."); - } + checkState(mVariant != null, "No Variant Configuration has been set."); + checkState(mTarget != null, "Target not set."); + checkNotNull(resOutputDir, "resOutputDir cannot be null."); if (inputs == null || inputs.isEmpty()) { return; } // launch aapt: create the command line - ArrayList<String> command = new ArrayList<String>(); + ArrayList<String> command = Lists.newArrayList(); @SuppressWarnings("deprecation") String aaptPath = mTarget.getPath(IAndroidTarget.AAPT); @@ -279,12 +277,9 @@ public class AndroidBuilder { * @param outManifestLocation the output location for the merged manifest */ public void processManifest(@NonNull String outManifestLocation) { - if (mVariant == null) { - throw new IllegalArgumentException("No Variant Configuration has been set."); - } - if (mTarget == null) { - throw new IllegalArgumentException("Target not set."); - } + checkState(mVariant != null, "No Variant Configuration has been set."); + checkState(mTarget != null, "Target not set."); + checkNotNull(outManifestLocation, "outManifestLocation cannot be null."); if (mVariant.getType() == VariantConfiguration.Type.TEST) { VariantConfiguration testedConfig = mVariant.getTestedConfig(); @@ -331,7 +326,7 @@ public class AndroidBuilder { typeLocation = null; } - List<File> flavorManifests = new ArrayList<File>(); + List<File> flavorManifests = Lists.newArrayList(); for (SourceSet sourceSet : config.getFlavorSourceSets()) { File f = sourceSet.getAndroidManifest(); if (f != null && f.isFile()) { @@ -347,7 +342,7 @@ public class AndroidBuilder { File appMergeOut = new File(outManifestLocation); - List<File> manifests = new ArrayList<File>(); + List<File> manifests = Lists.newArrayList(); if (typeLocation != null) { manifests.add(typeLocation); } @@ -377,7 +372,7 @@ public class AndroidBuilder { Iterable<AndroidDependency> directLibraries, File outManifest) throws IOException { - List<File> manifests = new ArrayList<File>(); + List<File> manifests = Lists.newArrayList(); for (AndroidDependency library : directLibraries) { List<AndroidDependency> subLibraries = library.getDependencies(); if (subLibraries == null || subLibraries.size() == 0) { @@ -454,20 +449,17 @@ public class AndroidBuilder { @Nullable String resPackageOutput, @Nullable String proguardOutput, @NonNull AaptOptions options) throws IOException, InterruptedException { - if (mVariant == null) { - throw new IllegalArgumentException("No Variant Configuration has been set."); - } - if (mTarget == null) { - throw new IllegalArgumentException("Target not set."); - } - + checkState(mVariant != null, "No Variant Configuration has been set."); + checkState(mTarget != null, "Target not set."); + checkNotNull(manifestFile, "manifestFile cannot be null."); + checkNotNull(resInputs, "resInputs cannot be null."); + checkNotNull(options, "options cannot be null."); // if both output types are empty, then there's nothing to do and this is an error - if (sourceOutputDir == null && resPackageOutput == null) { - throw new IllegalArgumentException("no output provided for aapt task"); - } + checkArgument(sourceOutputDir != null || resPackageOutput != null, + "No output provided for aapt task"); // launch aapt: create the command line - ArrayList<String> command = new ArrayList<String>(); + ArrayList<String> command = Lists.newArrayList(); @SuppressWarnings("deprecation") String aaptPath = mTarget.getPath(IAndroidTarget.AAPT); @@ -648,6 +640,8 @@ public class AndroidBuilder { public void compileAidl(@NonNull List<File> sourceFolders, @NonNull File sourceOutputDir) throws IOException, InterruptedException { + checkState(mVariant != null, "No Variant Configuration has been set."); + compileAidl(sourceFolders, sourceOutputDir, mVariant.getAidlImports()); } @@ -655,6 +649,11 @@ public class AndroidBuilder { @NonNull File sourceOutputDir, @NonNull List<File> importFolders) throws IOException, InterruptedException { + checkState(mVariant != null, "No Variant Configuration has been set."); + checkState(mTarget != null, "Target not set."); + checkNotNull(sourceFolders, "sourceFolders cannot be null."); + checkNotNull(sourceOutputDir, "sourceOutputDir cannot be null."); + checkNotNull(importFolders, "importFolders cannot be null."); SourceGenerator compiler = new SourceGenerator(mLogger); @@ -675,15 +674,15 @@ public class AndroidBuilder { @NonNull List<String> libraries, @NonNull String outDexFile, @NonNull DexOptions dexOptions) throws IOException, InterruptedException { - if (mVariant == null) { - throw new IllegalArgumentException("No Variant Configuration has been set."); - } - if (mTarget == null) { - throw new IllegalArgumentException("Target not set."); - } + checkState(mVariant != null, "No Variant Configuration has been set."); + checkState(mTarget != null, "Target not set."); + checkNotNull(classesLocation, "classesLocation cannot be null."); + checkNotNull(libraries, "libraries cannot be null."); + checkNotNull(outDexFile, "outDexFile cannot be null."); + checkNotNull(dexOptions, "dexOptions cannot be null."); // launch dx: create the command line - ArrayList<String> command = new ArrayList<String>(); + ArrayList<String> command = Lists.newArrayList(); @SuppressWarnings("deprecation") String dxPath = mTarget.getPath(IAndroidTarget.DX); @@ -724,12 +723,11 @@ public class AndroidBuilder { @NonNull String classesDexLocation, @Nullable String jniLibsLocation, @NonNull String outApkLocation) throws DuplicateFileException { - if (mVariant == null) { - throw new IllegalArgumentException("No Variant Configuration has been set."); - } - if (mTarget == null) { - throw new IllegalArgumentException("Target not set."); - } + checkState(mVariant != null, "No Variant Configuration has been set."); + checkState(mTarget != null, "Target not set."); + checkNotNull(androidResPkgLocation, "androidResPkgLocation cannot be null."); + checkNotNull(classesDexLocation, "classesDexLocation cannot be null."); + checkNotNull(outApkLocation, "outApkLocation cannot be null."); BuildType buildType = mVariant.getBuildType(); diff --git a/builder/src/main/java/com/android/builder/AndroidDependency.java b/builder/src/main/java/com/android/builder/AndroidDependency.java index 9bbb84a..227e984 100644 --- a/builder/src/main/java/com/android/builder/AndroidDependency.java +++ b/builder/src/main/java/com/android/builder/AndroidDependency.java @@ -25,6 +25,11 @@ import java.util.List; public interface AndroidDependency { /** + * Returns the location of the unarchived bundle. + */ + File getFolder(); + + /** * Returns the direct dependency of this dependency. */ List<AndroidDependency> getDependencies(); diff --git a/builder/src/main/java/com/android/builder/BuildConfigGenerator.java b/builder/src/main/java/com/android/builder/BuildConfigGenerator.java index 9d62313..eb2868c 100644 --- a/builder/src/main/java/com/android/builder/BuildConfigGenerator.java +++ b/builder/src/main/java/com/android/builder/BuildConfigGenerator.java @@ -16,10 +16,10 @@ package com.android.builder; import com.android.annotations.Nullable; +import com.google.common.collect.Maps; import java.io.File; import java.io.IOException; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -70,7 +70,7 @@ class BuildConfigGenerator { * @param additionalLines a list of additional lines to be added to the class. */ public void generate(@Nullable List<String> additionalLines) throws IOException { - Map<String, String> map = new HashMap<String, String>(); + Map<String, String> map = Maps.newHashMap(); map.put(PH_PACKAGE, mAppPackage); map.put(PH_DEBUG, Boolean.toString(mDebug)); diff --git a/builder/src/main/java/com/android/builder/BuildType.java b/builder/src/main/java/com/android/builder/BuildType.java index e4b5c50..674c477 100644 --- a/builder/src/main/java/com/android/builder/BuildType.java +++ b/builder/src/main/java/com/android/builder/BuildType.java @@ -18,6 +18,7 @@ package com.android.builder; import com.android.annotations.NonNull; import com.android.annotations.Nullable; +import com.google.common.base.Objects; import java.io.Serializable; import java.util.ArrayList; @@ -165,14 +166,15 @@ public class BuildType implements Serializable { @Override public String toString() { - return "BuildType{" + - "name='" + mName + '\'' + - ", debuggable=" + mDebuggable + - ", debugJniBuild=" + mDebugJniBuild + - ", debugSigned=" + mDebugSigned + - ", packageNameSuffix='" + mPackageNameSuffix + '\'' + - ", runProguard=" + mRunProguard + - ", zipAlign=" + mZipAlign + - '}'; + return Objects.toStringHelper(this) + .add("name", mName) + .add("debuggable", mDebuggable) + .add("debugJniBuild", mDebugJniBuild) + .add("debugSigned", mDebugSigned) + .add("packageNameSuffix", mPackageNameSuffix) + .add("runProguard", mRunProguard) + .add("zipAlign", mZipAlign) + .omitNullValues() + .toString(); } } diff --git a/builder/src/main/java/com/android/builder/BundleDependency.java b/builder/src/main/java/com/android/builder/BundleDependency.java new file mode 100644 index 0000000..8cab4f6 --- /dev/null +++ b/builder/src/main/java/com/android/builder/BundleDependency.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.builder; + +import com.android.SdkConstants; + +import java.io.File; + +/** + * Default implementation of the AndroidDependency interface that handles a default bundle project + * structure. + */ +public abstract class BundleDependency implements AndroidDependency { + + private final File mBundleFolder; + + protected BundleDependency(File bundleFolder) { + + mBundleFolder = bundleFolder; + } + + @Override + public File getFolder() { + return mBundleFolder; + } + + @Override + public File getJarFile() { + return new File(mBundleFolder, SdkConstants.FN_CLASSES_JAR); + } + + @Override + public File getManifest() { + return new File(mBundleFolder, SdkConstants.FN_ANDROID_MANIFEST_XML); + } + + @Override + public File getResFolder() { + return new File(mBundleFolder, SdkConstants.FD_RES); + } + + @Override + public File getAssetsFolder() { + return new File(mBundleFolder, SdkConstants.FD_ASSETS); + } + + @Override + public File getJniFolder() { + return new File(mBundleFolder, "jni"); + } + + @Override + public File getAidlFolder() { + return new File(mBundleFolder, SdkConstants.FD_AIDL); + } + + @Override + public File getProguardRules() { + return new File(mBundleFolder, "proguard.txt"); + } + + @Override + public File getLintJar() { + return new File(mBundleFolder, "lint.jar"); + } +} diff --git a/builder/src/main/java/com/android/builder/ProductFlavor.java b/builder/src/main/java/com/android/builder/ProductFlavor.java index ed7bb0b..fb6a7df 100644 --- a/builder/src/main/java/com/android/builder/ProductFlavor.java +++ b/builder/src/main/java/com/android/builder/ProductFlavor.java @@ -17,9 +17,10 @@ package com.android.builder; import com.android.annotations.NonNull; +import com.google.common.base.Objects; +import com.google.common.collect.Lists; import java.io.Serializable; -import java.util.ArrayList; import java.util.List; public class ProductFlavor implements Serializable { @@ -39,7 +40,7 @@ public class ProductFlavor implements Serializable { private String mSigningKeyAlias = null; private String mSigningKeyPassword = null; - private final List<String> mBuildConfigLines = new ArrayList<String>(); + private final List<String> mBuildConfigLines = Lists.newArrayList(); public ProductFlavor(String name) { mName = name; @@ -266,20 +267,21 @@ public class ProductFlavor implements Serializable { @Override public String toString() { - return "ProductFlavor{" + - "name='" + mName + '\'' + - ", minSdkVersion=" + mMinSdkVersion + - ", targetSdkVersion=" + mTargetSdkVersion + - ", versionCode=" + mVersionCode + - ", versionName='" + mVersionName + '\'' + - ", packageName='" + mPackageName + '\'' + - ", testPackageName='" + mTestPackageName + '\'' + - ", testInstrumentationRunner='" + mTestInstrumentationRunner + '\'' + - ", signingStoreLocation='" + mSigningStoreLocation + '\'' + - ", signingStorePassword='" + mSigningStorePassword + '\'' + - ", signingKeyAlias='" + mSigningKeyAlias + '\'' + - ", signingKeyPassword='" + mSigningKeyPassword + '\'' + - '}'; + return Objects.toStringHelper(this) + .add("name", mName) + .add("minSdkVersion", mMinSdkVersion) + .add("targetSdkVersion", mTargetSdkVersion) + .add("versionCode", mVersionCode) + .add("versionName", mVersionName) + .add("packageName", mPackageName) + .add("testPackageName", mTestPackageName) + .add("testInstrumentationRunner", mTestInstrumentationRunner) + .add("signingStoreLocation", mSigningStoreLocation) + .add("signingStorePassword", mSigningStorePassword) + .add("signingKeyAlias", mSigningKeyAlias) + .add("signingKeyPassword", mSigningKeyPassword) + .omitNullValues() + .toString(); } /* diff --git a/builder/src/main/java/com/android/builder/VariantConfiguration.java b/builder/src/main/java/com/android/builder/VariantConfiguration.java index a074858..8a5e392 100644 --- a/builder/src/main/java/com/android/builder/VariantConfiguration.java +++ b/builder/src/main/java/com/android/builder/VariantConfiguration.java @@ -19,10 +19,10 @@ package com.android.builder; import com.android.annotations.NonNull; import com.android.annotations.Nullable; import com.android.annotations.VisibleForTesting; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -43,8 +43,8 @@ public class VariantConfiguration { /** SourceSet for the BuildType. Can be null */ private final SourceSet mBuildTypeSourceSet; - private final List<ProductFlavor> mFlavorConfigs = new ArrayList<ProductFlavor>(); - private final List<SourceSet> mFlavorSourceSets = new ArrayList<SourceSet>(); + private final List<ProductFlavor> mFlavorConfigs = Lists.newArrayList(); + private final List<SourceSet> mFlavorSourceSets = Lists.newArrayList(); private final Type mType; /** Optional tested config in case type is Type#TEST */ @@ -58,12 +58,12 @@ public class VariantConfiguration { private List<JarDependency> mJars; /** List of direct library project dependencies. Each object defines its own dependencies. */ - private final List<AndroidDependency> mDirectLibraryProjects = - new ArrayList<AndroidDependency>(); + private final List<AndroidDependency> mDirectLibraryProjects = Lists.newArrayList(); + /** list of all library project dependencies in the flat list. * The order is based on the order needed to call aapt: earlier libraries override resources * of latter ones. */ - private final List<AndroidDependency> mFlatLibraryProjects = new ArrayList<AndroidDependency>(); + private final List<AndroidDependency> mFlatLibraryProjects = Lists.newArrayList(); public static enum Type { DEFAULT, LIBRARY, TEST; @@ -171,7 +171,7 @@ public class VariantConfiguration { public List<AndroidDependency> getFullDirectDependencies() { if (mTestedConfig != null && mTestedConfig.getType() == Type.LIBRARY) { // in case of a library we merge all the dependencies together. - List<AndroidDependency> list = new ArrayList<AndroidDependency>( + List<AndroidDependency> list = Lists.newArrayListWithExpectedSize( mDirectLibraryProjects.size() + mTestedConfig.mDirectLibraryProjects.size() + 1); list.addAll(mDirectLibraryProjects); @@ -235,22 +235,6 @@ public class VariantConfiguration { return !mFlavorConfigs.isEmpty(); } - /** - * @Deprecated this is only valid until we move to more than one flavor - */ - @Deprecated - public ProductFlavor getFirstFlavor() { - return mFlavorConfigs.get(0); - } - - /** - * @Deprecated this is only valid until we move to more than one flavor - */ - @Deprecated - public SourceSet getFirstFlavorSourceSet() { - return mFlavorSourceSets.get(0); - } - public Iterable<ProductFlavor> getFlavorConfigs() { return mFlavorConfigs; } @@ -394,7 +378,7 @@ public class VariantConfiguration { * @return */ public Iterable<Object> getConfigObjects() { - List<Object> list = new ArrayList<Object>(); + List<Object> list = Lists.newArrayListWithExpectedSize(mFlavorConfigs.size() + 2); list.add(mDefaultConfig); list.add(mBuildType); list.addAll(mFlavorConfigs); @@ -405,7 +389,7 @@ public class VariantConfiguration { } public List<File> getManifestInputs() { - List<File> inputs = new ArrayList<File>(); + List<File> inputs = Lists.newArrayList(); File defaultManifest = mDefaultSourceSet.getAndroidManifest(); // this could not exist in a test project. @@ -444,7 +428,7 @@ public class VariantConfiguration { * @return a list of input resource folders. */ public List<File> getResourceInputs() { - List<File> inputs = new ArrayList<File>(); + List<File> inputs = Lists.newArrayList(); if (mBuildTypeSourceSet != null) { File typeResLocation = mBuildTypeSourceSet.getAndroidResources(); @@ -481,7 +465,7 @@ public class VariantConfiguration { * @return */ public List<File> getAidlImports() { - List<File> list = new ArrayList<File>(); + List<File> list = Lists.newArrayList(); for (AndroidDependency lib : mFlatLibraryProjects) { File aidlLib = lib.getAidlFolder(); @@ -499,7 +483,7 @@ public class VariantConfiguration { * @return */ public Set<File> getCompileClasspath() { - Set<File> classpath = new HashSet<File>(); + Set<File> classpath = Sets.newHashSet(); for (File f : mDefaultSourceSet.getCompileClasspath()) { classpath.add(f); @@ -532,7 +516,7 @@ public class VariantConfiguration { } public List<String> getBuildConfigLines() { - List<String> fullList = new ArrayList<String>(); + List<String> fullList = Lists.newArrayList(); List<String> list = mDefaultConfig.getBuildConfigLines(); if (!list.isEmpty()) { diff --git a/builder/src/main/java/com/android/builder/compiler/AidlProcessor.java b/builder/src/main/java/com/android/builder/compiler/AidlProcessor.java index f5d633a..9bd3398 100644 --- a/builder/src/main/java/com/android/builder/compiler/AidlProcessor.java +++ b/builder/src/main/java/com/android/builder/compiler/AidlProcessor.java @@ -20,6 +20,7 @@ import com.android.annotations.NonNull; import com.android.builder.CommandLineRunner; import com.android.builder.compiler.SourceGenerator.DisplayType; import com.android.utils.ILogger; +import com.google.common.collect.Lists; import java.io.File; import java.io.IOException; @@ -55,7 +56,7 @@ public class AidlProcessor implements SourceGenerator.Processor { ILogger logger) throws IOException, InterruptedException { - ArrayList<String> command = new ArrayList<String>(); + ArrayList<String> command = Lists.newArrayList(); command.add(mAidlExecutable); diff --git a/builder/src/main/java/com/android/builder/compiler/DependencyGraph.java b/builder/src/main/java/com/android/builder/compiler/DependencyGraph.java index 1ae67da..785412a 100644 --- a/builder/src/main/java/com/android/builder/compiler/DependencyGraph.java +++ b/builder/src/main/java/com/android/builder/compiler/DependencyGraph.java @@ -18,12 +18,12 @@ package com.android.builder.compiler; import com.android.utils.ILogger; import com.google.common.base.Charsets; +import com.google.common.collect.Sets; import com.google.common.io.Files; import java.io.File; import java.io.IOException; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -179,14 +179,14 @@ public class DependencyGraph { prereqs = files[1].trim().split(" "); } - mTargets = new HashSet<File>(targets.length); + mTargets = Sets.newHashSetWithExpectedSize(targets.length); for (String path : targets) { if (path.length() > 0) { mTargets.add(new File(path)); } } - mPrereqs = new HashSet<File>(prereqs.length); + mPrereqs = Sets.newHashSetWithExpectedSize(prereqs.length); for (String path : prereqs) { if (path.length() > 0) { if (DEBUG) { diff --git a/builder/src/main/java/com/android/builder/compiler/SourceGenerator.java b/builder/src/main/java/com/android/builder/compiler/SourceGenerator.java index c5b8c23..627a88d 100644 --- a/builder/src/main/java/com/android/builder/compiler/SourceGenerator.java +++ b/builder/src/main/java/com/android/builder/compiler/SourceGenerator.java @@ -17,11 +17,12 @@ package com.android.builder.compiler; import com.android.utils.ILogger; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -66,9 +67,9 @@ public class SourceGenerator { // parse all the dep files and keep the ones that are of the proper type and check if // they require compilation again. - Map<File, File> toCompile = new HashMap<File, File>(); - ArrayList<File> toRemove = new ArrayList<File>(); - ArrayList<File> depsToRemove = new ArrayList<File>(); + Map<File, File> toCompile = Maps.newHashMap(); + ArrayList<File> toRemove = Lists.newArrayList(); + ArrayList<File> depsToRemove = Lists.newArrayList(); for (File depFile : depFiles) { DependencyGraph graph = new DependencyGraph(depFile, null /*watchPaths*/, mLogger); @@ -144,7 +145,7 @@ public class SourceGenerator { * @return a map of (file, folder) */ private Map<File, File> getFilesByNameEntryFilter(List<File> folders, String extension) { - Map<File, File> sourceFiles = new HashMap<File, File>(); + Map<File, File> sourceFiles = Maps.newHashMap(); for (File folder : folders) { List<File> files = getFilesByNameEntryFilter(folder, extension); @@ -164,7 +165,7 @@ public class SourceGenerator { * @return an iterator. */ private List<File> getFilesByNameEntryFilter(File sourceFolder, String extension) { - ArrayList<File> result = new ArrayList<File>(); + ArrayList<File> result = Lists.newArrayList(); if (sourceFolder.isDirectory()) { gatherFiles(sourceFolder, extension, result); diff --git a/builder/src/main/java/com/android/builder/signing/SigningInfo.java b/builder/src/main/java/com/android/builder/signing/SigningInfo.java index 124e49d..c06fe57 100644 --- a/builder/src/main/java/com/android/builder/signing/SigningInfo.java +++ b/builder/src/main/java/com/android/builder/signing/SigningInfo.java @@ -21,6 +21,8 @@ import com.android.annotations.NonNull; import java.security.PrivateKey; import java.security.cert.X509Certificate; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Signing information. * @@ -32,12 +34,8 @@ public class SigningInfo { public final X509Certificate mCertificate; public SigningInfo(@NonNull PrivateKey key, @NonNull X509Certificate certificate) { - if (key == null || certificate == null) { - throw new IllegalArgumentException("key and certificate cannot be null"); - } - - mKey = key; - mCertificate = certificate; + mKey = checkNotNull(key, "Key cannot be null."); + mCertificate = checkNotNull(certificate, "Certificate cannot be null."); } public PrivateKey getKey() { |