[jboss-svn-commits] JBL Code SVN: r13509 - in labs/jbossbuild/maven-plugins/tags: maven-test-ext-plugin-1.0.1 and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jul 14 14:49:29 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-07-14 14:49:29 -0400 (Sat, 14 Jul 2007)
New Revision: 13509

Added:
   labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/
   labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/pom.xml
   labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/src/
   labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java
Removed:
   labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/pom.xml
   labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/src/
   labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java
Log:
[maven-release-plugin]  copy for tag maven-test-ext-plugin-1.0.1

Copied: labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1 (from rev 13249, labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin)

Deleted: labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/pom.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/pom.xml	2007-07-09 01:15:26 UTC (rev 13249)
+++ labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/pom.xml	2007-07-14 18:49:29 UTC (rev 13509)
@@ -1,109 +0,0 @@
-<?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 classpath</description>
-    <url>http://jboss.org</url>
-
-    <developers>
-        <developer>
-            <name>Steve Ebersole</name>
-            <email>steve at hibernate.org</email>
-            <organization>JBoss, a division of Red Hat</organization>
-            <organizationUrl>http://jboss.com</organizationUrl>
-            <timezone>-5</timezone>
-        </developer>
-    </developers>
-
-    <licenses>
-        <license>
-            <name>GNU Lesser General Public License</name>
-            <url>http://www.gnu.org/copyleft/lesser.html</url>
-            <distribution>repo</distribution>
-        </license>
-    </licenses>
-
-    <scm>
-        <connection>scm:svn:https://svn.labs.jboss.org/labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin</connection>
-        <developerConnection>scm:svn:https://svn.labs.jboss.org/labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin</developerConnection>
-        <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/labs/labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/</url>
-    </scm>
-
-    <issueManagement>
-       <system>jira</system>
-       <url>http://jira.jboss.com/jira/browse/JBBUILD</url>
-    </issueManagement>
-
-    <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>
-
-    <reporting>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-javadoc-plugin</artifactId>
-                <configuration>
-                    <minmemory>128m</minmemory>
-                    <maxmemory>512</maxmemory>
-                    <links>
-                        <link>http://java.sun.com/j2se/1.4.2/docs/api/index.html</link>
-                    </links>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-jxr-plugin</artifactId>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-plugin-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </reporting>
-
-</project>

Copied: labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/pom.xml (from rev 13508, labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/pom.xml)
===================================================================
--- labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/pom.xml	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/pom.xml	2007-07-14 18:49:29 UTC (rev 13509)
@@ -0,0 +1,137 @@
+<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>
+
+    <parent>
+        <groupId>org.jboss</groupId>
+        <artifactId>jboss-parent</artifactId>
+        <version>3</version>
+    </parent>
+
+    <groupId>org.jboss.maven.plugins</groupId>
+    <artifactId>maven-test-ext-plugin</artifactId>
+    <version>1.0.1</version>
+    <packaging>maven-plugin</packaging>
+
+    <name>Test Environment Extension Plugin</name>
+    <description>Plugin for extending test environment classpath</description>
+    <url>http://jboss.org</url>
+
+    <developers>
+        <developer>
+            <name>Steve Ebersole</name>
+            <email>steve at hibernate.org</email>
+            <organization>JBoss, a division of Red Hat</organization>
+            <organizationUrl>http://jboss.com</organizationUrl>
+            <timezone>-5</timezone>
+        </developer>
+    </developers>
+
+    <licenses>
+        <license>
+            <name>GNU Lesser General Public License</name>
+            <url>http://www.gnu.org/copyleft/lesser.html</url>
+            <distribution>repo</distribution>
+        </license>
+    </licenses>
+
+    <scm>
+        <connection>scm:svn:https://svn.jboss.org/repos/labs/labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1</connection>
+        <developerConnection>scm:svn:https://svn.jboss.org/repos/labs/labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1</developerConnection>
+        <url>scm:svn:https://svn.jboss.org/repos/labs/labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1</url>
+    </scm>
+
+    <issueManagement>
+       <system>jira</system>
+       <url>http://jira.jboss.com/jira/browse/JBBUILD</url>
+    </issueManagement>
+
+    <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-model</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-artifact-manager</artifactId>
+            <version>2.0.4</version>
+        </dependency>
+        <!-- this one is needed for our use of maven-artifact-manager :( -->
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-container-default</artifactId>
+            <version>1.0-alpha-9</version>
+        </dependency>
+        <dependency>
+            <groupId>xml-apis</groupId>
+            <artifactId>xml-apis</artifactId>
+            <version>1.0.b2</version>
+        </dependency>
+        <dependency>
+            <groupId>dom4j</groupId>
+            <artifactId>dom4j</artifactId>
+            <version>1.6.1</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.4</source>
+                    <target>1.4</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-release-plugin</artifactId>
+                <configuration>
+                    <tagBase>https://svn.jboss.org/repos/labs/labs/jbossbuild/maven-plugins/tags</tagBase>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <configuration>
+                    <minmemory>128m</minmemory>
+                    <maxmemory>512</maxmemory>
+                    <links>
+                        <link>http://java.sun.com/j2se/1.4.2/docs/api/index.html</link>
+                    </links>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jxr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-plugin-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </reporting>
+
+</project>
\ No newline at end of file

Copied: labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/src (from rev 13248, labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src)

Deleted: labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/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	2007-07-09 01:12:55 UTC (rev 13248)
+++ labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java	2007-07-14 18:49:29 UTC (rev 13509)
@@ -1,276 +0,0 @@
-/*
- * 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.project.MavenProject;
-import org.codehaus.plexus.logging.LogEnabled;
-import org.codehaus.plexus.logging.Logger;
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.jboss.maven.shared.xml.dom4j.DocumentLoader;
-
-/**
- * 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 generate-resources
- *
- * @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 {
-		getLog().info( "starting test environment extension mojo" );
-		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!!!!!
-				getLog().info( "found environment definition [" + extenderEnv + "]" );
-				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 + "]" );
-		}
-
-		return new DocumentLoader( getLog() ).loadDocument( extenderConfigFile );
-	}
-
-	// extend classpath ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-	protected void extendTestClasspath(Environment environment)
-			throws MojoExecutionException {
-		attachDependencies( environment.getDependencies() );
-		attachResources( environment.getResources() );
-	}
-
-	protected void attachDependencies(List dependencies) throws MojoExecutionException {
-		getLog().info( "extending via dependencies" );
-		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() + "]";
-	}
-
-}

Copied: labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java (from rev 13506, labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java)
===================================================================
--- labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/tags/maven-test-ext-plugin-1.0.1/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java	2007-07-14 18:49:29 UTC (rev 13509)
@@ -0,0 +1,274 @@
+/*
+ * 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.project.MavenProject;
+import org.codehaus.plexus.logging.LogEnabled;
+import org.codehaus.plexus.logging.Logger;
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.jboss.maven.shared.xml.dom4j.DocumentLoader;
+
+/**
+ * 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 test-compile
+ * @requiresDependencyResolution
+ *
+ * @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 {
+		getLog().info( "starting test environment extension mojo" );
+		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!!!!!
+				getLog().info( "found environment definition [" + extenderEnv + "]" );
+				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 + "]" );
+		}
+
+		return new DocumentLoader( getLog() ).loadDocument( extenderConfigFile );
+	}
+
+
+	// extend classpath ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	protected void extendTestClasspath(Environment environment) throws MojoExecutionException {
+		attachDependencies( environment.getDependencies() );
+		attachResources( environment.getResources() );
+	}
+
+	protected void attachDependencies(List dependencies) throws MojoExecutionException {
+		Set combinedDependencyArtifacts = new HashSet();
+		combinedDependencyArtifacts.addAll( project.getDependencyArtifacts() );
+
+		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 );
+				}
+				getLog().info( "adding dependency artifact [" + extenderEnv + "] : " + artifact.getId() );
+			}
+
+		}
+		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 );
+		}
+
+		combinedDependencyArtifacts.addAll( artifacts );
+		project.setDependencyArtifacts( combinedDependencyArtifacts );
+		project.setArtifacts( null );
+	}
+
+	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() + "]";
+	}
+
+}




More information about the jboss-svn-commits mailing list