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 13dad4c11dc29aa874a64ca5881b7c5d12ba37d3 Author: Carsten Ziegeler <[email protected]> AuthorDate: Wed Jul 13 12:12:18 2011 +0000 SLING-2134 : Provide a way to add additional properties to sling.properties git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/maven/maven-launchpad-plugin@1145965 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractUsingBundleListMojo.java | 36 +++++++++++++++++++--- .../maven/projectsupport/PreparePackageMojo.java | 21 +++---------- 2 files changed, 35 insertions(+), 22 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 ec00009..a9af72a 100644 --- a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java +++ b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java @@ -37,6 +37,9 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.shared.filtering.MavenFileFilter; +import org.apache.maven.shared.filtering.MavenFilteringException; +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.util.StringUtils; @@ -59,6 +62,12 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo protected File configDirectory; /** + * @parameter expression="${additionalSlingProps}" + * default-value="src/main/sling/additional.properties" + */ + protected File additionalSlingProps; + + /** * JAR Packaging type. */ protected static final String JAR = "jar"; @@ -161,6 +170,11 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo */ protected MavenSession mavenSession; + /** + * @component + */ + private MavenFileFilter mavenFileFilter; + public final void execute() throws MojoFailureException, MojoExecutionException { try { initBundleList(); @@ -371,11 +385,23 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo } } - protected File getSlingProperties() { - if ( this.configDirectory != null && this.configDirectory.exists() && this.configDirectory.isDirectory() ) { - final File slingProps = new File(this.configDirectory, "sling.properties"); - if ( slingProps.exists() && slingProps.isFile() ) { - return slingProps; + protected Properties getSlingProperties() throws MojoExecutionException { + if (this.additionalSlingProps.exists()) { + File tmp = null; + try { + tmp = File.createTempFile("sling", "props"); + mavenFileFilter.copyFile(this.additionalSlingProps, tmp, true, project, null, true, + System.getProperty("file.encoding"), mavenSession); + final Properties loadedProps = PropertyUtils.loadPropertyFile(tmp, null); + return loadedProps; + } catch (IOException e) { + throw new MojoExecutionException("Unable to create filtered properties file", e); + } catch (MavenFilteringException e) { + throw new MojoExecutionException("Unable to create filtered properties file", e); + } finally { + if (tmp != null) { + tmp.delete(); + } } } 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 1d8c989..b2554da 100644 --- a/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java +++ b/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java @@ -152,8 +152,8 @@ public class PreparePackageMojo extends AbstractLaunchpadFrameworkMojo { + "." + artifact.getArtifactHandler().getExtension()); // check if custom sling.properties file exists - final File slingProps = this.getSlingProperties(); - if ( slingProps != null ) { + final Properties additionalProps = this.getSlingProperties(); + if ( additionalProps != null ) { // unpack to a temp destination final File dest = new File(this.tempDirectory, "basejar"); try { @@ -177,27 +177,14 @@ public class PreparePackageMojo extends AbstractLaunchpadFrameworkMojo { } } - // read additional properties - final Properties addProps = new Properties(); - try { - fis = new FileInputStream(slingProps); - addProps.load(fis); - } catch (final IOException ioe) { - throw new MojoExecutionException("Unable to read " + slingProps, ioe); - } finally { - if ( fis != null ) { - try { fis.close(); } catch (final IOException ignore) {} - } - } - // patch - final Enumeration<Object> keys = addProps.keys(); + 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, addProps.get(key)); + orig.put(key, additionalProps.get(key)); } /// and save -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
