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

rombert pushed a commit to annotated tag maven-sling-plugin-2.0.4-incubator
in repository https://gitbox.apache.org/repos/asf/sling-maven-sling-plugin.git

commit df0b01c8ed429c537c368877f6736780364de9dc
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Mon Jan 19 17:17:49 2009 +0000

    SLING-834 - Provide uninstall to uninstall a bundle and remove fs 
configurations.
    
    git-svn-id: 
https://svn.apache.org/repos/asf/incubator/sling/trunk/maven/maven-sling-plugin@735750
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../bundlesupport/AbstractBundleInstallMojo.java   |  10 +-
 .../maven/bundlesupport/BundleUninstallMojo.java   | 118 +++++++++++++++++++++
 2 files changed, 126 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
 
b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
index 38e1e7e..2b351e1 100644
--- 
a/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
@@ -68,7 +68,7 @@ abstract class AbstractBundleInstallMojo extends 
AbstractBundlePostMojo {
      *            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 @@ abstract class AbstractBundleInstallMojo extends 
AbstractBundlePostMojo {
             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 @@ abstract class AbstractBundleInstallMojo extends 
AbstractBundlePostMojo {
         } catch (IOException ex) {
             throw new MojoExecutionException("Removing configuration at " + 
postUrl
                     + " failed, cause: " + ex.getMessage(), ex);
+        } finally {
+            post.releaseConnection();
         }
     }
 
@@ -388,6 +390,8 @@ abstract class AbstractBundleInstallMojo extends 
AbstractBundlePostMojo {
         } catch (IOException ex) {
             throw new MojoExecutionException("Configuration on " + postUrl
                     + " failed, cause: " + ex.getMessage(), ex);
+        } finally {
+            post.releaseConnection();
         }
     }
 
@@ -442,6 +446,8 @@ abstract class AbstractBundleInstallMojo extends 
AbstractBundlePostMojo {
         } catch (IOException ex) {
             throw new MojoExecutionException("Reading configuration from " + 
getUrl
                     + " failed, cause: " + ex.getMessage(), ex);
+        } finally {
+            get.releaseConnection();
         }
         return result;
     }
diff --git 
a/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java 
b/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
new file mode 100644
index 0000000..b019c79
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
@@ -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

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to