You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/11/14 03:36:56 UTC
svn commit: r474631 - in /maven/plugins/trunk/maven-dependency-plugin/src:
main/java/org/apache/maven/plugin/dependency/
main/java/org/apache/maven/plugin/dependency/fromConfiguration/
test/java/org/apache/maven/plugin/dependency/
Author: brianf
Date: Mon Nov 13 18:36:55 2006
New Revision: 474631
URL: http://svn.apache.org/viewvc?view=rev&rev=474631
Log:
added overWriteIfNewer to copy/unpack to match copy-dependencies/unpack-dependencies
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java?view=diff&rev=474631&r1=474630&r2=474631
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java Mon Nov 13 18:36:55 2006
@@ -103,17 +103,20 @@
/**
* If the plugin should be silent.
+ *
* @optional
* @since 2.0
* @parameter expression="${silent}" default-value="false"
*/
protected boolean silent;
-
+
/**
* Output absolute filename for resolved artifacts
+ *
* @optional
* @since 2.0
- * @parameter expression="${outputAbsoluteArtifactFilename}" default-value="false"
+ * @parameter expression="${outputAbsoluteArtifactFilename}"
+ * default-value="false"
*/
protected boolean outputAbsoluteArtifactFilename;
@@ -151,81 +154,25 @@
* represents the file to copy.
* @param destFile
* file name of destination file.
- * @param log
- * to use for output.
- * @param overWriteSnapshots
- * force Over Writing of the file
*
* @throws MojoExecutionException
* with a message if an error occurs.
*/
- protected boolean copyFile( File artifact, File destFile, boolean overWrite )
+ protected void copyFile( File artifact, File destFile )
throws MojoExecutionException
{
Log theLog = this.getLog();
- boolean result = false;
- if ( !destFile.exists() || overWrite )
- {
- try
- {
- theLog.info( "Copying " + (this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() : artifact.getName()) + " to " + destFile );
- FileUtils.copyFile( artifact, destFile );
- result = true;
- }
- catch ( Exception e )
- {
- throw new MojoExecutionException( "Error copying artifact from " + artifact + " to " + destFile, e );
- }
- }
- else
+ try
{
- theLog.info( artifact.getName() + " already exists." );
- }
+ theLog.info( "Copying "
+ + ( this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() : artifact.getName() ) + " to "
+ + destFile );
+ FileUtils.copyFile( artifact, destFile );
- return result;
- }
-
- /**
- * Unpacks the archive file, checking for a marker file to see if it should
- * unpack again. Creates the marker file after unpacking.
- *
- * @param Artifact
- * File to be unpacked.
- * @param unpackDirectory
- * Location where to put the unpacked files.
- *
- * @deprecated Please now use unpack()
- * @see unpack()
- */
- protected void unpackFile( Artifact artifact, File unpackDirectory, File markersDirectory,
- boolean overWrite )
- throws MojoExecutionException
- {
- Log theLog = getLog();
- markersDirectory.mkdirs();
-
- File markerFile = new File( markersDirectory, artifact.getId().replace( ':', '-' ) + ".unpacked" );
-
- if ( !markerFile.exists() || overWrite )
- {
- try
- {
- unpackDirectory.mkdirs();
-
- unpack( artifact.getFile(), unpackDirectory);
-
- // create marker file
- markerFile.getParentFile().mkdirs();
- markerFile.createNewFile();
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error creating marker file: " + markerFile );
- }
}
- else
+ catch ( Exception e )
{
- theLog.info( artifact.getFile().getName() + " already unpacked." );
+ throw new MojoExecutionException( "Error copying artifact from " + artifact + " to " + destFile, e );
}
}
@@ -237,7 +184,7 @@
* @param location
* Location where to put the unpacked files.
*/
- protected void unpack( File file, File location)
+ protected void unpack( File file, File location )
throws MojoExecutionException
{
@@ -262,8 +209,9 @@
catch ( IOException e )
{
e.printStackTrace();
- throw new MojoExecutionException( "Error unpacking file: " + (this.outputAbsoluteArtifactFilename ? file.getAbsolutePath() : file.getName()) + " to: " + location + "\r\n"
- + e.toString(), e );
+ throw new MojoExecutionException( "Error unpacking file: "
+ + ( this.outputAbsoluteArtifactFilename ? file.getAbsolutePath() : file.getName() ) + " to: "
+ + location + "\r\n" + e.toString(), e );
}
catch ( ArchiverException e )
{
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java?view=diff&rev=474631&r1=474630&r2=474631
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java Mon Nov 13 18:36:55 2006
@@ -109,7 +109,7 @@
this.outputDirectory, artifact );
File destFile = new File( destDir, destFileName );
- copyFile( artifact.getFile(), destFile, true );
+ copyFile( artifact.getFile(), destFile );
}
protected ArtifactsFilter getMarkedArtifactFilter()
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java?view=diff&rev=474631&r1=474630&r2=474631
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java Mon Nov 13 18:36:55 2006
@@ -61,9 +61,17 @@
* Overwrite snapshot artifacts
* @optional
* @since 1.0
- * @parameter expression="${overWriteSnapshots}" default-value="true"
+ * @parameter expression="${overWriteSnapshots}" default-value="false"
*/
protected boolean overWriteSnapshots;
+
+ /**
+ * Overwrite if newer
+ * @optional
+ * @since 2.0
+ * @parameter expression="${overIfNewer}" default-value="true"
+ */
+ protected boolean overWriteIfNewer;
/**
* Collection of ArtifactItems to work on. (ArtifactItem contains groupId,
@@ -106,17 +114,11 @@
artifactItem.setArtifact( this.getArtifact( artifactItem ) );
+ //TODO:refactor this
String overWrite = artifactItem.getOverWrite();
if ( overWrite == null )
{
- if ( artifactItem.getArtifact().isSnapshot() )
- {
- artifactItem.setDoOverWrite( this.overWriteSnapshots );
- }
- else
- {
- artifactItem.setDoOverWrite( this.overWriteReleases );
- }
+ artifactItem.setDoOverWrite(false);
}
else
{
@@ -198,9 +200,9 @@
*/
private void fillMissingArtifactVersion( ArtifactItem artifact )
{
- this.getLog().debug(
- "Attempting to find missing version in " + artifact.getGroupId() + ":"
- + artifact.getArtifactId() );
+ // this.getLog().debug(
+ // "Attempting to find missing version in " + artifact.getGroupId() + ":"
+ // + artifact.getArtifactId() );
List list = this.project.getDependencies();
@@ -212,7 +214,7 @@
&& dependency.getArtifactId().equals( artifact.getArtifactId() )
&& dependency.getType().equals( artifact.getType() ) )
{
- this.getLog().debug( "Found missing version: " + dependency.getVersion() + " in dependency list." );
+// this.getLog().debug( "Found missing version: " + dependency.getVersion() + " in dependency list." );
artifact.setVersion( dependency.getVersion() );
@@ -230,9 +232,9 @@
&& dependency.getArtifactId().equals( artifact.getArtifactId() )
&& dependency.getType().equals( artifact.getType() ) )
{
- this.getLog().debug(
- "Found missing version: " + dependency.getVersion()
- + " in dependency management list" );
+ // this.getLog().debug(
+ // "Found missing version: " + dependency.getVersion()
+ // + " in dependency management list" );
artifact.setVersion( dependency.getVersion() );
}
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java?view=diff&rev=474631&r1=474630&r2=474631
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java Mon Nov 13 18:36:55 2006
@@ -90,11 +90,6 @@
private boolean doOverWrite;
/**
- * Check Timestamp
- */
- private boolean doOverWriteIfNewer;
-
- /**
* Artifact Item
*/
private Artifact artifact;
@@ -281,5 +276,4 @@
{
this.artifact = artifact;
}
-
}
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java?view=diff&rev=474631&r1=474630&r2=474631
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java Mon Nov 13 18:36:55 2006
@@ -101,7 +101,29 @@
File destFile = new File( artifactItem.getOutputDirectory(), destFileName );
- copyFile( artifact.getFile(), destFile, artifactItem.isDoOverWrite() );
+ // 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." );
+ }
}
}
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java?view=diff&rev=474631&r1=474630&r2=474631
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java Mon Nov 13 18:36:55 2006
@@ -23,12 +23,16 @@
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.MarkerFileFilter;
+import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
+import org.apache.maven.plugin.dependency.utils.markers.MarkerHandler;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
/**
* Goal that retrieves a list of artifacts from the repository and unpacks them
* in a defined location.
+ *
* @since 1.0
* @goal unpack
* @phase process-sources
@@ -86,8 +90,18 @@
{
Artifact artifact = artifactItem.getArtifact();
- File location = artifactItem.getOutputDirectory();
+ MarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory );
+ MarkerFileFilter filter = new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots,
+ this.overWriteIfNewer, handler );
- unpackFile( artifact, location, this.markersDirectory, artifactItem.isDoOverWrite() );
+ if (artifactItem.isDoOverWrite() || filter.okToProcess(artifact))
+ {
+ unpack(artifact.getFile(),artifactItem.getOutputDirectory());
+ handler.setMarker();
+ }
+ else
+ {
+ this.getLog().info( artifact.getFile().getName() + " already unpacked." );
+ }
}
}
Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java?view=diff&rev=474631&r1=474630&r2=474631
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java Mon Nov 13 18:36:55 2006
@@ -67,18 +67,13 @@
throws MojoExecutionException, IOException
{
File src = File.createTempFile( "copy", null );
- Random a = new Random();
- File outputFolder2 = new File( "target/copyTo" + a.nextLong() + "/" );
File dest = new File( mojo.outputDirectory, "toMe.jar" );
assertFalse( dest.exists() );
- assertTrue( mojo.copyFile( src, dest, false ) );
+ mojo.copyFile( src, dest );
assertTrue( dest.exists() );
- assertFalse( mojo.copyFile( src, dest, false ) );
- assertTrue( mojo.copyFile( src, dest, true ) );
-
}
/**
@@ -473,9 +468,9 @@
File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( release, false ) );
Thread.sleep( 100 );
- //round up to the next second
+ // round up to the next second
long time = System.currentTimeMillis() + 1000;
- time = time - (time % 1000);
+ time = time - ( time % 1000 );
copiedFile.setLastModified( time );
Thread.sleep( 100 );
@@ -505,11 +500,12 @@
File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( release, false ) );
Thread.sleep( 100 );
- //round down to the last second
+ // round down to the last second
long time = System.currentTimeMillis();
- time = time - (time % 1000);
+ time = time - ( time % 1000 );
copiedFile.setLastModified( time );
- //wait at least a second for filesystems that only record to the nearest second.
+ // wait at least a second for filesystems that only record to the
+ // nearest second.
Thread.sleep( 1000 );
mojo.execute();
@@ -540,9 +536,9 @@
File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) );
Thread.sleep( 100 );
- //round up to the next second
+ // round up to the next second
long time = System.currentTimeMillis() + 1000;
- time = time - (time % 1000);
+ time = time - ( time % 1000 );
copiedFile.setLastModified( time );
Thread.sleep( 100 );
@@ -573,11 +569,12 @@
File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) );
Thread.sleep( 100 );
- //round down to the last second
+ // round down to the last second
long time = System.currentTimeMillis();
- time = time - (time % 1000);
+ time = time - ( time % 1000 );
copiedFile.setLastModified( time );
- //wait at least a second for filesystems that only record to the nearest second.
+ // wait at least a second for filesystems that only record to the
+ // nearest second.
Thread.sleep( 1000 );
mojo.execute();