Permalink
Browse files

Merge branch '21-hseeberger'

  • Loading branch information...
2 parents affc751 + 93e0697 commit 01b7e3d57d0c1d86cc8c244c896f512893c0ee01 Heiko Seeberger committed Aug 29, 2010
View
2 README
@@ -1,2 +0,0 @@
-bnd4sbt is a BND plug-in for SBT: It enables you to create OSGi bundles from your SBT projects.
-bnd4sbt is open source software licensed under the Eclipse Public License v1.0. Just use it!
View
@@ -0,0 +1,77 @@
+bnd4sbt is a "BND":http://www.aqute.biz/Code/Bnd plug-in for "SBT":http://code.google.com/p/simple-build-tool: It enables you to create "OSGi":http://www.osgi.org bundles for your SBT projects.
+
+bnd4sbt is open source software licensed under the "Eclipse Public License v1.0":http://www.eclipse.org/legal/epl-v10.html. Just use it!
+
+h2. Getting bnd4sbt
+
+The latest releases of bnd4sbt are deployed to the Scala Tools repository":http://scala-tools.org/repo-releases. As this is available from every SBT project, you only have to add bnd4sbt as a plug-in to your project (see below).
+
+If you want to go for a nightly version, you can get it from here and build it yourself using SBT:
+
+<pre>
+git clone git://github.com/weiglewilczek/bnd4sbt.git
+cd bnd4sbt
+sbt publish-local
+</pre>
+
+h2. Adding bnd4sbt as a plug-in to your project
+
+Just add the following lines to your _project/plugins/Plugins.scala_ file:
+
+<pre>
+// Repositories: Using module configs to speed up resolution => Repos must be defs!
+def aquteRepo = "aQute Maven Repository" at "http://www.aqute.biz/repo"
+lazy val aquteModuleConfig = ModuleConfiguration("biz.aQute", aquteRepo)
+
+// Dependencies
+lazy val bnd4sbt = "com.weiglewilczek.bnd4sbt" % "bnd4sbt" % "1.0.0.RC5"
+</pre>
+
+If you don't already have such a file, you can take it from here:
+
+<pre>
+class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
+ lazy val bnd4sbt = "com.weiglewilczek.bnd4sbt" % "bnd4sbt" % "1.0.0.RC5"
+}
+</pre>
+
+h2. Using bnd4sbt
+
+Mix the _com.weiglewilczek.bnd4sbt.BNDPlugin_ trait into your project definition.
+
+<pre>
+class MyProject(info: ProjectInfo) extends DefaultProject(info) with BNDPlugin
+</pre>
+
+Now you can use the _bndBundle_ action to create an OGSi bundle for your project. bnd4sbt also overrides the _package_ action such that an OSGi bundle is created.
+
+bnd4sbt offers some properties to customize the way BND will create a bundle from your project. All properties have got (hopefully) sensible defaults, e.g. the _Bundle-Version_ will be the version of your project. Currently these properties are available:
+
+* _bndBundleSymbolicName_: The value for <code>Bundle-SymbolicName</code>. Defaults to <i>projectOrganization.projectName</i> with duplicate subsequences removed, e.g. "a.b.c" + "c-d" => "a.b.c.d". Recognized namespace separators are "." and "-".
+* _bndBundleName_: The value for <code>Bundle-Name</code>. Defaults to <code>bndBundleSymbolicName</code>.
+* _bndBundleVersion_: The value for <code>Bundle-Version</code>. Defaults to this project's version.
+* _bndFragmentHost_: The value for <code>Fragment-Host</code>, wrapped in an <code>Option</code>. Defaults to <code>None</code>, i.e. no fragment is defined.
+* _bndBundleVendor_: The value for <code>Bundle-Vendor</code>, wrapped in an <code>Option</code>. Defaults to <code>None</code>, i.e. no vendor is defined.
+* _bndBundleLicense_: The value for <code>Bundle-License</code>, wrapped in an <code>Option</code>. Defaults to <code>None</code>, i.e. no license is defined.
+* _bndExecutionEnvironment_: The value for <code>Bundle-RequiredExecutionEnvironment</code>. Defaults to empty <code>Set</code>, i.e. no execution environments are defined.
+* _bndPrivatePackage_: The value for <code>Private-Package</code>. Defaults to <code>"%s.*".format(bndBundleSymbolicName) :: Nil</code>, i.e. contains the root package and all subpackages of this project.
+* _bndExportPackage_: The value for <code>Export-Package</code>. Defaults to empty <code>Seq</code>, i.e. nothing is exported.
+* _bndImportPackage_: The value for <code>Import-Package</code>. Defaults to <code>""scala.*;version=[%1$s,%1$s]".format(project.buildScalaVersion) :: "*" :: Nil</code>, i.e. Scala is imported only in the exact version which is used to build this project.
+* _bndDynamicImportPackage_: The value for <code>Dynamic-ImportPackage</code>. Defaults to empty <code>Seq</code>, i.e. nothing is imported dynamically.
+_bndRequireBundle_ : The value for <code>Require-Bundle</code>. Defaults to empty <code>Seq</code>, i.e. no bundles are required.
+* _bndBundleActivator_: The value for <code>Bundle-Actiavtor</code>, wrapped in an <code>Option</code>. Defaults to <code>None</code>, i.e. no activator is defined.
+* _bndIncludeResource_: The value for <code>Include-Resource</code>. Defaults to the main resources of this project.
+* _bndEmbedDependencies_: Should the dependencies be embedded? Defaults to <code>false</code>.
+* _bndVersionPolicy_: The value for the <code>versionpolicy</code> directive, wrapped in an <code>Option</code>. Defaults to <code>None</code>, i.e. no version policy is defined.
+* _bndNoUses_: Should the <code>nouses</code> directive be applied? Defaults to <code>false</code>.
+* _bndFileName_: The file name as part of <code>bndOutput</code>. Defaults to this project's <code>defaultJarName</code>. <b>Attention</b>: Better not change this, but the SBT default property <code>artifactBaseName</code>!
+* _bndOutput_: The output path used by BND. Defaults to the <code>outputPath</code> of this project plus the value of <code>bndFileName</code>. <b>Attention</b>: Better not change this, but the appropriate SBT default properties!
+* _bndClasspath_: The classpath used by BND. Defaults to the <code>projectClasspath(Compile)</code> plus <code>providedClasspath</code> of this project. <b>Attention</b>: Don't mistake this for the Bundle-Classpath!
+
+In a very simple setup you will only change the packages to be exported, e.g.:
+
+<pre>
+class MyProject(info: ProjectInfo) extends DefaultProject(info) with BNDPlugin
+ override def bndExportPackage = Seq("test;version=\"1.3\"")
+}
+</pre>
View
@@ -1,8 +1,8 @@
#Project properties
-#Wed Jul 21 11:37:40 CEST 2010
+#Sun Aug 29 10:40:40 CEST 2010
project.organization=com.weiglewilczek.bnd4sbt
project.name=bnd4sbt
sbt.version=0.7.4
-project.version=1.0.0.RC6
+project.version=1.0.0.RC7
build.scala.versions=2.7.7
project.initialize=false
@@ -2,17 +2,16 @@ import sbt._
class Project(info: ProjectInfo) extends PluginProject(info) {
- // Compiler options
- override def compileOptions = Unchecked :: Nil
-
- // Repositories
+ // Module configurations
def aquteRepo = "aQute Maven Repository" at "http://www.aqute.biz/repo"
- lazy val aquteModuleConfig = ModuleConfiguration("biz.aQute", aquteRepo)
+ val aquteModuleConfig = ModuleConfiguration("biz.aQute", aquteRepo)
+
+ // Dependencies (compile)
+ val bnd = "biz.aQute" % "bndlib" % "0.0.384"
- // Dependencies
- lazy val bnd = "biz.aQute" % "bndlib" % "0.0.384"
- lazy val specs = "org.scala-tools.testing" % "specs" % "1.6.2.1" % "test"
- lazy val mockito = "org.mockito" % "mockito-all" % "1.8.4" % "test"
+ // Dependencies (test)
+ val specs = "org.scala-tools.testing" % "specs" % "1.6.2.1" % "test"
+ val mockito = "org.mockito" % "mockito-all" % "1.8.4" % "test"
// Publishing
override def managedStyle = ManagedStyle.Maven
@@ -54,50 +54,51 @@ trait BNDPlugin extends DefaultProject with BNDPluginProperties {
*/
override protected[bnd4sbt] final val project = this
- private def createBundle() {
- val builder = new Builder
- builder setClasspath classpath
- builder setProperties properties
- val jar = builder.build
- jar write bndOutput.absolutePath
- }
-
- private def classpath = {
+ private lazy val classpath = {
val cp = bndClasspath.getFiles.toArray
log debug "Using the following classpath for BND: %s".format(cp mkString ":")
cp
}
- private def properties = {
+ private lazy val properties = {
val properties = new Properties
// SBT packageOptions/ManifestAttributes
- for {
- o <- packageOptions if o.isInstanceOf[ManifestAttributes]
+ for (
+ o <- packageOptions if o.isInstanceOf[ManifestAttributes];
a <- o.asInstanceOf[ManifestAttributes].attributes
- } properties.setProperty(a._1.toString, a._2)
+ ) { properties.setProperty(a._1.toString, a._2) }
// Manifest headers
properties.setProperty(BUNDLE_SYMBOLICNAME, bndBundleSymbolicName)
properties.setProperty(BUNDLE_VERSION, bndBundleVersion)
+ for ( f <- bndFragmentHost ) { properties.setProperty(FRAGMENT_HOST, f) }
properties.setProperty(BUNDLE_NAME, bndBundleName)
- for { v <- bndBundleVendor } properties.setProperty(BUNDLE_VENDOR, v)
- for { l <- bndBundleLicense } properties.setProperty(BUNDLE_LICENSE, l)
+ for ( v <- bndBundleVendor ) { properties.setProperty(BUNDLE_VENDOR, v) }
+ for ( l <- bndBundleLicense ) { properties.setProperty(BUNDLE_LICENSE, l) }
properties.setProperty(BUNDLE_REQUIREDEXECUTIONENVIRONMENT, bndExecutionEnvironment mkString ",")
properties.setProperty(BUNDLE_CLASSPATH, bundleClasspath mkString ",")
properties.setProperty(PRIVATE_PACKAGE, bndPrivatePackage mkString ",")
properties.setProperty(EXPORT_PACKAGE, bndExportPackage mkString ",")
properties.setProperty(IMPORT_PACKAGE, bndImportPackage mkString ",")
properties.setProperty(DYNAMICIMPORT_PACKAGE, bndDynamicImportPackage mkString ",")
properties.setProperty(REQUIRE_BUNDLE, bndRequireBundle mkString ",")
- for { activator <- bndBundleActivator } properties.setProperty(BUNDLE_ACTIVATOR, activator)
+ for ( activator <- bndBundleActivator ) { properties.setProperty(BUNDLE_ACTIVATOR, activator) }
// Directives
properties.setProperty(INCLUDE_RESOURCE, resourcesToBeIncluded mkString ",")
- for { v <- bndVersionPolicy } properties.setProperty(VERSIONPOLICY, v)
+ for ( v <- bndVersionPolicy ) { properties.setProperty(VERSIONPOLICY, v) }
if (bndNoUses) properties.setProperty(NOUSES, "true")
log debug "Using the following properties for BND: %s".format(properties)
properties
}
+
+ private def createBundle() {
+ val builder = new Builder
+ builder setClasspath classpath
+ builder setProperties properties
+ val jar = builder.build
+ jar write bndOutput.absolutePath
+ }
}
@@ -69,6 +69,12 @@ private[bnd4sbt] trait BNDPluginProperties extends ProjectAccessor {
protected def bndBundleVersion: String = project.version.toString
/**
+ * The value for <code>Fragment-Host</code>, wrapped in an <code>Option</code>. Defaults to <code>None</code>,
+ * i.e. no fragment is defined.
+ */
+ protected def bndFragmentHost: Option[String] = None
+
+ /**
* The value for <code>Bundle-Vendor</code>, wrapped in an <code>Option</code>. Defaults to <code>None</code>,
* i.e. no vendor is defined.
*/
@@ -27,6 +27,7 @@ class TestProject(info: ProjectInfo) extends ParentProject(info: ProjectInfo) {
class B(info: ProjectInfo) extends DefaultProject(info) with BNDPlugin {
lazy val osgiCore = "org.osgi" % "org.osgi.core" % "4.2.0" % "provided"
override def bndBundleActivator = Some("com.weiglewilczek.bnd4sbttest.b.internal.Activator")
+ override def bndFragmentHost = Some("x.y.z")
}
lazy val c = project("c", "c", new C(_))
@@ -20,5 +20,5 @@ class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
// Dependencies
// ===================================================================================================================
- lazy val bnd4sbt = "com.weiglewilczek.bnd4sbt" % "bnd4sbt" % "1.0.0.RC6"
+ lazy val bnd4sbt = "com.weiglewilczek.bnd4sbt" % "bnd4sbt" % "1.0.0.RC7"
}
@@ -1,3 +1,3 @@
#Project properties
-#Wed Jul 28 17:13:51 CEST 2010
+#Sun Aug 29 11:00:53 CEST 2010
plugin.uptodate=true

0 comments on commit 01b7e3d

Please sign in to comment.