This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag maven-sling-plugin-2.0.2-incubator in repository https://gitbox.apache.org/repos/asf/sling-maven-sling-plugin.git
commit f6f3119d03c0c4cff1692d57ffd9eef583af9d88 Author: Felix Meschberger <[email protected]> AuthorDate: Mon Sep 24 08:34:29 2007 +0000 Add new plugin comparable to install named install-file which allows installation of a bundle without a POM git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/maven-sling-plugin@578707 13f79535-47bb-0310-9956-ffa450edef68 --- ...allMojo.java => AbstractBundleInstallMojo.java} | 87 ++++++--------- .../bundlesupport/AbstractBundlePostMojo.java | 31 ++++-- .../maven/bundlesupport/BundleInstallFileMojo.java | 48 ++++++++ .../maven/bundlesupport/BundleInstallMojo.java | 121 +++------------------ 4 files changed, 113 insertions(+), 174 deletions(-) diff --git a/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java similarity index 68% copy from src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java copy to src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java index 4b9d588..8f93351 100644 --- a/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java +++ b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java @@ -1,20 +1,17 @@ /* - * 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 + * $Url: $ + * $Id: $ * - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 1997-2005 Day Management AG + * Barfuesserplatz 6, 4001 Basel, Switzerland + * All Rights Reserved. * - * 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. + * This software is the confidential and proprietary information of + * Day Management AG, ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Day. */ - package org.apache.sling.maven.bundlesupport; import java.io.File; @@ -33,34 +30,10 @@ import org.apache.commons.httpclient.methods.multipart.FilePartSource; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; import org.apache.commons.httpclient.methods.multipart.StringPart; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; -/** - * Install an OSGi bundle to a running Sling instance. - * - * @goal install - * @phase install - * @description install an OSGi bundle jar to a running Sling instance - */ -public class BundleInstallMojo extends AbstractBundlePostMojo { - - /** - * Whether to skip this step even though it has been configured in the - * project to be executed. This property may be set by the - * <code>sling.install.skip</code> comparable to the <code>maven.test.skip</code> - * property to prevent running the unit tests. - * - * @parameter expression="${sling.install.skip}" default-value="false" - * @required - */ - private boolean skip; - - /** - * The name of the generated JAR file. - * - * @parameter expression="${sling.file}" default-value="${project.build.directory}/${project.build.finalName}.jar" - * @required - */ - private String bundleFileName; +public abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo { /** * The URL of the running Sling instance. @@ -102,15 +75,16 @@ public class BundleInstallMojo extends AbstractBundlePostMojo { */ private boolean bundleStart; - /** - * Execute this Mojo - */ - public void execute() { - // don't do anything, if this step is to be skipped - if (skip) { - getLog().debug("Skipping bundle installation as instructed"); - return; - } + public AbstractBundleInstallMojo() { + super(); + } + + protected abstract String getBundleFileName() throws MojoExecutionException; + + public void execute() throws MojoExecutionException { + + // get the file to upload + String bundleFileName = getBundleFileName(); // only upload if packaging as an osgi-bundle File bundleFile = new File(bundleFileName); @@ -122,15 +96,15 @@ public class BundleInstallMojo extends AbstractBundlePostMojo { getLog().info("Installing Bundle " + bundleName + "(" + bundleFile + ") to " + slingUrl); post(slingUrl, bundleFile); - } - - private void post(String targetURL, File file) { + } + protected void post(String targetURL, File file) { + // append pseudo path after root URL to not get redirected for nothing PostMethod filePost = new PostMethod(targetURL + "/install"); - + try { - + List<Part> partList = new ArrayList<Part>(); partList.add(new StringPart("action", "install")); partList.add(new StringPart("_noredir_", "_noredir_")); @@ -140,9 +114,9 @@ public class BundleInstallMojo extends AbstractBundlePostMojo { if (bundleStart) { partList.add(new StringPart("bundlestart", "start")); } - + Part[] parts = partList.toArray(new Part[partList.size()]); - + filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); @@ -171,4 +145,5 @@ public class BundleInstallMojo extends AbstractBundlePostMojo { filePost.releaseConnection(); } } + } \ No newline at end of file diff --git a/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundlePostMojo.java b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundlePostMojo.java index 93b5886..17d2317 100644 --- a/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundlePostMojo.java +++ b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundlePostMojo.java @@ -24,13 +24,14 @@ import java.util.jar.JarFile; import java.util.jar.Manifest; import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; public abstract class AbstractBundlePostMojo extends AbstractMojo { /** * Returns the symbolic name of the given bundle. If the - * <code>jarFile</code> does not exist or does not contain a manifest with - * a <code>Bundle-SymbolicName</code> header <code>null</code> is + * <code>jarFile</code> does not contain a manifest with a + * <code>Bundle-SymbolicName</code> header <code>null</code> is * returned. Otherwise the value of the <code>Bundle-SymbolicName</code> * header is returned. * <p> @@ -42,15 +43,17 @@ public abstract class AbstractBundlePostMojo extends AbstractMojo { * requested. * @return The bundle's symbolic name from the * <code>Bundle-SymbolicName</code> manifest header or - * <code>null</code> if the file does not exists or no manifest - * exists in the file or the header is not contained in the - * manifest. However, if <code>null</code> is returned, the file - * may be assumed to not contain an OSGi bundle. + * <code>null</code> if no manifest exists in the file or the + * header is not contained in the manifest. However, if + * <code>null</code> is returned, the file may be assumed to not + * contain an OSGi bundle. + * @throws MojoExecutionException if the file does not exist */ - protected String getBundleSymbolicName(File jarFile) { + protected String getBundleSymbolicName(File jarFile) + throws MojoExecutionException { + if (!jarFile.exists()) { - getLog().debug("getBundleSymbolicName: " + jarFile + " does not exist"); - return null; + throw new MojoExecutionException("Missing file " + jarFile); } JarFile jaf = null; @@ -58,20 +61,24 @@ public abstract class AbstractBundlePostMojo extends AbstractMojo { jaf = new JarFile(jarFile); Manifest manif = jaf.getManifest(); if (manif == null) { - getLog().debug("getBundleSymbolicName: Missing manifest in " + jarFile); + getLog().debug( + "getBundleSymbolicName: Missing manifest in " + jarFile); return null; } String symbName = manif.getMainAttributes().getValue( "Bundle-SymbolicName"); if (symbName == null) { - getLog().debug("getBundleSymbolicName: No Bundle-SymbolicName in " + jarFile); + getLog().debug( + "getBundleSymbolicName: No Bundle-SymbolicName in " + + jarFile); return null; } return symbName; } catch (IOException ioe) { - getLog().warn("getBundleSymbolicName: Problem checking " + jarFile, ioe); + getLog().warn("getBundleSymbolicName: Problem checking " + jarFile, + ioe); } finally { if (jaf != null) { try { diff --git a/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java b/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java new file mode 100644 index 0000000..5168ca2 --- /dev/null +++ b/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java @@ -0,0 +1,48 @@ +/* + * 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 org.apache.maven.plugin.MojoExecutionException; + +/** + * Install an OSGi bundle to a running Sling instance. + * + * @goal install-file + * @description install an OSGi bundle jar to a running Sling instance + * @requiresProject false + */ +public class BundleInstallFileMojo extends AbstractBundleInstallMojo { + + /** + * The name of the generated JAR file. + * + * @parameter expression="${sling.file}" + */ + private String bundleFileName; + + @Override + protected String getBundleFileName() throws MojoExecutionException { + if (bundleFileName == null) { + throw new MojoExecutionException("Missing sling.file parameter"); + } + + return bundleFileName; + } +} \ No newline at end of file diff --git a/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java b/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java index 4b9d588..121d299 100644 --- a/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java +++ b/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java @@ -33,6 +33,9 @@ import org.apache.commons.httpclient.methods.multipart.FilePartSource; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; import org.apache.commons.httpclient.methods.multipart.StringPart; +import org.apache.maven.model.Build; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; /** * Install an OSGi bundle to a running Sling instance. @@ -41,7 +44,7 @@ import org.apache.commons.httpclient.methods.multipart.StringPart; * @phase install * @description install an OSGi bundle jar to a running Sling instance */ -public class BundleInstallMojo extends AbstractBundlePostMojo { +public class BundleInstallMojo extends AbstractBundleInstallMojo { /** * Whether to skip this step even though it has been configured in the @@ -62,113 +65,19 @@ public class BundleInstallMojo extends AbstractBundlePostMojo { */ private String bundleFileName; - /** - * The URL of the running Sling instance. - * - * @parameter expression="${sling.url}" default-value="http://localhost:8080/sling" - * @required - */ - private String slingUrl; - - /** - * The user name to authenticate at the running Sling instance. - * - * @parameter expression="${sling.user}" default-value="admin" - * @required - */ - private String user; - - /** - * The password to authenticate at the running Sling instance. - * - * @parameter expression="${sling.password}" default-value="admin" - * @required - */ - private String password; - - /** - * The startlevel for the uploaded bundle - * - * @parameter expression="${sling.bundle.startlevel}" default-value="20" - * @required - */ - private String bundleStartLevel; - - /** - * Whether to start the uploaded bundle or not - * - * @parameter expression="${sling.bundle.start}" default-value="true" - * @required - */ - private boolean bundleStart; - - /** - * Execute this Mojo - */ - public void execute() { - // don't do anything, if this step is to be skipped - if (skip) { - getLog().debug("Skipping bundle installation as instructed"); - return; - } - - // only upload if packaging as an osgi-bundle - File bundleFile = new File(bundleFileName); - String bundleName = getBundleSymbolicName(bundleFile); - if (bundleName == null) { - getLog().info(bundleFile + " is not an OSGi Bundle, not uploading"); + @Override + public void execute() throws MojoExecutionException { + // don't do anything, if this step is to be skipped + if (skip) { + getLog().debug("Skipping bundle installation as instructed"); return; } - getLog().info("Installing Bundle " + bundleName + "(" + bundleFile + ") to " + slingUrl); - post(slingUrl, bundleFile); - } - - private void post(String targetURL, File file) { - - // append pseudo path after root URL to not get redirected for nothing - PostMethod filePost = new PostMethod(targetURL + "/install"); - - try { - - List<Part> partList = new ArrayList<Part>(); - partList.add(new StringPart("action", "install")); - partList.add(new StringPart("_noredir_", "_noredir_")); - partList.add(new FilePart("bundlefile", new FilePartSource(file.getName(), file))); - partList.add(new StringPart("bundlestartlevel", bundleStartLevel)); - - if (bundleStart) { - partList.add(new StringPart("bundlestart", "start")); - } - - Part[] parts = partList.toArray(new Part[partList.size()]); - - filePost.setRequestEntity(new MultipartRequestEntity(parts, - filePost.getParams())); - 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); - - int status = client.executeMethod(filePost); - if (status == HttpStatus.SC_OK) { - getLog().info("Bundle installed"); - } else { - getLog().error( - "Installation failed, cause: " + HttpStatus.getStatusText(status)); - } - } catch (ConnectException ce) { - getLog().info("Installation on " + targetURL + " failed, cause: " + ce.getMessage()); - getLog().debug(ce); // dump on debug - } catch (Exception ex) { - getLog().error(ex.getClass().getName() + " " + ex.getMessage()); - ex.printStackTrace(); - } finally { - filePost.releaseConnection(); - } + super.execute(); + } + + @Override + protected String getBundleFileName() { + return bundleFileName; } } \ No newline at end of file -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
