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

Remove DependencyFactory, introduce IDependencyManager.

This commit is contained in:
Cedric Beust 2016-03-26 08:26:25 -07:00
parent 10f2344edb
commit 984c514fa4
18 changed files with 107 additions and 97 deletions

View file

@ -6,7 +6,6 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.PluginTask
import com.beust.kobalt.api.Project
import com.beust.kobalt.app.*
import com.beust.kobalt.app.remote.DependencyData
import com.beust.kobalt.app.remote.KobaltClient
import com.beust.kobalt.app.remote.KobaltServer
import com.beust.kobalt.internal.Gc
@ -14,7 +13,7 @@ import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.internal.TaskManager
import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.maven.DependencyFactory
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.Http
import com.beust.kobalt.maven.dependency.FileDependency
import com.beust.kobalt.misc.*
@ -59,6 +58,7 @@ private class Main @Inject constructor(
val http: Http,
val files: KFiles,
val executors: KobaltExecutors,
val dependencyManager: DependencyManager,
val checkVersions: CheckVersions,
val github: GithubApi2,
val updateKobalt: UpdateKobalt,
@ -66,8 +66,6 @@ private class Main @Inject constructor(
val server: KobaltServer,
val pluginInfo: PluginInfo,
val projectGenerator: ProjectGenerator,
val depFactory: DependencyFactory,
val dependencyData: DependencyData,
val resolveDependency: ResolveDependency) {
data class RunInfo(val jc: JCommander, val args: Args)
@ -77,7 +75,7 @@ private class Main @Inject constructor(
val dependencies = arrayListOf<IClasspathDependency>()
args.pluginIds?.let {
// We want this call to go to the network if no version was specified, so set localFirst to false
dependencies.addAll(it.split(",").map { depFactory.create(it) })
dependencies.addAll(it.split(",").map { dependencyManager.create(it) })
}
args.pluginJarFiles?.let {
dependencies.addAll(it.split(",").map { FileDependency(it) })

View file

@ -7,7 +7,6 @@ import com.beust.kobalt.app.BuildFileCompiler
import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.maven.DependencyFactory
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.dependency.FileDependency
import com.beust.kobalt.misc.KFiles
@ -17,13 +16,12 @@ import java.io.File
import java.nio.file.Paths
class DependencyData @Inject constructor(val executors: KobaltExecutors, val dependencyManager: DependencyManager,
val buildFileCompilerFactory: BuildFileCompiler.IFactory, val pluginInfo: PluginInfo,
val depFactory: DependencyFactory) {
val buildFileCompilerFactory: BuildFileCompiler.IFactory, val pluginInfo: PluginInfo) {
fun dependenciesDataFor(buildFilePath: String, args: Args) : GetDependenciesData {
val projectDatas = arrayListOf<ProjectData>()
fun toDependencyData(d: IClasspathDependency, scope: String): DependencyData {
val dep = depFactory.create(d.id)
val dep = dependencyManager.create(d.id)
return DependencyData(d.id, scope, dep.jarFile.get().absolutePath)
}

View file

@ -2,7 +2,7 @@ package com.beust.kobalt.plugin.apt
import com.beust.kobalt.api.*
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.maven.DependencyFactory
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.google.common.collect.ArrayListMultimap
@ -18,7 +18,7 @@ import javax.inject.Singleton
* (outputDir, etc...).
*/
@Singleton
class AptPlugin @Inject constructor(val depFactory: DependencyFactory, val configActor: ConfigActor<AptConfig>)
class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, val configActor: ConfigActor<AptConfig>)
: BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor, IConfigActor<AptConfig> by configActor {
// ISourceDirectoryContributor
@ -54,7 +54,7 @@ class AptPlugin @Inject constructor(val depFactory: DependencyFactory, val confi
val result = arrayListOf<String>()
configurationFor(project)?.let { config ->
aptDependencies[project.name]?.let { aptDependencies ->
val deps = aptDependencies.map { depFactory.create(it) }
val deps = aptDependencies.map { dependencyManager.create(it) }
val dependencies = context.dependencyManager.calculateDependencies(null, context, emptyList(), deps)
.map { it.jarFile.get().path }

View file

@ -5,7 +5,6 @@ import com.beust.kobalt.api.*
import com.beust.kobalt.internal.ICompilerAction
import com.beust.kobalt.internal.JvmCompiler
import com.beust.kobalt.kotlin.ParentLastClassLoader
import com.beust.kobalt.maven.DependencyFactory
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.dependency.FileDependency
import com.beust.kobalt.misc.KFiles
@ -31,7 +30,6 @@ import kotlin.properties.Delegates
class KotlinCompiler @Inject constructor(
val files: KFiles,
val dependencyManager: DependencyManager,
val depFactory: DependencyFactory,
val executors: KobaltExecutors,
val jvmCompiler: JvmCompiler) {
companion object {
@ -137,7 +135,7 @@ class KotlinCompiler @Inject constructor(
otherClasspath: List<String>, sourceFiles: List<String>, outputDir: File, args: List<String>) : TaskResult {
val executor = executors.newExecutor("KotlinCompiler", 10)
val compilerDep = depFactory.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_VERSION")
val compilerDep = dependencyManager.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_VERSION")
val deps = dependencyManager.transitiveClosure(listOf(compilerDep))
// Force a download of the compiler dependencies

View file

@ -6,7 +6,7 @@ import com.beust.kobalt.api.*
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.internal.BaseJvmPlugin
import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.maven.DependencyFactory
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.dependency.FileDependency
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
@ -17,7 +17,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depFactory: DependencyFactory,
class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val dependencyManager: DependencyManager,
override val configActor: ConfigActor<KotlinConfig>)
: BaseJvmPlugin<KotlinConfig>(configActor), IDocContributor, IClasspathContributor, ICompilerContributor,
IBuildConfigContributor {
@ -95,7 +95,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depFa
private fun getKotlinCompilerJar(name: String): String {
val id = "org.jetbrains.kotlin:$name:${KotlinCompiler.KOTLIN_VERSION}"
val dep = depFactory.create(id)
val dep = dependencyManager.create(id)
val result = dep.jarFile.get().absolutePath
return result
}

View file

@ -10,8 +10,7 @@ import javax.inject.Inject
import kotlin.properties.Delegates
@Guice(modules = arrayOf(TestModule::class))
public class DependencyTest @Inject constructor(val depFactory: DependencyFactory,
val executors: KobaltExecutors) {
public class DependencyTest @Inject constructor(val executors: KobaltExecutors) {
@DataProvider
fun dpVersions(): Array<Array<out Any>> {

View file

@ -18,7 +18,6 @@ class DownloadTest @Inject constructor(
val localRepo: LocalRepo,
val pomFactory: Pom.IFactory,
val dependencyManager: DependencyManager,
val depFactory: DependencyFactory,
val aether: KobaltAether,
val executors: KobaltExecutors) : KobaltTest() {
private var executor: ExecutorService by Delegates.notNull()
@ -40,7 +39,7 @@ class DownloadTest @Inject constructor(
if (success) {
arrayListOf("$groupId:$artifactId:$version", "$groupId:$artifactId:$previousVersion").forEach {
val dep = depFactory.create(it)
val dep = dependencyManager.create(it)
val future = dep.jarFile
val file = future.get()
Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}")
@ -60,7 +59,7 @@ class DownloadTest @Inject constructor(
fun shouldDownloadNoVersion() {
val success = deleteDir()
if (success) {
val dep = depFactory.create(idNoVersion)
val dep = dependencyManager.create(idNoVersion)
val future = dep.jarFile
val file = future.get()
@ -77,7 +76,7 @@ class DownloadTest @Inject constructor(
val range = "[2.5,)"
val expected = "3.0-alpha-1"
val dep = depFactory.create("javax.servlet:servlet-api:$range")
val dep = dependencyManager.create("javax.servlet:servlet-api:$range")
val future = dep.jarFile
val file = future.get()
Assert.assertEquals(file.name, "servlet-api-$expected.jar")
@ -86,8 +85,8 @@ class DownloadTest @Inject constructor(
@Test
fun shouldFindLocalJar() {
depFactory.create("$idNoVersion$version")
val dep = depFactory.create("$idNoVersion$version")
dependencyManager.create("$idNoVersion$version")
val dep = dependencyManager.create("$idNoVersion$version")
val future = dep.jarFile
// Assert.assertTrue(future is CompletedFuture)
val file = future.get()
@ -96,11 +95,11 @@ class DownloadTest @Inject constructor(
@Test
fun shouldFindLocalJarNoVersion() {
val dep = depFactory.create("$idNoVersion$version")
val dep = dependencyManager.create("$idNoVersion$version")
val future = dep.jarFile
future.get().delete()
val dep2 = depFactory.create("$idNoVersion$version")
val dep2 = dependencyManager.create("$idNoVersion$version")
val file = dep2.jarFile.get()
Assert.assertNotNull(file)
Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}")
@ -140,7 +139,7 @@ class DownloadTest @Inject constructor(
@Test
fun containerPomTest() {
File(localRepo.toFullPath("nl/komponents/kovenant")).deleteRecursively()
val dep = depFactory.create("nl.komponents.kovenant:kovenant:3.0.0")
val dep = dependencyManager.create("nl.komponents.kovenant:kovenant:3.0.0")
dep.directDependencies().forEach {
Assert.assertTrue(it.jarFile.get().exists(), "Dependency was not downloaded: $it")
}

View file

@ -6,9 +6,9 @@ import org.testng.Assert
import org.testng.annotations.Test
@Test
class PomGenerationTest @Inject constructor(val depFactory: DependencyFactory): KobaltTest() {
class PomGenerationTest @Inject constructor(val dependencyManager: DependencyManager): KobaltTest() {
fun shouldGenerateDependencies() {
val md = depFactory.create("org.testng:testng:6.9.9").toMavenDependencies()
val md = dependencyManager.create("org.testng:testng:6.9.9").toMavenDependencies()
Assert.assertEquals(md.groupId, "org.testng")
Assert.assertEquals(md.artifactId, "testng")
Assert.assertEquals(md.version, "6.9.9")

View file

@ -1,21 +1,17 @@
package com.beust.kobalt.maven
import com.beust.kobalt.Args
import com.beust.kobalt.TestModule
import com.beust.kobalt.misc.DependencyExecutor
import org.testng.Assert
import org.testng.annotations.Test
import java.util.concurrent.ExecutorService
import javax.inject.Inject
@Test
@org.testng.annotations.Guice(modules = arrayOf(TestModule::class))
class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder, val depFactory: DependencyFactory,
@DependencyExecutor val executor: ExecutorService, val args: Args){
class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder, val dependencyManager: DependencyManager){
@Test
fun mavenMetadata() {
val dep = depFactory.create("org.codehaus.groovy:groovy-all:")
val dep = dependencyManager.create("org.codehaus.groovy:groovy-all:")
// Note: this test might fail if a new version of Groovy gets uploaded, need
// to find a stable (i.e. abandoned) package
with(dep.id.split(":")[2]) {
@ -25,7 +21,7 @@ class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder, val depFact
@Test(enabled = false)
fun metadataForSnapshots() {
val jar = depFactory.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT")
val jar = dependencyManager.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT")
Assert.assertTrue(jar.jarFile.get().exists())
}