Permalink
Browse files

closes #20: Changed bndClasspath property; also changed some other pr…

…operties and improved ScalaDoc.
  • Loading branch information...
1 parent 26c4984 commit c5498214233bd3fa59e15aa067481e4966c3888b Heiko Seeberger committed Jul 28, 2010
View
2 project/build.properties
@@ -3,6 +3,6 @@
project.organization=com.weiglewilczek.bnd4sbt
project.name=bnd4sbt
sbt.version=0.7.4
-project.version=1.0.0.RC5
+project.version=1.0.0.RC6
build.scala.versions=2.7.7
project.initialize=false
View
36 src/main/scala/BNDPlugin.scala
@@ -13,41 +13,51 @@ import java.util.Properties
import sbt.DefaultProject
/**
- * This BND plugin for SBT offers the following actions:
- * <ul>
- * <li>bndBundle: Creates an OSGi bundle out of this project by using BND</li>
- * </ul>
- * Additionally the package action is overridden with the bndBundle action.
+ * <p>This plug-in for <a href="code.google.com/p/simple-build-tool">SBT</a> lets you create OSGi bundles
+ * from your SBT projects by employing <a href="www.aqute.biz/Code/Bnd">BND</a>.</p>
+ * <p>It offers the <code>bndBundle</code> action and overrides the <code>package</code> action.</p>
*/
trait BNDPlugin extends DefaultProject with BNDPluginProperties {
- /** Creates an OSGi bundle out of this project by using BND. Initialized by bndBundleAction which can be overridden in order to modify the behavior. */
+ /**
+ * Creates an OSGi bundle from this project by using BND.
+ * Initialized by <code>bndBundleAction</code> which could be overridden in order to modify the behavior.
+ */
final lazy val bndBundle = bndBundleAction
- /** Creates an OSGi bundle out of this project by using BND. Attention: If you override this, you might loose the bnd4sbt functionality. */
+ /**
+ * Creates an OSGi bundle from this project by using BND.
+ * <b>Attention</b>: If you override this, you might loose the desired functionality!
+ */
protected def bndBundleAction =
task {
try {
createBundle()
log info "Created OSGi bundle at %s.".format(bndOutput)
None
- } catch {
+ }
+ catch {
case e =>
log error "Error when trying to create OSGi bundle: %s.".format(e.getMessage)
Some(e.getMessage)
}
} dependsOn compile describedAs "Creates an OSGi bundle out of this project by using BND."
- /** Overrides the package action with the bndBundle action. Attention: If you override this, you might loose the bnd4sbt functionality. */
+ /**
+ * Overrides the <code>package</code> action with the <code>bndBundle</code> action.
+ * <b>Attention</b>: If you override this, you might loose the desired functionality!
+ */
override protected def packageAction = bndBundle
- /** This SBT project. */
- final override protected[bnd4sbt] val project = this
+ /**
+ * This SBT project.
+ */
+ override protected[bnd4sbt] final val project = this
private def createBundle() {
val builder = new Builder
- builder setProperties properties
builder setClasspath classpath
+ builder setProperties properties
val jar = builder.build
jar write bndOutput.absolutePath
}
@@ -63,7 +73,7 @@ trait BNDPlugin extends DefaultProject with BNDPluginProperties {
// SBT packageOptions/ManifestAttributes
for {
- o <- packageOptions; if o.isInstanceOf[ManifestAttributes]
+ o <- packageOptions if o.isInstanceOf[ManifestAttributes]
a <- o.asInstanceOf[ManifestAttributes].attributes
} properties.setProperty(a._1.toString, a._2)
View
141 src/main/scala/properties.scala
@@ -7,27 +7,41 @@
*/
package com.weiglewilczek.bnd4sbt
-import sbt.{ DefaultProject, MavenStyleScalaPaths, PathFinder }
-import scala.collection.immutable.Set
+import sbt.{ DefaultProject, MavenStyleScalaPaths, Path, PathFinder}
+import sbt.Configurations._
/**
* Execution environments available for bnd4sbt. As Scala relies on Java 5, only Java 5 and later are supported.
*/
-object ExecutionEnvironments extends Enumeration {
- type ExecutionEnvironments = Value
+object ExecutionEnvironment extends Enumeration {
+
+ /**
+ * Type alias for the enumeration values. Use <code>import ExecutionEnvironment._</code> to make the
+ * enumeration values available under type <code>ExecutionEnvironment</code>.
+ */
+ type ExecutionEnvironment = Value
+
+ /**
+ * Execution environment for Java 5.
+ */
val Java5 = Value("J2SE-1.5")
+
+ /**
+ * Execution environment for Java 6.
+ */
val Java6 = Value("JavaSE-1.6")
}
/**
* Properties for BND with sensible defaults.
*/
private[bnd4sbt] trait BNDPluginProperties extends ProjectAccessor {
- import ExecutionEnvironments._
+ import ExecutionEnvironment._
/**
- * The value for Bundle-SymbolicName. Defaults to projectOrganization.projectName with duplicate subsequences
- * removed, e.g. "a.b.c" + "c-d" => "a.b.c.d". Recognized namespace separators are "." and "-".
+ * 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 "-".
*/
protected def bndBundleSymbolicName: String = {
def split(s: String) = s split """\.|-""" match {
@@ -44,59 +58,110 @@ private[bnd4sbt] trait BNDPluginProperties extends ProjectAccessor {
concat(name, Nil) mkString "."
}
- /** The value for Bundle-Name. Defaults to BNDPlugin.bndBundleSymbolicName. */
+ /**
+ * The value for <code>Bundle-Name</code>. Defaults to <code>bndBundleSymbolicName</code>.
+ */
protected def bndBundleName: String = bndBundleSymbolicName
- /** The value for Bundle-Version. Defaults to this project's version. */
- protected def bndBundleVersion = project.version.toString
+ /**
+ * The value for <code>Bundle-Version</code>. Defaults to this project's version.
+ */
+ protected def bndBundleVersion: String = project.version.toString
- /** The value for Bundle-Vendor, wrapped in an Option. Defaults to None, i.e. no vendor is defined. */
+ /**
+ * The value for <code>Bundle-Vendor</code>, wrapped in an <code>Option</code>. Defaults to <code>None</code>,
+ * i.e. no vendor is defined.
+ */
protected def bndBundleVendor: Option[String] = None
- /** The value for Bundle-License, wrapped in an Option. Defaults to None, i.e. no license is defined. */
+ /**
+ * The value for <code>Bundle-License</code>, wrapped in an <code>Option</code>. Defaults to <code>None</code>,
+ * i.e. no license is defined.
+ */
protected def bndBundleLicense: Option[String] = None
- /** The value for Bundle-RequiredExecutionEnvironment. Defaults to empty set, i.e. no execution environments are defined. */
- protected def bndExecutionEnvironment = Set[ExecutionEnvironments]()
+ /**
+ * The value for <code>Bundle-RequiredExecutionEnvironment</code>. Defaults to empty <code>Set</code>,
+ * i.e. no execution environments are defined.
+ */
+ protected def bndExecutionEnvironment: Set[ExecutionEnvironment] = Set.empty
- /** The value for Private-Package. Defaults to BNDPlugin.bndBundleSymbolicName.*, i.e. contains the root package and all subpackages. */
- protected def bndPrivatePackage = Seq(bndBundleSymbolicName + ".*")
+ /**
+ * 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.
+ */
+ protected def bndPrivatePackage: Seq[String] = "%s.*".format(bndBundleSymbolicName) :: Nil
- /** The value for Export-Package. Defaults to empty sequence, i.e. nothing is exported. */
- protected def bndExportPackage = Seq[String]()
+ /**
+ * The value for <code>Export-Package</code>. Defaults to empty <code>Seq</code>, i.e. nothing is exported.
+ */
+ protected def bndExportPackage: Seq[String] = Nil
- /** The value for Import-Package. Defaults to "*", i.e. everything is imported. */
- protected def bndImportPackage = Seq("*")
+ /**
+ * 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.
+ */
+ protected def bndImportPackage: Seq[String] =
+ "scala.*;version=\"[%1$s,%1$s]\"".format(project.buildScalaVersion) :: "*" :: Nil
- /** The value for Dynamic-ImportPackage. Defaults to empty sequence, i.e. nothing is imported dynamically. */
- protected def bndDynamicImportPackage = Seq[String]()
+ /**
+ * The value for <code>Dynamic-ImportPackage</code>. Defaults to empty <code>Seq</code>,
+ * i.e. nothing is imported dynamically.
+ */
+ protected def bndDynamicImportPackage: Seq[String] = Nil
- /** The value for Require-Bundle. Defaults to empty sequence, i.e. no bundles are required. */
- protected def bndRequireBundle = Seq[String]()
+ /**
+ * The value for <code>Require-Bundle</code>. Defaults to empty <code>Seq</code>, i.e. no bundles are required.
+ */
+ protected def bndRequireBundle: Seq[String] = Nil
- /** The value for Bundle-Actiavtor, wrapped in an Option. Defaults to None, i.e. no activator is defined. */
+ /**
+ * The value for <code>Bundle-Actiavtor</code>, wrapped in an <code>Option</code>. Defaults to <code>None</code>,
+ * i.e. no activator is defined.
+ */
protected def bndBundleActivator: Option[String] = None
- /** The value for Include-Resource. Defaults to the main resources. */
- protected def bndIncludeResource = Seq(project.mainResourcesPath.absolutePath)
+ /**
+ * The value for <code>Include-Resource</code>. Defaults to the main resources of this project.
+ */
+ protected def bndIncludeResource: Seq[String] = project.mainResourcesPath.absolutePath :: Nil
- /** Should the dependencies be embedded? Defaults to false. */
+ /**
+ * Should the dependencies be embedded? Defaults to <code>false</code>.
+ */
protected def bndEmbedDependencies = false
- /** The value for the versionpolicy directive, wrapped in an Option. Defaults to None, i.e. no version policy is defined. */
+ /**
+ * 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.
+ */
protected def bndVersionPolicy: Option[String] = None
- /** Should the nouses directive be applied? Defaults to false. */
+ /**
+ * Should the <code>nouses</code> directive be applied? Defaults to <code>false</code>.
+ */
protected def bndNoUses = false
- /** The fileName as part of BNDPlugin.bndOutput. Defaults to this project's defaultJarName. ATTENTION: Better not change this, but artifactBaseName! */
- protected def bndFileName = project.defaultJarName
+ /**
+ * 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>!
+ */
+ protected def bndFileName: String = project.defaultJarName
- /** The output path used by BND. Defaults to the outputPath of this project plus the value of BNDPlugin.bndFileName. ATTENTION: Better not change this, but the appropriate SBT default properties! */
- protected def bndOutput = project.outputPath / bndFileName
+ /**
+ * 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!
+ */
+ protected def bndOutput: Path = project.outputPath / bndFileName
- /** The classpath used by BND. Attention: Don't mistake this for the Bundle-Classpath! Defaults to the runClasspath of this project. */
- protected def bndClasspath: PathFinder = project.runClasspath
+ /**
+ * 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!
+ */
+ protected def bndClasspath: PathFinder = project.projectClasspath(Compile) +++ project.providedClasspath
private[bnd4sbt] def bundleClasspath =
if (bndEmbedDependencies) Set(".") ++ (project.publicClasspath.get filter { !_.isDirectory } map { _.name })
@@ -120,6 +185,8 @@ private[bnd4sbt] trait BNDPluginProperties extends ProjectAccessor {
*/
private[bnd4sbt] trait ProjectAccessor {
- /** The SBT project. */
+ /**
+ * The SBT project.
+ */
protected[bnd4sbt] val project: DefaultProject
}
View
11 test/a/src/test/scala/test.scala
@@ -0,0 +1,11 @@
+package com.weiglewilczek.bnd4sbttest.a
+
+import org.specs.Specification
+
+class ASpec extends Specification {
+ "A test" should {
+ "succeed" in {
+ 1 mustEqual 1
+ }
+ }
+}
View
13 test/project/build/Project.scala
@@ -1,13 +1,17 @@
-import com.weiglewilczek.bnd4sbt.BNDPlugin
+import com.weiglewilczek.bnd4sbt._
import sbt._
class TestProject(info: ProjectInfo) extends ParentProject(info: ProjectInfo) {
lazy val a = project("a", "a", new A(_))
+
class A(info: ProjectInfo) extends DefaultProject(info) with BNDPlugin {
- import com.weiglewilczek.bnd4sbt.ExecutionEnvironments._
+ import ExecutionEnvironment._
+
+ lazy val specs = "org.scala-tools.testing" % "specs" % "1.6.2.1" % "test"
+
override def bndBundleLicense = Some("Eclipse Public License v1.0")
- override def bndExportPackage = Seq("com.weiglewilczek.bnd4sbttest.a;version=1.0")
+ override def bndExportPackage = Seq("com.weiglewilczek.bnd4sbttest.a;version=\"1.0\"")
override def bndExecutionEnvironment = Set(Java5, Java6)
override def bndDynamicImportPackage = Seq("x.y.z")
override def bndVersionPolicy = Some("[$(@),$(@)]")
@@ -19,17 +23,20 @@ class TestProject(info: ProjectInfo) extends ParentProject(info: ProjectInfo) {
}
lazy val b = project("b", "b", new B(_), a)
+
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")
}
lazy val c = project("c", "c", new C(_))
+
class C(info: ProjectInfo) extends DefaultProject(info) {
lazy val commonsIO = "commons-io" % "commons-io" % "1.4"
}
lazy val d = project("d", "d", new D(_), c)
+
class D(info: ProjectInfo) extends DefaultProject(info) with BNDPlugin {
lazy val osgiCore = "org.osgi" % "org.osgi.core" % "4.2.0" % "provided"
lazy val commonsLogging = "commons-logging" % "commons-logging-api" % "1.1"
View
2 test/project/plugins/Plugins.scala
@@ -20,5 +20,5 @@ class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
// Dependencies
// ===================================================================================================================
- lazy val bnd4sbt = "com.weiglewilczek.bnd4sbt" % "bnd4sbt" % "1.0.0.RC5"
+ lazy val bnd4sbt = "com.weiglewilczek.bnd4sbt" % "bnd4sbt" % "1.0.0.RC6"
}
View
2 test/project/plugins/project/build.properties
@@ -1,3 +1,3 @@
#Project properties
-#Thu Jul 22 10:14:18 CEST 2010
+#Wed Jul 28 17:13:51 CEST 2010
plugin.uptodate=true

0 comments on commit c549821

Please sign in to comment.