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-17 18:37:26 -08:00
commit 8acd8b8fce
133 changed files with 861 additions and 125 deletions

4
.gitignore vendored
View file

@ -9,4 +9,6 @@ local.properties
classes
libs
.kobalt/
build/
./build/
out
.DS_Store

3
.idea/modules.xml generated
View file

@ -4,7 +4,8 @@
<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$/modules/wrapper/wrapper.iml" filepath="$PROJECT_DIR$/modules/wrapper/wrapper.iml" />
<module fileurl="file://$PROJECT_DIR$/modules/kobalt-plugin-api/kobalt-plugin-api.iml" filepath="$PROJECT_DIR$/modules/kobalt-plugin-api/kobalt-plugin-api.iml" />
<module fileurl="file://$PROJECT_DIR$/modules/wrapper/kobalt-wrapper.iml" filepath="$PROJECT_DIR$/modules/wrapper/kobalt-wrapper.iml" />
</modules>
</component>
</project>

View file

@ -1,23 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="kobalt" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="0.121" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<module external.linked.project.id="kobalt" external.linked.project.path="$USER_HOME$" external.root.project.path="$USER_HOME$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="0.121" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="wrapper" />
<orderEntry type="library" scope="TEST" name="kobalt (Test)" level="project" />
<orderEntry type="library" name="kobalt (Compile)" level="project" />
<orderEntry type="library" scope="TEST" name="kobalt (Test)" level="project" />
<orderEntry type="module" module-name="kobalt-plugin-api" />
<orderEntry type="module" module-name="kobalt-wrapper" />
</component>
</module>

View file

@ -1,14 +1,19 @@
import com.beust.kobalt.*
import com.beust.kobalt.api.*
import com.beust.kobalt.TaskResult
import com.beust.kobalt.api.License
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.Scm
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.homeDir
import com.beust.kobalt.plugin.application.application
import com.beust.kobalt.plugin.java.*
import com.beust.kobalt.plugin.kotlin.*
import com.beust.kobalt.plugin.java.javaCompiler
import com.beust.kobalt.plugin.java.javaProject
import com.beust.kobalt.plugin.kotlin.kotlinCompiler
import com.beust.kobalt.plugin.kotlin.kotlinProject
import com.beust.kobalt.plugin.packaging.assemble
import com.beust.kobalt.plugin.publish.github
import com.beust.kobalt.plugin.publish.jcenter
import com.beust.kobalt.plugin.retrolambda.*
import com.beust.kobalt.repos
import com.beust.kobalt.test
import java.io.File
import java.nio.file.Files
@ -35,25 +40,18 @@ val wrapper = javaProject {
}
}
// retrolambda {
// }
productFlavor("dev") {
}
buildType("debug") {
}
application {
mainClass = "com.beust.kobalt.wrapper.Main"
}
}
val kobalt = kotlinProject(wrapper) {
name = "kobalt"
val kobaltPluginApi = kotlinProject {
name = "kobalt-plugin-api"
group = "com.beust"
artifactId = name
version = readVersion()
directory = "modules/kobalt-plugin-api"
description = "A build system in Kotlin"
url = "http://beust.com/kobalt"
licenses = arrayListOf(License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0"))
@ -66,30 +64,78 @@ val kobalt = kotlinProject(wrapper) {
}
dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib:1.0.0-beta-3595",
"org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.0-beta-3595",
"org.jetbrains.dokka:dokka-fatjar:0.9.3",
"org.jetbrains.kotlinx:kotlinx.dom:0.0.4",
compile("org.jetbrains.kotlinx:kotlinx.dom:0.0.4",
"com.android.tools.build:builder:2.0.0-alpha3",
"com.beust:jcommander:1.48",
"com.squareup.okhttp:okhttp:2.5.0",
"org.jsoup:jsoup:1.8.3",
"com.squareup.okio:okio:1.6.0",
"com.google.inject:guice:4.0",
"com.google.inject.extensions:guice-assistedinject:4.0",
"javax.inject:javax.inject:1",
"com.google.guava:guava:19.0-rc2",
"org.apache.maven:maven-model:3.3.3",
"com.github.spullara.mustache.java:compiler:0.9.1",
"io.reactivex:rxjava:1.0.16",
"com.google.code.gson:gson:2.4",
"com.squareup.retrofit:retrofit:1.9.0",
"com.squareup.okio:okio:1.6.0"
"com.beust:jcommander:1.48"
)
}
assemble {
mavenJars {
fatJar = true
manifest {
attributes("Main-Class", "com.beust.kobalt.MainKt")
}
}
}
// install {
// libDir = "lib-test"
// }
test {
args("-log", "1", "src/test/resources/testng.xml")
}
kotlinCompiler {
args("-nowarn")
}
jcenter {
publish = true
}
}
val kobaltApp = kotlinProject(kobaltPluginApi, wrapper) {
name = "kobalt"
group = "com.beust"
artifactId = name
version = readVersion()
dependencies {
// Used by the plugins
compile("com.android.tools.build:builder:2.0.0-alpha3",
"org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.0-beta-3595",
"org.jetbrains.dokka:dokka-fatjar:0.9.3")
// Used by the main app
compile("com.github.spullara.mustache.java:compiler:0.9.1",
"com.squareup.okhttp:okhttp:2.5.0",
"javax.inject:javax.inject:1",
"com.google.inject:guice:4.0",
"com.google.inject.extensions:guice-assistedinject:4.0",
"com.beust:jcommander:1.48",
"com.squareup.retrofit:retrofit:1.9.0",
"org.apache.maven:maven-model:3.3.3",
"org.codehaus.plexus:plexus-utils:3.0.22")
}
dependenciesTest {
compile("org.testng:testng:6.9.9")
}
assemble {
mavenJars {
fatJar = true
@ -106,33 +152,17 @@ val kobalt = kotlinProject(wrapper) {
}
}
// install {
// libDir = "lib-test"
// }
test {
args("-log", "1", "src/test/resources/testng.xml")
}
kotlinCompiler {
args("-nowarn")
}
// dokka {
// outputFormat = "markdown"
// }
//
// dokka {
// outputFormat = "html"
// }
jcenter {
publish = true
}
github {
file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip")
}
jcenter {
publish = true
}
}
fun readVersion() : String {

View file

@ -1 +1 @@
kobalt.version=0.341
kobalt.version=0.346

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kobalt (Compile)" level="project" />
<orderEntry type="library" name="kobalt-plugin-api (Compile)" level="project" />
<orderEntry type="library" scope="TEST" name="kobalt-plugin-api (Test)" level="project" />
</component>
</module>

View file

@ -1,6 +1,7 @@
package com.beust.kobalt
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.MavenId
import com.beust.kobalt.maven.RepoFinder
import com.beust.kobalt.maven.SimpleDep
@ -13,7 +14,7 @@ import java.util.*
/**
* Display information about a Maven id.
*/
class ResolveDependency @Inject constructor(val repoFinder: RepoFinder) {
class ResolveDependency @Inject constructor(val repoFinder: RepoFinder, val localRepo: LocalRepo) {
val increment = 8
val leftFirst = "\u2558"
val leftMiddle = "\u255f"
@ -35,7 +36,8 @@ class ResolveDependency @Inject constructor(val repoFinder: RepoFinder) {
val simpleDep = SimpleDep(MavenId.create(id))
val url = repoResult.hostConfig.url + simpleDep.toJarFile(repoResult)
AsciiArt.logBox(listOf(id, url).map { " $it" }, {s -> println(s) })
val localFile = localRepo.toFullPath(simpleDep.toJarFile(repoResult))
AsciiArt.logBox(listOf(id, url, localFile).map { " $it" }, {s -> println(s) })
display(root.children)
println("")

View file

@ -3,10 +3,7 @@ package com.beust.kobalt.internal
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.TaskResult
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.ITestRunnerContributor
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.*
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import java.io.File
@ -14,15 +11,19 @@ import java.net.URLClassLoader
/**
* Base class for testing frameworks that are invoked from a main class with arguments. Test runners can
* subclass this class and override mainClass and args.
* subclass this class and override mainClass, args and the name of the dependency that should trigger this runner.
*/
abstract class GenericTestRunner : ITestRunnerContributor {
abstract val dependencyName : String
abstract val mainClass: String
abstract fun args(project: Project, classpath: List<IClasspathDependency>) : List<String>
override fun run(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>)
= TaskResult(runTests(project, classpath))
override fun affinity(project: Project, context: KobaltContext) =
if (project.testDependencies.any { it.id.contains(dependencyName)}) IAffinity.DEFAULT_POSITIVE_AFFINITY
else 0
protected fun findTestClasses(project: Project, classpath: List<IClasspathDependency>): List<String> {
val path = KFiles.joinDir(project.directory, project.buildDirectory, KFiles.TEST_CLASSES_DIR)

View file

@ -1,19 +1,13 @@
package com.beust.kobalt.internal
import com.beust.kobalt.api.IAffinity
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
open public class JUnitRunner() : GenericTestRunner() {
override val mainClass = "org.junit.runner.JUnitCore"
open val dependencyName = "junit"
override fun affinity(project: Project, context: KobaltContext) =
if (project.testDependencies.any { it.id.contains(dependencyName)}) IAffinity.DEFAULT_POSITIVE_AFFINITY
else 0
override val dependencyName = "junit"
override fun args(project: Project, classpath: List<IClasspathDependency>) = findTestClasses(project, classpath)
}

View file

@ -78,14 +78,25 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
val mavenIdInterceptors = arrayListOf<IMavenIdInterceptor>()
companion object {
val PLUGIN_XML = "META-INF/kobalt-plugin.xml" // Plugins.PLUGIN_XML)
/**
* Where plug-ins define their plug-in actors.
*/
val PLUGIN_XML = "META-INF/kobalt-plugin.xml"
/**
* Kobalt's core XML file needs to be different from kobalt-plugin.xml because classloaders
* can put a plug-in's jar file in front of Kobalt's, which means we'll read
* that one instead of the core one.
*/
val PLUGIN_CORE_XML = "META-INF/kobalt-core-plugin.xml"
/**
* Read Kobalt's own kobalt-plugin.xml.
*/
fun readKobaltPluginXml(): PluginInfo {
// Note: use forward slash here since we're looking up this file in a .jar file
val url = Kobalt::class.java.classLoader.getResource(PLUGIN_XML)
val url = Kobalt::class.java.classLoader.getResource(PLUGIN_CORE_XML)
log(2, "URL for core kobalt-plugin.xml: $url")
if (url != null) {
return readPluginXml(url.openConnection().inputStream)
} else {
@ -100,6 +111,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
val jaxbContext = JAXBContext.newInstance(KobaltPluginXml::class.java)
val kotlinPlugin: KobaltPluginXml = jaxbContext.createUnmarshaller().unmarshal(ins)
as KobaltPluginXml
log(2, "Parsed plugin XML file, found: " + kotlinPlugin.name)
return PluginInfo(kotlinPlugin, classLoader)
}

View file

@ -1,8 +1,6 @@
package com.beust.kobalt.internal
import com.beust.kobalt.api.IAffinity
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.misc.KFiles
import java.io.File
@ -11,9 +9,7 @@ public class TestNgRunner() : GenericTestRunner() {
override val mainClass = "org.testng.TestNG"
override fun affinity(project: Project, context: KobaltContext) =
if (project.testDependencies.any { it.id.contains("testng")}) IAffinity.DEFAULT_POSITIVE_AFFINITY
else 0
override val dependencyName = "org.testng"
override fun args(project: Project, classpath: List<IClasspathDependency>) = arrayListOf<String>().apply {
if (project.testArgs.size > 0) {

View file

@ -0,0 +1,60 @@
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 tentativeVersion = mavenId.version
var packaging = mavenId.packaging
var repoResult: RepoFinder.RepoResult?
val version =
if (tentativeVersion != null && ! MavenId.isRangedVersion(tentativeVersion)) tentativeVersion
else {
var localVersion: String? = tentativeVersion
if (localFirst) localVersion = localRepo.findLocalVersion(mavenId.groupId, mavenId.artifactId, mavenId.packaging)
if (localFirst && localVersion != null) {
localVersion
} else {
repoResult = remoteRepo.findCorrectRepo(id)
if (!repoResult.found) {
throw KobaltException("Couldn't resolve $id")
} else {
repoResult.version?.version
}
}
}
return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version),
executor, localRepo, remoteRepo, pomFactory, downloadManager)
}
}
}

View file

@ -11,20 +11,20 @@ open class SimpleDep(open val mavenId: MavenId) : UnversionedDep(mavenId.groupId
val version: String get() = mavenId.version!!
private fun toFile(v: String, s: String, suffix: String) : String {
private fun toFile(v: String, snapshotVersion: String?, suffix: String) : String {
val fv = if (v.contains("SNAPSHOT")) v.replace("SNAPSHOT", "") else v
val result = Strings.join("/", arrayListOf(toDirectory(v, false) +
artifactId + "-" + fv + s + suffix))
artifactId + "-" + fv + (snapshotVersion ?: "") + suffix))
return result
}
fun toPomFile(v: String) = toFile(v, "", ".pom")
fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion!!.version, ".pom")
fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion?.version, ".pom")
fun toJarFile(v: String = version) = toFile(v, "", suffix)
fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion!!.version, suffix)
fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion?.version, suffix)
fun toPomFileName() = "$artifactId-$version.pom"

Some files were not shown because too many files have changed in this diff Show more