diff --git a/maven-plugin-testing-harness/pom.xml b/maven-plugin-testing-harness/pom.xml deleted file mode 100644 index 25b2fbb..0000000 --- a/maven-plugin-testing-harness/pom.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - 4.0.0 - - - org.apache.maven - maven-plugin-tools - 2.2-SNAPSHOT - - - org.apache.maven.shared - maven-plugin-testing-harness - 1.2-SNAPSHOT - Maven Plugin Testing Mechanism - The Maven Plugin Testing Harness provides mechanisms to manage tests on Mojo. - - - - - org.apache.maven - maven-project - 2.0 - - - org.apache.maven - maven-core - 2.0 - - - org.apache.maven - maven-model - 2.0 - - - org.apache.maven - maven-artifact - 2.0 - - - org.apache.maven - maven-artifact-manager - 2.0 - - - org.apache.maven - maven-plugin-api - 2.0 - - - - - org.codehaus.plexus - plexus-utils - - - org.codehaus.plexus - plexus-archiver - 1.0-alpha-7 - - - - - - - maven-source-plugin - - true - - - - - jar - - - - - - - - - scm:svn:http://svn.apache.org/repos/asf/maven/plugin-tools/trunk/maven-plugin-testing-harness/ - scm:svn:https://svn.apache.org/repos/asf/maven/plugin-tools/trunk/maven-plugin-testing-harness/ - http://svn.apache.org/viewcvs.cgi/maven/plugin-tools/trunk/maven-plugin-testing-harness/ - - diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java deleted file mode 100644 index 93c0acc..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java +++ /dev/null @@ -1,455 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.monitor.logging.DefaultLog; -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.logging.Log; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.component.configurator.ComponentConfigurator; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.ReflectionUtils; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.Xpp3DomBuilder; - -import java.io.File; -import java.io.Reader; -import java.util.Map; -import java.util.HashMap; -import java.lang.reflect.Field; -import java.lang.reflect.AccessibleObject; - -/** - * TODO: add a way to use the plugin POM for the lookup so that the user doesn't have to provide the a:g:v:goal - * as the role hint for the mojo lookup. - * TODO: standardize the execution of the mojo and looking at the results, but could simply have a template method - * for verifying the state of the mojo post execution - * TODO: need a way to look at the state of the mojo without adding getters, this could be where we finally specify - * the expressions which extract values from the mojo. - * TODO: create a standard directory structure for picking up POMs to make this even easier, we really just need a testing - * descriptor and make this entirely declarative! - * - * @author jesse - * @version $Id$ - */ -public abstract class AbstractMojoTestCase - extends PlexusTestCase -{ - private ComponentConfigurator configurator; - - /* - * for the harness I think we have decided against going the route of using the maven project builder. - * instead I think we are going to try and make an instance of the localrespository and assign that - * to either the project stub or into the mojo directly with injection...not sure yet though. - */ - //private MavenProjectBuilder projectBuilder; - protected void setUp() - throws Exception - { - super.setUp(); - - configurator = (ComponentConfigurator) getContainer().lookup( ComponentConfigurator.ROLE, "basic" ); - - //projectBuilder = (MavenProjectBuilder) getContainer().lookup( MavenProjectBuilder.ROLE ); - } - - /** - * Lookup the mojo leveraging the subproject pom - * - * @param goal - * @param pluginPom - * @return a Mojo instance - * @throws Exception - */ - protected Mojo lookupMojo( String goal, String pluginPom ) - throws Exception - { - return lookupMojo( goal, new File( pluginPom ) ); - } - - /** - * Lookup an empty mojo - * - * @param goal - * @param pluginPom - * @return a Mojo instance - * @throws Exception - */ - protected Mojo lookupEmptyMojo( String goal, String pluginPom ) - throws Exception - { - return lookupEmptyMojo( goal, new File( pluginPom ) ); - } - - /** - * Lookup the mojo leveraging the actual subprojects pom - * - * @param goal - * @param pom - * @return a Mojo instance - * @throws Exception - */ - protected Mojo lookupMojo( String goal, File pom ) - throws Exception - { - File pluginPom = new File( getBasedir(), "pom.xml" ); - - Xpp3Dom pluginPomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( pluginPom ) ); - - String artifactId = pluginPomDom.getChild( "artifactId" ).getValue(); - - String groupId = resolveFromRootThenParent( pluginPomDom, "groupId" ); - - String version = resolveFromRootThenParent( pluginPomDom, "version" ); - - PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom ); - - return lookupMojo( groupId, artifactId, version, goal, pluginConfiguration ); - } - - /** - * Lookup the mojo leveraging the actual subprojects pom - * - * @param goal - * @param pom - * @return a Mojo instance - * @throws Exception - */ - protected Mojo lookupEmptyMojo( String goal, File pom ) - throws Exception - { - File pluginPom = new File( getBasedir(), "pom.xml" ); - - Xpp3Dom pluginPomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( pluginPom ) ); - - String artifactId = pluginPomDom.getChild( "artifactId" ).getValue(); - - String groupId = resolveFromRootThenParent( pluginPomDom, "groupId" ); - - String version = resolveFromRootThenParent( pluginPomDom, "version" ); - - return lookupMojo( groupId, artifactId, version, goal, null ); - } - - /* - protected Mojo lookupMojo( String groupId, String artifactId, String version, String goal, File pom ) - throws Exception - { - PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom ); - - return lookupMojo( groupId, artifactId, version, goal, pluginConfiguration ); - } - */ - /** - * lookup the mojo while we have all of the relavent information - * - * @param groupId - * @param artifactId - * @param version - * @param goal - * @param pluginConfiguration - * @return a Mojo instance - * @throws Exception - */ - protected Mojo lookupMojo( String groupId, String artifactId, String version, String goal, - PlexusConfiguration pluginConfiguration ) - throws Exception - { - validateContainerStatus(); - - // pluginkey = groupId : artifactId : version : goal - - Mojo mojo = (Mojo) lookup( Mojo.ROLE, groupId + ":" + artifactId + ":" + version + ":" + goal ); - - Log mojoLogger = new DefaultLog( container.getLoggerManager().getLoggerForComponent( Mojo.ROLE ) ); - - mojo.setLog( mojoLogger ); - - if ( pluginConfiguration != null ) - { - /* requires v10 of plexus container for lookup on expression evaluator - ExpressionEvaluator evaluator = (ExpressionEvaluator) getContainer().lookup( ExpressionEvaluator.ROLE, - "stub-evaluator" ); - */ - ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub(); - - configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() ); - } - - return mojo; - } - - /** - * @param artifactId - * @param pom - * @return the plexus configuration - * @throws Exception - */ - protected PlexusConfiguration extractPluginConfiguration( String artifactId, File pom ) - throws Exception - { - Reader reader = ReaderFactory.newXmlReader( pom ); - - Xpp3Dom pomDom = Xpp3DomBuilder.build( reader ); - - return extractPluginConfiguration( artifactId, pomDom ); - } - - /** - * @param artifactId - * @param pomDom - * @return the plexus configuration - * @throws Exception - */ - protected PlexusConfiguration extractPluginConfiguration( String artifactId, Xpp3Dom pomDom ) - throws Exception - { - Xpp3Dom pluginConfigurationElement = null; - - Xpp3Dom buildElement = pomDom.getChild( "build" ); - if ( buildElement != null ) - { - Xpp3Dom pluginsRootElement = buildElement.getChild( "plugins" ); - - if ( pluginsRootElement != null ) - { - Xpp3Dom[] pluginElements = pluginsRootElement.getChildren(); - - for ( int i = 0; i < pluginElements.length; i++ ) - { - Xpp3Dom pluginElement = pluginElements[i]; - - String pluginElementArtifactId = pluginElement.getChild( "artifactId" ).getValue(); - - if ( pluginElementArtifactId.equals( artifactId ) ) - { - pluginConfigurationElement = pluginElement.getChild( "configuration" ); - - break; - } - } - - if ( pluginConfigurationElement == null ) - { - throw new ConfigurationException( "Cannot find a configuration element for a plugin with an artifactId of " + artifactId + "." ); - } - } - } - - if ( pluginConfigurationElement == null ) - { - throw new ConfigurationException( "Cannot find a configuration element for a plugin with an artifactId of " - + artifactId + "." ); - } - - return new XmlPlexusConfiguration( pluginConfigurationElement ); - } - - /** - * Configure the mojo - * - * @param mojo - * @param artifactId - * @param pom - * @return a Mojo instance - * @throws Exception - */ - protected Mojo configureMojo( Mojo mojo, String artifactId, File pom ) - throws Exception - { - validateContainerStatus(); - - PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom ); - - ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub(); - - configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() ); - - return mojo; - } - - /** - * Configure the mojo with the given plexus configuration - * - * @param mojo - * @param pluginConfiguration - * @return a Mojo instance - * @throws Exception - */ - protected Mojo configureMojo( Mojo mojo, PlexusConfiguration pluginConfiguration ) - throws Exception - { - validateContainerStatus(); - - ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub(); - - configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() ); - - return mojo; - } - - /** - * Convenience method to obtain the value of a variable on a mojo that might not have a getter. - * - * NOTE: the caller is responsible for casting to to what the desired type is. - * - * @param object - * @param variable - * @return object value of variable - * @throws IllegalArgumentException - */ - protected Object getVariableValueFromObject( Object object, String variable ) - throws IllegalAccessException - { - Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() ); - - field.setAccessible( true ); - - return field.get( object ); - } - - /** - * Convenience method to obtain all variables and values from the mojo (including its superclasses) - * - * Note: the values in the map are of type Object so the caller is responsible for casting to desired types. - * - * @param object - * @return map of variable names and values - */ - protected Map getVariablesAndValuesFromObject( Object object ) - throws IllegalAccessException - { - return getVariablesAndValuesFromObject( object.getClass(), object ); - } - - /** - * Convenience method to obtain all variables and values from the mojo (including its superclasses) - * - * Note: the values in the map are of type Object so the caller is responsible for casting to desired types. - * - * @param clazz - * @param object - * @return map of variable names and values - */ - protected Map getVariablesAndValuesFromObject( Class clazz, Object object ) - throws IllegalAccessException - { - Map map = new HashMap(); - - Field[] fields = clazz.getDeclaredFields(); - - AccessibleObject.setAccessible( fields, true ); - - for ( int i = 0; i < fields.length; ++i ) - { - Field field = fields[i]; - - map.put( field.getName(), field.get( object ) ); - - } - - Class superclass = clazz.getSuperclass(); - - if ( !Object.class.equals( superclass ) ) - { - map.putAll( getVariablesAndValuesFromObject( superclass, object ) ); - } - - return map; - } - - /** - * Convenience method to set values to variables in objects that don't have setters - * - * @param object - * @param variable - * @param value - * @throws IllegalAccessException - */ - protected void setVariableValueToObject( Object object, String variable, Object value ) - throws IllegalAccessException - { - Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() ); - - field.setAccessible( true ); - - field.set( object, value ); - } - - /** - * sometimes the parent element might contain the correct value so generalize that access - * - * TODO find out where this is probably done elsewhere - * - * @param pluginPomDom - * @param element - * @return - * @throws Exception - */ - private String resolveFromRootThenParent( Xpp3Dom pluginPomDom, String element ) - throws Exception - { - Xpp3Dom elementDom = pluginPomDom.getChild( element ); - - // parent might have the group Id so resolve it - if ( elementDom == null ) - { - Xpp3Dom pluginParentDom = pluginPomDom.getChild( "parent" ); - - if ( pluginParentDom != null ) - { - elementDom = pluginParentDom.getChild( element ); - - if ( elementDom == null ) - { - throw new Exception( "unable to determine " + element ); - } - - return elementDom.getValue(); - } - - throw new Exception( "unable to determine " + element ); - } - - return elementDom.getValue(); - } - - /** - * We should make sure this is called in each method that makes use of the container, - * otherwise we throw ugly NPE's - * - * crops up when the subclassing code defines the setUp method but doesn't call super.setUp() - * - * @throws Exception - */ - private void validateContainerStatus() - throws Exception - { - if ( container != null ) - { - return; - } - - throw new Exception( "container is null, make sure super.setUp() is called" ); - } -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java deleted file mode 100644 index ac24987..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java +++ /dev/null @@ -1,587 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.HashSet; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; -import org.codehaus.plexus.archiver.Archiver; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.manager.ArchiverManager; -import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; -import org.codehaus.plexus.archiver.war.WarArchiver; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.ReflectionUtils; -import org.codehaus.plexus.util.StringUtils; - -/** - * This class creates artifacts to be used for testing purposes. It can optionally create actual files on the local disk - * for things like copying. It can create these files as archives with named files inside to be used for testing things - * like unpack. Also provided are some utility methods to quickly get a set of artifacts distinguished by various things - * like group,artifact,type,scope, etc It was originally developed for the dependency plugin, but can be useful in other - * plugins that need to simulate artifacts for unit tests. - * - * @author Brian Fox - * @version $Id$ - */ -public class ArtifactStubFactory -{ - private File workingDir; - - private boolean createFiles; - - private File srcFile; - - private boolean createUnpackableFile; - - private ArchiverManager archiverManager; - - /** - * Default constructor. This should be used only if real files aren't needed...just the artifact objects - */ - public ArtifactStubFactory() - { - this.workingDir = null; - this.createFiles = false; - } - - /** - * This constructor is to be used if files are needed and to set a working dir - * - * @param workingDir - * @param createFiles - */ - public ArtifactStubFactory( File workingDir, boolean createFiles ) - { - this.workingDir = new File( workingDir, "localTestRepo" ); - this.createFiles = createFiles; - } - - /** - * If set, the file will be created as a zip/jar/war with a file inside that can be checked to exist after - * unpacking. - * - * @param archiverManager - */ - public void setUnpackableFile( ArchiverManager archiverManager ) - { - this.createUnpackableFile = true; - this.archiverManager = archiverManager; - } - - /** - * @param groupId - * @param artifactId - * @param version - * @return a DefaultArtifact instance for the given parameters - * @throws IOException if any - * @see #createArtifact(String, String, String, String, String, String) - */ - public Artifact createArtifact( String groupId, String artifactId, String version ) - throws IOException - { - return createArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, "jar", "" ); - } - - /** - * @param groupId - * @param artifactId - * @param version - * @param scope - * @return a DefaultArtifact instance for the given parameters - * @throws IOException if any - * @see #createArtifact(String, String, String, String, String, String) - */ - public Artifact createArtifact( String groupId, String artifactId, String version, String scope ) - throws IOException - { - return createArtifact( groupId, artifactId, version, scope, "jar", "" ); - } - - /** - * @param groupId - * @param artifactId - * @param version - * @param scope - * @param type - * @param classifier - * @return a DefaultArtifact instance for the given parameters - * @throws IOException if any - * @see #createArtifact(String, String, VersionRange, String, String, String, boolean) - */ - public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type, - String classifier ) - throws IOException - { - VersionRange vr = VersionRange.createFromVersion( version ); - return createArtifact( groupId, artifactId, vr, scope, type, classifier, false ); - } - - /** - * @param groupId not null - * @param artifactId not null - * @param versionRange not null - * @param scope not null - * @param type not null - * @param classifier - * @param optional not null - * @return a DefaultArtifact instance - * @throws IOException if any - */ - public Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, - String type, String classifier, boolean optional ) - throws IOException - { - ArtifactHandler ah = new DefaultArtifactHandlerStub( type, classifier ); - - Artifact artifact = - new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, ah, optional ); - - // i have no idea why this needs to be done manually when isSnapshot is able to figure it out. - artifact.setRelease( !artifact.isSnapshot() ); - - if ( createFiles ) - { - setArtifactFile( artifact, this.workingDir, this.srcFile, this.createUnpackableFile ); - } - return artifact; - } - - /** - * Creates a new empty file and attaches it to the artifact. - * - * @param artifact to attach the file to. - * @param workingDir where to locate the new file - * @throws IOException - */ - public void setArtifactFile( Artifact artifact, File workingDir ) - throws IOException - { - setArtifactFile( artifact, workingDir, null, false ); - } - - /** - * Copyies the srcFile to the workingDir and then attaches it to the artifact. If srcFile is null, a new empty file - * will be created. - * - * @param artifact to attach - * @param workingDir where to copy the srcFile. - * @param srcFile file to be attached. - * @throws IOException - */ - public void setArtifactFile( Artifact artifact, File workingDir, File srcFile ) - throws IOException - { - setArtifactFile( artifact, workingDir, srcFile, false ); - } - - /** - * Creates an unpackable file (zip,jar etc) containing an empty file. - * - * @param artifact to attach - * @param workingDir where to create the file. - * @throws IOException - */ - public void setUnpackableArtifactFile( Artifact artifact, File workingDir ) - throws IOException - { - setArtifactFile( artifact, workingDir, null, true ); - } - - /** - * Creates an unpackable file (zip,jar etc) containing the srcFile. If srcFile is null, a new empty file will be - * created. - * - * @param artifact to attach - * @param workingDir where to create the file. - * @param srcFile - * @throws IOException if any - */ - public void setUnpackableArtifactFile( Artifact artifact, File workingDir, File srcFile ) - throws IOException - { - setArtifactFile( artifact, workingDir, srcFile, true ); - } - - /** - * Creates a file that can be copied or unpacked based on the passed in artifact - * - * @param artifact - * @param workingDir - * @param srcFile - * @param createUnpackableFile - * @throws IOException if any - */ - private void setArtifactFile( Artifact artifact, File workingDir, File srcFile, boolean createUnpackableFile ) - throws IOException - { - if ( workingDir == null ) - { - throw new IllegalArgumentException( - "The workingDir must be set." ); - } - - String fileName = getFormattedFileName( artifact, false ); - - File theFile = new File( workingDir, fileName ); - theFile.getParentFile().mkdirs(); - - if ( srcFile == null ) - { - theFile.createNewFile(); - } - else if ( createUnpackableFile ) - { - try - { - createUnpackableFile( artifact, theFile ); - } - catch ( NoSuchArchiverException e ) - { - throw new IOException( "NoSuchArchiverException: " + e.getMessage() ); - } - catch ( ArchiverException e ) - { - throw new IOException( "ArchiverException: " + e.getMessage() ); - } - } - else - { - FileUtils.copyFile( srcFile, theFile ); - } - - artifact.setFile( theFile ); - } - - /** - * @param artifact - * @return - */ - public static String getUnpackableFileName( Artifact artifact ) - { - return "" + artifact.getGroupId() + "-" + artifact.getArtifactId() + "-" + artifact.getVersion() + "-" - + artifact.getClassifier() + "-" + artifact.getType() + ".txt"; - } - - /** - * @param artifact - * @param destFile - * @throws NoSuchArchiverException - * @throws ArchiverException if any - * @throws IOException if any - */ - public void createUnpackableFile( Artifact artifact, File destFile ) - throws NoSuchArchiverException, ArchiverException, IOException - { - Archiver archiver = archiverManager.getArchiver( destFile ); - - archiver.setDestFile( destFile ); - archiver.addFile( srcFile, getUnpackableFileName( artifact ) ); - - try - { - setVariableValueToObject( archiver, "logger", new SilentLog() ); - } - catch ( IllegalAccessException e ) - { - System.out.println( "Unable to override logger with silent log." ); - e.printStackTrace(); - } - if ( archiver instanceof WarArchiver ) - { - WarArchiver war = (WarArchiver) archiver; - // the use of this is counter-intuitive: - // http://jira.codehaus.org/browse/PLX-286 - war.setIgnoreWebxml( false ); - } - archiver.createArchive(); - } - - /** - * @return a DefaultArtifact instance for testGroupId:release:jar:1.0 - * @throws IOException if any - */ - public Artifact getReleaseArtifact() - throws IOException - { - return createArtifact( "testGroupId", "release", "1.0" ); - } - - /** - * @return a default DefaultArtifact instance for testGroupId:snapshot:jar:2.0-SNAPSHOT - * @throws IOException if any - */ - public Artifact getSnapshotArtifact() - throws IOException - { - return createArtifact( "testGroupId", "snapshot", "2.0-SNAPSHOT" ); - } - - /** - * @return a default set of release and snapshot DefaultArtifact, i.e.: - * testGroupId:snapshot:jar:2.0-SNAPSHOT, testGroupId:release:jar:1.0 - * @throws IOException if any - * @see #getReleaseArtifact() - * @see #getSnapshotArtifact() - */ - public Set getReleaseAndSnapshotArtifacts() - throws IOException - { - Set set = new HashSet(); - set.add( getReleaseArtifact() ); - set.add( getSnapshotArtifact() ); - return set; - } - - /** - * @return a default set of DefaultArtifact, i.e.: - * g:provided:jar:1.0, g:compile:jar:1.0, g:system:jar:1.0, g:test:jar:1.0, g:runtime:jar:1.0 - * @throws IOException if any - */ - public Set getScopedArtifacts() - throws IOException - { - Set set = new HashSet(); - set.add( createArtifact( "g", "compile", "1.0", Artifact.SCOPE_COMPILE ) ); - set.add( createArtifact( "g", "provided", "1.0", Artifact.SCOPE_PROVIDED ) ); - set.add( createArtifact( "g", "test", "1.0", Artifact.SCOPE_TEST ) ); - set.add( createArtifact( "g", "runtime", "1.0", Artifact.SCOPE_RUNTIME ) ); - set.add( createArtifact( "g", "system", "1.0", Artifact.SCOPE_SYSTEM ) ); - return set; - } - - /** - * @return a set of DefaultArtifact, i.e.: - * g:d:zip:1.0, g:a:war:1.0, g:b:jar:1.0, g:c:sources:1.0, g:e:rar:1.0 - * @throws IOException if any - */ - public Set getTypedArtifacts() - throws IOException - { - Set set = new HashSet(); - set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "war", null ) ); - set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", null ) ); - set.add( createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE, "sources", null ) ); - set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE, "zip", null ) ); - set.add( createArtifact( "g", "e", "1.0", Artifact.SCOPE_COMPILE, "rar", null ) ); - return set; - } - - /** - * @return a set of DefaultArtifact, i.e.: - * g:c:jar:three:1.0, g:b:jar:two:1.0, g:d:jar:four:1.0, g:a:jar:one:1.0 - * @throws IOException if any - */ - public Set getClassifiedArtifacts() - throws IOException - { - Set set = new HashSet(); - set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "jar", "one" ) ); - set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", "two" ) ); - set.add( createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE, "jar", "three" ) ); - set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE, "jar", "four" ) ); - return set; - } - - /** - * @return a set of DefaultArtifact, i.e.: - * g:d:zip:1.0, g:a:war:1.0, g:b:jar:1.0, g:e:rar:1.0 - * @throws IOException if any - */ - public Set getTypedArchiveArtifacts() - throws IOException - { - Set set = new HashSet(); - set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "war", null ) ); - set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", null ) ); - set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE, "zip", null ) ); - set.add( createArtifact( "g", "e", "1.0", Artifact.SCOPE_COMPILE, "rar", null ) ); - return set; - } - - /** - * @return a set of DefaultArtifact, i.e.: - * g:one:jar:a:1.0, g:two:jar:a:1.0, g:four:jar:a:1.0, g:three:jar:a:1.0 - * @throws IOException if any - */ - public Set getArtifactArtifacts() - throws IOException - { - Set set = new HashSet(); - set.add( createArtifact( "g", "one", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "g", "two", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "g", "three", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "g", "four", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - return set; - } - - /** - * @return a set of DefaultArtifact, i.e.: - * one:group-one:jar:a:1.0, three:group-three:jar:a:1.0, four:group-four:jar:a:1.0, - * two:group-two:jar:a:1.0 - * @throws IOException if any - */ - public Set getGroupIdArtifacts() - throws IOException - { - Set set = new HashSet(); - set.add( createArtifact( "one", "group-one", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "two", "group-two", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "three", "group-three", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "four", "group-four", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - return set; - } - - /** - * @return a set of DefaultArtifact - * @throws IOException if any - * @see #getTypedArtifacts() - * @see #getScopedArtifacts() - * @see #getReleaseAndSnapshotArtifacts() - */ - public Set getMixedArtifacts() - throws IOException - { - Set set = new HashSet(); - set.addAll( getTypedArtifacts() ); - set.addAll( getScopedArtifacts() ); - set.addAll( getReleaseAndSnapshotArtifacts() ); - return set; - } - - /** - * @return Returns the createFiles. - */ - public boolean isCreateFiles() - { - return this.createFiles; - } - - /** - * @param createFiles The createFiles to set. - */ - public void setCreateFiles( boolean createFiles ) - { - this.createFiles = createFiles; - } - - /** - * @return Returns the workingDir. - */ - public File getWorkingDir() - { - return this.workingDir; - } - - /** - * @param workingDir The workingDir to set. - */ - public void setWorkingDir( File workingDir ) - { - this.workingDir = workingDir; - } - - /** - * @return Returns the srcFile. - */ - public File getSrcFile() - { - return this.srcFile; - } - - /** - * @param srcFile The srcFile to set. - */ - public void setSrcFile( File srcFile ) - { - this.srcFile = srcFile; - } - - /** - * Convenience method to set values to variables in objects that don't have setters - * - * @param object - * @param variable - * @param value - * @throws IllegalAccessException - */ - public static void setVariableValueToObject( Object object, String variable, Object value ) - throws IllegalAccessException - { - Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() ); - - field.setAccessible( true ); - - field.set( object, value ); - } - - /** - * Builds the file name. If removeVersion is set, then the file name must be reconstructed from the artifactId, - * Classifier (if used) and Type. Otherwise, this method returns the artifact file name. - * - * @param artifact File to be formatted. - * @param removeVersion Specifies if the version should be removed from the file name. - * @return Formatted file name in the format artifactId-[version]-[classifier].[type] - */ - public static String getFormattedFileName( Artifact artifact, boolean removeVersion ) - { - String destFileName = null; - - // if there is a file and we aren't stripping the version, just get the - // name directly - if ( artifact.getFile() != null && !removeVersion ) - { - destFileName = artifact.getFile().getName(); - } - else - // if offline - { - String versionString = null; - if ( !removeVersion ) - { - versionString = "-" + artifact.getVersion(); - } - else - { - versionString = ""; - } - - String classifierString = ""; - - if ( StringUtils.isNotEmpty( artifact.getClassifier() ) ) - { - classifierString = "-" + artifact.getClassifier(); - } - - destFileName = artifact.getArtifactId() + versionString + classifierString + "." - + artifact.getArtifactHandler().getExtension(); - } - return destFileName; - } - -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfigurationException.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfigurationException.java deleted file mode 100644 index 3b85c8f..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfigurationException.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * ConfigurationException - * - * @author jesse - * @version $Id$ - */ -public class ConfigurationException - extends Exception -{ - /** serialVersionUID */ - static final long serialVersionUID = -6180939638742159065L; - - /** - * @param message The detailed message. - */ - public ConfigurationException( String message ) - { - super( message ); - } - - /** - * @param cause The detailed cause. - */ - public ConfigurationException( Throwable cause ) - { - super( cause ); - } - - /** - * @param message The detailed message. - * @param cause The detailed cause. - */ - public ConfigurationException( String message, Throwable cause ) - { - super( message, cause ); - } -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java deleted file mode 100644 index 623d614..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.File; - -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; - -/** - * Stub for {@link ExpressionEvaluator} - * - * @author jesse - * @version $Id$ - */ -public class ResolverExpressionEvaluatorStub - implements ExpressionEvaluator -{ - /** {@inheritDoc} */ - public Object evaluate( String expr ) - throws ExpressionEvaluationException - { - - Object value = null; - - if ( expr == null ) - { - return null; - } - - String expression = stripTokens( expr ); - - if ( expression.equals( expr ) ) - { - int index = expr.indexOf( "${" ); - if ( index >= 0 ) - { - int lastIndex = expr.indexOf( "}", index ); - if ( lastIndex >= 0 ) - { - String retVal = expr.substring( 0, index ); - - if ( index > 0 && expr.charAt( index - 1 ) == '$' ) - { - retVal += expr.substring( index + 1, lastIndex + 1 ); - } - else - { - retVal += evaluate( expr.substring( index, lastIndex + 1 ) ); - } - - retVal += evaluate( expr.substring( lastIndex + 1 ) ); - return retVal; - } - } - - // Was not an expression - if ( expression.indexOf( "$$" ) > -1 ) - { - return expression.replaceAll( "\\$\\$", "\\$" ); - } - } - - if ( "basedir".equals( expression ) ) - { - return PlexusTestCase.getBasedir(); - } - else if ( expression.startsWith( "basedir" ) ) - { - int pathSeparator = expression.indexOf( "/" ); - - if ( pathSeparator > 0 ) - { - value = PlexusTestCase.getBasedir() + expression.substring( pathSeparator ); - } - else - { - System.out.println( "Got expression '" + expression + "' that was not recognised" ); - } - return value; - } - else if ( "localRepository".equals( expression ) ) - { - File localRepo = new File( PlexusTestCase.getBasedir(), "target/local-repo" ); - return new DefaultArtifactRepository( "localRepository", "file://" + localRepo.getAbsolutePath(), - new DefaultRepositoryLayout() ); - } - else - { - return expr; - } - } - - private String stripTokens( String expr ) - { - if ( expr.startsWith( "${" ) && expr.indexOf( "}" ) == expr.length() - 1 ) - { - expr = expr.substring( 2, expr.length() - 1 ); - } - - return expr; - } - - /** {@inheritDoc} */ - public File alignToBaseDirectory( File file ) - { - if ( file.getAbsolutePath().startsWith( PlexusTestCase.getBasedir() ) ) - { - return file; - } - else if ( file.isAbsolute() ) - { - return file; - } - else - { - return new File( PlexusTestCase.getBasedir(), file.getPath() ); - } - } -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java deleted file mode 100644 index 9df3ae7..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java +++ /dev/null @@ -1,328 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.plugin.logging.Log; -import org.codehaus.plexus.logging.Logger; - -/** - * This logger implements both types of logs currently in use. It can be injected where needed - * to turn off logs during testing where they aren't desired. - * - * @author Brian Fox - * @version $Id$ - */ -public class SilentLog - implements Log, Logger -{ - /** - * @return false - * @see org.apache.maven.plugin.logging.Log#isDebugEnabled() - */ - public boolean isDebugEnabled() - { - return false; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence) - */ - public void debug( CharSequence content ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence, java.lang.Throwable) - */ - public void debug( CharSequence content, Throwable error ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#debug(java.lang.Throwable) - */ - public void debug( Throwable error ) - { - // nop - } - - /** - * @return false - * @see org.apache.maven.plugin.logging.Log#isInfoEnabled() - */ - public boolean isInfoEnabled() - { - return false; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence) - */ - public void info( CharSequence content ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence, java.lang.Throwable) - */ - public void info( CharSequence content, Throwable error ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#info(java.lang.Throwable) - */ - public void info( Throwable error ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#isWarnEnabled() - */ - public boolean isWarnEnabled() - { - // nop - return false; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence) - */ - public void warn( CharSequence content ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence, java.lang.Throwable) - */ - public void warn( CharSequence content, Throwable error ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#warn(java.lang.Throwable) - */ - public void warn( Throwable error ) - { - // nop - } - - /** - * @return false - * @see org.apache.maven.plugin.logging.Log#isErrorEnabled() - */ - public boolean isErrorEnabled() - { - return false; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence) - */ - public void error( CharSequence content ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence, java.lang.Throwable) - */ - public void error( CharSequence content, Throwable error ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable) - */ - public void error( Throwable error ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#debug(java.lang.String) - */ - public void debug( String message ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#debug(java.lang.String, java.lang.Throwable) - */ - public void debug( String message, Throwable throwable ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#info(java.lang.String) - */ - public void info( String message ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#info(java.lang.String, java.lang.Throwable) - */ - public void info( String message, Throwable throwable ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#warn(java.lang.String) - */ - public void warn( String message ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#warn(java.lang.String, java.lang.Throwable) - */ - public void warn( String message, Throwable throwable ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#error(java.lang.String) - */ - public void error( String message ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#error(java.lang.String, java.lang.Throwable) - */ - public void error( String message, Throwable throwable ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#fatalError(java.lang.String) - */ - public void fatalError( String message ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.codehaus.plexus.logging.Logger#fatalError(java.lang.String, java.lang.Throwable) - */ - public void fatalError( String message, Throwable throwable ) - { - // nop - } - - /** - * @return false - * @see org.codehaus.plexus.logging.Logger#isFatalErrorEnabled() - */ - public boolean isFatalErrorEnabled() - { - return false; - } - - /** - * @return null - * @see org.codehaus.plexus.logging.Logger#getChildLogger(java.lang.String) - */ - public Logger getChildLogger( String name ) - { - return null; - } - - /** - * @return 0 - * @see org.codehaus.plexus.logging.Logger#getThreshold() - */ - public int getThreshold() - { - return 0; - } - - /** - * @return null - * @see org.codehaus.plexus.logging.Logger#getName() - */ - public String getName() - { - return null; - } -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java deleted file mode 100644 index 91ed81b..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java +++ /dev/null @@ -1,500 +0,0 @@ -package org.apache.maven.plugin.testing.stubs; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.OverConstrainedVersionException; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.metadata.ArtifactMetadata; - -import java.io.File; -import java.util.Collection; -import java.util.List; - -/** - * Stub class for {@link Artifact} testing. - * - * @author jesse - * @version $Id$ - */ -public class ArtifactStub - implements Artifact -{ - private String groupId; - - private String artifactId; - - private String version; - - private String scope; - - private String type; - - private String classifier; - - private File file; - - private ArtifactRepository artifactRepository; - - /** - * By default, return 0 - * - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - public int compareTo( Object object ) - { - return 0; - } - - /** {@inheritDoc} */ - public String getGroupId() - { - return groupId; - } - - /** {@inheritDoc} */ - public String getArtifactId() - { - return artifactId; - } - - /** {@inheritDoc} */ - public String getVersion() - { - return version; - } - - /** {@inheritDoc} */ - public void setVersion( String version ) - { - this.version = version; - } - - /** {@inheritDoc} */ - public String getScope() - { - return scope; - } - - /** {@inheritDoc} */ - public String getType() - { - return type; - } - - /** - * Set a new type - * - * @param type - */ - public void setType( String type ) - { - this.type = type; - } - - /** {@inheritDoc} */ - public String getClassifier() - { - return classifier; - } - - /** {@inheritDoc} */ - public boolean hasClassifier() - { - return classifier != null; - } - - /** {@inheritDoc} */ - public File getFile() - { - return file; - } - - /** {@inheritDoc} */ - public void setFile( File file ) - { - this.file = file; - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getBaseVersion() - */ - public String getBaseVersion() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setBaseVersion(java.lang.String) - */ - public void setBaseVersion( String string ) - { - // nop - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getId() - */ - public String getId() - { - return null; - } - - /** - * @return groupId:artifactId:type:classifier. - * @see org.apache.maven.artifact.Artifact#getDependencyConflictId() - */ - public String getDependencyConflictId() - { - StringBuffer buffer = new StringBuffer(); - - buffer.append( getGroupId() ); - buffer.append( ":" ).append( getArtifactId() ); - buffer.append( ":" ).append( getType() ); - buffer.append( ":" ).append( getClassifier() ); - - return buffer.toString(); - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#addMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) - */ - public void addMetadata( ArtifactMetadata artifactMetadata ) - { - // nop - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getMetadataList() - */ - public Collection getMetadataList() - { - return null; - } - - /** {@inheritDoc} */ - public void setRepository( ArtifactRepository artifactRepository ) - { - this.artifactRepository = artifactRepository; - } - - /** {@inheritDoc} */ - public ArtifactRepository getRepository() - { - return artifactRepository; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#updateVersion(java.lang.String, org.apache.maven.artifact.repository.ArtifactRepository) - */ - public void updateVersion( String string, ArtifactRepository artifactRepository ) - { - // nop - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getDownloadUrl() - */ - public String getDownloadUrl() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setDownloadUrl(java.lang.String) - */ - public void setDownloadUrl( String string ) - { - // nop - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getDependencyFilter() - */ - public ArtifactFilter getDependencyFilter() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setDependencyFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) - */ - public void setDependencyFilter( ArtifactFilter artifactFilter ) - { - // nop - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getArtifactHandler() - */ - public ArtifactHandler getArtifactHandler() - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getDependencyTrail() - */ - public List getDependencyTrail() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setDependencyTrail(java.util.List) - */ - public void setDependencyTrail( List list ) - { - // nop - } - - /** {@inheritDoc} */ - public void setScope( String scope ) - { - this.scope = scope; - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getVersionRange() - */ - public VersionRange getVersionRange() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setVersionRange(org.apache.maven.artifact.versioning.VersionRange) - */ - public void setVersionRange( VersionRange versionRange ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#selectVersion(java.lang.String) - */ - public void selectVersion( String string ) - { - // nop - } - - /** {@inheritDoc} */ - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - /** {@inheritDoc} */ - public void setArtifactId( String artifactId ) - { - this.artifactId = artifactId; - } - - /** - * @return false. - * @see org.apache.maven.artifact.Artifact#isSnapshot() - */ - public boolean isSnapshot() - { - return Artifact.VERSION_FILE_PATTERN.matcher( getVersion() ).matches() - || getVersion().endsWith( Artifact.SNAPSHOT_VERSION ); - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setResolved(boolean) - */ - public void setResolved( boolean b ) - { - // nop - } - - /** - * @return false. - * @see org.apache.maven.artifact.Artifact#isResolved() - */ - public boolean isResolved() - { - return false; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setResolvedVersion(java.lang.String) - */ - public void setResolvedVersion( String string ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) - */ - public void setArtifactHandler( ArtifactHandler artifactHandler ) - { - // nop - } - - /** - * @return false. - * @see org.apache.maven.artifact.Artifact#isRelease() - */ - public boolean isRelease() - { - return !isSnapshot(); - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setRelease(boolean) - */ - public void setRelease( boolean b ) - { - // nop - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getAvailableVersions() - */ - public List getAvailableVersions() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.Artifact#setAvailableVersions(java.util.List) - */ - public void setAvailableVersions( List list ) - { - // nop - } - - /** - * @return false. - * @see org.apache.maven.artifact.Artifact#isOptional() - */ - public boolean isOptional() - { - return false; - } - - /** - * By default, do nothing. - * - * @param b - */ - public void setOptional( boolean b ) - { - // nop - } - - /** - * @return null. - * @see org.apache.maven.artifact.Artifact#getSelectedVersion() - */ - public ArtifactVersion getSelectedVersion() - throws OverConstrainedVersionException - { - return null; - } - - /** - * @return false. - * @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() ); - } - } -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java deleted file mode 100644 index 99ee8f7..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java +++ /dev/null @@ -1,202 +0,0 @@ -package org.apache.maven.plugin.testing.stubs; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.handler.ArtifactHandler; - -/** - * Minimal artifact handler used by the stub factory to create unpackable archives. - * - * @author Brian Fox - * @version $Id$ - */ -public class DefaultArtifactHandlerStub - implements ArtifactHandler -{ - private String extension; - - private String type; - - private String classifier; - - private String directory; - - private String packaging; - - private boolean includesDependencies; - - private String language; - - private boolean addedToClasspath; - - /** - * @param t the artifact handler type - * @param c the artifact handler classifier - */ - public DefaultArtifactHandlerStub( String t, String c ) - { - type = t; - classifier = c; - if ( t.equals( "test-jar" ) ) - { - extension = "jar"; - } - - } - - /** - * @param type the artifact handler type - */ - public DefaultArtifactHandlerStub( String type ) - { - this.type = type; - } - - /** {@inheritDoc} */ - public String getExtension() - { - if ( extension == null ) - { - extension = type; - } - return extension; - } - - /** - * @return the artifact handler type - */ - public String getType() - { - return type; - } - - /** {@inheritDoc} */ - public String getClassifier() - { - return classifier; - } - - /** {@inheritDoc} */ - public String getDirectory() - { - if ( directory == null ) - { - directory = getPackaging() + "s"; - } - return directory; - } - - /** {@inheritDoc} */ - public String getPackaging() - { - if ( packaging == null ) - { - packaging = getType(); - } - return packaging; - } - - /** {@inheritDoc} */ - public boolean isIncludesDependencies() - { - return includesDependencies; - } - - /** {@inheritDoc} */ - public String getLanguage() - { - if ( language == null ) - { - language = "none"; - } - - return language; - } - - /** {@inheritDoc} */ - public boolean isAddedToClasspath() - { - return addedToClasspath; - } - - /** - * @param theAddedToClasspath The addedToClasspath to set. - */ - public void setAddedToClasspath( boolean theAddedToClasspath ) - { - this.addedToClasspath = theAddedToClasspath; - } - - /** - * @param theClassifier The classifier to set. - */ - public void setClassifier( String theClassifier ) - { - this.classifier = theClassifier; - } - - /** - * @param theDirectory The directory to set. - */ - public void setDirectory( String theDirectory ) - { - this.directory = theDirectory; - } - - /** - * @param theExtension The extension to set. - */ - public void setExtension( String theExtension ) - { - this.extension = theExtension; - } - - /** - * @param theIncludesDependencies The includesDependencies to set. - */ - public void setIncludesDependencies( boolean theIncludesDependencies ) - { - this.includesDependencies = theIncludesDependencies; - } - - /** - * @param theLanguage The language to set. - */ - public void setLanguage( String theLanguage ) - { - this.language = theLanguage; - } - - /** - * @param thePackaging The packaging to set. - */ - public void setPackaging( String thePackaging ) - { - this.packaging = thePackaging; - } - - /** - * @param theType The type to set. - */ - public void setType( String theType ) - { - this.type = theType; - } -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java deleted file mode 100644 index 81d20b9..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java +++ /dev/null @@ -1,1508 +0,0 @@ -package org.apache.maven.plugin.testing.stubs; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DependencyResolutionRequiredException; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.model.Build; -import org.apache.maven.model.CiManagement; -import org.apache.maven.model.Contributor; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.Developer; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.IssueManagement; -import org.apache.maven.model.License; -import org.apache.maven.model.MailingList; -import org.apache.maven.model.Model; -import org.apache.maven.model.Organization; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginManagement; -import org.apache.maven.model.Prerequisites; -import org.apache.maven.model.Reporting; -import org.apache.maven.model.Resource; -import org.apache.maven.model.Scm; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -/** - * Very simple stub of MavenProject object, going to take a lot of work to make it - * useful as a stub though. - * - * @author jesse - * @version $Id$ - */ -public class MavenProjectStub - extends MavenProject -{ - private String groupId; - - private String artifactId; - - private String name; - - private Model model; - - private MavenProject parent; - - private File file; - - private List collectedProjects; - - private List attachedArtifacts; - - private List compileSourceRoots; - - private List testCompileSourceRoots; - - private List scriptSourceRoots; - - private List pluginArtifactRepositories; - - private ArtifactRepository releaseArtifactRepository; - - private ArtifactRepository snapshotArtifactRepository; - - private List activeProfiles; - - private Set dependencyArtifacts; - - private Artifact artifact; - - private Map artifactMap; - - private Model originalModel; - - private Map pluginArtifactMap; - - private Map reportArtifactMap; - - private Map extensionArtifactMap; - - private Map projectReferences; - - private Build buildOverlay; - - private boolean executionRoot; - - private List compileArtifacts; - - private List compileDependencies; - - private List systemDependencies; - - private List testClasspathElements; - - private List testDependencies; - - private List systemClasspathElements; - - private List systemArtifacts; - - private List testArtifacts; - - private List runtimeArtifacts; - - private List runtimeDependencies; - - private List runtimeClasspathElements; - - private String modelVersion; - - private String packaging; - - private String inceptionYear; - - private String url; - - private String description; - - private String version; - - private String defaultGoal; - - private List licenses; - - private Build build; - - /** - * Default constructor - */ - public MavenProjectStub() - { - this( new Model() ); - } - - /** - * @param model the given model - */ - public MavenProjectStub( Model model ) - { - super( (Model) null ); - this.model = model; - } - - /** - * No project model is associated - * - * @param project the given project - */ - public MavenProjectStub( MavenProject project ) - { - super( (Model) null ); - } - - /** - * @param mavenProject - * @return an empty String - * @throws IOException if any - */ - public String getModulePathAdjustment( MavenProject mavenProject ) - throws IOException - { - return ""; - } - - /** {@inheritDoc} */ - public Artifact getArtifact() - { - return artifact; - } - - /** {@inheritDoc} */ - public void setArtifact( Artifact artifact ) - { - this.artifact = artifact; - } - - /** {@inheritDoc} */ - public Model getModel() - { - return model; - } - - /** {@inheritDoc} */ - public MavenProject getParent() - { - return parent; - } - - /** {@inheritDoc} */ - public void setParent( MavenProject mavenProject ) - { - this.parent = mavenProject; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setRemoteArtifactRepositories(java.util.List) - */ - public void setRemoteArtifactRepositories( List list ) - { - // nop - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getRemoteArtifactRepositories() - */ - public List getRemoteArtifactRepositories() - { - return Collections.EMPTY_LIST; - } - - /** {@inheritDoc} */ - public boolean hasParent() - { - if ( parent != null ) - { - return true; - } - - return false; - } - - /** {@inheritDoc} */ - public File getFile() - { - return file; - } - - /** {@inheritDoc} */ - public void setFile( File file ) - { - this.file = file; - } - - /** {@inheritDoc} */ - public File getBasedir() - { - return new File( PlexusTestCase.getBasedir() ); - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setDependencies(java.util.List) - */ - public void setDependencies( List list ) - { - // nop - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getDependencies() - */ - public List getDependencies() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getDependencyManagement() - */ - public DependencyManagement getDependencyManagement() - { - return null; - } - - /** {@inheritDoc} */ - public void addCompileSourceRoot( String string ) - { - if ( compileSourceRoots == null ) - { - compileSourceRoots = new ArrayList( Collections.singletonList( string ) ); - } - else - { - compileSourceRoots.add( string ); - } - } - - /** {@inheritDoc} */ - public void addScriptSourceRoot( String string ) - { - if ( scriptSourceRoots == null ) - { - scriptSourceRoots = new ArrayList( Collections.singletonList( string ) ); - } - else - { - scriptSourceRoots.add( string ); - } - } - - /** {@inheritDoc} */ - public void addTestCompileSourceRoot( String string ) - { - if ( testCompileSourceRoots == null ) - { - testCompileSourceRoots = new ArrayList( Collections.singletonList( string ) ); - } - else - { - testCompileSourceRoots.add( string ); - } - } - - /** {@inheritDoc} */ - public List getCompileSourceRoots() - { - return compileSourceRoots; - } - - /** {@inheritDoc} */ - public List getScriptSourceRoots() - { - return scriptSourceRoots; - } - - /** {@inheritDoc} */ - public List getTestCompileSourceRoots() - { - return testCompileSourceRoots; - } - - /** {@inheritDoc} */ - public List getCompileClasspathElements() - throws DependencyResolutionRequiredException - { - return compileSourceRoots; - } - - /** - * @param compileArtifacts - */ - public void setCompileArtifacts( List compileArtifacts ) - { - this.compileArtifacts = compileArtifacts; - } - - /** {@inheritDoc} */ - public List getCompileArtifacts() - { - return compileArtifacts; - } - - /** {@inheritDoc} */ - public List getCompileDependencies() - { - return compileDependencies; - } - - /** {@inheritDoc} */ - public List getTestClasspathElements() - throws DependencyResolutionRequiredException - { - return testClasspathElements; - } - - /** {@inheritDoc} */ - public List getTestArtifacts() - { - return testArtifacts; - } - - /** {@inheritDoc} */ - public List getTestDependencies() - { - return testDependencies; - } - - /** {@inheritDoc} */ - public List getRuntimeClasspathElements() - throws DependencyResolutionRequiredException - { - return runtimeClasspathElements; - } - - /** {@inheritDoc} */ - public List getRuntimeArtifacts() - { - return runtimeArtifacts; - } - - /** {@inheritDoc} */ - public List getRuntimeDependencies() - { - return runtimeDependencies; - } - - /** {@inheritDoc} */ - public List getSystemClasspathElements() - throws DependencyResolutionRequiredException - { - return systemClasspathElements; - } - - /** {@inheritDoc} */ - public List getSystemArtifacts() - { - return systemArtifacts; - } - - /** - * @param runtimeClasspathElements - */ - public void setRuntimeClasspathElements( List runtimeClasspathElements ) - { - this.runtimeClasspathElements = runtimeClasspathElements; - } - - /** - * @param attachedArtifacts - */ - public void setAttachedArtifacts( List attachedArtifacts ) - { - this.attachedArtifacts = attachedArtifacts; - } - - /** - * @param compileSourceRoots - */ - public void setCompileSourceRoots( List compileSourceRoots ) - { - this.compileSourceRoots = compileSourceRoots; - } - - /** - * @param testCompileSourceRoots - */ - public void setTestCompileSourceRoots( List testCompileSourceRoots ) - { - this.testCompileSourceRoots = testCompileSourceRoots; - } - - /** - * @param scriptSourceRoots - */ - public void setScriptSourceRoots( List scriptSourceRoots ) - { - this.scriptSourceRoots = scriptSourceRoots; - } - - /** - * @param artifactMap - */ - public void setArtifactMap( Map artifactMap ) - { - this.artifactMap = artifactMap; - } - - /** - * @param pluginArtifactMap - */ - public void setPluginArtifactMap( Map pluginArtifactMap ) - { - this.pluginArtifactMap = pluginArtifactMap; - } - - /** - * @param reportArtifactMap - */ - public void setReportArtifactMap( Map reportArtifactMap ) - { - this.reportArtifactMap = reportArtifactMap; - } - - /** - * @param extensionArtifactMap - */ - public void setExtensionArtifactMap( Map extensionArtifactMap ) - { - this.extensionArtifactMap = extensionArtifactMap; - } - - /** - * @param projectReferences - */ - public void setProjectReferences( Map projectReferences ) - { - this.projectReferences = projectReferences; - } - - /** - * @param buildOverlay - */ - public void setBuildOverlay( Build buildOverlay ) - { - this.buildOverlay = buildOverlay; - } - - /** - * @param compileDependencies - */ - public void setCompileDependencies( List compileDependencies ) - { - this.compileDependencies = compileDependencies; - } - - /** - * @param systemDependencies - */ - public void setSystemDependencies( List systemDependencies ) - { - this.systemDependencies = systemDependencies; - } - - /** - * @param testClasspathElements - */ - public void setTestClasspathElements( List testClasspathElements ) - { - this.testClasspathElements = testClasspathElements; - } - - /** - * @param testDependencies - */ - public void setTestDependencies( List testDependencies ) - { - this.testDependencies = testDependencies; - } - - /** - * @param systemClasspathElements - */ - public void setSystemClasspathElements( List systemClasspathElements ) - { - this.systemClasspathElements = systemClasspathElements; - } - - /** - * @param systemArtifacts - */ - public void setSystemArtifacts( List systemArtifacts ) - { - this.systemArtifacts = systemArtifacts; - } - - /** - * @param testArtifacts - */ - public void setTestArtifacts( List testArtifacts ) - { - this.testArtifacts = testArtifacts; - } - - /** - * @param runtimeArtifacts - */ - public void setRuntimeArtifacts( List runtimeArtifacts ) - { - this.runtimeArtifacts = runtimeArtifacts; - } - - /** - * @param runtimeDependencies - */ - public void setRuntimeDependencies( List runtimeDependencies ) - { - this.runtimeDependencies = runtimeDependencies; - } - - /** - * @param model - */ - public void setModel( Model model ) - { - this.model = model; - } - - /** {@inheritDoc} */ - public List getSystemDependencies() - { - return systemDependencies; - } - - /** {@inheritDoc} */ - public void setModelVersion( String string ) - { - this.modelVersion = string; - } - - /** {@inheritDoc} */ - public String getModelVersion() - { - return modelVersion; - } - - /** - * By default, return an empty String. - * - * @see org.apache.maven.project.MavenProject#getId() - */ - public String getId() - { - return ""; - } - - /** {@inheritDoc} */ - public void setGroupId( String string ) - { - this.groupId = string; - } - - /** {@inheritDoc} */ - public String getGroupId() - { - return groupId; - } - - /** {@inheritDoc} */ - public void setArtifactId( String string ) - { - this.artifactId = string; - } - - /** {@inheritDoc} */ - public String getArtifactId() - { - return artifactId; - } - - /** {@inheritDoc} */ - public void setName( String string ) - { - this.name = string; - } - - /** {@inheritDoc} */ - public String getName() - { - return name; - } - - /** {@inheritDoc} */ - public void setVersion( String string ) - { - this.version = string; - } - - /** {@inheritDoc} */ - public String getVersion() - { - return version; - } - - /** {@inheritDoc} */ - public String getPackaging() - { - return packaging; - } - - /** {@inheritDoc} */ - public void setPackaging( String string ) - { - this.packaging = string; - } - - /** {@inheritDoc} */ - public void setInceptionYear( String string ) - { - this.inceptionYear = string; - } - - /** {@inheritDoc} */ - public String getInceptionYear() - { - return inceptionYear; - } - - /** {@inheritDoc} */ - public void setUrl( String string ) - { - this.url = string; - } - - /** {@inheritDoc} */ - public String getUrl() - { - return url; - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getPrerequisites() - */ - public Prerequisites getPrerequisites() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setIssueManagement(org.apache.maven.model.IssueManagement) - */ - public void setIssueManagement( IssueManagement issueManagement ) - { - // nop - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getCiManagement() - */ - public CiManagement getCiManagement() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setCiManagement(org.apache.maven.model.CiManagement) - */ - public void setCiManagement( CiManagement ciManagement ) - { - // nop - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getIssueManagement() - */ - public IssueManagement getIssueManagement() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setDistributionManagement(org.apache.maven.model.DistributionManagement) - */ - public void setDistributionManagement( DistributionManagement distributionManagement ) - { - // nop - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getDistributionManagement() - */ - public DistributionManagement getDistributionManagement() - { - return null; - } - - /** {@inheritDoc} */ - public void setDescription( String string ) - { - this.description = string; - } - - /** {@inheritDoc} */ - public String getDescription() - { - return description; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setOrganization(org.apache.maven.model.Organization) - */ - public void setOrganization( Organization organization ) - { - // nop - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getOrganization() - */ - public Organization getOrganization() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setScm(org.apache.maven.model.Scm) - */ - public void setScm( Scm scm ) - { - // nop - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getScm() - */ - public Scm getScm() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setMailingLists(java.util.List) - */ - public void setMailingLists( List list ) - { - // nop - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getMailingLists() - */ - public List getMailingLists() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#addMailingList(org.apache.maven.model.MailingList) - */ - public void addMailingList( MailingList mailingList ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setDevelopers(java.util.List) - */ - public void setDevelopers( List list ) - { - // nop - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getDevelopers() - */ - public List getDevelopers() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#addDeveloper(org.apache.maven.model.Developer) - */ - public void addDeveloper( Developer developer ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setContributors(java.util.List) - */ - public void setContributors( List list ) - { - // nop - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getContributors() - */ - public List getContributors() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#addContributor(org.apache.maven.model.Contributor) - */ - public void addContributor( Contributor contributor ) - { - // nop - } - - /** {@inheritDoc} */ - public void setBuild( Build build ) - { - this.build = build; - } - - /** {@inheritDoc} */ - public Build getBuild() - { - return build; - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getResources() - */ - public List getResources() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getTestResources() - */ - public List getTestResources() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#addResource(org.apache.maven.model.Resource) - */ - public void addResource( Resource resource ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#addTestResource(org.apache.maven.model.Resource) - */ - public void addTestResource( Resource resource ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setReporting(org.apache.maven.model.Reporting) - */ - public void setReporting( Reporting reporting ) - { - // nop - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getReporting() - */ - public Reporting getReporting() - { - return null; - } - - /** {@inheritDoc} */ - public void setLicenses( List licenses ) - { - this.licenses = licenses; - } - - /** {@inheritDoc} */ - public List getLicenses() - { - return licenses; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#addLicense(org.apache.maven.model.License) - */ - public void addLicense( License license ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setArtifacts(java.util.Set) - */ - public void setArtifacts( Set set ) - { - // nop - } - - /** - * By default, return Collections.EMPTY_SET. - * - * @see org.apache.maven.project.MavenProject#getArtifacts() - */ - public Set getArtifacts() - { - return Collections.EMPTY_SET; - } - - /** - * By default, return Collections.EMPTY_MAP. - * - * @see org.apache.maven.project.MavenProject#getArtifactMap() - */ - public Map getArtifactMap() - { - return Collections.EMPTY_MAP; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setPluginArtifacts(java.util.Set) - */ - public void setPluginArtifacts( Set set ) - { - // nop - } - - /** - * By default, return Collections.EMPTY_SET. - * - * @see org.apache.maven.project.MavenProject#getPluginArtifacts() - */ - public Set getPluginArtifacts() - { - return Collections.EMPTY_SET; - } - - /** - * By default, return Collections.EMPTY_MAP. - * - * @see org.apache.maven.project.MavenProject#getPluginArtifactMap() - */ - public Map getPluginArtifactMap() - { - return Collections.EMPTY_MAP; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setReportArtifacts(java.util.Set) - */ - public void setReportArtifacts( Set set ) - { - // nop - } - - /** - * By default, return Collections.EMPTY_SET. - * - * @see org.apache.maven.project.MavenProject#getReportArtifacts() - */ - public Set getReportArtifacts() - { - return Collections.EMPTY_SET; - } - - /** - * By default, return Collections.EMPTY_MAP. - * - * @see org.apache.maven.project.MavenProject#getReportArtifactMap() - */ - public Map getReportArtifactMap() - { - return Collections.EMPTY_MAP; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setExtensionArtifacts(java.util.Set) - */ - public void setExtensionArtifacts( Set set ) - { - // nop - } - - /** - * By default, return Collections.EMPTY_SET. - * - * @see org.apache.maven.project.MavenProject#getExtensionArtifacts() - */ - public Set getExtensionArtifacts() - { - return Collections.EMPTY_SET; - } - - /** - * By default, return Collections.EMPTY_MAP. - * - * @see org.apache.maven.project.MavenProject#getExtensionArtifactMap() - */ - public Map getExtensionArtifactMap() - { - return Collections.EMPTY_MAP; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setParentArtifact(org.apache.maven.artifact.Artifact) - */ - public void setParentArtifact( Artifact artifact ) - { - // nop - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getParentArtifact() - */ - public Artifact getParentArtifact() - { - return null; - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getRepositories() - */ - public List getRepositories() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getReportPlugins() - */ - public List getReportPlugins() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getBuildPlugins() - */ - public List getBuildPlugins() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getModules() - */ - public List getModules() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getPluginManagement() - */ - public PluginManagement getPluginManagement() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#addPlugin(org.apache.maven.model.Plugin) - */ - public void addPlugin( Plugin plugin ) - { - // nop - } - - /** - * By default, do nothing. - * - * @param plugin - */ - public void injectPluginManagementInfo( Plugin plugin ) - { - // nop - } - - /** {@inheritDoc} */ - public List getCollectedProjects() - { - return collectedProjects; - } - - /** {@inheritDoc} */ - public void setCollectedProjects( List list ) - { - this.collectedProjects = list; - } - - /** {@inheritDoc} */ - public void setPluginArtifactRepositories( List list ) - { - this.pluginArtifactRepositories = list; - } - - /** {@inheritDoc} */ - public List getPluginArtifactRepositories() - { - return pluginArtifactRepositories; - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getDistributionManagementArtifactRepository() - */ - public ArtifactRepository getDistributionManagementArtifactRepository() - { - return null; - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getPluginRepositories() - */ - public List getPluginRepositories() - { - return Collections.EMPTY_LIST; - } - - /** {@inheritDoc} */ - public void setActiveProfiles( List list ) - { - activeProfiles = list; - } - - /** {@inheritDoc} */ - public List getActiveProfiles() - { - return activeProfiles; - } - - /** {@inheritDoc} */ - public void addAttachedArtifact( Artifact artifact ) - { - if ( attachedArtifacts == null ) - { - this.attachedArtifacts = new ArrayList( Collections.singletonList( artifact ) ); - } - else - { - attachedArtifacts.add( artifact ); - } - } - - /** {@inheritDoc} */ - public List getAttachedArtifacts() - { - return attachedArtifacts; - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getGoalConfiguration(java.lang.String, java.lang.String, java.lang.String, java.lang.String) - */ - public Xpp3Dom getGoalConfiguration( String string, String string1, String string2, String string3 ) - { - return null; - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getReportConfiguration(java.lang.String, java.lang.String, java.lang.String) - */ - public Xpp3Dom getReportConfiguration( String string, String string1, String string2 ) - { - return null; - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#getExecutionProject() - */ - public MavenProject getExecutionProject() - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#setExecutionProject(org.apache.maven.project.MavenProject) - */ - public void setExecutionProject( MavenProject mavenProject ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#writeModel(java.io.Writer) - */ - public void writeModel( Writer writer ) - throws IOException - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#writeOriginalModel(java.io.Writer) - */ - public void writeOriginalModel( Writer writer ) - throws IOException - { - // nop - } - - /** {@inheritDoc} */ - public Set getDependencyArtifacts() - { - return dependencyArtifacts; - } - - /** {@inheritDoc} */ - public void setDependencyArtifacts( Set set ) - { - this.dependencyArtifacts = set; - } - - /** {@inheritDoc} */ - public void setReleaseArtifactRepository( ArtifactRepository artifactRepository ) - { - this.releaseArtifactRepository = artifactRepository; - } - - /** {@inheritDoc} */ - public void setSnapshotArtifactRepository( ArtifactRepository artifactRepository ) - { - this.snapshotArtifactRepository = artifactRepository; - } - - /** {@inheritDoc} */ - public void setOriginalModel( Model model ) - { - this.originalModel = model; - } - - /** {@inheritDoc} */ - public Model getOriginalModel() - { - return originalModel; - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getBuildExtensions() - */ - public List getBuildExtensions() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, return Collections.EMPTY_SET. - * - * @see org.apache.maven.project.MavenProject#createArtifacts(org.apache.maven.artifact.factory.ArtifactFactory, java.lang.String, org.apache.maven.artifact.resolver.filter.ArtifactFilter) - */ - public Set createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter ) - throws InvalidDependencyVersionException - { - return Collections.EMPTY_SET; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#addProjectReference(org.apache.maven.project.MavenProject) - */ - public void addProjectReference( MavenProject mavenProject ) - { - // nop - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.project.MavenProject#attachArtifact(java.lang.String, java.lang.String, java.io.File) - */ - public void attachArtifact( String string, String string1, File file ) - { - // nop - } - - /** - * By default, return a new instance of Properties. - * - * @see org.apache.maven.project.MavenProject#getProperties() - */ - public Properties getProperties() - { - return new Properties(); - } - - /** - * By default, return Collections.EMPTY_LIST. - * - * @see org.apache.maven.project.MavenProject#getFilters() - */ - public List getFilters() - { - return Collections.EMPTY_LIST; - } - - /** - * By default, return Collections.EMPTY_MAP. - * - * @see org.apache.maven.project.MavenProject#getProjectReferences() - */ - public Map getProjectReferences() - { - return Collections.EMPTY_MAP; - } - - /** {@inheritDoc} */ - public boolean isExecutionRoot() - { - return executionRoot; - } - - /** {@inheritDoc} */ - public void setExecutionRoot( boolean b ) - { - this.executionRoot = b; - } - - /** {@inheritDoc} */ - public String getDefaultGoal() - { - return defaultGoal; - } - - /** - * By default, return null. - * - * @see org.apache.maven.project.MavenProject#replaceWithActiveArtifact(org.apache.maven.artifact.Artifact) - */ - public Artifact replaceWithActiveArtifact( Artifact artifact ) - { - return null; - } -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactCollector.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactCollector.java deleted file mode 100644 index 62d9181..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactCollector.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.apache.maven.plugin.testing.stubs; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactCollector; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.artifact.resolver.ResolutionNode; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; - -/** - * @author Brian Fox - * @version $Id$ - */ -public class StubArtifactCollector - implements ArtifactCollector -{ - /** - * Default constructor - */ - public StubArtifactCollector() - { - super(); - } - - /** {@inheritDoc} */ - public ArtifactResolutionResult collect( Set theArtifacts, Artifact theOriginatingArtifact, - ArtifactRepository theLocalRepository, List theRemoteRepositories, - ArtifactMetadataSource theSource, ArtifactFilter theFilter, - List theListeners ) - throws ArtifactResolutionException - { - Set nodes = new HashSet(); - ArtifactResolutionResult arr = new ArtifactResolutionResult(); - - Iterator iter = theArtifacts.iterator(); - while ( iter.hasNext() ) - { - nodes.add( new ResolutionNode( (Artifact) iter.next(), theRemoteRepositories ) ); - } - arr.setArtifactResolutionNodes( nodes ); - return arr; - } - - /** {@inheritDoc} */ - public ArtifactResolutionResult collect( Set theArtifacts, Artifact theOriginatingArtifact, Map theManagedVersions, - ArtifactRepository theLocalRepository, List theRemoteRepositories, - ArtifactMetadataSource theSource, ArtifactFilter theFilter, - List theListeners ) - throws ArtifactResolutionException - { - Set nodes = new HashSet(); - ArtifactResolutionResult arr = new ArtifactResolutionResult(); - - Iterator iter = theArtifacts.iterator(); - while ( iter.hasNext() ) - { - nodes.add( new ResolutionNode( (Artifact) iter.next(), theRemoteRepositories ) ); - } - arr.setArtifactResolutionNodes( nodes ); - return arr; - } -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java deleted file mode 100644 index 22c5751..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.apache.maven.plugin.testing.stubs; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; - -/** - * @author Brian Fox - * @version $Id$ - */ -public class StubArtifactRepository - implements ArtifactRepository -{ - private String baseDir = null; - - /** - * Default constructor - * - * @param dir the basedir - */ - public StubArtifactRepository( String dir ) - { - baseDir = dir; - } - - /** - * @return the artifactId. - * @see org.apache.maven.artifact.repository.ArtifactRepository#pathOf(org.apache.maven.artifact.Artifact) - */ - public String pathOf( Artifact artifact ) - { - return artifact.getId(); - } - - /** - * @return null. - * @see org.apache.maven.artifact.repository.ArtifactRepository#pathOfRemoteRepositoryMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) - */ - public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata ) - { - return null; - } - - /** - * @return the filename of this metadata on the local repository. - * @see org.apache.maven.artifact.repository.ArtifactRepository#pathOfLocalRepositoryMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata, org.apache.maven.artifact.repository.ArtifactRepository) - */ - public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) - { - return metadata.getLocalFilename( repository ); - } - - /** - * @return null. - * @see org.apache.maven.artifact.repository.ArtifactRepository#getUrl() - */ - public String getUrl() - { - return null; - } - - /** - * @return basedir. - * @see org.apache.maven.artifact.repository.ArtifactRepository#getBasedir() - */ - public String getBasedir() - { - return baseDir; - } - - /** - * @return null. - * @see org.apache.maven.artifact.repository.ArtifactRepository#getProtocol() - */ - public String getProtocol() - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.repository.ArtifactRepository#getId() - */ - public String getId() - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.repository.ArtifactRepository#getSnapshots() - */ - public ArtifactRepositoryPolicy getSnapshots() - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.repository.ArtifactRepository#getReleases() - */ - public ArtifactRepositoryPolicy getReleases() - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.repository.ArtifactRepository#getLayout() - */ - public ArtifactRepositoryLayout getLayout() - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.repository.ArtifactRepository#getKey() - */ - public String getKey() - { - return null; - } - - /** - * @return false. - * @see org.apache.maven.artifact.repository.ArtifactRepository#isUniqueVersion() - */ - public boolean isUniqueVersion() - { - return false; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.repository.ArtifactRepository#setBlacklisted(boolean) - */ - public void setBlacklisted( boolean blackListed ) - { - // nop - } - - /** - * @return false. - * @see org.apache.maven.artifact.repository.ArtifactRepository#isBlacklisted() - */ - public boolean isBlacklisted() - { - return false; - } -} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactResolver.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactResolver.java deleted file mode 100644 index aa4e2d1..0000000 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactResolver.java +++ /dev/null @@ -1,184 +0,0 @@ -package org.apache.maven.plugin.testing.stubs; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.plugin.testing.ArtifactStubFactory; - -/** - * Stub resolver. The constructor allows the specification of the exception to throw so that handling can be tested too. - * - * @author Brian Fox - * @version $Id$ - */ -public class StubArtifactResolver - implements ArtifactResolver -{ - private boolean throwArtifactResolutionException; - - private boolean throwArtifactNotFoundException; - - private ArtifactStubFactory factory; - - /** - * Default constructor - * - * @param factory - * @param throwArtifactResolutionException - * @param throwArtifactNotFoundException - */ - public StubArtifactResolver( ArtifactStubFactory factory, boolean throwArtifactResolutionException, - boolean throwArtifactNotFoundException ) - { - this.throwArtifactNotFoundException = throwArtifactNotFoundException; - this.throwArtifactResolutionException = throwArtifactResolutionException; - this.factory = factory; - } - - /** - * Creates dummy file and sets it in the artifact to simulate resolution - * - * @see org.apache.maven.artifact.resolver.ArtifactResolver#resolve(org.apache.maven.artifact.Artifact, java.util.List, org.apache.maven.artifact.repository.ArtifactRepository) - */ - public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) - throws ArtifactResolutionException, ArtifactNotFoundException - { - if ( !this.throwArtifactNotFoundException && !this.throwArtifactResolutionException ) - { - try - { - if ( factory != null ) - { - factory.setArtifactFile( artifact, factory.getWorkingDir() ); - } - } - catch ( IOException e ) - { - throw new ArtifactResolutionException( "IOException: " + e.getMessage(), artifact, e ); - } - } - else - { - if ( throwArtifactResolutionException ) - { - throw new ArtifactResolutionException( "Catch!", artifact ); - } - - throw new ArtifactNotFoundException( "Catch!", artifact ); - } - } - - /** - * @return null. - * @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.List, org.apache.maven.artifact.repository.ArtifactRepository, org.apache.maven.artifact.metadata.ArtifactMetadataSource) - */ - public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, - List remoteRepositories, ArtifactRepository localRepository, - ArtifactMetadataSource source ) - throws ArtifactResolutionException, ArtifactNotFoundException - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.List, org.apache.maven.artifact.repository.ArtifactRepository, org.apache.maven.artifact.metadata.ArtifactMetadataSource, java.util.List) - */ - public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, - List remoteRepositories, ArtifactRepository localRepository, - ArtifactMetadataSource source, List listeners ) - throws ArtifactResolutionException, ArtifactNotFoundException - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource, org.apache.maven.artifact.resolver.filter.ArtifactFilter) - */ - public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, - ArtifactRepository localRepository, List remoteRepositories, - ArtifactMetadataSource source, ArtifactFilter filter ) - throws ArtifactResolutionException, ArtifactNotFoundException - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.Map, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource) - */ - public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, - Map managedVersions, ArtifactRepository localRepository, - List remoteRepositories, ArtifactMetadataSource source ) - throws ArtifactResolutionException, ArtifactNotFoundException - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.Map, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource, org.apache.maven.artifact.resolver.filter.ArtifactFilter) - */ - public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, - Map managedVersions, ArtifactRepository localRepository, - List remoteRepositories, ArtifactMetadataSource source, - ArtifactFilter filter ) - throws ArtifactResolutionException, ArtifactNotFoundException - { - return null; - } - - /** - * @return null. - * @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveTransitively(java.util.Set, org.apache.maven.artifact.Artifact, java.util.Map, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List, org.apache.maven.artifact.metadata.ArtifactMetadataSource, org.apache.maven.artifact.resolver.filter.ArtifactFilter, java.util.List) - */ - public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, - Map managedVersions, ArtifactRepository localRepository, - List remoteRepositories, ArtifactMetadataSource source, - ArtifactFilter filter, List listeners ) - throws ArtifactResolutionException, ArtifactNotFoundException - { - return null; - } - - /** - * By default, do nothing. - * - * @see org.apache.maven.artifact.resolver.ArtifactResolver#resolveAlways(org.apache.maven.artifact.Artifact, java.util.List, org.apache.maven.artifact.repository.ArtifactRepository) - */ - public void resolveAlways( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) - throws ArtifactResolutionException, ArtifactNotFoundException - { - // nop - } -} diff --git a/maven-plugin-testing-harness/src/main/resources/META-INF/plexus/components.xml b/maven-plugin-testing-harness/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index 915d02a..0000000 --- a/maven-plugin-testing-harness/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator - stub-evaluator - org.apache.maven.plugin.testing.StubResolverExpressionEvaluator - - - org.codehaus.plexus.PlexusContainer - container - - - - - org.apache.maven.artifact.Artifact - stub - org.apache.maven.plugin.testing.stubs.StubArtifact - - - \ No newline at end of file diff --git a/maven-plugin-testing-harness/src/site/apt/examples/artifact.apt b/maven-plugin-testing-harness/src/site/apt/examples/artifact.apt deleted file mode 100644 index c5aa970..0000000 --- a/maven-plugin-testing-harness/src/site/apt/examples/artifact.apt +++ /dev/null @@ -1,218 +0,0 @@ - ------ - Testing Project Artifact - ------ - Vincent Siveton - ------ - February 2008 - ------ - -~~ Licensed to the Apache Software Foundation (ASF) under one -~~ or more contributor license agreements. See the NOTICE file -~~ distributed with this work for additional information -~~ regarding copyright ownership. The ASF licenses this file -~~ to you under the Apache License, Version 2.0 (the -~~ "License"); you may not use this file except in compliance -~~ with the License. You may obtain a copy of the License at -~~ -~~ http://www.apache.org/licenses/LICENSE-2.0 -~~ -~~ Unless required by applicable law or agreed to in writing, -~~ software distributed under the License is distributed on an -~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -~~ KIND, either express or implied. See the License for the -~~ specific language governing permissions and limitations -~~ under the License. - -Testing Project Artifact - - <>: This example improves the {{{../getting-started/index.html}cookbook}} to play with artifact handler. - - Sometimes, your Mojo uses project artifact and ArtifactHandler mechanisms. For instance, you could need to - filter on Java projects, i.e.: - ------ -public class MyMojo - extends AbstractMojo -{ - /** - * The Maven Project. - * - * @parameter expression="${project}" - * @required - * @readonly - */ - protected MavenProject project; - - public void execute() - throws MojoExecutionException - { - ... - - ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler(); - if ( "java".equals( artifactHandler.getLanguage() ) ) - { - ... - } - - ... - } -} ------ - -* Create Stubs - ------ -public class MyArtifactHandlerStub - extends DefaultArtifactHandler -{ - private String language; - - public String getLanguage() - { - if ( language == null ) - { - language = "java"; - } - - return language; - } - - public void setLanguage( String language ) - { - this.language = language; - } -} ------ - ------ -public class MyArtifactStub - extends ArtifactStub -{ - private String groupId; - - private String artifactId; - - private String version; - - private String packaging; - - private VersionRange versionRange; - - private ArtifactHandler handler; - - /** - * @param groupId - * @param artifactId - * @param version - * @param packaging - */ - public ProjectInfoPluginArtifactStub( String groupId, String artifactId, - String version, String packaging ) - { - this.groupId = groupId; - this.artifactId = artifactId; - this.version = version; - this.packaging = packaging; - versionRange = VersionRange.createFromVersion( version ); - } - - /** {@inheritDoc} */ - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - /** {@inheritDoc} */ - public String getGroupId() - { - return groupId; - } - - /** {@inheritDoc} */ - public void setArtifactId( String artifactId ) - { - this.artifactId = artifactId; - } - - /** {@inheritDoc} */ - public String getArtifactId() - { - return artifactId; - } - - /** {@inheritDoc} */ - public void setVersion( String version ) - { - this.version = version; - } - - /** {@inheritDoc} */ - public String getVersion() - { - return version; - } - - /** - * @param packaging - */ - public void setPackaging( String packaging ) - { - this.packaging = packaging; - } - - /** - * @return the packaging - */ - public String getPackaging() - { - return packaging; - } - - /** {@inheritDoc} */ - public VersionRange getVersionRange() - { - return versionRange; - } - - /** {@inheritDoc} */ - public void setVersionRange( VersionRange versionRange ) - { - this.versionRange = versionRange; - } - - /** {@inheritDoc} */ - public ArtifactHandler getArtifactHandler() - { - return handler; - } - - /** {@inheritDoc} */ - public void setArtifactHandler( ArtifactHandler handler ) - { - this.handler = handler; - } -} ------ - ------ -public class MyProjectStub - extends MavenProjectStub -{ - /** - * Default constructor - */ - public MyProjectStub() - { - ... - - Artifact artifact = new MyArtifactStub( getGroupId(), getArtifactId(), - getVersion(), getPackaging() ); - artifact.setArtifactHandler( new MyArtifactHandlerStub() ); - setArtifact( artifact ); - - ... - } - - ... -} ------ diff --git a/maven-plugin-testing-harness/src/site/apt/examples/complex-mojo-parameters.apt b/maven-plugin-testing-harness/src/site/apt/examples/complex-mojo-parameters.apt deleted file mode 100644 index 7a9caf9..0000000 --- a/maven-plugin-testing-harness/src/site/apt/examples/complex-mojo-parameters.apt +++ /dev/null @@ -1,186 +0,0 @@ - ------ - Testing Complex Mojo Parameters - ------ - Vincent Siveton - ------ - February 2008 - ------ - -~~ Licensed to the Apache Software Foundation (ASF) under one -~~ or more contributor license agreements. See the NOTICE file -~~ distributed with this work for additional information -~~ regarding copyright ownership. The ASF licenses this file -~~ to you under the Apache License, Version 2.0 (the -~~ "License"); you may not use this file except in compliance -~~ with the License. You may obtain a copy of the License at -~~ -~~ http://www.apache.org/licenses/LICENSE-2.0 -~~ -~~ Unless required by applicable law or agreed to in writing, -~~ software distributed under the License is distributed on an -~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -~~ KIND, either express or implied. See the License for the -~~ specific language governing permissions and limitations -~~ under the License. - -Testing Complex Mojo Parameters - - <>: This example improves the {{{../getting-started/index.html}cookbook}} for testing complex Mojo parameters. - - In real plugin development, you will use specific Maven objects like <<>>, <<>> or - <<>>. You could use them by defining stubs. - - Suppose that you have the following dependencies in the maven-my-plugin pom: - ------ - - ... - - - org.apache.maven - maven-artifact - 2.0.8 - - - org.apache.maven - maven-project - 2.0.8 - - ... - - ------ - - You will add the following in the <<>>: - ------ -public class MyMojo - extends AbstractMojo -{ - /** - * The Maven Project. - * - * @parameter expression="${project}" - * @required - * @readonly - */ - protected MavenProject project; - - /** - * Local Repository. - * - * @parameter expression="${localRepository}" - * @required - * @readonly - */ - protected ArtifactRepository localRepository; - - /** - * The Maven Settings. - * - * @parameter default-value="${settings}" - * @required - * @readonly - */ - private Settings settings; - - ... -} ------ - -* Create Stubs - - You need to create stub objects to run <<>>. By convention, the package name should - reflect the stubs, i.e. in our case <<>>. - ------ -public class MyProjectStub - extends MavenProjectStub -{ - /** - * Default constructor - */ - public MyProjectStub() - { - MavenXpp3Reader pomReader = new MavenXpp3Reader(); - Model model; - try - { - model = pomReader.read( ReaderFactory.newXmlReader( new File( getBasedir(), "pom.xml" ) ) ); - setModel( model ); - } - catch ( Exception e ) - { - throw new RuntimeException( e ); - } - - setGroupId( model.getGroupId() ); - setArtifactId( model.getArtifactId() ); - setVersion( model.getVersion() ); - setName( model.getName() ); - setUrl( model.getUrl() ); - setPackaging( model.getPackaging() ); - - Build build = new Build(); - build.setFinalName( model.getArtifactId() ); - build.setDirectory( getBasedir() + "/target" ); - build.setSourceDirectory( getBasedir() + "/src/main/java" ); - build.setOutputDirectory( getBasedir() + "/target/classes" ); - build.setTestSourceDirectory( getBasedir() + "/src/test/java" ); - build.setTestOutputDirectory( getBasedir() + "/target/test-classes" ); - setBuild( build ); - - List compileSourceRoots = new ArrayList(); - compileSourceRoots.add( getBasedir() + "/src/main/java" ); - setCompileSourceRoots( compileSourceRoots ); - - List testCompileSourceRoots = new ArrayList(); - testCompileSourceRoots.add( getBasedir() + "/src/test/java" ); - setTestCompileSourceRoots( testCompileSourceRoots ); - } - - /** {@inheritDoc} */ - public File getBasedir() - { - return new File( super.getBasedir() + "/src/test/resources/unit/project-to-test/" ); - } -} ------ - ------ -public class SettingsStub - extends Settings -{ - /** {@inheritDoc} */ - public List getProxies() - { - return Collections.EMPTY_LIST; - } -} ------ - -* Configure <<>> pom - ------ - - ... - - - - maven-my-plugin - - - target/test-harness/project-to-test - - - ${localRepository} - - - - - - - - ------ diff --git a/maven-plugin-testing-harness/src/site/apt/examples/multiproject.apt b/maven-plugin-testing-harness/src/site/apt/examples/multiproject.apt deleted file mode 100644 index 1564723..0000000 --- a/maven-plugin-testing-harness/src/site/apt/examples/multiproject.apt +++ /dev/null @@ -1,123 +0,0 @@ - ------ - Testing Multiproject - ------ - Vincent Siveton - ------ - February 2008 - ------ - -~~ Licensed to the Apache Software Foundation (ASF) under one -~~ or more contributor license agreements. See the NOTICE file -~~ distributed with this work for additional information -~~ regarding copyright ownership. The ASF licenses this file -~~ to you under the Apache License, Version 2.0 (the -~~ "License"); you may not use this file except in compliance -~~ with the License. You may obtain a copy of the License at -~~ -~~ http://www.apache.org/licenses/LICENSE-2.0 -~~ -~~ Unless required by applicable law or agreed to in writing, -~~ software distributed under the License is distributed on an -~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -~~ KIND, either express or implied. See the License for the -~~ specific language governing permissions and limitations -~~ under the License. - -Testing Multiproject - - <>: This example improves the {{{../getting-started/index.html}cookbook}} for multi-project testing. - - Your Mojo should have <<<@aggregator>>> parameter, i.e.: - ------- -/** - * @goal touch - * @aggregator - */ -public class MyMojo - extends AbstractMojo -{ - ... -} ------- - - To test a Mojo in a multiproject area, you need to define several stubs, i.e. for the main test project and its modules. - -* Create Stubs - - Stub for the main test project: - ------ -public class MyProjectStub - extends MavenProjectStub -{ - /** - * Default constructor - */ - public MyProjectStub() - { - ... - - setExecutionRoot( true ); - } - - /** {@inheritDoc} */ - public MavenProject getExecutionProject() - { - return this; - } -} ------ - - Stubs for the subprojects: - ------ -public class SubProject1Stub - extends MavenProjectStub -{ - /** - * Default constructor - */ - public SubProject1Stub() - { - ... - } -} ------ - ------ -public class SubProject2Stub - extends MavenProjectStub -{ - /** - * Default constructor - */ - public SubProject2Stub() - { - ... - } -} ------ - -* Configure <<>> pom - ------ - - ... - - - - maven-my-plugin - - ... - - - - - - - - - - ------ diff --git a/maven-plugin-testing-harness/src/site/apt/examples/repositories.apt b/maven-plugin-testing-harness/src/site/apt/examples/repositories.apt deleted file mode 100644 index ff4fca1..0000000 --- a/maven-plugin-testing-harness/src/site/apt/examples/repositories.apt +++ /dev/null @@ -1,138 +0,0 @@ - ------ - Testing Using Repositories - ------ - Vincent Siveton - ------ - February 2008 - ------ - -~~ Licensed to the Apache Software Foundation (ASF) under one -~~ or more contributor license agreements. See the NOTICE file -~~ distributed with this work for additional information -~~ regarding copyright ownership. The ASF licenses this file -~~ to you under the Apache License, Version 2.0 (the -~~ "License"); you may not use this file except in compliance -~~ with the License. You may obtain a copy of the License at -~~ -~~ http://www.apache.org/licenses/LICENSE-2.0 -~~ -~~ Unless required by applicable law or agreed to in writing, -~~ software distributed under the License is distributed on an -~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -~~ KIND, either express or implied. See the License for the -~~ specific language governing permissions and limitations -~~ under the License. - -Testing Using Repositories - - <>: This example improves the {{{../getting-started/index.html}cookbook}} for testing repositories. - - When developing a Maven plugin you often need to play with repositories. Suppose that the MyMojo needs - to download artifacts into your local repository, i.e.: - ------ -public class MyMojo - extends AbstractMojo -{ - /** - * Used for resolving artifacts - * - * @component - */ - private ArtifactResolver resolver; - - /** - * Factory for creating artifact objects - * - * @component - */ - private ArtifactFactory factory; - - /** - * Local Repository. - * - * @parameter expression="${localRepository}" - * @required - * @readonly - */ - private ArtifactRepository localRepository; - - public void execute() - throws MojoExecutionException - { - ... - - Artifact artifact = factory.createArtifact( "junit", "junit", "3.8.1", "compile", "jar" ); - try - { - resolver.resolve( artifact, project.getRemoteArtifactRepositories(), localRepository ); - } - catch ( ArtifactResolutionException e ) - { - throw new MojoExecutionException( "Unable to resolve artifact:" + artifact, e ); - } - catch ( ArtifactNotFoundException e ) - { - throw new MojoExecutionException( "Unable to find artifact:" + artifact, e ); - } - - ... - } -} ------ - -* Create Stubs - - Stub for the test project: - ------ -public class MyProjectStub - extends MavenProjectStub -{ - /** - * Default constructor - */ - public MyProjectStub() - { - ... - } - - /** {@inheritDoc} */ - public List getRemoteArtifactRepositories() - { - ArtifactRepository repository = new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2", - new DefaultRepositoryLayout() ); - - return Collections.singletonList( repository ); - } -} ------ - -* Configure <<>> pom - ------ - - ... - - - - maven-my-plugin - - - ${basedir}/target/test-harness/project-to-test - - - ${localRepository} - - - - - - - ------ - -** Execute test - - Calling <<>> will create <<<$\{basedir\}/target/local-repo/junitjunit/3.8.1/junit-3.8.1.jar>>> file. diff --git a/maven-plugin-testing-harness/src/site/apt/getting-started/index.apt b/maven-plugin-testing-harness/src/site/apt/getting-started/index.apt deleted file mode 100644 index 985e7ee..0000000 --- a/maven-plugin-testing-harness/src/site/apt/getting-started/index.apt +++ /dev/null @@ -1,186 +0,0 @@ - ------ - How To Use Maven Plugin Testing Harness - ------ - Vincent Siveton - ------ - February 2008 - ------ - -~~ Licensed to the Apache Software Foundation (ASF) under one -~~ or more contributor license agreements. See the NOTICE file -~~ distributed with this work for additional information -~~ regarding copyright ownership. The ASF licenses this file -~~ to you under the Apache License, Version 2.0 (the -~~ "License"); you may not use this file except in compliance -~~ with the License. You may obtain a copy of the License at -~~ -~~ http://www.apache.org/licenses/LICENSE-2.0 -~~ -~~ Unless required by applicable law or agreed to in writing, -~~ software distributed under the License is distributed on an -~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -~~ KIND, either express or implied. See the License for the -~~ specific language governing permissions and limitations -~~ under the License. - -Cookbook: How To Use Maven Plugin Testing Harness? - - This guide is intended as a reference for those developing Maven plugins, with self-contained references and - solutions for common testing cases. - -* Prerequisites - - We assume that you have already created a plugin. In this cookbook, we make reference to <<>> in - <<>> which is generated by the Maven Archetype Plugin, i.e.: - ------ -mvn archetype:create \ - -DgroupId=org.apache.maven.plugin.my \ - -DartifactId=maven-my-plugin \ - -DarchetypeArtifactId=maven-archetype-mojo ------ - - The generated structure should be: - ------ -maven-my-plugin - |- pom.xml - +- src/ - +- main/ - +- java/ - +- org/ - +- apache/ - +- maven/ - +- plugin/ - +- my/ - |- MyMojo.java ------ - -* Recipe - -** Add <<>> dependency - - As usual, just add <<>> as following in your pom. Be sure to specify <<>> scope. - ------ - - ... - - - org.apache.maven - maven-plugin-testing-harness - test - - ... - - ... - ------ - -** Create a <<>> - - Create a <<>> (by convention) class in <<>> directory. - This class should extend <<>> from <<>>. - ------ -public class MyMojoTest - extends AbstractMojoTestCase -{ - /** {@inheritDoc} */ - protected void setUp() - throws Exception - { - // required - super.setUp(); - - ... - } - - /** {@inheritDoc} */ - protected void tearDown() - throws Exception - { - // required - super.tearDown(); - - ... - } - - /** - * @throws Exception if any - */ - public void testSomething() - throws Exception - { - File pom = getTestFile( "src/test/resources/unit/project-to-test/pom.xml" ); - assertNotNull( pom ); - assertTrue( pom.exists() ); - - MyMojo myMojo = (MyMojo) lookupMojo( "touch", pom ); - assertNotNull( myMojo ); - myMojo.execute(); - - ... - } -} ------ - - In this case, <<>> will test <<>> against a Maven project called <<>>. - - <>: By convention, Mojo unit tests should be in the test resources directory. - -** Configuring <<>> pom - - Just create a pom as usual. The names for groupId and artifactId don't really matter since this project will not be deployed. - ------ - - 4.0.0 - - org.apache.maven.plugin.my.unit - project-to-test - 1.0-SNAPSHOT - jar - Test MyMojo - - - - junit - junit - 3.8.1 - test - - - - - - - maven-my-plugin - - - target/test-harness/project-to-test - - - - - ------ - -** Execute test - - As usual, just call: - ------ -mvn test ------ - -* Resources - - [[1]] {{{http://maven.apache.org/guides/plugin/guide-java-plugin-development.html}Guide to Developing Java Plugins}} - - [[2]] {{{http://maven.apache.org/guides/mini/guide-configuring-plugins.html}Guide to Configuring Plugins}} - - [] diff --git a/maven-plugin-testing-harness/src/site/apt/index.apt b/maven-plugin-testing-harness/src/site/apt/index.apt deleted file mode 100644 index d9472a5..0000000 --- a/maven-plugin-testing-harness/src/site/apt/index.apt +++ /dev/null @@ -1,46 +0,0 @@ - ------ - Introduction - ------ - Vincent Siveton - ------ - February 2008 - ------ - -~~ Licensed to the Apache Software Foundation (ASF) under one -~~ or more contributor license agreements. See the NOTICE file -~~ distributed with this work for additional information -~~ regarding copyright ownership. The ASF licenses this file -~~ to you under the Apache License, Version 2.0 (the -~~ "License"); you may not use this file except in compliance -~~ with the License. You may obtain a copy of the License at -~~ -~~ http://www.apache.org/licenses/LICENSE-2.0 -~~ -~~ Unless required by applicable law or agreed to in writing, -~~ software distributed under the License is distributed on an -~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -~~ KIND, either express or implied. See the License for the -~~ specific language governing permissions and limitations -~~ under the License. - -Maven Plugin Testing Mechanism - - The Maven Plugin Testing Harness provides mechanisms to manage tests on Mojos, i.e. by pre-constructing the - {{{http://plexus.codehaus.org}Plexus}} components, providing stub objects for Maven functionality such as projects, - and populating fields from an XML file that resembles the plugin configuration in the POM. - - The best way to start is to read the cookbook {{{getting-started/index.html}How to use Maven Plugin Testing Harness}}. - -* Examples - - The following examples shows how to use the Testing Harness in more advanced usecases: - - * {{{examples/complex-mojo-parameters.html}Testing Complex Mojo Parameters}} - - * {{{examples/multiproject.html}Testing Multiproject}} - - * {{{examples/repositories.html}Testing Using Repositories}} - - * {{{examples/artifact.html}Testing Project Artifact}} - - [] diff --git a/maven-plugin-testing-harness/src/site/fml/faq.fml b/maven-plugin-testing-harness/src/site/fml/faq.fml deleted file mode 100644 index ed4fde4..0000000 --- a/maven-plugin-testing-harness/src/site/fml/faq.fml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - What is a Mojo Testing Harness? - -

- A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment. - A mojo unit test does not attempt to run your plugin in the context of a real Maven build. - Unit tests are designed to be fast. -

-

- This testing library is NOT designed for integration or functional testing. -

-
-
- - What kind of unit tests are supported? - -

-

-
TestCase from JUnit
-
You could use the JUnit framework to test your plugin in - the same way you'd write any other JUnit test cases, i.e. by writing a test class which extends - TestCase.
-
TestCase from Plexus
-
Mojos are written to take specific advantage of the Plexus - container. If you need Plexus container services, you could write your class which extends PlexusTestCase, - instead of TestCase.
-
TestCase from Testing Harness
-
If you need to inject Maven objects into your mojo, you could use the maven-plugin-testing-harness. - The maven-plugin-testing-harness is explicitly intended to test the - org.apache.maven.reporting.AbstractMavenReport#execute() implementation.
-
-

-
-
-
-
\ No newline at end of file diff --git a/maven-plugin-testing-harness/src/site/site.xml b/maven-plugin-testing-harness/src/site/site.xml deleted file mode 100644 index 37d8270..0000000 --- a/maven-plugin-testing-harness/src/site/site.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java deleted file mode 100644 index 75d7836..0000000 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; - -import junit.framework.TestCase; - -public class ArtifactStubFactoryTest - extends TestCase -{ - public void testVersionChecks() throws IOException - { - ArtifactStubFactory factory = new ArtifactStubFactory(); - assertTrue(factory.getReleaseArtifact().isRelease()); - assertFalse(factory.getReleaseArtifact().isSnapshot()); - assertTrue(factory.getSnapshotArtifact().isSnapshot()); - assertFalse(factory.getSnapshotArtifact().isRelease()); - } - - public void testCreateFiles() throws IOException - { - ArtifactStubFactory factory = new ArtifactStubFactory(); - assertFalse(factory.isCreateFiles()); - } -} diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java deleted file mode 100644 index e57c14d..0000000 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.codehaus.plexus.util.StringUtils; - -/** - * @author Edwin Punzalan - * @version $Id$ - */ -public class ExpressionEvaluatorMojo - extends AbstractMojo -{ - private String basedir; - - private ArtifactRepository localRepository; - - private String workdir; - - /** {@inheritDoc} */ - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( StringUtils.isEmpty( basedir ) ) - { - throw new MojoExecutionException( "basedir was not injected." ); - } - - if ( localRepository == null ) - { - throw new MojoExecutionException( "localRepository was not injected." ); - } - - if ( StringUtils.isEmpty( workdir ) ) - { - throw new MojoExecutionException( "workdir was not injected." ); - } - else if ( !workdir.startsWith( basedir ) ) - { - throw new MojoExecutionException( "workdir does not start with basedir." ); - } - } -} diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java deleted file mode 100644 index 2c8fe05..0000000 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.plugin.MojoExecutionException; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.Xpp3DomBuilder; - -import java.io.StringReader; - -/** - * @author Edwin Punzalan - * @version $Id$ - */ -public class ExpressionEvaluatorTest - extends AbstractMojoTestCase -{ - private Xpp3Dom pomDom; - - private PlexusConfiguration pluginConfiguration; - - /** {@inheritDoc} */ - protected void setUp() - throws Exception - { - super.setUp(); - - StringBuffer pom = new StringBuffer(); - - pom.append( "" ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " maven-test-mojo" ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " ${basedir}" ).append( "\n" ); - pom.append( " ${basedir}/workDirectory" ).append( "\n" ); - pom.append( " ${localRepository}" ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( "" ).append( "\n" ); - - pomDom = Xpp3DomBuilder.build( new StringReader( pom.toString() ) ); - - pluginConfiguration = extractPluginConfiguration( "maven-test-mojo", pomDom ); - } - - /** - * @throws Exception if any - */ - public void testInjection() - throws Exception - { - ExpressionEvaluatorMojo mojo = new ExpressionEvaluatorMojo(); - - mojo = (ExpressionEvaluatorMojo) configureMojo( mojo, pluginConfiguration ); - - try - { - mojo.execute(); - } - catch ( MojoExecutionException e ) - { - fail( e.getMessage() ); - } - } -} diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java deleted file mode 100644 index e3b190c..0000000 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java +++ /dev/null @@ -1,142 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.Xpp3DomBuilder; - -import java.io.StringReader; -import java.util.Map; - -/** - * @author Jason van Zyl - * @version $Id$ - */ -public class MojoTestCaseTest - extends AbstractMojoTestCase -{ - private String pom; - - private Xpp3Dom pomDom; - - private PlexusConfiguration pluginConfiguration; - - /** {@inheritDoc} */ - protected void setUp() - throws Exception - { - super.setUp(); - - pom = - "" + - "" + - "" + - "" + - "maven-simple-plugin" + - "" + - "valueOne" + - "valueTwo" + - "" + - "" + - "" + - "" + - ""; - - pomDom = Xpp3DomBuilder.build( new StringReader( pom ) ); - - pluginConfiguration = extractPluginConfiguration( "maven-simple-plugin", pomDom ); - } - - /** - * @throws Exception if any - */ - public void testPluginConfigurationExtraction() - throws Exception - { - assertEquals( "valueOne", pluginConfiguration.getChild( "keyOne" ).getValue() ); - - assertEquals( "valueTwo", pluginConfiguration.getChild( "keyTwo" ).getValue() ); - } - - /** - * @throws Exception if any - */ - public void testMojoConfiguration() - throws Exception - { - SimpleMojo mojo = new SimpleMojo(); - - mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration ); - - assertEquals( "valueOne", mojo.getKeyOne() ); - - assertEquals( "valueTwo", mojo.getKeyTwo() ); - } - - /** - * @throws Exception if any - */ - public void testVariableAccessWithoutGetter() - throws Exception - { - SimpleMojo mojo = new SimpleMojo(); - - mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration ); - - assertEquals( "valueOne", (String)getVariableValueFromObject( mojo, "keyOne" ) ); - - assertEquals( "valueTwo", (String)getVariableValueFromObject( mojo, "keyTwo" ) ); - } - - /** - * @throws Exception if any - */ - public void testVariableAccessWithoutGetter2() - throws Exception - { - SimpleMojo mojo = new SimpleMojo(); - - mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration ); - - Map map = getVariablesAndValuesFromObject( mojo ); - - assertEquals( "valueOne", (String)map.get( "keyOne" ) ); - - assertEquals( "valueTwo", (String)map.get( "keyTwo" ) ); - } - - /** - * @throws Exception if any - */ - public void testSettingMojoVariables() - throws Exception - { - SimpleMojo mojo = new SimpleMojo(); - - mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration ); - - setVariableValueToObject( mojo, "keyOne", "myValueOne" ); - - assertEquals( "myValueOne", (String)getVariableValueFromObject( mojo, "keyOne" ) ); - - } - -} diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java deleted file mode 100644 index 4a101ec..0000000 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; - -/** - * @author Jason van Zyl - * @version $Id$ - */ -public class SimpleMojo - extends AbstractMojo -{ - private String keyOne; - - private String keyTwo; - - public String getKeyOne() - { - return keyOne; - } - - public String getKeyTwo() - { - return keyTwo; - } - - public void execute() - throws MojoExecutionException - { - } -} diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java deleted file mode 100644 index 4d782df..0000000 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.apache.maven.plugin.testing; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import junit.framework.TestCase; - -import org.apache.maven.plugin.logging.Log; -import org.codehaus.plexus.logging.Logger; - -public class TestSilentLog - extends TestCase -{ - - public void testLog() - { - Log log = new SilentLog(); - String text = new String( "Text" ); - Throwable e = new RuntimeException(); - log.debug( text ); - log.debug( text, e ); - log.debug( e ); - log.info( text ); - log.info( text, e ); - log.info( e ); - log.warn( text ); - log.warn( text, e ); - log.warn( e ); - log.error( text ); - log.error( text, e ); - log.error( e ); - log.isDebugEnabled(); - log.isErrorEnabled(); - log.isWarnEnabled(); - log.isInfoEnabled(); - } - - public void testLogger() - { - Logger log = new SilentLog(); - String text = new String( "Text" ); - Throwable e = new RuntimeException(); - - log.debug( text ); - log.debug( text, e ); - log.error( text ); - log.error( text, e ); - log.warn( text ); - log.warn( text, e ); - log.info( text ); - log.info( text, e ); - - log.fatalError( text ); - log.fatalError( text, e ); - log.getChildLogger( text ); - log.getName(); - log.getThreshold(); - log.isDebugEnabled(); - log.isErrorEnabled(); - log.isFatalErrorEnabled(); - log.isInfoEnabled(); - log.isWarnEnabled(); - } - -}