Author: veithen
Date: Sat Feb  8 23:28:30 2014
New Revision: 1566170

URL: http://svn.apache.org/r1566170
Log:
Move the OSGiManifestResourceTransformer to a separate module and use code from 
Equinox to properly parse Import-Package and Export-Package directives.

Added:
    webservices/axiom/trunk/buildutils/shade-osgi/   (with props)
    webservices/axiom/trunk/buildutils/shade-osgi/pom.xml   (with props)
    webservices/axiom/trunk/buildutils/shade-osgi/src/
    webservices/axiom/trunk/buildutils/shade-osgi/src/main/
    webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/
    webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/
    webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/
    
webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/axiom/
    
webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/axiom/buildutils/
    
webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/axiom/buildutils/shade/
    
webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/axiom/buildutils/shade/osgi/
    
webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/axiom/buildutils/shade/osgi/OSGiManifestResourceTransformer.java
      - copied, changed from r1566147, 
webservices/axiom/trunk/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/OSGiManifestResourceTransformer.java
Removed:
    
webservices/axiom/trunk/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/OSGiManifestResourceTransformer.java
Modified:
    webservices/axiom/trunk/buildutils/paxexam-maven-plugin/pom.xml
    webservices/axiom/trunk/buildutils/pom.xml
    webservices/axiom/trunk/modules/axiom-dom/pom.xml
    webservices/axiom/trunk/modules/axiom-impl/pom.xml
    webservices/axiom/trunk/pom.xml

Modified: webservices/axiom/trunk/buildutils/paxexam-maven-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/buildutils/paxexam-maven-plugin/pom.xml?rev=1566170&r1=1566169&r2=1566170&view=diff
==============================================================================
--- webservices/axiom/trunk/buildutils/paxexam-maven-plugin/pom.xml (original)
+++ webservices/axiom/trunk/buildutils/paxexam-maven-plugin/pom.xml Sat Feb  8 
23:28:30 2014
@@ -50,13 +50,6 @@
     <build>
         <plugins>
             <plugin>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>1.5</source>
-                    <target>1.5</target>
-                </configuration>
-            </plugin>
-            <plugin>
                 <artifactId>maven-plugin-plugin</artifactId>
             </plugin>
         </plugins>

Modified: webservices/axiom/trunk/buildutils/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/buildutils/pom.xml?rev=1566170&r1=1566169&r2=1566170&view=diff
==============================================================================
--- webservices/axiom/trunk/buildutils/pom.xml (original)
+++ webservices/axiom/trunk/buildutils/pom.xml Sat Feb  8 23:28:30 2014
@@ -29,6 +29,34 @@
     <packaging>pom</packaging>
     <build>
         <plugins>
+            <!-- The build requires Java 1.6; therefore we can use that 
version for the build utils as well -->
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>animal-sniffer-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>check</id>
+                        <phase>verify</phase>
+                        <goals>
+                            <goal>check</goal>
+                        </goals>
+                        <configuration>
+                            <signature>
+                                <groupId>org.codehaus.mojo.signature</groupId>
+                                <artifactId>java16</artifactId>
+                                <version>1.0</version>
+                            </signature>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <artifactId>maven-site-plugin</artifactId>
                 <configuration>
@@ -40,5 +68,6 @@
     </build>
     <modules>
         <module>paxexam-maven-plugin</module>
+        <module>shade-osgi</module>
     </modules>
 </project>

Propchange: webservices/axiom/trunk/buildutils/shade-osgi/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Feb  8 23:28:30 2014
@@ -0,0 +1,4 @@
+.settings
+.classpath
+.project
+target

Added: webservices/axiom/trunk/buildutils/shade-osgi/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/buildutils/shade-osgi/pom.xml?rev=1566170&view=auto
==============================================================================
--- webservices/axiom/trunk/buildutils/shade-osgi/pom.xml (added)
+++ webservices/axiom/trunk/buildutils/shade-osgi/pom.xml Sat Feb  8 23:28:30 
2014
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<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/maven-v4_0_0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.ws.commons.axiom</groupId>
+        <artifactId>buildutils</artifactId>
+        <version>1.2.15-SNAPSHOT</version>
+    </parent>
+    <artifactId>shade-osgi</artifactId>
+    <name>Resource Transformer for OSGi Manifests</name>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-shade-plugin</artifactId>
+            <version>${shade.plugin.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.osgi</groupId>
+            <artifactId>org.eclipse.osgi</artifactId>
+            <version>3.7.1</version>
+        </dependency>
+    </dependencies>
+</project>

Propchange: webservices/axiom/trunk/buildutils/shade-osgi/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: 
webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/axiom/buildutils/shade/osgi/OSGiManifestResourceTransformer.java
 (from r1566147, 
webservices/axiom/trunk/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/OSGiManifestResourceTransformer.java)
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/axiom/buildutils/shade/osgi/OSGiManifestResourceTransformer.java?p2=webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/axiom/buildutils/shade/osgi/OSGiManifestResourceTransformer.java&p1=webservices/axiom/trunk/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/OSGiManifestResourceTransformer.java&r1=1566147&r2=1566170&rev=1566170&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-buildutils/src/main/java/org/apache/axiom/buildutils/OSGiManifestResourceTransformer.java
 (original)
+++ 
webservices/axiom/trunk/buildutils/shade-osgi/src/main/java/org/apache/axiom/buildutils/shade/osgi/OSGiManifestResourceTransformer.java
 Sat Feb  8 23:28:30 2014
@@ -16,11 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axiom.buildutils;
+package org.apache.axiom.buildutils.shade.osgi;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -30,8 +31,11 @@ import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 
+import org.apache.maven.plugins.shade.relocation.Relocator;
 import org.apache.maven.plugins.shade.resource.ResourceTransformer;
 import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.osgi.util.ManifestElement;
+import org.osgi.framework.BundleException;
 
 /**
  * Resource transformer that modifies the OSGi metadata in the manifest. It is 
designed for
@@ -51,7 +55,26 @@ public class OSGiManifestResourceTransfo
         return resource.equals(JarFile.MANIFEST_NAME);
     }
 
-    public void processResource(String resource, InputStream is, List 
relocators) throws IOException {
+    private static List<String> extractPackages(Attributes attributes, String 
header) throws IOException {
+        String value = attributes.getValue(header);
+        if (value == null) {
+            return Collections.emptyList();
+        } else {
+            ManifestElement[] elements;
+            try {
+                elements = ManifestElement.parseHeader("Export-Package", 
value);
+            } catch (BundleException ex) {
+                throw new IOException("Invalid bundle manifest", ex);
+            }
+            List<String> result = new ArrayList<String>(elements.length);
+            for (ManifestElement element : elements) {
+                result.add(element.getValue());
+            }
+            return result;
+        }
+    }
+    
+    public void processResource(String resource, InputStream is, 
List<Relocator> relocators) throws IOException {
         // We know that the first invocation of processResource is for the 
project's
         // manifest (see the existing ManifestResourceTransformer's source 
code)
         if (shadedManifest == null) {
@@ -60,16 +83,10 @@ public class OSGiManifestResourceTransfo
             Manifest manifest = new Manifest(is);
             Attributes includedAttributes = manifest.getMainAttributes();
             Attributes shadedAttributes = shadedManifest.getMainAttributes();
-            Set shadedImportPackages = new LinkedHashSet(Arrays.asList(
-                    shadedAttributes.getValue("Import-Package").split(",")));
-            String exportPackage = 
includedAttributes.getValue("Export-Package");
-            if (exportPackage != null) {
-                
shadedImportPackages.removeAll(Arrays.asList(exportPackage.split(",")));
-            }
-            String importPackage = 
includedAttributes.getValue("Import-Package");
-            if (importPackage != null) {
-                
shadedImportPackages.addAll(Arrays.asList(importPackage.split(",")));
-            }
+            Set<String> shadedImportPackages = new LinkedHashSet<String>(
+                    extractPackages(shadedAttributes, "Import-Package"));
+            shadedImportPackages.removeAll(extractPackages(includedAttributes, 
"Export-Package"));
+            shadedImportPackages.addAll(extractPackages(includedAttributes, 
"Import-Package"));
             shadedAttributes.putValue("Import-Package",
                     StringUtils.join(shadedImportPackages.iterator(), ","));
         }

Modified: webservices/axiom/trunk/modules/axiom-dom/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/pom.xml?rev=1566170&r1=1566169&r2=1566170&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/pom.xml (original)
+++ webservices/axiom/trunk/modules/axiom-dom/pom.xml Sat Feb  8 23:28:30 2014
@@ -138,7 +138,7 @@
                                 </includes>
                             </artifactSet>
                             <transformers>
-                                <transformer 
implementation="org.apache.axiom.buildutils.OSGiManifestResourceTransformer" />
+                                <transformer 
implementation="org.apache.axiom.buildutils.shade.osgi.OSGiManifestResourceTransformer"
 />
                             </transformers>
                             <createSourcesJar>true</createSourcesJar>
                         </configuration>
@@ -147,7 +147,7 @@
                 <dependencies>
                     <dependency>
                         <groupId>${project.groupId}</groupId>
-                        <artifactId>axiom-buildutils</artifactId>
+                        <artifactId>shade-osgi</artifactId>
                         <version>${project.version}</version>
                     </dependency>
                 </dependencies>

Modified: webservices/axiom/trunk/modules/axiom-impl/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/pom.xml?rev=1566170&r1=1566169&r2=1566170&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/pom.xml (original)
+++ webservices/axiom/trunk/modules/axiom-impl/pom.xml Sat Feb  8 23:28:30 2014
@@ -132,7 +132,7 @@
                                 </includes>
                             </artifactSet>
                             <transformers>
-                                <transformer 
implementation="org.apache.axiom.buildutils.OSGiManifestResourceTransformer" />
+                                <transformer 
implementation="org.apache.axiom.buildutils.shade.osgi.OSGiManifestResourceTransformer"
 />
                             </transformers>
                             <createSourcesJar>true</createSourcesJar>
                         </configuration>
@@ -141,7 +141,7 @@
                 <dependencies>
                     <dependency>
                         <groupId>${project.groupId}</groupId>
-                        <artifactId>axiom-buildutils</artifactId>
+                        <artifactId>shade-osgi</artifactId>
                         <version>${project.version}</version>
                     </dependency>
                 </dependencies>

Modified: webservices/axiom/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/pom.xml?rev=1566170&r1=1566169&r2=1566170&view=diff
==============================================================================
--- webservices/axiom/trunk/pom.xml (original)
+++ webservices/axiom/trunk/pom.xml Sat Feb  8 23:28:30 2014
@@ -657,6 +657,7 @@
                 <version>1.8</version>
                 <executions>
                     <execution>
+                        <id>check</id>
                         <phase>verify</phase>
                         <goals>
                             <goal>check</goal>


Reply via email to