1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Move exclude() management to DependencyManager, where it belongs.

This commit is contained in:
Cedric Beust 2017-02-22 20:44:19 -08:00
parent 64437761a4
commit b54c4c63c8
3 changed files with 21 additions and 20 deletions

View file

@ -75,9 +75,7 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager
File(project.directory, buildDirectory.path).mkdirs()
// Remove all the excluded dependencies from the classpath
var classpath = fullClasspath.filter {
! isDependencyExcluded(it, project.excludedDependencies)
}
var classpath = fullClasspath
// The classpath needs to contain $buildDirectory/classes as well so that projects that contain
// multiple languages can use classes compiled by the compiler run before them.
@ -225,15 +223,4 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager
}
return result
}
companion object {
/**
* Naïve implementation: just exclude all dependencies that start with one of the excluded dependencies.
* Should probably make exclusion more generic (full on string) or allow exclusion to be specified
* formally by groupId or artifactId.
*/
fun isDependencyExcluded(dep: IClasspathDependency, excluded: List<IClasspathDependency>)
= excluded.any { excluded -> dep.id.startsWith(excluded.id) }
}
}

View file

@ -91,9 +91,7 @@ open class JvmCompilerPlugin @Inject constructor(
scopes = listOf(Scope.TEST))
val compileDependencies = dependencyManager.calculateDependencies(project, context,
scopes = listOf(Scope.COMPILE))
val allDependencies = (compileDependencies + testDependencies)
.toHashSet()
.filter { ! CompilerUtils.isDependencyExcluded(it, project.excludedDependencies) }
val allDependencies = (compileDependencies + testDependencies).toHashSet()
return testContributor.run(project, context, configName, allDependencies.toList())
} else {
context.logger.log(project.name, 2,

View file

@ -85,8 +85,10 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors,
// project.compileDependencies + project.compileRuntimeDependencies)
/**
* @return the classpath for this project, including the IClasspathContributors.
* allDependencies is typically either compileDependencies or testDependencies. If no dependencies
* @return the classpath for this project, including the IClasspathContributors. Excluded dependencies
* are removed from the result.
*
* @param{allDependencies} is typically either compileDependencies or testDependencies. If no dependencies
* are passed, they are calculated from the scope filters.
*/
override fun calculateDependencies(project: Project?, context: KobaltContext,
@ -130,10 +132,24 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors,
result.addAll(runClasspathContributors(project, context))
result.addAll(dependentProjectDependencies(project, context, dependencyFilter, scopes))
/**
* Naïve implementation: just exclude all dependencies that start with one of the excluded dependencies.
* Should probably make exclusion more generic (full on string) or allow exclusion to be specified
* formally by groupId or artifactId.
*/
fun isDependencyExcluded(dep: IClasspathDependency, excluded: List<IClasspathDependency>)
= excluded.any { excluded -> dep.id.startsWith(excluded.id) }
// Dependencies get reordered by transitiveClosure() but since we just added a bunch of new ones,
// we need to reorder them again in case we're adding dependencies that are already present
// but with a different version
val reordered = reorderDependencies(result)
val shortResult =
if (project != null) {
result.filter { ! isDependencyExcluded(it, project.excludedDependencies) }
} else {
result
}
val reordered = reorderDependencies(shortResult)
return reordered
}