o maven-plugin-testing-harness back out of the tools. See:

http://www.nabble.com/-Vote--Release-Maven-Plugin-Tools-projects-td15876907s177.html

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@634978 13f79535-47bb-0310-9956-ffa450edef68
master
Vincent Siveton 2008-03-08 14:36:39 +00:00
parent 569b96374d
commit 1b81facb3a
27 changed files with 0 additions and 5828 deletions

View File

@ -1,103 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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.apache.maven</groupId>
<artifactId>maven-plugin-tools</artifactId>
<version>2.2-SNAPSHOT</version>
</parent>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>1.2-SNAPSHOT</version>
<name>Maven Plugin Testing Mechanism</name>
<description>The Maven Plugin Testing Harness provides mechanisms to manage tests on Mojo.</description>
<dependencies>
<!-- maven -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<!-- plexus -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>1.0-alpha-7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/maven/plugin-tools/trunk/maven-plugin-testing-harness/</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/plugin-tools/trunk/maven-plugin-testing-harness/</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/maven/plugin-tools/trunk/maven-plugin-testing-harness/</url>
</scm>
</project>

View File

@ -1,455 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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 org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.ReflectionUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import java.io.File;
import java.io.Reader;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Field;
import java.lang.reflect.AccessibleObject;
/**
* TODO: add a way to use the plugin POM for the lookup so that the user doesn't have to provide the a:g:v:goal
* as the role hint for the mojo lookup.
* TODO: standardize the execution of the mojo and looking at the results, but could simply have a template method
* for verifying the state of the mojo post execution
* TODO: need a way to look at the state of the mojo without adding getters, this could be where we finally specify
* the expressions which extract values from the mojo.
* TODO: create a standard directory structure for picking up POMs to make this even easier, we really just need a testing
* descriptor and make this entirely declarative!
*
* @author jesse
* @version $Id$
*/
public abstract class AbstractMojoTestCase
extends PlexusTestCase
{
private ComponentConfigurator configurator;
/*
* for the harness I think we have decided against going the route of using the maven project builder.
* instead I think we are going to try and make an instance of the localrespository and assign that
* to either the project stub or into the mojo directly with injection...not sure yet though.
*/
//private MavenProjectBuilder projectBuilder;
protected void setUp()
throws Exception
{
super.setUp();
configurator = (ComponentConfigurator) getContainer().lookup( ComponentConfigurator.ROLE, "basic" );
//projectBuilder = (MavenProjectBuilder) getContainer().lookup( MavenProjectBuilder.ROLE );
}
/**
* Lookup the mojo leveraging the subproject pom
*
* @param goal
* @param pluginPom
* @return a Mojo instance
* @throws Exception
*/
protected Mojo lookupMojo( String goal, String pluginPom )
throws Exception
{
return lookupMojo( goal, new File( pluginPom ) );
}
/**
* Lookup an empty mojo
*
* @param goal
* @param pluginPom
* @return a Mojo instance
* @throws Exception
*/
protected Mojo lookupEmptyMojo( String goal, String pluginPom )
throws Exception
{
return lookupEmptyMojo( goal, new File( pluginPom ) );
}
/**
* Lookup the mojo leveraging the actual subprojects pom
*
* @param goal
* @param pom
* @return a Mojo instance
* @throws Exception
*/
protected Mojo lookupMojo( String goal, File pom )
throws Exception
{
File pluginPom = new File( getBasedir(), "pom.xml" );
Xpp3Dom pluginPomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( pluginPom ) );
String artifactId = pluginPomDom.getChild( "artifactId" ).getValue();
String groupId = resolveFromRootThenParent( pluginPomDom, "groupId" );
String version = resolveFromRootThenParent( pluginPomDom, "version" );
PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom );
return lookupMojo( groupId, artifactId, version, goal, pluginConfiguration );
}
/**
* Lookup the mojo leveraging the actual subprojects pom
*
* @param goal
* @param pom
* @return a Mojo instance
* @throws Exception
*/
protected Mojo lookupEmptyMojo( String goal, File pom )
throws Exception
{
File pluginPom = new File( getBasedir(), "pom.xml" );
Xpp3Dom pluginPomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( pluginPom ) );
String artifactId = pluginPomDom.getChild( "artifactId" ).getValue();
String groupId = resolveFromRootThenParent( pluginPomDom, "groupId" );
String version = resolveFromRootThenParent( pluginPomDom, "version" );
return lookupMojo( groupId, artifactId, version, goal, null );
}
/*
protected Mojo lookupMojo( String groupId, String artifactId, String version, String goal, File pom )
throws Exception
{
PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom );
return lookupMojo( groupId, artifactId, version, goal, pluginConfiguration );
}
*/
/**
* lookup the mojo while we have all of the relavent information
*
* @param groupId
* @param artifactId
* @param version
* @param goal
* @param pluginConfiguration
* @return a Mojo instance
* @throws Exception
*/
protected Mojo lookupMojo( String groupId, String artifactId, String version, String goal,
PlexusConfiguration pluginConfiguration )
throws Exception
{
validateContainerStatus();
// pluginkey = groupId : artifactId : version : goal
Mojo mojo = (Mojo) lookup( Mojo.ROLE, groupId + ":" + artifactId + ":" + version + ":" + goal );
Log mojoLogger = new DefaultLog( container.getLoggerManager().getLoggerForComponent( Mojo.ROLE ) );
mojo.setLog( mojoLogger );
if ( pluginConfiguration != null )
{
/* requires v10 of plexus container for lookup on expression evaluator
ExpressionEvaluator evaluator = (ExpressionEvaluator) getContainer().lookup( ExpressionEvaluator.ROLE,
"stub-evaluator" );
*/
ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub();
configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() );
}
return mojo;
}
/**
* @param artifactId
* @param pom
* @return the plexus configuration
* @throws Exception
*/
protected PlexusConfiguration extractPluginConfiguration( String artifactId, File pom )
throws Exception
{
Reader reader = ReaderFactory.newXmlReader( pom );
Xpp3Dom pomDom = Xpp3DomBuilder.build( reader );
return extractPluginConfiguration( artifactId, pomDom );
}
/**
* @param artifactId
* @param pomDom
* @return the plexus configuration
* @throws Exception
*/
protected PlexusConfiguration extractPluginConfiguration( String artifactId, Xpp3Dom pomDom )
throws Exception
{
Xpp3Dom pluginConfigurationElement = null;
Xpp3Dom buildElement = pomDom.getChild( "build" );
if ( buildElement != null )
{
Xpp3Dom pluginsRootElement = buildElement.getChild( "plugins" );
if ( pluginsRootElement != null )
{
Xpp3Dom[] pluginElements = pluginsRootElement.getChildren();
for ( int i = 0; i < pluginElements.length; i++ )
{
Xpp3Dom pluginElement = pluginElements[i];
String pluginElementArtifactId = pluginElement.getChild( "artifactId" ).getValue();
if ( pluginElementArtifactId.equals( artifactId ) )
{
pluginConfigurationElement = pluginElement.getChild( "configuration" );
break;
}
}
if ( pluginConfigurationElement == null )
{
throw new ConfigurationException( "Cannot find a configuration element for a plugin with an artifactId of " + artifactId + "." );
}
}
}
if ( pluginConfigurationElement == null )
{
throw new ConfigurationException( "Cannot find a configuration element for a plugin with an artifactId of "
+ artifactId + "." );
}
return new XmlPlexusConfiguration( pluginConfigurationElement );
}
/**
* Configure the mojo
*
* @param mojo
* @param artifactId
* @param pom
* @return a Mojo instance
* @throws Exception
*/
protected Mojo configureMojo( Mojo mojo, String artifactId, File pom )
throws Exception
{
validateContainerStatus();
PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom );
ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub();
configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() );
return mojo;
}
/**
* Configure the mojo with the given plexus configuration
*
* @param mojo
* @param pluginConfiguration
* @return a Mojo instance
* @throws Exception
*/
protected Mojo configureMojo( Mojo mojo, PlexusConfiguration pluginConfiguration )
throws Exception
{
validateContainerStatus();
ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub();
configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() );
return mojo;
}
/**
* Convenience method to obtain the value of a variable on a mojo that might not have a getter.
*
* NOTE: the caller is responsible for casting to to what the desired type is.
*
* @param object
* @param variable
* @return object value of variable
* @throws IllegalArgumentException
*/
protected Object getVariableValueFromObject( Object object, String variable )
throws IllegalAccessException
{
Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() );
field.setAccessible( true );
return field.get( object );
}
/**
* Convenience method to obtain all variables and values from the mojo (including its superclasses)
*
* Note: the values in the map are of type Object so the caller is responsible for casting to desired types.
*
* @param object
* @return map of variable names and values
*/
protected Map getVariablesAndValuesFromObject( Object object )
throws IllegalAccessException
{
return getVariablesAndValuesFromObject( object.getClass(), object );
}
/**
* Convenience method to obtain all variables and values from the mojo (including its superclasses)
*
* Note: the values in the map are of type Object so the caller is responsible for casting to desired types.
*
* @param clazz
* @param object
* @return map of variable names and values
*/
protected Map getVariablesAndValuesFromObject( Class clazz, Object object )
throws IllegalAccessException
{
Map map = new HashMap();
Field[] fields = clazz.getDeclaredFields();
AccessibleObject.setAccessible( fields, true );
for ( int i = 0; i < fields.length; ++i )
{
Field field = fields[i];
map.put( field.getName(), field.get( object ) );
}
Class superclass = clazz.getSuperclass();
if ( !Object.class.equals( superclass ) )
{
map.putAll( getVariablesAndValuesFromObject( superclass, object ) );
}
return map;
}
/**
* Convenience method to set values to variables in objects that don't have setters
*
* @param object
* @param variable
* @param value
* @throws IllegalAccessException
*/
protected void setVariableValueToObject( Object object, String variable, Object value )
throws IllegalAccessException
{
Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() );
field.setAccessible( true );
field.set( object, value );
}
/**
* sometimes the parent element might contain the correct value so generalize that access
*
* TODO find out where this is probably done elsewhere
*
* @param pluginPomDom
* @param element
* @return
* @throws Exception
*/
private String resolveFromRootThenParent( Xpp3Dom pluginPomDom, String element )
throws Exception
{
Xpp3Dom elementDom = pluginPomDom.getChild( element );
// parent might have the group Id so resolve it
if ( elementDom == null )
{
Xpp3Dom pluginParentDom = pluginPomDom.getChild( "parent" );
if ( pluginParentDom != null )
{
elementDom = pluginParentDom.getChild( element );
if ( elementDom == null )
{
throw new Exception( "unable to determine " + element );
}
return elementDom.getValue();
}
throw new Exception( "unable to determine " + element );
}
return elementDom.getValue();
}
/**
* We should make sure this is called in each method that makes use of the container,
* otherwise we throw ugly NPE's
*
* crops up when the subclassing code defines the setUp method but doesn't call super.setUp()
*
* @throws Exception
*/
private void validateContainerStatus()
throws Exception
{
if ( container != null )
{
return;
}
throw new Exception( "container is null, make sure super.setUp() is called" );
}
}

View File

@ -1,587 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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.IOException;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
import org.codehaus.plexus.archiver.war.WarArchiver;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.ReflectionUtils;
import org.codehaus.plexus.util.StringUtils;
/**
* This class creates artifacts to be used for testing purposes. It can optionally create actual files on the local disk
* for things like copying. It can create these files as archives with named files inside to be used for testing things
* like unpack. Also provided are some utility methods to quickly get a set of artifacts distinguished by various things
* like group,artifact,type,scope, etc It was originally developed for the dependency plugin, but can be useful in other
* plugins that need to simulate artifacts for unit tests.
*
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
*/
public class ArtifactStubFactory
{
private File workingDir;
private boolean createFiles;
private File srcFile;
private boolean createUnpackableFile;
private ArchiverManager archiverManager;
/**
* Default constructor. This should be used only if real files aren't needed...just the artifact objects
*/
public ArtifactStubFactory()
{
this.workingDir = null;
this.createFiles = false;
}
/**
* This constructor is to be used if files are needed and to set a working dir
*
* @param workingDir
* @param createFiles
*/
public ArtifactStubFactory( File workingDir, boolean createFiles )
{
this.workingDir = new File( workingDir, "localTestRepo" );
this.createFiles = createFiles;
}
/**
* If set, the file will be created as a zip/jar/war with a file inside that can be checked to exist after
* unpacking.
*
* @param archiverManager
*/
public void setUnpackableFile( ArchiverManager archiverManager )
{
this.createUnpackableFile = true;
this.archiverManager = archiverManager;
}
/**
* @param groupId
* @param artifactId
* @param version
* @return a <code>DefaultArtifact</code> instance for the given parameters
* @throws IOException if any
* @see #createArtifact(String, String, String, String, String, String)
*/
public Artifact createArtifact( String groupId, String artifactId, String version )
throws IOException
{
return createArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, "jar", "" );
}
/**
* @param groupId
* @param artifactId
* @param version
* @param scope
* @return a <code>DefaultArtifact</code> instance for the given parameters
* @throws IOException if any
* @see #createArtifact(String, String, String, String, String, String)
*/
public Artifact createArtifact( String groupId, String artifactId, String version, String scope )
throws IOException
{
return createArtifact( groupId, artifactId, version, scope, "jar", "" );
}
/**
* @param groupId
* @param artifactId
* @param version
* @param scope
* @param type
* @param classifier
* @return a <code>DefaultArtifact</code> instance for the given parameters
* @throws IOException if any
* @see #createArtifact(String, String, VersionRange, String, String, String, boolean)
*/
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type,
String classifier )
throws IOException
{
VersionRange vr = VersionRange.createFromVersion( version );
return createArtifact( groupId, artifactId, vr, scope, type, classifier, false );
}
/**
* @param groupId not null
* @param artifactId not null
* @param versionRange not null
* @param scope not null
* @param type not null
* @param classifier
* @param optional not null
* @return a <code>DefaultArtifact</code> instance
* @throws IOException if any
*/
public Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String scope,
String type, String classifier, boolean optional )
throws IOException
{
ArtifactHandler ah = new DefaultArtifactHandlerStub( type, classifier );
Artifact artifact =
new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, ah, optional );
// i have no idea why this needs to be done manually when isSnapshot is able to figure it out.
artifact.setRelease( !artifact.isSnapshot() );
if ( createFiles )
{
setArtifactFile( artifact, this.workingDir, this.srcFile, this.createUnpackableFile );
}
return artifact;
}
/**
* Creates a new empty file and attaches it to the artifact.
*
* @param artifact to attach the file to.
* @param workingDir where to locate the new file
* @throws IOException
*/
public void setArtifactFile( Artifact artifact, File workingDir )
throws IOException
{
setArtifactFile( artifact, workingDir, null, false );
}
/**
* Copyies the srcFile to the workingDir and then attaches it to the artifact. If srcFile is null, a new empty file
* will be created.
*
* @param artifact to attach
* @param workingDir where to copy the srcFile.
* @param srcFile file to be attached.
* @throws IOException
*/
public void setArtifactFile( Artifact artifact, File workingDir, File srcFile )
throws IOException
{
setArtifactFile( artifact, workingDir, srcFile, false );
}
/**
* Creates an unpackable file (zip,jar etc) containing an empty file.
*
* @param artifact to attach
* @param workingDir where to create the file.
* @throws IOException
*/
public void setUnpackableArtifactFile( Artifact artifact, File workingDir )
throws IOException
{
setArtifactFile( artifact, workingDir, null, true );
}
/**
* Creates an unpackable file (zip,jar etc) containing the srcFile. If srcFile is null, a new empty file will be
* created.
*
* @param artifact to attach
* @param workingDir where to create the file.
* @param srcFile
* @throws IOException if any
*/
public void setUnpackableArtifactFile( Artifact artifact, File workingDir, File srcFile )
throws IOException
{
setArtifactFile( artifact, workingDir, srcFile, true );
}
/**
* Creates a file that can be copied or unpacked based on the passed in artifact
*
* @param artifact
* @param workingDir
* @param srcFile
* @param createUnpackableFile
* @throws IOException if any
*/
private void setArtifactFile( Artifact artifact, File workingDir, File srcFile, boolean createUnpackableFile )
throws IOException
{
if ( workingDir == null )
{
throw new IllegalArgumentException(
"The workingDir must be set." );
}
String fileName = getFormattedFileName( artifact, false );
File theFile = new File( workingDir, fileName );
theFile.getParentFile().mkdirs();
if ( srcFile == null )
{
theFile.createNewFile();
}
else if ( createUnpackableFile )
{
try
{
createUnpackableFile( artifact, theFile );
}
catch ( NoSuchArchiverException e )
{
throw new IOException( "NoSuchArchiverException: " + e.getMessage() );
}
catch ( ArchiverException e )
{
throw new IOException( "ArchiverException: " + e.getMessage() );
}
}
else
{
FileUtils.copyFile( srcFile, theFile );
}
artifact.setFile( theFile );
}
/**
* @param artifact
* @return
*/
public static String getUnpackableFileName( Artifact artifact )
{
return "" + artifact.getGroupId() + "-" + artifact.getArtifactId() + "-" + artifact.getVersion() + "-"
+ artifact.getClassifier() + "-" + artifact.getType() + ".txt";
}
/**
* @param artifact
* @param destFile
* @throws NoSuchArchiverException
* @throws ArchiverException if any
* @throws IOException if any
*/
public void createUnpackableFile( Artifact artifact, File destFile )
throws NoSuchArchiverException, ArchiverException, IOException
{
Archiver archiver = archiverManager.getArchiver( destFile );
archiver.setDestFile( destFile );
archiver.addFile( srcFile, getUnpackableFileName( artifact ) );
try
{
setVariableValueToObject( archiver, "logger", new SilentLog() );
}
catch ( IllegalAccessException e )
{
System.out.println( "Unable to override logger with silent log." );
e.printStackTrace();
}
if ( archiver instanceof WarArchiver )
{
WarArchiver war = (WarArchiver) archiver;
// the use of this is counter-intuitive:
// http://jira.codehaus.org/browse/PLX-286
war.setIgnoreWebxml( false );
}
archiver.createArchive();
}
/**
* @return a <code>DefaultArtifact</code> instance for <code>testGroupId:release:jar:1.0</code>
* @throws IOException if any
*/
public Artifact getReleaseArtifact()
throws IOException
{
return createArtifact( "testGroupId", "release", "1.0" );
}
/**
* @return a default <code>DefaultArtifact</code> instance for <code>testGroupId:snapshot:jar:2.0-SNAPSHOT</code>
* @throws IOException if any
*/
public Artifact getSnapshotArtifact()
throws IOException
{
return createArtifact( "testGroupId", "snapshot", "2.0-SNAPSHOT" );
}
/**
* @return a default set of release and snapshot <code>DefaultArtifact</code>, i.e.:
* <code>testGroupId:snapshot:jar:2.0-SNAPSHOT, testGroupId:release:jar:1.0</code>
* @throws IOException if any
* @see #getReleaseArtifact()
* @see #getSnapshotArtifact()
*/
public Set getReleaseAndSnapshotArtifacts()
throws IOException
{
Set set = new HashSet();
set.add( getReleaseArtifact() );
set.add( getSnapshotArtifact() );
return set;
}
/**
* @return a default set of <code>DefaultArtifact</code>, i.e.:
* <code>g:provided:jar:1.0, g:compile:jar:1.0, g:system:jar:1.0, g:test:jar:1.0, g:runtime:jar:1.0</code>
* @throws IOException if any
*/
public Set getScopedArtifacts()
throws IOException
{
Set set = new HashSet();
set.add( createArtifact( "g", "compile", "1.0", Artifact.SCOPE_COMPILE ) );
set.add( createArtifact( "g", "provided", "1.0", Artifact.SCOPE_PROVIDED ) );
set.add( createArtifact( "g", "test", "1.0", Artifact.SCOPE_TEST ) );
set.add( createArtifact( "g", "runtime", "1.0", Artifact.SCOPE_RUNTIME ) );
set.add( createArtifact( "g", "system", "1.0", Artifact.SCOPE_SYSTEM ) );
return set;
}
/**
* @return a set of <code>DefaultArtifact</code>, i.e.:
* <code>g:d:zip:1.0, g:a:war:1.0, g:b:jar:1.0, g:c:sources:1.0, g:e:rar:1.0</code>
* @throws IOException if any
*/
public Set getTypedArtifacts()
throws IOException
{
Set set = new HashSet();
set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "war", null ) );
set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", null ) );
set.add( createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE, "sources", null ) );
set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE, "zip", null ) );
set.add( createArtifact( "g", "e", "1.0", Artifact.SCOPE_COMPILE, "rar", null ) );
return set;
}
/**
* @return a set of <code>DefaultArtifact</code>, i.e.:
* <code>g:c:jar:three:1.0, g:b:jar:two:1.0, g:d:jar:four:1.0, g:a:jar:one:1.0</code>
* @throws IOException if any
*/
public Set getClassifiedArtifacts()
throws IOException
{
Set set = new HashSet();
set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "jar", "one" ) );
set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", "two" ) );
set.add( createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE, "jar", "three" ) );
set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE, "jar", "four" ) );
return set;
}
/**
* @return a set of <code>DefaultArtifact</code>, i.e.:
* <code>g:d:zip:1.0, g:a:war:1.0, g:b:jar:1.0, g:e:rar:1.0</code>
* @throws IOException if any
*/
public Set getTypedArchiveArtifacts()
throws IOException
{
Set set = new HashSet();
set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "war", null ) );
set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", null ) );
set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE, "zip", null ) );
set.add( createArtifact( "g", "e", "1.0", Artifact.SCOPE_COMPILE, "rar", null ) );
return set;
}
/**
* @return a set of <code>DefaultArtifact</code>, i.e.:
* <code>g:one:jar:a:1.0, g:two:jar:a:1.0, g:four:jar:a:1.0, g:three:jar:a:1.0</code>
* @throws IOException if any
*/
public Set getArtifactArtifacts()
throws IOException
{
Set set = new HashSet();
set.add( createArtifact( "g", "one", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) );
set.add( createArtifact( "g", "two", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) );
set.add( createArtifact( "g", "three", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) );
set.add( createArtifact( "g", "four", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) );
return set;
}
/**
* @return a set of <code>DefaultArtifact</code>, i.e.:
* <code>one:group-one:jar:a:1.0, three:group-three:jar:a:1.0, four:group-four:jar:a:1.0,
* two:group-two:jar:a:1.0</code>
* @throws IOException if any
*/
public Set getGroupIdArtifacts()
throws IOException
{
Set set = new HashSet();
set.add( createArtifact( "one", "group-one", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) );
set.add( createArtifact( "two", "group-two", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) );
set.add( createArtifact( "three", "group-three", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) );
set.add( createArtifact( "four", "group-four", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) );
return set;
}
/**
* @return a set of <code>DefaultArtifact</code>
* @throws IOException if any
* @see #getTypedArtifacts()
* @see #getScopedArtifacts()
* @see #getReleaseAndSnapshotArtifacts()
*/
public Set getMixedArtifacts()
throws IOException
{
Set set = new HashSet();
set.addAll( getTypedArtifacts() );
set.addAll( getScopedArtifacts() );
set.addAll( getReleaseAndSnapshotArtifacts() );
return set;
}
/**
* @return Returns the createFiles.
*/
public boolean isCreateFiles()
{
return this.createFiles;
}
/**
* @param createFiles The createFiles to set.
*/
public void setCreateFiles( boolean createFiles )
{
this.createFiles = createFiles;
}
/**
* @return Returns the workingDir.
*/
public File getWorkingDir()
{
return this.workingDir;
}
/**
* @param workingDir The workingDir to set.
*/
public void setWorkingDir( File workingDir )
{
this.workingDir = workingDir;
}
/**
* @return Returns the srcFile.
*/
public File getSrcFile()
{
return this.srcFile;
}
/**
* @param srcFile The srcFile to set.
*/
public void setSrcFile( File srcFile )
{
this.srcFile = srcFile;
}
/**
* Convenience method to set values to variables in objects that don't have setters
*
* @param object
* @param variable
* @param value
* @throws IllegalAccessException
*/
public static void setVariableValueToObject( Object object, String variable, Object value )
throws IllegalAccessException
{
Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() );
field.setAccessible( true );
field.set( object, value );
}
/**
* Builds the file name. If removeVersion is set, then the file name must be reconstructed from the artifactId,
* Classifier (if used) and Type. Otherwise, this method returns the artifact file name.
*
* @param artifact File to be formatted.
* @param removeVersion Specifies if the version should be removed from the file name.
* @return Formatted file name in the format artifactId-[version]-[classifier].[type]
*/
public static String getFormattedFileName( Artifact artifact, boolean removeVersion )
{
String destFileName = null;
// if there is a file and we aren't stripping the version, just get the
// name directly
if ( artifact.getFile() != null && !removeVersion )
{
destFileName = artifact.getFile().getName();
}
else
// if offline
{
String versionString = null;
if ( !removeVersion )
{
versionString = "-" + artifact.getVersion();
}
else
{
versionString = "";
}
String classifierString = "";
if ( StringUtils.isNotEmpty( artifact.getClassifier() ) )
{
classifierString = "-" + artifact.getClassifier();
}
destFileName = artifact.getArtifactId() + versionString + classifierString + "."
+ artifact.getArtifactHandler().getExtension();
}
return destFileName;
}
}

View File

@ -1,58 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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.
*/
/**
* ConfigurationException
*
* @author jesse
* @version $Id$
*/
public class ConfigurationException
extends Exception
{
/** serialVersionUID */
static final long serialVersionUID = -6180939638742159065L;
/**
* @param message The detailed message.
*/
public ConfigurationException( String message )
{
super( message );
}
/**
* @param cause The detailed cause.
*/
public ConfigurationException( Throwable cause )
{
super( cause );
}
/**
* @param message The detailed message.
* @param cause The detailed cause.
*/
public ConfigurationException( String message, Throwable cause )
{
super( message, cause );
}
}

View File

@ -1,140 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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 org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
/**
* Stub for {@link ExpressionEvaluator}
*
* @author jesse
* @version $Id$
*/
public class ResolverExpressionEvaluatorStub
implements ExpressionEvaluator
{
/** {@inheritDoc} */
public Object evaluate( String expr )
throws ExpressionEvaluationException
{
Object value = null;
if ( expr == null )
{
return null;
}
String expression = stripTokens( expr );
if ( expression.equals( expr ) )
{
int index = expr.indexOf( "${" );
if ( index >= 0 )
{
int lastIndex = expr.indexOf( "}", index );
if ( lastIndex >= 0 )
{
String retVal = expr.substring( 0, index );
if ( index > 0 && expr.charAt( index - 1 ) == '$' )
{
retVal += expr.substring( index + 1, lastIndex + 1 );
}
else
{
retVal += evaluate( expr.substring( index, lastIndex + 1 ) );
}
retVal += evaluate( expr.substring( lastIndex + 1 ) );
return retVal;
}
}
// Was not an expression
if ( expression.indexOf( "$$" ) > -1 )
{
return expression.replaceAll( "\\$\\$", "\\$" );
}
}
if ( "basedir".equals( expression ) )
{
return PlexusTestCase.getBasedir();
}
else if ( expression.startsWith( "basedir" ) )
{
int pathSeparator = expression.indexOf( "/" );
if ( pathSeparator > 0 )
{
value = PlexusTestCase.getBasedir() + expression.substring( pathSeparator );
}
else
{
System.out.println( "Got expression '" + expression + "' that was not recognised" );
}
return value;
}
else if ( "localRepository".equals( expression ) )
{
File localRepo = new File( PlexusTestCase.getBasedir(), "target/local-repo" );
return new DefaultArtifactRepository( "localRepository", "file://" + localRepo.getAbsolutePath(),
new DefaultRepositoryLayout() );
}
else
{
return expr;
}
}
private String stripTokens( String expr )
{
if ( expr.startsWith( "${" ) && expr.indexOf( "}" ) == expr.length() - 1 )
{
expr = expr.substring( 2, expr.length() - 1 );
}
return expr;
}
/** {@inheritDoc} */
public File alignToBaseDirectory( File file )
{
if ( file.getAbsolutePath().startsWith( PlexusTestCase.getBasedir() ) )
{
return file;
}
else if ( file.isAbsolute() )
{
return file;
}
else
{
return new File( PlexusTestCase.getBasedir(), file.getPath() );
}
}
}

View File

@ -1,328 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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 org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.logging.Logger;
/**
* This logger implements both types of logs currently in use. It can be injected where needed
* to turn off logs during testing where they aren't desired.
*
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
*/
public class SilentLog
implements Log, Logger
{
/**
* @return <code>false</code>
* @see org.apache.maven.plugin.logging.Log#isDebugEnabled()
*/
public boolean isDebugEnabled()
{
return false;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence)
*/
public void debug( CharSequence content )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence, java.lang.Throwable)
*/
public void debug( CharSequence content, Throwable error )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#debug(java.lang.Throwable)
*/
public void debug( Throwable error )
{
// nop
}
/**
* @return <code>false</code>
* @see org.apache.maven.plugin.logging.Log#isInfoEnabled()
*/
public boolean isInfoEnabled()
{
return false;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence)
*/
public void info( CharSequence content )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence, java.lang.Throwable)
*/
public void info( CharSequence content, Throwable error )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#info(java.lang.Throwable)
*/
public void info( Throwable error )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#isWarnEnabled()
*/
public boolean isWarnEnabled()
{
// nop
return false;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence)
*/
public void warn( CharSequence content )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence, java.lang.Throwable)
*/
public void warn( CharSequence content, Throwable error )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#warn(java.lang.Throwable)
*/
public void warn( Throwable error )
{
// nop
}
/**
* @return <code>false</code>
* @see org.apache.maven.plugin.logging.Log#isErrorEnabled()
*/
public boolean isErrorEnabled()
{
return false;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence)
*/
public void error( CharSequence content )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence, java.lang.Throwable)
*/
public void error( CharSequence content, Throwable error )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable)
*/
public void error( Throwable error )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#debug(java.lang.String)
*/
public void debug( String message )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#debug(java.lang.String, java.lang.Throwable)
*/
public void debug( String message, Throwable throwable )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#info(java.lang.String)
*/
public void info( String message )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#info(java.lang.String, java.lang.Throwable)
*/
public void info( String message, Throwable throwable )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#warn(java.lang.String)
*/
public void warn( String message )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#warn(java.lang.String, java.lang.Throwable)
*/
public void warn( String message, Throwable throwable )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#error(java.lang.String)
*/
public void error( String message )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#error(java.lang.String, java.lang.Throwable)
*/
public void error( String message, Throwable throwable )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#fatalError(java.lang.String)
*/
public void fatalError( String message )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.codehaus.plexus.logging.Logger#fatalError(java.lang.String, java.lang.Throwable)
*/
public void fatalError( String message, Throwable throwable )
{
// nop
}
/**
* @return <code>false</code>
* @see org.codehaus.plexus.logging.Logger#isFatalErrorEnabled()
*/
public boolean isFatalErrorEnabled()
{
return false;
}
/**
* @return <code>null</code>
* @see org.codehaus.plexus.logging.Logger#getChildLogger(java.lang.String)
*/
public Logger getChildLogger( String name )
{
return null;
}
/**
* @return <code>0</code>
* @see org.codehaus.plexus.logging.Logger#getThreshold()
*/
public int getThreshold()
{
return 0;
}
/**
* @return <code>null</code>
* @see org.codehaus.plexus.logging.Logger#getName()
*/
public String getName()
{
return null;
}
}

View File

@ -1,500 +0,0 @@
package org.apache.maven.plugin.testing.stubs;
/*
* 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 org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import java.io.File;
import java.util.Collection;
import java.util.List;
/**
* Stub class for {@link Artifact} testing.
*
* @author jesse
* @version $Id$
*/
public class ArtifactStub
implements Artifact
{
private String groupId;
private String artifactId;
private String version;
private String scope;
private String type;
private String classifier;
private File file;
private ArtifactRepository artifactRepository;
/**
* By default, return <code>0</code>
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo( Object object )
{
return 0;
}
/** {@inheritDoc} */
public String getGroupId()
{
return groupId;
}
/** {@inheritDoc} */
public String getArtifactId()
{
return artifactId;
}
/** {@inheritDoc} */
public String getVersion()
{
return version;
}
/** {@inheritDoc} */
public void setVersion( String version )
{
this.version = version;
}
/** {@inheritDoc} */
public String getScope()
{
return scope;
}
/** {@inheritDoc} */
public String getType()
{
return type;
}
/**
* Set a new type
*
* @param type
*/
public void setType( String type )
{
this.type = type;
}
/** {@inheritDoc} */
public String getClassifier()
{
return classifier;
}
/** {@inheritDoc} */
public boolean hasClassifier()
{
return classifier != null;
}
/** {@inheritDoc} */
public File getFile()
{
return file;
}
/** {@inheritDoc} */
public void setFile( File file )
{
this.file = file;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getBaseVersion()
*/
public String getBaseVersion()
{
return null;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setBaseVersion(java.lang.String)
*/
public void setBaseVersion( String string )
{
// nop
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getId()
*/
public String getId()
{
return null;
}
/**
* @return <code>groupId:artifactId:type:classifier</code>.
* @see org.apache.maven.artifact.Artifact#getDependencyConflictId()
*/
public String getDependencyConflictId()
{
StringBuffer buffer = new StringBuffer();
buffer.append( getGroupId() );
buffer.append( ":" ).append( getArtifactId() );
buffer.append( ":" ).append( getType() );
buffer.append( ":" ).append( getClassifier() );
return buffer.toString();
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#addMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata)
*/
public void addMetadata( ArtifactMetadata artifactMetadata )
{
// nop
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getMetadataList()
*/
public Collection getMetadataList()
{
return null;
}
/** {@inheritDoc} */
public void setRepository( ArtifactRepository artifactRepository )
{
this.artifactRepository = artifactRepository;
}
/** {@inheritDoc} */
public ArtifactRepository getRepository()
{
return artifactRepository;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#updateVersion(java.lang.String, org.apache.maven.artifact.repository.ArtifactRepository)
*/
public void updateVersion( String string, ArtifactRepository artifactRepository )
{
// nop
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getDownloadUrl()
*/
public String getDownloadUrl()
{
return null;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setDownloadUrl(java.lang.String)
*/
public void setDownloadUrl( String string )
{
// nop
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getDependencyFilter()
*/
public ArtifactFilter getDependencyFilter()
{
return null;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setDependencyFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter)
*/
public void setDependencyFilter( ArtifactFilter artifactFilter )
{
// nop
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getArtifactHandler()
*/
public ArtifactHandler getArtifactHandler()
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getDependencyTrail()
*/
public List getDependencyTrail()
{
return null;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setDependencyTrail(java.util.List)
*/
public void setDependencyTrail( List list )
{
// nop
}
/** {@inheritDoc} */
public void setScope( String scope )
{
this.scope = scope;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getVersionRange()
*/
public VersionRange getVersionRange()
{
return null;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setVersionRange(org.apache.maven.artifact.versioning.VersionRange)
*/
public void setVersionRange( VersionRange versionRange )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#selectVersion(java.lang.String)
*/
public void selectVersion( String string )
{
// nop
}
/** {@inheritDoc} */
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
/** {@inheritDoc} */
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
/**
* @return <code>false</code>.
* @see org.apache.maven.artifact.Artifact#isSnapshot()
*/
public boolean isSnapshot()
{
return Artifact.VERSION_FILE_PATTERN.matcher( getVersion() ).matches()
|| getVersion().endsWith( Artifact.SNAPSHOT_VERSION );
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setResolved(boolean)
*/
public void setResolved( boolean b )
{
// nop
}
/**
* @return <code>false</code>.
* @see org.apache.maven.artifact.Artifact#isResolved()
*/
public boolean isResolved()
{
return false;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setResolvedVersion(java.lang.String)
*/
public void setResolvedVersion( String string )
{
// nop
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler)
*/
public void setArtifactHandler( ArtifactHandler artifactHandler )
{
// nop
}
/**
* @return <code>false</code>.
* @see org.apache.maven.artifact.Artifact#isRelease()
*/
public boolean isRelease()
{
return !isSnapshot();
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setRelease(boolean)
*/
public void setRelease( boolean b )
{
// nop
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getAvailableVersions()
*/
public List getAvailableVersions()
{
return null;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.Artifact#setAvailableVersions(java.util.List)
*/
public void setAvailableVersions( List list )
{
// nop
}
/**
* @return <code>false</code>.
* @see org.apache.maven.artifact.Artifact#isOptional()
*/
public boolean isOptional()
{
return false;
}
/**
* By default, do nothing.
*
* @param b
*/
public void setOptional( boolean b )
{
// nop
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.Artifact#getSelectedVersion()
*/
public ArtifactVersion getSelectedVersion()
throws OverConstrainedVersionException
{
return null;
}
/**
* @return <code>false</code>.
* @see org.apache.maven.artifact.Artifact#isSelectedVersionKnown()
*/
public boolean isSelectedVersionKnown()
throws OverConstrainedVersionException
{
return false;
}
/**
* @see java.lang.Object#toString()
*/
public String toString()
{
StringBuffer sb = new StringBuffer();
if ( getGroupId() != null )
{
sb.append( getGroupId() );
sb.append( ":" );
}
appendArtifactTypeClassifierString( sb );
if ( version != null )
{
sb.append( ":" );
sb.append( getVersion() );
}
if ( scope != null )
{
sb.append( ":" );
sb.append( scope );
}
return sb.toString();
}
private void appendArtifactTypeClassifierString( StringBuffer sb )
{
sb.append( getArtifactId() );
sb.append( ":" );
sb.append( getType() );
if ( hasClassifier() )
{
sb.append( ":" );
sb.append( getClassifier() );
}
}
}

View File

@ -1,202 +0,0 @@
package org.apache.maven.plugin.testing.stubs;
/*
* 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 org.apache.maven.artifact.handler.ArtifactHandler;
/**
* Minimal artifact handler used by the stub factory to create unpackable archives.
*
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
*/
public class DefaultArtifactHandlerStub
implements ArtifactHandler
{
private String extension;
private String type;
private String classifier;
private String directory;
private String packaging;
private boolean includesDependencies;
private String language;
private boolean addedToClasspath;
/**
* @param t the artifact handler type
* @param c the artifact handler classifier
*/
public DefaultArtifactHandlerStub( String t, String c )
{
type = t;
classifier = c;
if ( t.equals( "test-jar" ) )
{
extension = "jar";
}
}
/**
* @param type the artifact handler type
*/
public DefaultArtifactHandlerStub( String type )
{
this.type = type;
}
/** {@inheritDoc} */
public String getExtension()
{
if ( extension == null )
{
extension = type;
}
return extension;
}
/**
* @return the artifact handler type
*/
public String getType()
{
return type;
}
/** {@inheritDoc} */
public String getClassifier()
{
return classifier;
}
/** {@inheritDoc} */
public String getDirectory()
{
if ( directory == null )
{
directory = getPackaging() + "s";
}
return directory;
}
/** {@inheritDoc} */
public String getPackaging()
{
if ( packaging == null )
{
packaging = getType();
}
return packaging;
}
/** {@inheritDoc} */
public boolean isIncludesDependencies()
{
return includesDependencies;
}
/** {@inheritDoc} */
public String getLanguage()
{
if ( language == null )
{
language = "none";
}
return language;
}
/** {@inheritDoc} */
public boolean isAddedToClasspath()
{
return addedToClasspath;
}
/**
* @param theAddedToClasspath The addedToClasspath to set.
*/
public void setAddedToClasspath( boolean theAddedToClasspath )
{
this.addedToClasspath = theAddedToClasspath;
}
/**
* @param theClassifier The classifier to set.
*/
public void setClassifier( String theClassifier )
{
this.classifier = theClassifier;
}
/**
* @param theDirectory The directory to set.
*/
public void setDirectory( String theDirectory )
{
this.directory = theDirectory;
}
/**
* @param theExtension The extension to set.
*/
public void setExtension( String theExtension )
{
this.extension = theExtension;
}
/**
* @param theIncludesDependencies The includesDependencies to set.
*/
public void setIncludesDependencies( boolean theIncludesDependencies )
{
this.includesDependencies = theIncludesDependencies;
}
/**
* @param theLanguage The language to set.
*/
public void setLanguage( String theLanguage )
{
this.language = theLanguage;
}
/**
* @param thePackaging The packaging to set.
*/
public void setPackaging( String thePackaging )
{
this.packaging = thePackaging;
}
/**
* @param theType The type to set.
*/
public void setType( String theType )
{
this.type = theType;
}
}

View File

@ -1,89 +0,0 @@
package org.apache.maven.plugin.testing.stubs;
/*
* 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.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactCollector;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ResolutionNode;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
/**
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
*/
public class StubArtifactCollector
implements ArtifactCollector
{
/**
* Default constructor
*/
public StubArtifactCollector()
{
super();
}
/** {@inheritDoc} */
public ArtifactResolutionResult collect( Set theArtifacts, Artifact theOriginatingArtifact,
ArtifactRepository theLocalRepository, List theRemoteRepositories,
ArtifactMetadataSource theSource, ArtifactFilter theFilter,
List theListeners )
throws ArtifactResolutionException
{
Set nodes = new HashSet();
ArtifactResolutionResult arr = new ArtifactResolutionResult();
Iterator iter = theArtifacts.iterator();
while ( iter.hasNext() )
{
nodes.add( new ResolutionNode( (Artifact) iter.next(), theRemoteRepositories ) );
}
arr.setArtifactResolutionNodes( nodes );
return arr;
}
/** {@inheritDoc} */
public ArtifactResolutionResult collect( Set theArtifacts, Artifact theOriginatingArtifact, Map theManagedVersions,
ArtifactRepository theLocalRepository, List theRemoteRepositories,
ArtifactMetadataSource theSource, ArtifactFilter theFilter,
List theListeners )
throws ArtifactResolutionException
{
Set nodes = new HashSet();
ArtifactResolutionResult arr = new ArtifactResolutionResult();
Iterator iter = theArtifacts.iterator();
while ( iter.hasNext() )
{
nodes.add( new ResolutionNode( (Artifact) iter.next(), theRemoteRepositories ) );
}
arr.setArtifactResolutionNodes( nodes );
return arr;
}
}

View File

@ -1,173 +0,0 @@
package org.apache.maven.plugin.testing.stubs;
/*
* 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 org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
/**
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
*/
public class StubArtifactRepository
implements ArtifactRepository
{
private String baseDir = null;
/**
* Default constructor
*
* @param dir the basedir
*/
public StubArtifactRepository( String dir )
{
baseDir = dir;
}
/**
* @return the <code>artifactId</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#pathOf(org.apache.maven.artifact.Artifact)
*/
public String pathOf( Artifact artifact )
{
return artifact.getId();
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#pathOfRemoteRepositoryMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata)
*/
public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )
{
return null;
}
/**
* @return the filename of this metadata on the local repository.
* @see org.apache.maven.artifact.repository.ArtifactRepository#pathOfLocalRepositoryMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata, org.apache.maven.artifact.repository.ArtifactRepository)
*/
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
return metadata.getLocalFilename( repository );
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#getUrl()
*/
public String getUrl()
{
return null;
}
/**
* @return <code>basedir</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#getBasedir()
*/
public String getBasedir()
{
return baseDir;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#getProtocol()
*/
public String getProtocol()
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#getId()
*/
public String getId()
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#getSnapshots()
*/
public ArtifactRepositoryPolicy getSnapshots()
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#getReleases()
*/
public ArtifactRepositoryPolicy getReleases()
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#getLayout()
*/
public ArtifactRepositoryLayout getLayout()
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#getKey()
*/
public String getKey()
{
return null;
}
/**
* @return <code>false</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#isUniqueVersion()
*/
public boolean isUniqueVersion()
{
return false;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.repository.ArtifactRepository#setBlacklisted(boolean)
*/
public void setBlacklisted( boolean blackListed )
{
// nop
}
/**
* @return <code>false</code>.
* @see org.apache.maven.artifact.repository.ArtifactRepository#isBlacklisted()
*/
public boolean isBlacklisted()
{
return false;
}
}

View File

@ -1,184 +0,0 @@
package org.apache.maven.plugin.testing.stubs;
/*
* 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.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
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.filter.ArtifactFilter;
import org.apache.maven.plugin.testing.ArtifactStubFactory;
/**
* Stub resolver. The constructor allows the specification of the exception to throw so that handling can be tested too.
*
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
*/
public class StubArtifactResolver
implements ArtifactResolver
{
private boolean throwArtifactResolutionException;
private boolean throwArtifactNotFoundException;
private ArtifactStubFactory factory;
/**
* Default constructor
*
* @param factory
* @param throwArtifactResolutionException
* @param throwArtifactNotFoundException
*/
public StubArtifactResolver( ArtifactStubFactory factory, boolean throwArtifactResolutionException,
boolean throwArtifactNotFoundException )
{
this.throwArtifactNotFoundException = throwArtifactNotFoundException;
this.throwArtifactResolutionException = throwArtifactResolutionException;
this.factory = factory;
}
/**
* Creates dummy file and sets it in the artifact to simulate resolution
*
* @see org.apache.maven.artifact.resolver.ArtifactResolver#resolve(org.apache.maven.artifact.Artifact, java.util.List, org.apache.maven.artifact.repository.ArtifactRepository)
*/
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException
{
if ( !this.throwArtifactNotFoundException && !this.throwArtifactResolutionException )
{
try
{
if ( factory != null )
{
factory.setArtifactFile( artifact, factory.getWorkingDir() );
}
}
catch ( IOException e )
{
throw new ArtifactResolutionException( "IOException: " + e.getMessage(), artifact, e );
}
}
else
{
if ( throwArtifactResolutionException )
{
throw new ArtifactResolutionException( "Catch!", artifact );
}
throw new ArtifactNotFoundException( "Catch!", artifact );
}
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.List, org.apache.maven.artifact.repository.ArtifactRepository, org.apache.maven.artifact.metadata.ArtifactMetadataSource)
*/
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.List, org.apache.maven.artifact.repository.ArtifactRepository, org.apache.maven.artifact.metadata.ArtifactMetadataSource, java.util.List)
*/
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
List remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source, List listeners )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource, org.apache.maven.artifact.resolver.filter.ArtifactFilter)
*/
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
ArtifactRepository localRepository, List remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.Map, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource)
*/
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List remoteRepositories, ArtifactMetadataSource source )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.Map, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource, org.apache.maven.artifact.resolver.filter.ArtifactFilter)
*/
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List remoteRepositories, ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return null;
}
/**
* @return <code>null</code>.
* @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.Map, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource, org.apache.maven.artifact.resolver.filter.ArtifactFilter, java.util.List)
*/
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List remoteRepositories, ArtifactMetadataSource source,
ArtifactFilter filter, List listeners )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return null;
}
/**
* By default, do nothing.
*
* @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveAlways(org.apache.maven.artifact.Artifact, java.util.List, org.apache.maven.artifact.repository.ArtifactRepository)
*/
public void resolveAlways( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException
{
// nop
}
}

View File

@ -1,39 +0,0 @@
<!--
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.
-->
<component-set>
<components>
<component>
<role>org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator</role>
<role-hint>stub-evaluator</role-hint>
<implementation>org.apache.maven.plugin.testing.StubResolverExpressionEvaluator</implementation>
<requirements>
<requirement>
<role>org.codehaus.plexus.PlexusContainer</role>
<field-name>container</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.artifact.Artifact</role>
<role-hint>stub</role-hint>
<implementation>org.apache.maven.plugin.testing.stubs.StubArtifact</implementation>
</component>
</components>
</component-set>

View File

@ -1,218 +0,0 @@
------
Testing Project Artifact
------
Vincent Siveton
------
February 2008
------
~~ 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.
Testing Project Artifact
<<Note>>: This example improves the {{{../getting-started/index.html}cookbook}} to play with artifact handler.
Sometimes, your Mojo uses project artifact and ArtifactHandler mechanisms. For instance, you could need to
filter on Java projects, i.e.:
-----
public class MyMojo
extends AbstractMojo
{
/**
* The Maven Project.
*
* @parameter expression="${project}"
* @required
* @readonly
*/
protected MavenProject project;
public void execute()
throws MojoExecutionException
{
...
ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();
if ( "java".equals( artifactHandler.getLanguage() ) )
{
...
}
...
}
}
-----
* Create Stubs
-----
public class MyArtifactHandlerStub
extends DefaultArtifactHandler
{
private String language;
public String getLanguage()
{
if ( language == null )
{
language = "java";
}
return language;
}
public void setLanguage( String language )
{
this.language = language;
}
}
-----
-----
public class MyArtifactStub
extends ArtifactStub
{
private String groupId;
private String artifactId;
private String version;
private String packaging;
private VersionRange versionRange;
private ArtifactHandler handler;
/**
* @param groupId
* @param artifactId
* @param version
* @param packaging
*/
public ProjectInfoPluginArtifactStub( String groupId, String artifactId,
String version, String packaging )
{
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.packaging = packaging;
versionRange = VersionRange.createFromVersion( version );
}
/** {@inheritDoc} */
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
/** {@inheritDoc} */
public String getGroupId()
{
return groupId;
}
/** {@inheritDoc} */
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
/** {@inheritDoc} */
public String getArtifactId()
{
return artifactId;
}
/** {@inheritDoc} */
public void setVersion( String version )
{
this.version = version;
}
/** {@inheritDoc} */
public String getVersion()
{
return version;
}
/**
* @param packaging
*/
public void setPackaging( String packaging )
{
this.packaging = packaging;
}
/**
* @return the packaging
*/
public String getPackaging()
{
return packaging;
}
/** {@inheritDoc} */
public VersionRange getVersionRange()
{
return versionRange;
}
/** {@inheritDoc} */
public void setVersionRange( VersionRange versionRange )
{
this.versionRange = versionRange;
}
/** {@inheritDoc} */
public ArtifactHandler getArtifactHandler()
{
return handler;
}
/** {@inheritDoc} */
public void setArtifactHandler( ArtifactHandler handler )
{
this.handler = handler;
}
}
-----
-----
public class MyProjectStub
extends MavenProjectStub
{
/**
* Default constructor
*/
public MyProjectStub()
{
...
Artifact artifact = new MyArtifactStub( getGroupId(), getArtifactId(),
getVersion(), getPackaging() );
artifact.setArtifactHandler( new MyArtifactHandlerStub() );
setArtifact( artifact );
...
}
...
}
-----

View File

@ -1,186 +0,0 @@
------
Testing Complex Mojo Parameters
------
Vincent Siveton
------
February 2008
------
~~ 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.
Testing Complex Mojo Parameters
<<Note>>: This example improves the {{{../getting-started/index.html}cookbook}} for testing complex Mojo parameters.
In real plugin development, you will use specific Maven objects like <<<MavenProject>>>, <<<ArtifactRepository>>> or
<<<MavenSettings>>>. You could use them by defining stubs.
Suppose that you have the following dependencies in the maven-my-plugin pom:
-----
<project>
...
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.8</version>
</dependency>
...
</dependencies>
</project>
-----
You will add the following in the <<<MyMojo>>>:
-----
public class MyMojo
extends AbstractMojo
{
/**
* The Maven Project.
*
* @parameter expression="${project}"
* @required
* @readonly
*/
protected MavenProject project;
/**
* Local Repository.
*
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
protected ArtifactRepository localRepository;
/**
* The Maven Settings.
*
* @parameter default-value="${settings}"
* @required
* @readonly
*/
private Settings settings;
...
}
-----
* Create Stubs
You need to create stub objects to run <<<MyMojoTest#testSomething()>>>. By convention, the package name should
reflect the stubs, i.e. in our case <<<org.apache.maven.plugin.my.stubs>>>.
-----
public class MyProjectStub
extends MavenProjectStub
{
/**
* Default constructor
*/
public MyProjectStub()
{
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model;
try
{
model = pomReader.read( ReaderFactory.newXmlReader( new File( getBasedir(), "pom.xml" ) ) );
setModel( model );
}
catch ( Exception e )
{
throw new RuntimeException( e );
}
setGroupId( model.getGroupId() );
setArtifactId( model.getArtifactId() );
setVersion( model.getVersion() );
setName( model.getName() );
setUrl( model.getUrl() );
setPackaging( model.getPackaging() );
Build build = new Build();
build.setFinalName( model.getArtifactId() );
build.setDirectory( getBasedir() + "/target" );
build.setSourceDirectory( getBasedir() + "/src/main/java" );
build.setOutputDirectory( getBasedir() + "/target/classes" );
build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
build.setTestOutputDirectory( getBasedir() + "/target/test-classes" );
setBuild( build );
List compileSourceRoots = new ArrayList();
compileSourceRoots.add( getBasedir() + "/src/main/java" );
setCompileSourceRoots( compileSourceRoots );
List testCompileSourceRoots = new ArrayList();
testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
setTestCompileSourceRoots( testCompileSourceRoots );
}
/** {@inheritDoc} */
public File getBasedir()
{
return new File( super.getBasedir() + "/src/test/resources/unit/project-to-test/" );
}
}
-----
-----
public class SettingsStub
extends Settings
{
/** {@inheritDoc} */
public List getProxies()
{
return Collections.EMPTY_LIST;
}
}
-----
* Configure <<<project-to-test>>> pom
-----
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-my-plugin</artifactId>
<configuration>
<!-- Specify where this pom will output files -->
<outputDirectory>target/test-harness/project-to-test</outputDirectory>
<!-- By default <<<${basedir}/target/local-repo", where basedir refers
to the basedir of maven-my-plugin. -->
<localRepository>${localRepository}</localRepository>
<!-- The defined stubs -->
<project implementation="org.apache.maven.plugin.my.stubs.MyProjectStub"/>
<settings implementation="org.apache.maven.plugin.my.stubs.SettingsStub"/>
</configuration>
</plugin>
</plugins>
</build>
</project>
-----

View File

@ -1,123 +0,0 @@
------
Testing Multiproject
------
Vincent Siveton
------
February 2008
------
~~ 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.
Testing Multiproject
<<Note>>: This example improves the {{{../getting-started/index.html}cookbook}} for multi-project testing.
Your Mojo should have <<<@aggregator>>> parameter, i.e.:
------
/**
* @goal touch
* @aggregator
*/
public class MyMojo
extends AbstractMojo
{
...
}
------
To test a Mojo in a multiproject area, you need to define several stubs, i.e. for the main test project and its modules.
* Create Stubs
Stub for the main test project:
-----
public class MyProjectStub
extends MavenProjectStub
{
/**
* Default constructor
*/
public MyProjectStub()
{
...
setExecutionRoot( true );
}
/** {@inheritDoc} */
public MavenProject getExecutionProject()
{
return this;
}
}
-----
Stubs for the subprojects:
-----
public class SubProject1Stub
extends MavenProjectStub
{
/**
* Default constructor
*/
public SubProject1Stub()
{
...
}
}
-----
-----
public class SubProject2Stub
extends MavenProjectStub
{
/**
* Default constructor
*/
public SubProject2Stub()
{
...
}
}
-----
* Configure <<<project-to-test>>> pom
-----
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-my-plugin</artifactId>
<configuration>
...
<project implementation="org.apache.maven.plugin.my.stubs.MyProjectStub"/>
<reactorProjects>
<project implementation="org.apache.maven.plugin.my.stubs.SubProject1Stub"/>
<project implementation="org.apache.maven.plugin.my.stubs.SubProject2Stub"/>
</reactorProjects>
</configuration>
</plugin>
</plugins>
</build>
</project>
-----

View File

@ -1,138 +0,0 @@
------
Testing Using Repositories
------
Vincent Siveton
------
February 2008
------
~~ 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.
Testing Using Repositories
<<Note>>: This example improves the {{{../getting-started/index.html}cookbook}} for testing repositories.
When developing a Maven plugin you often need to play with repositories. Suppose that the MyMojo needs
to download artifacts into your local repository, i.e.:
-----
public class MyMojo
extends AbstractMojo
{
/**
* Used for resolving artifacts
*
* @component
*/
private ArtifactResolver resolver;
/**
* Factory for creating artifact objects
*
* @component
*/
private ArtifactFactory factory;
/**
* Local Repository.
*
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
private ArtifactRepository localRepository;
public void execute()
throws MojoExecutionException
{
...
Artifact artifact = factory.createArtifact( "junit", "junit", "3.8.1", "compile", "jar" );
try
{
resolver.resolve( artifact, project.getRemoteArtifactRepositories(), localRepository );
}
catch ( ArtifactResolutionException e )
{
throw new MojoExecutionException( "Unable to resolve artifact:" + artifact, e );
}
catch ( ArtifactNotFoundException e )
{
throw new MojoExecutionException( "Unable to find artifact:" + artifact, e );
}
...
}
}
-----
* Create Stubs
Stub for the test project:
-----
public class MyProjectStub
extends MavenProjectStub
{
/**
* Default constructor
*/
public MyProjectStub()
{
...
}
/** {@inheritDoc} */
public List getRemoteArtifactRepositories()
{
ArtifactRepository repository = new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
new DefaultRepositoryLayout() );
return Collections.singletonList( repository );
}
}
-----
* Configure <<<project-to-test>>> pom
-----
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-my-plugin</artifactId>
<configuration>
<!-- Specify where this pom will output files -->
<outputDirectory>${basedir}/target/test-harness/project-to-test</outputDirectory>
<!-- By default <<<${basedir}/target/local-repo", where basedir refers
to the basedir of maven-my-plugin. -->
<localRepository>${localRepository}</localRepository>
<!-- The defined stub -->
<project implementation="org.apache.maven.plugin.my.stubs.MyProjectStub"/>
</configuration>
</plugin>
</plugins>
</build>
</project>
-----
** Execute test
Calling <<<mvn test>>> will create <<<$\{basedir\}/target/local-repo/junitjunit/3.8.1/junit-3.8.1.jar>>> file.

View File

@ -1,186 +0,0 @@
------
How To Use Maven Plugin Testing Harness
------
Vincent Siveton
------
February 2008
------
~~ 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.
Cookbook: How To Use Maven Plugin Testing Harness?
This guide is intended as a reference for those developing Maven plugins, with self-contained references and
solutions for common testing cases.
* Prerequisites
We assume that you have already created a plugin. In this cookbook, we make reference to <<<MyMojo>>> in
<<<maven-my-plugin>>> which is generated by the Maven Archetype Plugin, i.e.:
-----
mvn archetype:create \
-DgroupId=org.apache.maven.plugin.my \
-DartifactId=maven-my-plugin \
-DarchetypeArtifactId=maven-archetype-mojo
-----
The generated structure should be:
-----
maven-my-plugin
|- pom.xml
+- src/
+- main/
+- java/
+- org/
+- apache/
+- maven/
+- plugin/
+- my/
|- MyMojo.java
-----
* Recipe
** Add <<<maven-plugin-testing-harness>>> dependency
As usual, just add <<<maven-plugin-testing-harness>>> as following in your pom. Be sure to specify <<<test>>> scope.
-----
<project>
...
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<scope>test</scope>
</dependency>
...
</dependencies>
...
</project>
-----
** Create a <<<MyMojoTest>>>
Create a <<<MyMojoTest>>> (by convention) class in <<<src/test/java/org/apache/maven/plugin/my>>> directory.
This class should extend <<<AbstractMojoTestCase>>> from <<<maven-plugin-testing-harness>>>.
-----
public class MyMojoTest
extends AbstractMojoTestCase
{
/** {@inheritDoc} */
protected void setUp()
throws Exception
{
// required
super.setUp();
...
}
/** {@inheritDoc} */
protected void tearDown()
throws Exception
{
// required
super.tearDown();
...
}
/**
* @throws Exception if any
*/
public void testSomething()
throws Exception
{
File pom = getTestFile( "src/test/resources/unit/project-to-test/pom.xml" );
assertNotNull( pom );
assertTrue( pom.exists() );
MyMojo myMojo = (MyMojo) lookupMojo( "touch", pom );
assertNotNull( myMojo );
myMojo.execute();
...
}
}
-----
In this case, <<<testSomething()>>> will test <<<MyMojo>>> against a Maven project called <<<project-to-test>>>.
<<Note>>: By convention, Mojo unit tests should be in the test resources directory.
** Configuring <<<project-to-test>>> pom
Just create a pom as usual. The names for groupId and artifactId don't really matter since this project will not be deployed.
-----
<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.apache.maven.plugin.my.unit</groupId>
<artifactId>project-to-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-my-plugin</artifactId>
<configuration>
<!-- Specify the MyMojo parameter -->
<outputDirectory>target/test-harness/project-to-test</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
-----
** Execute test
As usual, just call:
-----
mvn test
-----
* Resources
[[1]] {{{http://maven.apache.org/guides/plugin/guide-java-plugin-development.html}Guide to Developing Java Plugins}}
[[2]] {{{http://maven.apache.org/guides/mini/guide-configuring-plugins.html}Guide to Configuring Plugins}}
[]

View File

@ -1,46 +0,0 @@
------
Introduction
------
Vincent Siveton
------
February 2008
------
~~ 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.
Maven Plugin Testing Mechanism
The Maven Plugin Testing Harness provides mechanisms to manage tests on Mojos, i.e. by pre-constructing the
{{{http://plexus.codehaus.org}Plexus}} components, providing stub objects for Maven functionality such as projects,
and populating fields from an XML file that resembles the plugin configuration in the POM.
The best way to start is to read the cookbook {{{getting-started/index.html}How to use Maven Plugin Testing Harness}}.
* Examples
The following examples shows how to use the Testing Harness in more advanced usecases:
* {{{examples/complex-mojo-parameters.html}Testing Complex Mojo Parameters}}
* {{{examples/multiproject.html}Testing Multiproject}}
* {{{examples/repositories.html}Testing Using Repositories}}
* {{{examples/artifact.html}Testing Project Artifact}}
[]

View File

@ -1,59 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
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.
-->
<faqs id="FAQ" title="Frequently Asked Questions">
<part id="General">
<faq id="What is a Mojo Testing Harness">
<question>What is a Mojo Testing Harness?</question>
<answer>
<p>
A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment.
A mojo unit test does not attempt to run your plugin in the context of a real Maven build.
Unit tests are designed to be fast.
</p>
<p>
This testing library is <b>NOT</b> designed for integration or functional testing.
</p>
</answer>
</faq>
<faq id="What kinds of unit tests are supported">
<question>What kind of unit tests are supported?</question>
<answer>
<p>
<dl>
<dt>TestCase from JUnit</dt>
<dd>You could use the <a href="http://junit.org/">JUnit framework</a> to test your plugin in
the same way you'd write any other JUnit test cases, i.e. by writing a test class which extends
<i>TestCase</i>.</dd>
<dt>TestCase from Plexus</dt>
<dd>Mojos are written to take specific advantage of the <a href="http://plexus.codehaus.org/">Plexus</a>
container. If you need Plexus container services, you could write your class which extends <i>PlexusTestCase</i>,
instead of <i>TestCase</i>.</dd>
<dt>TestCase from Testing Harness</dt>
<dd>If you need to inject Maven objects into your mojo, you could use the <i>maven-plugin-testing-harness</i>.
The <i>maven-plugin-testing-harness</i> is explicitly intended to test the
<i>org.apache.maven.reporting.AbstractMavenReport#execute()</i> implementation.</dd>
</dl>
</p>
</answer>
</faq>
</part>
</faqs>

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<project name="Maven Plugin Testing Mechanism">
<body>
<menu name="Overview">
<item name="Introduction" href="index.html"/>
<item name="Getting Started" href="/getting-started/index.html"/>
<item name="FAQ" href="/faq.html"/>
</menu>
<menu name="Examples">
<item name="Testing Complex Mojo Parameters" href="/examples/complex-mojo-parameters.html"/>
<item name="Testing Multiproject" href="/examples/multiproject.html"/>
<item name="Testing Repositories" href="/examples/repositories.html"/>
<item name="Testing Project Artifact" href="/examples/artifact.html"/>
</menu>
<menu ref="reports" inherit="bottom" />
</body>
</project>

View File

@ -1,43 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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.IOException;
import junit.framework.TestCase;
public class ArtifactStubFactoryTest
extends TestCase
{
public void testVersionChecks() throws IOException
{
ArtifactStubFactory factory = new ArtifactStubFactory();
assertTrue(factory.getReleaseArtifact().isRelease());
assertFalse(factory.getReleaseArtifact().isSnapshot());
assertTrue(factory.getSnapshotArtifact().isSnapshot());
assertFalse(factory.getSnapshotArtifact().isRelease());
}
public void testCreateFiles() throws IOException
{
ArtifactStubFactory factory = new ArtifactStubFactory();
assertFalse(factory.isCreateFiles());
}
}

View File

@ -1,64 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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 org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.StringUtils;
/**
* @author Edwin Punzalan
* @version $Id$
*/
public class ExpressionEvaluatorMojo
extends AbstractMojo
{
private String basedir;
private ArtifactRepository localRepository;
private String workdir;
/** {@inheritDoc} */
public void execute()
throws MojoExecutionException, MojoFailureException
{
if ( StringUtils.isEmpty( basedir ) )
{
throw new MojoExecutionException( "basedir was not injected." );
}
if ( localRepository == null )
{
throw new MojoExecutionException( "localRepository was not injected." );
}
if ( StringUtils.isEmpty( workdir ) )
{
throw new MojoExecutionException( "workdir was not injected." );
}
else if ( !workdir.startsWith( basedir ) )
{
throw new MojoExecutionException( "workdir does not start with basedir." );
}
}
}

View File

@ -1,87 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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 org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import java.io.StringReader;
/**
* @author Edwin Punzalan
* @version $Id$
*/
public class ExpressionEvaluatorTest
extends AbstractMojoTestCase
{
private Xpp3Dom pomDom;
private PlexusConfiguration pluginConfiguration;
/** {@inheritDoc} */
protected void setUp()
throws Exception
{
super.setUp();
StringBuffer pom = new StringBuffer();
pom.append( "<project>" ).append( "\n" );
pom.append( " <build>" ).append( "\n" );
pom.append( " <plugins>" ).append( "\n" );
pom.append( " <plugin>" ).append( "\n" );
pom.append( " <artifactId>maven-test-mojo</artifactId>" ).append( "\n" );
pom.append( " <configuration>" ).append( "\n" );
pom.append( " <basedir>${basedir}</basedir>" ).append( "\n" );
pom.append( " <workdir>${basedir}/workDirectory</workdir>" ).append( "\n" );
pom.append( " <localRepository>${localRepository}</localRepository>" ).append( "\n" );
pom.append( " </configuration>" ).append( "\n" );
pom.append( " </plugin>" ).append( "\n" );
pom.append( " </plugins>" ).append( "\n" );
pom.append( " </build>" ).append( "\n" );
pom.append( "</project>" ).append( "\n" );
pomDom = Xpp3DomBuilder.build( new StringReader( pom.toString() ) );
pluginConfiguration = extractPluginConfiguration( "maven-test-mojo", pomDom );
}
/**
* @throws Exception if any
*/
public void testInjection()
throws Exception
{
ExpressionEvaluatorMojo mojo = new ExpressionEvaluatorMojo();
mojo = (ExpressionEvaluatorMojo) configureMojo( mojo, pluginConfiguration );
try
{
mojo.execute();
}
catch ( MojoExecutionException e )
{
fail( e.getMessage() );
}
}
}

View File

@ -1,142 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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 org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import java.io.StringReader;
import java.util.Map;
/**
* @author Jason van Zyl
* @version $Id$
*/
public class MojoTestCaseTest
extends AbstractMojoTestCase
{
private String pom;
private Xpp3Dom pomDom;
private PlexusConfiguration pluginConfiguration;
/** {@inheritDoc} */
protected void setUp()
throws Exception
{
super.setUp();
pom =
"<project>" +
"<build>" +
"<plugins>" +
"<plugin>" +
"<artifactId>maven-simple-plugin</artifactId>" +
"<configuration>" +
"<keyOne>valueOne</keyOne>" +
"<keyTwo>valueTwo</keyTwo>" +
"</configuration>" +
"</plugin>" +
"</plugins>" +
"</build>" +
"</project>";
pomDom = Xpp3DomBuilder.build( new StringReader( pom ) );
pluginConfiguration = extractPluginConfiguration( "maven-simple-plugin", pomDom );
}
/**
* @throws Exception if any
*/
public void testPluginConfigurationExtraction()
throws Exception
{
assertEquals( "valueOne", pluginConfiguration.getChild( "keyOne" ).getValue() );
assertEquals( "valueTwo", pluginConfiguration.getChild( "keyTwo" ).getValue() );
}
/**
* @throws Exception if any
*/
public void testMojoConfiguration()
throws Exception
{
SimpleMojo mojo = new SimpleMojo();
mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
assertEquals( "valueOne", mojo.getKeyOne() );
assertEquals( "valueTwo", mojo.getKeyTwo() );
}
/**
* @throws Exception if any
*/
public void testVariableAccessWithoutGetter()
throws Exception
{
SimpleMojo mojo = new SimpleMojo();
mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
assertEquals( "valueOne", (String)getVariableValueFromObject( mojo, "keyOne" ) );
assertEquals( "valueTwo", (String)getVariableValueFromObject( mojo, "keyTwo" ) );
}
/**
* @throws Exception if any
*/
public void testVariableAccessWithoutGetter2()
throws Exception
{
SimpleMojo mojo = new SimpleMojo();
mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
Map map = getVariablesAndValuesFromObject( mojo );
assertEquals( "valueOne", (String)map.get( "keyOne" ) );
assertEquals( "valueTwo", (String)map.get( "keyTwo" ) );
}
/**
* @throws Exception if any
*/
public void testSettingMojoVariables()
throws Exception
{
SimpleMojo mojo = new SimpleMojo();
mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
setVariableValueToObject( mojo, "keyOne", "myValueOne" );
assertEquals( "myValueOne", (String)getVariableValueFromObject( mojo, "keyOne" ) );
}
}

View File

@ -1,50 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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 org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/**
* @author Jason van Zyl
* @version $Id$
*/
public class SimpleMojo
extends AbstractMojo
{
private String keyOne;
private String keyTwo;
public String getKeyOne()
{
return keyOne;
}
public String getKeyTwo()
{
return keyTwo;
}
public void execute()
throws MojoExecutionException
{
}
}

View File

@ -1,81 +0,0 @@
package org.apache.maven.plugin.testing;
/*
* 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 junit.framework.TestCase;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.logging.Logger;
public class TestSilentLog
extends TestCase
{
public void testLog()
{
Log log = new SilentLog();
String text = new String( "Text" );
Throwable e = new RuntimeException();
log.debug( text );
log.debug( text, e );
log.debug( e );
log.info( text );
log.info( text, e );
log.info( e );
log.warn( text );
log.warn( text, e );
log.warn( e );
log.error( text );
log.error( text, e );
log.error( e );
log.isDebugEnabled();
log.isErrorEnabled();
log.isWarnEnabled();
log.isInfoEnabled();
}
public void testLogger()
{
Logger log = new SilentLog();
String text = new String( "Text" );
Throwable e = new RuntimeException();
log.debug( text );
log.debug( text, e );
log.error( text );
log.error( text, e );
log.warn( text );
log.warn( text, e );
log.info( text );
log.info( text, e );
log.fatalError( text );
log.fatalError( text, e );
log.getChildLogger( text );
log.getName();
log.getThreshold();
log.isDebugEnabled();
log.isErrorEnabled();
log.isFatalErrorEnabled();
log.isInfoEnabled();
log.isWarnEnabled();
}
}