From 6de1b4d893afc7905817a9f1fab917b513ce1310 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 25 Mar 2016 10:57:59 +0400 Subject: [PATCH] Remove usages of MavenDependency. --- .idea/libraries/kobalt_jar.xml | 9 - .../beust/kobalt/api/IClasspathDependency.kt | 3 + .../kotlin/com/beust/kobalt/api/Project.kt | 11 +- .../com/beust/kobalt/maven/DepFactory.kt | 39 +-- .../beust/kobalt/maven/DependencyManager.kt | 7 +- .../com/beust/kobalt/maven/SimpleDep.kt | 4 - .../com/beust/kobalt/maven/aether/Aether.kt | 11 + .../kobalt/maven/dependency/FileDependency.kt | 2 + .../maven/dependency/MavenDependency.kt | 264 +++++++++--------- .../com/beust/kobalt/misc/CheckVersions.kt | 12 +- .../kotlin/com/beust/kobalt/app/MainModule.kt | 4 +- .../beust/kobalt/app/remote/DependencyData.kt | 8 +- .../kobalt/plugin/kotlin/KotlinPlugin.kt | 6 +- .../com/beust/kobalt/maven/DownloadTest.kt | 81 +++--- .../beust/kobalt/maven/PomGenerationTest.kt | 6 +- .../com/beust/kobalt/maven/RemoteRepoTest.kt | 10 +- 16 files changed, 211 insertions(+), 266 deletions(-) delete mode 100644 .idea/libraries/kobalt_jar.xml diff --git a/.idea/libraries/kobalt_jar.xml b/.idea/libraries/kobalt_jar.xml deleted file mode 100644 index b72888c3..00000000 --- a/.idea/libraries/kobalt_jar.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt index 536bacee..cb10caf6 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt @@ -16,6 +16,9 @@ interface IClasspathDependency { /** Identifier for this dependency */ val id: String + /** Version for this identifier */ + val version: String + /** Absolute path to the jar file on the local file system */ val jarFile: Future 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 d3c5d55e..3e2c933b 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.dependency.MavenDependency +import com.beust.kobalt.maven.aether.KobaltAether import com.beust.kobalt.misc.KFiles import java.io.File import java.util.* @@ -83,8 +83,8 @@ open class Project( @Directive fun dependencies(init: Dependencies.() -> Unit) : Dependencies { - dependencies = Dependencies(this, compileDependencies, compileProvidedDependencies, compileRuntimeDependencies, - excludedDependencies) + dependencies = Dependencies(this, compileDependencies, compileProvidedDependencies, + compileRuntimeDependencies, excludedDependencies) dependencies!!.init() return dependencies!! } @@ -139,7 +139,8 @@ class Sources(val project: Project, val sources: HashSet) { } } -class Dependencies(val project: Project, val dependencies: ArrayList, +class Dependencies(val project: Project, + val dependencies: ArrayList, val providedDependencies: ArrayList, val runtimeDependencies: ArrayList, val excludedDependencies: ArrayList) { @@ -150,7 +151,7 @@ class Dependencies(val project: Project, val dependencies: ArrayList, dep: Array) : List - = with(dep.map { MavenDependency.create(it)}) { + = with(dep.map { KobaltAether.create(it)}) { dependencies.addAll(this) this.map { it.jarFile.get() } } 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/DepFactory.kt index bfe201fa..aa8aeba5 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/DepFactory.kt @@ -10,7 +10,10 @@ import com.google.inject.Key import java.util.concurrent.ExecutorService import javax.inject.Inject -public class DepFactory @Inject constructor(val localRepo: LocalRepo, +/** + * Use this class to create instances of `IClasspathDependency` from an id. + */ +class DepFactory @Inject constructor(val localRepo: LocalRepo, val executors: KobaltExecutors, val aether: KobaltAether) { @@ -29,38 +32,10 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo, if (id.startsWith(FileDependency.PREFIX_FILE)) { return FileDependency(id.substring(FileDependency.PREFIX_FILE.length)) } else { - val result = aether.create(id) + val mavenId = MavenId.create(id) + val result = if (mavenId.hasVersion) aether.create(id) + else aether.create(id + "(0,]") return result -// return deps.root -// val mavenId = MavenId.create(id) -// var tentativeVersion = mavenId.version -// var packaging = mavenId.packaging -// var repoResult: RepoFinder.RepoResult? -// -// val version = -// if (tentativeVersion != null && ! MavenId.isRangedVersion(tentativeVersion)) tentativeVersion -// else { -// var localVersion: String? = tentativeVersion -// if (localFirst) localVersion = localRepo.findLocalVersion(mavenId.groupId, mavenId.artifactId, -// mavenId.packaging) -// if (localFirst && localVersion != null) { -// localVersion -// } else { -// if (! localFirst && showNetworkWarning) { -// warn("The id \"$id\" doesn't contain a version, which will cause a network call") -// } -// repoResult = remoteRepo.findCorrectRepo(id) -// if (!repoResult.found) { -// throw KobaltException("Couldn't resolve $id") -// } else { -// repoResult.version?.version -// } -// } -// } -// -// -// val resultMavenId = MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version) -// return mavenDependencyFactory.create(resultMavenId, executor, downloadSources, downloadJavadocs) } } } 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 03b3614c..4c10734c 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 @@ -2,7 +2,6 @@ package com.beust.kobalt.maven import com.beust.kobalt.api.* 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.KobaltExecutors import com.google.common.collect.ArrayListMultimap @@ -11,14 +10,12 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class DependencyManager @Inject constructor(val executors: KobaltExecutors, - val depFactory: DepFactory, val mdFactory: MavenDependency.IFactory){ +class DependencyManager @Inject constructor(val executors: KobaltExecutors, val depFactory: DepFactory) { /** * Create an IClasspathDependency from a Maven id. */ - fun createMaven(id: String) : IClasspathDependency = - mdFactory.create(MavenId.create(id), executors.miscExecutor, false, false) + fun createMaven(id: String) : IClasspathDependency = depFactory.create(id) /** * Create an IClasspathDependency from a path. diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt index 9ec295f0..7c93f2ea 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt @@ -32,15 +32,11 @@ open class SimpleDep(open val mavenId: MavenId) : UnversionedDep(mavenId.groupId fun toPomFile(v: String) = toFile(Version.of(v), ".pom") - fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.snapshotVersion ?: r.version!!, ".pom") - fun toJarFile(v: String = version) = toFile(Version.of(v), suffix) fun toAarFile(v: String = version) = toFile(Version.of(v), ".aar") fun toPomFileName() = "$artifactId-$version.pom" - fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.snapshotVersion ?: r.version!!, suffix) - val suffix : String get() { val packaging = mavenId.packaging 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 084f67c1..812f7901 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,6 +30,15 @@ val TEST_DIR = ".aether/repository" class DependencyResult(val dependency: IClasspathDependency, val repoUrl: String) class KobaltAether(val localRepo: File = File(homeDir(TEST_DIR))) { + 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. + */ fun create(id: String): IClasspathDependency { val aether = Aether(localRepo) val cr = aether.transitiveDependencies(DefaultArtifact(id)) @@ -147,6 +156,8 @@ class AetherDependency(val artifact: Artifact): IClasspathDependency, Comparable override val id: String = toId(artifact) + override val version: String = artifact.version + private fun toId(a: Artifact) = with(a) { groupId + ":" + artifactId + ":" + version } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt index 368e37a4..ee5fdf59 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt @@ -12,6 +12,8 @@ open public class FileDependency(open val fileName: String) : IClasspathDependen override val id = PREFIX_FILE + fileName + override val version = "0.0" + override val jarFile = CompletedFuture(File(fileName)) override fun toMavenDependencies(): Dependency { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt index 6985b691..a83b368c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt @@ -1,142 +1,128 @@ package com.beust.kobalt.maven.dependency -import com.beust.kobalt.HostConfig -import com.beust.kobalt.KobaltException -import com.beust.kobalt.api.IClasspathDependency -import com.beust.kobalt.api.Kobalt -import com.beust.kobalt.maven.* -import com.beust.kobalt.misc.DependencyExecutor -import com.beust.kobalt.misc.Versions -import com.beust.kobalt.misc.log -import com.beust.kobalt.misc.warn -import com.google.inject.Key -import com.google.inject.assistedinject.Assisted -import org.apache.maven.model.Dependency -import java.io.File -import java.util.concurrent.ExecutorService -import java.util.concurrent.Future -import javax.inject.Inject -import kotlin.properties.Delegates - -class MavenDependency @Inject constructor( - @Assisted mavenId: MavenId, - @Assisted val executor: ExecutorService, - @Assisted("downloadSources") val downloadSources: Boolean, - @Assisted("downloadJavadocs") val downloadJavadocs: Boolean, - override val localRepo: LocalRepo, - val repoFinder: RepoFinder, - val dependencyManager: DependencyManager, - val downloadManager: DownloadManager) - : LocalDep(mavenId, localRepo), IClasspathDependency, Comparable { - override var jarFile: Future by Delegates.notNull() - var pomFile: Future by Delegates.notNull() - - interface IFactory { - fun create(mavenId: MavenId, executor: ExecutorService, - @Assisted("downloadSources") downloadSources: Boolean, - @Assisted("downloadJavadocs") downloadJavadocs: Boolean) : MavenDependency - } - - init { - val jar = File(localRepo.toFullPath(toJarFile(version))) - val aar = File(localRepo.toFullPath(toAarFile(version))) - val pom = File(localRepo.toFullPath(toPomFile(version))) - - fun toSuffix(name: String, suffix: String = "") : String { - val dot = name.lastIndexOf(".") - return name.substring(0, dot) + suffix + name.substring(dot) - } - - fun download(url: String, fileName: String, suffix: String = "") : Future { - val localPath = localRepo.toFullPath(toSuffix(fileName, suffix)) - return downloadManager.download(HostConfig(toSuffix(url, suffix)), localPath, executor) - } - - if (pom.exists() && (jar.exists() || aar.exists())) { - jarFile = CompletedFuture(if (jar.exists()) jar else aar) - pomFile = CompletedFuture(pom) - } else { - val repoResult = repoFinder.findCorrectRepo(mavenId.toId) - - if (repoResult.found) { - jarFile = - if (repoResult.archiveUrl != null) { - download(repoResult.archiveUrl, repoResult.path!!) - } else { - CompletedFuture(File("nonexistentFile")) // will be filtered out - } - pomFile = downloadManager.download(HostConfig(url = repoResult.hostConfig.url + toPomFile(repoResult)), - pom.absolutePath, executor) - } else { - throw KobaltException("Couldn't resolve ${mavenId.toId}") - } - } - - if (downloadSources || downloadJavadocs) { - val repoResult = repoFinder.findCorrectRepo(mavenId.toId) - if (repoResult.archiveUrl != null && repoResult.path != null) { - if (downloadSources) { - download(repoResult.archiveUrl, repoResult.path, "-sources") - } - if (downloadJavadocs) { - download(repoResult.archiveUrl, repoResult.path, "-javadoc") - } - } - } - - } - - companion object { - val defaultExecutor = - Kobalt.INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java)) - val depFactory = Kobalt.INJECTOR.getInstance(DepFactory::class.java) - - fun create(id: String, downloadSources: Boolean = false, downloadJavadocs: Boolean = false, - executor: ExecutorService = defaultExecutor) - = depFactory.create(id, downloadSources, downloadJavadocs, executor = executor) - - fun create(mavenId: MavenId, downloadSources: Boolean = false, downloadJavadocs: Boolean = false, - executor: ExecutorService = defaultExecutor) - = create(mavenId.toId, downloadSources, downloadJavadocs, executor) - } - - override fun toString() = mavenId.toId - - override val id = mavenId.toId - - override fun toMavenDependencies() = let { md -> - Dependency().apply { - groupId = md.groupId - artifactId = md.artifactId - version = md.version - } - } - - override fun compareTo(other: MavenDependency): Int { - return Versions.toLongVersion(version).compareTo(Versions.toLongVersion(other.version)) - } - - override val shortId = "$groupId:$artifactId:" - - override fun directDependencies() : List { - val result = arrayListOf() - val maybePom = Pom2.parse(pomFile.get(), dependencyManager) - if (maybePom.value != null) { - val pom = maybePom.value - pom.pomProject.dependencies.filter { - it.mustDownload - }.forEach { - if (it.isValid) { - result.add(create(MavenId.toId(it.groupId(pom), it.artifactId(pom), it.packaging, it.version(pom)))) - } else { - log(2, "Skipping invalid id: ${it.id(pom)}") - } - } - } else { - warn("Couldn't parse POM file ${pomFile.get()}: " + maybePom.exception?.message, maybePom.exception!!) - - } - return result - } -} +//class MavenDependency @Inject constructor(val aether: KobaltAether) : IClasspathDependency by aether { +// fun create(id: String) = aether.create(id) +//} +//class _MavenDependency @Inject constructor( +// @Assisted mavenId: MavenId, +// @Assisted val executor: ExecutorService, +// @Assisted("downloadSources") val downloadSources: Boolean, +// @Assisted("downloadJavadocs") val downloadJavadocs: Boolean, +// override val localRepo: LocalRepo, +// val repoFinder: RepoFinder, +// val dependencyManager: DependencyManager, +// val downloadManager: DownloadManager) +// : LocalDep(mavenId, localRepo), IClasspathDependency, Comparable<_MavenDependency> { +// override var jarFile: Future by Delegates.notNull() +// var pomFile: Future by Delegates.notNull() +// +// interface IFactory { +// fun create(mavenId: MavenId, executor: ExecutorService, +// @Assisted("downloadSources") downloadSources: Boolean, +// @Assisted("downloadJavadocs") downloadJavadocs: Boolean) : _MavenDependency +// } +// +// init { +// val jar = File(localRepo.toFullPath(toJarFile(version))) +// val aar = File(localRepo.toFullPath(toAarFile(version))) +// val pom = File(localRepo.toFullPath(toPomFile(version))) +// +// fun toSuffix(name: String, suffix: String = "") : String { +// val dot = name.lastIndexOf(".") +// return name.substring(0, dot) + suffix + name.substring(dot) +// } +// +// fun download(url: String, fileName: String, suffix: String = "") : Future { +// val localPath = localRepo.toFullPath(toSuffix(fileName, suffix)) +// return downloadManager.download(HostConfig(toSuffix(url, suffix)), localPath, executor) +// } +// +// if (pom.exists() && (jar.exists() || aar.exists())) { +// jarFile = CompletedFuture(if (jar.exists()) jar else aar) +// pomFile = CompletedFuture(pom) +// } else { +// val repoResult = repoFinder.findCorrectRepo(mavenId.toId) +// +// if (repoResult.found) { +// jarFile = +// if (repoResult.archiveUrl != null) { +// download(repoResult.archiveUrl, repoResult.path!!) +// } else { +// CompletedFuture(File("nonexistentFile")) // will be filtered out +// } +// pomFile = downloadManager.download(HostConfig(url = repoResult.hostConfig.url + toPomFile(repoResult)), +// pom.absolutePath, executor) +// } else { +// throw KobaltException("Couldn't resolve ${mavenId.toId}") +// } +// } +// +// if (downloadSources || downloadJavadocs) { +// val repoResult = repoFinder.findCorrectRepo(mavenId.toId) +// if (repoResult.archiveUrl != null && repoResult.path != null) { +// if (downloadSources) { +// download(repoResult.archiveUrl, repoResult.path, "-sources") +// } +// if (downloadJavadocs) { +// download(repoResult.archiveUrl, repoResult.path, "-javadoc") +// } +// } +// } +// +// } +// +// companion object { +// val defaultExecutor = +// Kobalt.INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java)) +// val depFactory = Kobalt.INJECTOR.getInstance(DepFactory::class.java) +// +// fun create(id: String, downloadSources: Boolean = false, downloadJavadocs: Boolean = false, +// executor: ExecutorService = defaultExecutor) +// = depFactory.create(id, downloadSources, downloadJavadocs, executor = executor) +// +// fun create(mavenId: MavenId, downloadSources: Boolean = false, downloadJavadocs: Boolean = false, +// executor: ExecutorService = defaultExecutor) +// = create(mavenId.toId, downloadSources, downloadJavadocs, executor) +// } +// +// override fun toString() = mavenId.toId +// +// override val id = mavenId.toId +// +// override fun toMavenDependencies() = let { md -> +// Dependency().apply { +// groupId = md.groupId +// artifactId = md.artifactId +// version = md.version +// } +// } +// +//// override fun compareTo(other: _MavenDependency): Int { +// return Versions.toLongVersion(version).compareTo(Versions.toLongVersion(other.version)) +// } +// +// override val shortId = "$groupId:$artifactId:" +// +// override fun directDependencies() : List { +// val result = arrayListOf() +// val maybePom = Pom2.parse(pomFile.get(), dependencyManager) +// if (maybePom.value != null) { +// val pom = maybePom.value +// pom.pomProject.dependencies.filter { +// it.mustDownload +// }.forEach { +// if (it.isValid) { +// result.add(create(MavenId.toId(it.groupId(pom), it.artifactId(pom), it.packaging, it.version(pom)))) +// } else { +// log(2, "Skipping invalid id: ${it.id(pom)}") +// } +// } +// } else { +// warn("Couldn't parse POM file ${pomFile.get()}: " + maybePom.exception?.message, maybePom.exception!!) +// +// } +// return result +// } +//} +// 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 bd8df089..4ea62101 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 @@ -4,7 +4,7 @@ import com.beust.kobalt.KobaltException import com.beust.kobalt.api.Project import com.beust.kobalt.maven.DepFactory import com.beust.kobalt.maven.MavenId -import com.beust.kobalt.maven.dependency.MavenDependency +import com.beust.kobalt.maven.aether.AetherDependency import javax.inject.Inject /** @@ -24,12 +24,10 @@ public class CheckVersions @Inject constructor(val depFactory : DepFactory, try { val dep = depFactory.create(compileDependency.shortId, localFirst = false, showNetworkWarning = false, executor = executor) - if (dep is MavenDependency) { - val other = compileDependency as MavenDependency - if (dep.id != compileDependency.id - && Versions.toLongVersion(dep.version) > Versions.toLongVersion(other.version)) { - newVersions.add(dep.id) - } + val other = compileDependency as AetherDependency + if (dep.id != compileDependency.id + && Versions.toLongVersion(dep.version) > Versions.toLongVersion(other.version)) { + newVersions.add(dep.id) } } catch(e: KobaltException) { log(1, " Cannot resolve ${compileDependency.shortId}. ignoring") diff --git a/src/main/kotlin/com/beust/kobalt/app/MainModule.kt b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt index 599bb1c5..1dcaab6a 100644 --- a/src/main/kotlin/com/beust/kobalt/app/MainModule.kt +++ b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt @@ -4,7 +4,6 @@ import com.beust.kobalt.Args import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.maven.* -import com.beust.kobalt.maven.dependency.MavenDependency import com.beust.kobalt.misc.DependencyExecutor import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.plugin.publish.BintrayApi @@ -32,8 +31,7 @@ public open class MainModule(val args: Args, val settings: KobaltSettings) : Abs Pom.IFactory::class.java, BuildFileCompiler.IFactory::class.java, ArtifactFetcher.IFactory::class.java, - RepoFinderCallable.IFactory::class.java, - MavenDependency.IFactory::class.java) + RepoFinderCallable.IFactory::class.java) .forEach { install(builder.build(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 cd940c2f..faeaa4f4 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/DependencyData.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/DependencyData.kt @@ -7,9 +7,9 @@ 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.DependencyManager 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.KobaltExecutors import com.google.inject.Inject @@ -17,13 +17,13 @@ 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 buildFileCompilerFactory: BuildFileCompiler.IFactory, val pluginInfo: PluginInfo, + val depFactory: DepFactory) { fun dependenciesDataFor(buildFilePath: String, args: Args) : GetDependenciesData { val projectDatas = arrayListOf() - val executor = executors.miscExecutor fun toDependencyData(d: IClasspathDependency, scope: String): DependencyData { - val dep = MavenDependency.create(d.id, executor = executor) + val dep = depFactory.create(d.id) return DependencyData(d.id, scope, dep.jarFile.get().absolutePath) } 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 6ae87b00..35318b86 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -6,8 +6,8 @@ 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.dependency.FileDependency -import com.beust.kobalt.maven.dependency.MavenDependency import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.log @@ -17,7 +17,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, +class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depFactory: DepFactory, override val configActor: ConfigActor) : BaseJvmPlugin(configActor), IDocContributor, IClasspathContributor, ICompilerContributor, IBuildConfigContributor { @@ -95,7 +95,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, private fun getKotlinCompilerJar(name: String): String { val id = "org.jetbrains.kotlin:$name:${KotlinCompiler.KOTLIN_VERSION}" - val dep = MavenDependency.create(id, executor = executors.miscExecutor) + val dep = depFactory.create(id) val result = dep.jarFile.get().absolutePath return result } diff --git a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt index 3a108eda..0fc8be3d 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt @@ -2,10 +2,8 @@ package com.beust.kobalt.maven import com.beust.kobalt.HostConfig import com.beust.kobalt.KobaltTest -import com.beust.kobalt.internal.KobaltSettings -import com.beust.kobalt.maven.dependency.MavenDependency +import com.beust.kobalt.maven.aether.KobaltAether import com.beust.kobalt.misc.KobaltExecutors -import com.beust.kobalt.misc.Version import com.beust.kobalt.misc.warn import org.testng.Assert import org.testng.annotations.BeforeClass @@ -15,17 +13,13 @@ import java.util.concurrent.ExecutorService import javax.inject.Inject import kotlin.properties.Delegates -/** - * TODO: test snapshots https://repository.jboss.org/nexus/content/repositories/root_repository//commons-lang/commons-lang/2.7-SNAPSHOT/commons-lang-2.7-SNAPSHOT.jar - */ @Test class DownloadTest @Inject constructor( - val depFactory: DepFactory, val localRepo: LocalRepo, - val mdFactory: MavenDependency.IFactory, val pomFactory: Pom.IFactory, val dependencyManager: DependencyManager, - val settings: KobaltSettings, + val depFactory: DepFactory, + val aether: KobaltAether, val executors: KobaltExecutors) : KobaltTest() { private var executor: ExecutorService by Delegates.notNull() @@ -48,7 +42,6 @@ class DownloadTest @Inject constructor( arrayListOf("$groupId:$artifactId:$version", "$groupId:$artifactId:$previousVersion").forEach { val dep = depFactory.create(it, executor = executor) val future = dep.jarFile - Assert.assertFalse(future is CompletedFuture) val file = future.get() Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}") } @@ -71,7 +64,6 @@ class DownloadTest @Inject constructor( val future = dep.jarFile val file = future.get() - Assert.assertFalse(future is CompletedFuture) Assert.assertNotNull(file) Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}") } else { @@ -88,14 +80,13 @@ class DownloadTest @Inject constructor( val dep = depFactory.create("javax.servlet:servlet-api:$range", executor = executor) val future = dep.jarFile val file = future.get() - Assert.assertFalse(future is CompletedFuture) Assert.assertEquals(file.name, "servlet-api-$expected.jar") Assert.assertTrue(file.exists()) } @Test fun shouldFindLocalJar() { - MavenDependency.create("$idNoVersion$version") + depFactory.create("$idNoVersion$version") val dep = depFactory.create("$idNoVersion$version", executor = executor) val future = dep.jarFile // Assert.assertTrue(future is CompletedFuture) @@ -105,40 +96,40 @@ class DownloadTest @Inject constructor( @Test fun shouldFindLocalJarNoVersion() { - val dep = MavenDependency.create("$idNoVersion$version") + val dep = depFactory.create("$idNoVersion$version") val future = dep.jarFile future.get().delete() - val dep2 = MavenDependency.create("$idNoVersion$version") + val dep2 = depFactory.create("$idNoVersion$version") val file = dep2.jarFile.get() Assert.assertNotNull(file) Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}") } - @Test(groups = arrayOf("broken"), enabled = false) - fun snapshotTest() { - val id = "org.jetbrains.spek:spek:0.1-SNAPSHOT" - val mavenId = MavenId.create(id) - val dep = SimpleDep(mavenId) - - // TODO: allow tests to add their own repo. The following call requires - // "http://repository.jetbrains.com/all" to work - // For now, just hardcoding the result we should have received -// val repoResult = repoFinder.findCorrectRepo(id) - - val hc = HostConfig("http://repository.jetbrains.com/all/") - val repoResult = RepoFinder.RepoResult(hc, - Version.of("0.1-SNAPSHOT"), hc.url, Version("0.1-SNAPSHOT", "20151011.112011-29")) - - val jarFile = dep.toJarFile(repoResult) - val url = repoResult.hostConfig.url + jarFile - - val metadataXmlPath = dep.toMetadataXmlPath(false, false, "0.1-SNAPSHOT") - .replace("\\", "/") - - Assert.assertEquals(metadataXmlPath, "org/jetbrains/spek/spek/0.1-SNAPSHOT/maven-metadata.xml") - Assert.assertTrue(Kurl(HostConfig(url)).exists, "Should exist: $url") - } +// @Test(groups = arrayOf("broken"), enabled = false) +// fun snapshotTest() { +// val id = "org.jetbrains.spek:spek:0.1-SNAPSHOT" +// val mavenId = MavenId.create(id) +// val dep = SimpleDep(mavenId) +// +// // TODO: allow tests to add their own repo. The following call requires +// // "http://repository.jetbrains.com/all" to work +// // For now, just hardcoding the result we should have received +//// val repoResult = repoFinder.findCorrectRepo(id) +// +// val hc = HostConfig("http://repository.jetbrains.com/all/") +// val repoResult = RepoFinder.RepoResult(hc, +// Version.of("0.1-SNAPSHOT"), hc.url, Version("0.1-SNAPSHOT", "20151011.112011-29")) +// +// val jarFile = dep.toJarFile(repoResult) +// val url = repoResult.hostConfig.url + jarFile +// +// val metadataXmlPath = dep.toMetadataXmlPath(false, false, "0.1-SNAPSHOT") +// .replace("\\", "/") +// +// Assert.assertEquals(metadataXmlPath, "org/jetbrains/spek/spek/0.1-SNAPSHOT/maven-metadata.xml") +// Assert.assertTrue(Kurl(HostConfig(url)).exists, "Should exist: $url") +// } @Test fun jitpackTest() { @@ -149,8 +140,7 @@ class DownloadTest @Inject constructor( @Test fun containerPomTest() { File(localRepo.toFullPath("nl/komponents/kovenant")).deleteRecursively() - val dep = mdFactory.create(MavenId.create("nl.komponents.kovenant:kovenant:3.0.0"), executor = executor, - downloadSources = false, downloadJavadocs = false) + val dep = depFactory.create("nl.komponents.kovenant:kovenant:3.0.0") dep.directDependencies().forEach { Assert.assertTrue(it.jarFile.get().exists(), "Dependency was not downloaded: $it") } @@ -162,11 +152,10 @@ class DownloadTest @Inject constructor( // This id has a parent pom which defines moshi version to be 1.1.0. Make sure that this // version is being fetched instead of moshi:1.2.0-SNAPSHOT (which gets discarded anyway // since snapshots are not allowed to be returned when looking up a versionless id) -// val host = HostConfig("http://repository.jetbrains.com/all/") -// val id = "com.squareup.moshi:moshi:" -// val results = finderFactory.create(id, host).call() -// Assert.assertEquals(results.size, 1) -// Assert.assertEquals(results[0].version, "1.1.0") + val host = HostConfig("http://repository.jetbrains.com/all/") + val id = "com.squareup.moshi:moshi:" + val dr = aether.resolve(id) + println("DEP: " + dr) } @Test diff --git a/src/test/kotlin/com/beust/kobalt/maven/PomGenerationTest.kt b/src/test/kotlin/com/beust/kobalt/maven/PomGenerationTest.kt index 8d671596..8bd57318 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/PomGenerationTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/PomGenerationTest.kt @@ -1,14 +1,14 @@ package com.beust.kobalt.maven import com.beust.kobalt.KobaltTest -import com.beust.kobalt.maven.dependency.MavenDependency +import com.google.inject.Inject import org.testng.Assert import org.testng.annotations.Test @Test -class PomGenerationTest : KobaltTest() { +class PomGenerationTest @Inject constructor(val depFactory: DepFactory): KobaltTest() { fun shouldGenerateDependencies() { - val md = MavenDependency.create("org.testng:testng:6.9.9").toMavenDependencies() + val md = depFactory.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") diff --git a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt index 5b33c0b4..fb3f2d89 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt @@ -2,7 +2,6 @@ package com.beust.kobalt.maven import com.beust.kobalt.Args import com.beust.kobalt.TestModule -import com.beust.kobalt.maven.dependency.MavenDependency import com.beust.kobalt.misc.DependencyExecutor import org.testng.Assert import org.testng.annotations.Test @@ -11,12 +10,12 @@ import javax.inject.Inject @Test @org.testng.annotations.Guice(modules = arrayOf(TestModule::class)) -class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder, +class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder, val depFactory: DepFactory, @DependencyExecutor val executor: ExecutorService, val args: Args){ @Test fun mavenMetadata() { - val dep = MavenDependency.create("org.codehaus.groovy:groovy-all:") + val dep = depFactory.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]) { @@ -26,9 +25,8 @@ class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder, @Test(enabled = false) fun metadataForSnapshots() { - val jar = MavenDependency.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT", - executor = executor).jarFile - Assert.assertTrue(jar.get().exists()) + val jar = depFactory.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT") + Assert.assertTrue(jar.jarFile.get().exists()) } fun resolveAarWithVersion() {