mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Use MavenId everywhere.
This commit is contained in:
parent
bcab73158a
commit
80fda66229
7 changed files with 23 additions and 36 deletions
|
@ -36,7 +36,7 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo,
|
|||
}
|
||||
}
|
||||
|
||||
return MavenDependency(mavenId.groupId, mavenId.artifactId, packaging, version!!,
|
||||
return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version!!),
|
||||
executor, localRepo, repoFinder, pomFactory, downloadManager)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,8 @@ import java.io.File
|
|||
import java.util.concurrent.Future
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
open public class LocalDep(override val groupId: String, override val artifactId: String,
|
||||
override val packaging: String?, override val version: String,
|
||||
open val localRepo: LocalRepo) : SimpleDep(groupId, artifactId, packaging, version) {
|
||||
open public class LocalDep(override val mavenId: MavenId, open val localRepo: LocalRepo)
|
||||
: SimpleDep(mavenId) {
|
||||
|
||||
fun toAbsoluteJarFilePath(v: String) = localRepo.toFullPath(toJarFile(v))
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ open public class LocalRepo(open val localRepo: String = KFiles.localRepo) {
|
|||
v2.compareTo(v1) // we want the most recent at position 0
|
||||
})
|
||||
val result = directories.get(0).name
|
||||
val newDep = LocalDep(groupId, artifactId, packaging, result, this)
|
||||
val newDep = LocalDep(MavenId.create(groupId, artifactId, packaging, result), this)
|
||||
if (existsPom(newDep, result) && existsJar(newDep, result)) {
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -1,26 +1,23 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.beust.kobalt.misc.DependencyExecutor
|
||||
import com.beust.kobalt.misc.Versions
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.google.inject.Key
|
||||
import com.google.inject.assistedinject.Assisted
|
||||
import java.io.File
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Future
|
||||
import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
public class MavenDependency @Inject constructor(override @Assisted("groupId") val groupId : String,
|
||||
override @Assisted("artifactId") val artifactId : String,
|
||||
override @Assisted("packaging") val packaging: String?,
|
||||
override @Assisted("version") val version : String,
|
||||
public class MavenDependency @Inject constructor(mavenId: MavenId,
|
||||
val executor: ExecutorService,
|
||||
override val localRepo: LocalRepo,
|
||||
val repoFinder: RepoFinder,
|
||||
val pomFactory: Pom.IFactory,
|
||||
val downloadManager: DownloadManager)
|
||||
: LocalDep(groupId, artifactId, packaging, version, localRepo), IClasspathDependency,
|
||||
Comparable<MavenDependency> {
|
||||
: LocalDep(mavenId, localRepo), IClasspathDependency, Comparable<MavenDependency> {
|
||||
override var jarFile: Future<File> by Delegates.notNull()
|
||||
var pomFile: Future<File> by Delegates.notNull()
|
||||
|
||||
|
@ -31,7 +28,7 @@ public class MavenDependency @Inject constructor(override @Assisted("groupId") v
|
|||
jarFile = CompletedFuture(jar)
|
||||
pomFile = CompletedFuture(pom)
|
||||
} else {
|
||||
val repoResult = repoFinder.findCorrectRepo(MavenId.toId(groupId, artifactId, packaging, version))
|
||||
val repoResult = repoFinder.findCorrectRepo(mavenId.toId)
|
||||
if (repoResult.found) {
|
||||
jarFile =
|
||||
if (repoResult.hasJar) {
|
||||
|
@ -42,19 +39,11 @@ public class MavenDependency @Inject constructor(override @Assisted("groupId") v
|
|||
pomFile = downloadManager.download(repoResult.repoUrl + toPomFile(repoResult), pom.absolutePath,
|
||||
executor)
|
||||
} else {
|
||||
throw KobaltException("Couldn't resolve " +
|
||||
"${MavenId.toId(groupId, artifactId, packaging, version)}")
|
||||
throw KobaltException("Couldn't resolve ${mavenId.toId}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// interface IFactory {
|
||||
// fun _create(@Assisted("groupId") groupId: String,
|
||||
// @Assisted("artifactId") artifactId: String,
|
||||
// @Assisted("version") version: String = "",
|
||||
// executor: ExecutorService) : MavenDependency
|
||||
// }
|
||||
|
||||
companion object {
|
||||
val executor = Kobalt.INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java))
|
||||
val depFactory = Kobalt.INJECTOR.getInstance(DepFactory::class.java)
|
||||
|
@ -69,9 +58,9 @@ public class MavenDependency @Inject constructor(override @Assisted("groupId") v
|
|||
}
|
||||
|
||||
|
||||
public override fun toString() = MavenId.toId(groupId, artifactId, packaging, version)
|
||||
public override fun toString() = mavenId.toId
|
||||
|
||||
override val id = MavenId.toId(groupId, artifactId, packaging, version)
|
||||
override val id = mavenId.toId
|
||||
|
||||
override fun toMavenDependencies(): org.apache.maven.model.Dependency {
|
||||
with(org.apache.maven.model.Dependency()) {
|
||||
|
|
|
@ -54,8 +54,8 @@ public class PomGenerator @Inject constructor(@Assisted val project: Project) {
|
|||
|
||||
val buildDir = com.beust.kobalt.misc.KFiles.makeDir(project.directory, project.buildDirectory!!)
|
||||
val outputDir = com.beust.kobalt.misc.KFiles.makeDir(buildDir.path, "libs")
|
||||
val pomFile = SimpleDep(project.group!!, project.artifactId!!, project.packaging, project.version!!)
|
||||
.toPomFileName()
|
||||
val mavenId = MavenId.create(project.group!!, project.artifactId!!, project.packaging, project.version!!)
|
||||
val pomFile = SimpleDep(mavenId).toPomFileName()
|
||||
val outputFile = File(outputDir, pomFile)
|
||||
outputFile.writeText(s.toString(), Charset.defaultCharset())
|
||||
log(1, " Wrote $outputFile")
|
||||
|
|
|
@ -85,7 +85,7 @@ public class RepoFinder @Inject constructor(val urlFactory: Kurl.IFactory, val e
|
|||
}
|
||||
} else {
|
||||
if (version!!.contains("SNAPSHOT")) {
|
||||
val dep = SimpleDep(groupId, artifactId, packaging, version)
|
||||
val dep = SimpleDep(mavenId)
|
||||
val snapshotVersion = findSnapshotVersion(dep.toMetadataXmlPath(false), repoUrl)
|
||||
if (snapshotVersion != null) {
|
||||
return RepoResult(repoUrl, true, version, true /* hasJar, potential bug here */,
|
||||
|
@ -94,7 +94,7 @@ public class RepoFinder @Inject constructor(val urlFactory: Kurl.IFactory, val e
|
|||
return RepoResult(repoUrl, false, "")
|
||||
}
|
||||
} else {
|
||||
val dep = SimpleDep(groupId, artifactId, packaging, version)
|
||||
val dep = SimpleDep(mavenId)
|
||||
// Try to find the jar file
|
||||
val urlJar = repoUrl + dep.toJarFile(dep.version)
|
||||
val hasJar = urlFactory.create(urlJar).exists
|
||||
|
|
|
@ -2,17 +2,15 @@ package com.beust.kobalt.maven
|
|||
|
||||
import com.beust.kobalt.misc.Strings
|
||||
|
||||
open public class SimpleDep(override val groupId: String, override val artifactId: String,
|
||||
open val packaging: String?, open val version: String) : UnversionedDep(groupId, artifactId) {
|
||||
open public class SimpleDep(open val mavenId: MavenId) : UnversionedDep(mavenId.groupId, mavenId.artifactId) {
|
||||
companion object {
|
||||
fun create(id: String) = MavenId(id).let {
|
||||
if (id.contains("android")) {
|
||||
println("DONOTCOMMIT")
|
||||
}
|
||||
SimpleDep(it.groupId, it.artifactId, it.packaging, it.version!!)
|
||||
SimpleDep(MavenId(id))
|
||||
}
|
||||
}
|
||||
|
||||
val version: String get() = mavenId.version!!
|
||||
|
||||
override public fun toMetadataXmlPath(fileSystem: Boolean): String {
|
||||
return toDirectory(version, fileSystem) + "maven-metadata.xml"
|
||||
}
|
||||
|
@ -35,6 +33,7 @@ open public class SimpleDep(override val groupId: String, override val artifactI
|
|||
|
||||
val suffix : String
|
||||
get() {
|
||||
return if (packaging != null && ! packaging.isNullOrBlank()) ".${packaging!!}" else ".jar"
|
||||
val packaging = mavenId.packaging
|
||||
return if (packaging != null && ! packaging.isNullOrBlank()) ".${packaging}" else ".jar"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue