1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-27 08:38:13 -07:00

Add IClasspathDependency factory methods to DependencyManager.

This commit is contained in:
Cedric Beust 2016-03-17 01:35:11 +04:00
parent f10685b8cc
commit 283868d5b3

View file

@ -2,6 +2,7 @@ package com.beust.kobalt.maven
import com.beust.kobalt.api.* import com.beust.kobalt.api.*
import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.maven.dependency.FileDependency
import com.beust.kobalt.maven.dependency.MavenDependency
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.KobaltExecutors
import com.google.common.collect.ArrayListMultimap import com.google.common.collect.ArrayListMultimap
@ -10,15 +11,36 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
public class DependencyManager @Inject constructor(val executors: KobaltExecutors, class DependencyManager @Inject constructor(val executors: KobaltExecutors,
val depFactory: DepFactory){ val depFactory: DepFactory, val mdFactory: MavenDependency.IFactory){
/**
* Create an IClasspathDependency from a Maven id.
*/
fun createMaven(id: String) : IClasspathDependency =
mdFactory.create(MavenId.create(id), executors.miscExecutor, false, false)
/**
* Create an IClasspathDependency from a path.
*/
fun createFile(path: String) : IClasspathDependency = FileDependency(path)
/**
* @return the source dependencies for this project, including the contributors.
*/
fun dependencies(project: Project, context: KobaltContext) = dependencies(project, context, false)
/**
* @return the test dependencies for this project, including the contributors.
*/
fun testDependencies(project: Project, context: KobaltContext) = dependencies(project, context, true)
/** /**
* Transitive dependencies for the compilation of this project. * Transitive dependencies for the compilation of this project.
*/ */
fun calculateTransitiveDependencies(project: Project, context: KobaltContext) // fun calculateTransitiveDependencies(project: Project, context: KobaltContext)
= calculateDependencies(project, context, project.dependentProjects, // = calculateDependencies(project, context, project.dependentProjects,
project.compileDependencies + project.compileRuntimeDependencies) // project.compileDependencies + project.compileRuntimeDependencies)
/** /**
* @return the classpath for this project, including the IClasspathContributors. * @return the classpath for this project, including the IClasspathContributors.
@ -80,7 +102,7 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
* Reorder dependencies so that if an artifact appears several times, only the one with the higest version * Reorder dependencies so that if an artifact appears several times, only the one with the higest version
* is included. * is included.
*/ */
fun reorderDependencies(dependencies: Collection<IClasspathDependency>): List<IClasspathDependency> { private fun reorderDependencies(dependencies: Collection<IClasspathDependency>): List<IClasspathDependency> {
val result = arrayListOf<IClasspathDependency>() val result = arrayListOf<IClasspathDependency>()
val map : ArrayListMultimap<String, IClasspathDependency> = ArrayListMultimap.create() val map : ArrayListMultimap<String, IClasspathDependency> = ArrayListMultimap.create()
// The multilist maps each artifact to a list of all the versions found // The multilist maps each artifact to a list of all the versions found
@ -101,8 +123,7 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
* their own dependencies * their own dependencies
*/ */
private fun dependentProjectDependencies(projectDescriptions: List<ProjectDescription>, private fun dependentProjectDependencies(projectDescriptions: List<ProjectDescription>,
project: Project?, context: KobaltContext) : project: Project?, context: KobaltContext) : List<IClasspathDependency> {
List<IClasspathDependency> {
val result = arrayListOf<IClasspathDependency>() val result = arrayListOf<IClasspathDependency>()
projectDescriptions.filter { projectDescriptions.filter {
it.project.name == project?.name it.project.name == project?.name
@ -141,10 +162,4 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
return result2 return result2
} }
fun dependencies(project: Project, context: KobaltContext) = dependencies(project, context, false)
/**
* @return the test dependencies for this project, including the contributors.
*/
fun testDependencies(project: Project, context: KobaltContext) = dependencies(project, context, true)
} }