From b75395949cab09decd74400180870f2f6f6a79a5 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Wed, 21 Oct 2015 16:05:43 +0000
Subject: [PATCH] OPENDJ-2226 PR-96 Make jar modules OSGI ready

---
 opendj-sdk/opendj-rest2ldap/pom.xml     |    9 ++
 opendj-sdk/opendj-config/pom.xml        |   34 +++++++-
 opendj-sdk/pom.xml                      |    7 +
 opendj-sdk/opendj-core/pom.xml          |   23 ++++-
 opendj-sdk/opendj-grizzly/pom.xml       |   20 +++-
 opendj-sdk/opendj-server-legacy/pom.xml |  119 +++++++++++++++++++++++++++--
 opendj-sdk/opendj-cli/pom.xml           |   24 ++++-
 7 files changed, 200 insertions(+), 36 deletions(-)

diff --git a/opendj-sdk/opendj-cli/pom.xml b/opendj-sdk/opendj-cli/pom.xml
index fb39c3a..3d1c4ea 100644
--- a/opendj-sdk/opendj-cli/pom.xml
+++ b/opendj-sdk/opendj-cli/pom.xml
@@ -36,7 +36,7 @@
   <description>
     This module includes CLI API for implementing CLI applications.
   </description>
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
   <dependencies>
      <dependency>
       <groupId>org.forgerock.opendj</groupId>
@@ -64,14 +64,16 @@
       <groupId>org.freemarker</groupId>
       <artifactId>freemarker</artifactId>
       <version>2.3.21</version>
+      <scope>provided</scope>
     </dependency>
   </dependencies>
+
   <properties>
-    <opendj.osgi.import>
-      com.sun.security.auth*;resolution:=optional,
-      *
-    </opendj.osgi.import>
+    <opendj.osgi.import.additional>
+      org.forgerock.opendj.*;provide:=true
+    </opendj.osgi.import.additional>
   </properties>
+
   <build>
     <plugins>
     <plugin>
@@ -99,8 +101,20 @@
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>cobertura-maven-plugin</artifactId>
       </plugin>
+
+      <!-- Creates opendj-cli bundle -->
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Export-Package>com.forgerock.opendj.cli</Export-Package>
+          </instructions>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
+
   <reporting>
     <plugins>
       <plugin>
diff --git a/opendj-sdk/opendj-config/pom.xml b/opendj-sdk/opendj-config/pom.xml
index bf7a097..a07357b 100644
--- a/opendj-sdk/opendj-config/pom.xml
+++ b/opendj-sdk/opendj-config/pom.xml
@@ -37,8 +37,7 @@
     This module includes Configuration APIs for implementing LDAP Directory
     client and server applications.
   </description>
-  <!-- Change to bundle when/if we have a need -->
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
   <dependencies>
     <dependency>
       <groupId>org.forgerock.commons</groupId>
@@ -76,19 +75,38 @@
       <version>${project.version}</version>
     </dependency>
   </dependencies>
+
   <properties>
-    <opendj.osgi.import>
-      com.sun.security.auth*;resolution:=optional,
-      *
-    </opendj.osgi.import>
+    <opendj.osgi.import.additional>
+      org.forgerock.opendj.*;provide:=true
+    </opendj.osgi.import.additional>
   </properties>
+
   <build>
+    <resources>
+      <!-- Main resources -->
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>false</filtering>
+      </resource>
+      <!-- Generated resources -->
+      <resource>
+        <directory>${project.build.directory}/generated-resources</directory>
+        <filtering>false</filtering>
+        <includes>
+          <include>**/*.properties</include>
+          <include>**/org.forgerock.opendj.config.AbstractManagedObjectDefinition</include>
+        </includes>
+      </resource>
+    </resources>
+
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <executions>
           <execution>
+            <id>generate-test-jar</id>
             <goals>
               <goal>test-jar</goal>
             </goals>
@@ -143,6 +161,10 @@
         </executions>
       </plugin>
       <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+      </plugin>
+      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
       </plugin>
diff --git a/opendj-sdk/opendj-core/pom.xml b/opendj-sdk/opendj-core/pom.xml
index c755ab2..bd5aac5 100644
--- a/opendj-sdk/opendj-core/pom.xml
+++ b/opendj-sdk/opendj-core/pom.xml
@@ -21,7 +21,7 @@
   !
   ! CDDL HEADER END
   !
-  !      Copyright 2011-2014 ForgeRock AS
+  !      Copyright 2011-2015 ForgeRock AS
   !    
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -64,10 +64,9 @@
     </dependency>
   </dependencies>
   <properties>
-    <opendj.osgi.import>
-      com.sun.security.auth*;resolution:=optional,
-      *
-    </opendj.osgi.import>
+    <opendj.osgi.import.additional>
+      com.sun.security.auth*;resolution:=optional
+    </opendj.osgi.import.additional>
   </properties>
   <build>
     <plugins>
@@ -88,11 +87,23 @@
           </execution>
         </executions>
       </plugin>
+
+      <!-- Creates opendj-core bundle -->
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
-        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>
+              com.forgerock.opendj.util,
+              org.forgerock.opendj.io,
+              org.forgerock.opendj.ldap*,
+              org.forgerock.opendj.ldif
+            </Export-Package>
+          </instructions>
+        </configuration>
       </plugin>
+
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
diff --git a/opendj-sdk/opendj-grizzly/pom.xml b/opendj-sdk/opendj-grizzly/pom.xml
index cfb188d..e4adbe0 100644
--- a/opendj-sdk/opendj-grizzly/pom.xml
+++ b/opendj-sdk/opendj-grizzly/pom.xml
@@ -21,7 +21,7 @@
   !
   ! CDDL HEADER END
   !
-  !      Copyright 2013 ForgeRock AS
+  !      Copyright 2013-2015 ForgeRock AS
   !    
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -70,12 +70,13 @@
       <scope>test</scope>
     </dependency>
   </dependencies>
+
   <properties>
-    <opendj.osgi.import>
-      com.sun.security.auth*;resolution:=optional,
-      *
-    </opendj.osgi.import>
+    <opendj.osgi.import.additional>
+      org.forgerock.opendj.*;provide:=true
+    </opendj.osgi.import.additional>
   </properties>
+
   <build>
     <plugins>
       <plugin>
@@ -98,7 +99,14 @@
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
-        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <!-- Export only public APIs of this module-->
+            <Export-Package>
+              org.forgerock.opendj.grizzly*
+            </Export-Package>
+          </instructions>
+        </configuration>
       </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
diff --git a/opendj-sdk/opendj-rest2ldap/pom.xml b/opendj-sdk/opendj-rest2ldap/pom.xml
index 160f5c7..e4367e1 100644
--- a/opendj-sdk/opendj-rest2ldap/pom.xml
+++ b/opendj-sdk/opendj-rest2ldap/pom.xml
@@ -30,6 +30,10 @@
     <packaging>bundle</packaging>
     <properties>
         <checkstyleHeaderLocation>org/forgerock/checkstyle/default-java-header</checkstyleHeaderLocation>
+        <opendj.osgi.import.additional>
+            org.forgerock.opendj.*;provide:=true,
+            org.forgerock.json.*;provide:=true
+        </opendj.osgi.import.additional>
     </properties>
     <dependencies>
         <dependency>
@@ -60,6 +64,11 @@
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>org.forgerock.opendj.rest2ldap</Export-Package>
+                    </instructions>
+                </configuration>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
diff --git a/opendj-sdk/opendj-server-legacy/pom.xml b/opendj-sdk/opendj-server-legacy/pom.xml
index 8fd8e60..f985a24 100644
--- a/opendj-sdk/opendj-server-legacy/pom.xml
+++ b/opendj-sdk/opendj-server-legacy/pom.xml
@@ -83,6 +83,12 @@
     <!-- If we release this project, we need to include the Forgerock binary license -->
     <include.binary.license>${project.build.directory}/legal-notices/</include.binary.license>
 
+    <!-- Additional OSGI import package for this module -->
+    <opendj.osgi.import.additional>
+      org.forgerock.opendj.*;provide:=true,
+      org.forgerock.json.*;provide:=true
+    </opendj.osgi.import.additional>
+
   </properties>
 
   <dependencies>
@@ -106,11 +112,6 @@
       <artifactId>opendj-server</artifactId>
       <version>${project.version}</version>
     </dependency>
-    <dependency>
-      <groupId>org.forgerock.opendj</groupId>
-      <artifactId>opendj-legacy</artifactId>
-      <version>${project.version}</version>
-    </dependency>
 
     <dependency>
       <groupId>org.forgerock.opendj</groupId>
@@ -170,9 +171,9 @@
       </exclusions>
     </dependency>
     <dependency>
-      <groupId>javax.mail</groupId>
-      <artifactId>mail</artifactId>
-      <version>1.4.7</version>
+      <groupId>com.sun.mail</groupId>
+      <artifactId>javax.mail</artifactId>
+      <version>1.5.1</version>
     </dependency>
 
     <!-- Tests -->
@@ -202,6 +203,12 @@
       <version>${project.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.freemarker</groupId>
+      <artifactId>freemarker</artifactId>
+      <version>2.3.21</version>
+      <scope>test</scope>
+    </dependency>
 
     <!-- Databases -->
     <dependency>
@@ -346,14 +353,14 @@
         </configuration>
       </plugin>
 
-      <!-- Unpack configuration files from opendj-maven-plugin -->
-      <!-- This plugin could be removed once the migration to the new config framework will be done -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
         <executions>
+          <!-- Unpack configuration files from opendj-maven-plugin -->
+          <!-- This plugin could be removed once the migration to the new config framework will be done -->
           <execution>
-            <id>unpack</id>
+            <id>unpack-config-files</id>
             <phase>generate-sources</phase>
             <goals>
               <goal>unpack</goal>
@@ -372,6 +379,29 @@
               </artifactItems>
             </configuration>
           </execution>
+
+          <!-- Unpack legacy classes to include them in main jar.
+               This "hacked" approach is needed since using the maven shade plugin
+               is too complex with this multi-artefact maven module. -->
+          <execution>
+            <id>unpack-legacy-classes</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>unpack</goal>
+            </goals>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.forgerock.opendj</groupId>
+                  <artifactId>opendj-legacy</artifactId>
+                  <version>${project.version}</version>
+                  <type>jar</type>
+                  <overWrite>true</overWrite>
+                  <outputDirectory>${project.build.directory}/classes</outputDirectory>
+                </artifactItem>
+              </artifactItems>
+            </configuration>
+          </execution>
         </executions>
       </plugin>
 
@@ -656,6 +686,59 @@
       </plugin>
 
       <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <executions>
+          <!-- Create opendj-slf4j-adapter manifest -->
+          <execution>
+            <id>opendj-slf4j-adapter-manifest</id>
+            <goals>
+              <goal>manifest</goal>
+            </goals>
+            <configuration>
+              <buildDirectory>${project.build.directory}/slf4j-adapter-manifest/META-INF</buildDirectory>
+              <manifestLocation>${project.build.directory}/slf4j-adapter-manifest/META-INF</manifestLocation>
+              <instructions>
+                <!-- Export only slf4j adapter -->
+                <Export-Package>org.opends.server.loggers.slf4j</Export-Package>
+                <Import-Package>
+                  org.forgerock.i18n,
+                  org.forgerock.i18n.slf4j,
+                  org.opends.messages,
+                  org.opends.server.loggers,
+                  org.slf4j,
+                  org.slf4j.helpers,
+                  org.slf4j.spi
+                </Import-Package>
+              </instructions>
+            </configuration>
+          </execution>
+
+          <!-- Create OpenDJ manifest -->
+          <execution>
+            <id>opendj-manifest</id>
+            <goals>
+              <goal>manifest</goal>
+            </goals>
+            <configuration>
+              <instructions>
+                <Bundle-Version>${project.version}</Bundle-Version>
+                <!-- Do not export packages of this module -->
+                <Export-Package>!*</Export-Package>
+                <!-- Import je changelog since it is not shipped in the main jar -->
+                <Import-Package>
+                  org.opends.server.replication.server.changelog.je,
+                  javax.jnlp,
+                  netscape.ldap,
+                  ${opendj.osgi.import}
+                </Import-Package>
+              </instructions>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <plugin>
         <artifactId>maven-jar-plugin</artifactId>
         <executions>
           <!-- Package boostrap jar - contains only a manifest with classpath for the server -->
@@ -761,6 +844,10 @@
                 <include>**/org/slf4j/**</include>
                 <include>**/org/opends/server/loggers/slf4j/**</include>
               </includes>
+              <archive>
+                <addMavenDescriptor>false</addMavenDescriptor>
+                <manifestFile>${project.build.directory}/slf4j-adapter-manifest/META-INF/MANIFEST.MF</manifestFile>
+              </archive>
             </configuration>
           </execution>
           <!-- Package JE backend and changelog jar -->
@@ -796,6 +883,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
@@ -814,6 +902,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
@@ -832,6 +921,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
@@ -850,6 +940,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
@@ -868,6 +959,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
@@ -886,6 +978,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
@@ -904,6 +997,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
@@ -922,6 +1016,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
@@ -940,6 +1035,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
@@ -978,6 +1074,7 @@
               <archive>
                 <addMavenDescriptor>false</addMavenDescriptor>
                 <index>true</index>
+                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
               </archive>
             </configuration>
           </execution>
diff --git a/opendj-sdk/pom.xml b/opendj-sdk/pom.xml
index 0d266c3..b09f9fe 100644
--- a/opendj-sdk/pom.xml
+++ b/opendj-sdk/pom.xml
@@ -125,8 +125,6 @@
      | it change the version policy from == + to == =+  [2.0,3) [2.0,2.1)
     -->
     <opendj.osgi.import>
-      org.forgerock.opendj.*;provide:=true,
-      org.forgerock.json.*;provide:=true,
       ${opendj.osgi.import.additional},
       *
     </opendj.osgi.import>
@@ -199,6 +197,11 @@
                       </_removeheaders>
                       <Import-Package>${opendj.osgi.import}</Import-Package>
                   </instructions>
+                  <archive>
+                    <addMavenDescriptor>false</addMavenDescriptor>
+                    <index>true</index>
+                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+                  </archive>
               </configuration>
           </plugin>
         <plugin>

--
Gitblit v1.10.0