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/08/18 15:35:37 UTC
svn commit: r1159213 -
/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/
Author: cziegeler
Date: Thu Aug 18 13:35:36 2011
New Revision: 1159213
URL: http://svn.apache.org/viewvc?rev=1159213&view=rev
Log:
SLING-2183 : Bundle configurations and sling files with bundlelist
Modified:
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java?rev=1159213&r1=1159212&r2=1159213&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java Thu Aug 18 13:35:36 2011
@@ -48,4 +48,25 @@ public abstract class AbstractBundleList
*/
protected MavenProjectHelper projectHelper;
+ /**
+ * @parameter expression="${configDirectory}"
+ * default-value="src/main/config"
+ */
+ private File configDirectory;
+
+ /**
+ * @parameter expression="${additionalSlingProps}"
+ * default-value="src/main/sling/additional.properties"
+ */
+ protected File additionalSlingProps;
+
+ /**
+ * @parameter expression="${additionalSlingBootstrap}"
+ * default-value="src/main/sling/bootstrap.txt"
+ */
+ protected File additionalSlingBootstrap;
+
+ protected File getConfigDirectory() {
+ return this.configDirectory;
+ }
}
Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java?rev=1159213&r1=1159212&r2=1159213&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractLaunchpadStartingMojo.java Thu Aug 18 13:35:36 2011
@@ -135,8 +135,8 @@ public abstract class AbstractLaunchpadS
List<String> empty = Collections.emptyList();
return empty.iterator();
} else if (path.equals(CONFIG_PATH_PREFIX)) {
- if (configDirectory.exists() && configDirectory.isDirectory()) {
- File[] configFiles = configDirectory.listFiles(new FileFilter() {
+ if (getConfigDirectory().exists() && getConfigDirectory().isDirectory()) {
+ File[] configFiles = getConfigDirectory().listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isFile();
@@ -188,7 +188,7 @@ public abstract class AbstractLaunchpadS
public URL getResource(String path) {
if (path.startsWith(CONFIG_PATH_PREFIX)) {
- File configFile = new File(configDirectory, path.substring(CONFIG_PATH_PREFIX.length() + 1));
+ File configFile = new File(getConfigDirectory(), path.substring(CONFIG_PATH_PREFIX.length() + 1));
if (configFile.exists()) {
try {
return configFile.toURI().toURL();
Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java?rev=1159213&r1=1159212&r2=1159213&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java Thu Aug 18 13:35:36 2011
@@ -21,6 +21,7 @@ import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
+import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.Set;
@@ -44,6 +45,9 @@ import org.apache.maven.shared.filtering
import org.apache.maven.shared.filtering.PropertyUtils;
import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Reader;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.zip.ZipUnArchiver;
+import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.drools.KnowledgeBase;
@@ -58,24 +62,6 @@ import org.drools.runtime.StatefulKnowle
public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo {
/**
- * @parameter expression="${configDirectory}"
- * default-value="src/main/config"
- */
- protected File configDirectory;
-
- /**
- * @parameter expression="${additionalSlingProps}"
- * default-value="src/main/sling/additional.properties"
- */
- private File additionalSlingProps;
-
- /**
- * @parameter expression="${additionalSlingBootstrap}"
- * default-value="src/main/sling/bootstrap.txt"
- */
- private File additionalSlingBootstrap;
-
- /**
* JAR Packaging type.
*/
protected static final String JAR = "jar";
@@ -182,6 +168,29 @@ public abstract class AbstractUsingBundl
*/
private MavenFileFilter mavenFileFilter;
+ /**
+ * The zip unarchiver.
+ *
+ * @component role="org.codehaus.plexus.archiver.UnArchiver" roleHint="zip"
+ */
+ private ZipUnArchiver zipUnarchiver;
+
+ private Properties slingProperties;
+
+ private String slingBootstrapCommand;
+
+ /**
+ * @parameter default-value="${project.build.directory}/tmpBundleListconfig"
+ */
+ private File tmpOutputDir;
+
+ /**
+ * @parameter default-value="${project.build.directory}/tmpConfigDir"
+ */
+ private File tempConfigDir;
+
+ private File overlayConfigDir;
+
public final void execute() throws MojoFailureException, MojoExecutionException {
try {
initBundleList();
@@ -194,6 +203,14 @@ public abstract class AbstractUsingBundl
}
+ @Override
+ protected File getConfigDirectory() {
+ if ( this.overlayConfigDir != null ) {
+ return this.overlayConfigDir;
+ }
+ return super.getConfigDirectory();
+ }
+
/**
* Execute the logic of the plugin after the default artifacts have been
* initialized.
@@ -331,13 +348,62 @@ public abstract class AbstractUsingBundl
}
}
- Set<Artifact> dependencies = project.getDependencyArtifacts();
+ final Set<Artifact> dependencies = project.getDependencyArtifacts();
for (Artifact artifact : dependencies) {
if (PARTIAL.equals(artifact.getType())) {
getLog().info(
String.format("merging partial bundle list for %s:%s:%s", artifact.getGroupId(),
artifact.getArtifactId(), artifact.getVersion()));
bundleList.merge(readBundleList(artifact.getFile()));
+
+ // check for configuration artifact
+ Artifact cfgArtifact = null;
+ try {
+ cfgArtifact = getArtifact(artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getVersion(),
+ AttachPartialBundleListMojo.CONFIG_TYPE,
+ AttachPartialBundleListMojo.CONFIG_CLASSIFIER);
+ } catch (final MojoExecutionException ignore) {
+ // we just ignore this
+ }
+ if ( cfgArtifact != null ) {
+ getLog().info(
+ String.format("merging partial bundle list configuration for %s:%s:%s", cfgArtifact.getGroupId(),
+ cfgArtifact.getArtifactId(), cfgArtifact.getVersion()));
+
+ // extract
+ zipUnarchiver.setSourceFile(cfgArtifact.getFile());
+ try {
+ this.tmpOutputDir.mkdirs();
+ zipUnarchiver.setDestDirectory(this.tmpOutputDir);
+ zipUnarchiver.extract();
+
+ final File slingDir = new File(this.tmpOutputDir, "sling");
+ this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_ADDITIONAL_PROPS));
+ this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_BOOTSTRAP));
+
+ // and now configurations
+ if ( this.overlayConfigDir == null ) {
+ this.tempConfigDir.mkdirs();
+ if ( this.getConfigDirectory().exists() ) {
+ FileUtils.copyDirectory(this.getConfigDirectory(), this.tempConfigDir,
+ null, FileUtils.getDefaultExcludesAsString());
+ }
+ this.overlayConfigDir = this.tempConfigDir;
+ }
+ final File configDir = new File(this.tmpOutputDir, "config");
+ if ( configDir.exists() ) {
+ FileUtils.copyDirectory(configDir, this.tempConfigDir,
+ null, FileUtils.getDefaultExcludesAsString());
+ }
+ } catch (final ArchiverException ae) {
+ throw new MojoExecutionException("Unable to extract configuration archive.",ae);
+ } finally {
+ // and delete at the end
+ FileUtils.deleteDirectory(this.tmpOutputDir);
+ }
+ }
}
}
@@ -392,15 +458,23 @@ public abstract class AbstractUsingBundl
}
}
- protected Properties getSlingProperties() throws MojoExecutionException {
- if (this.additionalSlingProps.exists()) {
+ private void readSlingProperties(final File propsFile) throws MojoExecutionException {
+ if (propsFile.exists()) {
File tmp = null;
try {
tmp = File.createTempFile("sling", "props");
- mavenFileFilter.copyFile(this.additionalSlingProps, tmp, true, project, null, true,
+ mavenFileFilter.copyFile(propsFile, tmp, true, project, null, true,
System.getProperty("file.encoding"), mavenSession);
final Properties loadedProps = PropertyUtils.loadPropertyFile(tmp, null);
- return loadedProps;
+ if ( this.slingProperties == null ) {
+ this.slingProperties = loadedProps;
+ } else {
+ final Enumeration<Object> keys = loadedProps.keys();
+ while ( keys.hasMoreElements() ) {
+ final Object key = keys.nextElement();
+ this.slingProperties.put(key, loadedProps.get(key));
+ }
+ }
} catch (IOException e) {
throw new MojoExecutionException("Unable to create filtered properties file", e);
} catch (MavenFilteringException e) {
@@ -411,32 +485,38 @@ public abstract class AbstractUsingBundl
}
}
}
- return null;
+ }
+
+ protected Properties getSlingProperties() throws MojoExecutionException {
+ readSlingProperties(this.additionalSlingProps);
+ return this.slingProperties;
}
/**
- * Try to read the bootstrap command file and return its content
+ * Try to read the bootstrap command file
* The filter is copied to a tmp location to apply filtering.
- * @return The contents are <code>null</code>
* @throws MojoExecutionException
*/
- protected String getSlingBootstrap() throws MojoExecutionException {
- if (this.additionalSlingBootstrap.exists()) {
+ private void readSlingBootstrap(final File bootstrapFile) throws MojoExecutionException {
+ if (bootstrapFile.exists()) {
File tmp = null;
Reader reader = null;
try {
tmp = File.createTempFile("sling", "bootstrap");
- mavenFileFilter.copyFile(this.additionalSlingBootstrap, tmp, true, project, null, true,
+ mavenFileFilter.copyFile(bootstrapFile, tmp, true, project, null, true,
System.getProperty("file.encoding"), mavenSession);
reader = new FileReader(tmp);
final StringBuilder sb = new StringBuilder();
+ if ( this.slingBootstrapCommand != null ) {
+ sb.append(this.slingBootstrapCommand);
+ }
final char[] buffer = new char[2048];
int l;
while ( (l = reader.read(buffer, 0, buffer.length) ) != -1 ) {
sb.append(buffer, 0, l);
}
- return sb.toString();
+ this.slingBootstrapCommand = sb.toString();
} catch (IOException e) {
throw new MojoExecutionException("Unable to create filtered bootstrap file", e);
} catch (MavenFilteringException e) {
@@ -452,6 +532,17 @@ public abstract class AbstractUsingBundl
}
}
}
- return null;
+ }
+
+ /**
+ * Try to read the bootstrap command file and return its content
+ * The filter is copied to a tmp location to apply filtering.
+ * @return The contents are <code>null</code>
+ * @throws MojoExecutionException
+ */
+ protected String getSlingBootstrap() throws MojoExecutionException {
+ this.readSlingBootstrap(this.additionalSlingBootstrap);
+
+ return this.slingBootstrapCommand;
}
}
Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java?rev=1159213&r1=1159212&r2=1159213&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java Thu Aug 18 13:35:36 2011
@@ -5,9 +5,9 @@
* 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
@@ -16,20 +16,102 @@
*/
package org.apache.sling.maven.projectsupport;
+import java.io.File;
+import java.io.IOException;
+
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+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.
- *
+ *
* @goal attach-partial-bundle-list
* @phase package
* @description attach the partial bundle list as a project artifact
*/
public class AttachPartialBundleListMojo extends AbstractBundleListMojo {
+ public static final String CONFIG_CLASSIFIER = "bundlelistconfig";
+
+ public static final String CONFIG_TYPE = "zip";
+
+ public static final String SLING_ADDITIONAL_PROPS = "additional.properties";
+
+ public static final String SLING_BOOTSTRAP = "bootstrap.txt";
+
+ /**
+ * @parameter default-value="${project.build.directory}/bundleListconfig"
+ */
+ private File configOutputDir;
+
+ /**
+ * @parameter expression="${ignoreBundleListConfig}"
+ * default-value="false"
+ */
+ private boolean ignoreBundleListConfig;
+
+ /**
+ * The zip archiver.
+ *
+ * @component role="org.codehaus.plexus.archiver.Archiver" roleHint="zip"
+ */
+ private ZipArchiver zipArchiver;
+
public void execute() throws MojoExecutionException, MojoFailureException {
project.getArtifact().setFile(bundleListFile);
+ 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.checkFile(this.additionalSlingBootstrap);
+ hasConfigs |= this.checkFile(this.additionalSlingProps);
+
+ 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.checkFile(this.additionalSlingBootstrap) ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ FileUtils.copyFile(this.additionalSlingBootstrap, new File(slingDir, SLING_BOOTSTRAP));
+ }
+ if ( this.checkFile(this.additionalSlingProps) ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ FileUtils.copyFile(this.additionalSlingProps, new File(slingDir, SLING_ADDITIONAL_PROPS));
+ }
+ 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, CONFIG_TYPE, CONFIG_CLASSIFIER, destFile);
+ }
}
Modified: sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java?rev=1159213&r1=1159212&r2=1159213&view=diff
==============================================================================
--- sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java (original)
+++ sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java Thu Aug 18 13:35:36 2011
@@ -303,7 +303,7 @@ public class PreparePackageMojo extends
private void copyConfigurationFiles() throws MojoExecutionException {
try {
- FileUtils.copyDirectory(configDirectory, new File(getOutputDirectory(), CONFIG_PATH_PREFIX), null, FileUtils.getDefaultExcludesAsString());
+ FileUtils.copyDirectory(this.getConfigDirectory(), new File(getOutputDirectory(), CONFIG_PATH_PREFIX), null, FileUtils.getDefaultExcludesAsString());
} catch (IOException e) {
throw new MojoExecutionException("Unable to copy configuration files", e);
}