1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00
This commit is contained in:
Dmitry Zhuravlev 2017-04-03 12:13:49 +03:00
commit 23bbcd4d84
18 changed files with 174 additions and 124 deletions

View file

@ -128,5 +128,9 @@ class Kobalt {
fun addBuildSourceDirs(dirs: Array<out String>) {
buildSourceDirs.addAll(dirs)
}
fun cleanUp() {
buildSourceDirs.clear()
}
}
}

View file

@ -4,9 +4,6 @@ import com.beust.kobalt.api.Dependencies
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.maven.CompletedFuture
import com.beust.kobalt.maven.LocalDep
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.MavenId
import com.beust.kobalt.misc.StringVersion
import com.beust.kobalt.misc.warn
import org.eclipse.aether.artifact.Artifact
@ -26,18 +23,13 @@ class AetherDependency(val artifact: Artifact, override val optional: Boolean =
private fun toId(a: Artifact) = a.toString()
override val jarFile: Future<File>
get() = if (artifact.file != null) {
CompletedFuture(artifact.file)
} else {
val localRepo = Kobalt.INJECTOR.getInstance(LocalRepo::class.java)
val file = File(LocalDep(MavenId.create(id), localRepo).toAbsoluteJarFilePath(version))
if (file.exists()) {
CompletedFuture(file)
get() =
if (artifact.file != null) {
CompletedFuture(artifact.file)
} else {
val td = aether.resolve(artifact, null)
CompletedFuture(td.root.artifact.file)
}
}
override fun toMavenDependencies(scope: String?) : org.apache.maven.model.Dependency {
val passedScope = scope

View file

@ -20,6 +20,7 @@ import org.eclipse.aether.resolution.DependencyRequest
import org.eclipse.aether.resolution.DependencyResult
import org.eclipse.aether.resolution.VersionRangeRequest
import org.eclipse.aether.resolution.VersionRangeResult
import java.util.*
class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
val args: Args,
@ -35,8 +36,9 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
fun resolveToArtifact(id: String, scope: Scope? = null, filter: DependencyFilter? = null) : Artifact
= resolve(id, scope, filter).root.artifact
fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null): DependencyResult {
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope), filter)
fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null,
repos: List<String> = emptyList()): DependencyResult {
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter)
val result = system.resolveDependencies(session, dependencyRequest)
if (args.downloadSources) {
listOf("sources", "javadoc").forEach {
@ -98,11 +100,12 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
private val system = Booter.newRepositorySystem()
private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus)
private fun createRepo(url: String) = RemoteRepository.Builder(Random().nextInt().toString(), "default", url)
.build()
private val kobaltRepositories: List<RemoteRepository>
get() = Kobalt.repos.map {
RemoteRepository.Builder(null, "default", it.url)
// .setSnapshotPolicy(RepositoryPolicy(false, null, null))
.build().let { repository ->
createRepo(it.url).let { repository ->
val proxyConfigs = settings.proxyConfigs ?: return@map repository
RemoteRepository.Builder(repository).apply {
setProxy(proxyConfigs.getProxy(repository.protocol)?.toAetherProxy())
@ -110,13 +113,14 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
}
}
private fun createCollectRequest(id: String, scope: Scope? = null) = CollectRequest().apply {
private fun createCollectRequest(id: String, scope: Scope? = null, repos: List<String> = emptyList())
= CollectRequest().apply {
val allIds = arrayListOf(MavenId.toMavenId(id))
dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) }
root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope)
repositories = kobaltRepositories
repositories = kobaltRepositories + repos.map { createRepo(it) }
}
private fun createCollectRequest( artifact: DefaultArtifact, scope: Scope? = null) = CollectRequest().apply {

View file

@ -20,6 +20,8 @@ class BuildScriptInfo(val file: File, val fullBuildFile: List<String>, val secti
val includedBuildSourceDirs = arrayListOf<IncludedBuildSourceDir>()
fun addBuildSourceDir(dir: IncludedBuildSourceDir) = includedBuildSourceDirs.add(dir)
fun includedBuildSourceDirsForLine(line: Int): List<String> {
val result = includedBuildSourceDirs.find { it.line == line }?.dirs
return result ?: emptyList()

View file

@ -1,8 +1,11 @@
package com.beust.kobalt.misc
import com.beust.kobalt.Args
import com.beust.kobalt.KobaltException
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.internal.DocUrl
import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.internal.build.VersionCheckTimestampFile
import com.beust.kobalt.maven.Http
import com.beust.kobalt.maven.aether.Exceptions
import com.google.gson.Gson
@ -16,12 +19,15 @@ import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.*
import rx.Observable
import java.io.File
import java.time.Duration
import java.time.Instant
import java.util.*
import java.util.concurrent.Callable
import java.util.concurrent.Future
class GithubApi2 @Inject constructor(
val executors: KobaltExecutors, val localProperties: LocalProperties, val http: Http, val settings:KobaltSettings) {
val executors: KobaltExecutors, val localProperties: LocalProperties, val http: Http,
val settings:KobaltSettings, val args: Args) {
companion object {
const val PROPERTY_ACCESS_TOKEN = "github.accessToken"
@ -109,39 +115,42 @@ class GithubApi2 @Inject constructor(
val latestKobaltVersion: Future<String>
get() {
val callable = Callable<String> {
var result = "0"
val username = localProperties.getNoThrows(PROPERTY_USERNAME, DOC_URL)
val accessToken = localProperties.getNoThrows(PROPERTY_ACCESS_TOKEN, DOC_URL)
try {
val req =
if (username != null && accessToken != null) {
service.getReleases(username, "kobalt", accessToken)
} else {
service.getReleasesNoAuth("cbeust", "kobalt")
}
val ex = req.execute()
val errorBody = ex.errorBody()
if (errorBody != null) {
val jsonError = JsonParser().parse(errorBody.string())
warn("Couldn't call Github.getReleases(): $jsonError")
} else {
val releases = ex.body()
if (releases != null) {
releases.firstOrNull()?.let {
try {
result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
} catch(ex: NoSuchElementException) {
throw KobaltException("Couldn't find the latest release")
var result = Kobalt.version
if (! args.dev && Duration.ofMinutes(10L) >
Duration.between(VersionCheckTimestampFile.timestamp, Instant.now())) {
kobaltLog(2, "Skipping GitHub latest release check, too soon.")
} else {
val username = localProperties.getNoThrows(PROPERTY_USERNAME, DOC_URL)
val accessToken = localProperties.getNoThrows(PROPERTY_ACCESS_TOKEN, DOC_URL)
try {
val req =
if (username != null && accessToken != null) {
service.getReleases(username, "kobalt", accessToken)
} else {
service.getReleasesNoAuth("cbeust", "kobalt")
}
}
val ex = req.execute()
val errorBody = ex.errorBody()
if (errorBody != null) {
val jsonError = JsonParser().parse(errorBody.string())
warn("Couldn't call Github.getReleases(): $jsonError")
} else {
warn("Didn't receive any body in the response to GitHub.getReleases()")
val releases = ex.body()
if (releases != null) {
releases.firstOrNull()?.let {
try {
result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
} catch(ex: NoSuchElementException) {
throw KobaltException("Couldn't find the latest release")
}
}
} else {
warn("Didn't receive any body in the response to GitHub.getReleases()")
}
}
}
} catch(e: Exception) {
kobaltLog(1, "Couldn't retrieve releases from github: " + e.message)
Exceptions.printStackTrace(e)
} catch(e: Exception) {
kobaltLog(1, "Couldn't retrieve releases from github: " + e.message)
Exceptions.printStackTrace(e)
// val error = parseRetrofitError(e)
// val details = if (error.errors != null) {
// error.errors[0]
@ -152,6 +161,7 @@ class GithubApi2 @Inject constructor(
// // using cbeust/kobalt, like above. Right now, just bailing.
// kobaltLog(2, "Couldn't retrieve releases from github, ${error.message ?: e}: "
// + details?.code + " field: " + details?.field)
}
}
result
}