Skip to content
This repository was archived by the owner on Apr 19, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -134,6 +142,11 @@ class PackageResolver {
}

def resolveSupportLibraryRepository() {

project.repositories.maven {
url = androidRepositoryDir
Copy link
Author

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.gradle file, 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.

}

def supportDeps = findDependenciesStartingWith 'com.android.support'

if (supportDeps.isEmpty()) {
Expand All @@ -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) {
Copy link
Author

Choose a reason for hiding this comment

The 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...'
}
Expand Down Expand Up @@ -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()
Copy link
Author

Choose a reason for hiding this comment

The 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
}
}
}
Expand Down
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
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The 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.
Bad thing I had to copy-paste it through "up-to-date", "missing", "outdated" fixtures.

}

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'
Expand Down