From 9d2d536fe6c4927685fd97ef2b85759c3ff5962e Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 4 Apr 2016 05:19:25 -0800 Subject: [PATCH] Initial work for the OSGI plug-in. --- kobalt/src/Build.kt | 5 ++++- .../plugin/packaging/PackagingPlugin.kt | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index b62e45e9..2eeaef53 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -135,7 +135,10 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { "com.google.code.findbugs:jsr305:3.0.1", "com.google.code.gson:gson:${Versions.gson}", "com.squareup.okhttp3:okhttp:${Versions.okhttp}", - "org.codehaus.plexus:plexus-utils:3.0.22") + "org.codehaus.plexus:plexus-utils:3.0.22", + + "biz.aQute.bnd:bndlib:2.4.0" + ) } 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 8657c11c..12e4394a 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.plugin.packaging +import aQute.bnd.osgi.Analyzer import com.beust.kobalt.* import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive @@ -107,6 +108,27 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana packages.add(p) } +// @Task(name = "generateOsgiManifest", alwaysRunAfter = arrayOf(TASK_ASSEMBLE)) + fun generateManifest(project: Project): TaskResult { + val analyzer = Analyzer().apply { + jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String) + val dependencies = project.compileDependencies + project.compileRuntimeDependencies + val dependentProjects = project.dependentProjects + dependencyManager.calculateDependencies(project, context, dependentProjects, dependencies).forEach { + addClasspath(it.jarFile.get()) + } + setProperty(Analyzer.BUNDLE_VERSION, project.version) + setProperty(Analyzer.BUNDLE_NAME, project.group) + setProperty(Analyzer.BUNDLE_DESCRIPTION, project.description) + setProperty(Analyzer.IMPORT_PACKAGE, "*") + setProperty(Analyzer.EXPORT_PACKAGE, "*;-noimport:=false;version=" + project.version) + } + + val manifest = analyzer.calcManifest() + manifest.write(System.out) + return TaskResult() + } + @Task(name = PackagingPlugin.TASK_INSTALL, description = "Install the artifacts", runAfter = arrayOf(PackagingPlugin.TASK_ASSEMBLE))