You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:30:47 UTC

[sling-org-apache-sling-tooling-support-source] 06/14: SLING-6256 skip bundle fragments for listing source references (as they are listed with their host bundle anyways)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-source.git

commit 80aacb944ba216b578ca84fcbb0f79a53ceb2ff6
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Tue Nov 8 16:09:53 2016 +0000

    SLING-6256 skip bundle fragments for listing source references (as they are listed with their host bundle anyways)
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1768719 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                                        |  2 ++
 .../support/source/impl/FelixJettySourceReferenceFinder.java   | 10 ++++++++--
 .../tooling/support/source/impl/SourceReferencesServlet.java   |  7 +++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index cd43f91..59c2f31 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,9 +69,11 @@
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
+        <!-- override version to OSGi 4.3.0 to support BundleRevision -->
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
+            <version>4.3.0</version>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
diff --git a/src/main/java/org/apache/sling/tooling/support/source/impl/FelixJettySourceReferenceFinder.java b/src/main/java/org/apache/sling/tooling/support/source/impl/FelixJettySourceReferenceFinder.java
index 704cfd8..e9be471 100644
--- a/src/main/java/org/apache/sling/tooling/support/source/impl/FelixJettySourceReferenceFinder.java
+++ b/src/main/java/org/apache/sling/tooling/support/source/impl/FelixJettySourceReferenceFinder.java
@@ -29,11 +29,15 @@ import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.commons.io.IOUtils;
 import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 public class FelixJettySourceReferenceFinder implements SourceReferenceFinder {
 
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
     @Override
     public List<SourceReference> findSourceReferences(Bundle bundle) throws SourceReferenceException {
         // the org.apache.felix.http.jetty bundle does not retain references to the source bundles
@@ -44,11 +48,12 @@ public class FelixJettySourceReferenceFinder implements SourceReferenceFinder {
             
         final Object jettyVersion = bundle.getHeaders().get("X-Jetty-Version");
         if ( !(jettyVersion instanceof String) ) {
+            log.warn("Could not retrieve Jetty version from bundle '{}' because header 'X-Jetty-Version' is not set!", bundle);
             return Collections.emptyList();
         }
-        Enumeration entries = bundle.findEntries("META-INF/maven", "pom.xml", true);
+        Enumeration<URL> entries = bundle.findEntries("META-INF/maven", "pom.xml", true);
         if (entries != null && entries.hasMoreElements()) {
-            URL entry = (URL)entries.nextElement();
+            URL entry = entries.nextElement();
             InputStream pom = null;
             try {
                 pom = entry.openStream();
@@ -74,6 +79,7 @@ public class FelixJettySourceReferenceFinder implements SourceReferenceFinder {
             }
             
         } else {
+            log.warn("Could not find a pom.xml in bundle '{}'!", bundle);
             return Collections.emptyList();
         }
     }
diff --git a/src/main/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServlet.java b/src/main/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServlet.java
index a6ffb39..f19cdf7 100644
--- a/src/main/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServlet.java
+++ b/src/main/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServlet.java
@@ -41,6 +41,7 @@ import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.io.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -87,6 +88,12 @@ public class SourceReferencesServlet extends HttpServlet {
             
             for ( Bundle bundle : ctx.getBundleContext().getBundles() ) {
 
+                // skip bundle if it is a fragment (http://stackoverflow.com/questions/11655295/using-the-osgi-api-how-do-i-find-out-if-a-given-bundle-is-a-fragment)
+                if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
+                    log.debug("Skip bundle '{}' because it is a fragment", bundle);
+                    // source references should only be listed with the host bundle
+                    continue;
+                }
                 Object bundleVersion = bundle.getHeaders().get(Constants.BUNDLE_VERSION);
                 
                 w.object();

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.