mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
* merge
This commit is contained in:
commit
23bbcd4d84
18 changed files with 174 additions and 124 deletions
|
@ -117,6 +117,7 @@ val kobaltPluginApi = project {
|
||||||
"org.testng:testng:${Versions.testng}"
|
"org.testng:testng:${Versions.testng}"
|
||||||
)
|
)
|
||||||
exclude(*aether("impl", "spi", "util", "api"))
|
exclude(*aether("impl", "spi", "util", "api"))
|
||||||
|
compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,6 +181,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
// "org.glassfish.jersey.media:jersey-media-moxy:${Versions.jersey}",
|
// "org.glassfish.jersey.media:jersey-media-moxy:${Versions.jersey}",
|
||||||
// "org.wasabi:wasabi:0.1.182"
|
// "org.wasabi:wasabi:0.1.182"
|
||||||
)
|
)
|
||||||
|
compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.1")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +190,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
"org.assertj:assertj-core:3.4.1",
|
"org.assertj:assertj-core:3.4.1",
|
||||||
*mavenResolver("util")
|
*mavenResolver("util")
|
||||||
)
|
)
|
||||||
|
compile("org.jetbrains.kotlin:kotlin-test:1.1.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
assemble {
|
assemble {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
kobalt.version=1.0.41
|
kobalt.version=1.0.45
|
|
@ -128,5 +128,9 @@ class Kobalt {
|
||||||
fun addBuildSourceDirs(dirs: Array<out String>) {
|
fun addBuildSourceDirs(dirs: Array<out String>) {
|
||||||
buildSourceDirs.addAll(dirs)
|
buildSourceDirs.addAll(dirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun cleanUp() {
|
||||||
|
buildSourceDirs.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,6 @@ import com.beust.kobalt.api.Dependencies
|
||||||
import com.beust.kobalt.api.IClasspathDependency
|
import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.maven.CompletedFuture
|
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.StringVersion
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
import org.eclipse.aether.artifact.Artifact
|
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()
|
private fun toId(a: Artifact) = a.toString()
|
||||||
|
|
||||||
override val jarFile: Future<File>
|
override val jarFile: Future<File>
|
||||||
get() = if (artifact.file != null) {
|
get() =
|
||||||
|
if (artifact.file != null) {
|
||||||
CompletedFuture(artifact.file)
|
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)
|
|
||||||
} else {
|
} else {
|
||||||
val td = aether.resolve(artifact, null)
|
val td = aether.resolve(artifact, null)
|
||||||
CompletedFuture(td.root.artifact.file)
|
CompletedFuture(td.root.artifact.file)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun toMavenDependencies(scope: String?) : org.apache.maven.model.Dependency {
|
override fun toMavenDependencies(scope: String?) : org.apache.maven.model.Dependency {
|
||||||
val passedScope = scope
|
val passedScope = scope
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.aether.resolution.DependencyRequest
|
||||||
import org.eclipse.aether.resolution.DependencyResult
|
import org.eclipse.aether.resolution.DependencyResult
|
||||||
import org.eclipse.aether.resolution.VersionRangeRequest
|
import org.eclipse.aether.resolution.VersionRangeRequest
|
||||||
import org.eclipse.aether.resolution.VersionRangeResult
|
import org.eclipse.aether.resolution.VersionRangeResult
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
val args: Args,
|
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
|
fun resolveToArtifact(id: String, scope: Scope? = null, filter: DependencyFilter? = null) : Artifact
|
||||||
= resolve(id, scope, filter).root.artifact
|
= resolve(id, scope, filter).root.artifact
|
||||||
|
|
||||||
fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null): DependencyResult {
|
fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null,
|
||||||
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope), filter)
|
repos: List<String> = emptyList()): DependencyResult {
|
||||||
|
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter)
|
||||||
val result = system.resolveDependencies(session, dependencyRequest)
|
val result = system.resolveDependencies(session, dependencyRequest)
|
||||||
if (args.downloadSources) {
|
if (args.downloadSources) {
|
||||||
listOf("sources", "javadoc").forEach {
|
listOf("sources", "javadoc").forEach {
|
||||||
|
@ -98,11 +100,12 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
private val system = Booter.newRepositorySystem()
|
private val system = Booter.newRepositorySystem()
|
||||||
private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus)
|
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>
|
private val kobaltRepositories: List<RemoteRepository>
|
||||||
get() = Kobalt.repos.map {
|
get() = Kobalt.repos.map {
|
||||||
RemoteRepository.Builder(null, "default", it.url)
|
createRepo(it.url).let { repository ->
|
||||||
// .setSnapshotPolicy(RepositoryPolicy(false, null, null))
|
|
||||||
.build().let { repository ->
|
|
||||||
val proxyConfigs = settings.proxyConfigs ?: return@map repository
|
val proxyConfigs = settings.proxyConfigs ?: return@map repository
|
||||||
RemoteRepository.Builder(repository).apply {
|
RemoteRepository.Builder(repository).apply {
|
||||||
setProxy(proxyConfigs.getProxy(repository.protocol)?.toAetherProxy())
|
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))
|
val allIds = arrayListOf(MavenId.toMavenId(id))
|
||||||
|
|
||||||
dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) }
|
dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) }
|
||||||
|
|
||||||
root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), 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 {
|
private fun createCollectRequest( artifact: DefaultArtifact, scope: Scope? = null) = CollectRequest().apply {
|
||||||
|
|
|
@ -20,6 +20,8 @@ class BuildScriptInfo(val file: File, val fullBuildFile: List<String>, val secti
|
||||||
|
|
||||||
val includedBuildSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
val includedBuildSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
||||||
|
|
||||||
|
fun addBuildSourceDir(dir: IncludedBuildSourceDir) = includedBuildSourceDirs.add(dir)
|
||||||
|
|
||||||
fun includedBuildSourceDirsForLine(line: Int): List<String> {
|
fun includedBuildSourceDirsForLine(line: Int): List<String> {
|
||||||
val result = includedBuildSourceDirs.find { it.line == line }?.dirs
|
val result = includedBuildSourceDirs.find { it.line == line }?.dirs
|
||||||
return result ?: emptyList()
|
return result ?: emptyList()
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.KobaltException
|
import com.beust.kobalt.KobaltException
|
||||||
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.internal.DocUrl
|
import com.beust.kobalt.internal.DocUrl
|
||||||
import com.beust.kobalt.internal.KobaltSettings
|
import com.beust.kobalt.internal.KobaltSettings
|
||||||
|
import com.beust.kobalt.internal.build.VersionCheckTimestampFile
|
||||||
import com.beust.kobalt.maven.Http
|
import com.beust.kobalt.maven.Http
|
||||||
import com.beust.kobalt.maven.aether.Exceptions
|
import com.beust.kobalt.maven.aether.Exceptions
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
@ -16,12 +19,15 @@ import retrofit2.converter.gson.GsonConverterFactory
|
||||||
import retrofit2.http.*
|
import retrofit2.http.*
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.time.Duration
|
||||||
|
import java.time.Instant
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.Callable
|
import java.util.concurrent.Callable
|
||||||
import java.util.concurrent.Future
|
import java.util.concurrent.Future
|
||||||
|
|
||||||
class GithubApi2 @Inject constructor(
|
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 {
|
companion object {
|
||||||
const val PROPERTY_ACCESS_TOKEN = "github.accessToken"
|
const val PROPERTY_ACCESS_TOKEN = "github.accessToken"
|
||||||
|
@ -109,8 +115,11 @@ class GithubApi2 @Inject constructor(
|
||||||
val latestKobaltVersion: Future<String>
|
val latestKobaltVersion: Future<String>
|
||||||
get() {
|
get() {
|
||||||
val callable = Callable<String> {
|
val callable = Callable<String> {
|
||||||
var result = "0"
|
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 username = localProperties.getNoThrows(PROPERTY_USERNAME, DOC_URL)
|
||||||
val accessToken = localProperties.getNoThrows(PROPERTY_ACCESS_TOKEN, DOC_URL)
|
val accessToken = localProperties.getNoThrows(PROPERTY_ACCESS_TOKEN, DOC_URL)
|
||||||
try {
|
try {
|
||||||
|
@ -153,6 +162,7 @@ class GithubApi2 @Inject constructor(
|
||||||
// kobaltLog(2, "Couldn't retrieve releases from github, ${error.message ?: e}: "
|
// kobaltLog(2, "Couldn't retrieve releases from github, ${error.message ?: e}: "
|
||||||
// + details?.code + " field: " + details?.field)
|
// + details?.code + " field: " + details?.field)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ private class Main @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = 1
|
var result = 1
|
||||||
|
|
||||||
val latestVersionFuture = github.latestKobaltVersion
|
val latestVersionFuture = github.latestKobaltVersion
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -46,7 +46,8 @@ class Options @Inject constructor(
|
||||||
val buildSources = if (p.isDirectory) BuildSources(p.absoluteFile) else SingleFileBuildSources(p)
|
val buildSources = if (p.isDirectory) BuildSources(p.absoluteFile) else SingleFileBuildSources(p)
|
||||||
var pluginClassLoader = javaClass.classLoader
|
var pluginClassLoader = javaClass.classLoader
|
||||||
|
|
||||||
val allProjects = projectFinder.initForBuildFile(buildSources, args)
|
val allProjectResult = projectFinder.initForBuildFile(buildSources, args)
|
||||||
|
val allProjects = allProjectResult.projects
|
||||||
|
|
||||||
// Modify `args` with options found in buildScript { kobaltOptions(...) }, if any
|
// Modify `args` with options found in buildScript { kobaltOptions(...) }, if any
|
||||||
addOptionsFromBuild(args, Kobalt.optionsFromBuild)
|
addOptionsFromBuild(args, Kobalt.optionsFromBuild)
|
||||||
|
@ -139,6 +140,7 @@ class Options @Inject constructor(
|
||||||
private fun cleanUp() {
|
private fun cleanUp() {
|
||||||
pluginInfo.cleanUp()
|
pluginInfo.cleanUp()
|
||||||
taskManager.cleanUp()
|
taskManager.cleanUp()
|
||||||
|
Kobalt.cleanUp()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addOptionsFromBuild(args: Args, optionsFromBuild: ArrayList<String>) {
|
private fun addOptionsFromBuild(args: Args, optionsFromBuild: ArrayList<String>) {
|
||||||
|
|
|
@ -76,26 +76,14 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS
|
||||||
}
|
}
|
||||||
|
|
||||||
class FindProjectResult(val context: KobaltContext, val projects: List<Project>, val pluginUrls: List<URL>,
|
class FindProjectResult(val context: KobaltContext, val projects: List<Project>, val pluginUrls: List<URL>,
|
||||||
val taskResult: TaskResult)
|
val buildContentRoots: List<String>, val taskResult: TaskResult)
|
||||||
|
|
||||||
private fun findProjects(context: KobaltContext): FindProjectResult {
|
private fun findProjects(context: KobaltContext): FindProjectResult {
|
||||||
val root = buildSources.root
|
val root = buildSources.root
|
||||||
var errorTaskResult: TaskResult? = null
|
var errorTaskResult: TaskResult? = null
|
||||||
val projects = arrayListOf<Project>()
|
val projects = arrayListOf<Project>()
|
||||||
|
|
||||||
// Parse the build files in kobalt/src/*.kt, which will analyze all the buildScriptInfo{} sections
|
// If buildScript.jar was generated by a different version, wipe our temporary build directory
|
||||||
// and possibly add new source build directories. The output of this process is a new Build.kt
|
|
||||||
// file that contains the aggregation of all the build files with the profiles applied and with
|
|
||||||
// the included build files inserted at the correct line.
|
|
||||||
val newBuildKt = buildFiles.parseBuildFiles(root.absolutePath, context)
|
|
||||||
|
|
||||||
//
|
|
||||||
// Save the current build script absolute directory
|
|
||||||
//
|
|
||||||
context.internalContext.absoluteDir = buildSources.root
|
|
||||||
|
|
||||||
// If buildScript.jar was generated by a different version, wipe them it case the API
|
|
||||||
// changed in-between
|
|
||||||
val buildScriptJarDir = KFiles.findBuildScriptDir(root.absolutePath)
|
val buildScriptJarDir = KFiles.findBuildScriptDir(root.absolutePath)
|
||||||
buildScriptJarDir.let { dir ->
|
buildScriptJarDir.let { dir ->
|
||||||
if (! VersionFile.isSameVersionFile(dir)) {
|
if (! VersionFile.isSameVersionFile(dir)) {
|
||||||
|
@ -104,6 +92,18 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse the build files in kobalt/src/*.kt, which will analyze all the buildScriptInfo{} sections
|
||||||
|
// and possibly add new source build directories. The output of this process is a new Build.kt
|
||||||
|
// file that contains the aggregation of all the build files with the profiles applied and with
|
||||||
|
// the included build files inserted at the correct line.
|
||||||
|
val parseResult = buildFiles.parseBuildFiles(root.absolutePath, context)
|
||||||
|
val newBuildKt = parseResult.buildKt
|
||||||
|
|
||||||
|
//
|
||||||
|
// Save the current build script absolute directory
|
||||||
|
//
|
||||||
|
context.internalContext.absoluteDir = buildSources.root
|
||||||
|
|
||||||
val buildScriptJarFile = File(KFiles.findBuildScriptDir(root.absolutePath), SCRIPT_JAR)
|
val buildScriptJarFile = File(KFiles.findBuildScriptDir(root.absolutePath), SCRIPT_JAR)
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -129,7 +129,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS
|
||||||
// Clear the absolute dir
|
// Clear the absolute dir
|
||||||
context.internalContext.absoluteDir = null
|
context.internalContext.absoluteDir = null
|
||||||
|
|
||||||
return FindProjectResult(context, projects, pluginUrls,
|
return FindProjectResult(context, projects, pluginUrls, parseResult.buildSourceDirectories,
|
||||||
if (errorTaskResult != null) errorTaskResult else TaskResult())
|
if (errorTaskResult != null) errorTaskResult else TaskResult())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,13 +40,17 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
|
|
||||||
class BuildFileWithBuildScript(val file: File, val buildScriptInfo: BuildScriptInfo)
|
class BuildFileWithBuildScript(val file: File, val buildScriptInfo: BuildScriptInfo)
|
||||||
|
|
||||||
|
class BuildFileParseResult(val projectRoot: String, val buildKt: File,
|
||||||
|
val buildSourceDirectories: List<String>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the new Build.kt
|
* @return the new Build.kt
|
||||||
*/
|
*/
|
||||||
fun parseBuildFiles(projectDir: String, context: KobaltContext) : File {
|
fun parseBuildFiles(projectDir: String, context: KobaltContext) : BuildFileParseResult {
|
||||||
val profiles = Profiles(context)
|
val profiles = Profiles(context)
|
||||||
val bsiMap = hashMapOf<File, BuildFileWithBuildScript>()
|
val bsiMap = hashMapOf<File, BuildFileWithBuildScript>()
|
||||||
val newSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
val newSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create a map of File -> FileWithBuildScript
|
// Create a map of File -> FileWithBuildScript
|
||||||
//
|
//
|
||||||
|
@ -111,7 +115,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
//
|
//
|
||||||
// Create the big Build.kt out of the imports and code we've found so far
|
// Create the big Build.kt out of the imports and code we've found so far
|
||||||
//
|
//
|
||||||
with(File(KFiles.findBuildScriptDir(projectDir), "Build.kt")) {
|
val newBuildFile = with(File(KFiles.findBuildScriptDir(projectDir), "Build.kt")) {
|
||||||
parentFile.mkdirs()
|
parentFile.mkdirs()
|
||||||
val imp = arrayListOf<String>().apply {
|
val imp = arrayListOf<String>().apply {
|
||||||
addAll(imports)
|
addAll(imports)
|
||||||
|
@ -119,9 +123,12 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
Collections.sort(imp)
|
Collections.sort(imp)
|
||||||
writeText(imp.joinToString("\n"))
|
writeText(imp.joinToString("\n"))
|
||||||
appendText(code.joinToString("\n"))
|
appendText(code.joinToString("\n"))
|
||||||
|
this
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val newDirs = listOf(File(BuildFiles.buildContentRoot(projectDir)).relativeTo(File(projectDir)).path) +
|
||||||
|
newSourceDirs.flatMap{ it.dirs.map { BuildFiles.buildContentRoot(it)} }
|
||||||
|
return BuildFileParseResult(projectDir, newBuildFile, newDirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
class SplitBuildFile(val imports: List<String>, val code: List<String>, val containsProfiles: Boolean)
|
class SplitBuildFile(val imports: List<String>, val code: List<String>, val containsProfiles: Boolean)
|
||||||
|
@ -144,6 +151,10 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
val BUILD_SCRIPT_REGEXP: Pattern = Pattern.compile("^val.*buildScript.*\\{")
|
val BUILD_SCRIPT_REGEXP: Pattern = Pattern.compile("^val.*buildScript.*\\{")
|
||||||
val BLOCK_EXTRACTOR = BlockExtractor(BUILD_SCRIPT_REGEXP, '{', '}')
|
val BLOCK_EXTRACTOR = BlockExtractor(BUILD_SCRIPT_REGEXP, '{', '}')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The content root for a build file module.
|
||||||
|
*/
|
||||||
|
fun buildContentRoot(root: String) = root + File.separatorChar + "kobalt"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parseBuildScriptInfos(projectDir: String, context: KobaltContext, profiles: Profiles)
|
fun parseBuildScriptInfos(projectDir: String, context: KobaltContext, profiles: Profiles)
|
||||||
|
@ -205,7 +216,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
val newDirs = arrayListOf<String>().apply { addAll(Kobalt.buildSourceDirs) }
|
val newDirs = arrayListOf<String>().apply { addAll(Kobalt.buildSourceDirs) }
|
||||||
newDirs.removeAll(currentDirs)
|
newDirs.removeAll(currentDirs)
|
||||||
if (newDirs.any()) {
|
if (newDirs.any()) {
|
||||||
buildScriptInfo.includedBuildSourceDirs.add(IncludedBuildSourceDir(section.start, newDirs))
|
buildScriptInfo.addBuildSourceDir(IncludedBuildSourceDir(section.start, newDirs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +225,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
return analyzedFiles
|
return analyzedFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sourceDir(root: String) = File(KFiles.joinDir(root, "kobalt", "src"))
|
private fun sourceDir(root: String) = File(KFiles.joinDir(buildContentRoot(root), "src"))
|
||||||
|
|
||||||
private fun findFiles(file: File, accept: (File) -> Boolean) : List<File> {
|
private fun findFiles(file: File, accept: (File) -> Boolean) : List<File> {
|
||||||
val result = arrayListOf<File>()
|
val result = arrayListOf<File>()
|
||||||
|
@ -231,6 +242,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findBuildSourceFiles(root: String) : List<File> {
|
private fun findBuildSourceFiles(root: String) : List<File> {
|
||||||
val result = arrayListOf<File>()
|
val result = arrayListOf<File>()
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.internal.build.BuildSources
|
|
||||||
import com.beust.kobalt.internal.build.IBuildSources
|
import com.beust.kobalt.internal.build.IBuildSources
|
||||||
import com.beust.kobalt.misc.kobaltLog
|
import com.beust.kobalt.misc.kobaltLog
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
@ -16,7 +15,7 @@ import java.util.*
|
||||||
class ProjectFinder @Inject constructor(val buildFileCompilerFactory: BuildFileCompiler.IFactory,
|
class ProjectFinder @Inject constructor(val buildFileCompilerFactory: BuildFileCompiler.IFactory,
|
||||||
val pluginInfo: PluginInfo, val plugins: Plugins) {
|
val pluginInfo: PluginInfo, val plugins: Plugins) {
|
||||||
|
|
||||||
fun initForBuildFile(buildSources: IBuildSources, args: Args): List<Project> {
|
fun initForBuildFile(buildSources: IBuildSources, args: Args): BuildFileCompiler.FindProjectResult {
|
||||||
val findProjectResult = buildFileCompilerFactory.create(buildSources, pluginInfo)
|
val findProjectResult = buildFileCompilerFactory.create(buildSources, pluginInfo)
|
||||||
.compileBuildFiles(args)
|
.compileBuildFiles(args)
|
||||||
if (! findProjectResult.taskResult.success) {
|
if (! findProjectResult.taskResult.success) {
|
||||||
|
@ -49,7 +48,7 @@ class ProjectFinder @Inject constructor(val buildFileCompilerFactory: BuildFileC
|
||||||
//
|
//
|
||||||
plugins.applyPlugins(Kobalt.context!!, allProjects)
|
plugins.applyPlugins(Kobalt.context!!, allProjects)
|
||||||
|
|
||||||
return allProjects
|
return findProjectResult
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runClasspathInterceptors(allProjects: List<Project>) {
|
private fun runClasspathInterceptors(allProjects: List<Project>) {
|
||||||
|
|
|
@ -21,7 +21,8 @@ class UpdateKobalt @Inject constructor(val github: GithubApi2, val wrapperProper
|
||||||
val newVersion = github.latestKobaltVersion
|
val newVersion = github.latestKobaltVersion
|
||||||
wrapperProperties.create(newVersion.get())
|
wrapperProperties.create(newVersion.get())
|
||||||
VersionCheckTimestampFile.updateTimestamp(Instant.now())
|
VersionCheckTimestampFile.updateTimestamp(Instant.now())
|
||||||
Main.main(arrayOf())
|
val args = if (KobaltLogger.isQuiet) { arrayOf("--log", "0") } else { arrayOf() }
|
||||||
|
Main.main(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,8 +22,9 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
// so I have to do dependency injections manually :-(
|
// so I have to do dependency injections manually :-(
|
||||||
val projectFinder = Kobalt.INJECTOR.getInstance(ProjectFinder::class.java)
|
val projectFinder = Kobalt.INJECTOR.getInstance(ProjectFinder::class.java)
|
||||||
|
|
||||||
|
// URL parameters sent by the client
|
||||||
val PARAMETER_PROJECT_ROOT = "projectRoot"
|
val PARAMETER_PROJECT_ROOT = "projectRoot"
|
||||||
val PARAMETER_BUILD_FILE = "buildFile"
|
val PARAMETER_BUILD_FILE = "buildFile" // Deprecated
|
||||||
val PARAMETER_PROFILES = "profiles"
|
val PARAMETER_PROFILES = "profiles"
|
||||||
val PARAMETER_DOWNLOAD_SOURCES = "downloadSources"
|
val PARAMETER_DOWNLOAD_SOURCES = "downloadSources"
|
||||||
|
|
||||||
|
@ -40,8 +41,9 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
|
|
||||||
fun <T> sendWebsocketCommand(endpoint: RemoteEndpoint, commandName: String, payload: T,
|
fun <T> sendWebsocketCommand(endpoint: RemoteEndpoint, commandName: String, payload: T,
|
||||||
errorMessage: String? = null) {
|
errorMessage: String? = null) {
|
||||||
endpoint.sendString(Gson().toJson(WebSocketCommand(commandName, payload = Gson().toJson(payload),
|
val json = Gson().toJson(WebSocketCommand(commandName, payload = Gson().toJson(payload),
|
||||||
errorMessage = errorMessage)))
|
errorMessage = errorMessage))
|
||||||
|
endpoint.sendString(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findProfiles(map: Map<String, List<String>>) = map[PARAMETER_PROFILES]?.getOrNull(0)
|
private fun findProfiles(map: Map<String, List<String>>) = map[PARAMETER_PROFILES]?.getOrNull(0)
|
||||||
|
@ -63,8 +65,9 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
|
|
||||||
override fun onWebSocketConnect(s: Session) {
|
override fun onWebSocketConnect(s: Session) {
|
||||||
session = s
|
session = s
|
||||||
val buildSources = findBuildFile(s.upgradeRequest.parameterMap)
|
val parameterMap = s.upgradeRequest.parameterMap
|
||||||
val profiles = findProfiles(s.upgradeRequest.parameterMap)
|
val buildSources = findBuildFile(parameterMap)
|
||||||
|
val profiles = findProfiles(parameterMap)
|
||||||
val downloadSources = findDownloadSources(s.upgradeRequest.parameterMap)
|
val downloadSources = findDownloadSources(s.upgradeRequest.parameterMap)
|
||||||
|
|
||||||
fun <T> getInstance(cls: Class<T>) : T = Kobalt.INJECTOR.getInstance(cls)
|
fun <T> getInstance(cls: Class<T>) : T = Kobalt.INJECTOR.getInstance(cls)
|
||||||
|
@ -89,12 +92,13 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
try {
|
try {
|
||||||
val dependencyData = getInstance(RemoteDependencyData::class.java)
|
val dependencyData = getInstance(RemoteDependencyData::class.java)
|
||||||
val args = getInstance(Args::class.java)
|
val args = getInstance(Args::class.java)
|
||||||
|
args.buildFile = buildSources.root.absolutePath
|
||||||
args.profiles = profiles
|
args.profiles = profiles
|
||||||
args.downloadSources = downloadSources
|
args.downloadSources = downloadSources
|
||||||
|
|
||||||
val allProjects = projectFinder.initForBuildFile(buildSources, args)
|
val projectResults = projectFinder.initForBuildFile(buildSources, args)
|
||||||
|
|
||||||
dependencyData.dependenciesDataFor(buildSources, args, object : IProgressListener {
|
dependencyData.dependenciesDataFor(buildSources, args, projectResults, object : IProgressListener {
|
||||||
override fun onProgress(progress: Int?, message: String?) {
|
override fun onProgress(progress: Int?, message: String?) {
|
||||||
sendWebsocketCommand(s.remote, ProgressCommand.NAME, ProgressCommand(progress, message))
|
sendWebsocketCommand(s.remote, ProgressCommand.NAME, ProgressCommand(progress, message))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
package com.beust.kobalt.app.remote
|
package com.beust.kobalt.app.remote
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
|
||||||
import com.beust.kobalt.api.Kobalt
|
|
||||||
import com.beust.kobalt.app.MainModule
|
|
||||||
import com.beust.kobalt.homeDir
|
|
||||||
import com.beust.kobalt.internal.KobaltSettings
|
|
||||||
import com.beust.kobalt.internal.build.BuildSources
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
//enum class Command(val n: Int, val command: ICommand) {
|
//enum class Command(val n: Int, val command: ICommand) {
|
||||||
// GET_DEPENDENCIES(1, Kobalt.INJECTOR.getInstance(GetDependenciesCommand::class.java)),
|
// GET_DEPENDENCIES(1, Kobalt.INJECTOR.getInstance(GetDependenciesCommand::class.java)),
|
||||||
// GET_DEPENDENCIES_GRAPH(2, Kobalt.INJECTOR.getInstance(GetDependenciesGraphCommand::class.java));
|
// GET_DEPENDENCIES_GRAPH(2, Kobalt.INJECTOR.getInstance(GetDependenciesGraphCommand::class.java));
|
||||||
|
@ -18,29 +9,29 @@ import java.io.File
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
class KobaltHub(val dependencyData: RemoteDependencyData) {
|
//class KobaltHub(val dependencyData: RemoteDependencyData) {
|
||||||
val args = Args()
|
// val args = Args()
|
||||||
|
//
|
||||||
fun runCommand(n: Int) : String {
|
// fun runCommand(n: Int) : String {
|
||||||
val buildSources = BuildSources(File(homeDir("kotlin/klaxon")))
|
// val buildSources = BuildSources(File(homeDir("kotlin/klaxon")))
|
||||||
val data =
|
// val data =
|
||||||
when(n) {
|
// when(n) {
|
||||||
1 -> Gson().toJson(
|
// 1 -> Gson().toJson(
|
||||||
dependencyData.dependenciesDataFor(buildSources, args))
|
// dependencyData.dependenciesDataFor(buildSources, args))
|
||||||
2 -> Gson().toJson(
|
// 2 -> Gson().toJson(
|
||||||
dependencyData.dependenciesDataFor(buildSources, args,
|
// dependencyData.dependenciesDataFor(buildSources, args,
|
||||||
useGraph = true))
|
// useGraph = true))
|
||||||
else -> throw RuntimeException("Unknown command")
|
// else -> throw RuntimeException("Unknown command")
|
||||||
}
|
// }
|
||||||
println("Data: $data")
|
// println("Data: $data")
|
||||||
return data
|
// return data
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
fun main(argv: Array<String>) {
|
//fun main(argv: Array<String>) {
|
||||||
Kobalt.init(MainModule(Args(), KobaltSettings.readSettingsXml()))
|
// Kobalt.init(MainModule(Args(), KobaltSettings.readSettingsXml()))
|
||||||
val dependencyData = Kobalt.INJECTOR.getInstance(RemoteDependencyData::class.java)
|
// val dependencyData = Kobalt.INJECTOR.getInstance(RemoteDependencyData::class.java)
|
||||||
val json = KobaltHub(dependencyData).runCommand(1)
|
// val json = KobaltHub(dependencyData).runCommand(1)
|
||||||
val dd = Gson().fromJson(json, RemoteDependencyData.GetDependenciesData::class.java)
|
// val dd = Gson().fromJson(json, RemoteDependencyData.GetDependenciesData::class.java)
|
||||||
println("Data2: $dd")
|
// println("Data2: $dd")
|
||||||
}
|
//}
|
||||||
|
|
|
@ -4,10 +4,16 @@ import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.api.IClasspathDependency
|
import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.app.BuildFileCompiler
|
import com.beust.kobalt.app.BuildFileCompiler
|
||||||
import com.beust.kobalt.internal.*
|
import com.beust.kobalt.internal.DynamicGraph
|
||||||
|
import com.beust.kobalt.internal.GraphUtil
|
||||||
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
|
import com.beust.kobalt.internal.TaskManager
|
||||||
import com.beust.kobalt.internal.build.BuildSources
|
import com.beust.kobalt.internal.build.BuildSources
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.misc.*
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
|
import com.beust.kobalt.misc.StringVersion
|
||||||
|
import com.beust.kobalt.misc.log
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
@ -22,7 +28,9 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v
|
||||||
val buildFileCompilerFactory: BuildFileCompiler.IFactory, val pluginInfo: PluginInfo,
|
val buildFileCompilerFactory: BuildFileCompiler.IFactory, val pluginInfo: PluginInfo,
|
||||||
val taskManager: TaskManager) {
|
val taskManager: TaskManager) {
|
||||||
|
|
||||||
fun dependenciesDataFor(buildSources: BuildSources, args: Args, progressListener: IProgressListener? = null,
|
fun dependenciesDataFor(buildSources: BuildSources, args: Args,
|
||||||
|
findProjectResult: BuildFileCompiler.FindProjectResult,
|
||||||
|
progressListener: IProgressListener? = null,
|
||||||
useGraph : Boolean = false): GetDependenciesData {
|
useGraph : Boolean = false): GetDependenciesData {
|
||||||
val projectDatas = arrayListOf<ProjectData>()
|
val projectDatas = arrayListOf<ProjectData>()
|
||||||
|
|
||||||
|
@ -168,7 +176,7 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetDependenciesData(projectDatas, allTasks, pluginDependencies,
|
return GetDependenciesData(projectDatas, allTasks, pluginDependencies, findProjectResult.buildContentRoots,
|
||||||
projectResult.taskResult.errorMessage)
|
projectResult.taskResult.errorMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +202,7 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v
|
||||||
class GetDependenciesData(val projects: List<ProjectData> = emptyList(),
|
class GetDependenciesData(val projects: List<ProjectData> = emptyList(),
|
||||||
val allTasks: Collection<TaskData> = emptySet(),
|
val allTasks: Collection<TaskData> = emptySet(),
|
||||||
val pluginDependencies: List<DependencyData> = emptyList(),
|
val pluginDependencies: List<DependencyData> = emptyList(),
|
||||||
|
val buildContentRoots: List<String> = emptyList(),
|
||||||
val errorMessage: String?) {
|
val errorMessage: String?) {
|
||||||
companion object {
|
companion object {
|
||||||
val NAME = "GetDependencies"
|
val NAME = "GetDependencies"
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
kobalt.version=1.0.41
|
kobalt.version=1.0.45
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.aether.graph.Dependency
|
||||||
import org.eclipse.aether.repository.RemoteRepository
|
import org.eclipse.aether.repository.RemoteRepository
|
||||||
import org.eclipse.aether.resolution.ArtifactResult
|
import org.eclipse.aether.resolution.ArtifactResult
|
||||||
import org.eclipse.aether.resolution.DependencyRequest
|
import org.eclipse.aether.resolution.DependencyRequest
|
||||||
|
import org.eclipse.aether.resolution.DependencyResolutionException
|
||||||
import org.testng.annotations.DataProvider
|
import org.testng.annotations.DataProvider
|
||||||
import org.testng.annotations.Guice
|
import org.testng.annotations.Guice
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
@ -68,6 +69,21 @@ class MavenResolverTest {
|
||||||
assertThat(closure.none { it.toString().contains("android") })
|
assertThat(closure.none { it.toString().contains("android") })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldResolveSnapshots() {
|
||||||
|
try {
|
||||||
|
// Should throw
|
||||||
|
resolver.resolve("org.bukkit:bukkit:1.11.2-R0.1-SNAPSHOT")
|
||||||
|
} catch(ex: DependencyResolutionException) {
|
||||||
|
// Success. Note: run the failing test first, because once the resolve succeeds, its
|
||||||
|
// results are cached in the local repo.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should succeed
|
||||||
|
resolver.resolve("org.bukkit:bukkit:1.11.2-R0.1-SNAPSHOT",
|
||||||
|
repos = listOf("https://hub.spigotmc.org/nexus/content/repositories/snapshots"))
|
||||||
|
}
|
||||||
|
|
||||||
private fun resolve(id: String): List<ArtifactResult> {
|
private fun resolve(id: String): List<ArtifactResult> {
|
||||||
val system = Booter.newRepositorySystem()
|
val system = Booter.newRepositorySystem()
|
||||||
val session = Booter.newRepositorySystemSession(system,
|
val session = Booter.newRepositorySystemSession(system,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue