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 f6b4c24cadb5ef851ed67e23c47378b5e1dbb706 Author: Felix Meschberger <[email protected]> AuthorDate: Mon May 19 07:53:48 2008 +0000 SLING-463 Add support for refresh packages git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/maven/maven-sling-plugin@657746 13f79535-47bb-0310-9956-ffa450edef68 --- .../bundlesupport/AbstractBundleInstallMojo.java | 71 ++++++++++++++-------- 1 file changed, 45 insertions(+), 26 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 501388c..2ac5385 100644 --- a/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java +++ b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java @@ -39,50 +39,59 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo { /** * The URL of the running Sling instance. - * - * @parameter expression="${sling.url}" default-value="http://localhost:8080/sling" + * + * @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; + /** + * Whether to refresh the packages after installing the uploaded bundle + * + * @parameter expression="${sling.refreshPackages}" default-value="true" + * @required + */ + private boolean refreshPackages; + public AbstractBundleInstallMojo() { super(); } protected abstract String getBundleFileName() throws MojoExecutionException; - + public void execute() throws MojoExecutionException { // get the file to upload @@ -96,52 +105,62 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo { return; } - getLog().info("Installing Bundle " + bundleName + "(" + bundleFile + ") to " + slingUrl); + getLog().info( + "Installing Bundle " + bundleName + "(" + bundleFile + ") to " + + slingUrl); post(slingUrl, bundleFile); } - protected void post(String targetURL, File file) throws MojoExecutionException { - + protected void post(String targetURL, File file) + throws MojoExecutionException { + // 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 FilePart("bundlefile", new FilePartSource( + file.getName(), file))); partList.add(new StringPart("bundlestartlevel", bundleStartLevel)); - + if (bundleStart) { partList.add(new StringPart("bundlestart", "start")); } - + + if (refreshPackages) { + partList.add(new StringPart("refreshPackages", "true")); + } + 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); + 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)); + "Installation failed, cause: " + + HttpStatus.getStatusText(status)); } } catch (Exception ex) { - throw new MojoExecutionException("Installation on " + targetURL + " failed, cause: " + ex.getMessage(), ex); + throw new MojoExecutionException("Installation on " + targetURL + + " failed, cause: " + ex.getMessage(), ex); } finally { filePost.releaseConnection(); } } - } \ No newline at end of file -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
