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

Add support for native dependencies.

This commit is contained in:
Cedric Beust 2016-06-14 22:32:46 -08:00
parent 438e72038a
commit d8bbe547ae
8 changed files with 77 additions and 6 deletions

View file

@ -36,7 +36,7 @@ fun Project.application(init: ApplicationConfig.() -> Unit) {
@Singleton
class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<ApplicationConfig>,
val executors: KobaltExecutors,
val executors: KobaltExecutors, val nativeManager: NativeManager,
val dependencyManager: DependencyManager, val taskContributor : TaskContributor)
: BasePlugin(), IRunnerContributor, ITaskContributor, IConfigActor<ApplicationConfig> by configActor {
@ -84,6 +84,9 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
override fun run(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>): TaskResult {
var result = TaskResult()
if (project.nativeDependencies.any()) {
nativeManager.installLibraries(project)
}
configurationFor(project)?.let { config ->
if (config.mainClass != null) {
result = runJarFile(project, context, config)
@ -113,7 +116,11 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
allDeps.addAll(allTheDependencies)
}
val allDepsJoined = allDeps.joinToString(File.pathSeparator)
val args = listOf("-classpath", allDepsJoined) + config.jvmArgs + config.mainClass!!
val initialArgs = listOf("-classpath", allDepsJoined) + config.jvmArgs + config.mainClass!!
val contributorFlags = context.pluginInfo.jvmFlagContributors.flatMap {
it.jvmFlagsFor(project, context, initialArgs)
}
val args = contributorFlags + initialArgs
val exitCode = RunCommand(java.absolutePath).run(args,
successCallback = { output: List<String> ->
println(output.joinToString("\n"))

View file

@ -0,0 +1,36 @@
package com.beust.kobalt.plugin.application
import com.beust.kobalt.api.IJvmFlagContributor
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.misc.JarUtils
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.google.inject.Inject
import java.io.File
/**
* Used for projects that define native() dependencies. This class extracts the native jar files in the
* $build/native library and configures -Djava.library.path with that directory.
*/
class NativeManager @Inject constructor() : IJvmFlagContributor {
fun buildDir(project: Project) = File(KFiles.nativeBuildDir(project))
override fun jvmFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>): List<String> {
return if (project.nativeDependencies.any()) listOf("-Djava.library.path=${buildDir(project)}")
else emptyList()
}
fun installLibraries(project: Project) {
val buildDir = buildDir(project)
if (! buildDir.exists()) {
buildDir.mkdirs()
project.nativeDependencies.forEach { dep ->
log(2, "Extracting $dep " + dep.jarFile.get() + " in $buildDir")
JarUtils.extractJarFile(dep.jarFile.get(), buildDir)
}
} else {
log(2, "Native directory $buildDir already exists, not extracting the native jar files")
}
}
}

View file

@ -6,6 +6,7 @@
<!-- are found to implement one of IPluginActor's interfaces, they are added as such -->
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
<class-name>com.beust.kobalt.plugin.application.ApplicationPlugin</class-name>
<class-name>com.beust.kobalt.plugin.application.NativeManager</class-name>
<class-name>com.beust.kobalt.plugin.KobaltPlugin</class-name>
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
<class-name>com.beust.kobalt.plugin.packaging.PackagingPlugin</class-name>