You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2014/02/09 10:55:16 UTC

svn commit: r1566259 - in /webservices/axiom/trunk: modules/axiom-api/ modules/axiom-c14n/ modules/axiom-common-impl/ modules/axiom-dom/ modules/axiom-impl/ modules/axiom-jaxb/ systests/osgi-tests/ systests/osgi-tests/src/test/java/org/apache/axiom/test/

Author: veithen
Date: Sun Feb  9 09:55:15 2014
New Revision: 1566259

URL: http://svn.apache.org/r1566259
Log:
AXIOM-457: Add uses constraints to Export-Package directives to avoid LinkageErrors at runtime.

Added:
    webservices/axiom/trunk/systests/osgi-tests/src/test/java/org/apache/axiom/test/UsesConstraintsTest.java   (with props)
Modified:
    webservices/axiom/trunk/modules/axiom-api/pom.xml
    webservices/axiom/trunk/modules/axiom-c14n/pom.xml
    webservices/axiom/trunk/modules/axiom-common-impl/pom.xml
    webservices/axiom/trunk/modules/axiom-dom/pom.xml
    webservices/axiom/trunk/modules/axiom-impl/pom.xml
    webservices/axiom/trunk/modules/axiom-jaxb/pom.xml
    webservices/axiom/trunk/systests/osgi-tests/pom.xml

Modified: webservices/axiom/trunk/modules/axiom-api/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/pom.xml?rev=1566259&r1=1566258&r2=1566259&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/pom.xml (original)
+++ webservices/axiom/trunk/modules/axiom-api/pom.xml Sun Feb  9 09:55:15 2014
@@ -204,7 +204,6 @@
                 <configuration>
                     <excludeDependencies>true</excludeDependencies>
                     <instructions>
-                        <_nouses>true</_nouses>
                         <_removeheaders>Private-Package</_removeheaders>
                         <Export-Package>*;-noimport:=true</Export-Package>
                         <Import-Package>

Modified: webservices/axiom/trunk/modules/axiom-c14n/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-c14n/pom.xml?rev=1566259&r1=1566258&r2=1566259&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-c14n/pom.xml (original)
+++ webservices/axiom/trunk/modules/axiom-c14n/pom.xml Sun Feb  9 09:55:15 2014
@@ -64,7 +64,6 @@
                 <configuration>
                     <excludeDependencies>true</excludeDependencies>
                     <instructions>
-                        <_nouses>true</_nouses>
                         <_removeheaders>Private-Package</_removeheaders>
                         <Export-Package>*;-noimport:=true</Export-Package>
                     </instructions>

Modified: webservices/axiom/trunk/modules/axiom-common-impl/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/pom.xml?rev=1566259&r1=1566258&r2=1566259&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/pom.xml (original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/pom.xml Sun Feb  9 09:55:15 2014
@@ -61,7 +61,6 @@
                 <configuration>
                     <excludeDependencies>true</excludeDependencies>
                     <instructions>
-                        <_nouses>true</_nouses>
                         <Export-Package>*;-noimport:=true</Export-Package>
                         <Import-Package>*</Import-Package>
                     </instructions>

Modified: webservices/axiom/trunk/modules/axiom-dom/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/pom.xml?rev=1566259&r1=1566258&r2=1566259&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/pom.xml (original)
+++ webservices/axiom/trunk/modules/axiom-dom/pom.xml Sun Feb  9 09:55:15 2014
@@ -117,7 +117,6 @@
                 <configuration>
                     <excludeDependencies>true</excludeDependencies>
                     <instructions>
-                        <_nouses>true</_nouses>
                         <Private-Package>org.apache.axiom.*</Private-Package>
                         <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
                     </instructions>

Modified: webservices/axiom/trunk/modules/axiom-impl/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/pom.xml?rev=1566259&r1=1566258&r2=1566259&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/pom.xml (original)
+++ webservices/axiom/trunk/modules/axiom-impl/pom.xml Sun Feb  9 09:55:15 2014
@@ -111,7 +111,6 @@
                 <configuration>
                     <excludeDependencies>true</excludeDependencies>
                     <instructions>
-                        <_nouses>true</_nouses>
                         <Private-Package>org.apache.axiom.*</Private-Package>
                         <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
                     </instructions>

Modified: webservices/axiom/trunk/modules/axiom-jaxb/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-jaxb/pom.xml?rev=1566259&r1=1566258&r2=1566259&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-jaxb/pom.xml (original)
+++ webservices/axiom/trunk/modules/axiom-jaxb/pom.xml Sun Feb  9 09:55:15 2014
@@ -109,7 +109,6 @@
                 <configuration>
                     <excludeDependencies>true</excludeDependencies>
                     <instructions>
-                        <_nouses>true</_nouses>
                         <_removeheaders>Private-Package</_removeheaders>
                         <Export-Package>*;-noimport:=true</Export-Package>
                         <Import-Package>javax.xml.bind;version="[2.1,3)",javax.xml.bind.attachment;version="[2.1,3)",*</Import-Package>

Modified: webservices/axiom/trunk/systests/osgi-tests/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/systests/osgi-tests/pom.xml?rev=1566259&r1=1566258&r2=1566259&view=diff
==============================================================================
--- webservices/axiom/trunk/systests/osgi-tests/pom.xml (original)
+++ webservices/axiom/trunk/systests/osgi-tests/pom.xml Sun Feb  9 09:55:15 2014
@@ -109,6 +109,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.ops4j.pax.logging</groupId>
+            <artifactId>pax-logging-api</artifactId>
+            <version>1.7.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-jdk14</artifactId>
             <version>1.5.11</version>

Added: webservices/axiom/trunk/systests/osgi-tests/src/test/java/org/apache/axiom/test/UsesConstraintsTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/systests/osgi-tests/src/test/java/org/apache/axiom/test/UsesConstraintsTest.java?rev=1566259&view=auto
==============================================================================
--- webservices/axiom/trunk/systests/osgi-tests/src/test/java/org/apache/axiom/test/UsesConstraintsTest.java (added)
+++ webservices/axiom/trunk/systests/osgi-tests/src/test/java/org/apache/axiom/test/UsesConstraintsTest.java Sun Feb  9 09:55:15 2014
@@ -0,0 +1,133 @@
+/*
+ * 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.
+ */
+package org.apache.axiom.test;
+
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
+import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
+import static org.osgi.framework.Constants.FRAMEWORK_STORAGE;
+import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN;
+import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT;
+import static org.osgi.framework.Constants.IMPORT_PACKAGE;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * Tests that the Axiom bundles have <tt>Export-Package</tt> directives with the appropriate uses
+ * constraints so that the OSGi runtime can guarantee that packages are wired consistently. This is
+ * a regression test for <a href="https://issues.apache.org/jira/browse/AXIOM-457">AXIOM-457</a>.
+ * <p>
+ * The test installs two test bundles, one importing the <tt>javax.xml.stream</tt> package from the
+ * framework bundle (i.e. the JRE) and the other importing the same package from the ServiceMix StAX
+ * API bundle. Both bundles also import <tt>org.apache.axiom.om</tt>. Since the StAX API is used in
+ * the public Axiom API, this would lead to a class loading issue (reported as a
+ * {@link LinkageError} at runtime). With the appropriate uses constraints, the OSGi runtime should
+ * detect this when the bundles are resolved. The test registers a {@link FrameworkListener} to
+ * check that the expected error is generated.
+ */
+public class UsesConstraintsTest {
+    static class Listener implements FrameworkListener {
+        private final Pattern regex = Pattern.compile(
+                "Uses constraint violation\\. Unable to resolve module testbundle. \\[.*\\] because it is exposed to "
+                + "package 'javax\\.xml\\.stream' from modules org\\.apache\\.felix\\.framework \\[0\\] and "
+                + "org\\.apache\\.servicemix\\.specs\\.stax-api-1.0 \\[.*\\] via two dependency chains\\."
+                + ".*package=org\\.apache\\.axiom\\.om.*", Pattern.DOTALL); 
+        private final CountDownLatch latch = new CountDownLatch(1);
+        private boolean gotExpectedError;
+        
+        public void frameworkEvent(FrameworkEvent event) {
+            switch (event.getType()) {
+                case FrameworkEvent.STARTED:
+                    latch.countDown();
+                    break;
+                case FrameworkEvent.ERROR:
+                    if (regex.matcher(event.getThrowable().getMessage()).matches()) {
+                        System.out.println("Got expected");
+                        gotExpectedError = true;
+                    }
+            }
+        }
+        
+        void awaitStart() throws InterruptedException {
+            latch.await(10, TimeUnit.SECONDS);
+        }
+        
+        boolean gotExpectedError() {
+            return gotExpectedError;
+        }
+    }
+    
+    @Test
+    public void test() throws Exception {
+        System.setProperty("java.protocol.handler.pkgs", "org.ops4j.pax.url");
+        Map<String,Object> p = new HashMap<String,Object>(); // createFrameworkProperties();
+        p.put(FRAMEWORK_STORAGE, new File("target/felix").getAbsolutePath());
+        p.put(FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
+        FrameworkFactory frameworkFactory = new org.apache.felix.framework.FrameworkFactory();
+        Framework framework = frameworkFactory.newFramework(p);
+        framework.init();
+        BundleContext context = framework.getBundleContext();
+        Listener listener = new Listener();
+        context.addFrameworkListener(listener);
+        List<Bundle> bundles = new ArrayList<Bundle>();
+        bundles.add(context.installBundle("link:classpath:org.ops4j.pax.logging.pax-logging-api.link"));
+        bundles.add(context.installBundle("link:classpath:org.apache.geronimo.specs.geronimo-activation_1.1_spec.link"));
+        bundles.add(context.installBundle("link:classpath:org.apache.servicemix.specs.stax-api-1.0.link"));
+        bundles.add(context.installBundle("link:classpath:stax2-api.link"));
+        bundles.add(context.installBundle("link:classpath:woodstox-core-asl.link"));
+        bundles.add(context.installBundle("link:classpath:org.apache.james.apache-mime4j-core.link"));
+        bundles.add(context.installBundle("link:classpath:org.apache.ws.commons.axiom.axiom-api.link"));
+        // This bundle will be wired to the javax.xml.stream package exported by the ServiceMix stax-api bundle.
+        bundles.add(context.installBundle(streamBundle(bundle()
+                .set(BUNDLE_SYMBOLICNAME, "testbundle1")
+                .set(IMPORT_PACKAGE, "org.apache.axiom.om, javax.xml.stream; version=1.0")
+                .build()).getURL()));
+        // This bundle will be wired to the javax.xml.stream package exported by the framework bundle
+        bundles.add(context.installBundle(streamBundle(bundle()
+                .set(BUNDLE_SYMBOLICNAME, "testbundle2")
+                .set(IMPORT_PACKAGE, "org.apache.axiom.om, javax.xml.stream; version=\"[0.0.0,1.0)\"")
+                .build()).getURL()));
+        for (Bundle bundle : bundles) {
+            bundle.start();
+        }
+        framework.start();
+        try {
+            listener.awaitStart();
+            assertTrue("Uses constraint violation expected", listener.gotExpectedError());
+        } finally {
+            framework.stop();
+        }
+    }
+}

Propchange: webservices/axiom/trunk/systests/osgi-tests/src/test/java/org/apache/axiom/test/UsesConstraintsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native