mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Pass the class loader to archetypes.
This commit is contained in:
parent
7963e2fc99
commit
471410a9bc
5 changed files with 11 additions and 9 deletions
|
@ -31,6 +31,6 @@ interface IArchetype {
|
||||||
* Generate the files for this archetype. The parameter is the arguments that were passed to the kobaltw
|
* Generate the files for this archetype. The parameter is the arguments that were passed to the kobaltw
|
||||||
* command.
|
* command.
|
||||||
*/
|
*/
|
||||||
fun generateArchetype(args: Args)
|
fun generateArchetype(args: Args, classLoader: ClassLoader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,12 @@ private class Main @Inject constructor(
|
||||||
|
|
||||||
public fun run(jc: JCommander, args: Args, argv: Array<String>): Int {
|
public fun run(jc: JCommander, args: Args, argv: Array<String>): Int {
|
||||||
// Install plug-ins requested from the command line
|
// Install plug-ins requested from the command line
|
||||||
|
var pluginClassLoader = javaClass.classLoader
|
||||||
args.pluginIds?.let {
|
args.pluginIds?.let {
|
||||||
val dependencies = it.split(",").map { depFactory.create(it) }
|
val dependencies = it.split(",").map { depFactory.create(it) }
|
||||||
val urls = dependencies.map { it.jarFile.get().toURI().toURL() }
|
val urls = dependencies.map { it.jarFile.get().toURI().toURL() }
|
||||||
plugins.installPlugins(dependencies, URLClassLoader(urls.toTypedArray()))
|
pluginClassLoader = URLClassLoader(urls.toTypedArray())
|
||||||
|
plugins.installPlugins(dependencies, pluginClassLoader)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -97,7 +99,7 @@ private class Main @Inject constructor(
|
||||||
|
|
||||||
val seconds = benchmarkSeconds {
|
val seconds = benchmarkSeconds {
|
||||||
try {
|
try {
|
||||||
result = runWithArgs(jc, args, argv)
|
result = runWithArgs(jc, args, argv, pluginClassLoader)
|
||||||
} catch(ex: KobaltException) {
|
} catch(ex: KobaltException) {
|
||||||
error("", ex.cause ?: ex)
|
error("", ex.cause ?: ex)
|
||||||
result = 1
|
result = 1
|
||||||
|
@ -116,7 +118,7 @@ private class Main @Inject constructor(
|
||||||
// val file = File("src\\main\\resources\\META-INF\\plugin.ml")
|
// val file = File("src\\main\\resources\\META-INF\\plugin.ml")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
private fun runWithArgs(jc: JCommander, args: Args, argv: Array<String>): Int {
|
private fun runWithArgs(jc: JCommander, args: Args, argv: Array<String>, pluginClassLoader: ClassLoader): Int {
|
||||||
// val file = File("/Users/beust/.kobalt/repository/com/google/guava/guava/19.0-rc2/guava-19.0-rc2.pom")
|
// val file = File("/Users/beust/.kobalt/repository/com/google/guava/guava/19.0-rc2/guava-19.0-rc2.pom")
|
||||||
// val md5 = Md5.toMd5(file)
|
// val md5 = Md5.toMd5(file)
|
||||||
// val md52 = MessageDigest.getInstance("MD5").digest(file.readBytes()).toHexString()
|
// val md52 = MessageDigest.getInstance("MD5").digest(file.readBytes()).toHexString()
|
||||||
|
@ -135,7 +137,7 @@ private class Main @Inject constructor(
|
||||||
// Make sure the wrapper won't call us back with --noLaunch
|
// Make sure the wrapper won't call us back with --noLaunch
|
||||||
//
|
//
|
||||||
com.beust.kobalt.wrapper.Main.main(arrayOf("--noLaunch") + argv)
|
com.beust.kobalt.wrapper.Main.main(arrayOf("--noLaunch") + argv)
|
||||||
projectGenerator.run(args)
|
projectGenerator.run(args, pluginClassLoader)
|
||||||
} else if (args.usage) {
|
} else if (args.usage) {
|
||||||
jc.usage()
|
jc.usage()
|
||||||
} else if (args.serverMode) {
|
} else if (args.serverMode) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ abstract class BuildGenerator : IArchetype {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun generateArchetype(args: Args) {
|
override fun generateArchetype(args: Args, classLoader: ClassLoader) {
|
||||||
val file = File(args.buildFile)
|
val file = File(args.buildFile)
|
||||||
if (! file.exists()) {
|
if (! file.exists()) {
|
||||||
PrintWriter(FileOutputStream(file)).use {
|
PrintWriter(FileOutputStream(file)).use {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.io.File
|
||||||
* Invoked with --init. Generate a new project.
|
* Invoked with --init. Generate a new project.
|
||||||
*/
|
*/
|
||||||
class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){
|
class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){
|
||||||
fun run(args: Args) {
|
fun run(args: Args, classLoader: ClassLoader) {
|
||||||
File(args.buildFile).parentFile.mkdirs()
|
File(args.buildFile).parentFile.mkdirs()
|
||||||
val map = hashMapOf<String, IArchetype>()
|
val map = hashMapOf<String, IArchetype>()
|
||||||
pluginInfo.initContributors.forEach {
|
pluginInfo.initContributors.forEach {
|
||||||
|
@ -26,7 +26,7 @@ class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){
|
||||||
val archetype = map[archetypeName]
|
val archetype = map[archetypeName]
|
||||||
if (archetype != null) {
|
if (archetype != null) {
|
||||||
log(2, "Running archetype $archetypeName")
|
log(2, "Running archetype $archetypeName")
|
||||||
archetype.generateArchetype(args)
|
archetype.generateArchetype(args, classLoader)
|
||||||
} else {
|
} else {
|
||||||
warn("Couldn't find any archetype named $archetypeName")
|
warn("Couldn't find any archetype named $archetypeName")
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ class PomTest @Inject constructor() : KobaltTest() {
|
||||||
args.buildFile = file.absolutePath
|
args.buildFile = file.absolutePath
|
||||||
args.archetypes = "java"
|
args.archetypes = "java"
|
||||||
|
|
||||||
ProjectGenerator(Kobalt.INJECTOR.getInstance(PluginInfo::class.java)).run(args)
|
ProjectGenerator(Kobalt.INJECTOR.getInstance(PluginInfo::class.java)).run(args, javaClass.classLoader)
|
||||||
|
|
||||||
var contents = file.readText()
|
var contents = file.readText()
|
||||||
Assert.assertTrue(contents.contains("group = \"${pom.groupId}\""), "Should find the group defined")
|
Assert.assertTrue(contents.contains("group = \"${pom.groupId}\""), "Should find the group defined")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue