mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Add support for native dependencies.
This commit is contained in:
parent
438e72038a
commit
d8bbe547ae
8 changed files with 77 additions and 6 deletions
|
@ -14,6 +14,7 @@ interface IDependencyHolder {
|
|||
val compileProvidedDependencies : ArrayList<IClasspathDependency>
|
||||
val compileRuntimeDependencies : ArrayList<IClasspathDependency>
|
||||
val excludedDependencies : ArrayList<IClasspathDependency>
|
||||
val nativeDependencies : ArrayList<IClasspathDependency>
|
||||
|
||||
@Directive
|
||||
var dependencies: Dependencies?
|
||||
|
@ -28,12 +29,13 @@ open class DependencyHolder : IDependencyHolder {
|
|||
override val compileProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
override val compileRuntimeDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
override val excludedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
override val nativeDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
|
||||
override var dependencies : Dependencies? = null
|
||||
|
||||
override fun dependencies(init: Dependencies.() -> Unit) : Dependencies {
|
||||
dependencies = Dependencies(project, compileDependencies, compileProvidedDependencies,
|
||||
compileRuntimeDependencies, excludedDependencies)
|
||||
compileRuntimeDependencies, excludedDependencies, nativeDependencies)
|
||||
dependencies!!.init()
|
||||
return dependencies!!
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
/**
|
||||
* Plug-ins that add flags to the JVM used to run apps should implement this interface.
|
||||
*/
|
||||
interface IJvmFlagContributor : IContributor {
|
||||
/**
|
||||
* The list of JVM flags that will be added to the JVM when the app gets run. @param[currentFlags] is only here
|
||||
* for convenience, in case you need to look at the current JVM flags before adding your own flags.
|
||||
*/
|
||||
fun jvmFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>) : List<String>
|
||||
}
|
||||
|
|
@ -90,7 +90,7 @@ open class Project(
|
|||
@Directive
|
||||
fun dependenciesTest(init: Dependencies.() -> Unit) : Dependencies {
|
||||
dependencies = Dependencies(this, testDependencies, testProvidedDependencies, compileRuntimeDependencies,
|
||||
excludedDependencies)
|
||||
excludedDependencies, nativeDependencies)
|
||||
dependencies!!.init()
|
||||
return dependencies!!
|
||||
}
|
||||
|
@ -138,7 +138,8 @@ class Dependencies(val project: Project,
|
|||
val dependencies: ArrayList<IClasspathDependency>,
|
||||
val providedDependencies: ArrayList<IClasspathDependency>,
|
||||
val runtimeDependencies: ArrayList<IClasspathDependency>,
|
||||
val excludedDependencies: 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
|
||||
|
@ -164,6 +165,9 @@ class Dependencies(val project: Project,
|
|||
|
||||
@Directive
|
||||
fun exclude(vararg dep: String) = addToDependencies(project, excludedDependencies, dep)
|
||||
|
||||
@Directive
|
||||
fun native(vararg dep: String) = addToDependencies(project, nativeDependencies, dep)
|
||||
}
|
||||
|
||||
class Scm(val connection: String, val developerConnection: String, val url: String)
|
||||
|
|
|
@ -93,6 +93,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
|
|||
// Not documented yet
|
||||
val buildConfigContributors = arrayListOf<IBuildConfigContributor>()
|
||||
val mavenIdInterceptors = arrayListOf<IMavenIdInterceptor>()
|
||||
val jvmFlagContributors = arrayListOf<IJvmFlagContributor>()
|
||||
|
||||
// Note: intentionally repeating them here even though they are defined by our base class so
|
||||
// that this class always contains the full list of contributors and interceptors
|
||||
|
@ -206,6 +207,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
|
|||
// Not documented yet
|
||||
if (this is ITestJvmFlagContributor) testJvmFlagContributors.add(this)
|
||||
if (this is ITestJvmFlagInterceptor) testJvmFlagInterceptors.add(this)
|
||||
if (this is IJvmFlagContributor) jvmFlagContributors.add(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +220,8 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
|
|||
compilerContributors, docContributors, sourceDirContributors,
|
||||
testSourceDirContributors, buildConfigFieldContributors,
|
||||
taskContributors, assemblyContributors,
|
||||
incrementalAssemblyContributors, testJvmFlagInterceptors
|
||||
incrementalAssemblyContributors, testJvmFlagInterceptors,
|
||||
jvmFlagContributors
|
||||
).forEach {
|
||||
it.forEach {
|
||||
it.cleanUpActors()
|
||||
|
@ -256,6 +259,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
|
|||
incrementalAssemblyContributors.addAll(pluginInfo.incrementalAssemblyContributors)
|
||||
testJvmFlagContributors.addAll(pluginInfo.testJvmFlagContributors)
|
||||
testJvmFlagInterceptors.addAll(pluginInfo.testJvmFlagInterceptors)
|
||||
jvmFlagContributors.addAll(pluginInfo.jvmFlagContributors)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,10 @@ class KFiles {
|
|||
|
||||
val TEST_CLASSES_DIR : String = "test-classes"
|
||||
|
||||
val NATIVES_DIR : String = "native"
|
||||
|
||||
fun nativeBuildDir(project: Project) = KFiles.joinDir(project.directory, project.buildDirectory, NATIVES_DIR)
|
||||
|
||||
fun generatedSourceDir(project: Project, variant: Variant, name: String) =
|
||||
KFiles.joinDir(project.directory, project.buildDirectory, "generated", "source", name,
|
||||
variant.toIntermediateDir())
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue