-
Couldn't load subscription status.
- Fork 132
Find indirect dependencies. #98
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,14 @@ import com.android.sdklib.repository.FullRevision | |
| import org.gradle.api.Project | ||
| import org.gradle.api.artifacts.Configuration | ||
| import org.gradle.api.artifacts.Dependency | ||
| import org.gradle.api.artifacts.DependencySet | ||
| import org.gradle.api.artifacts.LenientConfiguration | ||
| import org.gradle.api.artifacts.UnresolvedDependency | ||
| import org.gradle.api.artifacts.result.DependencyResult | ||
| import org.gradle.api.artifacts.result.ResolutionResult | ||
| import org.gradle.api.artifacts.result.ResolvedDependencyResult | ||
| import org.gradle.api.artifacts.result.UnresolvedDependencyResult | ||
| import org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult | ||
| import org.gradle.api.logging.Logger | ||
| import org.gradle.api.logging.Logging | ||
| import org.gradle.api.tasks.StopExecutionException | ||
|
|
@@ -134,6 +142,11 @@ class PackageResolver { | |
| } | ||
|
|
||
| def resolveSupportLibraryRepository() { | ||
|
|
||
| project.repositories.maven { | ||
| url = androidRepositoryDir | ||
| } | ||
|
|
||
| def supportDeps = findDependenciesStartingWith 'com.android.support' | ||
|
|
||
| if (supportDeps.isEmpty()) { | ||
|
|
@@ -143,15 +156,11 @@ class PackageResolver { | |
|
|
||
| log.debug "Found support library dependencies: $supportDeps" | ||
|
|
||
| project.repositories.maven { | ||
| url = androidRepositoryDir | ||
| } | ||
|
|
||
| def needsDownload = false; | ||
| if (!folderExists(androidRepositoryDir)) { | ||
| needsDownload = true | ||
| log.lifecycle 'Support library repository missing. Downloading...' | ||
| } else if (!dependenciesAvailable(supportDeps)) { | ||
| } else if (supportDeps.count { it instanceof UnresolvedDependencyResult } > 0) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can trust gradle resolving mechanism that if it thinks that dependency is resolved, then we are all set. No need to make additional check. |
||
| needsDownload = true | ||
| log.lifecycle 'Support library repository outdated. Downloading update...' | ||
| } | ||
|
|
@@ -279,11 +288,12 @@ class PackageResolver { | |
| } | ||
|
|
||
| def findDependenciesStartingWith(String prefix) { | ||
| def deps = [] | ||
| def deps = new HashSet() | ||
| for (Configuration configuration : project.configurations) { | ||
| for (Dependency dependency : configuration.dependencies) { | ||
| if (dependency.group != null && dependency.group.startsWith(prefix)) { | ||
| deps.add dependency | ||
| ResolutionResult result = configuration.getIncoming().getResolutionResult() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line will make internet connection if necessary. Is there any way to limit configurations scope or make a batch resolution? Will this call be cached at the daemon level? |
||
| result.allDependencies { dependency -> | ||
| if (dependency.requested.displayName.startsWith(prefix)) { | ||
| deps << dependency | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>com.etsy.android.grid</groupId> | ||
| <artifactId>library</artifactId> | ||
| <version>1.0.5</version> | ||
| <packaging>aar</packaging> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.android.support</groupId> | ||
| <artifactId>support-v4</artifactId> | ||
| <version>19.1.0</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>com.etsy.android.grid</groupId> | ||
| <artifactId>library</artifactId> | ||
| <version>1.0.5</version> | ||
| <packaging>aar</packaging> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.android.support</groupId> | ||
| <artifactId>support-v4</artifactId> | ||
| <version>19.1.0</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>com.etsy.android.grid</groupId> | ||
| <artifactId>library</artifactId> | ||
| <version>1.0.5</version> | ||
| <packaging>aar</packaging> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.android.support</groupId> | ||
| <artifactId>support-v4</artifactId> | ||
| <version>19.1.0</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,6 +195,24 @@ class PackageResolverTest { | |
| assertThat(androidCommand).isEmpty() | ||
| } | ||
|
|
||
| @FixtureName("up-to-date-android-m2repository") | ||
| @Test public void upToDateIndirectSupportLibraryRepositoryRecognized() { | ||
| project.apply plugin: 'com.android.application' | ||
|
|
||
| def localMaven = new File(fixture.getRoot(), "localMaven") | ||
| assertThat(localMaven).exists() | ||
| project.repositories.maven { | ||
| url = localMaven | ||
| } | ||
|
|
||
| project.dependencies { | ||
| compile 'com.etsy.android.grid:library:1.0.5' | ||
| } | ||
|
|
||
| packageResolver.resolveSupportLibraryRepository() | ||
| assertThat(androidCommand).isEmpty() | ||
| } | ||
|
|
||
| @FixtureName("missing-android-m2repository") | ||
| @Test public void missingSupportLibraryRepositoryIsDownloaded() { | ||
| project.apply plugin: 'com.android.application' | ||
|
|
@@ -206,6 +224,24 @@ class PackageResolverTest { | |
| assertThat(androidCommand).containsExactly('update extra-android-m2repository') | ||
| } | ||
|
|
||
| @FixtureName("missing-android-m2repository") | ||
| @Test public void missingIndirectSupportLibraryRepositoryIsDownloaded() { | ||
| project.apply plugin: 'com.android.application' | ||
|
|
||
| def localMaven = new File(fixture.getRoot(), "localMaven") | ||
| assertThat(localMaven).exists() | ||
| project.repositories.maven { | ||
| url = localMaven | ||
| } | ||
|
|
||
| project.dependencies { | ||
| compile 'com.etsy.android.grid:library:1.0.5' | ||
| } | ||
|
|
||
| packageResolver.resolveSupportLibraryRepository() | ||
| assertThat(androidCommand).containsExactly('update extra-android-m2repository') | ||
| } | ||
|
|
||
| @FixtureName("missing-android-m2repository") | ||
| @Test public void missingSupportTestingRepositoryIsDownloaded() { | ||
| project.apply plugin: 'com.android.application' | ||
|
|
@@ -228,6 +264,24 @@ class PackageResolverTest { | |
| assertThat(androidCommand).containsExactly('update extra-android-m2repository') | ||
| } | ||
|
|
||
| @FixtureName("outdated-android-m2repository") | ||
| @Test public void outdatedIndirectSupportLibraryRepositoryIsDownloaded() { | ||
| project.apply plugin: 'com.android.application' | ||
|
|
||
| def localMaven = new File(fixture.getRoot(), "localMaven") | ||
| assertThat(localMaven).exists() | ||
| project.repositories.maven { | ||
| url = localMaven | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid making internet connection at the tests. I have created localMaven repo with nested library. |
||
| } | ||
|
|
||
| project.dependencies { | ||
| compile 'com.etsy.android.grid:library:1.0.5' | ||
| } | ||
|
|
||
| packageResolver.resolveSupportLibraryRepository() | ||
| assertThat(androidCommand).containsExactly('update extra-android-m2repository') | ||
| } | ||
|
|
||
| @FixtureName("outdated-android-m2repository") | ||
| @Test public void outdatedSupportTestingRepositoryIsDownloaded() { | ||
| project.apply plugin: 'com.android.application' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved adding android repository url above dependency scan routine.
This is necessary because now we are not just parsing strings at the
build.gradlefile, but gradle actually tries to resolve dependencies. And to be able to resolve the "up-to-date" case gradle needs m2repository link to resolve support library if it's repository is present.