[jboss-svn-commits] JBL Code SVN: r12929 - in labs/jbossbuild/maven-plugins/trunk: maven-test-ext-plugin and 13 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jun 28 12:03:15 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-06-28 12:03:15 -0400 (Thu, 28 Jun 2007)
New Revision: 12929

Added:
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/pom.xml
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/Environment.java
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/EnvironmentBuilder.java
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/resources/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/resources/example.xml
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/resources/extend.dtd
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/examples/
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/examples/basic.apt
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/index.apt
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/usage.apt
   labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/site.xml
Modified:
   labs/jbossbuild/maven-plugins/trunk/
Log:
added maven-test-ext-plugin project; added svn:ignore


Property changes on: labs/jbossbuild/maven-plugins/trunk
___________________________________________________________________
Name: svn:ignore
   + target
*.ipr
*.iws
*.iml
.classpath
.project
.nbattrs
*.log
.clover


Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/pom.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/pom.xml	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/pom.xml	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+
+<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.jboss.maven.plugins</groupId>
+    <artifactId>maven-test-ext-plugin</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>maven-plugin</packaging>
+
+    <name>Test Environment Extension Plugin</name>
+    <description>Plugin for extending test environment via configuration</description>
+
+    <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-project</artifactId>
+            <version>2.0.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-artifact</artifactId>
+            <version>2.0.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-archiver</artifactId>
+            <version>2.0.4</version>
+        </dependency>
+        <dependency>
+            <groupId>plexus</groupId>
+            <artifactId>plexus-utils</artifactId>
+            <version>1.0.1</version>
+        </dependency>
+        <dependency>
+            <groupId>avalon-framework</groupId>
+            <artifactId>avalon-framework</artifactId>
+            <version>4.1.5</version>
+        </dependency>
+        <dependency>
+            <groupId>dom4j</groupId>
+            <artifactId>dom4j</artifactId>
+            <version>1.6.1</version>
+        </dependency>
+    </dependencies>
+
+</project>

Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/Environment.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/Environment.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/Environment.java	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.plugins.test.ext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Structured representation of an <environment/> definition.
+ *
+ * @author Steve Ebersole
+ */
+public class Environment {
+	private final String name;
+	private List dependencies = new ArrayList();
+	private List resources = new ArrayList();
+
+	public Environment(String name) {
+		this.name = name;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public List getDependencies() {
+		return dependencies;
+	}
+
+	public List getResources() {
+		return resources;
+	}
+}

Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/EnvironmentBuilder.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/EnvironmentBuilder.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/EnvironmentBuilder.java	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.plugins.test.ext;
+
+import java.util.Iterator;
+import java.util.ArrayList;
+
+import org.dom4j.Element;
+import org.dom4j.Attribute;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Exclusion;
+import org.apache.maven.model.Resource;
+
+/**
+ * Builds {@link Environment} instances by parsing its XML definition.
+ *
+ * @author Steve Ebersole
+ */
+public class EnvironmentBuilder {
+
+	public static final String ENVIRONMENT = "environment";
+
+	/**
+	 * Constructs a new EnvironmentBuilder instance.
+	 */
+	public EnvironmentBuilder() {
+	}
+
+	public String extractEnvironmentName(Element environmentElement) {
+		return getTrimmedValue( environmentElement.attribute( "name" ) );
+	}
+
+	public Environment buildEnvironment(Element environmentElement) {
+		return extractEnvironmentInfo( environmentElement );
+	}
+
+	private Environment extractEnvironmentInfo(Element environmentElement) {
+		Environment env = new Environment( environmentElement.attributeValue( "name" ) );
+
+		// deps...
+		Element dependenciesElement = environmentElement.element( "dependencies" );
+		if ( dependenciesElement != null ) {
+			Iterator dependencyElements = dependenciesElement.elementIterator( "dependency" );
+			while ( dependencyElements.hasNext() ) {
+				final Element dependencyElement = ( Element ) dependencyElements.next();
+				env.getDependencies().add( extractDependencyInfo( dependencyElement ) );
+			}
+		}
+
+		// resources...
+		Element resourcesElement = environmentElement.element( "testResources" );
+		if ( resourcesElement != null ) {
+			Iterator resourceElements = resourcesElement.elementIterator( "testResource" );
+			while ( resourceElements.hasNext() ) {
+				final Element resourceElement = ( Element ) resourceElements.next();
+				env.getResources().add( extractResourceInfo( resourceElement ) );
+			}
+		}
+
+		return env;
+	}
+
+	private Dependency extractDependencyInfo(Element dependencyElement) {
+		Dependency dependency = new Dependency();
+		dependency.setModelEncoding( dependencyElement.getDocument().getXMLEncoding() );
+		dependency.setGroupId( getTrimmedValue( dependencyElement.attribute( "groupId" ) ) );
+		dependency.setArtifactId( getTrimmedValue( dependencyElement.attribute( "artifactId" ) ) );
+		dependency.setVersion( getTrimmedValue( dependencyElement.attribute( "version" ) ) );
+		dependency.setType( getTrimmedValue( dependencyElement.attribute( "type" ) ) );
+		dependency.setClassifier( getTrimmedValue( dependencyElement.attribute( "classifier" ) ) );
+		// ignore scope in environment, but instead set it here to test for correctness
+		dependency.setScope( "test" );
+		dependency.setSystemPath( getTrimmedValue( dependencyElement.attribute( "systemPath" ) ) );
+		dependency.setOptional( getBooleanValue( dependencyElement.attribute( "optional" ) ) );
+
+		ArrayList exclusions = new ArrayList();
+		Element exclusionsElement = dependencyElement.element( "exclusions" );
+		if ( exclusionsElement != null ) {
+			Iterator itr = exclusionsElement.elementIterator( "exclusion" );
+			while ( itr.hasNext() ) {
+				final Element exclusionElement = ( Element ) itr.next();
+				exclusions.add( extractExclusionInfo( exclusionElement ) );
+			}
+		}
+		dependency.setExclusions( exclusions );
+
+		return dependency;
+	}
+
+	private Object extractExclusionInfo(Element exclusionElement) {
+		Exclusion exclusion = new Exclusion();
+		exclusion.setModelEncoding( exclusionElement.getDocument().getXMLEncoding() );
+		exclusion.setGroupId( getTrimmedValue( exclusionElement.attribute( "groupId" ) ) );
+		exclusion.setArtifactId( getTrimmedValue( exclusionElement.attribute( "artifactId" ) ) );
+		return exclusion;
+	}
+
+	private Resource extractResourceInfo(Element resourceElement) {
+		Resource resource = new Resource();
+		resource.setModelEncoding( resourceElement.getDocument().getXMLEncoding() );
+		resource.setTargetPath( getTrimmedValue( resourceElement.attribute( "targetPath" ) ) );
+		resource.setFiltering( getBooleanValue( resourceElement.attribute( "filtering" ) ) );
+		resource.setDirectory( getTrimmedValue( resourceElement.attribute( "directory" ) ) );
+
+		ArrayList includes = new ArrayList();
+		Element includesElement = resourceElement.element( "includes" );
+		if ( includesElement != null ) {
+			Iterator itr = includesElement.elementIterator( "include" );
+			while ( itr.hasNext() ) {
+				final Element includeElement = ( Element ) itr.next();
+				includes.add( getTrimmedText( includeElement.getText() ) );
+			}
+		}
+		resource.setIncludes( includes );
+
+		ArrayList excludes = new ArrayList();
+		Element excludesElement = resourceElement.element( "excludes" );
+		if ( excludesElement != null ) {
+			Iterator itr = excludesElement.elementIterator( "exclude" );
+			while ( itr.hasNext() ) {
+				final Element excludeElement = ( Element ) itr.next();
+				excludes.add( getTrimmedText( excludeElement.getText() ) );
+			}
+		}
+		resource.setExcludes( excludes );
+
+		return resource;
+	}
+
+	public String getTrimmedValue(Attribute attribute) {
+		if ( attribute == null ) {
+			return null;
+		}
+		String text = attribute.getStringValue();
+		return getTrimmedText( text );
+	}
+
+	public String getTrimmedText(String text) {
+		if ( text == null ) {
+			return null;
+		}
+		return text.trim();
+	}
+
+	public boolean getBooleanValue(Attribute attribute) {
+		String text = getTrimmedValue( attribute );
+		if ( text == null ) {
+			return false;
+		}
+		return Boolean.valueOf( text ).booleanValue();
+	}
+}

Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,321 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.plugins.test.ext;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.DebugResolutionListener;
+import org.apache.maven.artifact.resolver.ResolutionNode;
+import org.apache.maven.artifact.resolver.WarningResolutionListener;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.logging.LogEnabled;
+import org.codehaus.plexus.logging.Logger;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Extends the test environment by expanding the test classpath based on some
+ * external configuration.  Mainly this is useful in integration testing
+ * scenarios where you want to allow end-users (testers) to supply dependencies
+ * (jdbc drivers, e.g.) and/or config (properties).
+ * <p/>
+ * The accepted external configuration format is described by the DTD in this
+ * plugins resources (extend.dtd)
+ *
+ * @goal extend
+ * @phase 
+ *
+ * @author Steve Ebersole
+ */
+public class ExtenderMojo extends AbstractMojo implements LogEnabled {
+	/**
+	 * INTERNAL : The Maven project
+	 *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+	/**
+     * INTERNAL : Local maven repository.
+     *
+     * @parameter expression="${localRepository}"
+     * @required
+     * @readonly
+     */
+    protected ArtifactRepository localRepository;
+
+	/**
+     * INTERNAL : Artifact collector, needed to resolve dependencies.
+     *
+     * @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
+     * @required
+     * @readonly
+     */
+    protected ArtifactCollector artifactCollector;
+
+	/**
+	 * INTERNAL : Artifact factory, needed to download dependencies
+	 *
+	 * @component role="org.apache.maven.artifact.factory.ArtifactFactory"
+	 * @required
+	 * @readonly
+	 */
+	protected ArtifactFactory artifactFactory;
+
+	/**
+	 * INTERNAL : Artifact resolver, needed to download dependencies
+	 *
+	 * @component role="org.apache.maven.artifact.resolver.ArtifactResolver"
+	 * @required
+	 * @readonly
+	 */
+	protected ArtifactResolver artifactResolver;
+
+	/**
+	 * INTERNAL : The artifact metadata source ;)
+	 *
+     * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource" hint="maven"
+     */
+    protected ArtifactMetadataSource artifactMetadataSource;
+
+	/**
+	 * The path to the extender configuration file to use.  Defined as String
+	 * so that it can be specified as a build property
+	 *
+	 * @parameter expression="${test.extender.cfg}"
+	 */
+	protected String extenderConfig;
+
+	/**
+	 * As a matter of convenience, an extender config can name multiple 
+	 * environment entries.  However, for a test run a particular one must
+	 * be selected from the many.  This parameter specifies which environment
+	 * to use.
+	 * <p/>
+	 * The anticipated usage here is to set this as a build property...
+	 *
+	 * @parameter expression="${test.extender.env}"
+	 */
+	protected String extenderEnv;
+
+
+	// LogEnabled impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	private Logger logger;
+
+	public void enableLogging(Logger logger) {
+		this.logger = logger;
+	}
+
+
+	// Mojo#execute impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public void execute() throws MojoExecutionException, MojoFailureException {
+		Environment environment = parseEnvironment();
+		extendTestClasspath( environment );
+	}
+
+
+	// read/parse XML ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	protected Environment parseEnvironment() throws MojoExecutionException {
+		Document extenderConfigDocument = loadExtenderConfigDocument();
+		EnvironmentBuilder environmentBuilder = new EnvironmentBuilder();
+		Iterator itr = extenderConfigDocument.getRootElement().elementIterator( EnvironmentBuilder.ENVIRONMENT );
+		while ( itr.hasNext() ) {
+			final Element environmentElement = ( Element ) itr.next();
+			if ( extenderEnv.equals( environmentBuilder.extractEnvironmentName( environmentElement ) ) ) {
+				// EARLY EXIT!!!!!
+				return environmentBuilder.buildEnvironment( environmentElement );
+			}
+		}
+		getLog().info( "Unable to locate appropriate extender env [" + extenderEnv + "] in specified config [" + extenderConfig + "]" );
+		return null;
+	}
+
+	protected Document loadExtenderConfigDocument()
+			throws MojoExecutionException {
+		File extenderConfigFile = new File( extenderConfig );
+		if ( !extenderConfigFile.exists() ) {
+			getLog().warn( "Could not locate specified extender config file [" + extenderConfig + "]" );
+		}
+
+
+		try {
+			List errors = new ArrayList();
+			SAXReader saxReader = new SAXReader();
+			saxReader.setErrorHandler( new ErrorLogger( extenderConfig, errors, getLog() ) );
+			saxReader.setMergeAdjacentText( true );
+			saxReader.setValidation( true );
+
+			Document doc = saxReader.read( extenderConfigFile );
+			if ( errors.size() != 0 ) {
+				throw new MojoExecutionException( "errors reading extender-config file [" + extenderConfig + "]", ( Throwable ) errors.get( 0 ) );
+			}
+			return doc;
+		}
+		catch ( DocumentException e) {
+			throw new MojoExecutionException( "errors reading extender-config file [" + extenderConfig + "]", e );
+		}
+	}
+
+
+	public static class ErrorLogger implements ErrorHandler {
+		private final String file;
+		private final List errors;
+		private final Log log;
+
+		public ErrorLogger(String file, List errors, Log log) {
+			this.file = file;
+			this.errors = errors;
+			this.log = log;
+		}
+
+		public void error(SAXParseException error) {
+			log.error( "Error parsing XML: " + file + '(' + error.getLineNumber() + ") " + error.getMessage() );
+			errors.add(error);
+		}
+
+		public void fatalError(SAXParseException error) {
+			error(error);
+		}
+
+		public void warning(SAXParseException warn) {
+			log.warn( "Warning parsing XML: " + file + '(' + warn.getLineNumber() + ") " + warn.getMessage() );
+		}
+	}
+
+
+	// extend classpath ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	protected void extendTestClasspath(Environment environment)
+			throws MojoExecutionException {
+		attachDependencies( environment.getDependencies() );
+		attachResources( environment.getResources() );
+	}
+
+	protected void attachDependencies(List dependencies)
+			throws MojoExecutionException {
+		Set artifacts = new HashSet();
+		Iterator itr = dependencies.iterator();
+		while ( itr.hasNext() ) {
+			final Dependency dependency = ( Dependency ) itr.next();
+			try {
+				VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() );
+				Artifact artifact = artifactFactory.createDependencyArtifact(
+						dependency.getGroupId(),
+						dependency.getArtifactId(),
+						versionRange,
+						dependency.getType(),
+						dependency.getClassifier(),
+						Artifact.SCOPE_TEST,
+						false
+				);
+				artifacts.add( artifact );
+			}
+			catch( InvalidVersionSpecificationException e ) {
+				throw new MojoExecutionException( "Unable to parse version" );
+			}
+		}
+
+
+		try {
+			List listeners = new ArrayList();
+			listeners.add( new WarningResolutionListener( logger ) );
+			if ( logger.isDebugEnabled() ) {
+				listeners.add( new DebugResolutionListener( logger ) );
+			}
+
+			ArtifactResolutionResult artifactResolutionResult = artifactCollector.collect(
+					artifacts,
+					project.getArtifact(),
+					localRepository, 
+					project.getRemoteArtifactRepositories(),
+					artifactMetadataSource,
+					null,
+					listeners
+			);
+
+			itr = artifactResolutionResult.getArtifactResolutionNodes().iterator();
+			while ( itr.hasNext() ) {
+				final ResolutionNode node = ( ResolutionNode ) itr.next();
+				final Artifact artifact = node.getArtifact();
+				if ( ! artifact.isResolved() ) {
+					artifactResolver.resolve( artifact, node.getRemoteRepositories(), localRepository );
+				}
+			}
+
+		}
+		catch( ArtifactNotFoundException e ) {
+			throw new MojoExecutionException( "Unable to download artifact " + buildInfo( e ) + " : " + e.getMessage(), e );
+		}
+		catch ( ArtifactResolutionException e ) {
+			throw new MojoExecutionException( "Unable to resolve artifact " + buildInfo( e ) + " : " + e.getMessage(), e );
+		}
+
+		ArrayList allDependencies = new ArrayList();
+		allDependencies.addAll( project.getDependencies() );
+		allDependencies.addAll( dependencies );
+		project.setDependencies( allDependencies );
+
+		HashSet allArtifacts = new HashSet();
+		allArtifacts.addAll( project.getArtifacts() );
+		allArtifacts.addAll( artifacts );
+		project.setArtifacts( allArtifacts );
+	}
+
+	protected void attachResources(List resources) {
+		Iterator itr = resources.iterator();
+		while ( itr.hasNext() ) {
+			final Resource resource = ( Resource ) itr.next();
+			project.addTestResource( resource );
+		}
+	}
+
+	private String buildInfo(AbstractArtifactResolutionException e) {
+		return "[" + e.getGroupId() + ":" + e.getArtifactId() + ":" + e.getVersion() + "]";
+	}
+
+}

Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/resources/example.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/resources/example.xml	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/resources/example.xml	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,38 @@
+<!DOCTYPE environments SYSTEM "extend.dtd">
+
+<!--
+  ~ Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+  ~
+  ~ This copyrighted material is made available to anyone wishing to use, modify,
+  ~ copy, or redistribute it subject to the terms and conditions of the GNU
+  ~ Lesser General Public License, v. 2.1. This program is distributed in the
+  ~ hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+  ~ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  ~ Lesser General Public License for more details. You should have received a
+  ~ copy of the GNU Lesser General Public License, v.2.1 along with this
+  ~ distribution; if not, write to the Free Software Foundation, Inc.,
+  ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  ~
+  ~ Red Hat Author(s): Steve Ebersole
+  -->
+<environments>
+    <environment name="hsqldb">
+        <testResources>
+            <testResource>
+                <directory>environment/acme</directory>
+                <filtering>false</filtering>
+                <includes>
+                    <include>*.xml</include>
+                    <include>*.properties</include>
+                </includes>
+            </testResource>
+        </testResources>
+        <dependencies>
+            <dependency>
+                <groupId>com.acme</groupId>
+                <artifactId>acme-db</artifactId>
+                <version>1.0</version>
+            </dependency>
+        </dependencies>
+    </environment>
+</environments>
\ No newline at end of file

Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/resources/extend.dtd
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/resources/extend.dtd	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/resources/extend.dtd	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,36 @@
+<!DOCTYPE environments>
+
+<!--
+  ~ Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+  ~
+  ~ This copyrighted material is made available to anyone wishing to use, modify,
+  ~ copy, or redistribute it subject to the terms and conditions of the GNU
+  ~ Lesser General Public License, v. 2.1. This program is distributed in the
+  ~ hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+  ~ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  ~ Lesser General Public License for more details. You should have received a
+  ~ copy of the GNU Lesser General Public License, v.2.1 along with this
+  ~ distribution; if not, write to the Free Software Foundation, Inc.,
+  ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  ~
+  ~ Red Hat Author(s): Steve Ebersole
+  -->
+
+<!ELEMENT environments (environment)*>
+
+<!ELEMENT environment (testResources|dependencies)>
+<!ATTLIST environment name CDATA #REQUIRED>
+
+<!ELEMENT testResources (testResource)*>
+<!ELEMENT testResource (directory|targetDirectory|filtering|includes|excludes)>
+<!ELEMENT directory (#PCDATA)>
+<!ELEMENT targetDirectory (#PCDATA)>
+<!ELEMENT filtering (#PCDATA)>
+<!ELEMENT includes (#PCDATA)>
+<!ELEMENT excludes (#PCDATA)>
+
+<!ELEMENT dependencies (dependency)*>
+<!ELEMENT dependency (groupId|artifactId|version)>
+<!ELEMENT groupId (#PCDATA)>
+<!ELEMENT artifactId (#PCDATA)>
+<!ELEMENT version (#PCDATA)>

Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/examples/basic.apt
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/examples/basic.apt	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/examples/basic.apt	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,69 @@
+ ------
+ Basic Setup
+ ------
+ Steve Ebersole
+ ------
+ 28 June 2007
+ ------
+
+~~ Copyright (c) 2007  Red Hat Middleware, LLC. All rights reserved.
+~~
+~~ This copyrighted material is made available to anyone wishing to use, modify,
+~~ copy, or redistribute it subject to the terms and conditions of the GNU
+~~ Lesser General Public License, v. 2.1. This program is distributed in the
+~~ hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+~~ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+~~ Lesser General Public License for more details. You should have received a
+~~ copy of the GNU Lesser General Public License, v.2.1 along with this
+~~ distribution; if not, write to the Free Software Foundation, Inc.,
+~~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+~~
+~~ Red Hat Author(s): Steve Ebersole
+
+Basic Setup
+
+    In order to have the <Test Environment Extension Plugin> extend the test
+    environment, users must define one or more environments and then tell the
+    <Test Environment Extension Plugin> where to find those environments as
+    well as which environment to use for a particular test suite run.
+
+* Define environment(s)
+
+    Environments are defined in XML format.  Here is an example to define
+    some dependencies and resources specific to a database from venerable
+    acme.com:
++-----+
+<environments>
+    <environment name="hsqldb">
+        <testResources>
+            <testResource>
+                <directory>environment/acme</directory>
+                <filtering>false</filtering>
+                <includes>
+                    <include>*.xml</include>
+                    <include>*.properties</include>
+                </includes>
+            </testResource>
+        </testResources>
+        <dependencies>
+            <dependency>
+                <groupId>com.acme</groupId>
+                <artifactId>acme-db</artifactId>
+                <version>1.0</version>
+            </dependency>
+        </dependencies>
+    </environment>
+</environments>
++-----+
+
+    Within the \<environment/\> tag, we see \<testResources/\> and \<depedencies/\>
+    both of which follow the allowable syntax of their general Maven counterparts.
+    It is important to note, however, that any resources and dependencies defined
+    via this mechanism are implicitly added to the <<test>> classpath.
+
+* Use specific environment during test
+
+    The anticipated usage of this plugin would specify using properties to
+    control the declaration of the environment to use.  For example, to use
+    the environment we defined above, we would do
+    <<<mvn test -Dtest.extender.cfg=path-to-env-file.xml -Dtest.extender.env=acme>>>
\ No newline at end of file

Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/index.apt
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/index.apt	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/index.apt	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,61 @@
+ ------
+ Introduction
+ ------
+ Steve Ebersole
+ ------
+ 28 June 2007
+ ------
+
+~~ Copyright © 2007  Red Hat Middleware, LLC. All rights reserved.
+~~
+~~ This copyrighted material is made available to anyone wishing to use, modify,
+~~ copy, or redistribute it subject to the terms and conditions of the GNU
+~~ Lesser General Public License, v. 2.1. This program is distributed in the
+~~ hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+~~ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+~~ Lesser General Public License for more details. You should have received a
+~~ copy of the GNU Lesser General Public License, v.2.1 along with this
+~~ distribution; if not, write to the Free Software Foundation, Inc.,
+~~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+~~
+~~ Red Hat Author(s): Steve Ebersole
+
+Test Environment Extension Plugin
+
+    Maven has great support for running tests through Surefire.  However, one
+    feature it does lack is the ability for users to extend the test classpath
+    beyond what the project POM defines.
+
+    Consider a test suite which must be run against a number of databases.
+    Database-related tests typically require access to driver jars and various
+    resource files on the classpath to function properly.  Maven handles this
+    fine when all the ingredients are known ahead of time.  But say someone
+    other than the project team wants to run that test suite against a database
+    other than the ones defined by dependencies/resources in the POM...  How
+    can they do it?  The answer is that they currently (pre Maven 2.1) cannot
+    without modifying the project POM.
+
+    A logical answer would seem to be using profiles.xml to add these extra
+    classpath elements.  But the problem is that profiles.xml does not allow
+    definition of dependencies (actually, 2.1 will allow users to define
+    <<test>> dependencies in profiles.xml.  With the release of 2.1, this plugin
+    becomes obsolete.
+
+    Until that time, we define a parallel extension approach, via some "extra"
+    XML allowing project teams to allow their test environments to be
+    extended/expanded.
+
+* Goals Overview
+    This plugin defines only a single goal:
+    {{{extend.html}maven-test-ext-plugin:extend}} reads the extra XML and
+    extends the projects test classpath accordingly.
+
+* Usage
+
+    Instructions on how to use the <Test Environment Extension Plugin> can be found {{{usage.html}here}}.
+
+* Examples
+
+    The main thing with the <Test Environment Extension Plugin> is setting up
+    and then using the environments.  Here is an {{{examples/basic.html}example}}
+    of doing that.

Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/usage.apt
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/usage.apt	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/apt/usage.apt	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,57 @@
+ ------
+ Usage
+ ------
+ Steve Ebersole
+ ------
+ 28 June 2007
+ ------
+
+~~ Copyright (c) 2007  Red Hat Middleware, LLC. All rights reserved.
+~~
+~~ This copyrighted material is made available to anyone wishing to use, modify,
+~~ copy, or redistribute it subject to the terms and conditions of the GNU
+~~ Lesser General Public License, v. 2.1. This program is distributed in the
+~~ hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+~~ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+~~ Lesser General Public License for more details. You should have received a
+~~ copy of the GNU Lesser General Public License, v.2.1 along with this
+~~ distribution; if not, write to the Free Software Foundation, Inc.,
+~~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+~~
+~~ Red Hat Author(s): Steve Ebersole
+
+Usage
+
+    The <Test Environment Extension Plugin> aims to allow project teams the
+    ability to let their project's users extend the project's test environment
+    in an extensible manner.  For a full discussion of this intention, see
+    the {{{index.html}Introduction}}.
+
+* Minimal configuration
+
+    The plugin defines only a single goal (extend) which has pretty minimal
+    configuration options.  The basic configuration from a project team's
+    perspective is to simply name the plugin in the project's build plugins:
++-----+
+<project>
+  ...
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.jboss.maven.plugins</groupId>
+        <artifactId>maven-test-ext-plugin</artifactId>
+      </plugin>
+    </plugins>
+    ...
+  </build>
+  ...
+</project>
++-----+
+
+* Environment Configuration
+
+    The <Test Environment Extension Plugin> does define two configuration
+    options, which are anticipated to be set through properties rather than
+    directly in the plugin configuration.  See the {{{extend.html}goal}}
+    documentation for discussion of the <extenderConfig> and <extenderEnv>
+    parameters.
\ No newline at end of file

Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/site.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/site.xml	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/site/site.xml	2007-06-28 16:03:15 UTC (rev 12929)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+  ~
+  ~ This copyrighted material is made available to anyone wishing to use, modify,
+  ~ copy, or redistribute it subject to the terms and conditions of the GNU
+  ~ Lesser General Public License, v. 2.1. This program is distributed in the
+  ~ hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+  ~ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  ~ Lesser General Public License for more details. You should have received a
+  ~ copy of the GNU Lesser General Public License, v.2.1 along with this
+  ~ distribution; if not, write to the Free Software Foundation, Inc.,
+  ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  ~
+  ~ Red Hat Author(s): Steve Ebersole
+  -->
+<project name="Maven">
+
+    <body>
+        <menu name="Overview">
+            <item name="Introduction" href="index.html"/>
+            <item name="Goals" href="plugin-info.html"/>
+            <item name="Usage" href="usage.html"/>
+            <item name="FAQ" href="faq.html"/>
+        </menu>
+
+        <menu name="Examples">
+            <item name="Basic Setup" href="examples/basic.html"/>
+        </menu>
+
+        ${reports}
+    </body>
+
+</project>




More information about the jboss-svn-commits mailing list