You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/11/09 19:42:28 UTC
svn commit: r712530 - in
/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration:
./ src/main/java/org/apache/maven/plugin/coreit/
Author: bentmann
Date: Sun Nov 9 10:42:27 2008
New Revision: 712530
URL: http://svn.apache.org/viewvc?rev=712530&view=rev
Log:
o Extended plugin to allow more thorough/easier testing of effective plugin configuration
Added:
maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java (with props)
maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java (with props)
Removed:
maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/PluginConfigurationEmitter.java
Modified:
maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/pom.xml
Modified: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/pom.xml?rev=712530&r1=712529&r2=712530&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/pom.xml (original)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/pom.xml Sun Nov 9 10:42:27 2008
@@ -45,16 +45,6 @@
<version>2.0</version>
</dependency>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- <version>2.0</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- <version>1.4</version>
- </dependency>
- <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<version>1.0-alpha-9</version>
Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java?rev=712530&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java (added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java Sun Nov 9 10:42:27 2008
@@ -0,0 +1,43 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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 License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * A bean to receive mojo configuration.
+ *
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class Bean
+{
+
+ String fieldParam;
+
+ String setterParam;
+
+ boolean setterCalled;
+
+ public void setSetterParam( String value )
+ {
+ setterParam = value;
+ setterCalled = true;
+ }
+
+}
Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/Bean.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java?rev=712530&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java (added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java Sun Nov 9 10:42:27 2008
@@ -0,0 +1,377 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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 License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Array;
+import java.net.URI;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+
+/**
+ * Dumps this mojo's configuration into a properties file.
+ *
+ * @goal config
+ * @phase validate
+ *
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class ConfigMojo
+ extends AbstractMojo
+{
+
+ /**
+ * The current project's base directory, used for path alignment.
+ *
+ * @parameter default-value="${basedir}"
+ * @readonly
+ */
+ private File basedir;
+
+ /**
+ * The path to the properties file into which to save the mojo configuration. Unlike all the other parameters, this
+ * parameter features both a default value and an alias.
+ *
+ * @parameter alias="outputFile"
+ * expression="${config.propertiesFile} default-value="${project.build.directory}/config.properties"
+ */
+ private File propertiesFile;
+
+ /**
+ * A simple parameter of type {@link java.lang.Boolean}.
+ *
+ * @parameter expression="${config.booleanParam}"
+ */
+ private Boolean booleanParam;
+
+ /**
+ * A simple parameter of type {@link java.lang.Byte}.
+ *
+ * @parameter expression="${config.byteParam}"
+ */
+ private Byte byteParam;
+
+ /**
+ * A simple parameter of type {@link java.lang.Short}.
+ *
+ * @parameter expression="${config.shortParam}"
+ */
+ private Short shortParam;
+
+ /**
+ * A simple parameter of type {@link java.lang.Integer}.
+ *
+ * @parameter expression="${config.intergerParam}"
+ */
+ private Integer integerParam;
+
+ /**
+ * A simple parameter of type {@link java.lang.Long}.
+ *
+ * @parameter expression="${config.longParam}"
+ */
+ private Long longParam;
+
+ /**
+ * A simple parameter of type {@link java.lang.Float}.
+ *
+ * @parameter expression="${config.floatParam}"
+ */
+ private Float floatParam;
+
+ /**
+ * A simple parameter of type {@link java.lang.Double}.
+ *
+ * @parameter expression="${config.doubleParam}"
+ */
+ private Double doubleParam;
+
+ /**
+ * A simple parameter of type {@link java.lang.Character}.
+ *
+ * @parameter expression="${config.characterParam}"
+ */
+ private Character characterParam;
+
+ /**
+ * A simple parameter of type {@link java.lang.String}.
+ *
+ * @parameter expression="${config.stringParam}"
+ */
+ private String stringParam;
+
+ /**
+ * A simple parameter of type {@link java.io.File}.
+ *
+ * @parameter expression="${config.fileParam}"
+ */
+ private File fileParam;
+
+ /**
+ * A simple parameter of type {@link java.util.Date}.
+ *
+ * @parameter expression="${config.dateParam}"
+ */
+ private Date dateParam;
+
+ /**
+ * A simple parameter of type {@link java.net.URL}.
+ *
+ * @parameter expression="${config.urlParam}"
+ */
+ private URL urlParam;
+
+ /**
+ * A simple parameter of type {@link java.net.URI} (requires Maven 3.x).
+ *
+ * @parameter
+ */
+ private URI uriParam;
+
+ /**
+ * An array parameter of component type {@link java.lang.String}.
+ *
+ * @parameter
+ */
+ private String[] stringParams;
+
+ /**
+ * A collection parameter of type {@link java.util.List}.
+ *
+ * @parameter
+ */
+ private List listParam;
+
+ /**
+ * A collection parameter of type {@link java.util.Set}.
+ *
+ * @parameter
+ */
+ private Set setParam;
+
+ /**
+ * A collection parameter of type {@link java.util.Map}.
+ *
+ * @parameter
+ */
+ private Map mapParam;
+
+ /**
+ * A collection parameter of type {@link java.util.Properties}.
+ *
+ * @parameter
+ */
+ private Properties propertiesParam;
+
+ /**
+ * A complex parameter of type {@link org.apache.maven.plugin.coreit.Bean}.
+ *
+ * @parameter
+ */
+ private Bean beanParam;
+
+ /**
+ * A raw DOM snippet.
+ *
+ * @parameter
+ */
+ private PlexusConfiguration domParam;
+
+ /**
+ * Runs this mojo.
+ *
+ * @throws MojoExecutionException If the output file could not be created.
+ */
+ public void execute()
+ throws MojoExecutionException
+ {
+ getLog().info( "[MAVEN-CORE-IT-LOG] Using output file path: " + propertiesFile );
+
+ if ( propertiesFile == null )
+ {
+ throw new MojoExecutionException( "Path name for output file has not been specified" );
+ }
+
+ if ( !propertiesFile.isAbsolute() )
+ {
+ propertiesFile = new File( basedir, propertiesFile.getPath() ).getAbsoluteFile();
+ }
+
+ Properties configProps = new Properties();
+ dumpConfiguration( configProps );
+
+ getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + propertiesFile );
+
+ OutputStream out = null;
+ try
+ {
+ propertiesFile.getParentFile().mkdirs();
+ out = new FileOutputStream( propertiesFile );
+ configProps.store( out, "MAVEN-CORE-IT-LOG" );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Output file could not be created: " + propertiesFile, e );
+ }
+ finally
+ {
+ if ( out != null )
+ {
+ try
+ {
+ out.close();
+ }
+ catch ( IOException e )
+ {
+ // just ignore
+ }
+ }
+ }
+
+ getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + propertiesFile );
+ }
+
+ /**
+ * Dumps the mojo configuration into the specified properties.
+ *
+ * @param props The properties to dump the configuration into, must not be <code>null</code>.
+ */
+ private void dumpConfiguration( Properties props )
+ {
+ dumpValue( props, "propertiesFile", propertiesFile );
+ dumpValue( props, "booleanParam", booleanParam );
+ dumpValue( props, "byteParam", byteParam );
+ dumpValue( props, "shortParam", shortParam );
+ dumpValue( props, "integerParam", integerParam );
+ dumpValue( props, "longParam", longParam );
+ dumpValue( props, "floatParam", floatParam );
+ dumpValue( props, "doubleParam", doubleParam );
+ dumpValue( props, "characterParam", characterParam );
+ dumpValue( props, "stringParam", stringParam );
+ dumpValue( props, "fileParam", fileParam );
+ dumpValue( props, "dateParam", dateParam );
+ dumpValue( props, "urlParam", urlParam );
+ dumpValue( props, "uriParam", uriParam );
+ dumpValue( props, "stringParams", stringParams );
+ dumpValue( props, "listParam", listParam );
+ dumpValue( props, "setParam", setParam );
+ dumpValue( props, "mapParam", mapParam );
+ dumpValue( props, "propertiesParam", propertiesParam );
+ dumpValue( props, "domParam", domParam );
+ if ( beanParam != null )
+ {
+ dumpValue( props, "beanParam.fieldParam", beanParam.fieldParam );
+ dumpValue( props, "beanParam.setterParam", beanParam.setterParam );
+ dumpValue( props, "beanParam.setterCalled", Boolean.valueOf( beanParam.setterCalled ) );
+ }
+ }
+
+ private void dumpValue( Properties props, String key, Object value )
+ {
+ if ( value != null && value.getClass().isArray() )
+ {
+ props.setProperty( key, Integer.toString( Array.getLength( value ) ) );
+ for ( int i = Array.getLength( value ) - 1; i >= 0; i-- )
+ {
+ dumpValue( props, key + "." + i, Array.get( value, i ) );
+ }
+ }
+ else if ( value instanceof Collection )
+ {
+ Collection collection = (Collection) value;
+ props.setProperty( key, Integer.toString( collection.size() ) );
+ int i = 0;
+ for ( Iterator it = collection.iterator(); it.hasNext(); i++ )
+ {
+ dumpValue( props, key + "." + i, it.next() );
+ }
+ }
+ else if ( value instanceof Map )
+ {
+ Map map = (Map) value;
+ props.setProperty( key, Integer.toString( map.size() ) );
+ int i = 0;
+ for ( Iterator it = map.keySet().iterator(); it.hasNext(); i++ )
+ {
+ Object k = it.next();
+ Object v = map.get( k );
+ dumpValue( props, key + "." + k, v );
+ }
+ }
+ else if ( value instanceof PlexusConfiguration )
+ {
+ PlexusConfiguration config = (PlexusConfiguration) value;
+
+ String val = config.getValue( null );
+ if ( val != null )
+ {
+ props.setProperty( key + ".value", val );
+ }
+
+ String[] attributes = config.getAttributeNames();
+ props.setProperty( key + ".attributes", Integer.toString( attributes.length ) );
+ for ( int i = attributes.length - 1; i >= 0; i-- )
+ {
+ props.setProperty( key + ".attributes." + attributes[i], config.getAttribute( attributes[i], "" ) );
+ }
+
+ PlexusConfiguration children[] = config.getChildren();
+ props.setProperty( key + ".children", Integer.toString( children.length ) );
+ Map indices = new HashMap();
+ for ( int i = children.length - 1; i >= 0; i-- )
+ {
+ PlexusConfiguration child = children[i];
+ String name = child.getName();
+ Integer index = (Integer) indices.get( name );
+ if ( index == null )
+ {
+ index = new Integer( 0 );
+ }
+ dumpValue( props, key + ".children." + name + "." + index, child );
+ indices.put( name, new Integer( index.intValue() + 1 ) );
+ }
+ }
+ else if ( value instanceof Date )
+ {
+ props.setProperty( key, new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format( (Date) value ) );
+ }
+ else if ( value != null )
+ {
+ props.setProperty( key, value.toString() );
+ }
+ }
+
+}
Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-configuration/src/main/java/org/apache/maven/plugin/coreit/ConfigMojo.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision