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

Merge branch 'master' of github.com:cbeust/kobalt

This commit is contained in:
Cedric Beust 2015-12-12 23:03:26 -08:00
commit 8be4fa009a
14 changed files with 63 additions and 31 deletions

3
.idea/modules.xml generated
View file

@ -2,8 +2,9 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/kobalt/Build.kt.iml" filepath="$PROJECT_DIR$/kobalt/Build.kt.iml" />
<module fileurl="file://$PROJECT_DIR$/kobalt.iml" filepath="$PROJECT_DIR$/kobalt.iml" /> <module fileurl="file://$PROJECT_DIR$/kobalt.iml" filepath="$PROJECT_DIR$/kobalt.iml" />
<module fileurl="file://$PROJECT_DIR$/modules/wrapper/wrapper.iml" filepath="$PROJECT_DIR$/modules/wrapper/wrapper.iml" /> <module fileurl="file://$PROJECT_DIR$/modules/wrapper/wrapper.iml" filepath="$PROJECT_DIR$/modules/wrapper/wrapper.iml" />
</modules> </modules>
</component> </component>
</project> </project>

13
kobalt/Build.kt.iml Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file:///Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kobalt.jar" level="project" />
</component>
</module>

View file

@ -1 +1 @@
kobalt.version=0.329 kobalt.version=0.334

View file

@ -1 +1,2 @@
#!/usr/bin/env bash
java -jar $(dirname $0)/kobalt/wrapper/kobalt-wrapper.jar $* java -jar $(dirname $0)/kobalt/wrapper/kobalt-wrapper.jar $*

View file

@ -85,11 +85,13 @@ class AsciiArt {
const val WHITE = "\u001B[37m" const val WHITE = "\u001B[37m"
private fun wrap(s: String, color: String) = color + s + RESET private fun wrap(s: String, color: String) = color + s + RESET
private fun blue(s: String) = wrap(s, BLUE)
private fun red(s: String) = wrap(s, RED) private fun red(s: String) = wrap(s, RED)
private fun yellow(s: String) = wrap(s, YELLOW) private fun yellow(s: String) = wrap(s, YELLOW)
fun taskColor(s: String) = yellow(s) fun taskColor(s: String) = s
fun errorColor(s: String) = red(s) fun errorColor(s: String) = red(s)
fun warnColor(s: String) = red(s)
} }
} }

View file

@ -5,7 +5,6 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.maven.DepFactory import com.beust.kobalt.maven.DepFactory
import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.maven.dependency.FileDependency
import com.beust.kobalt.misc.KobaltExecutors
import java.io.File import java.io.File
@Directive @Directive
@ -17,15 +16,14 @@ fun file(file: String) : String = FileDependency.PREFIX_FILE + file
@Directive @Directive
fun plugins(vararg dependency : IClasspathDependency) { fun plugins(vararg dependency : IClasspathDependency) {
Plugins.dynamicPlugins.addAll(dependency) dependency.forEach { Plugins.addDynamicPlugin(it) }
} }
@Directive @Directive
fun plugins(vararg dependencies : String) { fun plugins(vararg dependencies : String) {
val executor = Kobalt.INJECTOR.getInstance(KobaltExecutors::class.java).miscExecutor
val factory = Kobalt.INJECTOR.getInstance(DepFactory::class.java) val factory = Kobalt.INJECTOR.getInstance(DepFactory::class.java)
dependencies.forEach { dependencies.forEach {
Plugins.dynamicPlugins.add(factory.create(it, executor)) Plugins.addDynamicPlugin(factory.create(it))
} }
} }

View file

@ -0,0 +1,6 @@
package com.beust.kobalt
object Constants {
val BUILD_FILE_NAME = "Build.kt"
val BUILD_FILE_DIRECTORY = "kobalt/src"
}

View file

@ -251,17 +251,16 @@ private class Main @Inject constructor(
return result return result
} }
private fun findBuildFile(): File { private fun findBuildFile() : File {
val files = arrayListOf("Build.kt", "build.kobalt", KFiles.src("build.kobalt"), val deprecatedLocation = File(Constants.BUILD_FILE_NAME)
KFiles.src("Build.kt")) val result: File =
try { if (deprecatedLocation.exists()) {
return files.map { warn(Constants.BUILD_FILE_NAME + " is in a deprecated location, please move it to "
File(SystemProperties.currentDir, it) + Constants.BUILD_FILE_DIRECTORY)
}.first { deprecatedLocation
it.exists() } else {
File(KFiles.joinDir(Constants.BUILD_FILE_DIRECTORY, Constants.BUILD_FILE_NAME))
} }
} catch(ex: NoSuchElementException) { return result
return File("Build.kt")
}
} }
} }

View file

@ -41,7 +41,8 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider<Tas
/** /**
* The list of plugins found in the build file. * The list of plugins found in the build file.
*/ */
val dynamicPlugins : ArrayList<IClasspathDependency> = arrayListOf() internal val dynamicPlugins : ArrayList<IClasspathDependency> = arrayListOf()
fun addDynamicPlugin(plugin: IClasspathDependency) = dynamicPlugins.add(plugin)
val defaultPlugin : IPlugin get() = findPlugin(KobaltPlugin.PLUGIN_NAME)!! val defaultPlugin : IPlugin get() = findPlugin(KobaltPlugin.PLUGIN_NAME)!!

View file

@ -1,6 +1,7 @@
package com.beust.kobalt.internal.build package com.beust.kobalt.internal.build
import com.beust.kobalt.Args import com.beust.kobalt.Args
import com.beust.kobalt.Constants
import com.beust.kobalt.KobaltException import com.beust.kobalt.KobaltException
import com.beust.kobalt.Plugins import com.beust.kobalt.Plugins
import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Kobalt
@ -55,11 +56,14 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
return allProjects return allProjects
} }
val parsedBuildFiles = arrayListOf<ParsedBuildFile>()
private fun findProjects(context: KobaltContext): List<Project> { private fun findProjects(context: KobaltContext): List<Project> {
val result = arrayListOf<Project>() val result = arrayListOf<Project>()
buildFiles.forEach { buildFile -> buildFiles.forEach { buildFile ->
val processBuildFile = parseBuildFile(context, buildFile) val parsedBuildFile = parseBuildFile(context, buildFile)
val pluginUrls = processBuildFile.pluginUrls parsedBuildFiles.add(parsedBuildFile)
val pluginUrls = parsedBuildFile.pluginUrls
val buildScriptJarFile = File(KFiles.findBuildScriptLocation(buildFile, SCRIPT_JAR)) val buildScriptJarFile = File(KFiles.findBuildScriptLocation(buildFile, SCRIPT_JAR))
// If the script jar files were generated by a different version, wipe them in case the API // If the script jar files were generated by a different version, wipe them in case the API
@ -74,8 +78,9 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
// Write the modified Build.kt (e.g. maybe profiles were applied) to a temporary file, // Write the modified Build.kt (e.g. maybe profiles were applied) to a temporary file,
// compile it, jar it in buildScript.jar and run it // compile it, jar it in buildScript.jar and run it
val modifiedBuildFile = KFiles.createTempFile(".kt") val modifiedBuildFile = KFiles.createTempFile(".kt")
KFiles.saveFile(modifiedBuildFile, processBuildFile.buildScriptCode) KFiles.saveFile(modifiedBuildFile, parsedBuildFile.buildScriptCode)
maybeCompileBuildFile(context, BuildFile(Paths.get(modifiedBuildFile.path), "Modified Build.kt"), maybeCompileBuildFile(context, BuildFile(Paths.get(modifiedBuildFile.path),
"Modified ${Constants.BUILD_FILE_NAME}"),
buildScriptJarFile, pluginUrls) buildScriptJarFile, pluginUrls)
val projects = buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context) val projects = buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context)
result.addAll(projects) result.addAll(projects)

View file

@ -1,12 +1,14 @@
package com.beust.kobalt.internal.remote package com.beust.kobalt.internal.remote
import com.beust.kobalt.Args import com.beust.kobalt.Args
import com.beust.kobalt.Constants
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.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.internal.build.BuildFileCompiler import com.beust.kobalt.internal.build.BuildFileCompiler
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.MavenDependency import com.beust.kobalt.maven.dependency.MavenDependency
import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
@ -14,6 +16,7 @@ import com.google.gson.Gson
import com.google.gson.JsonObject import com.google.gson.JsonObject
import java.io.PrintWriter import java.io.PrintWriter
import java.net.Socket import java.net.Socket
import java.net.URL
import java.nio.file.Paths import java.nio.file.Paths
import javax.inject.Inject import javax.inject.Inject
@ -29,12 +32,12 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
override val name = "getDependencies" override val name = "getDependencies"
override fun run(sender: ICommandSender, received: JsonObject) { override fun run(sender: ICommandSender, received: JsonObject) {
val buildFile = BuildFile(Paths.get(received.get("buildFile").asString), "GetDependenciesCommand") val buildFile = BuildFile(Paths.get(received.get("buildFile").asString), "GetDependenciesCommand")
val scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo) val buildFileCompiler = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo)
val projects = scriptCompiler.compileBuildFiles(args) val projects = buildFileCompiler.compileBuildFiles(args)
sender.sendData(toData(projects)) sender.sendData(toData(projects, buildFileCompiler.parsedBuildFiles.flatMap { it.pluginUrls }))
} }
private fun toData(projects: List<Project>) : CommandData { private fun toData(projects: List<Project>, pluginUrls: List<URL>) : CommandData {
val projectDatas = arrayListOf<ProjectData>() val projectDatas = arrayListOf<ProjectData>()
val executor = executors.miscExecutor val executor = executors.miscExecutor
@ -45,8 +48,10 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
fun allDeps(l: List<IClasspathDependency>) = dependencyManager.transitiveClosure(l) fun allDeps(l: List<IClasspathDependency>) = dependencyManager.transitiveClosure(l)
val pluginDependencies = pluginUrls.map { java.io.File(it.toURI()) }.map { FileDependency(it.absolutePath) }
projects.forEach { project -> projects.forEach { project ->
val allDependencies = val allDependencies =
pluginDependencies.map { toDependencyData(it, "compile")} +
allDeps(project.compileDependencies).map { toDependencyData(it, "compile") } + allDeps(project.compileDependencies).map { toDependencyData(it, "compile") } +
allDeps(project.compileProvidedDependencies).map { toDependencyData(it, "provided") } + allDeps(project.compileProvidedDependencies).map { toDependencyData(it, "provided") } +
allDeps(project.compileRuntimeDependencies).map { toDependencyData(it, "runtime") } + allDeps(project.compileRuntimeDependencies).map { toDependencyData(it, "runtime") } +
@ -75,6 +80,7 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
fun main(argv: Array<String>) { fun main(argv: Array<String>) {
val socket = Socket("localhost", 1234) val socket = Socket("localhost", 1234)
(PrintWriter(socket.outputStream, true)).use { out -> (PrintWriter(socket.outputStream, true)).use { out ->
out.println("""{ "name" : "getDependencies", "buildFile": "/c/users/cbeust/kotlin/kobalt/kobalt/src/Build.kt" }""") out.println("""{ "name" : "getDependencies", "buildFile":
"/Users/beust/kotlin/kobalt/kobalt/src/${Constants.BUILD_FILE_NAME}"}""")
} }
} }

View file

@ -75,7 +75,7 @@ class Logger(val dev: Boolean) {
final fun warn(tag: String, message: String, e: Throwable? = null) { final fun warn(tag: String, message: String, e: Throwable? = null) {
val fullMessage = "***** WARNING " + (e?.message ?: message) val fullMessage = "***** WARNING " + (e?.message ?: message)
println(getPattern("W", fullMessage, fullMessage, tag)) println(AsciiArt.Companion.warnColor(getPattern("W", fullMessage, fullMessage, tag)))
} }
final fun log(tag: String, message: String, newLine: Boolean) = final fun log(tag: String, message: String, newLine: Boolean) =

View file

@ -109,7 +109,7 @@ public class JarUtils {
while (enumEntries.hasMoreElements()) { while (enumEntries.hasMoreElements()) {
val file = enumEntries.nextElement() val file = enumEntries.nextElement()
if (file.name == fileName) { if (file.name == fileName) {
log(2, "Found $fileName in $zip") log(2, "Found $fileName in ${zip.name}")
zip.getInputStream(file).use { ins -> zip.getInputStream(file).use { ins ->
return CharStreams.toString(InputStreamReader(ins, "UTF-8")) return CharStreams.toString(InputStreamReader(ins, "UTF-8"))
} }

View file

@ -1 +1 @@
kobalt.version=0.329 kobalt.version=0.334