This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag maven-launchpad-plugin-2.1.0 in repository https://gitbox.apache.org/repos/asf/sling-maven-launchpad-plugin.git
commit ba156ae8d985e97680b9ec5e257e50a48dcb6876 Author: Carsten Ziegeler <[email protected]> AuthorDate: Thu Aug 18 08:46:19 2011 +0000 SLING-2182 : Provide a way to specify additional bootstrap commands git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/maven/maven-launchpad-plugin@1159088 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractUsingBundleListMojo.java | 58 ++++++++- .../maven/projectsupport/PreparePackageMojo.java | 135 ++++++++++++++------- 2 files changed, 142 insertions(+), 51 deletions(-) diff --git a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java index a9af72a..be08450 100644 --- a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java +++ b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java @@ -18,7 +18,9 @@ package org.apache.sling.maven.projectsupport; import java.io.File; import java.io.FileInputStream; +import java.io.FileReader; import java.io.IOException; +import java.io.Reader; import java.util.List; import java.util.Properties; import java.util.Set; @@ -65,7 +67,13 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo * @parameter expression="${additionalSlingProps}" * default-value="src/main/sling/additional.properties" */ - protected File additionalSlingProps; + private File additionalSlingProps; + + /** + * @parameter expression="${additionalSlingBootstrap}" + * default-value="src/main/sling/bootstrap.txt" + */ + private File additionalSlingBootstrap; /** * JAR Packaging type. @@ -84,9 +92,8 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo protected static boolean shouldCopy(File source, File dest) { if (!dest.exists()) { return true; - } else { - return source.lastModified() > dest.lastModified(); } + return source.lastModified() > dest.lastModified(); } /** @@ -149,7 +156,7 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo * @readonly * @required */ - private List remoteRepos; + private List<?> remoteRepos; /** * Used to look up Artifacts in the remote repository. @@ -232,7 +239,7 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo // This code kicks in when the version specifier is a range. if (vr.getRecommendedVersion() == null) { try { - List availVersions = metadataSource.retrieveAvailableVersions(artifact, local, remoteRepos); + List<?> availVersions = metadataSource.retrieveAvailableVersions(artifact, local, remoteRepos); ArtifactVersion resolvedVersion = vr.matchVersion(availVersions); artifact.setVersion(resolvedVersion.toString()); } catch (ArtifactMetadataRetrievalException e) { @@ -406,4 +413,45 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo } 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 { + if (this.additionalSlingBootstrap.exists()) { + File tmp = null; + Reader reader = null; + try { + tmp = File.createTempFile("sling", "bootstrap"); + mavenFileFilter.copyFile(this.additionalSlingBootstrap, tmp, true, project, null, true, + System.getProperty("file.encoding"), mavenSession); + reader = new FileReader(tmp); + final StringBuilder sb = new StringBuilder(); + 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(); + } catch (IOException e) { + throw new MojoExecutionException("Unable to create filtered bootstrap file", e); + } catch (MavenFilteringException e) { + throw new MojoExecutionException("Unable to create filtered bootstrap file", e); + } finally { + if (tmp != null) { + tmp.delete(); + } + if ( reader != null ) { + try { + reader.close(); + } catch (final IOException ignore) {} + } + } + } + return null; + } } diff --git a/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java index b2554da..2f60407 100644 --- a/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java +++ b/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java @@ -19,6 +19,7 @@ package org.apache.sling.maven.projectsupport; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.util.Enumeration; import java.util.Properties; @@ -137,13 +138,86 @@ public class PreparePackageMojo extends AbstractLaunchpadFrameworkMojo { } } - private void copyBaseArtifact() throws MojoExecutionException { + /** + * Patch the sling properties + */ + private void patchSlingProperties(final File dest, final Properties additionalProps) + throws MojoExecutionException { + final File origSlingProps = new File(dest, "sling.properties"); + if ( !origSlingProps.exists() ) { + throw new MojoExecutionException("sling.properties not found at " + origSlingProps); + } + + // read original properties + final Properties orig = new Properties(); + FileInputStream fis = null; + try { + fis = new FileInputStream(origSlingProps); + orig.load(fis); + } catch (final IOException ioe) { + throw new MojoExecutionException("Unable to read " + origSlingProps, ioe); + } finally { + if ( fis != null ) { + try { fis.close(); } catch (final IOException ignore) {} + } + } + + // patch + final Enumeration<Object> keys = additionalProps.keys(); + if ( keys.hasMoreElements() ) { + getLog().info("Patching sling.properties"); + } + while ( keys.hasMoreElements() ) { + final Object key = keys.nextElement(); + orig.put(key, additionalProps.get(key)); + } + + /// and save + FileOutputStream fos = null; + try { + fos = new FileOutputStream(origSlingProps); + orig.store(fos, null); + } catch (final IOException ioe) { + throw new MojoExecutionException("Unable to save " + origSlingProps, ioe); + } finally { + if ( fis != null ) { + try { fis.close(); } catch (final IOException ignore) {} + } + } + } + + /** + * Patch the sling bootstrap command file + */ + private void patchSlingBootstrap(final File dest, final String additionalCmd) + throws MojoExecutionException { + getLog().info("Patching sling.bootstrap.txt"); + final File origSlingCmd = new File(dest, "sling_bootstrap.txt"); + FileWriter writer = null; + + /// and write or append + try { + if ( !origSlingCmd.exists() ) { + writer = new FileWriter(origSlingCmd); + } else { + writer = new FileWriter(origSlingCmd, true); + } + + writer.write(additionalCmd); + } catch (final IOException ioe) { + throw new MojoExecutionException("Unable to save " + origSlingCmd, ioe); + } finally { + if ( writer != null ) { + try { writer.close(); } catch (final IOException ignore) {} + } + } + } + + private void copyBaseArtifact() throws MojoExecutionException { Artifact artifact = getBaseArtifact(); if (artifact == null) { throw new MojoExecutionException( - String - .format( - "Project doesn't have a base dependency of groupId %s and artifactId %s", + String.format("Project doesn't have a base dependency of groupId %s and artifactId %s", base.getGroupId(), base.getArtifactId())); } File destinationDir = new File(getOutputDirectory(), baseDestination); @@ -151,53 +225,23 @@ public class PreparePackageMojo extends AbstractLaunchpadFrameworkMojo { .getArtifactId() + "." + artifact.getArtifactHandler().getExtension()); - // check if custom sling.properties file exists + // check if custom sling.properties file or bootstrap command exists final Properties additionalProps = this.getSlingProperties(); - if ( additionalProps != null ) { + final String bootstrapCmd = this.getSlingBootstrap(); + if ( additionalProps != null || bootstrapCmd != null ) { // unpack to a temp destination final File dest = new File(this.tempDirectory, "basejar"); try { unpack(artifact.getFile(), dest); - final File origSlingProps = new File(dest, "sling.properties"); - if ( !origSlingProps.exists() ) { - throw new MojoExecutionException("sling.properties not found at " + origSlingProps); - } - // read original properties - final Properties orig = new Properties(); - FileInputStream fis = null; - try { - fis = new FileInputStream(origSlingProps); - orig.load(fis); - } catch (final IOException ioe) { - throw new MojoExecutionException("Unable to read " + origSlingProps, ioe); - } finally { - if ( fis != null ) { - try { fis.close(); } catch (final IOException ignore) {} - } + // patch sling properties + if ( additionalProps != null ) { + this.patchSlingProperties(dest, additionalProps); } - // patch - final Enumeration<Object> keys = additionalProps.keys(); - if ( keys.hasMoreElements() ) { - getLog().info("Patching sling.properties"); - } - while ( keys.hasMoreElements() ) { - final Object key = keys.nextElement(); - orig.put(key, additionalProps.get(key)); - } - - /// and save - FileOutputStream fos = null; - try { - fos = new FileOutputStream(origSlingProps); - orig.store(fos, null); - } catch (final IOException ioe) { - throw new MojoExecutionException("Unable to save " + origSlingProps, ioe); - } finally { - if ( fis != null ) { - try { fis.close(); } catch (final IOException ignore) {} - } + // patch bootstrap command + if ( bootstrapCmd != null ) { + this.patchSlingBootstrap(dest, bootstrapCmd); } // and repack again @@ -245,9 +289,8 @@ public class PreparePackageMojo extends AbstractLaunchpadFrameworkMojo { protected File getOutputDirectory() { if (WAR.equals(packaging)) { return warOutputDirectory; - } else { - return buildOutputDirectory; - } + } + return buildOutputDirectory; } protected void unpackBaseArtifact() throws MojoExecutionException { -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
