incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1159088 - in /sling/trunk/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport: AbstractUsingBundleListMojo.java PreparePackageMojo.java
Date Thu, 18 Aug 2011 08:46:20 GMT
Author: cziegeler
Date: Thu Aug 18 08:46:19 2011
New Revision: 1159088

URL: http://svn.apache.org/viewvc?rev=1159088&view=rev
Log:
SLING-2182 : Provide a way to specify additional bootstrap commands

Modified:
    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/PreparePackageMojo.java

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=1159088&r1=1159087&r2=1159088&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 08:46:19 2011
@@ -18,7 +18,9 @@ package org.apache.sling.maven.projectsu
 
 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 AbstractUsingBundl
      * @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 AbstractUsingBundl
     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 AbstractUsingBundl
      * @readonly
      * @required
      */
-    private List remoteRepos;
+    private List<?> remoteRepos;
 
     /**
      * Used to look up Artifacts in the remote repository.
@@ -232,7 +239,7 @@ public abstract class AbstractUsingBundl
         // 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 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 {
+        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;
+    }
 }

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=1159088&r1=1159087&r2=1159088&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 08:46:19 2011
@@ -19,6 +19,7 @@ package org.apache.sling.maven.projectsu
 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 
         }
     }
 
-	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 
 				.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 
 	protected File getOutputDirectory() {
 		if (WAR.equals(packaging)) {
 			return warOutputDirectory;
-		} else {
-			return buildOutputDirectory;
-		}
+        }
+		return buildOutputDirectory;
 	}
 
 	protected void unpackBaseArtifact() throws MojoExecutionException {



Mime
View raw message