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

Support for archetypes.

This commit is contained in:
Cedric Beust 2016-02-11 21:20:29 -08:00
parent 1821f46e1c
commit b57b1845bc
9 changed files with 51 additions and 48 deletions

View file

@ -29,8 +29,8 @@ class Args {
@Parameter(names = arrayOf("--help", "--usage"), description = "Display the help")
var usage: Boolean = false
@Parameter(names = arrayOf("-i", "--init"), description = "Create a build file based on the current project")
var init: Boolean = false
@Parameter(names = arrayOf("-i", "--init"), description = "Invoke the archetypes named, separated by a comma")
var archetypes : String? = null
@Parameter(names = arrayOf("--log"), description = "Define the log level (1-3)")
var log: Int = 1

View file

@ -1,8 +1,11 @@
package com.beust.kobalt
import com.beust.kobalt.misc.KFiles
object Constants {
val BUILD_FILE_NAME = "Build.kt"
val BUILD_FILE_DIRECTORY = "kobalt/src"
val BUILD_FILE_PATH = KFiles.joinDir(BUILD_FILE_DIRECTORY, BUILD_FILE_NAME)
internal val DEFAULT_REPOS = listOf(
"http://repo1.maven.org/maven2/",

View file

@ -1,15 +1,14 @@
package com.beust.kobalt.api
import java.io.OutputStream
import com.beust.kobalt.Args
/**
* Plugins that want to participate in the --init process (they can generate files to initialize
* a new project).
*/
interface IInitContributor<T> : ISimpleAffinity<T> {
/**
* Generate the Build.kt file into the given OutputStream.
*/
fun generateBuildFile(os: OutputStream)
interface IInitContributor {
val name: String
fun generateArchetype(args: Args)
}

View file

@ -59,7 +59,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
val plugins = arrayListOf<IPlugin>()
val projectContributors = arrayListOf<IProjectContributor>()
val classpathContributors = arrayListOf<IClasspathContributor>()
val initContributors = arrayListOf<IInitContributor<File>>()
val initContributors = arrayListOf<IInitContributor>()
val repoContributors = arrayListOf<IRepoContributor>()
val compilerFlagContributors = arrayListOf<ICompilerFlagContributor>()
val compilerInterceptors = arrayListOf<ICompilerInterceptor>()
@ -147,7 +147,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
if (this is ICompilerFlagContributor) compilerFlagContributors.add(this)
if (this is ICompilerInterceptor) compilerInterceptors.add(this)
if (this is IDocContributor) docContributors.add(this)
if (this is IInitContributor<*>) initContributors.add(this as IInitContributor<File>)
if (this is IInitContributor) initContributors.add(this as IInitContributor)
if (this is IPlugin) plugins.add(this)
if (this is IProjectContributor) projectContributors.add(this)
if (this is IRepoContributor) repoContributors.add(this)

View file

@ -28,6 +28,9 @@ import javax.xml.xpath.XPathFactory
class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
fun findCorrectRepo(id: String) = FOUND_REPOS.get(id)
/**
* archiveUrl: full URL
*/
data class RepoResult(val hostConfig: HostConfig, val version: Version? = null,
val archiveUrl: String? = null, val snapshotVersion: Version? = null) {
val found = archiveUrl != null
@ -96,7 +99,7 @@ class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
val path = ud.toMetadataXmlPath(false, isLocal)
val foundVersion = findCorrectVersionRelease(path, repoUrl)
if (foundVersion != null) {
return RepoResult(repo, Version.of(foundVersion), path)
return RepoResult(repo, Version.of(foundVersion), repoUrl + path)
} else {
return RepoResult(repo)
}