move the plugin testing harness
git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@589478 13f79535-47bb-0310-9956-ffa450edef68master
parent
dd5a51c6f5
commit
c0f7a59cfa
|
|
@ -0,0 +1,95 @@
|
|||
<?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.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>maven-plugin-testing-harness</artifactId>
|
||||
<name>Maven Plugin Testing Mechanism</name>
|
||||
<dependencies>
|
||||
<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>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-utils</artifactId>
|
||||
<version>1.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-archiver</artifactId>
|
||||
<version>1.0-alpha-7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jxr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration>
|
||||
<links>
|
||||
<link>http://java.sun.com/j2se/1.4.2/docs/api/</link>
|
||||
<link>http://maven.apache.org/ref/current/maven-project/apidocs/</link>
|
||||
<link>http://maven.apache.org/ref/current/maven-plugin-api/apidocs/</link>
|
||||
<link>http://maven.apache.org/ref/current/maven-artifact/apidocs/</link>
|
||||
<link>http://plexus.codehaus.org/plexus-utils/apidocs/</link>
|
||||
<link>http://www.junit.org/junit/javadoc/</link>
|
||||
</links>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
<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>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,456 @@
|
|||
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.ReflectionUtils;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
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: standarize 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( new FileReader( 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( new FileReader( 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 = new FileReader( 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 + "." );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* convience 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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* convience 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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* convience 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* convience 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 );
|
||||
}
|
||||
else
|
||||
{
|
||||
return elementDom.getValue();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception( "unable to determine " + element );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception( "container is null, make sure super.setUp() is called" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,435 @@
|
|||
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>
|
||||
*
|
||||
*/
|
||||
public class ArtifactStubFactory
|
||||
{
|
||||
File workingDir;
|
||||
|
||||
boolean createFiles;
|
||||
|
||||
File srcFile;
|
||||
|
||||
boolean createUnpackableFile;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public Artifact createArtifact( String groupId, String artifactId, String version )
|
||||
throws IOException
|
||||
{
|
||||
return createArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, "jar", "" );
|
||||
}
|
||||
|
||||
public Artifact createArtifact( String groupId, String artifactId, String version, String scope )
|
||||
throws IOException
|
||||
{
|
||||
return createArtifact( groupId, artifactId, version, scope, "jar", "" );
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
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 );
|
||||
if ( createFiles )
|
||||
{
|
||||
setArtifactFile( artifact );
|
||||
}
|
||||
return artifact;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a file that can be copied or unpacked based on the passed in
|
||||
* artifact
|
||||
*/
|
||||
public void setArtifactFile( Artifact artifact )
|
||||
throws IOException
|
||||
{
|
||||
if (this.workingDir == null )
|
||||
{
|
||||
throw new IllegalArgumentException("The workingDir must be set if createFiles is true.");
|
||||
}
|
||||
|
||||
String fileName = getFormattedFileName( artifact, false );
|
||||
|
||||
File theFile = new File( this.workingDir, fileName );
|
||||
theFile.getParentFile().mkdirs();
|
||||
|
||||
if ( srcFile == null )
|
||||
{
|
||||
theFile.createNewFile();
|
||||
}
|
||||
else if ( createUnpackableFile )
|
||||
{
|
||||
try
|
||||
{
|
||||
createUnpackableFile( artifact, theFile );
|
||||
}
|
||||
catch ( NoSuchArchiverException e )
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( ArchiverException e )
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FileUtils.copyFile( srcFile, theFile );
|
||||
}
|
||||
|
||||
artifact.setFile( theFile );
|
||||
}
|
||||
|
||||
static public String getUnpackableFileName( Artifact artifact )
|
||||
{
|
||||
return "" + artifact.getGroupId() + "-" + artifact.getArtifactId() + "-" + artifact.getVersion() + "-"
|
||||
+ artifact.getClassifier() + "-" + artifact.getType() + ".txt";
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public Artifact getReleaseArtifact()
|
||||
throws IOException
|
||||
{
|
||||
return createArtifact( "testGroupId", "release", "1.0" );
|
||||
}
|
||||
|
||||
public Artifact getSnapshotArtifact()
|
||||
throws IOException
|
||||
{
|
||||
return createArtifact( "testGroupId", "snapshot", "2.0-SNAPSHOT" );
|
||||
}
|
||||
|
||||
public Set getReleaseAndSnapshotArtifacts()
|
||||
throws IOException
|
||||
{
|
||||
Set set = new HashSet();
|
||||
set.add( getReleaseArtifact() );
|
||||
set.add( getSnapshotArtifact() );
|
||||
return set;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* convience 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
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
|
||||
{
|
||||
public ConfigurationException( String message )
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ConfigurationException( Throwable cause )
|
||||
{
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ConfigurationException( String message, Throwable cause )
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
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
|
||||
{
|
||||
/**
|
||||
* @see org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator#evaluate(java.lang.String)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator#alignToBaseDirectory(java.io.File)
|
||||
*/
|
||||
public File alignToBaseDirectory( File file )
|
||||
{
|
||||
if ( file.getAbsolutePath().startsWith( PlexusTestCase.getBasedir() ) )
|
||||
{
|
||||
return file;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new File( PlexusTestCase.getBasedir() + File.pathSeparator + file.getPath() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
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: SilentLog.java 546355 2007-06-12 02:00:02Z brianf $
|
||||
*/
|
||||
public class SilentLog
|
||||
implements Log, Logger
|
||||
{
|
||||
|
||||
public boolean isDebugEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void debug( CharSequence content )
|
||||
{
|
||||
}
|
||||
|
||||
public void debug( CharSequence content, Throwable error )
|
||||
{
|
||||
}
|
||||
|
||||
public void debug( Throwable error )
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isInfoEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void info( CharSequence content )
|
||||
{
|
||||
}
|
||||
|
||||
public void info( CharSequence content, Throwable error )
|
||||
{
|
||||
}
|
||||
|
||||
public void info( Throwable error )
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isWarnEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void warn( CharSequence content )
|
||||
{
|
||||
}
|
||||
|
||||
public void warn( CharSequence content, Throwable error )
|
||||
{
|
||||
}
|
||||
|
||||
public void warn( Throwable error )
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void error( CharSequence content )
|
||||
{
|
||||
}
|
||||
|
||||
public void error( CharSequence content, Throwable error )
|
||||
{
|
||||
}
|
||||
|
||||
public void error( Throwable error )
|
||||
{
|
||||
}
|
||||
|
||||
public void debug( String message )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void debug( String message, Throwable throwable )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void info( String message )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void info( String message, Throwable throwable )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void warn( String message )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void warn( String message, Throwable throwable )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void error( String message )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void error( String message, Throwable throwable )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void fatalError( String message )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void fatalError( String message, Throwable throwable )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public boolean isFatalErrorEnabled()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public Logger getChildLogger( String name )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getThreshold()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.codehaus.plexus.logging.Logger#setThreshold(int)
|
||||
*/
|
||||
public void setThreshold( int theThreshold )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,550 @@
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#getGroupId()
|
||||
*/
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#getArtifactId()
|
||||
*/
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#getVersion()
|
||||
*/
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#setVersion(java.lang.String)
|
||||
*/
|
||||
public void setVersion( String version )
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#getScope()
|
||||
*/
|
||||
public String getScope()
|
||||
{
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#getType()
|
||||
*/
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new type
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public void setType( String type )
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#getClassifier()
|
||||
*/
|
||||
public String getClassifier()
|
||||
{
|
||||
return classifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#hasClassifier()
|
||||
*/
|
||||
public boolean hasClassifier()
|
||||
{
|
||||
return classifier != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#getFile()
|
||||
*/
|
||||
public File getFile()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#setFile(java.io.File)
|
||||
*/
|
||||
public void setFile( File file )
|
||||
{
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, return <code>null</code>.
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#getId()
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, return <code>null</code>.
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#getMetadataList()
|
||||
*/
|
||||
public Collection getMetadataList()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new artifact repository
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#setRepository(org.apache.maven.artifact.repository.ArtifactRepository)
|
||||
*/
|
||||
public void setRepository( ArtifactRepository artifactRepository )
|
||||
{
|
||||
this.artifactRepository = artifactRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns repository for artifact
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#getRepository()
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, return <code>null</code>.
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#getArtifactHandler()
|
||||
*/
|
||||
public ArtifactHandler getArtifactHandler()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#setScope(java.lang.String)
|
||||
*/
|
||||
public void setScope( String scope )
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#setGroupId(java.lang.String)
|
||||
*/
|
||||
public void setGroupId( String groupId )
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.artifact.Artifact#setArtifactId(java.lang.String)
|
||||
*/
|
||||
public void setArtifactId( String artifactId )
|
||||
{
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, return <code>false</code>.
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#isSnapshot()
|
||||
*/
|
||||
public boolean isSnapshot()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, do nothing.
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#setResolved(boolean)
|
||||
*/
|
||||
public void setResolved( boolean b )
|
||||
{
|
||||
// nop
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, return <code>false</code>.
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#isRelease()
|
||||
*/
|
||||
public boolean isRelease()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, do nothing.
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#setRelease(boolean)
|
||||
*/
|
||||
public void setRelease( boolean b )
|
||||
{
|
||||
// nop
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, return <code>null</code>.
|
||||
*
|
||||
* @see org.apache.maven.artifact.Artifact#getSelectedVersion()
|
||||
*/
|
||||
public ArtifactVersion getSelectedVersion()
|
||||
throws OverConstrainedVersionException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, 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() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,192 @@
|
|||
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>
|
||||
*
|
||||
*/
|
||||
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;
|
||||
|
||||
public DefaultArtifactHandlerStub( String t, String c )
|
||||
{
|
||||
type = t;
|
||||
classifier = c;
|
||||
if ( t.equals( "test-jar" ) )
|
||||
{
|
||||
extension = "jar";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DefaultArtifactHandlerStub( String type )
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getExtension()
|
||||
{
|
||||
if ( extension == null )
|
||||
{
|
||||
extension = type;
|
||||
}
|
||||
return extension;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getClassifier()
|
||||
{
|
||||
return classifier;
|
||||
}
|
||||
|
||||
public String getDirectory()
|
||||
{
|
||||
if ( directory == null )
|
||||
{
|
||||
directory = getPackaging() + "s";
|
||||
}
|
||||
return directory;
|
||||
}
|
||||
|
||||
public String getPackaging()
|
||||
{
|
||||
if ( packaging == null )
|
||||
{
|
||||
packaging = type;
|
||||
}
|
||||
return packaging;
|
||||
}
|
||||
|
||||
public boolean isIncludesDependencies()
|
||||
{
|
||||
return includesDependencies;
|
||||
}
|
||||
|
||||
public String getLanguage()
|
||||
{
|
||||
if ( language == null )
|
||||
{
|
||||
language = "none";
|
||||
}
|
||||
|
||||
return language;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,113 @@
|
|||
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>
|
||||
*
|
||||
*/
|
||||
public class StubArtifactCollector
|
||||
implements ArtifactCollector
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StubArtifactCollector()
|
||||
{
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.maven.artifact.resolver.ArtifactCollector#collect(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,
|
||||
* java.util.List)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.apache.maven.artifact.resolver.ArtifactCollector#collect(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 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
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>
|
||||
*
|
||||
*/
|
||||
public class StubArtifactRepository
|
||||
implements ArtifactRepository
|
||||
{
|
||||
String baseDir = null;
|
||||
|
||||
public StubArtifactRepository( String dir )
|
||||
{
|
||||
baseDir = dir;
|
||||
}
|
||||
|
||||
public String pathOf( Artifact artifact )
|
||||
{
|
||||
return artifact.getId();
|
||||
}
|
||||
|
||||
public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
|
||||
{
|
||||
return metadata.getLocalFilename( repository );
|
||||
}
|
||||
|
||||
public String getUrl()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getBasedir()
|
||||
{
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
public String getProtocol()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArtifactRepositoryPolicy getSnapshots()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArtifactRepositoryPolicy getReleases()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArtifactRepositoryLayout getLayout()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isUniqueVersion()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setBlacklisted( boolean blackListed )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public boolean isBlacklisted()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
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>
|
||||
*
|
||||
*/
|
||||
public class StubArtifactResolver
|
||||
implements ArtifactResolver
|
||||
{
|
||||
|
||||
boolean throwArtifactResolutionException;
|
||||
|
||||
boolean throwArtifactNotFoundException;
|
||||
|
||||
ArtifactStubFactory factory;
|
||||
|
||||
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
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @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 );
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( throwArtifactResolutionException )
|
||||
{
|
||||
throw new ArtifactResolutionException( "Catch!", artifact );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArtifactNotFoundException( "Catch!", artifact );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
||||
List remoteRepositories, ArtifactRepository localRepository,
|
||||
ArtifactMetadataSource source )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
||||
List remoteRepositories, ArtifactRepository localRepository,
|
||||
ArtifactMetadataSource source, List listeners )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
||||
ArtifactRepository localRepository, List remoteRepositories,
|
||||
ArtifactMetadataSource source, ArtifactFilter filter )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
||||
Map managedVersions, ArtifactRepository localRepository,
|
||||
List remoteRepositories, ArtifactMetadataSource source )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
||||
Map managedVersions, ArtifactRepository localRepository,
|
||||
List remoteRepositories, ArtifactMetadataSource source,
|
||||
ArtifactFilter filter )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
||||
Map managedVersions, ArtifactRepository localRepository,
|
||||
List remoteRepositories, ArtifactMetadataSource source,
|
||||
ArtifactFilter filter, List listeners )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public void resolveAlways( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<!--
|
||||
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>
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
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;
|
||||
|
||||
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." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
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;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
public void testInjection()
|
||||
throws Exception
|
||||
{
|
||||
ExpressionEvaluatorMojo mojo = new ExpressionEvaluatorMojo();
|
||||
|
||||
mojo = (ExpressionEvaluatorMojo) configureMojo( mojo, pluginConfiguration );
|
||||
|
||||
try
|
||||
{
|
||||
mojo.execute();
|
||||
}
|
||||
catch ( MojoExecutionException e )
|
||||
{
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
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;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
public void testPluginConfigurationExtraction()
|
||||
throws Exception
|
||||
{
|
||||
assertEquals( "valueOne", pluginConfiguration.getChild( "keyOne" ).getValue() );
|
||||
|
||||
assertEquals( "valueTwo", pluginConfiguration.getChild( "keyTwo" ).getValue() );
|
||||
}
|
||||
|
||||
public void testMojoConfiguration()
|
||||
throws Exception
|
||||
{
|
||||
SimpleMojo mojo = new SimpleMojo();
|
||||
|
||||
mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
|
||||
|
||||
assertEquals( "valueOne", mojo.getKeyOne() );
|
||||
|
||||
assertEquals( "valueTwo", mojo.getKeyTwo() );
|
||||
}
|
||||
|
||||
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" ) );
|
||||
}
|
||||
|
||||
|
||||
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" ) );
|
||||
}
|
||||
|
||||
|
||||
public void testSettingMojoVariables()
|
||||
throws Exception
|
||||
{
|
||||
SimpleMojo mojo = new SimpleMojo();
|
||||
|
||||
mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
|
||||
|
||||
setVariableValueToObject( mojo, "keyOne", "myValueOne" );
|
||||
|
||||
assertEquals( "myValueOne", (String)getVariableValueFromObject( mojo, "keyOne" ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
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
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue