diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt index 3d75614e9..9fed270f5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt @@ -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) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScriptConfig.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScriptConfig.kt new file mode 100644 index 000000000..92dc07f61 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScriptConfig.kt @@ -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 +} \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/BuildConfig.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/BuildConfig.kt new file mode 100644 index 000000000..df60be4d4 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/BuildConfig.kt @@ -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() + + fun field(type: String, name: String, value: Any) { + fields.add(Field(name, type, value)) + } +} \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Dependencies.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Dependencies.kt new file mode 100644 index 000000000..ae62d18e3 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Dependencies.kt @@ -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, + val optionalDependencies: ArrayList, + val providedDependencies: ArrayList, + val runtimeDependencies: ArrayList, + val excludedDependencies: ArrayList, + val nativeDependencies: ArrayList) { + + /** + * 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, + dep: Array, optional: Boolean = false): List> + = 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) +} \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfig.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfig.kt new file mode 100644 index 000000000..14e354b17 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfig.kt @@ -0,0 +1,11 @@ +package com.beust.kobalt.api + +interface IBuildConfig { + var buildConfig: BuildConfig? + + fun buildConfig(init: BuildConfig.() -> Unit) { + buildConfig = BuildConfig().apply { + init() + } + } +} \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index 5e45e7cb5..72e08a6e1 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -49,7 +49,7 @@ open class Project( val testConfigs = arrayListOf() // 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() @@ -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().apply { addAll(DEFAULT_SOURCE_DIRECTORIES)} + var sourceDirectories = hashSetOf().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().apply { addAll(DEFAULT_SOURCE_DIRECTORIES_TEST)} + var sourceDirectoriesTest = hashSetOf().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 = arrayListOf() - val testProvidedDependencies : ArrayList = arrayListOf() + val testDependencies: ArrayList = arrayListOf() + val testProvidedDependencies: ArrayList = arrayListOf() /** Used to disambiguate various name properties */ @Directive @@ -104,7 +104,7 @@ open class Project( productFlavors.put(name, pf) } - var defaultConfig : BuildConfig? = null + var defaultConfig: BuildConfig? = null val buildTypes = hashMapOf() @@ -121,112 +121,24 @@ open class Project( } override fun toString() = "[Project $name]" -} - -class Sources(val project: Project, val sources: HashSet) { - @Directive - fun path(vararg paths: String) { - sources.addAll(paths) - } -} -class Dependencies(val project: Project, - val dependencies: ArrayList, - val optionalDependencies: ArrayList, - val providedDependencies: ArrayList, - val runtimeDependencies: ArrayList, - val excludedDependencies: ArrayList, - val nativeDependencies: ArrayList) { - - /** - * 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, - dep: Array, optional: Boolean = false): List> - = 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() - - 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) -} diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Sources.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Sources.kt new file mode 100644 index 000000000..605f058d0 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Sources.kt @@ -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) { + @Directive + fun path(vararg paths: String) { + sources.addAll(paths) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationConfig.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationConfig.kt new file mode 100644 index 000000000..af25f6ac3 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationConfig.kt @@ -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() + + @Directive + fun args(vararg argv: String) = argv.forEach { args.add(it) } + val args = arrayListOf() +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt index d053b9188..400fab6b2 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -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() - - @Directive - fun args(vararg argv: String) = argv.forEach { args.add(it) } - val args = arrayListOf() -} - @Directive fun Project.application(init: ApplicationConfig.() -> Unit): ApplicationConfig { return ApplicationConfig().also { config -> @@ -40,8 +27,8 @@ fun Project.application(init: ApplicationConfig.() -> Unit): ApplicationConfig { @Singleton class ApplicationPlugin @Inject constructor(val configActor: ConfigActor, - 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 by configActor { companion object { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptConfig.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptConfig.kt new file mode 100644 index 000000000..4338c62d8 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptConfig.kt @@ -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") \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index 666e009d3..da29a9bf5 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -147,15 +147,12 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va } } -class AptConfig(var outputDir: String = "generated/source/apt") - @Directive -fun Project.apt(init: AptConfig.() -> Unit) { - AptConfig().let { - it.init() - (Kobalt.findPlugin(AptPlugin.PLUGIN_NAME) as AptPlugin).addAptConfig(this, it) +fun Project.apt(init: AptConfig.() -> Unit) = + AptConfig().also { config -> + config.init() + (Kobalt.findPlugin(AptPlugin.PLUGIN_NAME) as AptPlugin).addAptConfig(this, config) } -} @Directive fun Dependencies.apt(vararg dep: String) { @@ -164,12 +161,9 @@ fun Dependencies.apt(vararg dep: String) { } } -class KaptConfig(var outputDir: String = "generated/source/apt") - @Directive -fun Project.kapt(init: KaptConfig.() -> Unit) { - KaptConfig().let { - it.init() - (Kobalt.findPlugin(AptPlugin.PLUGIN_NAME) as AptPlugin).addKaptConfig(this, it) +fun Project.kapt(init: KaptConfig.() -> Unit) = + KaptConfig().also { config -> + config.init() + (Kobalt.findPlugin(AptPlugin.PLUGIN_NAME) as AptPlugin).addKaptConfig(this, config) } -} diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/KaptConfig.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/KaptConfig.kt new file mode 100644 index 000000000..846ea9773 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/KaptConfig.kt @@ -0,0 +1,5 @@ +package com.beust.kobalt.plugin.apt + +import com.beust.kobalt.api.annotation.Directive + +class KaptConfig(@Directive var outputDir: String = "generated/source/apt") \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/plugin/groovy/GroovyConfig.kt b/src/main/kotlin/com/beust/kobalt/plugin/groovy/GroovyConfig.kt new file mode 100644 index 000000000..a829041af --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/plugin/groovy/GroovyConfig.kt @@ -0,0 +1,9 @@ +package com.beust.kobalt.plugin.groovy + +import com.beust.kobalt.api.Project +import com.beust.kobalt.api.annotation.Directive + +class GroovyConfig(val project: Project) { + val compilerArgs = arrayListOf() + @Directive fun args(vararg options: String) = compilerArgs.addAll(options) +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/plugin/groovy/GroovyPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/groovy/GroovyPlugin.kt index 138505716..c8202995c 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/groovy/GroovyPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/groovy/GroovyPlugin.kt @@ -38,11 +38,6 @@ class GroovyPlugin @Inject constructor(val groovyCompiler: GroovyCompiler, = if (sourceFileCount(project) > 0) listOf(compiler) else emptyList() } -class GroovyConfig(val project: Project) { - val compilerArgs = arrayListOf() - fun args(vararg options: String) = compilerArgs.addAll(options) -} - @Directive fun Project.groovyCompiler(init: GroovyConfig.() -> Unit) = GroovyConfig(this).also { config -> diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaConfig.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaConfig.kt new file mode 100644 index 000000000..06d7a58da --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaConfig.kt @@ -0,0 +1,9 @@ +package com.beust.kobalt.plugin.java + +import com.beust.kobalt.api.Project +import com.beust.kobalt.api.annotation.Directive + +class JavaConfig(val project: Project) { + val compilerArgs = arrayListOf() + @Directive fun args(vararg options: String) = compilerArgs.addAll(options) +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt index e0d233c04..ff7f09be9 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt @@ -78,11 +78,6 @@ fun javaProject(vararg projects: Project, init: Project.() -> Unit): Project { } } -class JavaConfig(val project: Project) { - val compilerArgs = arrayListOf() - fun args(vararg options: String) = compilerArgs.addAll(options) -} - @Directive fun Project.javaCompiler(init: JavaConfig.() -> Unit) = JavaConfig(this).also { config -> diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinConfig.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinConfig.kt new file mode 100644 index 000000000..7a1fce650 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinConfig.kt @@ -0,0 +1,13 @@ +package com.beust.kobalt.plugin.kotlin + +import com.beust.kobalt.api.Project +import com.beust.kobalt.api.annotation.Directive + +class KotlinConfig(val project: Project) { + val args = arrayListOf() + fun args(vararg options: String) = args.addAll(options) + + /** The version of the Kotlin compiler */ + @Directive + var version: String? = null +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index 8f16a3d4e..480e4dfdb 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -144,15 +144,6 @@ fun kotlinProject(vararg projects: Project, init: Project.() -> Unit): Project { } } -class KotlinConfig(val project: Project) { - val args = arrayListOf() - fun args(vararg options: String) = args.addAll(options) - - /** The version of the Kotlin compiler */ - @Directive - var version: String? = null -} - @Directive fun Project.kotlinCompiler(init: KotlinConfig.() -> Unit) = KotlinConfig(this).also { config -> diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackageConfig.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackageConfig.kt new file mode 100644 index 000000000..53a40fbb2 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackageConfig.kt @@ -0,0 +1,88 @@ +package com.beust.kobalt.plugin.packaging + +import com.beust.kobalt.api.Kobalt +import com.beust.kobalt.api.Project +import com.beust.kobalt.api.annotation.Directive +import com.beust.kobalt.archive.* +import com.beust.kobalt.glob +import com.beust.kobalt.internal.JvmCompilerPlugin +import com.beust.kobalt.misc.KFiles +import java.io.File + +class PackageConfig(val project: Project) : AttributeHolder { + val jars = arrayListOf() + val wars = arrayListOf() + val zips = arrayListOf() + var generatePom: Boolean = false + + init { + (Kobalt.findPlugin(PackagingPlugin.PLUGIN_NAME) as PackagingPlugin).addPackage(this) + } + + @Directive + fun jar(init: Jar.(p: Jar) -> Unit) = Jar(project).apply { + init(this) + jars.add(this) + } + + @Directive + fun zip(init: Zip.(p: Zip) -> Unit) = Zip(project).apply { + init(this) + zips.add(this) + } + + @Directive + fun war(init: War.(p: War) -> Unit) = War(project).apply { + init(this) + wars.add(this) + } + + /** + * Package all the jar files necessary for a maven repo: classes, sources, javadocs. + */ + @Directive + fun mavenJars(init: MavenJars.(p: MavenJars) -> Unit) : MavenJars { + val m = MavenJars(this) + m.init(m) + + val mainJar = jar { + fatJar = m.fatJar + } + jar { + name = "${project.name}-${project.version}-sources.jar" + project.sourceDirectories.forEach { + if (File(project.directory, it).exists()) { + include(from(it), to(""), glob("**")) + } + } + } + jar { + name = "${project.name}-${project.version}-javadoc.jar" + val fromDir = KFiles.joinDir(project.buildDirectory, JvmCompilerPlugin.DOCS_DIRECTORY) + include(from(fromDir), to(""), glob("**")) + } + + mainJarAttributes.forEach { + mainJar.addAttribute(it.first, it.second) + } + + generatePom = true + + return m + } + + val mainJarAttributes = arrayListOf>() + + override fun addAttribute(k: String, v: String) { + mainJarAttributes.add(Pair(k, v)) + } + + class MavenJars(val ah: AttributeHolder, var fatJar: Boolean = false, var manifest: Manifest? = null) : + AttributeHolder by ah { + fun manifest(init: Manifest.(p: Manifest) -> Unit) : Manifest { + val m = Manifest(this) + m.init(m) + return m + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index 0518fed6f..428af875e 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -175,84 +175,6 @@ fun Project.assemble(init: PackageConfig.(p: Project) -> Unit): PackageConfig = PackageConfig(this).apply { init(it) } } -class PackageConfig(val project: Project) : AttributeHolder { - val jars = arrayListOf() - val wars = arrayListOf() - val zips = arrayListOf() - var generatePom: Boolean = false - - init { - (Kobalt.findPlugin(PackagingPlugin.PLUGIN_NAME) as PackagingPlugin).addPackage(this) - } - - @Directive - fun jar(init: Jar.(p: Jar) -> Unit) = Jar(project).apply { - init(this) - jars.add(this) - } - - @Directive - fun zip(init: Zip.(p: Zip) -> Unit) = Zip(project).apply { - init(this) - zips.add(this) - } - - @Directive - fun war(init: War.(p: War) -> Unit) = War(project).apply { - init(this) - wars.add(this) - } - - /** - * Package all the jar files necessary for a maven repo: classes, sources, javadocs. - */ - @Directive - fun mavenJars(init: MavenJars.(p: MavenJars) -> Unit) : MavenJars { - val m = MavenJars(this) - m.init(m) - - val mainJar = jar { - fatJar = m.fatJar - } - jar { - name = "${project.name}-${project.version}-sources.jar" - project.sourceDirectories.forEach { - if (File(project.directory, it).exists()) { - include(from(it), to(""), glob("**")) - } - } - } - jar { - name = "${project.name}-${project.version}-javadoc.jar" - val fromDir = KFiles.joinDir(project.buildDirectory, JvmCompilerPlugin.DOCS_DIRECTORY) - include(from(fromDir), to(""), glob("**")) - } - - mainJarAttributes.forEach { - mainJar.addAttribute(it.first, it.second) - } - - generatePom = true - - return m - } - - val mainJarAttributes = arrayListOf>() - - override fun addAttribute(k: String, v: String) { - mainJarAttributes.add(Pair(k, v)) - } - - class MavenJars(val ah: AttributeHolder, var fatJar: Boolean = false, var manifest: Manifest? = null) : - AttributeHolder by ah { - fun manifest(init: Manifest.(p: Manifest) -> Unit) : Manifest { - val m = Manifest(this) - m.init(m) - return m - } - } -} - class Pom { }