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

kwin pushed a commit to branch feature/new-tooling-support-bundles
in repository https://gitbox.apache.org/repos/asf/sling-ide-tooling.git

commit 4e4d670ff25fdca25391f203437615e337cdd4ba
Author: Konrad Windszus <[email protected]>
AuthorDate: Tue Nov 22 13:45:45 2022 +0100

    SLING-11694 Embed new Tooling Support Install/Source bundles
    
    WIP
---
 .../core/internal/SlingLaunchpadBehaviour.java     |  8 ++--
 shared/api/pom.xml                                 |  5 ++-
 .../java/org/apache/sling/ide/osgi/OsgiClient.java | 29 ++++++-------
 .../apache/sling/ide/osgi/impl/HttpOsgiClient.java | 34 ++++-----------
 .../sling/ide/osgi/impl/HttpOsgiClientIT.java      |  5 +--
 shared/artifacts/pom.xml                           | 20 ++++++++-
 .../ide/artifacts/EmbeddedArtifactLocator.java     |  2 +-
 .../ide/artifacts/impl/ArtifactsLocatorImpl.java   |  2 +-
 .../artifacts/impl/ArtifactsLocatorImplTest.java   | 48 ++++++++++++++++++++++
 9 files changed, 100 insertions(+), 53 deletions(-)

diff --git 
a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
 
b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
index 81dd8928..974bd67d 100644
--- 
a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
+++ 
b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
@@ -110,7 +110,7 @@ public class SlingLaunchpadBehaviour extends 
ServerBehaviourDelegateWithModulePu
                    EmbeddedArtifactLocator artifactLocator = 
Activator.getDefault().getArtifactLocator();
        
                    installBundle(monitor,client, 
artifactLocator.loadSourceSupportBundle(), 
SUPPORT_SOURCE_BUNDLE_SYMBOLIC_NAME); // 15/50 done
-                   installBundle(monitor,client, 
artifactLocator.loadToolingSupportBundle(), SUPPORT_BUNDLE_SYMBOLIC_NAME); // 
20/50 done
+                   installBundle(monitor,client, 
artifactLocator.loadInstallSupportBundle(), SUPPORT_BUNDLE_SYMBOLIC_NAME); // 
20/50 done
                    
                } catch ( IOException | OsgiClientException e) {
                    Activator.getDefault().getPluginLogger()
@@ -355,8 +355,8 @@ public class SlingLaunchpadBehaviour extends 
ServerBehaviourDelegateWithModulePu
 
             //TODO SLING-3767:
             //osgiClient must have a timeout!!!
-            if ( installLocally ) {
-                
osgiClient.installLocalBundle(outputLocation.toFile().toPath());
+            if (installLocally) {
+                osgiClient.installBundle(outputLocation.toFile().toPath());
                 monitor.worked(3);
             } else {
 
@@ -364,7 +364,7 @@ public class SlingLaunchpadBehaviour extends 
ServerBehaviourDelegateWithModulePu
                 InputStream bundle = builder.buildJar(outputFolder);
                 monitor.worked(1);
                 
-                osgiClient.installLocalBundle(bundle, 
outputFolder.getLocation().toOSString());
+                osgiClient.installBundle(bundle, 
outputFolder.getLocation().toOSString());
                 monitor.worked(2);
             }
 
diff --git a/shared/api/pom.xml b/shared/api/pom.xml
index 9fc914c5..af3e3187 100644
--- a/shared/api/pom.xml
+++ b/shared/api/pom.xml
@@ -46,12 +46,12 @@
                                                                <artifactItem>
                                                                        
<groupId>org.apache.sling</groupId>
                                                                        
<artifactId>org.apache.sling.tooling.support.install</artifactId>
-                                                                       
<version>1.0.6</version>
+                                                                       
<version>1.0.7-SNAPSHOT</version>
                                                                </artifactItem>
                                                                <artifactItem>
                                                                        
<groupId>org.apache.sling</groupId>
                                                                        
<artifactId>org.apache.sling.tooling.support.source</artifactId>
-                                                                       
<version>1.0.4</version>
+                                                                       
<version>1.0.5-SNAPSHOT</version>
                                                                </artifactItem>
                                                                <artifactItem>
                                                                        
<groupId>org.apache.sling</groupId>
@@ -126,6 +126,7 @@
                                                        
<startTimeoutSeconds>${startTimeoutSeconds}</startTimeoutSeconds>
                                                </launch>
                                        </launches>
+                                       
                                </configuration>
                                <executions>
                                        <execution>
diff --git a/shared/api/src/main/java/org/apache/sling/ide/osgi/OsgiClient.java 
b/shared/api/src/main/java/org/apache/sling/ide/osgi/OsgiClient.java
index 00b58b88..bfb0861d 100644
--- a/shared/api/src/main/java/org/apache/sling/ide/osgi/OsgiClient.java
+++ b/shared/api/src/main/java/org/apache/sling/ide/osgi/OsgiClient.java
@@ -37,33 +37,33 @@ public interface OsgiClient extends AutoCloseable {
 
     Version getBundleVersion(String bundleSymbolicName) throws 
OsgiClientException;
 
-    void installBundle(InputStream in, String fileName) throws 
OsgiClientException;
-
     /**
-     * Installs a bundle from a local directory
-     * 
+     * Installs a bundle from a JAR.
      * <p>
-     * The Sling launchpad instance must have filesystem access to the 
specified <tt>explodedBundleLocation</tt>
-     * </p>
+     * Leverages the <a 
href="https://felix.apache.org/documentation/subprojects/apache-felix-web-console/web-console-restful-api.html";>Felix
 Web Console ReST endpoint</a>.
+     * @param in the contents of the jarred bundle
+     * @param sourceLocation the source location, for informative purposes only
      * 
-     * @param explodedBundleLocation
      * @throws OsgiClientException
      */
-    void installLocalBundle(Path explodedBundleLocation) throws 
OsgiClientException;
+    void installBundle(InputStream in, String sourceLocation) throws 
OsgiClientException;
 
     /**
-     * Installs a local bundle from an already-built jar file
+     * Installs a bundle from a local filesystem directory.
      * 
-     * @param jarredBundle the contents of the jarred bundle
-     * @param sourceLocation the source location, for informative purposes only
+     * <strong>The Sling launchpad instance must have filesystem access to the 
specified <tt>explodedBundleLocation</tt></strong>
+     * <p>
+     * Leverages the <a 
href="https://github.com/apache/sling-org-apache-sling-tooling-support-install";>Sling
 Tooling Support Install bundle</a>.
      * 
+     * @param explodedBundleLocation the local path of the directory 
containing the exploded bundle
      * @throws OsgiClientException
      */
-    void installLocalBundle(InputStream jarredBundle, String sourceLocation) 
throws OsgiClientException;
+    void installBundle(Path explodedBundleLocation) throws OsgiClientException;
     
     /**
      * Finds source references for all bundles deployed in the Sling instance
-     * 
+     * <p>
+     * Leverages the <a 
href="https://github.com/apache/sling-org-apache-sling-tooling-support-source";>Sling
 Tooling Support Source bundle</a>.
      * @return the source references, possibly empty
      * @throws OsgiClientException
      */
@@ -71,7 +71,8 @@ public interface OsgiClient extends AutoCloseable {
     
     /**
      * Uninstalls the bundle with the specified Bundle-SymbolicName, if present
-     * 
+     * <p>
+     * Leverages the <a 
href="https://felix.apache.org/documentation/subprojects/apache-felix-web-console/web-console-restful-api.html";>Felix
 Web Console ReST endpoint</a>.
      * @param bundleSymbolicName The Bundle-SymbolicName
      * @return true in case a bundle with that BSN was found and uninstalled, 
false in case the BSN was not found
      * @throws OsgiClientException error when trying to uninstall the bundle
diff --git 
a/shared/api/src/main/java/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java 
b/shared/api/src/main/java/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
index 16375121..10cc40e1 100644
--- 
a/shared/api/src/main/java/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
+++ 
b/shared/api/src/main/java/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
@@ -296,7 +296,7 @@ public class HttpOsgiClient implements OsgiClient, 
AutoCloseable {
        }
 
        @Override
-       public void installLocalBundle(final Path explodedBundleLocation) 
throws OsgiClientException {
+       public void installBundle(final Path explodedBundleLocation) throws 
OsgiClientException {
 
                if (explodedBundleLocation == null) {
                        throw new 
IllegalArgumentException("explodedBundleLocation may not be null");
@@ -305,24 +305,19 @@ public class HttpOsgiClient implements OsgiClient, 
AutoCloseable {
                List<? extends NameValuePair> parameters = Collections
                                .singletonList(new BasicNameValuePair("dir", 
explodedBundleLocation.toString()));
                try {
-                       installLocalBundle(new 
UrlEncodedFormEntity(parameters), explodedBundleLocation.toString());
+                       HttpPost request = new 
HttpPost(repositoryInfo.getUrl().resolve("system/sling/tooling/install"));
+                       request.setEntity(new UrlEncodedFormEntity(parameters));
+                       BundleInstallerResult result = 
executeJsonRequest(request, BundleInstallerResult.class, "install local bundle 
from " + explodedBundleLocation.toString());
+                       if (!result.isSuccessful()) {
+                               String errorMessage = !result.hasMessage() ? 
"Bundle deployment failed, please check the Sling logs"
+                                               : result.getMessage();
+                               throw new OsgiClientException(errorMessage);
+                       }
                } catch (UnsupportedEncodingException e) {
                        throw new OsgiClientException("Cannot install local 
bundle due to unsupported encoding", e);
                }
        }
 
-       @Override
-       public void installLocalBundle(final InputStream jarredBundle, String 
sourceLocation) throws OsgiClientException {
-
-               if (jarredBundle == null) {
-                       throw new IllegalArgumentException("jarredBundle may 
not be null");
-               }
-
-               MultipartEntityBuilder entityBuilder = 
MultipartEntityBuilder.create();
-               entityBuilder.addBinaryBody("bundle", jarredBundle, 
ContentType.DEFAULT_BINARY, "bundle.jar");
-               installLocalBundle(entityBuilder.build(), sourceLocation);
-       }
-
        @Override
        public List<SourceReference> findSourceReferences() throws 
OsgiClientException {
                SourceBundleData[] sourceBundleData = 
executeJsonGetRequest("system/sling/tooling/sourceReferences.json", 
SourceBundleData[].class, "find source references");
@@ -449,17 +444,6 @@ public class HttpOsgiClient implements OsgiClient, 
AutoCloseable {
 
        }
 
-       void installLocalBundle(HttpEntity httpEntity, String bundleSource) 
throws OsgiClientException {
-               HttpPost request = new 
HttpPost(repositoryInfo.getUrl().resolve("system/sling/tooling/install"));
-               request.setEntity(httpEntity);
-               BundleInstallerResult result = executeJsonRequest(request, 
BundleInstallerResult.class, "install local bundle from " + bundleSource);
-               if (!result.isSuccessful()) {
-                       String errorMessage = !result.hasMessage() ? "Bundle 
deployment failed, please check the Sling logs"
-                                       : result.getMessage();
-                       throw new OsgiClientException(errorMessage);
-               }
-       }
-
        private <T> T executeJsonGetRequest(String relativePath, Class<T> 
jsonObjectClass, String requestLabel) throws OsgiClientException {
                HttpGet request = new 
HttpGet(repositoryInfo.getUrl().resolve(relativePath));
                return executeJsonRequest(request, jsonObjectClass, 
requestLabel);
diff --git 
a/shared/api/src/test/java/org/apache/sling/ide/osgi/impl/HttpOsgiClientIT.java 
b/shared/api/src/test/java/org/apache/sling/ide/osgi/impl/HttpOsgiClientIT.java
index d5466263..131ca5b9 100644
--- 
a/shared/api/src/test/java/org/apache/sling/ide/osgi/impl/HttpOsgiClientIT.java
+++ 
b/shared/api/src/test/java/org/apache/sling/ide/osgi/impl/HttpOsgiClientIT.java
@@ -88,11 +88,8 @@ public class HttpOsgiClientIT {
                osgiClient.installBundle(input, "org.apache.sling.api");
        }
        
osgiClient.waitForComponentRegistered("org.apache.sling.tooling.support.install.impl.InstallServlet",
 20000, 500);
-       try (InputStream input = 
Objects.requireNonNull(this.getClass().getResourceAsStream("/org.apache.sling.commons.messaging.jar")))
 {
-               osgiClient.installLocalBundle(input, "commons-messaging.jar");
-       }
        
-       osgiClient.installLocalBundle(explodedJarFolder);
+       osgiClient.installBundle(explodedJarFolder);
         osgiClient.uninstallBundle("org.apache.sling.tooling.support.install");
     }
     
diff --git a/shared/artifacts/pom.xml b/shared/artifacts/pom.xml
index 667caef4..82da4f6c 100644
--- a/shared/artifacts/pom.xml
+++ b/shared/artifacts/pom.xml
@@ -48,19 +48,35 @@
             <scope>provided</scope>
         </dependency>
 
-        <!-- will be embedded -->
+        <!-- embedded via Bnd-->
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.tooling.support.install</artifactId>
             <version>1.0.6</version>
             <scope>provided</scope>
         </dependency>
-        <!-- will be embedded -->
+        <!-- embedded via Bnd-->
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.tooling.support.source</artifactId>
             <version>1.0.4</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-simple</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>commons-io</groupId>
+                       <artifactId>commons-io</artifactId>
+                       <version>2.11.0</version>
+                       <scope>test</scope>
+               </dependency>
     </dependencies>
 </project>
diff --git 
a/shared/artifacts/src/main/java/org/apache/sling/ide/artifacts/EmbeddedArtifactLocator.java
 
b/shared/artifacts/src/main/java/org/apache/sling/ide/artifacts/EmbeddedArtifactLocator.java
index 6982de98..b8001f84 100644
--- 
a/shared/artifacts/src/main/java/org/apache/sling/ide/artifacts/EmbeddedArtifactLocator.java
+++ 
b/shared/artifacts/src/main/java/org/apache/sling/ide/artifacts/EmbeddedArtifactLocator.java
@@ -22,7 +22,7 @@ public interface EmbeddedArtifactLocator {
     
     public static final String SUPPORT_SOURCE_BUNDLE_SYMBOLIC_NAME = 
"org.apache.sling.tooling.support.source";
 
-    EmbeddedArtifact loadToolingSupportBundle();
+    EmbeddedArtifact loadInstallSupportBundle();
     
     EmbeddedArtifact loadSourceSupportBundle();
 }
diff --git 
a/shared/artifacts/src/main/java/org/apache/sling/ide/artifacts/impl/ArtifactsLocatorImpl.java
 
b/shared/artifacts/src/main/java/org/apache/sling/ide/artifacts/impl/ArtifactsLocatorImpl.java
index 3dc74968..7677cfb0 100644
--- 
a/shared/artifacts/src/main/java/org/apache/sling/ide/artifacts/impl/ArtifactsLocatorImpl.java
+++ 
b/shared/artifacts/src/main/java/org/apache/sling/ide/artifacts/impl/ArtifactsLocatorImpl.java
@@ -30,7 +30,7 @@ public class ArtifactsLocatorImpl implements 
EmbeddedArtifactLocator {
        }
 
     @Override
-    public EmbeddedArtifact loadToolingSupportBundle() {
+    public EmbeddedArtifact loadInstallSupportBundle() {
 
         String version = "1.0.6"; // TODO - remove version hardcoding
         String artifactId = "org.apache.sling.tooling.support.install";
diff --git 
a/shared/artifacts/src/test/java/org/apache/sling/ide/artifacts/impl/ArtifactsLocatorImplTest.java
 
b/shared/artifacts/src/test/java/org/apache/sling/ide/artifacts/impl/ArtifactsLocatorImplTest.java
new file mode 100644
index 00000000..a1cc8c17
--- /dev/null
+++ 
b/shared/artifacts/src/test/java/org/apache/sling/ide/artifacts/impl/ArtifactsLocatorImplTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.artifacts.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.ide.artifacts.EmbeddedArtifact;
+import org.junit.Test;
+
+public class ArtifactsLocatorImplTest {
+
+       @Test
+       public void testLoadSourceSupportBundle() throws IOException {
+               ArtifactsLocatorImpl artifactsLocator = new 
ArtifactsLocatorImpl();
+               
assertEmbeddedArtifact(artifactsLocator.loadSourceSupportBundle(), 
"org.apache.sling.tooling.support.source-1.0.4.jar");
+       }
+
+       @Test
+       public void testLoadInstallSupportBundle() throws IOException {
+               ArtifactsLocatorImpl artifactsLocator = new 
ArtifactsLocatorImpl();
+               
assertEmbeddedArtifact(artifactsLocator.loadInstallSupportBundle(), 
"org.apache.sling.tooling.support.install-1.0.6.jar");
+       }
+
+       private void assertEmbeddedArtifact(EmbeddedArtifact embeddedArtifact, 
String expectedInputResourceName) throws IOException {
+               try (InputStream expectedInput = 
this.getClass().getClassLoader().getResourceAsStream(expectedInputResourceName);
+                       InputStream actualInput = 
embeddedArtifact.openInputStream()) {
+                       assertTrue(IOUtils.contentEquals(expectedInput, 
actualInput));
+               }
+       }
+}

Reply via email to