made a copy
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/branches/maven-dependency-plugin-copy-refactor@480814 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..b5dd759
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,9 @@
+Maven Dependency Plugin
+ Copyright 1999-2006 The Apache Software Foundation
+
+ This product includes software developed at
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Portions of this software utilize the Plexus Container, API, and
+ Components. Copyright the Codehaus. The original software is
+ available from http://plexus.codehaus.org/
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java b/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
index 2727505..c172c51 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
@@ -111,7 +111,7 @@
* @since 2.0
* @parameter expression="${silent}" default-value="false"
*/
- protected boolean silent;
+ public boolean silent;
/**
* Output absolute filename for resolved artifacts
@@ -224,4 +224,83 @@
}
}
+ /**
+ * @return Returns the factory.
+ */
+ public org.apache.maven.artifact.factory.ArtifactFactory getFactory()
+ {
+ return this.factory;
+ }
+
+ /**
+ * @param factory The factory to set.
+ */
+ public void setFactory( org.apache.maven.artifact.factory.ArtifactFactory factory )
+ {
+ this.factory = factory;
+ }
+
+ /**
+ * @return Returns the project.
+ */
+ public MavenProject getProject()
+ {
+ return this.project;
+ }
+
+ /**
+ * @return Returns the local.
+ */
+ public org.apache.maven.artifact.repository.ArtifactRepository getLocal()
+ {
+ return this.local;
+ }
+
+ /**
+ * @param local The local to set.
+ */
+ public void setLocal( org.apache.maven.artifact.repository.ArtifactRepository local )
+ {
+ this.local = local;
+ }
+
+ /**
+ * @return Returns the remoteRepos.
+ */
+ public java.util.List getRemoteRepos()
+ {
+ return this.remoteRepos;
+ }
+
+ /**
+ * @param remoteRepos The remoteRepos to set.
+ */
+ public void setRemoteRepos( java.util.List remoteRepos )
+ {
+ this.remoteRepos = remoteRepos;
+ }
+
+ /**
+ * @return Returns the resolver.
+ */
+ public org.apache.maven.artifact.resolver.ArtifactResolver getResolver()
+ {
+ return this.resolver;
+ }
+
+ /**
+ * @param resolver The resolver to set.
+ */
+ public void setResolver( org.apache.maven.artifact.resolver.ArtifactResolver resolver )
+ {
+ this.resolver = resolver;
+ }
+
+ /**
+ * @param archiverManager The archiverManager to set.
+ */
+ public void setArchiverManager( ArchiverManager archiverManager )
+ {
+ this.archiverManager = archiverManager;
+ }
}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
index f66e561..0e5184f 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
@@ -30,6 +30,9 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.dependency.AbstractDependencyMojo;
+import org.apache.maven.plugin.dependency.utils.DependencyUtil;
+import org.apache.maven.plugin.dependency.utils.filters.ArtifactItemFilter;
+import org.codehaus.plexus.util.StringUtils;
/**
* Abstract Parent class used by mojos that get Artifact information from the
@@ -55,6 +58,7 @@
/**
* Overwrite release artifacts
+ *
* @optional
* @since 1.0
* @parameter expression="${overWriteReleases}" default-value="false"
@@ -63,14 +67,16 @@
/**
* Overwrite snapshot artifacts
+ *
* @optional
* @since 1.0
* @parameter expression="${overWriteSnapshots}" default-value="false"
*/
protected boolean overWriteSnapshots;
-
+
/**
* Overwrite if newer
+ *
* @optional
* @since 2.0
* @parameter expression="${overIfNewer}" default-value="true"
@@ -86,13 +92,17 @@
* @required
* @since 1.0
*/
- private ArrayList artifactItems;
+ protected ArrayList artifactItems;
+
+ abstract ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item );
/**
* Preprocesses the list of ArtifactItems. This method defaults the
* outputDirectory if not set and creates the output Directory if it doesn't
* exist.
*
+ * @param removeVersion
+ * remove the version from the filename.
* @return An ArrayList of preprocessed ArtifactItems
*
* @throws MojoExecutionException
@@ -100,9 +110,13 @@
*
* @see ArtifactItem
*/
- protected ArrayList getArtifactItems()
+ protected ArrayList getArtifactItems( boolean removeVersion )
throws MojoExecutionException
{
+ if ( artifactItems == null || artifactItems.size() < 1 )
+ {
+ throw new MojoExecutionException( "There are no artifactItems configured." );
+ }
Iterator iter = artifactItems.iterator();
while ( iter.hasNext() )
@@ -116,22 +130,44 @@
}
artifactItem.getOutputDirectory().mkdirs();
+ // make sure we have a version.
+ if ( StringUtils.isEmpty( artifactItem.getVersion() ) )
+ {
+ fillMissingArtifactVersion( artifactItem );
+ }
+
artifactItem.setArtifact( this.getArtifact( artifactItem ) );
- //TODO:refactor this
- String overWrite = artifactItem.getOverWrite();
- if ( overWrite == null )
+ if ( StringUtils.isEmpty( artifactItem.getDestFileName() ) )
{
- artifactItem.setDoOverWrite(false);
- }
- else
- {
- artifactItem.setDoOverWrite( overWrite.equalsIgnoreCase( "true" ) );
- }
+ artifactItem.setDestFileName( DependencyUtil.getFormattedFileName( artifactItem.getArtifact(),
+ removeVersion ) );
+ }
+
+ artifactItem.setNeedsProcessing(checkIfProcessingNeeded(artifactItem));
}
return artifactItems;
}
+ private boolean checkIfProcessingNeeded(ArtifactItem item) throws MojoExecutionException
+ {
+ boolean result = false;
+ if ( StringUtils.equalsIgnoreCase( item.getOverWrite(), "true" ) )
+ {
+ result = true;
+ }
+ else if (StringUtils.equalsIgnoreCase( item.getOverWrite(), "false" ))
+ {
+ result = false;
+ }
+ else
+ {
+ ArtifactItemFilter filter = getMarkedArtifactFilter( item );
+ result = filter.okToProcess( item );
+ }
+ return result;
+ }
+
/**
* Resolves the Artifact from the remote repository if nessessary. If no
* version is specified, it will be retrieved from the dependency list or
@@ -151,23 +187,7 @@
{
Artifact artifact;
- if ( artifactItem.getVersion() == null )
- {
- fillMissingArtifactVersion( artifactItem );
-
- if ( artifactItem.getVersion() == null )
- {
- throw new MojoExecutionException( "Unable to find artifact version of " + artifactItem.getGroupId()
- + ":" + artifactItem.getArtifactId()
- + " in either dependency list or in project's dependency management." );
- }
-
- }
-
- // use classifer if set.
- String classifier = artifactItem.getClassifier();
-
- if ( classifier == null || classifier.equals( "" ) )
+ if ( StringUtils.isEmpty( artifactItem.getClassifier() ) )
{
artifact = factory.createArtifact( artifactItem.getGroupId(), artifactItem.getArtifactId(), artifactItem
.getVersion(), Artifact.SCOPE_PROVIDED, artifactItem.getType() );
@@ -201,47 +221,47 @@
*
* @param artifact
* representing configured file.
+ * @throws MojoExecutionException
*/
private void fillMissingArtifactVersion( ArtifactItem artifact )
+ throws MojoExecutionException
{
- // this.getLog().debug(
- // "Attempting to find missing version in " + artifact.getGroupId() + ":"
- // + artifact.getArtifactId() );
+ if ( !findDependencyVersion( artifact, project.getDependencies() )
+ && !findDependencyVersion( artifact, project.getDependencyManagement().getDependencies() ) )
+ {
+ throw new MojoExecutionException( "Unable to find artifact version of " + artifact.getGroupId() + ":"
+ + artifact.getArtifactId() + " in either dependency list or in project's dependency management." );
+ }
+ }
- List list = this.project.getDependencies();
-
- for ( int i = 0; i < list.size(); ++i )
+ /**
+ * Tries to find missing version from a list of dependencies. If found, the
+ * artifact is updated with the correct version.
+ *
+ * @param artifact
+ * representing configured file.
+ * @param list
+ * list of dependencies to search.
+ * @returns the found dependency
+ */
+ private boolean findDependencyVersion( ArtifactItem artifact, List list )
+ {
+ boolean result = false;
+ for ( int i = 0; i < list.size(); i++ )
{
Dependency dependency = (Dependency) list.get( i );
-
- if ( dependency.getGroupId().equals( artifact.getGroupId() )
- && dependency.getArtifactId().equals( artifact.getArtifactId() )
- && dependency.getType().equals( artifact.getType() ) )
+ if ( StringUtils.equals( dependency.getArtifactId(), artifact.getArtifactId() )
+ && StringUtils.equals( dependency.getGroupId(), artifact.getGroupId() )
+ && StringUtils.equals( dependency.getClassifier(), artifact.getClassifier() )
+ && StringUtils.equals( dependency.getType(), artifact.getType() ) )
{
-// this.getLog().debug( "Found missing version: " + dependency.getVersion() + " in dependency list." );
artifact.setVersion( dependency.getVersion() );
- return;
+ result = true;
+ break;
}
}
-
- list = this.project.getDependencyManagement().getDependencies();
-
- for ( int i = 0; i < list.size(); ++i )
- {
- Dependency dependency = (Dependency) list.get( i );
-
- if ( dependency.getGroupId().equals( artifact.getGroupId() )
- && dependency.getArtifactId().equals( artifact.getArtifactId() )
- && dependency.getType().equals( artifact.getType() ) )
- {
- // this.getLog().debug(
- // "Found missing version: " + dependency.getVersion()
- // + " in dependency management list" );
-
- artifact.setVersion( dependency.getVersion() );
- }
- }
+ return result;
}
}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
index 66ab7d3..3b5d6d0 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
@@ -22,10 +22,12 @@
import java.io.File;
import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.StringUtils;
/**
* ArtifactItem represents information specified in the plugin configuration
* section for each artifact.
+ *
* @since 1.0
* @author brianf
*/
@@ -91,13 +93,39 @@
/**
* Force Overwrite
*/
- private boolean doOverWrite;
-
+ private boolean needsProcessing;
+
/**
* Artifact Item
*/
private Artifact artifact;
+ public ArtifactItem()
+ {
+ // default constructor
+ }
+
+ public ArtifactItem( Artifact artifact )
+ {
+ this.setArtifact(artifact);
+ this.setArtifactId(artifact.getArtifactId());
+ this.setClassifier(artifact.getClassifier());
+ this.setGroupId(artifact.getGroupId());
+ this.setType(artifact.getType());
+ this.setVersion(artifact.getVersion());
+ }
+
+ private final String filterEmptyString(String in)
+ {
+ if (in == null || in.equals(""))
+ {
+ return null;
+ }
+ else
+ {
+ return in;
+ }
+ }
/**
* @return Returns the artifactId.
*/
@@ -112,7 +140,7 @@
*/
public void setArtifactId( String artifact )
{
- this.artifactId = artifact;
+ this.artifactId = filterEmptyString(artifact);
}
/**
@@ -129,7 +157,7 @@
*/
public void setGroupId( String groupId )
{
- this.groupId = groupId;
+ this.groupId = filterEmptyString(groupId);
}
/**
@@ -146,7 +174,7 @@
*/
public void setType( String type )
{
- this.type = type;
+ this.type = filterEmptyString(type);
}
/**
@@ -163,7 +191,7 @@
*/
public void setVersion( String version )
{
- this.version = version;
+ this.version = filterEmptyString(version);
}
/**
@@ -180,19 +208,18 @@
*/
public void setClassifier( String classifier )
{
- this.classifier = classifier;
+ this.classifier = filterEmptyString(classifier);
}
public String toString()
{
- String ver = (version == null)? "?" : version;
- if (this.classifier == null)
+ if ( this.classifier == null )
{
- return groupId + ":" + artifactId + ":" + ver + ":" + type;
+ return groupId + ":" + artifactId + ":" + StringUtils.defaultString(version,"?") + ":" + type;
}
else
{
- return groupId + ":" + artifactId + ":" + classifier + ":" + ver + ":" + type;
+ return groupId + ":" + artifactId + ":" + classifier + ":" + StringUtils.defaultString(version,"?") + ":" + type;
}
}
@@ -227,24 +254,24 @@
*/
public void setDestFileName( String destFileName )
{
- this.destFileName = destFileName;
+ this.destFileName = filterEmptyString(destFileName);
}
/**
- * @return Returns the doOverWrite.
+ * @return Returns the needsProcessing.
*/
- public boolean isDoOverWrite()
+ public boolean isNeedsProcessing()
{
- return this.doOverWrite;
+ return this.needsProcessing;
}
/**
- * @param doOverWrite
- * The doOverWrite to set.
+ * @param needsProcessing
+ * The needsProcessing to set.
*/
- public void setDoOverWrite( boolean doOverWrite )
+ public void setNeedsProcessing( boolean needsProcessing )
{
- this.doOverWrite = doOverWrite;
+ this.needsProcessing = needsProcessing;
}
/**
diff --git a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java
index 1310801..98672ca 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.maven.plugin.dependency.fromConfiguration;
import java.io.File;
@@ -27,6 +26,8 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
+import org.apache.maven.plugin.dependency.utils.filters.DestFileFilter;
+import org.apache.maven.plugin.dependency.utils.filters.ArtifactItemFilter;
import org.apache.maven.plugin.logging.Log;
/**
@@ -64,12 +65,19 @@
public void execute()
throws MojoExecutionException
{
- ArrayList artifactItems = getArtifactItems();
- Iterator iter = artifactItems.iterator();
+ ArrayList theArtifactItems = getArtifactItems( this.stripVersion );
+ Iterator iter = theArtifactItems.iterator();
while ( iter.hasNext() )
{
ArtifactItem artifactItem = (ArtifactItem) iter.next();
- copyArtifact( artifactItem, this.stripVersion );
+ if (artifactItem.isNeedsProcessing())
+ {
+ copyArtifact( artifactItem);
+ }
+ else
+ {
+ this.getLog().info(artifactItem+" already exists in "+ artifactItem.getOutputDirectory());
+ }
}
}
@@ -79,55 +87,42 @@
*
* @param artifactItem
* containing the information about the Artifact to copy.
- * @param removeVersion
- * specifies if the version should be removed from the file name
- * when copying.
* @throws MojoExecutionException
* with a message if an error occurs.
*
* @see DependencyUtil#copyFile(File, File, Log)
* @see DependencyUtil#getFormattedFileName(Artifact, boolean)
*/
- protected void copyArtifact( ArtifactItem artifactItem, boolean removeVersion )
+ protected void copyArtifact( ArtifactItem artifactItem )
throws MojoExecutionException
{
- Artifact artifact = artifactItem.getArtifact();
+ File destFile = new File( artifactItem.getOutputDirectory(), artifactItem.getDestFileName() );
- String destFileName = null;
- if ( artifactItem.getDestFileName() != null )
- {
- destFileName = artifactItem.getDestFileName();
- }
- else
- {
- destFileName = DependencyUtil.getFormattedFileName( artifact, removeVersion );
- }
+ copyFile( artifactItem.getArtifact().getFile(), destFile );
+ }
- File destFile = new File( artifactItem.getOutputDirectory(), destFileName );
+ protected ArtifactItemFilter getMarkedArtifactFilter(ArtifactItem item)
+ {
+ ArtifactItemFilter destinationNameOverrideFilter = new DestFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer,
+ false, false, this.stripVersion,
+ item.getOutputDirectory() );
+ return destinationNameOverrideFilter;
+ }
+
+ /**
+ * @return Returns the stripVersion.
+ */
+ public boolean isStripVersion()
+ {
+ return this.stripVersion;
+ }
- // TODO: refactor this to use the filters.
- if ( !artifactItem.isDoOverWrite() )
- {
- if ( artifactItem.getArtifact().isSnapshot() )
- {
- artifactItem.setDoOverWrite( this.overWriteSnapshots );
- }
- else
- {
- artifactItem.setDoOverWrite( this.overWriteReleases );
- }
- }
-
- File artifactFile = artifact.getFile();
- if ( artifactItem.isDoOverWrite()
- || ( !destFile.exists() || ( overWriteIfNewer && artifactFile.lastModified() < destFile.lastModified() ) ) )
- {
- copyFile( artifactFile, destFile );
- }
- else
- {
- this.getLog().info( artifactFile + " already exists." );
- }
+ /**
+ * @param stripVersion The stripVersion to set.
+ */
+ public void setStripVersion( boolean stripVersion )
+ {
+ this.stripVersion = stripVersion;
}
}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
index 76a07c1..3e5c4b9 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.maven.plugin.dependency.fromConfiguration;
import java.io.File;
@@ -27,6 +26,8 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
+import org.apache.maven.plugin.dependency.utils.filters.ArtifactsFilter;
+import org.apache.maven.plugin.dependency.utils.filters.ArtifactItemFilter;
import org.apache.maven.plugin.dependency.utils.filters.MarkerFileFilter;
import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
import org.apache.maven.plugin.dependency.utils.markers.MarkerHandler;
@@ -67,12 +68,19 @@
public void execute()
throws MojoExecutionException
{
- ArrayList artifactItems = getArtifactItems();
+ ArrayList artifactItems = getArtifactItems( false );
Iterator iter = artifactItems.iterator();
while ( iter.hasNext() )
{
ArtifactItem artifactItem = (ArtifactItem) iter.next();
+ if (artifactItem.isNeedsProcessing())
+ {
unpackArtifact( artifactItem );
+ }
+ else
+ {
+ this.getLog().info( artifactItem.getArtifact().getFile().getName() + " already unpacked." );
+ }
}
}
@@ -95,17 +103,15 @@
Artifact artifact = artifactItem.getArtifact();
MarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory );
- MarkerFileFilter filter = new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots,
- this.overWriteIfNewer, handler );
- if (artifactItem.isDoOverWrite() || filter.okToProcess(artifact))
- {
- unpack(artifact.getFile(),artifactItem.getOutputDirectory());
- handler.setMarker();
- }
- else
- {
- this.getLog().info( artifact.getFile().getName() + " already unpacked." );
- }
+ unpack( artifact.getFile(), artifactItem.getOutputDirectory() );
+ handler.setMarker();
+
+ }
+
+ ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
+ {
+ // TODO Auto-generated method stub
+ return null;
}
}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java b/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java
index f275f68..80193e5 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java
@@ -47,39 +47,35 @@
public static String getFormattedFileName( Artifact artifact, boolean removeVersion )
{
String destFileName = null;
+ String versionString = null;
if ( !removeVersion )
{
- File file = artifact.getFile();
- if ( file != null )
- {
- destFileName = file.getName();
- }
- // so it can be used offline
- else
- {
- if ( StringUtils.isNotEmpty( artifact.getClassifier() ) )
- {
- destFileName = artifact.getArtifactId() + "-" + artifact.getClassifier() + "-"
- + artifact.getVersion() + "." + artifact.getType();
- }
- else
- {
- destFileName = artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getType();
- }
- }
-
+ versionString = "-" + artifact.getVersion();
}
else
{
- if ( artifact.getClassifier() != null )
+ versionString = "";
+ }
+
+ File file = artifact.getFile();
+ if ( file != null )
+ {
+ destFileName = file.getName();
+ }
+ // so it can be used offline
+ else
+ {
+ if ( StringUtils.isNotEmpty( artifact.getClassifier() ) )
{
- destFileName = artifact.getArtifactId() + "-" + artifact.getClassifier() + "." + artifact.getType();
+ destFileName = artifact.getArtifactId() + "-" + artifact.getClassifier() + versionString + "."
+ + artifact.getType();
}
else
{
- destFileName = artifact.getArtifactId() + "." + artifact.getType();
+ destFileName = artifact.getArtifactId() + versionString + "." + artifact.getType();
}
}
+
return destFileName;
}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/AbstractArtifactFeatureFilter.java b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/AbstractArtifactFeatureFilter.java
index 33c30d4..6355425 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/AbstractArtifactFeatureFilter.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/AbstractArtifactFeatureFilter.java
@@ -20,6 +20,7 @@
package org.apache.maven.plugin.dependency.utils.filters;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.util.StringUtils;
@@ -34,7 +35,9 @@
*
* @author <a href="richardv@mxtelecom.com">Richard van der Hoff</a>
*/
-public abstract class AbstractArtifactFeatureFilter implements ArtifactsFilter {
+public abstract class AbstractArtifactFeatureFilter
+ extends AbstractArtifactsFilter
+{
/** The list of types or classifiers to include */
private List includes;
@@ -46,17 +49,20 @@
/** The configuration string for the exclude list - comma separated */
private String excludeString;
-
- /** The name of the feature we are filtering on - for logging - "Classifiers" or "Types" */
+
+ /**
+ * The name of the feature we are filtering on - for logging - "Classifiers"
+ * or "Types"
+ */
private String featureName;
-
+
public AbstractArtifactFeatureFilter( String include, String exclude, String featureName )
{
setExcludes( exclude );
setIncludes( include );
this.featureName = featureName;
}
-
+
/**
* This function determines if filtering needs to be performed. Excludes are
* ignored if Includes are used.
@@ -72,14 +78,14 @@
if ( this.includes != null && !this.includes.isEmpty() )
{
- log.debug( "Including only "+featureName+": " + this.includeString );
+ log.debug( "Including only " + featureName + ": " + this.includeString );
results = filterIncludes( artifacts, this.includes );
}
else
{
if ( this.excludes != null && !this.excludes.isEmpty() )
{
- log.debug( "Excluding "+featureName+": " + this.excludeString );
+ log.debug( "Excluding " + featureName + ": " + this.excludeString );
results = filterExcludes( artifacts, this.excludes );
}
}
@@ -110,9 +116,10 @@
{
Artifact artifact = (Artifact) iter.next();
- // if the classifier or type of the artifact matches the feature to include, add to the
+ // if the classifier or type of the artifact matches the feature
+ // to include, add to the
// results
- if ( getArtifactFeature(artifact).equals( include ) )
+ if ( getArtifactFeature( artifact ).equals( include ) )
{
result.add( artifact );
}
@@ -141,7 +148,7 @@
{
boolean exclude = false;
Artifact artifact = (Artifact) iter.next();
- String artifactFeature = getArtifactFeature(artifact);
+ String artifactFeature = getArtifactFeature( artifact );
// look through all types or classifiers. If no matches are found
// then it can be added to the results.
@@ -165,15 +172,15 @@
return result;
}
-
-
/**
- * Should return the type or classifier of the given artifact, so that we can filter it
+ * Should return the type or classifier of the given artifact, so that we
+ * can filter it
*
- * @param artifact artifact to return type or classifier of
+ * @param artifact
+ * artifact to return type or classifier of
* @return type or classifier
*/
- protected abstract String getArtifactFeature(Artifact artifact);
+ protected abstract String getArtifactFeature( Artifact artifact );
public void setExcludes( String excludeString )
{
@@ -185,7 +192,6 @@
}
}
-
public void setIncludes( String includeString )
{
this.includeString = includeString;
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/AbstractArtifactsFilter.java b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/AbstractArtifactsFilter.java
new file mode 100644
index 0000000..8e9a6e0
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/AbstractArtifactsFilter.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.dependency.utils.filters;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+
+public abstract class AbstractArtifactsFilter
+ implements ArtifactsFilter
+{
+
+ public boolean okToProcess( Artifact artifact, Log log )
+ throws MojoExecutionException
+ {
+ Set set = new HashSet();
+ set.add( artifact );
+
+ set = filter( set, log );
+ return set.contains( artifact );
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ArtifactItemFilter.java b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ArtifactItemFilter.java
new file mode 100644
index 0000000..f668501
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ArtifactItemFilter.java
@@ -0,0 +1,34 @@
+ /*
+ * 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.
+ */
+/**
+ *
+ */
+package org.apache.maven.plugin.dependency.utils.filters;
+
+import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem;
+
+/**
+ * @author brianf
+ *
+ */
+public interface ArtifactItemFilter
+{
+
+ public boolean okToProcess ( ArtifactItem item);
+}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ArtifactsFilter.java b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ArtifactsFilter.java
index 212a6a8..69f3b52 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ArtifactsFilter.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ArtifactsFilter.java
@@ -24,6 +24,7 @@
import java.util.Set;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
@@ -36,4 +37,6 @@
public Set filter( Set artifacts, Log log )
throws MojoExecutionException;
+ public boolean okToProcess( Artifact artifact, Log log )
+ throws MojoExecutionException;
}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/DestFileFilter.java b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/DestFileFilter.java
index 576e40b..d4f5128 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/DestFileFilter.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/DestFileFilter.java
@@ -29,15 +29,18 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem;
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.StringUtils;
/**
* @author brianf
*
*/
public class DestFileFilter
- implements ArtifactsFilter
+ extends AbstractArtifactsFilter
+ implements ArtifactItemFilter
{
boolean overWriteReleases;
@@ -54,7 +57,7 @@
File outputFileDirectory;
- public DestFileFilter (File outputFileDirectory)
+ public DestFileFilter( File outputFileDirectory )
{
this.outputFileDirectory = outputFileDirectory;
overWriteReleases = false;
@@ -64,6 +67,7 @@
useSubDirectoryPerType = false;
removeVersion = false;
}
+
public DestFileFilter( boolean overWriteReleases, boolean overWriteSnapshots, boolean overWriteIfNewer,
boolean useSubDirectoryPerArtifact, boolean useSubDirectoryPerType, boolean removeVersion,
File outputFileDirectory )
@@ -93,7 +97,7 @@
while ( iter.hasNext() )
{
Artifact artifact = (Artifact) iter.next();
- if ( okToProcess( artifact ) )
+ if (okToProcess( new ArtifactItem(artifact) ) )
{
result.add( artifact );
}
@@ -101,32 +105,6 @@
return result;
}
- public boolean okToProcess( Artifact artifact )
- throws MojoExecutionException
- {
- boolean overWrite = false;
- boolean result = false;
- if ( ( artifact.isSnapshot() && this.overWriteSnapshots )
- || ( !artifact.isSnapshot() && this.overWriteReleases ) )
- {
- overWrite = true;
- }
-
- File destFolder = DependencyUtil.getFormattedOutputDirectory( this.useSubDirectoryPerType,
- this.useSubDirectoryPerArtifact,
- this.outputFileDirectory, artifact );
- File destFile = new File( destFolder, DependencyUtil.getFormattedFileName( artifact, this.removeVersion ) );
-
- if ( overWrite
- || ( !destFile.exists() || ( overWriteIfNewer && artifact.getFile().lastModified() < destFile
- .lastModified() ) ) )
- {
- result = true;
- }
-
- return result;
- }
-
/**
* @return Returns the overWriteReleases.
*/
@@ -177,6 +155,7 @@
{
this.overWriteIfNewer = overWriteIfNewer;
}
+
/**
* @return Returns the outputFileDirectory.
*/
@@ -184,13 +163,16 @@
{
return this.outputFileDirectory;
}
+
/**
- * @param outputFileDirectory The outputFileDirectory to set.
+ * @param outputFileDirectory
+ * The outputFileDirectory to set.
*/
public void setOutputFileDirectory( File outputFileDirectory )
{
this.outputFileDirectory = outputFileDirectory;
}
+
/**
* @return Returns the removeVersion.
*/
@@ -198,13 +180,16 @@
{
return this.removeVersion;
}
+
/**
- * @param removeVersion The removeVersion to set.
+ * @param removeVersion
+ * The removeVersion to set.
*/
public void setRemoveVersion( boolean removeVersion )
{
this.removeVersion = removeVersion;
}
+
/**
* @return Returns the useSubDirectoryPerArtifact.
*/
@@ -212,13 +197,16 @@
{
return this.useSubDirectoryPerArtifact;
}
+
/**
- * @param useSubDirectoryPerArtifact The useSubDirectoryPerArtifact to set.
+ * @param useSubDirectoryPerArtifact
+ * The useSubDirectoryPerArtifact to set.
*/
public void setUseSubDirectoryPerArtifact( boolean useSubDirectoryPerArtifact )
{
this.useSubDirectoryPerArtifact = useSubDirectoryPerArtifact;
}
+
/**
* @return Returns the useSubDirectoryPerType.
*/
@@ -226,11 +214,51 @@
{
return this.useSubDirectoryPerType;
}
+
/**
- * @param useSubDirectoryPerType The useSubDirectoryPerType to set.
+ * @param useSubDirectoryPerType
+ * The useSubDirectoryPerType to set.
*/
public void setUseSubDirectoryPerType( boolean useSubDirectoryPerType )
{
this.useSubDirectoryPerType = useSubDirectoryPerType;
}
+
+ public boolean okToProcess( ArtifactItem item )
+ {
+ boolean overWrite = false;
+ boolean result = false;
+ Artifact artifact = item.getArtifact();
+
+ if ( ( artifact.isSnapshot() && this.overWriteSnapshots )
+ || ( !artifact.isSnapshot() && this.overWriteReleases ) )
+ {
+ overWrite = true;
+ }
+
+ File destFolder = item.getOutputDirectory();
+ if ( destFolder == null )
+ {
+ destFolder = DependencyUtil.getFormattedOutputDirectory( this.useSubDirectoryPerType, this.useSubDirectoryPerArtifact,
+ this.outputFileDirectory, artifact );
+ }
+
+ File destFile = null;
+ if (StringUtils.isEmpty(item.getDestFileName()))
+ {
+ destFile = new File( destFolder, DependencyUtil.getFormattedFileName( artifact, this.removeVersion ) );
+ }
+ else
+ {
+ destFile = new File (destFolder,item.getDestFileName());
+ }
+
+ if ( overWrite
+ || ( !destFile.exists() || ( overWriteIfNewer && artifact.getFile().lastModified() > destFile
+ .lastModified() ) ) )
+ {
+ result = true;
+ }
+ return result;
+ }
}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/MarkerFileFilter.java b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/MarkerFileFilter.java
index b62fae9..efac5ab 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/MarkerFileFilter.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/MarkerFileFilter.java
@@ -36,7 +36,7 @@
*
*/
public class MarkerFileFilter
- implements ArtifactsFilter
+ extends AbstractArtifactsFilter
{
boolean overWriteReleases;
@@ -72,7 +72,7 @@
while ( iter.hasNext() )
{
Artifact artifact = (Artifact) iter.next();
- if ( okToProcess( artifact ) )
+ if ( doOverwrite( artifact ) )
{
result.add( artifact );
}
@@ -80,7 +80,7 @@
return result;
}
- public boolean okToProcess( Artifact artifact )
+ protected boolean doOverwrite( Artifact artifact )
throws MojoExecutionException
{
boolean overWrite = false;
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ResolveFileFilter.java b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ResolveFileFilter.java
index 4003a5f..44d7098 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ResolveFileFilter.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ResolveFileFilter.java
@@ -39,11 +39,10 @@
super( true, true, true, handler );
}
- public boolean okToProcess( Artifact artifact )
+ protected boolean doOverwrite( Artifact artifact )
throws MojoExecutionException
- {
+ {
handler.setArtifact( artifact );
-
return ( !handler.isMarkerSet() );
}
}
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ScopeFilter.java b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ScopeFilter.java
index a783ede..07c9d8c 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ScopeFilter.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ScopeFilter.java
@@ -30,7 +30,7 @@
import org.codehaus.plexus.util.StringUtils;
public class ScopeFilter
- implements ArtifactsFilter
+ extends AbstractArtifactsFilter
{
private String includeScope;
diff --git a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/TransitivityFilter.java b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/TransitivityFilter.java
index 3dd0c5a..824e23b 100644
--- a/src/main/java/org/apache/maven/plugin/dependency/utils/filters/TransitivityFilter.java
+++ b/src/main/java/org/apache/maven/plugin/dependency/utils/filters/TransitivityFilter.java
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.maven.plugin.dependency.utils.filters;
import java.util.HashSet;
@@ -28,7 +27,7 @@
import org.apache.maven.plugin.logging.Log;
public class TransitivityFilter
- implements ArtifactsFilter
+ extends AbstractArtifactsFilter
{
private boolean excludeTransitive;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java b/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
index cf4fe93..9aa0b4c 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
@@ -1,5 +1,24 @@
package org.apache.maven.plugin.dependency;
-/*
+/*
+ * 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.
+ */
+
+/*
* 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
@@ -20,8 +39,8 @@
import java.io.File;
import java.io.IOException;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
-import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
public class AbstractDependencyMojoTestCase
diff --git a/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java b/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
index f8e3248..a09bd96 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
@@ -1,5 +1,24 @@
package org.apache.maven.plugin.dependency;
-/*
+/*
+ * 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.
+ */
+
+/*
* 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
@@ -26,9 +45,9 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.dependency.stubs.StubArtifactRepository;
-import org.apache.maven.plugin.dependency.stubs.StubArtifactResolver;
-import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactRepository;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactResolver;
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
import org.apache.maven.project.MavenProject;
@@ -52,8 +71,8 @@
// mojo.silent = true;
assertNotNull( mojo );
- assertNotNull( mojo.project );
- MavenProject project = mojo.project;
+ assertNotNull( mojo.getProject() );
+ MavenProject project = mojo.getProject();
Set artifacts = this.stubFactory.getScopedArtifacts();
Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
@@ -440,9 +459,9 @@
mojo.type = testType;
// init classifier things
- mojo.factory = DependencyTestUtils.getArtifactFactory();
- mojo.resolver = new StubArtifactResolver( stubFactory, false, false );
- mojo.local = new StubArtifactRepository( this.testDir.getAbsolutePath() );
+ mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
+ mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) );
+ mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
mojo.execute();
diff --git a/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java b/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java
index 18025f3..3b6664a 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java
@@ -1,5 +1,24 @@
package org.apache.maven.plugin.dependency;
-/*
+/*
+ * 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.
+ */
+
+/*
* 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
@@ -46,9 +65,11 @@
{
File testPom = new File( getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml" );
ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( "resolve", testPom );
+
assertNotNull( mojo );
- assertNotNull( mojo.project );
- MavenProject project = mojo.project;
+ assertNotNull( mojo.getProject() );
+ MavenProject project = mojo.getProject();
+
mojo.silent = true;
Set artifacts = this.stubFactory.getScopedArtifacts();
Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
diff --git a/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java b/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
index 8556a70..183c122 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
@@ -18,6 +18,25 @@
*/
package org.apache.maven.plugin.dependency;
+/*
+ * 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.util.HashSet;
import java.util.Iterator;
@@ -26,9 +45,9 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.dependency.stubs.StubArtifactRepository;
-import org.apache.maven.plugin.dependency.stubs.StubArtifactResolver;
-import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactRepository;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactResolver;
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
import org.apache.maven.project.MavenProject;
@@ -59,8 +78,8 @@
+ "target/test-classes/unit/unpack-dependencies-test/test.txt" ) );
assertNotNull( mojo );
- assertNotNull( mojo.project );
- MavenProject project = mojo.project;
+ assertNotNull( mojo.getProject() );
+ MavenProject project = mojo.getProject();
Set artifacts = this.stubFactory.getScopedArtifacts();
Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
@@ -85,10 +104,7 @@
File destFile = new File( folder, stubFactory.getUnpackableFileName( artifact ) );
- /*
- * System.out.println( "Checking file: " + destFile.getPath() ); if (
- * val != destFile.exists() ) { System.out.println( "FAIL!" ); }
- */
+
assertEquals( val, destFile.exists() );
assertMarkerFile( val, artifact );
}
@@ -371,9 +387,9 @@
mojo.classifier = "jdk";
mojo.type = "java-sources";
// init classifier things
- mojo.factory = DependencyTestUtils.getArtifactFactory();
- mojo.resolver = new StubArtifactResolver( null, are, anfe );
- mojo.local = new StubArtifactRepository( this.testDir.getAbsolutePath() );
+ mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
+ mojo.setResolver( new StubArtifactResolver( null, are, anfe ) );
+ mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
try
{
diff --git a/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestArtifactItem.java b/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestArtifactItem.java
new file mode 100644
index 0000000..295d631
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestArtifactItem.java
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.dependency.fromConfiguration;
+
+import java.io.IOException;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
+
+public class TestArtifactItem
+ extends AbstractDependencyMojoTestCase
+{
+
+ protected void setUp()
+ throws Exception
+ {
+ setUp("artifactItems",false);
+ }
+
+ public void testArtifactItemConstructor() throws IOException
+ {
+ Artifact artifact = stubFactory.createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "jar", "one" );
+
+ ArtifactItem item = new ArtifactItem(artifact);
+
+ assertEquals(item.getArtifact(),artifact);
+ assertEquals(item.getArtifactId(),artifact.getArtifactId());
+ assertEquals(item.getGroupId(),artifact.getGroupId());
+ assertEquals(item.getVersion(),artifact.getVersion());
+ assertEquals(item.getClassifier(),artifact.getClassifier());
+ assertEquals(item.getType(),artifact.getType());
+ }
+
+ public void testArtifactItemDefaultType()
+ {
+ ArtifactItem item = new ArtifactItem();
+ //check type default
+ assertEquals( "jar", item.getType() );
+ }
+
+}
diff --git a/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java b/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
new file mode 100644
index 0000000..0fa488c
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
@@ -0,0 +1,584 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.dependency.fromConfiguration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
+import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactRepository;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactResolver;
+import org.apache.maven.plugin.dependency.utils.DependencyUtil;
+import org.apache.maven.project.MavenProject;
+
+public class TestCopyMojo
+ extends AbstractDependencyMojoTestCase
+{
+
+ CopyMojo mojo;
+
+ public TestCopyMojo()
+ {
+ super();
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp( "copy", false );
+
+ File testPom = new File( getBasedir(), "target/test-classes/unit/copy-test/plugin-config.xml" );
+ mojo = (CopyMojo) lookupMojo( "copy", testPom );
+ mojo.outputDirectory = new File( this.testDir, "outputDirectory" );
+ // mojo.silent = true;
+
+ assertNotNull( mojo );
+ assertNotNull( mojo.getProject() );
+ // MavenProject project = mojo.getProject();
+ // init classifier things
+ mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
+ mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) );
+ mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
+ }
+
+ public ArtifactItem getSingleArtifactItem( boolean removeVersion )
+ throws MojoExecutionException
+ {
+ ArrayList list = mojo.getArtifactItems( removeVersion );
+ return (ArtifactItem) list.get( 0 );
+ }
+
+ public void testGetArtifactItems()
+ throws MojoExecutionException
+ {
+
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifact" );
+ item.setGroupId( "groupId" );
+ item.setVersion( "1.0" );
+
+ ArrayList list = new ArrayList( 1 );
+ list.add( item );
+
+ mojo.artifactItems = list;
+
+ ArtifactItem result = getSingleArtifactItem( false );
+ assertEquals( mojo.outputDirectory, result.getOutputDirectory() );
+
+ File output = new File( mojo.outputDirectory, "override" );
+ item.setOutputDirectory( output );
+ result = getSingleArtifactItem( false );
+ assertEquals( output, result.getOutputDirectory() );
+ }
+
+ public void assertFilesExist( Collection items, boolean exist )
+ {
+ Iterator iter = items.iterator();
+ while ( iter.hasNext() )
+ {
+ assertFileExists( (ArtifactItem) iter.next(), exist );
+ }
+ }
+
+ public void assertFileExists( ArtifactItem item, boolean exist )
+ {
+ File file = new File( item.getOutputDirectory(), item.getDestFileName() );
+ assertEquals( exist, file.exists() );
+ }
+
+ public void testMojoDefaults()
+ {
+ CopyMojo mojo = new CopyMojo();
+
+ assertFalse( mojo.isStripVersion() );
+ }
+
+ public void testCopyFile()
+ throws IOException, MojoExecutionException
+ {
+ ArrayList list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts() );
+
+ mojo.artifactItems = list;
+
+ mojo.execute();
+
+ assertFilesExist( list, true );
+ }
+
+ public void testCopyToLocation()
+ throws IOException, MojoExecutionException
+ {
+ ArrayList list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts() );
+ ArtifactItem item = (ArtifactItem) list.get( 0 );
+ item.setOutputDirectory( new File( mojo.outputDirectory, "testOverride" ) );
+
+ mojo.artifactItems = list;
+
+ mojo.execute();
+
+ assertFilesExist( list, true );
+ }
+
+ public void testCopyStripVersion()
+ throws IOException, MojoExecutionException
+ {
+ ArrayList list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts() );
+ ArtifactItem item = (ArtifactItem) list.get( 0 );
+ item.setOutputDirectory( new File( mojo.outputDirectory, "testOverride" ) );
+ mojo.setStripVersion( true );
+
+ mojo.artifactItems = list;
+
+ mojo.execute();
+
+ assertFilesExist( list, true );
+ }
+
+ public void testNonClassifierStrip()
+ throws IOException, MojoExecutionException
+ {
+ ArrayList list = stubFactory.getArtifactItems( stubFactory.getReleaseAndSnapshotArtifacts() );
+ mojo.setStripVersion( true );
+ mojo.artifactItems = list;
+
+ mojo.execute();
+
+ assertFilesExist( list, true );
+ }
+
+ public void testNonClassifierNoStrip()
+ throws IOException, MojoExecutionException
+ {
+ ArrayList list = stubFactory.getArtifactItems( stubFactory.getReleaseAndSnapshotArtifacts() );
+
+ mojo.artifactItems = list;
+
+ mojo.execute();
+
+ assertFilesExist( list, true );
+ }
+
+ public void testMissingVersionNotFound()
+ throws MojoExecutionException
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+ mojo.artifactItems = list;
+
+ try
+ {
+ mojo.execute();
+ fail( "Expected Exception Here." );
+ }
+ catch ( MojoExecutionException e )
+ {
+ // caught the expected exception.
+ }
+ }
+
+ public List getDependencyList( ArtifactItem item )
+ {
+ Dependency dep = new Dependency();
+ dep.setArtifactId( item.getArtifactId() );
+ dep.setClassifier( item.getClassifier() );
+ dep.setGroupId( item.getGroupId() );
+ dep.setType( item.getType() );
+ dep.setVersion( "2.0-SNAPSHOT" );
+
+ Dependency dep2 = new Dependency();
+ dep2.setArtifactId( item.getArtifactId() );
+ dep2.setClassifier( "classifier" );
+ dep2.setGroupId( item.getGroupId() );
+ dep2.setType( item.getType() );
+ dep2.setVersion( "2.1" );
+
+ List list = new ArrayList( 2 );
+ list.add( dep2 );
+ list.add( dep );
+
+ return list;
+ }
+
+ public void testMissingVersionFromDependencies()
+ throws MojoExecutionException
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+ mojo.artifactItems = list;
+
+ MavenProject project = mojo.getProject();
+ project.setDependencies( getDependencyList( item ) );
+
+ mojo.execute();
+ this.assertFileExists( item, true );
+ assertEquals( "2.0-SNAPSHOT", item.getVersion() );
+ }
+
+ public void testMissingVersionFromDependenciesWithClassifier()
+ throws MojoExecutionException
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "classifier" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+ mojo.artifactItems = list;
+
+ MavenProject project = mojo.getProject();
+ project.setDependencies( getDependencyList( item ) );
+
+ mojo.execute();
+ this.assertFileExists( item, true );
+ assertEquals( "2.1", item.getVersion() );
+ }
+
+ public List getDependencyMgtList( ArtifactItem item )
+ {
+ Dependency dep = new Dependency();
+ dep.setArtifactId( item.getArtifactId() );
+ dep.setClassifier( item.getClassifier() );
+ dep.setGroupId( item.getGroupId() );
+ dep.setType( item.getType() );
+ dep.setVersion( "3.0-SNAPSHOT" );
+
+ Dependency dep2 = new Dependency();
+ dep2.setArtifactId( item.getArtifactId() );
+ dep2.setClassifier( "classifier" );
+ dep2.setGroupId( item.getGroupId() );
+ dep2.setType( item.getType() );
+ dep2.setVersion( "3.1" );
+
+ List list = new ArrayList( 2 );
+ list.add( dep2 );
+ list.add( dep );
+
+ return list;
+ }
+
+ public void testMissingVersionFromDependencyMgt()
+ throws MojoExecutionException
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ MavenProject project = mojo.getProject();
+ project.setDependencies( getDependencyList( item ) );
+
+ item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId-2" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+
+ mojo.artifactItems = list;
+
+ project.getDependencyManagement().setDependencies( getDependencyMgtList( item ) );
+
+ mojo.execute();
+
+ this.assertFileExists( item, true );
+ assertEquals( "3.0-SNAPSHOT", item.getVersion() );
+ }
+
+ public void testMissingVersionFromDependencyMgtWithClassifier()
+ throws MojoExecutionException
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "classifier" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ MavenProject project = mojo.getProject();
+ project.setDependencies( getDependencyList( item ) );
+
+ item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId-2" );
+ item.setClassifier( "classifier" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+
+ mojo.artifactItems = list;
+
+ project.getDependencyManagement().setDependencies( getDependencyMgtList( item ) );
+
+ mojo.execute();
+
+ this.assertFileExists( item, true );
+ assertEquals( "3.1", item.getVersion() );
+ }
+
+ public void testArtifactNotFound()
+ throws Exception
+ {
+ dotestArtifactExceptions( false, true );
+ }
+
+ public void testArtifactResolutionException()
+ throws Exception
+ {
+ dotestArtifactExceptions( true, false );
+ }
+
+ public void dotestArtifactExceptions( boolean are, boolean anfe )
+ throws Exception
+ {
+ ArtifactItem item = new ArtifactItem();
+
+ item.setArtifactId( "artifactId" );
+ item.setClassifier( "" );
+ item.setGroupId( "groupId" );
+ item.setType( "type" );
+ item.setVersion( "1.0" );
+
+ ArrayList list = new ArrayList();
+ list.add( item );
+ mojo.artifactItems = list;
+
+ // init classifier things
+ mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
+ mojo.setResolver( new StubArtifactResolver( null, are, anfe ) );
+ mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
+
+ try
+ {
+ mojo.execute();
+ fail( "ExpectedException" );
+ }
+ catch ( MojoExecutionException e )
+ {
+ if ( are )
+ {
+ assertEquals( "Unable to resolve artifact.", e.getMessage() );
+ }
+ else
+ {
+ assertEquals( "Unable to find artifact.", e.getMessage() );
+ }
+ }
+ }
+
+ public void testNoArtifactItems()
+ {
+ try
+ {
+ mojo.getArtifactItems( false );
+ fail( "Expected Exception" );
+ }
+ catch ( MojoExecutionException e )
+ {
+ assertEquals( "There are no artifactItems configured.", e.getMessage() );
+ }
+
+ }
+
+ public void testCopyDontOverWriteReleases()
+ throws IOException, MojoExecutionException, InterruptedException
+ {
+ stubFactory.setCreateFiles( true );
+ Artifact release = stubFactory.getReleaseArtifact();
+ release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+ ArtifactItem item = new ArtifactItem( release );
+
+ ArrayList list = new ArrayList( 1 );
+ list.add( item );
+ mojo.artifactItems = list;
+
+ mojo.overWriteIfNewer = false;
+
+ mojo.execute();
+
+ File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+ Thread.sleep( 100 );
+ // round up to the next second
+ long time = System.currentTimeMillis() + 1000;
+ time = time - ( time % 1000 );
+ copiedFile.setLastModified( time );
+ Thread.sleep( 100 );
+
+ mojo.execute();
+
+ assertEquals( time, copiedFile.lastModified() );
+ }
+
+ public void testCopyDontOverWriteSnapshots()
+ throws IOException, MojoExecutionException, InterruptedException
+ {
+ stubFactory.setCreateFiles( true );
+ Artifact artifact = stubFactory.getSnapshotArtifact();
+ artifact.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+ ArtifactItem item = new ArtifactItem( artifact );
+
+ ArrayList list = new ArrayList( 1 );
+ list.add( item );
+ mojo.artifactItems = list;
+
+ mojo.overWriteIfNewer = false;
+
+ mojo.execute();
+
+ File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+ Thread.sleep( 100 );
+ // round up to the next second
+ long time = System.currentTimeMillis() + 1000;
+ time = time - ( time % 1000 );
+ copiedFile.setLastModified( time );
+ Thread.sleep( 100 );
+
+ mojo.execute();
+
+ assertEquals( time, copiedFile.lastModified() );
+ }
+
+ public void testCopyOverWriteReleases()
+ throws IOException, MojoExecutionException, InterruptedException
+ {
+ stubFactory.setCreateFiles( true );
+ Artifact release = stubFactory.getReleaseArtifact();
+ release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+ ArtifactItem item = new ArtifactItem( release );
+
+ ArrayList list = new ArrayList( 1 );
+ list.add( item );
+ mojo.artifactItems = list;
+
+ mojo.overWriteIfNewer = false;
+ mojo.overWriteReleases = true;
+ mojo.execute();
+
+ File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+ // round up to the next second
+ long time = System.currentTimeMillis() - 2000;
+ copiedFile.setLastModified( time );
+
+ mojo.execute();
+
+ assertTrue( time < copiedFile.lastModified() );
+ }
+
+ public void testCopyOverWriteSnapshot()
+ throws IOException, MojoExecutionException, InterruptedException
+ {
+ stubFactory.setCreateFiles( true );
+ Artifact artifact = stubFactory.getSnapshotArtifact();
+ artifact.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+ ArtifactItem item = new ArtifactItem( artifact );
+
+ ArrayList list = new ArrayList( 1 );
+ list.add( item );
+ mojo.artifactItems = list;
+
+ mojo.overWriteIfNewer = false;
+ mojo.overWriteReleases = false;
+ mojo.overWriteSnapshots = true;
+ mojo.execute();
+
+ File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+ // round up to the next second
+ long time = System.currentTimeMillis() - 2000;
+ copiedFile.setLastModified( time );
+
+ mojo.execute();
+
+ assertTrue( time < copiedFile.lastModified() );
+ }
+
+ public void testCopyOverWriteIfNewer()
+ throws IOException, MojoExecutionException, InterruptedException
+{
+ stubFactory.setCreateFiles( true );
+ Artifact artifact = stubFactory.getSnapshotArtifact();
+ artifact.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+ ArtifactItem item = new ArtifactItem( artifact );
+
+ ArrayList list = new ArrayList( 1 );
+ list.add( item );
+ mojo.artifactItems = list;
+ mojo.overWriteIfNewer = true;
+ mojo.execute();
+
+ File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+ // set dest to be old
+ long time = System.currentTimeMillis() - 10000;
+ copiedFile.setLastModified( time );
+
+ //set source to be newer
+ artifact.getFile().setLastModified(time + 4000);
+ mojo.execute();
+
+ assertTrue( time < copiedFile.lastModified() );
+}
+ // TODO: test overwrite / overwrite if newer / overwrite release / overwrite
+ // snapshot
+
+}
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
similarity index 90%
rename from src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
rename to src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
index c5d3cb1..f84b706 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
@@ -16,11 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.plugin.dependency.utils;
+package org.apache.maven.plugin.dependency.testUtils;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
@@ -28,6 +32,10 @@
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem;
+import org.apache.maven.plugin.dependency.utils.DependencyUtil;
+import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
@@ -93,6 +101,9 @@
return artifact;
}
+ /*
+ * Creates a file that can be copied or unpacked based on the passed in artifact
+ */
public void setArtifactFile( Artifact artifact )
throws IOException
{
@@ -293,4 +304,21 @@
{
this.srcFile = srcFile;
}
+
+ public ArtifactItem getArtifactItem(Artifact artifact)
+ {
+ ArtifactItem item = new ArtifactItem(artifact);
+ return item;
+ }
+
+ public ArrayList getArtifactItems(Collection artifacts)
+ {
+ ArrayList list = new ArrayList();
+ Iterator iter = artifacts.iterator();
+ while (iter.hasNext())
+ {
+ list.add(getArtifactItem((Artifact) iter.next()));
+ }
+ return list;
+ }
}
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/DependencyTestUtils.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyTestUtils.java
similarity index 96%
rename from src/test/java/org/apache/maven/plugin/dependency/utils/DependencyTestUtils.java
rename to src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyTestUtils.java
index 5be01f2..dd4b6cf 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/DependencyTestUtils.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/DependencyTestUtils.java
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.dependency.utils;
+package org.apache.maven.plugin.dependency.testUtils;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -27,6 +27,7 @@
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.shared.model.fileset.FileSet;
import org.apache.maven.shared.model.fileset.util.FileSetManager;
import org.codehaus.plexus.util.ReflectionUtils;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/stubs/DependencyProjectStub.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
similarity index 97%
rename from src/test/java/org/apache/maven/plugin/dependency/stubs/DependencyProjectStub.java
rename to src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
index f5c55dd..c8369dc 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/stubs/DependencyProjectStub.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/DependencyProjectStub.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.maven.plugin.dependency.stubs;
+package org.apache.maven.plugin.dependency.testUtils.stubs;
/*
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -86,6 +86,8 @@
private MavenProject parent;
+ private List dependencies;
+
private File file;
private List collectedProjects;
@@ -108,6 +110,8 @@
private Set dependencyArtifacts;
+ private DependencyManagement dependencyManagement;
+
private Artifact artifact;
private Map artifactMap;
@@ -253,17 +257,26 @@
public void setDependencies( List list )
{
-
+ dependencies = list;
}
public List getDependencies()
{
- return Collections.singletonList( "" );
+ if (dependencies == null)
+ {
+ dependencies = Collections.EMPTY_LIST;
+ }
+ return dependencies;
}
public DependencyManagement getDependencyManagement()
{
- return null;
+ if (dependencyManagement == null)
+ {
+ dependencyManagement = new DependencyManagement();
+ }
+
+ return dependencyManagement;
}
public void addCompileSourceRoot( String string )
diff --git a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubArtifactRepository.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactRepository.java
similarity index 97%
rename from src/test/java/org/apache/maven/plugin/dependency/stubs/StubArtifactRepository.java
rename to src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactRepository.java
index 9e7d166..278f22b 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubArtifactRepository.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactRepository.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.maven.plugin.dependency.stubs;
+package org.apache.maven.plugin.dependency.testUtils.stubs;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubArtifactResolver.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactResolver.java
similarity index 93%
rename from src/test/java/org/apache/maven/plugin/dependency/stubs/StubArtifactResolver.java
rename to src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactResolver.java
index 27c2116..d026329 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubArtifactResolver.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactResolver.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.maven.plugin.dependency.stubs;
+package org.apache.maven.plugin.dependency.testUtils.stubs;
import java.io.IOException;
import java.util.List;
@@ -32,7 +32,7 @@
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.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
public class StubArtifactResolver
implements ArtifactResolver
@@ -52,6 +52,10 @@
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
{
diff --git a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubDefaultFileMarkerHandler.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubDefaultFileMarkerHandler.java
similarity index 95%
rename from src/test/java/org/apache/maven/plugin/dependency/stubs/StubDefaultFileMarkerHandler.java
rename to src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubDefaultFileMarkerHandler.java
index 359f47e..4de7bab 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubDefaultFileMarkerHandler.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubDefaultFileMarkerHandler.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.maven.plugin.dependency.stubs;
+package org.apache.maven.plugin.dependency.testUtils.stubs;
import java.io.File;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubMarkerFile.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubMarkerFile.java
similarity index 96%
rename from src/test/java/org/apache/maven/plugin/dependency/stubs/StubMarkerFile.java
rename to src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubMarkerFile.java
index be83714..2c8a761 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubMarkerFile.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubMarkerFile.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.maven.plugin.dependency.stubs;
+package org.apache.maven.plugin.dependency.testUtils.stubs;
import java.io.File;
import java.io.IOException;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubSourcesFileMarkerHandler.java b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubSourcesFileMarkerHandler.java
similarity index 96%
rename from src/test/java/org/apache/maven/plugin/dependency/stubs/StubSourcesFileMarkerHandler.java
rename to src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubSourcesFileMarkerHandler.java
index 07b8879..d780793 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/stubs/StubSourcesFileMarkerHandler.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubSourcesFileMarkerHandler.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.maven.plugin.dependency.stubs;
+package org.apache.maven.plugin.dependency.testUtils.stubs;
import java.io.File;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyStatusSets.java b/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyStatusSets.java
index da8739b..923b665 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyStatusSets.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyStatusSets.java
@@ -1,5 +1,24 @@
package org.apache.maven.plugin.dependency.utils;
-/*
+/*
+ * 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.
+ */
+
+/*
* 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
@@ -86,7 +105,7 @@
public void testDependencyStatusLogNullFiles()
throws IOException
{
- this.stubFactory.createFiles = false;
+ this.stubFactory.setCreateFiles(false);
Set artifacts = this.stubFactory.getMixedArtifacts();
doTestDependencyStatusLog( artifacts );
}
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java b/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java
index a2fd528..f7dfd72 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils;
+/*
+ * 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.util.ArrayList;
import java.util.List;
@@ -60,7 +79,7 @@
ArtifactHandler ah = new DefaultArtifactHandler();
VersionRange vr = VersionRange.createFromVersion( "1.1" );
- this.release = new DefaultArtifact( "test", "1", vr, Artifact.SCOPE_COMPILE, "jar", null, ah, false );
+ release = new DefaultArtifact( "test", "1", vr, Artifact.SCOPE_COMPILE, "jar", null, ah, false );
artifacts.add( release );
vr = VersionRange.createFromVersion( "1.1-SNAPSHOT" );
@@ -79,8 +98,6 @@
}
-
-
public void testDirectoryName()
throws MojoExecutionException
{
@@ -127,7 +144,7 @@
public void testFileName()
throws MojoExecutionException
{
- DefaultArtifact artifact = (DefaultArtifact) artifacts.get( 0 );
+ Artifact artifact = (Artifact) artifacts.get( 0 );
String name = DependencyUtil.getFormattedFileName( artifact, false );
String expectedResult = "1-1.1.jar";
@@ -136,15 +153,27 @@
name = DependencyUtil.getFormattedFileName( artifact, true );
expectedResult = "1.jar";
assertTrue( expectedResult.equalsIgnoreCase( name ) );
+ }
- artifact = (DefaultArtifact) artifacts.get( 1 );
-
- name = DependencyUtil.getFormattedFileName( artifact, false );
- expectedResult = "2-sources-1.1-SNAPSHOT.war";
- assertTrue( expectedResult.equalsIgnoreCase( name ) );
+ public void testFileNameClassifier()
+ throws MojoExecutionException
+ {
+ ArtifactHandler ah = new DefaultArtifactHandler();
+ VersionRange vr = VersionRange.createFromVersion( "1.1-SNAPSHOT" );
+ Artifact artifact = new DefaultArtifact( "test", "2", vr, Artifact.SCOPE_PROVIDED, "war", "sources", ah, false );
+
+ String name = DependencyUtil.getFormattedFileName( artifact, false );
+ String expectedResult = "2-sources-1.1-SNAPSHOT.war";
+ assertEquals(expectedResult,name );
name = DependencyUtil.getFormattedFileName( artifact, true );
expectedResult = "2-sources.war";
- assertTrue( expectedResult.equalsIgnoreCase( name ) );
+ assertEquals(expectedResult,name );
+
+ artifact = new DefaultArtifact( "test", "2", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false );
+ name = DependencyUtil.getFormattedFileName( artifact, true );
+ expectedResult = "2.war";
+ assertEquals(expectedResult,name );
+
}
}
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/TestSilentLog.java b/src/test/java/org/apache/maven/plugin/dependency/utils/TestSilentLog.java
index b935e9c..e4a4531 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/TestSilentLog.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/TestSilentLog.java
@@ -1,5 +1,24 @@
package org.apache.maven.plugin.dependency.utils;
-/*
+/*
+ * 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.
+ */
+
+/*
* 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
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestClassifierFilter.java b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestClassifierFilter.java
index 52c5dc4..d3e2cd7 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestClassifierFilter.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestClassifierFilter.java
@@ -22,6 +22,25 @@
*/
package org.apache.maven.plugin.dependency.utils.filters;
+/*
+ * 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;
@@ -30,7 +49,7 @@
import junit.framework.TestCase;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.logging.Log;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestDestFileFilter.java b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestDestFileFilter.java
index e965930..9e6a7d0 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestDestFileFilter.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestDestFileFilter.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.filters;
+/*
+ * 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.util.HashSet;
@@ -30,8 +49,8 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
-import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.logging.Log;
@@ -96,12 +115,12 @@
DestFileFilter filter = new DestFileFilter( outputFolder );
Artifact artifact = fact.getReleaseArtifact();
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log) );
createFile( artifact );
- assertFalse( filter.okToProcess( artifact ) );
+ assertFalse( filter.okToProcess( artifact ,log) );
filter.overWriteReleases = true;
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log));
}
public void testDestFileSnapshot()
@@ -110,12 +129,12 @@
DestFileFilter filter = new DestFileFilter( outputFolder );
Artifact artifact = fact.getSnapshotArtifact();
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log) );
createFile( artifact );
- assertFalse( filter.okToProcess( artifact ) );
+ assertFalse( filter.okToProcess( artifact ,log) );
filter.overWriteSnapshots = true;
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log) );
}
public void testDestFileStripVersion()
@@ -125,12 +144,12 @@
Artifact artifact = fact.getSnapshotArtifact();
filter.removeVersion = true;
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log) );
createFile( artifact, false, false, true );
- assertFalse( filter.okToProcess( artifact ) );
+ assertFalse( filter.okToProcess( artifact ,log) );
filter.overWriteSnapshots = true;
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log) );
}
public void testDestFileSubPerArtifact()
@@ -140,12 +159,12 @@
Artifact artifact = fact.getSnapshotArtifact();
filter.useSubDirectoryPerArtifact = true;
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log) );
createFile( artifact, true, false, false );
- assertFalse( filter.okToProcess( artifact ) );
+ assertFalse( filter.okToProcess( artifact ,log) );
filter.overWriteSnapshots = true;
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log) );
}
public void testDestFileSubPerType()
@@ -155,12 +174,12 @@
Artifact artifact = fact.getSnapshotArtifact();
filter.useSubDirectoryPerType = true;
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log) );
createFile( artifact, false, true, false );
- assertFalse( filter.okToProcess( artifact ) );
+ assertFalse( filter.okToProcess( artifact ,log) );
filter.overWriteSnapshots = true;
- assertTrue( filter.okToProcess( artifact ) );
+ assertTrue( filter.okToProcess( artifact ,log) );
}
public void testDestFileOverwriteIfNewer()
@@ -171,17 +190,23 @@
fact.setCreateFiles( true );
Artifact artifact = fact.getSnapshotArtifact();
File artifactFile = artifact.getFile();
- artifactFile.setLastModified( artifactFile.lastModified() - 1000 );
+ artifactFile.setLastModified( artifactFile.lastModified() );
filter.overWriteIfNewer = true;
- assertTrue( filter.okToProcess( artifact ) );
+ //should pass because the file doesn't exist yet.
+ assertTrue( filter.okToProcess( artifact ,log) );
+ //create the file in the destination
File destFile = createFile( artifact, false, false, false );
- assertTrue( filter.okToProcess( artifact ) );
+
+ //set the last modified timestamp to be older than the source
+ destFile.setLastModified( artifactFile.lastModified()-1000 );
+ assertTrue( filter.okToProcess( artifact ,log) );
- destFile.setLastModified( destFile.lastModified() - 2000 );
+ //now set the last modified timestamp to be newer than the source
+ destFile.setLastModified( artifactFile.lastModified() + 1000 );
- assertFalse( filter.okToProcess( artifact ) );
+ assertFalse( filter.okToProcess( artifact ,log) );
}
public void testGettersSetters()
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestFilterArtifacts.java b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestFilterArtifacts.java
index 652c5fa..4cc3d2f 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestFilterArtifacts.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestFilterArtifacts.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.filters;
+/*
+ * 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.ArrayList;
import java.util.HashSet;
import java.util.Set;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestMarkerFileFilter.java b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestMarkerFileFilter.java
index 24570db..7c3b11c 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestMarkerFileFilter.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestMarkerFileFilter.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.filters;
+/*
+ * 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.util.HashSet;
@@ -30,8 +49,8 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
-import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
import org.apache.maven.plugin.logging.Log;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestResolveMarkerFileFilter.java b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestResolveMarkerFileFilter.java
index 724401c..763706e 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestResolveMarkerFileFilter.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestResolveMarkerFileFilter.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.filters;
+/*
+ * 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.util.HashSet;
@@ -30,8 +49,8 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
-import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.dependency.utils.markers.SourcesFileMarkerHandler;
import org.apache.maven.plugin.logging.Log;
@@ -64,7 +83,8 @@
artifacts = fact.getReleaseAndSnapshotArtifacts();
}
- protected void tearDown() throws IOException
+ protected void tearDown()
+ throws IOException
{
DependencyTestUtils.removeDirectory( outputFolder );
}
@@ -73,16 +93,15 @@
throws MojoExecutionException, IOException
{
SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler( outputFolder );
- ResolveFileFilter filter = new ResolveFileFilter( handler );
-
- handler = new SourcesFileMarkerHandler( outputFolder );
-
+
Artifact artifact = fact.getReleaseArtifact();
handler.setArtifact( artifact );
-
- assertTrue( filter.okToProcess( artifact ) );
+
+ ResolveFileFilter filter = new ResolveFileFilter( handler );
+
+ assertTrue( filter.okToProcess( artifact , log));
handler.setMarker();
- assertFalse( filter.okToProcess( artifact ) );
+ assertFalse( filter.okToProcess( artifact, log ));
}
}
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestScopeFilter.java b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestScopeFilter.java
index fae61a8..62ceeb2 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestScopeFilter.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestScopeFilter.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.filters;
+/*
+ * 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.Set;
@@ -29,7 +48,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.logging.Log;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestTransitivityFilter.java b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestTransitivityFilter.java
index 7d4ecfd..2b36dac 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestTransitivityFilter.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestTransitivityFilter.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.filters;
+/*
+ * 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.Set;
@@ -28,7 +47,7 @@
import junit.framework.TestCase;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.logging.Log;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestTypeFilter.java b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestTypeFilter.java
index 974ca65..20ab308 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestTypeFilter.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestTypeFilter.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.filters;
+/*
+ * 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;
@@ -29,7 +48,7 @@
import junit.framework.TestCase;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.logging.Log;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java b/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
index cf2e6fa..ae4d7f6 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.markers;
+/*
+ * 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.util.ArrayList;
@@ -34,8 +53,8 @@
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.dependency.stubs.StubDefaultFileMarkerHandler;
-import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubDefaultFileMarkerHandler;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.logging.Log;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java b/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java
index 93897d7..0b4cc42 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.markers;
+/*
+ * 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.util.ArrayList;
@@ -35,7 +54,7 @@
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.dependency.stubs.StubSourcesFileMarkerHandler;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubSourcesFileMarkerHandler;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.logging.Log;
diff --git a/src/test/java/org/apache/maven/plugin/dependency/utils/translators/TestClassifierTypeTranslator.java b/src/test/java/org/apache/maven/plugin/dependency/utils/translators/TestClassifierTypeTranslator.java
index 926717d..a25d200 100644
--- a/src/test/java/org/apache/maven/plugin/dependency/utils/translators/TestClassifierTypeTranslator.java
+++ b/src/test/java/org/apache/maven/plugin/dependency/utils/translators/TestClassifierTypeTranslator.java
@@ -21,6 +21,25 @@
*/
package org.apache.maven.plugin.dependency.utils.translators;
+/*
+ * 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.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -32,7 +51,7 @@
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager;
import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.testUtils.ArtifactStubFactory;
import org.apache.maven.plugin.dependency.utils.SilentLog;
import org.apache.maven.plugin.logging.Log;
diff --git a/src/test/resources/unit/copy-dependencies-test/plugin-config.xml b/src/test/resources/unit/copy-dependencies-test/plugin-config.xml
index 2049d00..ae52722 100644
--- a/src/test/resources/unit/copy-dependencies-test/plugin-config.xml
+++ b/src/test/resources/unit/copy-dependencies-test/plugin-config.xml
@@ -23,7 +23,7 @@
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
- <project implementation="org.apache.maven.plugin.dependency.stubs.DependencyProjectStub"/>
+ <project implementation="org.apache.maven.plugin.dependency.testUtils.stubs.DependencyProjectStub"/>
<silent>true</silent>
</configuration>
</plugin>
diff --git a/src/test/resources/unit/copy-test/plugin-config.xml b/src/test/resources/unit/copy-test/plugin-config.xml
index 9867293..1a89632 100644
--- a/src/test/resources/unit/copy-test/plugin-config.xml
+++ b/src/test/resources/unit/copy-test/plugin-config.xml
@@ -23,7 +23,7 @@
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
- <project implementation="org.apache.maven.plugin.dependency.stubs.DependencyProjectStub"/>
+ <project implementation="org.apache.maven.plugin.dependency.testUtils.stubs.DependencyProjectStub"/>
</configuration>
</plugin>
</plugins>
diff --git a/src/test/resources/unit/resolve-test/plugin-config.xml b/src/test/resources/unit/resolve-test/plugin-config.xml
index 9867293..1a89632 100644
--- a/src/test/resources/unit/resolve-test/plugin-config.xml
+++ b/src/test/resources/unit/resolve-test/plugin-config.xml
@@ -23,7 +23,7 @@
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
- <project implementation="org.apache.maven.plugin.dependency.stubs.DependencyProjectStub"/>
+ <project implementation="org.apache.maven.plugin.dependency.testUtils.stubs.DependencyProjectStub"/>
</configuration>
</plugin>
</plugins>
diff --git a/src/test/resources/unit/unpack-dependencies-test/plugin-config.xml b/src/test/resources/unit/unpack-dependencies-test/plugin-config.xml
index 2049d00..ae52722 100644
--- a/src/test/resources/unit/unpack-dependencies-test/plugin-config.xml
+++ b/src/test/resources/unit/unpack-dependencies-test/plugin-config.xml
@@ -23,7 +23,7 @@
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
- <project implementation="org.apache.maven.plugin.dependency.stubs.DependencyProjectStub"/>
+ <project implementation="org.apache.maven.plugin.dependency.testUtils.stubs.DependencyProjectStub"/>
<silent>true</silent>
</configuration>
</plugin>