Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,6 @@ import java.net.InetSocketAddress

var BUILD_SCRIPT_CONFIG : BuildScriptConfig? = null

class BuildScriptConfig {
/** The list of repos used to locate plug-ins. */
@Directive
fun repos(vararg r: String) = newRepos(*r)

/** The list of plug-ins to use for this build file. */
@Directive
fun plugins(vararg pl: String) = newPlugins(*pl)

/** The build file classpath. */
@Directive
fun buildFileClasspath(vararg bfc: String) = newBuildFileClasspath(*bfc)

// The following settings modify the compiler used to compile the build file.
// Projects should use kotlinCompiler { compilerVersion } to configure the Kotin compiler for their source files.
var kobaltCompilerVersion : String? = null
var kobaltCompilerRepo: String? = null
var kobaltCompilerFlags: String? = null
}

@Directive
fun homeDir(vararg dirs: String) : String = SystemProperties.homeDir +
File.separator + dirs.toMutableList().joinToString(File.separator)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.beust.kobalt

import com.beust.kobalt.api.annotation.Directive

class BuildScriptConfig {
/** The list of repos used to locate plug-ins. */
@Directive
fun repos(vararg r: String) = newRepos(*r)

/** The list of plug-ins to use for this build file. */
@Directive
fun plugins(vararg pl: String) = newPlugins(*pl)

/** The build file classpath. */
@Directive
fun buildFileClasspath(vararg bfc: String) = newBuildFileClasspath(*bfc)

// The following settings modify the compiler used to compile the build file.
// Projects should use kotlinCompiler { compilerVersion } to configure the Kotin compiler for their source files.
var kobaltCompilerVersion : String? = null
var kobaltCompilerRepo: String? = null
var kobaltCompilerFlags: String? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.beust.kobalt.api

class BuildConfig {
class Field(val name: String, val type: String, val value: Any) {
override fun hashCode() = name.hashCode()
override fun equals(other: Any?) = (other as Field).name == name
}

val fields = arrayListOf<Field>()

fun field(type: String, name: String, value: Any) {
fields.add(Field(name, type, value))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.beust.kobalt.api

import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.aether.KobaltMavenResolver
import com.beust.kobalt.misc.kobaltLog
import java.io.File
import java.util.ArrayList
import java.util.concurrent.Future

class Dependencies(val project: Project,
val dependencies: ArrayList<IClasspathDependency>,
val optionalDependencies: ArrayList<IClasspathDependency>,
val providedDependencies: ArrayList<IClasspathDependency>,
val runtimeDependencies: ArrayList<IClasspathDependency>,
val excludedDependencies: ArrayList<IClasspathDependency>,
val nativeDependencies: ArrayList<IClasspathDependency>) {

/**
* Add the dependencies to the given ArrayList and return a list of future jar files corresponding to
* these dependencies. Futures are necessary here since this code is invoked from the build file and
* we might not have set up the extra IRepositoryContributors just yet. By the time these
* future tasks receive a get(), the repos will be correct.
*/
private fun addToDependencies(project: Project, dependencies: ArrayList<IClasspathDependency>,
dep: Array<out String>, optional: Boolean = false): List<Future<File>>
= with(dep.map {
val resolved =
if (KobaltMavenResolver.isRangeVersion(it)) {
// Range id
val node = Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java).resolveToArtifact(it)
val result = KobaltMavenResolver.artifactToId(node)
kobaltLog(2, "Resolved range id $it to $result")
result
} else {
it
}
DependencyManager.create(resolved, optional, project.directory)
}) {
dependencies.addAll(this)
this.map { java.util.concurrent.FutureTask { it.jarFile.get() } }
}

@Directive
fun compile(vararg dep: String) = addToDependencies(project, dependencies, dep)

@Directive
fun compileOptional(vararg dep: String) {
addToDependencies(project, optionalDependencies, dep, optional = true)
addToDependencies(project, dependencies, dep, optional = true)
}

@Directive
fun provided(vararg dep: String) {
addToDependencies(project, providedDependencies, dep)
addToDependencies(project, dependencies, dep)
}

@Directive
fun runtime(vararg dep: String) = addToDependencies(project, runtimeDependencies, dep)

@Directive
fun exclude(vararg dep: String) = addToDependencies(project, excludedDependencies, dep)

@Directive
fun native(vararg dep: String) = addToDependencies(project, nativeDependencies, dep)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.beust.kobalt.api

interface IBuildConfig {
var buildConfig: BuildConfig?

fun buildConfig(init: BuildConfig.() -> Unit) {
buildConfig = BuildConfig().apply {
init()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ open class Project(
val testConfigs = arrayListOf<TestConfig>()

// If one is specified by default, we only generateAndSave a BuildConfig, find a way to fix that
override var buildConfig : BuildConfig? = null // BuildConfig()
override var buildConfig: BuildConfig? = null // BuildConfig()

val projectProperties = ProjectProperties()

Expand All @@ -66,33 +66,33 @@ open class Project(
//

@Directive
fun sourceDirectories(init: Sources.() -> Unit) : Sources {
fun sourceDirectories(init: Sources.() -> Unit): Sources {
return Sources(this, sourceDirectories).apply { init() }
}

var sourceDirectories = hashSetOf<String>().apply { addAll(DEFAULT_SOURCE_DIRECTORIES)}
var sourceDirectories = hashSetOf<String>().apply { addAll(DEFAULT_SOURCE_DIRECTORIES) }

@Directive
fun sourceDirectoriesTest(init: Sources.() -> Unit) : Sources {
fun sourceDirectoriesTest(init: Sources.() -> Unit): Sources {
return Sources(this, sourceDirectoriesTest).apply { init() }
}

var sourceDirectoriesTest = hashSetOf<String>().apply { addAll(DEFAULT_SOURCE_DIRECTORIES_TEST)}
var sourceDirectoriesTest = hashSetOf<String>().apply { addAll(DEFAULT_SOURCE_DIRECTORIES_TEST) }

//
// Dependencies
//

@Directive
fun dependenciesTest(init: Dependencies.() -> Unit) : Dependencies {
fun dependenciesTest(init: Dependencies.() -> Unit): Dependencies {
dependencies = Dependencies(this, testDependencies, arrayListOf(),
testProvidedDependencies, compileRuntimeDependencies, excludedDependencies, nativeDependencies)
dependencies!!.init()
return dependencies!!
}

val testDependencies : ArrayList<IClasspathDependency> = arrayListOf()
val testProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
val testDependencies: ArrayList<IClasspathDependency> = arrayListOf()
val testProvidedDependencies: ArrayList<IClasspathDependency> = arrayListOf()

/** Used to disambiguate various name properties */
@Directive
Expand All @@ -104,7 +104,7 @@ open class Project(
productFlavors.put(name, pf)
}

var defaultConfig : BuildConfig? = null
var defaultConfig: BuildConfig? = null

val buildTypes = hashMapOf<String, BuildTypeConfig>()

Expand All @@ -121,112 +121,24 @@ open class Project(
}

override fun toString() = "[Project $name]"
}

class Sources(val project: Project, val sources: HashSet<String>) {
@Directive
fun path(vararg paths: String) {
sources.addAll(paths)
}
}

class Dependencies(val project: Project,
val dependencies: ArrayList<IClasspathDependency>,
val optionalDependencies: ArrayList<IClasspathDependency>,
val providedDependencies: ArrayList<IClasspathDependency>,
val runtimeDependencies: ArrayList<IClasspathDependency>,
val excludedDependencies: ArrayList<IClasspathDependency>,
val nativeDependencies: ArrayList<IClasspathDependency>) {

/**
* Add the dependencies to the given ArrayList and return a list of future jar files corresponding to
* these dependencies. Futures are necessary here since this code is invoked from the build file and
* we might not have set up the extra IRepositoryContributors just yet. By the time these
* future tasks receive a get(), the repos will be correct.
*/
private fun addToDependencies(project: Project, dependencies: ArrayList<IClasspathDependency>,
dep: Array<out String>, optional: Boolean = false): List<Future<File>>
= with(dep.map {
val resolved =
if (KobaltMavenResolver.isRangeVersion(it)) {
// Range id
val node = Kobalt.INJECTOR.getInstance(KobaltMavenResolver::class.java).resolveToArtifact(it)
val result = KobaltMavenResolver.artifactToId(node)
kobaltLog(2, "Resolved range id $it to $result")
result
} else {
it
}
DependencyManager.create(resolved, optional, project.directory)
}) {
dependencies.addAll(this)
this.map { FutureTask { it.jarFile.get() } }
fun defaultConfig(init: BuildConfig.() -> Unit) = let { project ->
BuildConfig().apply {
init()
project.defaultConfig = this
}

@Directive
fun compile(vararg dep: String) = addToDependencies(project, dependencies, dep)

@Directive
fun compileOptional(vararg dep: String) {
addToDependencies(project, optionalDependencies, dep, optional = true)
addToDependencies(project, dependencies, dep, optional = true)
}

@Directive
fun provided(vararg dep: String) {
addToDependencies(project, providedDependencies, dep)
addToDependencies(project, dependencies, dep)
fun buildType(name: String, init: BuildTypeConfig.() -> Unit) = BuildTypeConfig(name).apply {
init()
addBuildType(name, this)
}

@Directive
fun runtime(vararg dep: String) = addToDependencies(project, runtimeDependencies, dep)

@Directive
fun exclude(vararg dep: String) = addToDependencies(project, excludedDependencies, dep)

@Directive
fun native(vararg dep: String) = addToDependencies(project, nativeDependencies, dep)
}

class BuildConfig {
class Field(val name: String, val type: String, val value: Any) {
override fun hashCode() = name.hashCode()
override fun equals(other: Any?) = (other as Field).name == name
}

val fields = arrayListOf<Field>()

fun field(type: String, name: String, value: Any) {
fields.add(Field(name, type, value))
}
}

interface IBuildConfig {
var buildConfig: BuildConfig?

fun buildConfig(init: BuildConfig.() -> Unit) {
buildConfig = BuildConfig().apply {
init()
}
}
}

fun Project.defaultConfig(init: BuildConfig.() -> Unit) = let { project ->
BuildConfig().apply {
fun productFlavor(name: String, init: ProductFlavorConfig.() -> Unit) = ProductFlavorConfig(name).apply {
init()
project.defaultConfig = this
addProductFlavor(name, this)
}
}

@Directive
fun Project.buildType(name: String, init: BuildTypeConfig.() -> Unit) = BuildTypeConfig(name).apply {
init()
addBuildType(name, this)
}


@Directive
fun Project.productFlavor(name: String, init: ProductFlavorConfig.() -> Unit) = ProductFlavorConfig(name).apply {
init()
addProductFlavor(name, this)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.beust.kobalt.api

import com.beust.kobalt.api.annotation.Directive
import java.util.HashSet

class Sources(val project: Project, val sources: HashSet<String>) {
@Directive
fun path(vararg paths: String) {
sources.addAll(paths)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.beust.kobalt.plugin.application

import com.beust.kobalt.api.annotation.Directive

class ApplicationConfig {
@Directive
var mainClass: String? = null

@Directive
fun jvmArgs(vararg args: String) = args.forEach { jvmArgs.add(it) }
val jvmArgs = arrayListOf<String>()

@Directive
fun args(vararg argv: String) = argv.forEach { args.add(it) }
val args = arrayListOf<String>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ import com.google.inject.Inject
import com.google.inject.Singleton
import java.io.File

class ApplicationConfig {
@Directive
var mainClass: String? = null

@Directive
fun jvmArgs(vararg args: String) = args.forEach { jvmArgs.add(it) }
val jvmArgs = arrayListOf<String>()

@Directive
fun args(vararg argv: String) = argv.forEach { args.add(it) }
val args = arrayListOf<String>()
}

@Directive
fun Project.application(init: ApplicationConfig.() -> Unit): ApplicationConfig {
return ApplicationConfig().also { config ->
Expand All @@ -40,8 +27,8 @@ fun Project.application(init: ApplicationConfig.() -> Unit): ApplicationConfig {

@Singleton
class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<ApplicationConfig>,
val executors: KobaltExecutors, val nativeManager: NativeManager,
val dependencyManager: DependencyManager, val taskContributor : TaskContributor)
val executors: KobaltExecutors, val nativeManager: NativeManager,
val dependencyManager: DependencyManager, val taskContributor : TaskContributor)
: BasePlugin(), IRunnerContributor, ITaskContributor, IConfigActor<ApplicationConfig> by configActor {

companion object {
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/com/beust/kobalt/plugin/apt/AptConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.beust.kobalt.plugin.apt

import com.beust.kobalt.api.annotation.Directive

class AptConfig(@Directive var outputDir: String = "generated/source/apt")
Loading