Author: brianf
Date: Fri Jun 29 20:06:13 2007
New Revision: 552085
URL: http://svn.apache.org/viewvc?view=rev&rev=552085
Log:
added several stubs and utils from the dependency plugin tests that generally
allow easy creation of stub artifacts.
Added:
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactCollector.java
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactResolver.java
maven/shared/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java
Modified:
maven/shared/trunk/maven-plugin-testing-harness/pom.xml
Modified: maven/shared/trunk/maven-plugin-testing-harness/pom.xml
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-harness/pom.xml?view=diff&rev=552085&r1=552084&r2=552085
==============================================================================
--- maven/shared/trunk/maven-plugin-testing-harness/pom.xml (original)
+++ maven/shared/trunk/maven-plugin-testing-harness/pom.xml Fri Jun 29 20:06:13
2007
@@ -98,6 +98,11 @@
<artifactId>plexus-utils</artifactId>
<version>1.1</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-archiver</artifactId>
+ <version>1.0-alpha-8</version>
+ </dependency>
</dependencies>
<reporting>
<plugins>
Added:
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java?view=auto&rev=552085
==============================================================================
---
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java
(added)
+++
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java
Fri Jun 29 20:06:13 2007
@@ -0,0 +1,415 @@
+package org.apache.maven.plugin.testing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.archiver.war.WarArchiver;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.ReflectionUtils;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * This class creates artifacts to be used for testing purposes. It can
optionally create actual
+ * files on the local disk for things like copying. It can create these files
as archives with named
+ * files inside to be used for testing things like unpack.
+ *
+ * Also provided are some utility methods to quickly get a set of artifacts
distinguished by various things like
+ * group,artifact,type,scope, etc
+ *
+ * It was originally developed for the dependency plugin, but can be useful in
other plugins that
+ * need to simulate artifacts for unit tests.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a>
+ *
+ */
+public class ArtifactStubFactory
+{
+ File workingDir;
+
+ boolean createFiles;
+
+ File srcFile;
+
+ boolean createUnpackableFile;
+
+ ArchiverManager archiverManager;
+
+ public ArtifactStubFactory( File workingDir, boolean createFiles )
+ {
+ this.workingDir = new File( workingDir, "localTestRepo" );
+ this.createFiles = createFiles;
+ }
+
+ /**
+ * If set, the file will be created as a zip/jar/war with a file inside
that can be
+ * checked to exist after unpacking.
+ * @param archiverManager
+ */
+ public void setUnpackableFile( ArchiverManager archiverManager )
+ {
+ this.createUnpackableFile = true;
+ this.archiverManager = archiverManager;
+ }
+
+ public Artifact createArtifact( String groupId, String artifactId, String
version )
+ throws IOException
+ {
+ return createArtifact( groupId, artifactId, version,
Artifact.SCOPE_COMPILE, "jar", "" );
+ }
+
+ public Artifact createArtifact( String groupId, String artifactId, String
version, String scope )
+ throws IOException
+ {
+ return createArtifact( groupId, artifactId, version, scope, "jar", ""
);
+ }
+
+ public Artifact createArtifact( String groupId, String artifactId, String
version, String scope, String type,
+ String classifier )
+ throws IOException
+ {
+ VersionRange vr = VersionRange.createFromVersion( version );
+ return createArtifact( groupId, artifactId, vr, scope, type,
classifier, false );
+ }
+
+ public Artifact createArtifact( String groupId, String artifactId,
VersionRange versionRange, String scope,
+ String type, String classifier, boolean
optional )
+ throws IOException
+ {
+ ArtifactHandler ah = new DefaultArtifactHandlerStub( type, classifier
);
+
+ Artifact artifact = new DefaultArtifact( groupId, artifactId,
versionRange, scope, type, classifier, ah,
+ optional );
+ if ( createFiles )
+ {
+ setArtifactFile( artifact );
+ }
+ return artifact;
+ }
+
+ /*
+ * Creates a file that can be copied or unpacked based on the passed in
+ * artifact
+ */
+ public void setArtifactFile( Artifact artifact )
+ throws IOException
+ {
+ String fileName = getFormattedFileName( artifact, false );
+
+ File theFile = new File( this.workingDir, fileName );
+ theFile.getParentFile().mkdirs();
+
+ if ( srcFile == null )
+ {
+ theFile.createNewFile();
+ }
+ else if ( createUnpackableFile )
+ {
+ try
+ {
+ createUnpackableFile( artifact, theFile );
+ }
+ catch ( NoSuchArchiverException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch ( ArchiverException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ FileUtils.copyFile( srcFile, theFile );
+ }
+
+ artifact.setFile( theFile );
+ }
+
+ static public String getUnpackableFileName( Artifact artifact )
+ {
+ return "" + artifact.getGroupId() + "-" + artifact.getArtifactId() +
"-" + artifact.getVersion() + "-"
+ + artifact.getClassifier() + "-" + artifact.getType() + ".txt";
+ }
+
+ public void createUnpackableFile( Artifact artifact, File destFile )
+ throws NoSuchArchiverException, ArchiverException, IOException
+ {
+ Archiver archiver = archiverManager.getArchiver( destFile );
+
+ archiver.setDestFile( destFile );
+ archiver.addFile( srcFile, getUnpackableFileName( artifact ) );
+
+ try
+ {
+ setVariableValueToObject( archiver, "logger", new SilentLog() );
+ }
+ catch ( IllegalAccessException e )
+ {
+ System.out.println( "Unable to override logger with silent log." );
+ e.printStackTrace();
+ }
+ if ( archiver instanceof WarArchiver )
+ {
+ WarArchiver war = (WarArchiver) archiver;
+ // the use of this is counter-intuitive:
+ // http://jira.codehaus.org/browse/PLX-286
+ war.setIgnoreWebxml( false );
+ }
+ archiver.createArchive();
+ }
+
+ public Artifact getReleaseArtifact()
+ throws IOException
+ {
+ return createArtifact( "testGroupId", "release", "1.0" );
+ }
+
+ public Artifact getSnapshotArtifact()
+ throws IOException
+ {
+ return createArtifact( "testGroupId", "snapshot", "2.0-SNAPSHOT" );
+ }
+
+ public Set getReleaseAndSnapshotArtifacts()
+ throws IOException
+ {
+ Set set = new HashSet();
+ set.add( getReleaseArtifact() );
+ set.add( getSnapshotArtifact() );
+ return set;
+ }
+
+ public Set getScopedArtifacts()
+ throws IOException
+ {
+ Set set = new HashSet();
+ set.add( createArtifact( "g", "compile", "1.0", Artifact.SCOPE_COMPILE
) );
+ set.add( createArtifact( "g", "provided", "1.0",
Artifact.SCOPE_PROVIDED ) );
+ set.add( createArtifact( "g", "test", "1.0", Artifact.SCOPE_TEST ) );
+ set.add( createArtifact( "g", "runtime", "1.0", Artifact.SCOPE_RUNTIME
) );
+ set.add( createArtifact( "g", "system", "1.0", Artifact.SCOPE_SYSTEM )
);
+ return set;
+ }
+
+ public Set getTypedArtifacts()
+ throws IOException
+ {
+ Set set = new HashSet();
+ set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE,
"war", null ) );
+ set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE,
"jar", null ) );
+ set.add( createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE,
"sources", null ) );
+ set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE,
"zip", null ) );
+ set.add( createArtifact( "g", "e", "1.0", Artifact.SCOPE_COMPILE,
"rar", null ) );
+ return set;
+ }
+
+ public Set getClassifiedArtifacts()
+ throws IOException
+ {
+ Set set = new HashSet();
+ set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE,
"jar", "one" ) );
+ set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE,
"jar", "two" ) );
+ set.add( createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE,
"jar", "three" ) );
+ set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE,
"jar", "four" ) );
+ return set;
+ }
+
+ public Set getTypedArchiveArtifacts()
+ throws IOException
+ {
+ Set set = new HashSet();
+ set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE,
"war", null ) );
+ set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE,
"jar", null ) );
+ set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE,
"zip", null ) );
+ set.add( createArtifact( "g", "e", "1.0", Artifact.SCOPE_COMPILE,
"rar", null ) );
+ return set;
+ }
+
+ public Set getArtifactArtifacts()
+ throws IOException
+ {
+ Set set = new HashSet();
+ set.add( createArtifact( "g", "one", "1.0", Artifact.SCOPE_COMPILE,
"jar", "a" ) );
+ set.add( createArtifact( "g", "two", "1.0", Artifact.SCOPE_COMPILE,
"jar", "a" ) );
+ set.add( createArtifact( "g", "three", "1.0", Artifact.SCOPE_COMPILE,
"jar", "a" ) );
+ set.add( createArtifact( "g", "four", "1.0", Artifact.SCOPE_COMPILE,
"jar", "a" ) );
+ return set;
+ }
+
+ public Set getGroupIdArtifacts()
+ throws IOException
+ {
+ Set set = new HashSet();
+ set.add( createArtifact( "one", "group-one", "1.0",
Artifact.SCOPE_COMPILE, "jar", "a" ) );
+ set.add( createArtifact( "two", "group-two", "1.0",
Artifact.SCOPE_COMPILE, "jar", "a" ) );
+ set.add( createArtifact( "three", "group-three", "1.0",
Artifact.SCOPE_COMPILE, "jar", "a" ) );
+ set.add( createArtifact( "four", "group-four", "1.0",
Artifact.SCOPE_COMPILE, "jar", "a" ) );
+ return set;
+ }
+
+ public Set getMixedArtifacts()
+ throws IOException
+ {
+ Set set = new HashSet();
+ set.addAll( getTypedArtifacts() );
+ set.addAll( getScopedArtifacts() );
+ set.addAll( getReleaseAndSnapshotArtifacts() );
+ return set;
+ }
+
+ /**
+ * @return Returns the createFiles.
+ */
+ public boolean isCreateFiles()
+ {
+ return this.createFiles;
+ }
+
+ /**
+ * @param createFiles
+ * The createFiles to set.
+ */
+ public void setCreateFiles( boolean createFiles )
+ {
+ this.createFiles = createFiles;
+ }
+
+ /**
+ * @return Returns the workingDir.
+ */
+ public File getWorkingDir()
+ {
+ return this.workingDir;
+ }
+
+ /**
+ * @param workingDir
+ * The workingDir to set.
+ */
+ public void setWorkingDir( File workingDir )
+ {
+ this.workingDir = workingDir;
+ }
+
+ /**
+ * @return Returns the srcFile.
+ */
+ public File getSrcFile()
+ {
+ return this.srcFile;
+ }
+
+ /**
+ * @param srcFile
+ * The srcFile to set.
+ */
+ public void setSrcFile( File srcFile )
+ {
+ this.srcFile = srcFile;
+ }
+
+ /**
+ * convience method to set values to variables in objects that don't have
+ * setters
+ *
+ * @param object
+ * @param variable
+ * @param value
+ * @throws IllegalAccessException
+ */
+ public static void setVariableValueToObject( Object object, String
variable, Object value )
+ throws IllegalAccessException
+ {
+ Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(
variable, object.getClass() );
+
+ field.setAccessible( true );
+
+ field.set( object, value );
+ }
+
+ /**
+ * Builds the file name. If removeVersion is set, then the file name must
be
+ * reconstructed from the artifactId, Classifier (if used) and Type.
+ * Otherwise, this method returns the artifact file name.
+ *
+ * @param artifact
+ * File to be formatted.
+ * @param removeVersion
+ * Specifies if the version should be removed from the file
name.
+ * @return Formatted file name in the format
+ * artifactId-[version]-[classifier].[type]
+ */
+ public static String getFormattedFileName( Artifact artifact, boolean
removeVersion )
+ {
+ String destFileName = null;
+
+ // if there is a file and we aren't stripping the version, just get the
+ // name directly
+ if ( artifact.getFile() != null && !removeVersion )
+ {
+ destFileName = artifact.getFile().getName();
+ }
+ else
+ // if offline
+ {
+ String versionString = null;
+ if ( !removeVersion )
+ {
+ versionString = "-" + artifact.getVersion();
+ }
+ else
+ {
+ versionString = "";
+ }
+
+ String classifierString = "";
+
+ if ( StringUtils.isNotEmpty( artifact.getClassifier() ) )
+ {
+ classifierString = "-" + artifact.getClassifier();
+ }
+
+ destFileName = artifact.getArtifactId() + versionString +
classifierString + "."
+ + artifact.getArtifactHandler().getExtension();
+ }
+ return destFileName;
+ }
+
+}
Added:
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java?view=auto&rev=552085
==============================================================================
---
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java
(added)
+++
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java
Fri Jun 29 20:06:13 2007
@@ -0,0 +1,195 @@
+package org.apache.maven.plugin.testing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ * This logger implements both types of logs currently in use. It can be
injected where needed
+ * to turn off logs during testing where they aren't desired.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a>
+ * @version $Id: SilentLog.java 546355 2007-06-12 02:00:02Z brianf $
+ */
+public class SilentLog
+ implements Log, Logger
+{
+
+ public boolean isDebugEnabled()
+ {
+ return false;
+ }
+
+ public void debug( CharSequence content )
+ {
+ }
+
+ public void debug( CharSequence content, Throwable error )
+ {
+ }
+
+ public void debug( Throwable error )
+ {
+ }
+
+ public boolean isInfoEnabled()
+ {
+ return false;
+ }
+
+ public void info( CharSequence content )
+ {
+ }
+
+ public void info( CharSequence content, Throwable error )
+ {
+ }
+
+ public void info( Throwable error )
+ {
+ }
+
+ public boolean isWarnEnabled()
+ {
+ return false;
+ }
+
+ public void warn( CharSequence content )
+ {
+ }
+
+ public void warn( CharSequence content, Throwable error )
+ {
+ }
+
+ public void warn( Throwable error )
+ {
+ }
+
+ public boolean isErrorEnabled()
+ {
+ return false;
+ }
+
+ public void error( CharSequence content )
+ {
+ }
+
+ public void error( CharSequence content, Throwable error )
+ {
+ }
+
+ public void error( Throwable error )
+ {
+ }
+
+ public void debug( String message )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void debug( String message, Throwable throwable )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void info( String message )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void info( String message, Throwable throwable )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void warn( String message )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void warn( String message, Throwable throwable )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void error( String message )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void error( String message, Throwable throwable )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void fatalError( String message )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void fatalError( String message, Throwable throwable )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isFatalErrorEnabled()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Logger getChildLogger( String name )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getThreshold()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codehaus.plexus.logging.Logger#setThreshold(int)
+ */
+ public void setThreshold( int theThreshold )
+ {
+ // TODO Auto-generated method stub
+
+ }
+}
Added:
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java?view=auto&rev=552085
==============================================================================
---
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java
(added)
+++
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java
Fri Jun 29 20:06:13 2007
@@ -0,0 +1,192 @@
+package org.apache.maven.plugin.testing.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+/**
+ * minimal artifact handler used by the stub factory to create unpackable
archives.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a>
+ *
+ */
+public class DefaultArtifactHandlerStub
+ implements ArtifactHandler
+{
+ private String extension;
+
+ private String type;
+
+ private String classifier;
+
+ private String directory;
+
+ private String packaging;
+
+ private boolean includesDependencies;
+
+ private String language;
+
+ private boolean addedToClasspath;
+
+ public DefaultArtifactHandlerStub( String t, String c )
+ {
+ type = t;
+ classifier = c;
+ if ( t.equals( "test-jar" ) )
+ {
+ extension = "jar";
+ }
+
+ }
+
+ public DefaultArtifactHandlerStub( String type )
+ {
+ this.type = type;
+ }
+
+ public String getExtension()
+ {
+ if ( extension == null )
+ {
+ extension = type;
+ }
+ return extension;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ public String getDirectory()
+ {
+ if ( directory == null )
+ {
+ directory = getPackaging() + "s";
+ }
+ return directory;
+ }
+
+ public String getPackaging()
+ {
+ if ( packaging == null )
+ {
+ packaging = type;
+ }
+ return packaging;
+ }
+
+ public boolean isIncludesDependencies()
+ {
+ return includesDependencies;
+ }
+
+ public String getLanguage()
+ {
+ if ( language == null )
+ {
+ language = "none";
+ }
+
+ return language;
+ }
+
+ public boolean isAddedToClasspath()
+ {
+ return addedToClasspath;
+ }
+
+ /**
+ * @param theAddedToClasspath
+ * The addedToClasspath to set.
+ */
+ public void setAddedToClasspath( boolean theAddedToClasspath )
+ {
+ this.addedToClasspath = theAddedToClasspath;
+ }
+
+ /**
+ * @param theClassifier
+ * The classifier to set.
+ */
+ public void setClassifier( String theClassifier )
+ {
+ this.classifier = theClassifier;
+ }
+
+ /**
+ * @param theDirectory
+ * The directory to set.
+ */
+ public void setDirectory( String theDirectory )
+ {
+ this.directory = theDirectory;
+ }
+
+ /**
+ * @param theExtension
+ * The extension to set.
+ */
+ public void setExtension( String theExtension )
+ {
+ this.extension = theExtension;
+ }
+
+ /**
+ * @param theIncludesDependencies
+ * The includesDependencies to set.
+ */
+ public void setIncludesDependencies( boolean theIncludesDependencies )
+ {
+ this.includesDependencies = theIncludesDependencies;
+ }
+
+ /**
+ * @param theLanguage
+ * The language to set.
+ */
+ public void setLanguage( String theLanguage )
+ {
+ this.language = theLanguage;
+ }
+
+ /**
+ * @param thePackaging
+ * The packaging to set.
+ */
+ public void setPackaging( String thePackaging )
+ {
+ this.packaging = thePackaging;
+ }
+
+ /**
+ * @param theType
+ * The type to set.
+ */
+ public void setType( String theType )
+ {
+ this.type = theType;
+ }
+}
Added:
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactCollector.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactCollector.java?view=auto&rev=552085
==============================================================================
---
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactCollector.java
(added)
+++
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactCollector.java
Fri Jun 29 20:06:13 2007
@@ -0,0 +1,113 @@
+package org.apache.maven.plugin.testing.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ResolutionNode;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+
+/**
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a>
+ *
+ */
+public class StubArtifactCollector
+ implements ArtifactCollector
+{
+
+ /**
+ *
+ */
+ public StubArtifactCollector()
+ {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.maven.artifact.resolver.ArtifactCollector#collect(java.util.Set,
+ * org.apache.maven.artifact.Artifact,
+ * org.apache.maven.artifact.repository.ArtifactRepository,
+ * java.util.List,
+ * org.apache.maven.artifact.metadata.ArtifactMetadataSource,
+ * org.apache.maven.artifact.resolver.filter.ArtifactFilter,
+ * java.util.List)
+ */
+ public ArtifactResolutionResult collect( Set theArtifacts, Artifact
theOriginatingArtifact,
+ ArtifactRepository
theLocalRepository, List theRemoteRepositories,
+ ArtifactMetadataSource theSource,
ArtifactFilter theFilter,
+ List theListeners )
+ throws ArtifactResolutionException
+ {
+ Set nodes = new HashSet();
+ ArtifactResolutionResult arr = new ArtifactResolutionResult();
+
+ Iterator iter = theArtifacts.iterator();
+ while ( iter.hasNext() )
+ {
+ nodes.add( new ResolutionNode( (Artifact) iter.next(),
theRemoteRepositories ) );
+ }
+ arr.setArtifactResolutionNodes( nodes );
+ return arr;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.maven.artifact.resolver.ArtifactCollector#collect(java.util.Set,
+ * org.apache.maven.artifact.Artifact, java.util.Map,
+ * org.apache.maven.artifact.repository.ArtifactRepository,
+ * java.util.List,
+ * org.apache.maven.artifact.metadata.ArtifactMetadataSource,
+ * org.apache.maven.artifact.resolver.filter.ArtifactFilter,
+ * java.util.List)
+ */
+ public ArtifactResolutionResult collect( Set theArtifacts, Artifact
theOriginatingArtifact, Map theManagedVersions,
+ ArtifactRepository
theLocalRepository, List theRemoteRepositories,
+ ArtifactMetadataSource theSource,
ArtifactFilter theFilter,
+ List theListeners )
+ throws ArtifactResolutionException
+ {
+ Set nodes = new HashSet();
+ ArtifactResolutionResult arr = new ArtifactResolutionResult();
+
+ Iterator iter = theArtifacts.iterator();
+ while ( iter.hasNext() )
+ {
+ nodes.add( new ResolutionNode( (Artifact) iter.next(),
theRemoteRepositories ) );
+ }
+ arr.setArtifactResolutionNodes( nodes );
+ return arr;
+ }
+
+}
Added:
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java?view=auto&rev=552085
==============================================================================
---
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java
(added)
+++
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java
Fri Jun 29 20:06:13 2007
@@ -0,0 +1,121 @@
+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;
+
+public class StubArtifactRepository
+ implements ArtifactRepository
+{
+ String baseDir = null;
+
+ public StubArtifactRepository( String dir )
+ {
+ baseDir = dir;
+ }
+
+ public String pathOf( Artifact artifact )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String pathOfRemoteRepositoryMetadata( ArtifactMetadata
artifactMetadata )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata,
ArtifactRepository repository )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getUrl()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getBasedir()
+ {
+ return baseDir;
+ }
+
+ public String getProtocol()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getId()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArtifactRepositoryPolicy getSnapshots()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArtifactRepositoryPolicy getReleases()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArtifactRepositoryLayout getLayout()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getKey()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isUniqueVersion()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setBlacklisted( boolean blackListed )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isBlacklisted()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
Added:
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactResolver.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactResolver.java?view=auto&rev=552085
==============================================================================
---
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactResolver.java
(added)
+++
maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactResolver.java
Fri Jun 29 20:06:13 2007
@@ -0,0 +1,162 @@
+package org.apache.maven.plugin.testing.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.plugin.testing.ArtifactStubFactory;
+
+/**
+ * Stub resolver. The constructor allows the specification of the exception to
throw so that handling can be tested too.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a>
+ *
+ */
+public class StubArtifactResolver
+ implements ArtifactResolver
+{
+
+ boolean throwArtifactResolutionException;
+
+ boolean throwArtifactNotFoundException;
+
+ ArtifactStubFactory factory;
+
+ public StubArtifactResolver( ArtifactStubFactory factory, boolean
throwArtifactResolutionException,
+ boolean throwArtifactNotFoundException )
+ {
+ this.throwArtifactNotFoundException = throwArtifactNotFoundException;
+ this.throwArtifactResolutionException =
throwArtifactResolutionException;
+ this.factory = factory;
+ }
+
+ /*
+ * Creates dummy file and sets it in the artifact to simulate resolution
+ * (non-Javadoc)
+ *
+ * @see
org.apache.maven.artifact.resolver.ArtifactResolver#resolve(org.apache.maven.artifact.Artifact,
+ * java.util.List,
+ * org.apache.maven.artifact.repository.ArtifactRepository)
+ */
+ public void resolve( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository )
+ throws ArtifactResolutionException, ArtifactNotFoundException
+ {
+ if ( !this.throwArtifactNotFoundException &&
!this.throwArtifactResolutionException )
+ {
+ try
+ {
+ if ( factory != null )
+ {
+ factory.setArtifactFile( artifact );
+ }
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ if ( throwArtifactResolutionException )
+ {
+ throw new ArtifactResolutionException( "Catch!", artifact );
+ }
+ else
+ {
+ throw new ArtifactNotFoundException( "Catch!", artifact );
+ }
+ }
+ }
+
+ public ArtifactResolutionResult resolveTransitively( Set artifacts,
Artifact originatingArtifact,
+ List
remoteRepositories, ArtifactRepository localRepository,
+ ArtifactMetadataSource
source )
+ throws ArtifactResolutionException, ArtifactNotFoundException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArtifactResolutionResult resolveTransitively( Set artifacts,
Artifact originatingArtifact,
+ List
remoteRepositories, ArtifactRepository localRepository,
+ ArtifactMetadataSource
source, List listeners )
+ throws ArtifactResolutionException, ArtifactNotFoundException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArtifactResolutionResult resolveTransitively( Set artifacts,
Artifact originatingArtifact,
+ ArtifactRepository
localRepository, List remoteRepositories,
+ ArtifactMetadataSource
source, ArtifactFilter filter )
+ throws ArtifactResolutionException, ArtifactNotFoundException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArtifactResolutionResult resolveTransitively( Set artifacts,
Artifact originatingArtifact,
+ Map managedVersions,
ArtifactRepository localRepository,
+ List
remoteRepositories, ArtifactMetadataSource source )
+ throws ArtifactResolutionException, ArtifactNotFoundException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArtifactResolutionResult resolveTransitively( Set artifacts,
Artifact originatingArtifact,
+ Map managedVersions,
ArtifactRepository localRepository,
+ List
remoteRepositories, ArtifactMetadataSource source,
+ ArtifactFilter filter )
+ throws ArtifactResolutionException, ArtifactNotFoundException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArtifactResolutionResult resolveTransitively( Set artifacts,
Artifact originatingArtifact,
+ Map managedVersions,
ArtifactRepository localRepository,
+ List
remoteRepositories, ArtifactMetadataSource source,
+ ArtifactFilter filter,
List listeners )
+ throws ArtifactResolutionException, ArtifactNotFoundException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void resolveAlways( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository )
+ throws ArtifactResolutionException, ArtifactNotFoundException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added:
maven/shared/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java?view=auto&rev=552085
==============================================================================
---
maven/shared/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java
(added)
+++
maven/shared/trunk/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java
Fri Jun 29 20:06:13 2007
@@ -0,0 +1,81 @@
+package org.apache.maven.plugin.testing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.logging.Logger;
+
+public class TestSilentLog
+ extends TestCase
+{
+
+ public void testLog()
+ {
+ Log log = new SilentLog();
+ String text = new String( "Text" );
+ Throwable e = new RuntimeException();
+ log.debug( text );
+ log.debug( text, e );
+ log.debug( e );
+ log.info( text );
+ log.info( text, e );
+ log.info( e );
+ log.warn( text );
+ log.warn( text, e );
+ log.warn( e );
+ log.error( text );
+ log.error( text, e );
+ log.error( e );
+ log.isDebugEnabled();
+ log.isErrorEnabled();
+ log.isWarnEnabled();
+ log.isInfoEnabled();
+ }
+
+ public void testLogger()
+ {
+ Logger log = new SilentLog();
+ String text = new String( "Text" );
+ Throwable e = new RuntimeException();
+
+ log.debug( text );
+ log.debug( text, e );
+ log.error( text );
+ log.error( text, e );
+ log.warn( text );
+ log.warn( text, e );
+ log.info( text );
+ log.info( text, e );
+
+ log.fatalError( text );
+ log.fatalError( text, e );
+ log.getChildLogger( text );
+ log.getName();
+ log.getThreshold();
+ log.isDebugEnabled();
+ log.isErrorEnabled();
+ log.isFatalErrorEnabled();
+ log.isInfoEnabled();
+ log.isWarnEnabled();
+ }
+
+}