I moved it to the sandbox until released

On 6 Jun 2007 20:43:31 -0000, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:


 Revision 4287 Author arsenalist Date 2007-06-06 15:43:30 -0500 (Wed, 06 Jun
2007)
Log Message Initial commit for properties-maven-plugin

Added Paths

trunk/mojo/properties-maven-plugin/
trunk/mojo/properties-maven-plugin/LICENSE.txt
trunk/mojo/properties-maven-plugin/pom.xml
trunk/mojo/properties-maven-plugin/src/
trunk/mojo/properties-maven-plugin/src/main/
trunk/mojo/properties-maven-plugin/src/main/java/
trunk/mojo/properties-maven-plugin/src/main/java/org/
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/AbstractWritePropertiesMojo.java
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/ReadPropertiesMojo.java
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/WriteActiveProfileProperties.java
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/WriteProjectProperties.java
trunk/mojo/properties-maven-plugin/src/site/
trunk/mojo/properties-maven-plugin/src/site/apt/
trunk/mojo/properties-maven-plugin/src/site/apt/howto.apt
trunk/mojo/properties-maven-plugin/src/site/apt/index.apt
trunk/mojo/properties-maven-plugin/src/site/apt/introduction.apt
trunk/mojo/properties-maven-plugin/src/site/site.xml

Diff
Added: trunk/mojo/properties-maven-plugin/LICENSE.txt (0 =>
4287) --- trunk/mojo/properties-maven-plugin/LICENSE.txt
(rev 0)
+++ trunk/mojo/properties-maven-plugin/LICENSE.txt
2007-06-06 20:43:30 UTC (rev 4287)
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright 2005-2006 The Codehaus.
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy of
+this software and associated documentation files (the "Software"), to deal
in
+the Software without restriction, including without limitation the rights
to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies
+of the Software, and to permit persons to whom the Software is furnished to
do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE
+SOFTWARE.
\ No newline at end of file


Added: trunk/mojo/properties-maven-plugin/pom.xml (0 =>
4287) --- trunk/mojo/properties-maven-plugin/pom.xml (rev
0)
+++ trunk/mojo/properties-maven-plugin/pom.xml 2007-06-06
20:43:30 UTC (rev 4287)
@@ -0,0 +1,41 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd";>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>properties-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>Maven Properties Plugin</name>
+
+ <parent>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>mojo-sandbox</artifactId>
+ <version>2</version>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>2.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <developers>
+ <developer>
+ <id>1</id>
+ <name>Zarar Siddiqi</name>
+ <email>[EMAIL PROTECTED]</email>
+ <url>http://arsenalist.com/tag/tech</url>
+ </developer>
+ </developers>
+</project>


Added:
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/AbstractWritePropertiesMojo.java
(0 => 4287) ---
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/AbstractWritePropertiesMojo.java
(rev 0)
+++
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/AbstractWritePropertiesMojo.java
2007-06-06 20:43:30 UTC (rev 4287)
@@ -0,0 +1,63 @@
+package org.codehaus.mojo.properties;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Zarar Siddiqi</a>
+ * @version $Id$
+ */
+public abstract class AbstractWritePropertiesMojo extends AbstractMojo {
+
+ /**
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ */
+ protected MavenProject project;
+
+ /**
+ * @parameter
+ * @required
+ */
+ protected File outputFile;
+
+ protected void writeProperties(Properties properties, File file) {
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(file);
+ } catch (FileNotFoundException e) {
+ getLog().error("Could not create FileOutputStream: " + fos);
+ e.printStackTrace();
+ }
+ try {
+ properties.store(fos, "Properties");
+ } catch (IOException e) {
+ getLog().error("Error writing properties: " + fos);
+ e.printStackTrace();
+ }
+ try {
+ fos.close();
+ } catch (IOException e) {
+ getLog().error("Error closing FileOutputStream: " + fos);
+ e.printStackTrace();
+ }
+ }
+
+ protected void validateOutputFile() throws MojoExecutionException {
+ if (outputFile.isDirectory()) {
+ throw new MojoExecutionException("outputFile must be a
file and not a directory");
+ }
+ // ensure path exists
+ if (outputFile.getParentFile() != null) {
+ outputFile.getParentFile().mkdirs();
+ }
+ }
+}


Added:
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/ReadPropertiesMojo.java
(0 => 4287) ---
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/ReadPropertiesMojo.java
(rev 0)
+++
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/ReadPropertiesMojo.java
2007-06-06 20:43:30 UTC (rev 4287)
@@ -0,0 +1,147 @@
+package org.codehaus.mojo.properties;
+
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Properties;
+
+/**
+ * Reads property files as Project properties
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Zarar Siddiqi</a>
+ * @version $Id$
+ * @goal read-project-properties
+ */
+public class ReadPropertiesMojo
+ extends AbstractMojo
+{
+
+ /**
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * @parameter
+ * @required
+ */
+ private File[] files;
+
+ public void execute()
+ throws MojoExecutionException {
+ Properties projectProperties = new Properties();
+ for (int i = 0; i < files.length; i++) {
+ File file = files[i];
+ try {
+ FileInputStream stream = new FileInputStream(file);
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("Loading property file: " + file);
+ }
+ projectProperties = project.getProperties();
+ try {
+ projectProperties.load(stream);
+ } finally {
+ if( stream != null ) {
+ stream.close();
+ }
+ }
+ } catch (Exception e) {
+ throw new MojoExecutionException("Error: ", e);
+ }
+ }
+ boolean useEnvVariables = false;
+ for( Enumeration n = projectProperties.propertyNames();
n.hasMoreElements(); ) {
+ String k = (String) n.nextElement();
+ String p = (String) projectProperties.get(k);
+ if( p.indexOf("${env.") != -1) {
+ useEnvVariables = true;
+ break;
+ }
+ }
+ Properties environment = null;
+ if( useEnvVariables ) {
+ try {
+ environment = CommandLineUtils.getSystemEnvVars();
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error: ", e);
+ }
+ }
+ for( Enumeration n = projectProperties.propertyNames();
n.hasMoreElements(); ) {
+ String k = (String) n.nextElement();
+ projectProperties.setProperty(k, getPropertyValue(k, projectProperties,
environment));
+ }
+ }
+
+ /**
+ * Retrieves a property value, replacing values like ${token}
+ * using the Properties to look them up.
+ * Shamelessly adapted from:
+ *
http://maven.apache.org/plugins/maven-war-plugin/xref/org/apache/maven/plugin/war/PropertyUtils.html
+ *
+ * It will leave unresolved properties alone, trying for System
+ * properties, and environment variables and implements reparsing
+ * (in the case that the value of a property contains a key), and will
+ * not loop endlessly on a pair like test = ${test}
+ *
+ * @param k property key
+ * @param p project properties
+ * @param environment environment variables
+ * @return resolved property value
+ */
+ private String getPropertyValue(String k, Properties p, Properties
environment) {
+ String v = p.getProperty(k);
+ String ret = "";
+ int idx, idx2;
+
+ while( (idx = v.indexOf("${")) >= 0 ) {
+ // append prefix to result
+ ret += v.substring(0, idx);
+
+ // strip prefix from original
+ v = v.substring(idx + 2);
+
+ // if no matching } then bail
+ if( (idx2 = v.indexOf("}")) < 0 ) {
+ break;
+ }
+
+ // strip out the key and resolve it
+ // resolve the key/value for the ${statement}
+ String nk = v.substring(0, idx2);
+ v = v.substring(idx2 + 1);
+ String nv = p.getProperty(nk);
+
+ // try global environment
+ if( nv == null ) {
+ nv = System.getProperty(nk);
+ }
+
+ // try environment variable
+ if( nv == null && nk.startsWith("env.") && environment != null) {
+ nv = environment.getProperty(nk.substring(4));
+ }
+
+ // if the key cannot be resolved,
+ // leave it alone ( and don't parse again )
+ // else prefix the original string with the
+ // resolved property ( so it can be parsed further )
+ // taking recursion into account.
+ if( nv == null || nv.equals(nk) ) {
+ ret += "${" + nk + "}";
+ } else {
+ v = nv + v;
+ }
+ }
+ return ret + v;
+ }
+}
+


Added:
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/WriteActiveProfileProperties.java
(0 => 4287) ---
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/WriteActiveProfileProperties.java
(rev 0)
+++
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/WriteActiveProfileProperties.java
2007-06-06 20:43:30 UTC (rev 4287)
@@ -0,0 +1,42 @@
+package org.codehaus.mojo.properties;
+
+/*
+ */
+
+import org.apache.maven.model.Profile;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Writes properties of all active profiles to a file
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Zarar Siddiqi</a>
+ * @version $Id$
+ * @goal write-active-profile-properties
+ */
+public class WriteActiveProfileProperties
+ extends AbstractWritePropertiesMojo
+{
+
+ public void execute()
+ throws MojoExecutionException {
+ validateOutputFile();
+ List list = project.getActiveProfiles();
+ if (getLog().isInfoEnabled()) {
+ getLog().info(list.size() + " profile(s) active");
+ }
+ Properties properties = new Properties();
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ Profile profile = (Profile) iter.next();
+ if (profile.getProperties() != null) {
+ properties.putAll(profile.getProperties());
+ }
+ }
+
+ writeProperties(properties, outputFile);
+ }
+}
+


Added:
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/WriteProjectProperties.java
(0 => 4287) ---
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/WriteProjectProperties.java
(rev 0)
+++
trunk/mojo/properties-maven-plugin/src/main/java/org/codehaus/mojo/properties/WriteProjectProperties.java
2007-06-06 20:43:30 UTC (rev 4287)
@@ -0,0 +1,22 @@
+package org.codehaus.mojo.properties;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.util.Properties;
+
+/**
+ * Writes project properties to a file
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Zarar Siddiqi</a>
+ * @version $Id$
+ * @goal write-project-properties
+ */
+public class WriteProjectProperties extends AbstractWritePropertiesMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException
{
+ validateOutputFile();
+ Properties properties = project.getProperties();
+ writeProperties(properties, outputFile);
+ }
+}


Added:
trunk/mojo/properties-maven-plugin/src/site/apt/howto.apt
(0 => 4287) ---
trunk/mojo/properties-maven-plugin/src/site/apt/howto.apt
(rev 0)
+++
trunk/mojo/properties-maven-plugin/src/site/apt/howto.apt
2007-06-06 20:43:30 UTC (rev 4287)
@@ -0,0 +1,73 @@
+Usage
+
+* The read-project-properties goal
+
+----------------
+<plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>maven-properties-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>initialize</phase>
+ <goals>
+ <goal>read-project-properties</goal>
+ </goals>
+ <configuration>
+ <files>
+ <file>etc/config/dev.properties</file>
+ </files>
+ </configuration>
+ </execution>
+ </executions>
+</plugin>
+
+----------------
+
+* The write-project-properties goal
+
+----------------
+<plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>maven-properties-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>write-project-properties</goal>
+ </goals>
+ <configuration>
+ <outputFile>
+ ${project.build.outputDirectory}/app.properties
+ </outputFile>
+ </configuration>
+ </execution>
+ </executions>
+</plugin>
+
+----------------
+
+* The write-active-profile-properties goal
+
+----------------
+<plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>maven-properties-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>write-active-profile-properties</goal>
+ </goals>
+ <configuration>
+ <outputFile>
+ ${project.build.outputDirectory}/app.properties
+ </outputFile>
+ </configuration>
+ </execution>
+ </executions>
+</plugin>
+
+----------------
\ No newline at end of file


Added:
trunk/mojo/properties-maven-plugin/src/site/apt/index.apt (
=> )
Added:
trunk/mojo/properties-maven-plugin/src/site/apt/introduction.apt
===================================================================
---
trunk/mojo/properties-maven-plugin/src/site/apt/introduction.apt
(rev 0)
+++
trunk/mojo/properties-maven-plugin/src/site/apt/introduction.apt
2007-06-06 20:43:30 UTC (rev 4287)
@@ -0,0 +1,4 @@
+Introduction
+
+ The Properties Maven Plugin is here to make life a little easier when
dealing
+ with properties. It provides goals to read and write properties from
files.


Added: trunk/mojo/properties-maven-plugin/src/site/site.xml
(0 => 4287) ---
trunk/mojo/properties-maven-plugin/src/site/site.xml (rev
0)
+++ trunk/mojo/properties-maven-plugin/src/site/site.xml
2007-06-06 20:43:30 UTC (rev 4287)
@@ -0,0 +1,28 @@
+<project name="Maven Properties Plugin">
+ <bannerLeft>
+ <name>Mojo</name>
+ <src>http://mojo.codehaus.org/images/mojo_logo.png</src>
+ <href>http://mojo.codehaus.org</href>
+ </bannerLeft>
+ <bannerRight>
+ <name>Codehaus</name>
+
<src>http://mojo.codehaus.org/images/codehaus-small.png</src>
+ <href>http://www.codehaus.org</href>
+ </bannerRight>
+ <body>
+ <links>
+ <item name="Mojo" href="http://mojo.codehaus.org"/>
+ <item name="Maven" href="http://maven.apache.org/"/>
+ </links>
+ <menu name="Mojo">
+ <item name="Back to Mojo" href="http://mojo.codehaus.org"/>
+ </menu>
+ <menu name="Overview">
+ <item name="Introduction" href="introduction.html"/>
+ <item name="Plugin Goals" href="index.html"/>
+ <item name="How to Use" href="howto.html"/>
+ <item name="Javadoc" href="apidocs/index.html"/>
+ </menu>
+ ${reports}
+ </body>
+</project>
\ No newline at end of file


 ________________________________


 To unsubscribe from this list please visit:

 http://xircles.codehaus.org/manage_email


--
I could give you my word as a Spaniard.
No good. I've known too many Spaniards.
                            -- The Princess Bride

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to