Skip to content

Commit

Permalink
handle .* in fail on classes excluded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ktoso committed Aug 3, 2016
1 parent 32c639c commit 5b93fbe
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In order to add sbt-osgi as a plugin, just add the below setting to the relevant
```
// Other stuff
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.1")
```

If you want to use the latest and greatest features, you can instead have sbt depend on and locally build the current source snapshot by adding the following to your plugin definition file.
Expand Down Expand Up @@ -139,7 +139,8 @@ OsgiKeys.bundleActivator := Option("com.typesafe.sbt.osgidemo.internal.Activator
Contribution policy
-------------------

Contributions via GitHub pull requests are gladly accepted from their original author. Before we can accept pull requests, you will need to agree to the [Typesafe Contributor License Agreement](http://www.typesafe.com/contribute/cla) online, using your GitHub account - it takes 30 seconds.
Contributions via GitHub pull requests are gladly accepted from their original author.
Before we can accept pull requests, you will need to agree to the [Typesafe Contributor License Agreement](http://www.typesafe.com/contribute/cla) online, using your GitHub account - it takes 30 seconds.

License
-------
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/com/typesafe/sbt/osgi/Osgi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ private object Osgi {
s" Offending package: $pack\n")
}

validateAllPackagesDecidedAbout(internal, exported, allPackages.toList)
val i = internal.map(_.replaceAll(".*", ""))
val e = exported.map(_.replaceAll(".*", ""))
validateAllPackagesDecidedAbout(i, e, allPackages.toList)
}

def requireCapabilityTask(compiler: JavaTool, logger: Logger): String = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
lazy val test01 = (project in file (".")).enablePlugins(SbtOsgi)

organization := "com.typesafe.sbt"

name := "sbt-osgi-test"

version := "1.2.3"

libraryDependencies += "org.osgi" % "org.osgi.core" % "4.3.0" % "provided"

osgiSettings

OsgiKeys.bundleActivator := Some("com.typesafe.sbt.osgi.test.internal.Activator")

OsgiKeys.dynamicImportPackage := Seq("scala.*")


// we set an explicit internal package
OsgiKeys.privatePackage := Seq("com.typesafe.sbt.osgi.test.internal")

// we set what to export one specific one
OsgiKeys.exportPackage := Seq("com.typesafe.sbt.osgi.test.exportme.*")

// yet we "forget" on purpose to decide what to do about undecided!
// however we also enable the fail setting:
OsgiKeys.failOnUndecidedPackage := true


OsgiKeys.bundleRequiredExecutionEnvironment := Seq("JavaSE-1.7", "JavaSE-1.8")

apiURL := Some(url("http://typesafe.com"))

licenses += ("license" -> url("http://license.license"))


TaskKey[Unit]("verify-bundle") <<= OsgiKeys.bundle map { file =>
import java.io.IOException
import java.util.zip.ZipFile
import scala.io.Source
val newLine = System.getProperty("line.separator")
val zipFile = new ZipFile(file)
// Verify manifest
val manifestIn = zipFile.getInputStream(zipFile.getEntry("META-INF/MANIFEST.MF"))
try {
val lines = Source.fromInputStream(manifestIn).getLines().toList
val allLines = lines mkString newLine
val butWas = newLine + "But was:" + newLine + allLines
if (!(lines contains "Bundle-Activator: com.typesafe.sbt.osgi.test.internal.Activator"))
error("Expected 'Bundle-Activator: com.typesafe.sbt.osgi.test.internal.Activator' in manifest!" + butWas)
if (!(lines contains "Bundle-Description: sbt-osgi-test"))
sys.error("Expected 'Bundle-Description: sbt-osgi-test' in manifest!" + butWas)
if (!(lines contains "Bundle-DocURL: http://typesafe.com"))
sys.error("Expected 'Bundle-DocURL: http://typesafe.com' in manifest!" + butWas)
if (!(lines contains "Bundle-License: http://license.license;description=license"))
sys.error("Expected 'Bundle-License: http://license.license;description=license' in manifest!" + butWas)
if (!(lines contains "Bundle-Name: sbt-osgi-test"))
sys.error("Expected 'Bundle-Name: sbt-osgi-test' in manifest!" + butWas)
if (!(lines contains "Bundle-RequiredExecutionEnvironment: JavaSE-1.7,JavaSE-1.8"))
sys.error("Expected 'Bundle-RequiredExecutionEnvironment: JavaSE-1.7,JavaSE-1.8' in manifest!" + butWas)
if (!(lines contains "Bundle-Vendor: com.typesafe.sbt"))
sys.error("Expected 'Bundle-Vendor: com.typesafe.sbt' in manifest!" + butWas)
if (!(lines contains "Bundle-SymbolicName: com.typesafe.sbt.osgi.test"))
error("Expected 'Bundle-SymbolicName: com.typesafe.sbt.osgi.test' in manifest!" + butWas)
if (!(lines contains "Bundle-Version: 1.2.3"))
error("Expected 'Bundle-Version: 1.2.3' in manifest!" + butWas)
if (!(lines contains "DynamicImport-Package: scala.*"))
error("Expected 'DynamicImport-Package: scala.*' in manifest!" + butWas)
if (!(lines exists (_ containsSlice "Export-Package: com.typesafe.sbt.osgi.test")))
error("Expected 'Export-Package: com.typesafe.sbt.osgi.test' in manifest!" + butWas)
if (!(lines exists (l => (l containsSlice "org.osgi.framework") && (l containsSlice "Import-Package: "))))
error("""Expected 'Import-Package: ' and 'org.osgi.framework' in manifest!""" + butWas)
if (!(lines contains "Private-Package: com.typesafe.sbt.osgi.test.internal"))
error("Expected 'Private-Package: com.typesafe.sbt.osgi.test.internal' in manifest!" + butWas)
} catch {
case e: IOException => error("Expected to be able to read the manifest, but got exception!" + newLine + e)
} finally manifestIn.close()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.typesafe.sbt.osgi.test.exportme

class Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.typesafe.sbt.osgi.test
package internal

import org.osgi.framework._

class Activator extends BundleActivator {

def start(context: BundleContext): Unit = ()

def stop(context: BundleContext): Unit = ()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.typesafe.sbt.osgi.test.undecided

class Undecided
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-> verify-bundle
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

version in ThisBuild := "0.9.0"
version in ThisBuild := "0.9.1"

0 comments on commit 5b93fbe

Please sign in to comment.