Author: brianf Date: Sat Dec 29 20:10:52 2007 New Revision: 607510 URL: http://svn.apache.org/viewvc?rev=607510&view=rev Log: fixed a bug with isRelease and isSnapshot; added a few unit tests.
Added: maven/plugin-tools/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java Modified: maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java Modified: maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java?rev=607510&r1=607509&r2=607510&view=diff ============================================================================== --- maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java (original) +++ maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java Sat Dec 29 20:10:52 2007 @@ -40,17 +40,13 @@ 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. + * 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. * - * Also provided are some utility methods to quickly get a set of artifacts distinguished by various things like - * group,artifact,type,scope, etc - * - * It was originally developed for the dependency plugin, but can be useful in other plugins that - * need to simulate artifacts for unit tests. * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a> - * */ public class ArtifactStubFactory { @@ -66,16 +62,16 @@ /** * 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 */ @@ -86,8 +82,9 @@ } /** - * If set, the file will be created as a zip/jar/war with a file inside that can be - * checked to exist after unpacking. + * 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 ) @@ -109,7 +106,7 @@ } public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type, - String classifier ) + String classifier ) throws IOException { VersionRange vr = VersionRange.createFromVersion( version ); @@ -117,13 +114,17 @@ } public Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, - String type, String classifier, boolean optional ) + 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 ); + 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 ); @@ -132,17 +133,16 @@ } /* - * Creates a file that can be copied or unpacked based on the passed in - * artifact + * Creates a file that can be copied or unpacked based on the passed in artifact */ public void setArtifactFile( Artifact artifact ) throws IOException { - if (this.workingDir == null ) + if ( this.workingDir == null ) { - throw new IllegalArgumentException("The workingDir must be set if createFiles is true."); + throw new IllegalArgumentException( "The workingDir must be set if createFiles is true." ); } - + String fileName = getFormattedFileName( artifact, false ); File theFile = new File( this.workingDir, fileName ); @@ -184,8 +184,8 @@ static public String getUnpackableFileName( Artifact artifact ) { - return "" + artifact.getGroupId() + "-" + artifact.getArtifactId() + "-" + artifact.getVersion() + "-" - + artifact.getClassifier() + "-" + artifact.getType() + ".txt"; + return "" + artifact.getGroupId() + "-" + artifact.getArtifactId() + "-" + artifact.getVersion() + "-" + + artifact.getClassifier() + "-" + artifact.getType() + ".txt"; } public void createUnpackableFile( Artifact artifact, File destFile ) @@ -323,8 +323,7 @@ } /** - * @param createFiles - * The createFiles to set. + * @param createFiles The createFiles to set. */ public void setCreateFiles( boolean createFiles ) { @@ -340,8 +339,7 @@ } /** - * @param workingDir - * The workingDir to set. + * @param workingDir The workingDir to set. */ public void setWorkingDir( File workingDir ) { @@ -357,8 +355,7 @@ } /** - * @param srcFile - * The srcFile to set. + * @param srcFile The srcFile to set. */ public void setSrcFile( File srcFile ) { @@ -366,8 +363,7 @@ } /** - * convience method to set values to variables in objects that don't have - * setters + * convience method to set values to variables in objects that don't have setters * * @param object * @param variable @@ -383,18 +379,14 @@ 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. + * 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] + * @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 ) { @@ -426,10 +418,11 @@ classifierString = "-" + artifact.getClassifier(); } - destFileName = artifact.getArtifactId() + versionString + classifierString + "." - + artifact.getArtifactHandler().getExtension(); + destFileName = + artifact.getArtifactId() + versionString + classifierString + "." + + artifact.getArtifactHandler().getExtension(); } return destFileName; } - + } Modified: maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java?rev=607510&r1=607509&r2=607510&view=diff ============================================================================== --- maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java (original) +++ maven/plugin-tools/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java Sat Dec 29 20:10:52 2007 @@ -385,7 +385,8 @@ */ public boolean isSnapshot() { - return false; + return Artifact.VERSION_FILE_PATTERN.matcher( version ).matches() || + version.endsWith( Artifact.SNAPSHOT_VERSION ); } /** @@ -435,7 +436,7 @@ */ public boolean isRelease() { - return false; + return !isSnapshot(); } /** Added: maven/plugin-tools/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java?rev=607510&view=auto ============================================================================== --- maven/plugin-tools/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java (added) +++ maven/plugin-tools/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java Sat Dec 29 20:10:52 2007 @@ -0,0 +1,26 @@ +package org.apache.maven.plugin.testing; + +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()); + factory.getReleaseArtifact(); + } +}