Author: rombert
Date: Fri Sep 27 15:06:33 2013
New Revision: 1526938

URL: http://svn.apache.org/r1526938
Log:
SLING-3121 - Deployment of java bundles fails if the maven-sling-plugin
is not declared in the pom

Move local deployment to use the OSGiClient.

Modified:
    
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
    
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java?rev=1526938&r1=1526937&r2=1526938&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
 Fri Sep 27 15:06:33 2013
@@ -30,4 +30,16 @@ public interface OsgiClient {
 
     void installBundle(InputStream in, String fileName) throws 
OsgiClientException;
 
+    /**
+     * Installs a bundle from a local directory
+     * 
+     * <p>
+     * The Sling launchpad instance must have filesystem access to the 
specified <tt>explodedBundleLocation</tt>
+     * </p>
+     * 
+     * @param explodedBundleLocation
+     * @throws OsgiClientException
+     */
+    void installLocalBundle(String explodedBundleLocation) throws 
OsgiClientException;
+
 }
\ No newline at end of file

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java?rev=1526938&r1=1526937&r2=1526938&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
 Fri Sep 27 15:06:33 2013
@@ -23,8 +23,6 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.xml.ws.http.HTTPException;
-
 import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
@@ -138,7 +136,7 @@ public class HttpOsgiClient implements O
 
             int status = getHttpClient().executeMethod(filePost);
             if (status != 200) {
-                throw new HTTPException(status);
+                throw new OsgiClientException("Method execution returned 
status " + status);
             }
         } catch (IOException e) {
             throw new OsgiClientException(e);
@@ -147,4 +145,27 @@ public class HttpOsgiClient implements O
         }
     }
 
+    @Override
+    public void installLocalBundle(String explodedBundleLocation) throws 
OsgiClientException {
+
+        if (explodedBundleLocation == null) {
+            throw new IllegalArgumentException("explodedBundleLocation may not 
be null");
+        }
+
+        PostMethod method = new PostMethod(repositoryInfo.getUrl() + 
"system/sling/tooling/install");
+        method.addParameter("dir", explodedBundleLocation);
+
+        try {
+            int status = getHttpClient().executeMethod(method);
+            if (status != 200) {
+                throw new OsgiClientException("Method execution returned 
status " + status);
+            }
+        } catch (IOException e) {
+            throw new OsgiClientException(e);
+        } finally {
+            method.releaseConnection();
+        }
+
+    }
+
 }

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java?rev=1526938&r1=1526937&r2=1526938&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
 Fri Sep 27 15:06:33 2013
@@ -29,13 +29,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.URIException;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.io.IOUtils;
 import org.apache.sling.ide.artifacts.EmbeddedArtifactLocator;
 import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
@@ -265,44 +258,29 @@ public class SlingLaunchpadBehaviour ext
             launchConfig.launch(ILaunchManager.RUN_MODE, monitor);
                } else {
                        monitor.beginTask("deploying via local install", 5);
-               HttpClient httpClient = new HttpClient();
-               String hostname = getServer().getHost();
-               int launchpadPort = 
getServer().getAttribute(ISlingLaunchpadServer.PROP_PORT, 8080);
-               PostMethod method = new 
PostMethod("http://"+hostname+":"+launchpadPort+"/system/sling/tooling/install";);
-               String username = 
getServer().getAttribute(ISlingLaunchpadServer.PROP_USERNAME, "admin");
-               String password = 
getServer().getAttribute(ISlingLaunchpadServer.PROP_PASSWORD, "admin");
-               String userInfo = username+":"+password;
-               if (userInfo != null) {
-                       Credentials c = new 
UsernamePasswordCredentials(userInfo);
-                       try {
-                                       httpClient.getState().setCredentials(
-                                                       new 
AuthScope(method.getURI().getHost(), method
-                                                                       
.getURI().getPort()), c);
-                               } catch (URIException e) {
-                                       // TODO proper logging
-                                       e.printStackTrace();
-                               }
-               }
-               IJavaProject javaProject = ProjectHelper.asJavaProject(project);
-               IPath outputLocation = javaProject.getOutputLocation();
-                       outputLocation = 
outputLocation.makeRelativeTo(project.getFullPath());
-               IPath location = project.getRawLocation();
-               if (location==null) {
-                       location = project.getLocation();
-               }
-                       method.addParameter("dir", location.toString() + "/" + 
outputLocation.toString());
-               monitor.worked(1);
+
             try {
-                               httpClient.executeMethod(method);
-                       monitor.worked(4);
-                       setModulePublishState(module, 
IServer.PUBLISH_STATE_NONE);
-                       } catch (HttpException e) {
-                               // TODO proper logging
-                               e.printStackTrace();
-                       } catch (IOException e) {
-                               // TODO proper logging
-                               e.printStackTrace();
-                       }
+                OsgiClient osgiClient = 
Activator.getDefault().getOsgiClientFactory()
+                        
.createOsgiClient(ServerUtil.getRepositoryInfo(getServer(), monitor));
+
+                IJavaProject javaProject = 
ProjectHelper.asJavaProject(project);
+
+                IPath outputLocation = 
project.getWorkspace().getRoot().findMember(javaProject.getOutputLocation())
+                        .getLocation();
+                monitor.worked(1);
+
+                osgiClient.installLocalBundle(outputLocation.toOSString());
+                monitor.worked(4);
+                setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
+
+            } catch (URISyntaxException e1) {
+                throw new CoreException(new Status(IStatus.ERROR, 
Activator.PLUGIN_ID, e1.getMessage(), e1));
+            } catch (OsgiClientException e1) {
+                throw new CoreException(new Status(IStatus.ERROR, 
Activator.PLUGIN_ID, "Failed installing bundle : "
+                        + e1.getMessage(), e1));
+            } finally {
+                monitor.done();
+            }
                }
        }
 


Reply via email to