Author: cziegeler
Date: Mon Jan 19 09:17:49 2009
New Revision: 735750

URL: http://svn.apache.org/viewvc?rev=735750&view=rev
Log:
SLING-834 - Provide uninstall to uninstall a bundle and remove fs 
configurations.

Added:
    
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
   (with props)
Modified:
    
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java

Modified: 
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java?rev=735750&r1=735749&r2=735750&view=diff
==============================================================================
--- 
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
 (original)
+++ 
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
 Mon Jan 19 09:17:49 2009
@@ -68,7 +68,7 @@
      *            default-value="http://localhost:8080/system/console";
      * @required
      */
-    private String slingUrl;
+    protected String slingUrl;
 
     /**
      * The user name to authenticate at the running Sling instance.
@@ -343,7 +343,7 @@
             final int status = client.executeMethod(post);
             // we get a moved temporarily back from the configMgr plugin
             if (status == HttpStatus.SC_MOVED_TEMPORARILY || status == 
HttpStatus.SC_OK) {
-                getLog().info("Configuration removed.");
+                getLog().debug("Configuration removed.");
             } else {
                 getLog().error(
                     "Removing configuration failed, cause: "
@@ -355,6 +355,8 @@
         } catch (IOException ex) {
             throw new MojoExecutionException("Removing configuration at " + 
postUrl
                     + " failed, cause: " + ex.getMessage(), ex);
+        } finally {
+            post.releaseConnection();
         }
     }
 
@@ -388,6 +390,8 @@
         } catch (IOException ex) {
             throw new MojoExecutionException("Configuration on " + postUrl
                     + " failed, cause: " + ex.getMessage(), ex);
+        } finally {
+            post.releaseConnection();
         }
     }
 
@@ -442,6 +446,8 @@
         } catch (IOException ex) {
             throw new MojoExecutionException("Reading configuration from " + 
getUrl
                     + " failed, cause: " + ex.getMessage(), ex);
+        } finally {
+            get.releaseConnection();
         }
         return result;
     }

Added: 
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java?rev=735750&view=auto
==============================================================================
--- 
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
 (added)
+++ 
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
 Mon Jan 19 09:17:49 2009
@@ -0,0 +1,118 @@
+/*
+ * 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.maven.bundlesupport;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Uninstall an OSGi bundle from a running Sling instance.
+ *
+ * @goal uninstall
+ * @description uninstall an OSGi bundle from a running Sling instance
+ */
+public class BundleUninstallMojo extends AbstractBundleInstallMojo {
+
+    /**
+     * The name of the generated JAR file.
+     *
+     * @parameter expression="${sling.file}" 
default-value="${project.build.directory}/${project.build.finalName}.jar"
+     * @required
+     */
+    private String bundleFileName;
+
+    @Override
+    protected String getBundleFileName() {
+        return bundleFileName;
+    }
+
+    /**
+     * @see org.apache.maven.plugin.AbstractMojo#execute()
+     */
+    public void execute() throws MojoExecutionException {
+        // only upload if packaging as an osgi-bundle
+        final File bundleFile = new File(bundleFileName);
+        final String bundleName = getBundleSymbolicName(bundleFile);
+        if (bundleName == null) {
+            getLog().info(bundleFile + " is not an OSGi Bundle, not 
uploading");
+            return;
+        }
+
+        getLog().info(
+            "Unistalling Bundle " + bundleName + ") from "
+                + slingUrl);
+        configure(slingUrl, bundleFile);
+        post(slingUrl, bundleName);
+    }
+
+    protected void post(String targetURL, String symbolicName)
+    throws MojoExecutionException {
+        final PostMethod post = new PostMethod(targetURL + "/bundles/" + 
symbolicName);
+        post.addParameter("action", "uninstall");
+
+        try {
+
+            int status = getHttpClient().executeMethod(post);
+            if (status == HttpStatus.SC_OK) {
+                getLog().info("Bundle uninstalled");
+            } else {
+                getLog().error(
+                    "Uninstall failed, cause: "
+                        + HttpStatus.getStatusText(status));
+            }
+        } catch (Exception ex) {
+            throw new MojoExecutionException("Uninstall from " + targetURL
+                + " failed, cause: " + ex.getMessage(), ex);
+        } finally {
+            post.releaseConnection();
+        }
+    }
+
+    /**
+     * Add configurations to a running OSGi instance for initial content.
+     * @param targetURL The web console base url
+     * @param file The artifact (bundle)
+     * @throws MojoExecutionException
+     */
+    protected void configure(String targetURL, File file)
+    throws MojoExecutionException {
+        getLog().info("Removing file system provider configurations...");
+
+        // now get current configurations
+        final HttpClient client = this.getHttpClient();
+        final Map oldConfigs = this.getCurrentFileProviderConfigs(targetURL, 
client);
+
+
+        final Iterator entryIterator = oldConfigs.entrySet().iterator();
+        while ( entryIterator.hasNext() ) {
+            final Map.Entry current = (Map.Entry) entryIterator.next();
+            final String[] value = (String[])current.getValue();
+            getLog().debug("Removing old configuration for " + value[0] + " 
and " + value[1]);
+            // remove old config
+            removeConfiguration(client, targetURL, 
current.getKey().toString());
+        }
+    }
+
+}
\ No newline at end of file

Propchange: 
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: 
incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to