diff options
author | Xavier Ducrohet <xav@android.com> | 2012-10-09 14:19:08 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-10-09 14:19:08 -0700 |
commit | a90bcc84673c6d7596188c0657f8233103618155 (patch) | |
tree | 670fe7ab7e62fc54091a75ff32691814127d5d34 /gradle | |
parent | 6bdc2a5034543bb3a9b6d9f7090a9256bd62b51b (diff) | |
download | build-a90bcc84673c6d7596188c0657f8233103618155.tar.gz |
Update DependencyChecker to run in the per-variant prepare task.
Change-Id: I2c3e4d16ee9efeb916e46428b11d2e55b8c56e00
Diffstat (limited to 'gradle')
6 files changed, 69 insertions, 40 deletions
diff --git a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy index 065ffe7..c9767e2 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy @@ -99,7 +99,7 @@ abstract class BasePlugin { testSourceSet = sourceSets.create("test") defaultConfigData = new ProductFlavorData(defaultConfig, mainSourceSet, - testSourceSet, project) + testSourceSet, project, ConfigurationDependencies.ConfigType.DEFAULT) } ProductFlavorData getDefaultConfigData() { @@ -554,6 +554,7 @@ abstract class BasePlugin { // for all libraries required by the configurations of this variant, make this task // depend on all the tasks preparing these libraries. for (ConfigurationDependencies configDependencies : configDependenciesList) { + prepareDependenciesTask.addChecker(configDependencies.checker) for (AndroidDependencyImpl lib : configDependencies.libraries) { addDependencyToPrepareTask(prepareDependenciesTask, lib) @@ -632,21 +633,21 @@ abstract class BasePlugin { // TODO - shouldn't need to do this - fix this in Gradle ensureConfigured(compileClasspath) - def checker = new DependencyChecker(logger) + configDependencies.checker = new DependencyChecker(configDependencies, logger) // TODO - defer downloading until required -- This is hard to do as we need the info to build the variant config. List<AndroidDependency> bundles = [] List<JarDependency> jars = [] collectArtifacts(compileClasspath, artifacts) compileClasspath.resolvedConfiguration.resolutionResult.root.dependencies.each { ResolvedDependencyResult dep -> - addDependency(dep.selected, checker, configDependencies, bundles, jars, modules, + addDependency(dep.selected, configDependencies, bundles, jars, modules, artifacts, reverseMap) } // also need to process local jar files, as they are not processed by the // resolvedConfiguration result compileClasspath.allDependencies.each { dep -> if (dep instanceof SelfResolvingDependency && - (dep instanceof ProjectDependency) == false) { + !(dep instanceof ProjectDependency)) { Set<File> files = ((SelfResolvingDependency) dep).resolve() for (File f : files) { jars << new JarDependency(f.absolutePath, true, true, true) @@ -683,7 +684,6 @@ abstract class BasePlugin { } def addDependency(ResolvedModuleVersionResult moduleVersion, - DependencyChecker checker, ConfigurationDependencies configDependencies, Collection<AndroidDependency> bundles, Collection<JarDependency> jars, @@ -691,7 +691,7 @@ abstract class BasePlugin { Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts, Multimap<AndroidDependency, ConfigurationDependencies> reverseMap) { def id = moduleVersion.id - if (checker.excluded(id)) { + if (configDependencies.checker.excluded(id)) { return } @@ -702,7 +702,7 @@ abstract class BasePlugin { def nestedBundles = [] moduleVersion.dependencies.each { ResolvedDependencyResult dep -> - addDependency(dep.selected, checker, configDependencies, nestedBundles, + addDependency(dep.selected, configDependencies, nestedBundles, jars, modules, artifacts, reverseMap) } diff --git a/gradle/src/main/groovy/com/android/build/gradle/DependencyChecker.groovy b/gradle/src/main/groovy/com/android/build/gradle/DependencyChecker.groovy index a9ca472..9b6ea22 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/DependencyChecker.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/DependencyChecker.groovy @@ -15,6 +15,7 @@ */ package com.android.build.gradle +import com.android.build.gradle.internal.ConfigurationDependencies import com.android.utils.ILogger import org.gradle.api.artifacts.ModuleVersionIdentifier @@ -23,20 +24,22 @@ import org.gradle.api.artifacts.ModuleVersionIdentifier */ class DependencyChecker { + final ConfigurationDependencies configurationDependencies final logger - final List<Integer> mFoundAndroidApis = [] - final List<String> mFoundBouncyCastle = [] + final List<Integer> foundAndroidApis = [] + final List<String> foundBouncyCastle = [] - DependencyChecker(ILogger logger) { + DependencyChecker(ConfigurationDependencies configurationDependencies, ILogger logger) { + this.configurationDependencies = configurationDependencies this.logger = logger; } boolean excluded(ModuleVersionIdentifier id) { if (id.group == 'com.google.android' && id.name == 'android') { int moduleLevel = getApiLevelFromMavenArtifact(id.version) - mFoundAndroidApis.add(moduleLevel) + foundAndroidApis.add(moduleLevel) - logger.info("Ignoring Android API artifact: " + id) + logger.info("Ignoring Android API artifact %s for %s", id, getConfigName()) return true } @@ -46,35 +49,49 @@ class DependencyChecker { (id.group == 'xerces' && id.name == 'xmlParserAPIs')) { logger.warning( - "WARNING: Dependency %s is ignored as it may be conflicting with the internal version provided by Android.\n" + + "WARNING: Dependency %s is ignored for %s as it may be conflicting with the internal version provided by Android.\n" + " In case of problem, please repackage with jarjar to change the class packages", - id) + id, getConfigName()) return true; } if (id.group == 'org.json' && id.name == 'json') { logger.warning( - "WARNING: Dependency %s is ignored as it may be conflicting with the internal version provided by Android.\n" + + "WARNING: Dependency %s is ignored for %s as it may be conflicting with the internal version provided by Android.\n" + " In case of problem, please repackage with jarjar to change the class packages", - id) + id, getConfigName()) return true } if (id.group == 'org.khronos' && id.name == 'opengl-api') { logger.warning( - "WARNING: Dependency %s is ignored as it may be conflicting with the internal version provided by Android.\n" + + "WARNING: Dependency %s is ignored for %s as it may be conflicting with the internal version provided by Android.\n" + " In case of problem, please repackage with jarjar to change the class packages", - id) + id, getConfigName()) return true } if (id.group == 'org.bouncycastle' && id.name.startsWith("bcprov")) { - mFoundBouncyCastle.add(id.version) + foundBouncyCastle.add(id.version) } return false } + public String getConfigName() { + switch (configurationDependencies.type) { + case ConfigurationDependencies.ConfigType.DEFAULT: + if (configurationDependencies.sourceSet.name.equals("test")) { + return "the default test configuration" + } + + return "the default configuration" + case ConfigurationDependencies.ConfigType.FLAVOR: + return "Flavor ${configurationDependencies.sourceSet.name.capitalize()}" + case ConfigurationDependencies.ConfigType.BUILDTYPE: + return "Build Type ${configurationDependencies.sourceSet.name.capitalize()}" + } + } private int getApiLevelFromMavenArtifact(String version) { switch (version) { diff --git a/gradle/src/main/groovy/com/android/build/gradle/PrepareDependenciesTask.groovy b/gradle/src/main/groovy/com/android/build/gradle/PrepareDependenciesTask.groovy index 9180c55..077be5b 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/PrepareDependenciesTask.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/PrepareDependenciesTask.groovy @@ -19,6 +19,7 @@ import com.android.utils.Pair import org.gradle.api.tasks.TaskAction class PrepareDependenciesTask extends BaseTask { + final List<DependencyChecker> checkers = [] final Set<Pair<Integer, String>> androidDependencies = [] void addDependency(Pair<Integer, String> api) { @@ -27,24 +28,21 @@ class PrepareDependenciesTask extends BaseTask { @TaskAction def prepare() { - // TODO check against variant's minSdkVersion - if (!androidDependencies.isEmpty()) { - def builder = getBuilder(); - def target = builder.getTargetApiLevel() - for (Pair<Integer, String> dependency : androidDependencies) { - if (dependency.getFirst() > target) { - String parentDependency = dependency.getSecond() - if (parentDependency != null) { - throw new RuntimeException(String.format( - "ERROR: %s depends on Android API level %d, but project target is API level %d", - parentDependency, dependency.getFirst(), target)) - } else { - throw new RuntimeException(String.format( - "ERROR: project depends on Android API level %d, but project target is API level %d", - dependency.getFirst(), target)) - } + def minSdkVersion = variant.config.minSdkVersion + + for (DependencyChecker checker : checkers) { + for (Integer api : checker.foundAndroidApis) { + if (api > minSdkVersion) { + throw new RuntimeException(String.format( + "ERROR: %s has an indirect dependency on Android API level %d, but minSdkVersion for variant '%s' is API level %d", + checker.configName.capitalize(), api, variant.name, minSdkVersion)) } } + } } + + def addChecker(DependencyChecker checker) { + checkers.add(checker) + } } diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/BuildTypeData.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/BuildTypeData.groovy index 1b543d5..4c2932b 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/BuildTypeData.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/BuildTypeData.groovy @@ -27,7 +27,7 @@ class BuildTypeData extends ConfigurationDependencies { final Task assembleTask BuildTypeData(BuildType buildType, AndroidSourceSet sourceSet, Project project) { - super(project, sourceSet) + super(project, sourceSet, ConfigType.BUILDTYPE) this.buildType = buildType diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/ConfigurationDependencies.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/ConfigurationDependencies.groovy index 1e48c10..2626145 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/ConfigurationDependencies.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/ConfigurationDependencies.groovy @@ -20,6 +20,7 @@ import com.android.build.gradle.AndroidSourceSet import com.android.builder.JarDependency import org.gradle.api.Project import org.gradle.api.artifacts.Configuration +import com.android.build.gradle.DependencyChecker /** * Object that represents the dependencies of a configuration, and optionally contains the @@ -27,13 +28,19 @@ import org.gradle.api.artifacts.Configuration */ class ConfigurationDependencies { + protected static enum ConfigType { DEFAULT, FLAVOR, BUILDTYPE } + final Project project final AndroidSourceSet sourceSet + final ConfigType type ConfigurationDependencies testConfigDependencies; - ConfigurationDependencies(Project project, AndroidSourceSet sourceSet) { + DependencyChecker checker + + ConfigurationDependencies(Project project, AndroidSourceSet sourceSet, ConfigType type) { this.project = project this.sourceSet = sourceSet + this.type = type } List<AndroidDependencyImpl> libraries diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/ProductFlavorData.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/ProductFlavorData.groovy index 39266b4..15060a8 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/ProductFlavorData.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/ProductFlavorData.groovy @@ -30,13 +30,20 @@ class ProductFlavorData extends ConfigurationDependencies { ProductFlavorData(ProductFlavorDsl productFlavor, AndroidSourceSet sourceSet, AndroidSourceSet testSourceSet, - Project project) { - super(project, sourceSet) + Project project, ConfigType type) { + super(project, sourceSet, type) this.productFlavor = productFlavor this.testSourceSet = testSourceSet - setTestConfigDependencies(new ConfigurationDependencies(project, testSourceSet)) + setTestConfigDependencies( + new ConfigurationDependencies(project, testSourceSet, type)) + } + + ProductFlavorData(ProductFlavorDsl productFlavor, + AndroidSourceSet sourceSet, AndroidSourceSet testSourceSet, + Project project) { + this(productFlavor, sourceSet, testSourceSet, project, ConfigType.FLAVOR) } |