diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt index ac242117..a4d2f77d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt @@ -3,7 +3,7 @@ package com.beust.kobalt import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.annotation.Directive -import com.beust.kobalt.maven.DepFactory +import com.beust.kobalt.maven.DependencyFactory import com.beust.kobalt.maven.dependency.FileDependency import java.io.File @@ -24,7 +24,7 @@ fun plugins(vararg dependency : IClasspathDependency) { @Directive fun plugins(vararg dependencies : String) { - val factory = Kobalt.INJECTOR.getInstance(DepFactory::class.java) + val factory = Kobalt.INJECTOR.getInstance(DependencyFactory::class.java) dependencies.forEach { Plugins.addDynamicPlugin(factory.create(it)) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt index 5b6532ae..2b2f2025 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt @@ -5,7 +5,7 @@ import com.beust.kobalt.api.annotation.IncrementalTask import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.TaskManager -import com.beust.kobalt.maven.DepFactory +import com.beust.kobalt.maven.DependencyFactory import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.misc.JarUtils import com.beust.kobalt.misc.KFiles @@ -22,7 +22,7 @@ import javax.inject.Singleton @Singleton public class Plugins @Inject constructor (val taskManagerProvider : Provider, val files: KFiles, - val depFactory: DepFactory, + val depFactory: DependencyFactory, val localRepo: LocalRepo, val executors: KobaltExecutors, val pluginInfo: PluginInfo, @@ -152,7 +152,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider { - val executor = Kobalt.INJECTOR.getInstance(KobaltExecutors::class.java).miscExecutor - val depFactory = Kobalt.INJECTOR.getInstance(DepFactory::class.java) - return depFactory.create(id, executor = executor).jarFile - } + fun byIdFuture(id: String) : Future = DependencyFactory.create(id).jarFile /** * @return the jar file corresponding to this id. This might cause a network call. diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index 3e2c933b..73f0b669 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -3,7 +3,7 @@ package com.beust.kobalt.api import com.beust.kobalt.TestConfig import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.internal.JvmCompilerPlugin -import com.beust.kobalt.maven.aether.KobaltAether +import com.beust.kobalt.maven.DependencyFactory import com.beust.kobalt.misc.KFiles import java.io.File import java.util.* @@ -151,7 +151,7 @@ class Dependencies(val project: Project, */ private fun addToDependencies(dependencies: ArrayList, dep: Array) : List - = with(dep.map { KobaltAether.create(it)}) { + = with(dep.map { DependencyFactory.create(it)}) { dependencies.addAll(this) this.map { it.jarFile.get() } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index b2eab908..f98deb6d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -8,7 +8,7 @@ import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.ExportedProjectProperty import com.beust.kobalt.api.annotation.IncrementalTask import com.beust.kobalt.api.annotation.Task -import com.beust.kobalt.maven.DepFactory +import com.beust.kobalt.maven.DependencyFactory import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.maven.Md5 @@ -29,7 +29,7 @@ import javax.inject.Singleton open class JvmCompilerPlugin @Inject constructor( open val localRepo: LocalRepo, open val files: KFiles, - open val depFactory: DepFactory, + open val depFactory: DependencyFactory, open val dependencyManager: DependencyManager, open val executors: KobaltExecutors, open val jvmCompiler: JvmCompiler, diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyFactory.kt similarity index 60% rename from modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyFactory.kt index aa8aeba5..2aebd1ea 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyFactory.kt @@ -4,31 +4,25 @@ import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Kobalt import com.beust.kobalt.maven.aether.KobaltAether import com.beust.kobalt.maven.dependency.FileDependency -import com.beust.kobalt.misc.DependencyExecutor import com.beust.kobalt.misc.KobaltExecutors -import com.google.inject.Key -import java.util.concurrent.ExecutorService import javax.inject.Inject /** * Use this class to create instances of `IClasspathDependency` from an id. */ -class DepFactory @Inject constructor(val localRepo: LocalRepo, +class DependencyFactory @Inject constructor(val localRepo: LocalRepo, val executors: KobaltExecutors, val aether: KobaltAether) { companion object { - val defExecutor : ExecutorService by lazy { - Kobalt.INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java)) - } + fun create(id: String) = + Kobalt.INJECTOR.getInstance(DependencyFactory::class.java).create(id) } /** * Parse the id and return the correct IClasspathDependency */ - fun create(id: String, downloadSources: Boolean = false, downloadJavadocs: Boolean = false, - localFirst : Boolean = true, showNetworkWarning: Boolean = true, executor: ExecutorService = defExecutor) - : IClasspathDependency { + fun create(id: String) : IClasspathDependency { if (id.startsWith(FileDependency.PREFIX_FILE)) { return FileDependency(id.substring(FileDependency.PREFIX_FILE.length)) } else { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 4c10734c..82ffc18a 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -10,7 +10,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class DependencyManager @Inject constructor(val executors: KobaltExecutors, val depFactory: DepFactory) { +class DependencyManager @Inject constructor(val executors: KobaltExecutors, val depFactory: DependencyFactory) { /** * Create an IClasspathDependency from a Maven id. @@ -77,7 +77,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val dependencies.forEach { projectDependency -> result.add(projectDependency) projectDependency.id.let { - result.add(depFactory.create(it, executor = executor)) + result.add(depFactory.create(it)) val downloaded = transitiveClosure(projectDependency.directDependencies()) result.addAll(downloaded) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt index 6b3be0fb..84476e05 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt @@ -30,12 +30,6 @@ class DependencyResult(val dependency: IClasspathDependency, val repoUrl: String class KobaltAether @Inject constructor (val settings: KobaltSettings) { val localRepo: File get() = File(settings.localRepo) - companion object { - val aether : KobaltAether get() = Kobalt.INJECTOR.getInstance(KobaltAether::class.java) - - fun create(id: String) = aether.create(id) - } - /** * Don't call this method directly, use `DepFactory` instead. */ diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt index 4ea62101..f6d360c8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt @@ -2,7 +2,7 @@ package com.beust.kobalt.misc import com.beust.kobalt.KobaltException import com.beust.kobalt.api.Project -import com.beust.kobalt.maven.DepFactory +import com.beust.kobalt.maven.DependencyFactory import com.beust.kobalt.maven.MavenId import com.beust.kobalt.maven.aether.AetherDependency import javax.inject.Inject @@ -10,7 +10,7 @@ import javax.inject.Inject /** * Find out if any newer versions of the dependencies are available. */ -public class CheckVersions @Inject constructor(val depFactory : DepFactory, +public class CheckVersions @Inject constructor(val depFactory : DependencyFactory, val executors : KobaltExecutors) { fun run(projects: List) { @@ -22,8 +22,7 @@ public class CheckVersions @Inject constructor(val depFactory : DepFactory, cds.forEach { compileDependency -> if (MavenId.isMavenId(compileDependency.id)) { try { - val dep = depFactory.create(compileDependency.shortId, localFirst = false, - showNetworkWarning = false, executor = executor) + val dep = depFactory.create(compileDependency.shortId) val other = compileDependency as AetherDependency if (dep.id != compileDependency.id && Versions.toLongVersion(dep.version) > Versions.toLongVersion(other.version)) { diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index a1a8478f..0343383e 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -14,7 +14,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.DepFactory +import com.beust.kobalt.maven.DependencyFactory import com.beust.kobalt.maven.Http import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.misc.* @@ -66,7 +66,7 @@ private class Main @Inject constructor( val server: KobaltServer, val pluginInfo: PluginInfo, val projectGenerator: ProjectGenerator, - val depFactory: DepFactory, + val depFactory: DependencyFactory, val dependencyData: DependencyData, val resolveDependency: ResolveDependency) { @@ -77,7 +77,7 @@ private class Main @Inject constructor( val dependencies = arrayListOf() 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, localFirst = false) }) + dependencies.addAll(it.split(",").map { depFactory.create(it) }) } args.pluginJarFiles?.let { dependencies.addAll(it.split(",").map { FileDependency(it) }) diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/DependencyData.kt b/src/main/kotlin/com/beust/kobalt/app/remote/DependencyData.kt index faeaa4f4..c221a9d8 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/DependencyData.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/DependencyData.kt @@ -7,7 +7,7 @@ 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.DepFactory +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 @@ -18,7 +18,7 @@ import java.nio.file.Paths class DependencyData @Inject constructor(val executors: KobaltExecutors, val dependencyManager: DependencyManager, val buildFileCompilerFactory: BuildFileCompiler.IFactory, val pluginInfo: PluginInfo, - val depFactory: DepFactory) { + val depFactory: DependencyFactory) { fun dependenciesDataFor(buildFilePath: String, args: Args) : GetDependenciesData { val projectDatas = arrayListOf() diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index b0080ec8..77d1f914 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -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.DepFactory +import com.beust.kobalt.maven.DependencyFactory 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: DepFactory, val configActor: ConfigActor) +class AptPlugin @Inject constructor(val depFactory: DependencyFactory, val configActor: ConfigActor) : BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor, IConfigActor by configActor { // ISourceDirectoryContributor diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index f765e38e..e1343e18 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -5,7 +5,7 @@ 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.DepFactory +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 +31,7 @@ import kotlin.properties.Delegates class KotlinCompiler @Inject constructor( val files: KFiles, val dependencyManager: DependencyManager, - val depFactory: DepFactory, + val depFactory: DependencyFactory, val executors: KobaltExecutors, val jvmCompiler: JvmCompiler) { companion object { @@ -137,8 +137,7 @@ class KotlinCompiler @Inject constructor( otherClasspath: List, sourceFiles: List, outputDir: File, args: List) : TaskResult { val executor = executors.newExecutor("KotlinCompiler", 10) - val compilerDep = depFactory.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_VERSION", - executor = executor) + val compilerDep = depFactory.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_VERSION") val deps = dependencyManager.transitiveClosure(listOf(compilerDep)) // Force a download of the compiler dependencies diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index 35318b86..ad2aeb39 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -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.DepFactory +import com.beust.kobalt.maven.DependencyFactory 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: DepFactory, +class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depFactory: DependencyFactory, override val configActor: ConfigActor) : BaseJvmPlugin(configActor), IDocContributor, IClasspathContributor, ICompilerContributor, IBuildConfigContributor { diff --git a/src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt index afe9cbe5..2b40d482 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt @@ -10,7 +10,7 @@ import javax.inject.Inject import kotlin.properties.Delegates @Guice(modules = arrayOf(TestModule::class)) -public class DependencyTest @Inject constructor(val depFactory: DepFactory, +public class DependencyTest @Inject constructor(val depFactory: DependencyFactory, val executors: KobaltExecutors) { @DataProvider diff --git a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt index f07b18b7..c030b0e8 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt @@ -18,7 +18,7 @@ class DownloadTest @Inject constructor( val localRepo: LocalRepo, val pomFactory: Pom.IFactory, val dependencyManager: DependencyManager, - val depFactory: DepFactory, + val depFactory: DependencyFactory, val aether: KobaltAether, val executors: KobaltExecutors) : KobaltTest() { private var executor: ExecutorService by Delegates.notNull() @@ -40,7 +40,7 @@ class DownloadTest @Inject constructor( if (success) { arrayListOf("$groupId:$artifactId:$version", "$groupId:$artifactId:$previousVersion").forEach { - val dep = depFactory.create(it, executor = executor) + val dep = depFactory.create(it) val future = dep.jarFile val file = future.get() Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}") @@ -60,7 +60,7 @@ class DownloadTest @Inject constructor( fun shouldDownloadNoVersion() { val success = deleteDir() if (success) { - val dep = depFactory.create(idNoVersion, executor = executor) + val dep = depFactory.create(idNoVersion) val future = dep.jarFile val file = future.get() @@ -77,7 +77,7 @@ class DownloadTest @Inject constructor( val range = "[2.5,)" val expected = "3.0-alpha-1" - val dep = depFactory.create("javax.servlet:servlet-api:$range", executor = executor) + val dep = depFactory.create("javax.servlet:servlet-api:$range") val future = dep.jarFile val file = future.get() Assert.assertEquals(file.name, "servlet-api-$expected.jar") @@ -87,7 +87,7 @@ class DownloadTest @Inject constructor( @Test fun shouldFindLocalJar() { depFactory.create("$idNoVersion$version") - val dep = depFactory.create("$idNoVersion$version", executor = executor) + val dep = depFactory.create("$idNoVersion$version") val future = dep.jarFile // Assert.assertTrue(future is CompletedFuture) val file = future.get() diff --git a/src/test/kotlin/com/beust/kobalt/maven/PomGenerationTest.kt b/src/test/kotlin/com/beust/kobalt/maven/PomGenerationTest.kt index 8bd57318..76ad2a69 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/PomGenerationTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/PomGenerationTest.kt @@ -6,7 +6,7 @@ import org.testng.Assert import org.testng.annotations.Test @Test -class PomGenerationTest @Inject constructor(val depFactory: DepFactory): KobaltTest() { +class PomGenerationTest @Inject constructor(val depFactory: DependencyFactory): KobaltTest() { fun shouldGenerateDependencies() { val md = depFactory.create("org.testng:testng:6.9.9").toMavenDependencies() Assert.assertEquals(md.groupId, "org.testng") diff --git a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt index fb3f2d89..eeb6c363 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt @@ -10,7 +10,7 @@ import javax.inject.Inject @Test @org.testng.annotations.Guice(modules = arrayOf(TestModule::class)) -class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder, val depFactory: DepFactory, +class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder, val depFactory: DependencyFactory, @DependencyExecutor val executor: ExecutorService, val args: Args){ @Test