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 349edbe5cad5eedcab3c5747e84cd41932a2b15b Author: Carsten Ziegeler <[email protected]> AuthorDate: Wed Feb 18 13:32:18 2009 +0000 SLING-861 : Apply patch by Alexander Klimetschek to support PUT in the maven-sling-plugin git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/maven/maven-sling-plugin@745510 13f79535-47bb-0310-9956-ffa450edef68 --- .../bundlesupport/AbstractBundleInstallMojo.java | 91 +++++++++++++++++++++- .../maven/bundlesupport/BundleUninstallMojo.java | 38 ++++++++- 2 files changed, 123 insertions(+), 6 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 2b351e1..01e62b7 100644 --- a/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java +++ b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java @@ -34,8 +34,10 @@ 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.FileRequestEntity; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.multipart.FilePart; import org.apache.commons.httpclient.methods.multipart.FilePartSource; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; @@ -71,6 +73,38 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo { protected String slingUrl; /** + * An optional url suffix which will be appended to the <code>sling.url</code> + * for use as the real target url. This allows to configure different target URLs + * in each POM, while using the same common <code>sling.url</code> in a parent + * POM (eg. <code>sling.url=http://localhost:8080</code> and + * <code>sling.urlSuffix=/project/specific/path</code>). This is typically used + * in conjunction with a HTTP PUT (<code>sling.usePut=true</code>). + * + * @parameter expression="${sling.urlSuffix}" + */ + protected String slingUrlSuffix; + + /** + * If a simple HTTP PUT should be used instead of the standard POST to the + * felix console. In the <code>uninstall</code> goal, a HTTP DELETE will be + * used. + * + * @parameter expression="${sling.usePut}" default-value="false" + * @required + */ + protected boolean usePut; + + /** + * The content type / mime type used for the HTTP PUT (if + * <code>sling.usePut=true</code>). + * + * @parameter expression="${sling.mimeTypeForPut}" + * default-value="application/java-archive" + * @required + */ + protected String mimeTypeForPut; + + /** * The user name to authenticate at the running Sling instance. * * @parameter expression="${sling.user}" default-value="admin" @@ -133,6 +167,26 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo { protected abstract String getBundleFileName() throws MojoExecutionException; + /** + * Returns the combination of <code>sling.url</code> and + * <code>sling.urlSuffix</code>. + */ + protected String getTargetURL() { + String targetURL = slingUrl; + if (slingUrlSuffix != null) { + targetURL += slingUrlSuffix; + } + return targetURL; + } + + /** + * Returns the URL for PUT or DELETE by appending the filename to the + * targetURL. + */ + protected String getPutURL(String targetURL, String fileName) { + return targetURL + (targetURL.endsWith("/") ? "" : "/") + fileName; + } + public void execute() throws MojoExecutionException { // get the file to upload @@ -145,13 +199,21 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo { getLog().info(bundleFile + " is not an OSGi Bundle, not uploading"); return; } + + String targetURL = getTargetURL(); getLog().info( "Installing Bundle " + bundleName + "(" + bundleFile + ") to " - + slingUrl); - post(slingUrl, bundleFile); + + targetURL + " via " + (usePut ? "PUT" : "POST")); + + if (usePut) { + put(targetURL, bundleFile); + } else { + post(targetURL, bundleFile); + } + if ( mountByFS ) { - configure(slingUrl, bundleFile); + configure(targetURL, bundleFile); } } @@ -228,6 +290,29 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo { } } + protected void put(String targetURL, File file) throws MojoExecutionException { + + PutMethod filePut = new PutMethod(getPutURL(targetURL, file.getName())); + + try { + filePut.setRequestEntity(new FileRequestEntity(file, mimeTypeForPut)); + + int status = getHttpClient().executeMethod(filePut); + if (status >= 200 && status < 300) { + getLog().info("Bundle installed"); + } else { + getLog().error( + "Installation failed, cause: " + + HttpStatus.getStatusText(status)); + } + } catch (Exception ex) { + throw new MojoExecutionException("Installation on " + targetURL + + " failed, cause: " + ex.getMessage(), ex); + } finally { + filePut.releaseConnection(); + } + } + /** * Add configurations to a running OSGi instance for initial content. * @param targetURL The web console base url diff --git a/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java b/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java index b019c79..53e41a4 100644 --- a/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java +++ b/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.DeleteMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.maven.plugin.MojoExecutionException; @@ -60,11 +61,42 @@ public class BundleUninstallMojo extends AbstractBundleInstallMojo { return; } + String targetURL = getTargetURL(); + getLog().info( "Unistalling Bundle " + bundleName + ") from " - + slingUrl); - configure(slingUrl, bundleFile); - post(slingUrl, bundleName); + + targetURL + " via " + (usePut ? "DELETE" : "POST")); + + configure(targetURL, bundleFile); + + if (usePut) { + delete(targetURL, bundleFile); + } else { + post(targetURL, bundleName); + } + } + + protected void delete(String targetURL, File file) + throws MojoExecutionException { + + final DeleteMethod delete = new DeleteMethod(getPutURL(targetURL, file.getName())); + + try { + + int status = getHttpClient().executeMethod(delete); + if (status >= 200 && status < 300) { + 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 { + delete.releaseConnection(); + } } protected void post(String targetURL, String symbolicName) -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
