Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
Merge branch '1-hseeberger'
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiko Seeberger committed May 7, 2010
2 parents 4c9493e + 14d16e4 commit 603957c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
project.organization=com.weiglewilczek
project.name=bnd4sbt
sbt.version=0.7.3
project.version=0.1
project.version=0.2
build.scala.versions=2.7.7
project.initialize=false
13 changes: 7 additions & 6 deletions project/build/Project.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sbt._

class Bnd4SbtPluginProject(info: ProjectInfo) extends PluginProject(info) {
class Project(info: ProjectInfo) extends PluginProject(info) {

lazy val aquteRepo = "aQute Repository" at "http://www.aqute.biz/repo"
lazy val localMavenRepo = "Local Maven Repository" at "file://%s/.m2/repository".format(Path.userHome)
lazy val aquteRepo = "aQute Maven Repository" at "http://www.aqute.biz/repo"

lazy val bnd = "biz.aQute" % "bndlib" % "0.0.384"
lazy val specs = "org.scala-tools.testing" % "specs" % "1.6.2.1" % "test"
lazy val junit = "junit" % "junit" % "4.7" % "test"
lazy val mockito = "org.mockito" % "mockito-all" % "1.8.4" % "test"
lazy val bnd = "biz.aQute" % "bndlib" % "0.0.384"
lazy val specs = "org.scala-tools.testing" % "specs" % "1.6.2.1" % "test"
lazy val junit = "junit" % "junit" % "4.7" % "test"
lazy val mockito = "org.mockito" % "mockito-all" % "1.8.4" % "test"
}
25 changes: 19 additions & 6 deletions src/main/scala/BNDPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,38 @@ import aQute.lib.osgi.Builder
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.
*/
trait BNDPlugin extends DefaultProject with BNDPluginProperties {

/** Creates an OSGi bundle out of this project by using BND. */
/** Creates an OSGi bundle out of this project by using BND. Initialized by bndBundleAction which can be overridden in order to modify the behavior. */
lazy val bndBundle = bndBundleAction

/** Creates an OSGi bundle out of this project by using BND. Override to modify the behavior of the bndBundle action. */
protected def bndBundleAction =
task {
try {
createBundle()
log info "Created OSGi bundle at %s.".format(bndOutput)
None
} catch { case e =>
log error "Error when trying to create OSGi bundle: %s.".format(e.getMessage)
Some(e.getMessage)
} 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."

protected val project = this

/** Overrides the package action with the bndBundle action. */
override protected def packageAction = bndBundle

/** This SBT project. */
override protected val project = this

private def createBundle() {
val builder = new Builder
builder setProperties properties
Expand All @@ -48,6 +59,8 @@ trait BNDPlugin extends DefaultProject with BNDPluginProperties {
properties.setProperty("Private-Package", bndPrivatePackage mkString ",")
properties.setProperty("Export-Package", bndExportPackage mkString ",")
properties.setProperty("Import-Package", bndImportPackage mkString ",")
properties.setProperty("Include-Resource", bndIncludeResource mkString ",")
log debug "Using the following properties for BND: %s".format(properties)
properties
}
}
19 changes: 15 additions & 4 deletions src/main/scala/BNDPluginProperties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ package com.weiglewilczek.bnd4sbt
import sbt.MavenStyleScalaPaths
import scala.collection.Set

private[bnd4sbt] trait BNDPluginProperties extends WithSBTProject {
/**
* Properties for BND with sensible defaults.
*/
private[bnd4sbt] trait BNDPluginProperties extends ProjectAccessor {

/**
* The value for Bundle-SymbolicName. Defaults to projectOrganization.projectName with duplicate subsequences
Expand Down Expand Up @@ -41,10 +44,13 @@ private[bnd4sbt] trait BNDPluginProperties extends WithSBTProject {
protected def bndPrivatePackage = Set("*")

/** The value for Export-Package. Defaults to empty set, i.e. nothing is exported. */
protected def bndExportPackage: Set[String] = Set.empty
protected def bndExportPackage = Set[String]()

/** The value for Import-Package. Defaults to "*", i.e. everything is imported. */
protected def bndImportPackage: Set[String] = Set("*")
protected def bndImportPackage = Set("*")

/** The value for Include-Resource. Defaults to the main resources. */
protected def bndIncludeResource: Set[String] = Set(project.mainResourcesPath.relativePath)

/** The classpath used by BND. Defaults to the mainCompilePath of this project. */
protected def bndClasspath = project.mainCompilePath
Expand All @@ -56,6 +62,11 @@ private[bnd4sbt] trait BNDPluginProperties extends WithSBTProject {
protected def bndFileName = "%s-%s.jar".format(project.name, project.version)
}

private[bnd4sbt] trait WithSBTProject {
/**
* Gives access to a SBT project.
*/
private[bnd4sbt] trait ProjectAccessor {

/** The SBT project. */
protected val project: MavenStyleScalaPaths
}
10 changes: 5 additions & 5 deletions src/test/scala/BNDPluginPropertiesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BNDPluginPropertiesSpec extends SpecificationWithJUnit with Mockito {

"return organization.name if organization does not end with a sequence name begins with" in {
new BNDPluginProperties {
val project = mock[MavenStyleScalaPaths]
override val project = mock[MavenStyleScalaPaths]
project.organization returns "organization"
project.name returns "name"
bndBundleSymbolicName mustEqual "organization.name"
Expand All @@ -26,7 +26,7 @@ class BNDPluginPropertiesSpec extends SpecificationWithJUnit with Mockito {

"return a.b.c.d if organization is a.b.c and name is c.d" in {
new BNDPluginProperties {
val project = mock[MavenStyleScalaPaths]
override val project = mock[MavenStyleScalaPaths]
project.organization returns "a.b.c"
project.name returns "c.d"
bndBundleSymbolicName mustEqual "a.b.c.d"
Expand All @@ -35,7 +35,7 @@ class BNDPluginPropertiesSpec extends SpecificationWithJUnit with Mockito {

"return a.b.c.d if organization is a.b.c and name is c-d" in {
new BNDPluginProperties {
val project = mock[MavenStyleScalaPaths]
override val project = mock[MavenStyleScalaPaths]
project.organization returns "a.b.c"
project.name returns "c-d"
bndBundleSymbolicName mustEqual "a.b.c.d"
Expand All @@ -44,7 +44,7 @@ class BNDPluginPropertiesSpec extends SpecificationWithJUnit with Mockito {

"return a.b.c.d.e if organization is a.b.c.d and name is c-d.e" in {
new BNDPluginProperties {
val project = mock[MavenStyleScalaPaths]
override val project = mock[MavenStyleScalaPaths]
project.organization returns "a.b.c.d"
project.name returns "c-d.e"
bndBundleSymbolicName mustEqual "a.b.c.d.e"
Expand All @@ -53,7 +53,7 @@ class BNDPluginPropertiesSpec extends SpecificationWithJUnit with Mockito {

"return a.b.c.b.c if organization is a-b and name is c.b-c" in {
new BNDPluginProperties {
val project = mock[MavenStyleScalaPaths]
override val project = mock[MavenStyleScalaPaths]
project.organization returns "a-b"
project.name returns "c.b-c"
bndBundleSymbolicName mustEqual "a.b.c.b.c"
Expand Down

0 comments on commit 603957c

Please sign in to comment.