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

Remove usages of MavenDependency.

This commit is contained in:
Cedric Beust 2016-03-25 10:57:59 +04:00
parent c57b8c96e9
commit 6de1b4d893
16 changed files with 211 additions and 266 deletions

View file

@ -1,9 +0,0 @@
<component name="libraryTable">
<library name="kobalt.jar">
<CLASSES>
<root url="jar://$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.682/kobalt/wrapper/kobalt-0.682.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View file

@ -16,6 +16,9 @@ interface IClasspathDependency {
/** Identifier for this dependency */ /** Identifier for this dependency */
val id: String val id: String
/** Version for this identifier */
val version: String
/** Absolute path to the jar file on the local file system */ /** Absolute path to the jar file on the local file system */
val jarFile: Future<File> val jarFile: Future<File>

View file

@ -3,7 +3,7 @@ package com.beust.kobalt.api
import com.beust.kobalt.TestConfig import com.beust.kobalt.TestConfig
import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.internal.JvmCompilerPlugin 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 com.beust.kobalt.misc.KFiles
import java.io.File import java.io.File
import java.util.* import java.util.*
@ -83,8 +83,8 @@ open class Project(
@Directive @Directive
fun dependencies(init: Dependencies.() -> Unit) : Dependencies { fun dependencies(init: Dependencies.() -> Unit) : Dependencies {
dependencies = Dependencies(this, compileDependencies, compileProvidedDependencies, compileRuntimeDependencies, dependencies = Dependencies(this, compileDependencies, compileProvidedDependencies,
excludedDependencies) compileRuntimeDependencies, excludedDependencies)
dependencies!!.init() dependencies!!.init()
return dependencies!! return dependencies!!
} }
@ -139,7 +139,8 @@ class Sources(val project: Project, val sources: HashSet<String>) {
} }
} }
class Dependencies(val project: Project, val dependencies: ArrayList<IClasspathDependency>, class Dependencies(val project: Project,
val dependencies: ArrayList<IClasspathDependency>,
val providedDependencies: ArrayList<IClasspathDependency>, val providedDependencies: ArrayList<IClasspathDependency>,
val runtimeDependencies: ArrayList<IClasspathDependency>, val runtimeDependencies: ArrayList<IClasspathDependency>,
val excludedDependencies: ArrayList<IClasspathDependency>) { val excludedDependencies: ArrayList<IClasspathDependency>) {
@ -150,7 +151,7 @@ class Dependencies(val project: Project, val dependencies: ArrayList<IClasspathD
*/ */
private fun addToDependencies(dependencies: ArrayList<IClasspathDependency>, dep: Array<out String>) private fun addToDependencies(dependencies: ArrayList<IClasspathDependency>, dep: Array<out String>)
: List<File> : List<File>
= with(dep.map { MavenDependency.create(it)}) { = with(dep.map { KobaltAether.create(it)}) {
dependencies.addAll(this) dependencies.addAll(this)
this.map { it.jarFile.get() } this.map { it.jarFile.get() }
} }

View file

@ -10,7 +10,10 @@ import com.google.inject.Key
import java.util.concurrent.ExecutorService import java.util.concurrent.ExecutorService
import javax.inject.Inject 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 executors: KobaltExecutors,
val aether: KobaltAether) { val aether: KobaltAether) {
@ -29,38 +32,10 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo,
if (id.startsWith(FileDependency.PREFIX_FILE)) { if (id.startsWith(FileDependency.PREFIX_FILE)) {
return FileDependency(id.substring(FileDependency.PREFIX_FILE.length)) return FileDependency(id.substring(FileDependency.PREFIX_FILE.length))
} else { } 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 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)
} }
} }
} }

View file

@ -2,7 +2,6 @@ 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
@ -11,14 +10,12 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
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. * Create an IClasspathDependency from a Maven id.
*/ */
fun createMaven(id: String) : IClasspathDependency = fun createMaven(id: String) : IClasspathDependency = depFactory.create(id)
mdFactory.create(MavenId.create(id), executors.miscExecutor, false, false)
/** /**
* Create an IClasspathDependency from a path. * Create an IClasspathDependency from a path.

View file

@ -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(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 toJarFile(v: String = version) = toFile(Version.of(v), suffix)
fun toAarFile(v: String = version) = toFile(Version.of(v), ".aar") fun toAarFile(v: String = version) = toFile(Version.of(v), ".aar")
fun toPomFileName() = "$artifactId-$version.pom" fun toPomFileName() = "$artifactId-$version.pom"
fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.snapshotVersion ?: r.version!!, suffix)
val suffix : String val suffix : String
get() { get() {
val packaging = mavenId.packaging val packaging = mavenId.packaging

View file

@ -30,6 +30,15 @@ val TEST_DIR = ".aether/repository"
class DependencyResult(val dependency: IClasspathDependency, val repoUrl: String) class DependencyResult(val dependency: IClasspathDependency, val repoUrl: String)
class KobaltAether(val localRepo: File = File(homeDir(TEST_DIR))) { 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 { fun create(id: String): IClasspathDependency {
val aether = Aether(localRepo) val aether = Aether(localRepo)
val cr = aether.transitiveDependencies(DefaultArtifact(id)) 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 id: String = toId(artifact)
override val version: String = artifact.version
private fun toId(a: Artifact) = with(a) { private fun toId(a: Artifact) = with(a) {
groupId + ":" + artifactId + ":" + version groupId + ":" + artifactId + ":" + version
} }

View file

@ -12,6 +12,8 @@ open public class FileDependency(open val fileName: String) : IClasspathDependen
override val id = PREFIX_FILE + fileName override val id = PREFIX_FILE + fileName
override val version = "0.0"
override val jarFile = CompletedFuture(File(fileName)) override val jarFile = CompletedFuture(File(fileName))
override fun toMavenDependencies(): Dependency { override fun toMavenDependencies(): Dependency {

View file

@ -1,142 +1,128 @@
package com.beust.kobalt.maven.dependency package com.beust.kobalt.maven.dependency
import com.beust.kobalt.HostConfig //class MavenDependency @Inject constructor(val aether: KobaltAether) : IClasspathDependency by aether {
import com.beust.kobalt.KobaltException // fun create(id: String) = aether.create(id)
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<MavenDependency> {
override var jarFile: Future<File> by Delegates.notNull()
var pomFile: Future<File> 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<File> {
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<IClasspathDependency> {
val result = arrayListOf<IClasspathDependency>()
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(
// @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<File> by Delegates.notNull()
// var pomFile: Future<File> 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<File> {
// 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<IClasspathDependency> {
// val result = arrayListOf<IClasspathDependency>()
// 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
// }
//}
//

View file

@ -4,7 +4,7 @@ import com.beust.kobalt.KobaltException
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
import com.beust.kobalt.maven.DepFactory import com.beust.kobalt.maven.DepFactory
import com.beust.kobalt.maven.MavenId import com.beust.kobalt.maven.MavenId
import com.beust.kobalt.maven.dependency.MavenDependency import com.beust.kobalt.maven.aether.AetherDependency
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -24,12 +24,10 @@ public class CheckVersions @Inject constructor(val depFactory : DepFactory,
try { try {
val dep = depFactory.create(compileDependency.shortId, localFirst = false, val dep = depFactory.create(compileDependency.shortId, localFirst = false,
showNetworkWarning = false, executor = executor) showNetworkWarning = false, executor = executor)
if (dep is MavenDependency) { val other = compileDependency as AetherDependency
val other = compileDependency as MavenDependency if (dep.id != compileDependency.id
if (dep.id != compileDependency.id && Versions.toLongVersion(dep.version) > Versions.toLongVersion(other.version)) {
&& Versions.toLongVersion(dep.version) > Versions.toLongVersion(other.version)) { newVersions.add(dep.id)
newVersions.add(dep.id)
}
} }
} catch(e: KobaltException) { } catch(e: KobaltException) {
log(1, " Cannot resolve ${compileDependency.shortId}. ignoring") log(1, " Cannot resolve ${compileDependency.shortId}. ignoring")

View file

@ -4,7 +4,6 @@ import com.beust.kobalt.Args
import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.maven.* import com.beust.kobalt.maven.*
import com.beust.kobalt.maven.dependency.MavenDependency
import com.beust.kobalt.misc.DependencyExecutor import com.beust.kobalt.misc.DependencyExecutor
import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.plugin.publish.BintrayApi 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, Pom.IFactory::class.java,
BuildFileCompiler.IFactory::class.java, BuildFileCompiler.IFactory::class.java,
ArtifactFetcher.IFactory::class.java, ArtifactFetcher.IFactory::class.java,
RepoFinderCallable.IFactory::class.java, RepoFinderCallable.IFactory::class.java)
MavenDependency.IFactory::class.java)
.forEach { .forEach {
install(builder.build(it)) install(builder.build(it))
} }

View file

@ -7,9 +7,9 @@ import com.beust.kobalt.app.BuildFileCompiler
import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.maven.DepFactory
import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.DependencyManager
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.inject.Inject import com.google.inject.Inject
@ -17,13 +17,13 @@ import java.io.File
import java.nio.file.Paths import java.nio.file.Paths
class DependencyData @Inject constructor(val executors: KobaltExecutors, val dependencyManager: DependencyManager, 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 { fun dependenciesDataFor(buildFilePath: String, args: Args) : GetDependenciesData {
val projectDatas = arrayListOf<ProjectData>() val projectDatas = arrayListOf<ProjectData>()
val executor = executors.miscExecutor
fun toDependencyData(d: IClasspathDependency, scope: String): DependencyData { 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) return DependencyData(d.id, scope, dep.jarFile.get().absolutePath)
} }

View file

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

View file

@ -2,10 +2,8 @@ package com.beust.kobalt.maven
import com.beust.kobalt.HostConfig import com.beust.kobalt.HostConfig
import com.beust.kobalt.KobaltTest import com.beust.kobalt.KobaltTest
import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.maven.aether.KobaltAether
import com.beust.kobalt.maven.dependency.MavenDependency
import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.Version
import com.beust.kobalt.misc.warn import com.beust.kobalt.misc.warn
import org.testng.Assert import org.testng.Assert
import org.testng.annotations.BeforeClass import org.testng.annotations.BeforeClass
@ -15,17 +13,13 @@ import java.util.concurrent.ExecutorService
import javax.inject.Inject import javax.inject.Inject
import kotlin.properties.Delegates 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 @Test
class DownloadTest @Inject constructor( class DownloadTest @Inject constructor(
val depFactory: DepFactory,
val localRepo: LocalRepo, val localRepo: LocalRepo,
val mdFactory: MavenDependency.IFactory,
val pomFactory: Pom.IFactory, val pomFactory: Pom.IFactory,
val dependencyManager: DependencyManager, val dependencyManager: DependencyManager,
val settings: KobaltSettings, val depFactory: DepFactory,
val aether: KobaltAether,
val executors: KobaltExecutors) : KobaltTest() { val executors: KobaltExecutors) : KobaltTest() {
private var executor: ExecutorService by Delegates.notNull() private var executor: ExecutorService by Delegates.notNull()
@ -48,7 +42,6 @@ class DownloadTest @Inject constructor(
arrayListOf("$groupId:$artifactId:$version", "$groupId:$artifactId:$previousVersion").forEach { arrayListOf("$groupId:$artifactId:$version", "$groupId:$artifactId:$previousVersion").forEach {
val dep = depFactory.create(it, executor = executor) val dep = depFactory.create(it, executor = executor)
val future = dep.jarFile val future = dep.jarFile
Assert.assertFalse(future is CompletedFuture)
val file = future.get() val file = future.get()
Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}") Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}")
} }
@ -71,7 +64,6 @@ class DownloadTest @Inject constructor(
val future = dep.jarFile val future = dep.jarFile
val file = future.get() val file = future.get()
Assert.assertFalse(future is CompletedFuture)
Assert.assertNotNull(file) Assert.assertNotNull(file)
Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}") Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}")
} else { } else {
@ -88,14 +80,13 @@ class DownloadTest @Inject constructor(
val dep = depFactory.create("javax.servlet:servlet-api:$range", executor = executor) val dep = depFactory.create("javax.servlet:servlet-api:$range", executor = executor)
val future = dep.jarFile val future = dep.jarFile
val file = future.get() val file = future.get()
Assert.assertFalse(future is CompletedFuture)
Assert.assertEquals(file.name, "servlet-api-$expected.jar") Assert.assertEquals(file.name, "servlet-api-$expected.jar")
Assert.assertTrue(file.exists()) Assert.assertTrue(file.exists())
} }
@Test @Test
fun shouldFindLocalJar() { fun shouldFindLocalJar() {
MavenDependency.create("$idNoVersion$version") depFactory.create("$idNoVersion$version")
val dep = depFactory.create("$idNoVersion$version", executor = executor) val dep = depFactory.create("$idNoVersion$version", executor = executor)
val future = dep.jarFile val future = dep.jarFile
// Assert.assertTrue(future is CompletedFuture) // Assert.assertTrue(future is CompletedFuture)
@ -105,40 +96,40 @@ class DownloadTest @Inject constructor(
@Test @Test
fun shouldFindLocalJarNoVersion() { fun shouldFindLocalJarNoVersion() {
val dep = MavenDependency.create("$idNoVersion$version") val dep = depFactory.create("$idNoVersion$version")
val future = dep.jarFile val future = dep.jarFile
future.get().delete() future.get().delete()
val dep2 = MavenDependency.create("$idNoVersion$version") val dep2 = depFactory.create("$idNoVersion$version")
val file = dep2.jarFile.get() val file = dep2.jarFile.get()
Assert.assertNotNull(file) Assert.assertNotNull(file)
Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}") Assert.assertTrue(file.exists(), "Couldn't find ${file.absolutePath}")
} }
@Test(groups = arrayOf("broken"), enabled = false) // @Test(groups = arrayOf("broken"), enabled = false)
fun snapshotTest() { // fun snapshotTest() {
val id = "org.jetbrains.spek:spek:0.1-SNAPSHOT" // val id = "org.jetbrains.spek:spek:0.1-SNAPSHOT"
val mavenId = MavenId.create(id) // val mavenId = MavenId.create(id)
val dep = SimpleDep(mavenId) // val dep = SimpleDep(mavenId)
//
// TODO: allow tests to add their own repo. The following call requires // // TODO: allow tests to add their own repo. The following call requires
// "http://repository.jetbrains.com/all" to work // // "http://repository.jetbrains.com/all" to work
// For now, just hardcoding the result we should have received // // For now, just hardcoding the result we should have received
// val repoResult = repoFinder.findCorrectRepo(id) //// val repoResult = repoFinder.findCorrectRepo(id)
//
val hc = HostConfig("http://repository.jetbrains.com/all/") // val hc = HostConfig("http://repository.jetbrains.com/all/")
val repoResult = RepoFinder.RepoResult(hc, // val repoResult = RepoFinder.RepoResult(hc,
Version.of("0.1-SNAPSHOT"), hc.url, Version("0.1-SNAPSHOT", "20151011.112011-29")) // Version.of("0.1-SNAPSHOT"), hc.url, Version("0.1-SNAPSHOT", "20151011.112011-29"))
//
val jarFile = dep.toJarFile(repoResult) // val jarFile = dep.toJarFile(repoResult)
val url = repoResult.hostConfig.url + jarFile // val url = repoResult.hostConfig.url + jarFile
//
val metadataXmlPath = dep.toMetadataXmlPath(false, false, "0.1-SNAPSHOT") // val metadataXmlPath = dep.toMetadataXmlPath(false, false, "0.1-SNAPSHOT")
.replace("\\", "/") // .replace("\\", "/")
//
Assert.assertEquals(metadataXmlPath, "org/jetbrains/spek/spek/0.1-SNAPSHOT/maven-metadata.xml") // Assert.assertEquals(metadataXmlPath, "org/jetbrains/spek/spek/0.1-SNAPSHOT/maven-metadata.xml")
Assert.assertTrue(Kurl(HostConfig(url)).exists, "Should exist: $url") // Assert.assertTrue(Kurl(HostConfig(url)).exists, "Should exist: $url")
} // }
@Test @Test
fun jitpackTest() { fun jitpackTest() {
@ -149,8 +140,7 @@ class DownloadTest @Inject constructor(
@Test @Test
fun containerPomTest() { fun containerPomTest() {
File(localRepo.toFullPath("nl/komponents/kovenant")).deleteRecursively() File(localRepo.toFullPath("nl/komponents/kovenant")).deleteRecursively()
val dep = mdFactory.create(MavenId.create("nl.komponents.kovenant:kovenant:3.0.0"), executor = executor, val dep = depFactory.create("nl.komponents.kovenant:kovenant:3.0.0")
downloadSources = false, downloadJavadocs = false)
dep.directDependencies().forEach { dep.directDependencies().forEach {
Assert.assertTrue(it.jarFile.get().exists(), "Dependency was not downloaded: $it") 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 // 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 // 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) // since snapshots are not allowed to be returned when looking up a versionless id)
// val host = HostConfig("http://repository.jetbrains.com/all/") val host = HostConfig("http://repository.jetbrains.com/all/")
// val id = "com.squareup.moshi:moshi:" val id = "com.squareup.moshi:moshi:"
// val results = finderFactory.create(id, host).call() val dr = aether.resolve(id)
// Assert.assertEquals(results.size, 1) println("DEP: " + dr)
// Assert.assertEquals(results[0].version, "1.1.0")
} }
@Test @Test

View file

@ -1,14 +1,14 @@
package com.beust.kobalt.maven package com.beust.kobalt.maven
import com.beust.kobalt.KobaltTest import com.beust.kobalt.KobaltTest
import com.beust.kobalt.maven.dependency.MavenDependency import com.google.inject.Inject
import org.testng.Assert import org.testng.Assert
import org.testng.annotations.Test import org.testng.annotations.Test
@Test @Test
class PomGenerationTest : KobaltTest() { class PomGenerationTest @Inject constructor(val depFactory: DepFactory): KobaltTest() {
fun shouldGenerateDependencies() { 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.groupId, "org.testng")
Assert.assertEquals(md.artifactId, "testng") Assert.assertEquals(md.artifactId, "testng")
Assert.assertEquals(md.version, "6.9.9") Assert.assertEquals(md.version, "6.9.9")

View file

@ -2,7 +2,6 @@ package com.beust.kobalt.maven
import com.beust.kobalt.Args import com.beust.kobalt.Args
import com.beust.kobalt.TestModule import com.beust.kobalt.TestModule
import com.beust.kobalt.maven.dependency.MavenDependency
import com.beust.kobalt.misc.DependencyExecutor import com.beust.kobalt.misc.DependencyExecutor
import org.testng.Assert import org.testng.Assert
import org.testng.annotations.Test import org.testng.annotations.Test
@ -11,12 +10,12 @@ import javax.inject.Inject
@Test @Test
@org.testng.annotations.Guice(modules = arrayOf(TestModule::class)) @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){ @DependencyExecutor val executor: ExecutorService, val args: Args){
@Test @Test
fun mavenMetadata() { 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 // Note: this test might fail if a new version of Groovy gets uploaded, need
// to find a stable (i.e. abandoned) package // to find a stable (i.e. abandoned) package
with(dep.id.split(":")[2]) { with(dep.id.split(":")[2]) {
@ -26,9 +25,8 @@ class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder,
@Test(enabled = false) @Test(enabled = false)
fun metadataForSnapshots() { fun metadataForSnapshots() {
val jar = MavenDependency.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT", val jar = depFactory.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT")
executor = executor).jarFile Assert.assertTrue(jar.jarFile.get().exists())
Assert.assertTrue(jar.get().exists())
} }
fun resolveAarWithVersion() { fun resolveAarWithVersion() {