Skip to content

Commit

Permalink
Friendlier logging of repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Jun 24, 2015
1 parent 446cb31 commit 0967855
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,23 @@ import static org.gradle.api.specs.Specs.SATISFIES_ALL
*/
@TypeChecked
class Resolver {
final Map<ScriptHandler, List<ArtifactRepository>> repositoriesForBuildscript;
final Map<Project, List<ArtifactRepository>> repositoriesForProject;
final Set<ArtifactRepository> allRepositories;
final Project project

Resolver(Project project) {
this.project = project
this.repositoriesForBuildscript = project.allprojects.collectEntries { proj ->
[proj, proj.buildscript.repositories.asImmutable()]
}
this.repositoriesForProject = project.allprojects.collectEntries { proj ->
[proj, proj.repositories.asImmutable()]
}
this.allRepositories = project.allprojects.collectMany { Project proj ->
(proj.repositories + proj.buildscript.repositories)
} as Set
logRepositories()
}

/** Returns the version status of the configuration's dependencies at the given revision. */
Expand Down Expand Up @@ -150,38 +163,31 @@ class Resolver {
* completes.
*/
private <T> T resolveWithAllRepositories(Closure<T> closure) {
Map<Project, List<ArtifactRepository>> repositoriesForProject =
project.allprojects.collectEntries { proj -> [proj, proj.repositories.asImmutable()]}
Map<ScriptHandler, List<ArtifactRepository>> repositoriesForBuildscript =
project.allprojects.collectEntries { proj -> [proj, proj.buildscript.repositories.asImmutable()]}
List<ArtifactRepository> allRepositories = project.allprojects.collectMany { Project proj ->
(proj.repositories + proj.buildscript.repositories)
}

project.allprojects.each { proj ->
proj.buildscript.repositories.clear()
proj.buildscript.repositories.addAll(allRepositories)
proj.buildscript.repositories.unique(true)

proj.repositories.clear()
proj.repositories.addAll(allRepositories)
proj.repositories.unique(true)
}
logRepositories()
try {
closure.call()
} finally {
repositoriesForProject.each { proj, original ->
proj.repositories.retainAll(original)
proj.repositories.clear()
proj.repositories.addAll(original)
}
repositoriesForBuildscript.each { buildscript, original ->
buildscript.repositories.retainAll(original)
buildscript.repositories.clear()
buildscript.repositories.addAll(original)
}
}
}

@TypeChecked(SKIP)
private void logRepositories() {
project.logger.info('Resolving with repositories:')
project.repositories.each {
allRepositories.each {
if (it instanceof FlatDirectoryArtifactRepository) {
project.logger.info(" - $it.name: ${it.dirs}")
} else if (it instanceof MavenArtifactRepository || it instanceof IvyArtifactRepository) {
Expand Down

0 comments on commit 0967855

Please sign in to comment.