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 2016/02/17 21:50:35 UTC

svn commit: r1730936 - in /sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi: MavenSourceReference.java OsgiClient.java SourceReference.java impl/HttpOsgiClient.java impl/MavenSourceReferenceImpl.java impl/TracingOsgiClient.java

Author: rombert
Date: Wed Feb 17 20:50:34 2016
New Revision: 1730936

URL: http://svn.apache.org/viewvc?rev=1730936&view=rev
Log:
SLING-3605 - Debug based on bundles deployed on the server

Add OsgiClient.findSourceReferences

Added:
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/MavenSourceReference.java
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/SourceReference.java
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/MavenSourceReferenceImpl.java
Modified:
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java

Added: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/MavenSourceReference.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/MavenSourceReference.java?rev=1730936&view=auto
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/MavenSourceReference.java (added)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/MavenSourceReference.java Wed Feb 17 20:50:34 2016
@@ -0,0 +1,30 @@
+/*
+ * 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.sling.ide.osgi;
+
+/**
+ * A {@link SourceReference} represented as a set of Maven GAV coordinates
+ *
+ */
+public interface MavenSourceReference extends SourceReference {
+
+    String getGroupId();
+    
+    String getArtifactId();
+    
+    String getVersion();
+}

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java?rev=1730936&r1=1730935&r2=1730936&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java Wed Feb 17 20:50:34 2016
@@ -17,6 +17,7 @@
 package org.apache.sling.ide.osgi;
 
 import java.io.InputStream;
+import java.util.List;
 
 import org.osgi.framework.Version;
 
@@ -51,5 +52,13 @@ public interface OsgiClient {
      * @throws OsgiClientException
      */
     void installLocalBundle(InputStream jarredBundle, String sourceLocation) throws OsgiClientException;
+    
+    /**
+     * Finds source references for all bundles deployed in the Sling instance
+     * 
+     * @return the source references, possibly empty
+     * @throws OsgiClientException
+     */
+    List<SourceReference> findSourceReferences() throws OsgiClientException;
 
 }
\ No newline at end of file

Added: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/SourceReference.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/SourceReference.java?rev=1730936&view=auto
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/SourceReference.java (added)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/SourceReference.java Wed Feb 17 20:50:34 2016
@@ -0,0 +1,31 @@
+/*
+ * 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.sling.ide.osgi;
+
+/**
+ * Describes a SourceReference for bundles deployed in a Sling instance  
+ * 
+ */
+public interface SourceReference {
+
+    enum Type {
+        MAVEN;
+    }
+    
+    Type getType();
+}

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java?rev=1730936&r1=1730935&r2=1730936&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java Wed Feb 17 20:50:34 2016
@@ -41,6 +41,7 @@ import org.apache.commons.httpclient.met
 import org.apache.commons.io.IOUtils;
 import org.apache.sling.ide.osgi.OsgiClient;
 import org.apache.sling.ide.osgi.OsgiClientException;
+import org.apache.sling.ide.osgi.SourceReference;
 import org.apache.sling.ide.transport.RepositoryInfo;
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -185,6 +186,45 @@ public class HttpOsgiClient implements O
             }
         }.installBundle();        
     }
+    
+    @Override
+    public List<SourceReference> findSourceReferences() throws OsgiClientException {
+        GetMethod method = new GetMethod(repositoryInfo.appendPath("system/sling/tooling/sourceReferences.json"));
+        HttpClient client = getHttpClient();
+
+        try {
+            int result = client.executeMethod(method);
+            if (result != HttpStatus.SC_OK) {
+                throw new HttpException("Got status code " + result + " for call to " + method.getURI());
+            }
+
+            List<SourceReference> refs = new ArrayList<>();
+            try ( InputStream input = method.getResponseBodyAsStream() ) {
+
+                JSONArray bundles = new JSONArray(new JSONTokener(new InputStreamReader(input)));
+                for ( int i = 0 ; i < bundles.length(); i++) {
+                    JSONObject bundle = bundles.getJSONObject(i);
+                    JSONArray references = bundle.getJSONArray("sourceReferences");
+                    for ( int j = 0 ; j < references.length(); j++ ) {
+                        JSONObject reference = references.getJSONObject(j);
+                        if ( !"maven".equals(reference.get("__type__")) ) {
+                            // unknown type, skipping
+                            continue;
+                        }
+                        
+                        refs.add(new MavenSourceReferenceImpl(reference.getString("groupId"), reference.getString("artifactId"), reference.getString("version")));
+                    }
+                }
+    
+    
+                return refs;
+            }
+        } catch (IOException | JSONException e) {
+            throw new OsgiClientException(e);
+        } finally {
+            method.releaseConnection();
+        }        
+    }
 
     static abstract class LocalBundleInstaller {
 

Added: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/MavenSourceReferenceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/MavenSourceReferenceImpl.java?rev=1730936&view=auto
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/MavenSourceReferenceImpl.java (added)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/MavenSourceReferenceImpl.java Wed Feb 17 20:50:34 2016
@@ -0,0 +1,53 @@
+/*
+ * 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.sling.ide.osgi.impl;
+
+import org.apache.sling.ide.osgi.MavenSourceReference;
+
+public class MavenSourceReferenceImpl implements MavenSourceReference {
+    
+    public MavenSourceReferenceImpl(String groupId, String artifactId, String version) {
+        this.groupId = groupId;
+        this.artifactId = artifactId;
+        this.version = version;
+    }
+
+    private final String groupId;
+    private final String artifactId;
+    private final String version;
+    
+    @Override
+    public Type getType() {
+        return Type.MAVEN;
+    }
+
+    @Override
+    public String getGroupId() {
+        return groupId;
+    }
+
+    @Override
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    @Override
+    public String getVersion() {
+        return version;
+    }
+
+}

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java?rev=1730936&r1=1730935&r2=1730936&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java Wed Feb 17 20:50:34 2016
@@ -18,10 +18,12 @@ package org.apache.sling.ide.osgi.impl;
 
 import java.io.InputStream;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.sling.ide.osgi.OsgiClient;
 import org.apache.sling.ide.osgi.OsgiClientException;
+import org.apache.sling.ide.osgi.SourceReference;
 import org.apache.sling.ide.transport.CommandExecutionProperties;
 import org.osgi.framework.Version;
 import org.osgi.service.event.Event;
@@ -102,5 +104,10 @@ public class TracingOsgiClient implement
 
         logInstallLocalBundle(jarredBundle, sourceLocation);
     }
+    
+    @Override
+    public List<SourceReference> findSourceReferences() throws OsgiClientException {
+        return osgiClient.findSourceReferences();
+    }
 
 }