You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2011/11/30 15:03:22 UTC
svn commit: r1208441 -
/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java
Author: cziegeler
Date: Wed Nov 30 14:03:21 2011
New Revision: 1208441
URL: http://svn.apache.org/viewvc?rev=1208441&view=rev
Log:
SLING-2310 : Attach bundle list goal should also add configuration artifact
Modified:
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java
Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java?rev=1208441&r1=1208440&r2=1208441&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachBundleListMojo.java Wed Nov 30 14:03:21 2011
@@ -17,12 +17,16 @@
package org.apache.sling.maven.projectsupport;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Writer;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.zip.ZipArchiver;
+import org.codehaus.plexus.util.FileUtils;
/**
* Attaches the bundle list as a project artifact.
@@ -43,7 +47,19 @@ public class AttachBundleListMojo extend
*/
private File outputFile;
- private BundleListXpp3Writer writer = new BundleListXpp3Writer();
+ /**
+ * @parameter default-value="${project.build.directory}/bundleListconfig"
+ */
+ private File configOutputDir;
+
+ /**
+ * The zip archiver.
+ *
+ * @component role="org.codehaus.plexus.archiver.Archiver" roleHint="zip"
+ */
+ private ZipArchiver zipArchiver;
+
+ private final BundleListXpp3Writer writer = new BundleListXpp3Writer();
@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
@@ -62,6 +78,82 @@ public class AttachBundleListMojo extend
}
}
}
+ this.getLog().info("Attaching bundle list configuration");
+ try {
+ this.attachConfigurations();
+ } catch (final IOException ioe) {
+ throw new MojoExecutionException("Unable to attach configuration.", ioe);
+ } catch (final ArchiverException ioe) {
+ throw new MojoExecutionException("Unable to attach configuration.", ioe);
+ }
}
+ private boolean checkFile(final File f) {
+ return f != null && f.exists();
+ }
+
+ private void attachConfigurations() throws MojoExecutionException, IOException, ArchiverException {
+ if ( this.ignoreBundleListConfig ) {
+ this.getLog().debug("ignoreBundleListConfig is set to true, therefore not attaching configurations.");
+ return;
+ }
+ // check if we have configurations
+ boolean hasConfigs = this.checkFile(this.getConfigDirectory());
+ hasConfigs |= this.getSlingBootstrap(true) != null;
+ hasConfigs |= this.getSlingBootstrap(false) != null;
+ hasConfigs |= this.getSlingProperties(true) != null;
+ hasConfigs |= this.getSlingProperties(false) != null;
+
+ if ( !hasConfigs ) {
+ this.getLog().debug("No configurations to attach.");
+ return;
+ }
+ // copy configuration, as this project might use different names we have to copy everything!
+ this.configOutputDir.mkdirs();
+ if ( this.getSlingBootstrap(false) != null ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ FileUtils.fileWrite(new File(slingDir, AttachPartialBundleListMojo.SLING_WEBAPP_BOOTSTRAP).getAbsolutePath(),
+ "UTF-8", this.getSlingBootstrap(false));
+ }
+ if ( this.getSlingProperties(false) != null ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ final FileOutputStream fos = new FileOutputStream(new File(slingDir, AttachPartialBundleListMojo.SLING_WEBAPP_PROPS));
+ try {
+ this.getSlingProperties(false).store(fos, null);
+ } finally {
+ try { fos.close(); } catch (final IOException ioe) {}
+ }
+ }
+ if ( this.getSlingBootstrap(true) != null ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ FileUtils.fileWrite(new File(slingDir, AttachPartialBundleListMojo.SLING_STANDALONE_BOOTSTRAP).getAbsolutePath(),
+ "UTF-8", this.getSlingBootstrap(true));
+ }
+ if ( this.getSlingProperties(true) != null ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ final FileOutputStream fos = new FileOutputStream(new File(slingDir, AttachPartialBundleListMojo.SLING_STANDALONE_PROPS));
+ try {
+ this.getSlingProperties(true).store(fos, null);
+ } finally {
+ try { fos.close(); } catch (final IOException ioe) {}
+ }
+ }
+ if ( this.checkFile(this.getConfigDirectory()) ) {
+ final File configDir = new File(this.configOutputDir, "config");
+ configDir.mkdirs();
+ FileUtils.copyDirectory(this.getConfigDirectory(), configDir,
+ null, FileUtils.getDefaultExcludesAsString());
+ }
+ final File destFile = new File(this.configOutputDir.getParent(), this.configOutputDir.getName() + ".zip");
+ zipArchiver.setDestFile(destFile);
+ zipArchiver.addDirectory(this.configOutputDir);
+ zipArchiver.createArchive();
+
+ projectHelper.attachArtifact(project, AttachPartialBundleListMojo.CONFIG_TYPE,
+ AttachPartialBundleListMojo.CONFIG_CLASSIFIER, destFile);
+ }
}