Author: rombert
Date: Thu Sep 26 13:14:02 2013
New Revision: 1526474

URL: http://svn.apache.org/r1526474
Log:
SLING-3120 - Allow installing/updating the install support bundle from
the servers view

- extract an OSGiClient into the api bundle so that it can be reused
- when connecting to a Launchpad server, read the version of the tooling
support bundle
- add UI support for installing/updating the bundle, but without
actually performing the operation, since bundle is not yet available
outside the eclipse-m2e-ui bundle.

Added:
    
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/
    
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
   (with props)
    
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientException.java
   (with props)
    
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientFactory.java
   (with props)
    
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/
    
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
   (with props)
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/EmbeddedArtifacts.java
   (with props)
Modified:
    sling/branches/tooling-ide-vlt/tooling/ide/api/META-INF/MANIFEST.MF
    sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/META-INF/MANIFEST.MF
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ServerUtil.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java
    sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java

Modified: sling/branches/tooling-ide-vlt/tooling/ide/api/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api/META-INF/MANIFEST.MF?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/api/META-INF/MANIFEST.MF 
(original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/api/META-INF/MANIFEST.MF Thu Sep 
26 13:14:02 2013
@@ -6,7 +6,16 @@ Bundle-Version: 0.0.1.qualifier
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Export-Package: org.apache.sling.ide.filter,
+ org.apache.sling.ide.osgi,
  org.apache.sling.ide.serialization,
  org.apache.sling.ide.transport,
  org.apache.sling.ide.util
-Import-Package: org.osgi.service.event
+Import-Package: org.apache.commons.httpclient;version="3.1.0",
+ org.apache.commons.httpclient.auth;version="3.1.0",
+ org.apache.commons.httpclient.methods;version="3.1.0",
+ org.apache.commons.httpclient.methods.multipart;version="3.1.0",
+ org.apache.commons.httpclient.params;version="3.1.0",
+ org.apache.commons.io;version="2.0.1",
+ org.json,
+ org.osgi.framework;version="1.6.0",
+ org.osgi.service.event

Added: 
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=1526474&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
 Thu Sep 26 13:14:02 2013
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+
+import org.osgi.framework.Version;
+
+/**
+ * The <tt>OsgiClient</tt> exposes information and actions related to the OSGi 
subsystem of Sling
+ * 
+ */
+public interface OsgiClient {
+
+    Version getBundleVersion(String bundleSymbolicName) throws 
OsgiClientException;
+
+    void installBundle(InputStream in, String fileName) throws 
OsgiClientException;
+
+}
\ No newline at end of file

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClient.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientException.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientException.java?rev=1526474&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientException.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientException.java
 Thu Sep 26 13:14:02 2013
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+public class OsgiClientException extends Exception {
+
+    private static final long serialVersionUID = 1L;
+
+    public OsgiClientException() {
+        super();
+    }
+
+    public OsgiClientException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public OsgiClientException(String message) {
+        super(message);
+    }
+
+    public OsgiClientException(Throwable cause) {
+        super(cause);
+    }
+
+}

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientFactory.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientFactory.java?rev=1526474&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientFactory.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientFactory.java
 Thu Sep 26 13:14:02 2013
@@ -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;
+
+import org.apache.sling.ide.osgi.impl.HttpOsgiClient;
+import org.apache.sling.ide.transport.RepositoryInfo;
+
+/**
+ * The <tt>OsgiClientFactory</tt> creates <tt>OsgiClient</tt> instances
+ * 
+ */
+public class OsgiClientFactory {
+
+    public OsgiClient createOsgiClient(RepositoryInfo repositoryInfo) {
+        return new HttpOsgiClient(repositoryInfo);
+    }
+}

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/OsgiClientFactory.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 
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=1526474&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
 Thu Sep 26 13:14:02 2013
@@ -0,0 +1,141 @@
+/*
+ * 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+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;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
+import org.apache.commons.httpclient.methods.multipart.FilePart;
+import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.PartSource;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
+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.transport.RepositoryInfo;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.osgi.framework.Version;
+
+public class HttpOsgiClient implements OsgiClient {
+
+    private RepositoryInfo repositoryInfo;
+
+    public HttpOsgiClient(RepositoryInfo repositoryInfo) {
+
+        this.repositoryInfo = repositoryInfo;
+    }
+
+    @Override
+    public Version getBundleVersion(String bundleSymbolicName) throws 
OsgiClientException {
+
+        GetMethod method = new GetMethod(repositoryInfo.getUrl() + 
"system/console/bundles.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());
+            }
+
+            JSONObject object = new 
JSONObject(method.getResponseBodyAsString());
+
+            JSONArray bundleData = object.getJSONArray("data");
+            for (int i = 0; i < bundleData.length(); i++) {
+                JSONObject bundle = bundleData.getJSONObject(i);
+                String remotebundleSymbolicName = 
bundle.getString("symbolicName");
+                Version bundleVersion = new 
Version(bundle.getString("version"));
+
+                if (bundleSymbolicName.equals(remotebundleSymbolicName)) {
+                    return bundleVersion;
+                }
+            }
+
+            return null;
+        } catch (HttpException e) {
+            throw new OsgiClientException(e);
+        } catch (IOException e) {
+            throw new OsgiClientException(e);
+        } catch (JSONException e) {
+            throw new OsgiClientException(e);
+        } finally {
+            method.releaseConnection();
+        }
+    }
+
+    private HttpClient getHttpClient() {
+
+        HttpClient client = new HttpClient();
+        client.getParams().setAuthenticationPreemptive(true);
+        Credentials defaultcreds = new 
UsernamePasswordCredentials(repositoryInfo.getUsername(),
+                repositoryInfo.getPassword());
+        client.getState().setCredentials(
+                new AuthScope(repositoryInfo.getHost(), 
repositoryInfo.getPort(), AuthScope.ANY_REALM), defaultcreds);
+        return client;
+    }
+
+    @Override
+    public void installBundle(InputStream in, String fileName) throws 
OsgiClientException {
+        // append pseudo path after root URL to not get redirected for nothing
+        final PostMethod filePost = new 
PostMethod(repositoryInfo.getUrl()+"system/console/install");
+
+        try {
+            // set referrer
+            filePost.setRequestHeader("referer", "about:blank");
+
+            List<Part> partList = new ArrayList<Part>();
+            partList.add(new StringPart("action", "install"));
+            partList.add(new StringPart("_noredir_", "_noredir_"));
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            IOUtils.copy(in, baos);
+            PartSource partSource = new ByteArrayPartSource(fileName, 
baos.toByteArray());
+            partList.add(new FilePart("bundlefile", partSource));
+            partList.add(new StringPart("bundlestart", "start"));
+
+            Part[] parts = partList.toArray(new Part[partList.size()]);
+
+            filePost.setRequestEntity(new MultipartRequestEntity(parts, 
filePost.getParams()));
+
+            int status = getHttpClient().executeMethod(filePost);
+            if (status != 200) {
+                throw new HTTPException(status);
+            }
+        } catch (IOException e) {
+            throw new OsgiClientException(e);
+        } finally {
+            filePost.releaseConnection();
+        }
+    }
+
+}

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/META-INF/MANIFEST.MF?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/META-INF/MANIFEST.MF 
(original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/META-INF/MANIFEST.MF 
Thu Sep 26 13:14:02 2013
@@ -15,6 +15,7 @@ Import-Package: org.apache.commons.httpc
  org.apache.commons.httpclient.auth;version="3.1.0",
  org.apache.commons.httpclient.methods;version="3.1.0",
  org.apache.sling.ide.filter,
+ org.apache.sling.ide.osgi,
  org.apache.sling.ide.serialization,
  org.apache.sling.ide.transport,
  org.eclipse.core.commands,

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/EmbeddedArtifacts.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/EmbeddedArtifacts.java?rev=1526474&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/EmbeddedArtifacts.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/EmbeddedArtifacts.java
 Thu Sep 26 13:14:02 2013
@@ -0,0 +1,24 @@
+/*
+ * 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.eclipse.core;
+
+public class EmbeddedArtifacts {
+
+    public static final String SUPPORT_BUNDLE_SYMBOLIC_NAME = 
"org.apache.sling.tooling.support.install";
+    public static final String SUPPORT_BUNDLE_VERSION = "0.0.1.SNAPSHOT"; // 
TODO - remove version hardcoding
+
+}

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/EmbeddedArtifacts.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/EmbeddedArtifacts.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ISlingLaunchpadServer.java
 Thu Sep 26 13:14:02 2013
@@ -17,6 +17,7 @@
 package org.apache.sling.ide.eclipse.core;
 
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.osgi.framework.Version;
 
 public interface ISlingLaunchpadServer {
 
@@ -31,10 +32,15 @@ public interface ISlingLaunchpadServer {
     public static final String PROP_DEBUG_PORT = "launchpad.debugPort";
 
     public static final String PROP_INSTALL_LOCALLY = 
"launchpad.installLocally";
+    public static final String PROP_BUNDLE_VERSION_FORMAT = 
"launchpad.bundle.%s.version";
     
     void setPublishState(int publishState, IProgressMonitor monitor);
 
     int getPublishState();
 
     ISlingLaunchpadConfiguration getConfiguration();
+
+    void setBundleVersion(String bundleSymbolicName, Version version, 
IProgressMonitor monitor);
+
+    Version getBundleVersion(String bundleSymbolicName);
 }

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ServerUtil.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ServerUtil.java?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ServerUtil.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ServerUtil.java
 Thu Sep 26 13:14:02 2013
@@ -32,18 +32,10 @@ public abstract class ServerUtil {
 
     public static Repository getRepository(IServer server, IProgressMonitor 
monitor) throws CoreException {
 
-        ISlingLaunchpadServer launchpadServer = (ISlingLaunchpadServer) 
server.loadAdapter(SlingLaunchpadServer.class,
-                monitor);
-
-        ISlingLaunchpadConfiguration configuration = 
launchpadServer.getConfiguration();
 
         Repository repository = Activator.getDefault().getRepository();
         try {
-            // TODO configurable scheme?
-            URI uri = new URI("http", null, server.getHost(), 
configuration.getPort(), configuration.getContextPath(),
-                    null, null);
-            RepositoryInfo repositoryInfo = new 
RepositoryInfo(configuration.getUsername(),
-                    configuration.getPassword(), uri.toString());
+            RepositoryInfo repositoryInfo = getRepositoryInfo(server, monitor);
             repository.setRepositoryInfo(repositoryInfo);
         } catch (URISyntaxException e) {
             throw new CoreException(new Status(Status.ERROR, 
Activator.PLUGIN_ID, e.getMessage(), e));
@@ -53,6 +45,20 @@ public abstract class ServerUtil {
         return repository;
     }
 
+    public static RepositoryInfo getRepositoryInfo(IServer server, 
IProgressMonitor monitor) throws URISyntaxException {
+
+        ISlingLaunchpadServer launchpadServer = (ISlingLaunchpadServer) 
server.loadAdapter(SlingLaunchpadServer.class,
+                monitor);
+
+        ISlingLaunchpadConfiguration configuration = 
launchpadServer.getConfiguration();
+
+        // TODO configurable scheme?
+        URI uri = new URI("http", null, server.getHost(), 
configuration.getPort(), configuration.getContextPath(),
+                null, null);
+        return new RepositoryInfo(configuration.getUsername(),
+                configuration.getPassword(), uri.toString());
+    }
+
     private ServerUtil() {
 
     }

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=1526474&r1=1526473&r2=1526474&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
 Thu Sep 26 13:14:02 2013
@@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -35,6 +36,7 @@ import org.apache.commons.httpclient.URI
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.sling.ide.eclipse.core.EmbeddedArtifacts;
 import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
 import org.apache.sling.ide.eclipse.core.MavenLaunchHelper;
 import org.apache.sling.ide.eclipse.core.ProjectUtil;
@@ -42,12 +44,16 @@ import org.apache.sling.ide.eclipse.core
 import org.apache.sling.ide.filter.Filter;
 import org.apache.sling.ide.filter.FilterLocator;
 import org.apache.sling.ide.filter.FilterResult;
+import org.apache.sling.ide.osgi.OsgiClient;
+import org.apache.sling.ide.osgi.OsgiClientException;
+import org.apache.sling.ide.osgi.OsgiClientFactory;
 import org.apache.sling.ide.serialization.SerializationException;
 import org.apache.sling.ide.serialization.SerializationKind;
 import org.apache.sling.ide.serialization.SerializationManager;
 import org.apache.sling.ide.transport.Command;
 import org.apache.sling.ide.transport.FileInfo;
 import org.apache.sling.ide.transport.Repository;
+import org.apache.sling.ide.transport.RepositoryInfo;
 import org.apache.sling.ide.transport.ResourceProxy;
 import org.apache.sling.ide.transport.Result;
 import org.eclipse.core.resources.IFile;
@@ -72,6 +78,7 @@ import org.eclipse.wst.server.core.IServ
 import org.eclipse.wst.server.core.model.IModuleResource;
 import org.eclipse.wst.server.core.model.IModuleResourceDelta;
 import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
+import org.osgi.framework.Version;
 
 public class SlingLaunchpadBehaviour extends ServerBehaviourDelegate {
 
@@ -108,6 +115,24 @@ public class SlingLaunchpadBehaviour ext
             Command<ResourceProxy> command = 
repository.newListChildrenNodeCommand("/");
             result = command.execute();
             success = result.isSuccess();
+            
+            RepositoryInfo repositoryInfo;
+            try {
+                repositoryInfo = ServerUtil.getRepositoryInfo(getServer(), 
monitor);
+                OsgiClient client = new 
OsgiClientFactory().createOsgiClient(repositoryInfo);
+                Version bundleVersion = 
client.getBundleVersion(EmbeddedArtifacts.SUPPORT_BUNDLE_SYMBOLIC_NAME);
+                
+                ISlingLaunchpadServer launchpadServer = 
(ISlingLaunchpadServer) getServer().loadAdapter(SlingLaunchpadServer.class,
+                        monitor);
+                
launchpadServer.setBundleVersion(EmbeddedArtifacts.SUPPORT_BUNDLE_SYMBOLIC_NAME,
 bundleVersion, monitor);
+                
+            } catch (URISyntaxException e) {
+                Activator.getDefault().getLog().log(new 
Status(IStatus.WARNING, Activator.PLUGIN_ID, 
+                        "Failed retrieving information about the installation 
support bundle", e));
+            } catch (OsgiClientException e) {
+                Activator.getDefault().getLog().log(new 
Status(IStatus.WARNING, Activator.PLUGIN_ID, 
+                        "Failed retrieving information about the installation 
support bundle", e));
+            }
         }
 
         if (success) {
@@ -498,6 +523,8 @@ public class SlingLaunchpadBehaviour ext
         }
 
         if (res.isTeamPrivateMember(IResource.CHECK_ANCESTORS)) {
+            Activator.getDefault().getLog()
+                    .log(new Status(IStatus.INFO, Activator.PLUGIN_ID, 
"Skipping team-private resource " + res));
             return null;
         }
 
@@ -680,6 +707,11 @@ public class SlingLaunchpadBehaviour ext
         }
         
         if (deletedResource.isTeamPrivateMember(IResource.CHECK_ANCESTORS)) {
+            Activator
+                    .getDefault()
+                    .getLog()
+                    .log(new Status(IStatus.INFO, Activator.PLUGIN_ID, 
"Skipping team-private resource "
+                            + deletedResource));
             return null;
         }
         

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadServer.java
 Thu Sep 26 13:14:02 2013
@@ -25,6 +25,7 @@ import org.eclipse.core.runtime.Status;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServerWorkingCopy;
 import org.eclipse.wst.server.core.model.ServerDelegate;
+import org.osgi.framework.Version;
 
 public class SlingLaunchpadServer extends ServerDelegate implements 
ISlingLaunchpadServer {
 
@@ -152,4 +153,24 @@ public class SlingLaunchpadServer extend
                        throw new RuntimeException(e);
                }
     }
+
+    @Override
+    public Version getBundleVersion(String bundleSymbolicName) {
+
+        return new 
Version(getAttribute(String.format(PROP_BUNDLE_VERSION_FORMAT, 
bundleSymbolicName), (String) null));
+    }
+
+    @Override
+    public void setBundleVersion(String bundleSymbolicName, Version version, 
IProgressMonitor monitor) {
+
+        String stringVersion = version != null ? version.toString() : null;
+
+        IServerWorkingCopy wc = getServer().createWorkingCopy();
+        wc.setAttribute(String.format(PROP_BUNDLE_VERSION_FORMAT, 
bundleSymbolicName), stringVersion);
+        try {
+            wc.save(false, monitor);
+        } catch (CoreException e) {
+            throw new RuntimeException(e);
+        }
+    }
 }

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF 
(original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF 
Thu Sep 26 13:14:02 2013
@@ -11,6 +11,7 @@ Import-Package: org.apache.commons.httpc
  org.apache.commons.httpclient.methods;version="3.1.0",
  org.apache.commons.httpclient.methods.multipart;version="3.1.0",
  org.apache.commons.httpclient.params;version="3.1.0",
+ org.apache.commons.io;version="2.0.1",
  org.apache.maven,
  org.apache.maven.archetype,
  org.apache.maven.archetype.catalog,
@@ -23,6 +24,8 @@ Import-Package: org.apache.commons.httpc
  org.apache.maven.model,
  org.apache.maven.plugin,
  org.apache.sling.ide.eclipse.core,
+ org.apache.sling.ide.osgi,
+ org.apache.sling.ide.transport,
  org.codehaus.plexus,
  org.eclipse.core.resources,
  org.eclipse.core.runtime;version="3.4.0",

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
 Thu Sep 26 13:14:02 2013
@@ -172,7 +172,7 @@ public abstract class AbstractNewSlingAp
                }
                IServer server = setupServerWizardPage.getOrCreateServer();
                monitor.worked(1);
-               if (monitor.isCanceled()) {
+        if (monitor.isCanceled() || server == null) {
                        return false;
                }
                

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/SetupServerWizardPage.java
 Thu Sep 26 13:14:02 2013
@@ -16,35 +16,22 @@
  */
 package org.apache.sling.ide.eclipse.ui.wizards.np;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.HashMap;
-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.HttpStatus;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
-import org.apache.commons.httpclient.methods.multipart.FilePart;
-import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
-import org.apache.commons.httpclient.methods.multipart.Part;
-import org.apache.commons.httpclient.methods.multipart.PartSource;
-import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.ide.eclipse.core.EmbeddedArtifacts;
 import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
 import org.apache.sling.ide.eclipse.m2e.internal.Activator;
+import org.apache.sling.ide.osgi.OsgiClient;
+import org.apache.sling.ide.osgi.OsgiClientException;
+import org.apache.sling.ide.osgi.OsgiClientFactory;
+import org.apache.sling.ide.transport.RepositoryInfo;
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.KeyEvent;
@@ -66,10 +53,11 @@ import org.eclipse.wst.server.core.IServ
 import org.eclipse.wst.server.core.IServerType;
 import org.eclipse.wst.server.core.IServerWorkingCopy;
 import org.eclipse.wst.server.core.ServerCore;
+import org.osgi.framework.Version;
 
 public class SetupServerWizardPage extends WizardPage {
        
-       private Button useExistingServer;
+    private Button useExistingServer;
        private Combo existingServerCombo;
        private Button setupNewServer;
        private Text newServerName;
@@ -291,86 +279,36 @@ public class SetupServerWizardPage exten
        }
        
 
-       private boolean containsToolingSupportBundle() {
-        String hostname = getHostname();
-        int launchpadPort = getPort();
-        GetMethod method = new 
GetMethod("http://"+hostname+":"+launchpadPort+"/system/console/bundles/org.apache.sling.tooling.support.install";);
-        
-        try {
-                       return getHttpClient("admin", 
"admin").executeMethod(method) == 200;
-               } catch (IOException e) {
-            getWizard().reportError(e);
-                       return false;
-               }
-    }
-    
-    /**
-     * Get the http client
-     * @param user 
-     * @param password 
-     */
-    protected HttpClient getHttpClient(String user, String password) {
-        final HttpClient client = new HttpClient();
-        client.getHttpConnectionManager().getParams().setConnectionTimeout(
-            5000);
-
-        // authentication stuff
-        client.getParams().setAuthenticationPreemptive(true);
-        Credentials defaultcreds = new UsernamePasswordCredentials(user,
-            password);
-        client.getState().setCredentials(AuthScope.ANY, defaultcreds);
+    private Version getToolingSupportBundleVersion() throws 
OsgiClientException {
 
-        return client;
+        return 
newOsgiClient().getBundleVersion(EmbeddedArtifacts.SUPPORT_BUNDLE_SYMBOLIC_NAME);
     }
+    
+    private void installToolingSupportBundle() throws OsgiClientException, 
IOException {
+        // TODO centralize version and resource lookup
+       String fileName = 
"org.apache.sling.tooling.support.install-0.0.1-SNAPSHOT.jar";
+               URL jarUrl = Activator.getDefault().getBundle().getResource(
+                       "target/sling-tooling-support-install/"+fileName);
 
-    protected int post(String targetURL, String user, String passwd, 
InputStream in, String fileName) throws IOException {
-        // append pseudo path after root URL to not get redirected for nothing
-        final PostMethod filePost = new PostMethod(targetURL + "/install");
-
+        InputStream contents = null;
         try {
-            // set referrer
-            filePost.setRequestHeader("referer", "about:blank");
-
-            List<Part> partList = new ArrayList<Part>();
-            partList.add(new StringPart("action", "install"));
-            partList.add(new StringPart("_noredir_", "_noredir_"));
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            copyStream(in, baos);
-                       PartSource partSource = new 
ByteArrayPartSource(fileName, baos.toByteArray());
-            partList.add(new FilePart("bundlefile", partSource));
-            partList.add(new StringPart("bundlestart", "start"));
-
-            Part[] parts = partList.toArray(new Part[partList.size()]);
-
-            filePost.setRequestEntity(new MultipartRequestEntity(parts,
-                filePost.getParams()));
-
-            int status = getHttpClient(user, passwd).executeMethod(filePost);
-            return status;
+            contents = jarUrl.openStream();
+            newOsgiClient().installBundle(contents, fileName);
         } finally {
-            filePost.releaseConnection();
+            IOUtils.closeQuietly(contents);
         }
     }
 
-    private void copyStream(InputStream in, OutputStream os) throws 
IOException {
-               final byte[] bytes = new byte[4*1024];
-               while (true) {
-                       final int numRead = in.read(bytes);
-                       if (numRead < 0) {
-                               break;
-                       }
-                       os.write(bytes, 0, numRead);
-               }
-       }
+    private OsgiClient newOsgiClient() {
 
-    private int installToolingSupportBundle() throws IOException {
         String hostname = getHostname();
         int launchpadPort = getPort();
-        String targetURL = 
"http://"+hostname+":"+launchpadPort+"/system/console";;
-       String fileName = 
"org.apache.sling.tooling.support.install-0.0.1-SNAPSHOT.jar";
-               URL jarUrl = Activator.getDefault().getBundle().getResource(
-                       "target/sling-tooling-support-install/"+fileName);
-               return post(targetURL, "admin", "admin", jarUrl.openStream(), 
fileName);
+
+        OsgiClientFactory factory = new OsgiClientFactory();
+
+        // TODO remove credential hardcoding
+        return factory.createOsgiClient(new RepositoryInfo("admin", "admin", 
"http://"; + hostname + ":" + launchpadPort
+                + "/"));
     }
        
        IServer getOrCreateServer() {
@@ -389,33 +327,34 @@ public class SetupServerWizardPage exten
                                }
                        }
                        
-                       boolean installedLocally = false;
                        if (installToolingSupportBundle.getSelection()) {
-                               if (containsToolingSupportBundle()) {
-                                       // then nothing to overwrite
-                                       installedLocally = true;
-                               } else {
+                // TODO - read from manifest instead of hardcoding
+                Version ourVersion = new Version(0, 0, 1, "SNAPSHOT");
+                Version installedVersion;
+                try {
+                    installedVersion = getToolingSupportBundleVersion();
+                } catch (OsgiClientException e) {
+                    getWizard().reportError(e);
+                    return null;
+                }
+                if (installedVersion == null || 
ourVersion.compareTo(installedVersion) > 0) {
                                        // then auto-install it if possible
                                        try {
-                                               int status = 
installToolingSupportBundle();
-                                               
-                                               if (status!=HttpStatus.SC_OK) {
-                            getWizard().reportError(
-                                    new CoreException(new 
Status(IStatus.WARNING, Activator.PLUGIN_ID,
-                                            "Could not install sling tooling 
support bundle: " + status)));
-                                               } else {
-                                                       installedLocally = true;
-                                               }
+                        installToolingSupportBundle();
                                        } catch (IOException e) {
                         getWizard().reportError(e);
                         return null;
-                                       }
+                    } catch (OsgiClientException e) {
+                        getWizard().reportError(e);
+                        return null;
+                    }
                                }
                        }
                        
                        IRuntimeType serverRuntime = 
ServerCore.findRuntimeType("org.apache.sling.ide.launchpadRuntimeType");
             // TODO progress monitor
                        try {
+                // TODO pass in username and password
                                IRuntime runtime = 
serverRuntime.createRuntime(null, new NullProgressMonitor());
                                runtime = 
runtime.createWorkingCopy().save(true, new NullProgressMonitor());
                                IServerWorkingCopy wc = 
serverType.createServer(null, null, runtime, new NullProgressMonitor());
@@ -423,7 +362,7 @@ public class SetupServerWizardPage exten
                                wc.setName(newServerName.getText() + " 
(external)");
                                
wc.setAttribute(ISlingLaunchpadServer.PROP_PORT, getPort());
                                
wc.setAttribute(ISlingLaunchpadServer.PROP_DEBUG_PORT, 
Integer.parseInt(newServerDebugPort.getText()));
-                               
wc.setAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, installedLocally);
+                wc.setAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, 
installToolingSupportBundle.getSelection());
                                wc.setAttribute("auto-publish-setting", 2); // 
2: automatically publish when resources change
                                wc.setAttribute("auto-publish-time", 0);    // 
0: zero delay after a resource change (and the builder was kicked, I guess)
                                wc.setRuntime(runtime);

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF 
(original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF 
Thu Sep 26 13:14:02 2013
@@ -16,6 +16,7 @@ Import-Package: org.apache.commons.httpc
  org.apache.jackrabbit.util,
  org.apache.sling.ide.eclipse.core,
  org.apache.sling.ide.filter,
+ org.apache.sling.ide.osgi,
  org.apache.sling.ide.serialization,
  org.apache.sling.ide.transport,
  org.apache.sling.ide.util,

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java
 Thu Sep 26 13:14:02 2013
@@ -18,25 +18,44 @@ package org.apache.sling.ide.eclipse.ui.
 
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
 
+import org.apache.sling.ide.eclipse.core.EmbeddedArtifacts;
 import org.apache.sling.ide.eclipse.core.ISlingLaunchpadConfiguration;
 import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
+import org.apache.sling.ide.eclipse.core.ServerUtil;
 import org.apache.sling.ide.eclipse.core.SetBundleInstallLocallyCommand;
+import org.apache.sling.ide.osgi.OsgiClient;
+import org.apache.sling.ide.osgi.OsgiClientException;
+import org.apache.sling.ide.osgi.OsgiClientFactory;
+import org.apache.sling.ide.transport.RepositoryInfo;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
 import org.eclipse.ui.forms.widgets.ExpandableComposite;
 import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Hyperlink;
 import org.eclipse.ui.forms.widgets.Section;
 import org.eclipse.wst.server.ui.editor.ServerEditorSection;
+import org.osgi.framework.Version;
 
 public class InstallEditorSection extends ServerEditorSection {
     protected boolean _updating;
@@ -44,8 +63,11 @@ public class InstallEditorSection extend
 
     private Button mvnSlingInstallButton;
     private Button quickLocalInstallButton;
+    private Hyperlink installOrUpdateSupportBundleLink;
     private ISlingLaunchpadServer launchpadServer;
     private PropertyChangeListener serverListener;
+    private Label supportBundleVersionLabel;
+    private Composite actionArea;
 
     @Override
     public void createSection(Composite parent) {
@@ -72,16 +94,23 @@ public class InstallEditorSection extend
         section.setClient(composite);
 
         
-        mvnSlingInstallButton = new Button(composite, SWT.RADIO);
-        mvnSlingInstallButton.setText("Install bundles via mvn sling:install");
+        mvnSlingInstallButton = toolkit.createButton(composite, "Install 
bundles via mvn sling:install", SWT.RADIO);
         GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
         mvnSlingInstallButton.setLayoutData(data);
         
-        quickLocalInstallButton = new Button(composite, SWT.RADIO);
-        quickLocalInstallButton.setText("Install bundles directly from local 
directory");
+        quickLocalInstallButton = toolkit.createButton(composite, "Install 
bundles directly from local directory",
+                SWT.RADIO);
         data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
         quickLocalInstallButton.setLayoutData(data);
 
+        actionArea = toolkit.createComposite(composite);
+        RowLayout actionAreaLayout = new RowLayout();
+        actionAreaLayout.center = true;
+        actionArea.setLayout(actionAreaLayout);
+
+        supportBundleVersionLabel = toolkit.createLabel(actionArea, "");
+        installOrUpdateSupportBundleLink = toolkit.createHyperlink(actionArea, 
"(Install)", SWT.NONE);
+
         initialize();
     }
 
@@ -127,6 +156,84 @@ public class InstallEditorSection extend
 
         quickLocalInstallButton.addSelectionListener(listener);
         mvnSlingInstallButton.addSelectionListener(listener);
+        
+
+        Version version = 
launchpadServer.getBundleVersion(EmbeddedArtifacts.SUPPORT_BUNDLE_SYMBOLIC_NAME);
+        final Version embeddedVersion = new 
Version(EmbeddedArtifacts.SUPPORT_BUNDLE_VERSION);
+        if (version == null || embeddedVersion.compareTo(version) > 0) {
+            supportBundleVersionLabel
+                    .setText("Installation support bundle is not present our 
outdated, local deployment will not work");
+            installOrUpdateSupportBundleLink.setEnabled(true);
+            // actionArea.setVisible(true);
+        } else {
+            supportBundleVersionLabel.setText("Installation support bundle is 
present and up to date.");
+            installOrUpdateSupportBundleLink.setEnabled(false);
+            // actionArea.setVisible(false);
+        }
+
+        installOrUpdateSupportBundleLink.addHyperlinkListener(new 
HyperlinkAdapter() {
+
+            @Override
+            public void linkActivated(HyperlinkEvent e) {
+
+                ProgressMonitorDialog dialog = new 
ProgressMonitorDialog(getShell());
+                dialog.setCancelable(true);
+                try {
+                    dialog.run(true, false, new IRunnableWithProgress() {
+
+                        @Override
+                        public void run(IProgressMonitor monitor) throws 
InvocationTargetException,
+                                InterruptedException {
+                            final Version remoteVersion;
+                            monitor.beginTask("Installing support bundle", 2);
+                            // double-check, just in case
+                            monitor.setTaskName("Getting remote bundle 
version");
+
+                            final String message;
+                            try {
+                                RepositoryInfo repositoryInfo = 
ServerUtil.getRepositoryInfo(server.getOriginal(),
+                                        monitor);
+                                OsgiClient client = new 
OsgiClientFactory().createOsgiClient(repositoryInfo);
+                                remoteVersion = 
client.getBundleVersion(EmbeddedArtifacts.SUPPORT_BUNDLE_SYMBOLIC_NAME);
+
+                                monitor.worked(1);
+
+                                if (remoteVersion != null && 
remoteVersion.compareTo(embeddedVersion) >= 0) {
+                                    // version already up-to-date, due to 
bundle version
+                                    // changing between startup check and now
+                                    message = "Bundle is already installed and 
up to date";
+                                } else {
+                                    monitor.setTaskName("Installing bundle");
+                                    message = "!!! Installation not yet 
supported";
+                                }
+                                monitor.worked(1);
+
+                            } catch (OsgiClientException e) {
+                                throw new InvocationTargetException(e);
+                            } catch (URISyntaxException e) {
+                                throw new InvocationTargetException(e);
+                            } finally {
+                                monitor.done();
+                            }
+
+                            Display.getDefault().asyncExec(new Runnable() {
+                                @Override
+                                public void run() {
+                                    MessageDialog.openInformation(getShell(), 
"Support bundle install operation",
+                                            message);
+                                }
+                            });
+                        }
+                    });
+                } catch (InvocationTargetException e1) {
+                    // TODO error reporting
+                    e1.printStackTrace();
+                } catch (InterruptedException e1) {
+                    Thread.currentThread().interrupt();
+                    return;
+                }
+            }
+        });
     }
 
     /*

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java?rev=1526474&r1=1526473&r2=1526474&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
 Thu Sep 26 13:14:02 2013
@@ -147,7 +147,7 @@ public class ConvertToBundleAction imple
                fSelection = selection;
                if (selection instanceof IStructuredSelection) {
                        final IStructuredSelection iss = (IStructuredSelection) 
selection;
-                       Iterator<Object> it = iss.iterator();
+                       Iterator<?> it = iss.iterator();
                        if (!it.hasNext()) {
                                action.setEnabled(false);
                                return;


Reply via email to