Applied Stuart McColloch's patch for issue 121 - making Guice into an OSGi bundle, using BND.

git-svn-id: https://google-guice.googlecode.com/svn/trunk@510 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/build.properties b/build.properties
index fc56103..ca5f2d9 100644
--- a/build.properties
+++ b/build.properties
@@ -17,3 +17,5 @@
   com.google.inject.multibindings,\
   com.google.inject.commands
 test.class=com.google.inject.AllTests
+module=com.google.inject
+exclude.imports: !net.sf.cglib.*,!org.objectweb.asm.*
diff --git a/common.xml b/common.xml
index 6c62660..402e54d 100644
--- a/common.xml
+++ b/common.xml
@@ -7,10 +7,7 @@
   <!-- can be overridden at the command line with -Dversion=
        or in IDEA, in the ant properties dialog -->
   <property name="version" value="snapshot"/>
-  <property name="bundle.version" value="0.0.0.snapshot"/>
-  <tstamp prefix="datestamp">
-    <format property="dateAndTime" pattern="yyyy-MM-dd H:mm"/>
-  </tstamp>
+  <property name="api.version" value="1.0"/>
 
   <target name="compile" description="Compile Java source.">
     <mkdir dir="${build.dir}/classes"/>
@@ -24,39 +21,37 @@
     </copy>
   </target>
 
-  <target name="manifest"
-      description="Build a jar manifest so Guice can be used as an OSGi bundle">
-    <dirname property="guice_home" file="${ant.file.common}" />
-    <taskdef name="osgiBundleInfo" classname="org.knopflerfish.ant.taskdefs.bundle.BundleInfoTask"
-        classpath="${guice_home}/lib/build/OSGiBundleInfo.jar"/>
+  <target name="manifest" description="Generate OSGi manifest." depends="compile">
+    <dirname property="common.basedir" file="${ant.file.common}"/>
+    <taskdef resource="aQute/bnd/ant/taskdef.properties"
+      classpath="${common.basedir}/lib/build/bnd-0.0.255.jar"/>
 
-    <!-- extracts the packagelist for OSGi -->
-    <osgiBundleInfo exports="exports" imports="imports" defaultimports="com.google.inject"
-        stdimports="java.,net.sf.cglib,org.objectweb.asm,com.google.inject.InjectorImpl,com.google.inject.BindCommandProcessor">
-      <fileset dir="${basedir}">
-        <include name="src/**/*.java"/>
-        <!--<exclude name="src/com/google/inject/internal/**/*.java"/>-->
-      </fileset>
-    </osgiBundleInfo>
+    <fail unless="module" message="Missing 'module' property (use the primary package name in this jar)"/>
 
-    <mkdir dir="${build.dir}/META-INF"/>
-    <manifest file="${build.dir}/META-INF/MANIFEST.MF">
-      <attribute name="Manifest-Version" value="1.0"/>
-      <attribute name="Built-By" value="${user.name}"/>
-      <attribute name="Built-At" value="${datestamp.dateAndTime}"/>
+    <property name="Bundle-Name" value="${ant.project.name}"/>
+    <property name="Bundle-SymbolicName" value="${module}"/>
+    <property name="Bundle-Version" value="${replace;${version};^[^0-9];${api.version}.$0}"/>
 
-      <attribute name="Bundle-License" value="http://www.apache.org/licenses/LICENSE-2.0"/>
-      <attribute name="Import-Package" value="${imports}"/>
-      <attribute name="Export-Package" value="${exports}"/>
-      <attribute name="Bundle-Version" value="${bundle.version}"/>
-      <attribute name="Bundle-Copyright" value="Google Inc. (C) 2006"/>
-      <attribute name="Bundle-Name" value="${ant.project.name}"/>
-      <attribute name="Bundle-Description" value="Guice is a lightweight dependency injection framework for Java 5 and above"/>
-      <attribute name="Bundle-DocURL" value="http://code.google.com/p/google-guice/"/>
-      <attribute name="Bundle-Vendor" value="Google Inc."/>
-      <attribute name="Bundle-ManifestVersion" value="2"/>
-      <attribute name="Bundle-SymbolicName" value="${ant.project.name}"/>
-    </manifest>
+    <property name="Bundle-Description" value="Guice is a lightweight dependency injection framework for Java 5 and above"/>
+    <property name="Bundle-DocURL" value="http://code.google.com/p/google-guice/"/>
+    <property name="Bundle-Copyright" value="Copyright (C) 2006 Google Inc."/>
+    <property name="Bundle-License" value="http://www.apache.org/licenses/LICENSE-2.0"/>
+    <property name="Bundle-Vendor" value="Google Inc."/>
+
+    <property name="exclude.imports" value=""/>
+    <property name="guice.imports" value="com.google.inject.*;version=${api.version}"/>
+    <property name="Import-Package" value="${exclude.imports},${guice.imports},*;resolution:=optional"/>
+    <property name="Export-Package" value="${module}.*;version=${api.version}"/>
+    <property name="-nouses" value="true"/>
+    <property name="-removeheaders" value="Bnd-LastModified,Ignore-Package,Include-Resource,Private-Package,Tool"/>
+
+    <bndwrap jars="${build.dir}/classes" output="${build.dir}"/>
+
+    <unjar src="${build.dir}/classes.bar" dest="${build.dir}">
+      <patternset>
+        <include name="META-INF/MANIFEST.MF"/>
+      </patternset>
+    </unjar>
   </target>
 
   <target name="test.compile"
diff --git a/extensions/assistedinject/build.properties b/extensions/assistedinject/build.properties
index f7a30b2..e1f60a3 100644
--- a/extensions/assistedinject/build.properties
+++ b/extensions/assistedinject/build.properties
@@ -3,3 +3,4 @@
 test.dir=test
 build.dir=build
 test.class=com.google.inject.assistedinject.FactoryProviderTest
+module=com.google.inject.assistedinject
diff --git a/extensions/commands/build.properties b/extensions/commands/build.properties
index 4fa44e4..baa80d9 100644
--- a/extensions/commands/build.properties
+++ b/extensions/commands/build.properties
@@ -3,3 +3,4 @@
 test.dir=test
 build.dir=build
 test.class=com.google.inject.commands.intercepting.AllTests
+module=com.google.inject.commands.intercepting
diff --git a/extensions/multibindings/build.properties b/extensions/multibindings/build.properties
index 083b69a..9575ddb 100644
--- a/extensions/multibindings/build.properties
+++ b/extensions/multibindings/build.properties
@@ -3,3 +3,4 @@
 test.dir=test
 build.dir=build
 test.class=com.google.inject.multibindings.AllTests
+module=com.google.inject.multibindings
diff --git a/extensions/throwingproviders/build.properties b/extensions/throwingproviders/build.properties
index 0222b47..abcc096 100644
--- a/extensions/throwingproviders/build.properties
+++ b/extensions/throwingproviders/build.properties
@@ -3,3 +3,4 @@
 test.dir=test
 build.dir=build
 test.class=com.google.inject.throwingproviders.ThrowingProviderBinderTest
+module=com.google.inject.throwingproviders
diff --git a/guice.ipr b/guice.ipr
index 56a6b4c..45d3544 100644
--- a/guice.ipr
+++ b/guice.ipr
@@ -110,6 +110,15 @@
           <option name="LABEL_INDENT_SIZE" value="0" />
           <option name="LABEL_INDENT_ABSOLUTE" value="false" />
         </ADDITIONAL_INDENT_OPTIONS>
+        <ADDITIONAL_INDENT_OPTIONS fileType="js">
+          <option name="INDENT_SIZE" value="4" />
+          <option name="CONTINUATION_INDENT_SIZE" value="8" />
+          <option name="TAB_SIZE" value="4" />
+          <option name="USE_TAB_CHARACTER" value="false" />
+          <option name="SMART_TABS" value="false" />
+          <option name="LABEL_INDENT_SIZE" value="0" />
+          <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+        </ADDITIONAL_INDENT_OPTIONS>
       </value>
     </option>
     <option name="USE_PER_PROJECT_SETTINGS" value="true" />
@@ -453,7 +462,7 @@
       <module fileurl="file://$PROJECT_DIR$/extensions/throwingproviders/throwingproviders.iml" filepath="$PROJECT_DIR$/extensions/throwingproviders/throwingproviders.iml" />
     </modules>
   </component>
-  <component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="java version &quot;1.5.0_06&quot;" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="1.5" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/classes" />
   </component>
   <component name="ResourceManagerContainer">
diff --git a/lib/build/OSGiBundleInfo.jar b/lib/build/OSGiBundleInfo.jar
deleted file mode 100644
index fc631b0..0000000
--- a/lib/build/OSGiBundleInfo.jar
+++ /dev/null
Binary files differ
diff --git a/lib/build/bnd-0.0.255.jar b/lib/build/bnd-0.0.255.jar
new file mode 100644
index 0000000..6c4e0d5
--- /dev/null
+++ b/lib/build/bnd-0.0.255.jar
Binary files differ
diff --git a/servlet/build.properties b/servlet/build.properties
index 9722f8b..5d8e11d 100644
--- a/servlet/build.properties
+++ b/servlet/build.properties
@@ -3,3 +3,4 @@
 test.dir=test
 build.dir=build
 test.class=com.google.inject.servlet.ServletTest
+module=com.google.inject.servlet
diff --git a/spring/build.properties b/spring/build.properties
index 2ee6533..a0789d2 100644
--- a/spring/build.properties
+++ b/spring/build.properties
@@ -2,4 +2,4 @@
 test.dir=test
 build.dir=build
 test.class=com.google.inject.spring.SpringTest
-
+module=com.google.inject.spring
diff --git a/struts2/plugin/build.properties b/struts2/plugin/build.properties
index a155282..f1d0ef7 100644
--- a/struts2/plugin/build.properties
+++ b/struts2/plugin/build.properties
@@ -1,3 +1,4 @@
 lib.dir=../lib
 src.dir=src
 build.dir=build
+module=com.google.inject.struts2