You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2022/11/15 17:28:59 UTC

[sling-org-apache-sling-tooling-support-source] branch master updated: SLING-11676 followup fix to workaround SLING-11677

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

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


The following commit(s) were added to refs/heads/master by this push:
     new ab6579c  SLING-11676 followup fix to workaround SLING-11677
ab6579c is described below

commit ab6579cbae250043c8c96bda69735118f543257e
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Tue Nov 15 18:28:54 2022 +0100

    SLING-11676 followup fix to workaround SLING-11677
    
    fix version casting
---
 pom.xml                                                             | 5 +++++
 .../sling/tooling/support/source/impl/SourceReferencesServlet.java  | 6 +++++-
 .../tooling/support/source/impl/SourceReferencesServletTest.java    | 2 ++
 .../sling/tooling/support/source/impl/expectedBundleSource.json     | 2 +-
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 708ef0c..9d39481 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,11 @@
             <artifactId>org.osgi.resource</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component</artifactId>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.service.component.annotations</artifactId>
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 92626ef..cf67211 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,8 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardContextSelect;
 import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,6 +52,8 @@ import org.slf4j.LoggerFactory;
  */
 @Component(service = Servlet.class)
 @HttpWhiteboardServletPattern("/system/sling/tooling/sourceReferences.json")
+// choose another servlet context with a higher ranking than the Sling one (https://issues.apache.org/jira/browse/SLING-11677)
+@HttpWhiteboardContextSelect("(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=org.osgi.service.http)")
 public class SourceReferencesServlet extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
@@ -99,7 +103,7 @@ public class SourceReferencesServlet extends HttpServlet {
                 // source references should only be listed with the host bundle
                 continue;
             }
-            Object bundleVersion = bundle.getVersion();
+            String bundleVersion = bundle.getVersion().toString();
 
             w.object();
             w.key(Constants.BUNDLE_SYMBOLICNAME);
diff --git a/src/test/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServletTest.java b/src/test/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServletTest.java
index 40da3b4..8c8788b 100644
--- a/src/test/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServletTest.java
+++ b/src/test/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServletTest.java
@@ -37,6 +37,7 @@ import org.mockito.Mockito;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
 import org.osgi.framework.wiring.BundleRevision;
 
 @ExtendWith(MockitoExtension.class)
@@ -50,6 +51,7 @@ class SourceReferencesServletTest {
         Mockito.when(bundle1.adapt(BundleRevision.class)).thenReturn(bundleRevision);
         Dictionary<String, String> dictionary = Mockito.mock(Dictionary.class);
         Mockito.when(bundle1.getHeaders()).thenReturn(dictionary);
+        Mockito.when(bundle1.getVersion()).thenReturn(new Version("1.0.0"));
         BundleContext ctx = Mockito.mock(BundleContext.class);
         URLConnection mockUrlConnection = Mockito.mock(URLConnection.class);
         URLStreamHandler stubUrlHandler = new URLStreamHandler() {
diff --git a/src/test/resources/org/apache/sling/tooling/support/source/impl/expectedBundleSource.json b/src/test/resources/org/apache/sling/tooling/support/source/impl/expectedBundleSource.json
index ca01f19..b7e71b7 100644
--- a/src/test/resources/org/apache/sling/tooling/support/source/impl/expectedBundleSource.json
+++ b/src/test/resources/org/apache/sling/tooling/support/source/impl/expectedBundleSource.json
@@ -1 +1 @@
-[{"Bundle-SymbolicName":null,"Bundle-Version":null,"sourceReferences":[{"__type__":"maven","groupId":"com.example.myGroupId","artifactId":"myArtifactId","version":"1.0.0"}]}]
\ No newline at end of file
+[{"Bundle-SymbolicName":null,"Bundle-Version":"1.0.0","sourceReferences":[{"__type__":"maven","groupId":"com.example.myGroupId","artifactId":"myArtifactId","version":"1.0.0"}]}]
\ No newline at end of file