mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
tmp files.
This commit is contained in:
parent
1cba229703
commit
4f6c089cbb
4 changed files with 388 additions and 8 deletions
58
tmp/DepFactory.kt
Normal file
58
tmp/DepFactory.kt
Normal file
|
@ -0,0 +1,58 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.maven.dependency.FileDependency
|
||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||
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
|
||||
|
||||
public class DepFactory @Inject constructor(val localRepo: LocalRepo,
|
||||
val remoteRepo: RepoFinder,
|
||||
val executors: KobaltExecutors,
|
||||
val downloadManager: DownloadManager,
|
||||
val pomFactory: Pom.IFactory) {
|
||||
|
||||
companion object {
|
||||
val defExecutor : ExecutorService by lazy {
|
||||
Kobalt.INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the id and return the correct IClasspathDependency
|
||||
*/
|
||||
public fun create(id: String, executor: ExecutorService = defExecutor, localFirst : Boolean = true)
|
||||
: IClasspathDependency {
|
||||
if (id.startsWith(FileDependency.PREFIX_FILE)) {
|
||||
return FileDependency(id.substring(FileDependency.PREFIX_FILE.length))
|
||||
} else {
|
||||
val mavenId = MavenId.create(id)
|
||||
var version = mavenId.version
|
||||
var packaging = mavenId.packaging
|
||||
var repoResult: RepoFinder.RepoResult?
|
||||
|
||||
if (version == null || MavenId.isRangedVersion(version)) {
|
||||
var localVersion: String? = version
|
||||
if (localFirst) localVersion = localRepo.findLocalVersion(mavenId.groupId, mavenId.artifactId, mavenId.packaging)
|
||||
if (localFirst && localVersion != null) {
|
||||
version = localVersion
|
||||
} else {
|
||||
repoResult = remoteRepo.findCorrectRepo(id)
|
||||
if (!repoResult.found) {
|
||||
throw KobaltException("Couldn't resolve $id")
|
||||
} else {
|
||||
version = repoResult.version?.version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version),
|
||||
executor, localRepo, remoteRepo, pomFactory, downloadManager)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue