Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle incremental upload/download #38

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/main/java/org/codehaus/mojo/wagon/CopyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
* under the License.
*/

import java.io.File;
import java.io.IOException;

import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.WagonException;
import org.codehaus.mojo.wagon.shared.ContinuationType;
import org.codehaus.mojo.wagon.shared.WagonCopy;
import org.codehaus.mojo.wagon.shared.WagonFileSet;

Expand Down Expand Up @@ -60,10 +62,26 @@ public class CopyMojo
@Parameter( property = "wagon.caseSensitive")
private boolean caseSensitive = true;

/**
* Local directory to store downloaded artifacts. This directory is needed in order to use continuation type ONLY_MISSING during the download from source Wagon.
* If not provided, the artifacts are downloaded to a temporary directory and the continuation type ONLY_MISSING will only work during the upload to target Wagon
*/
@Parameter( property = "wagon.downloadDirectory" )
private File downloadDirectory;

/**
* Configure the continuation type.
* When continuation type is ONLY_MISSING, download file from source Wagon that do not exist in
* downloadDirectory and copy files that do not exist in target Wagon
* When continuation type is NONE, copy all files
*/
@Parameter( property = "wagon.continuationType" )
private ContinuationType continuationType = ContinuationType.NONE;

/**
* Remote path relative to target's url to copy files to.
*/
@Parameter( property = "wagon.toDir")
@Parameter( property = "wagon.toDir" )
private String toDir = "";

@Component
Expand All @@ -74,8 +92,11 @@ protected void copy( Wagon srcWagon, Wagon targetWagon )
throws IOException, WagonException
{
WagonFileSet fileSet = this.getWagonFileSet( fromDir, includes, excludes, caseSensitive, toDir );

wagonCopy.copy( srcWagon, fileSet, targetWagon, optimize, this.getLog() );
if ( downloadDirectory != null )
{
fileSet.setDownloadDirectory(downloadDirectory);
}
wagonCopy.copy(srcWagon, fileSet, targetWagon, optimize, this.getLog(), continuationType);
}

}
12 changes: 11 additions & 1 deletion src/main/java/org/codehaus/mojo/wagon/DownloadMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.WagonException;
import org.codehaus.mojo.wagon.shared.ContinuationType;
import org.codehaus.mojo.wagon.shared.WagonFileSet;

/**
Expand All @@ -41,14 +42,23 @@ public class DownloadMojo
@Parameter( property = "wagon.toDir", defaultValue = "${project.build.directory}/wagon-plugin")
private File toDir;


/**
* Configure the continuation type
* When continuation type is ONLY_MISSING, download file from source Wagon that do not exist in toDir directory
* When continuation type is NONE, download all files
*/
@Parameter( property = "wagon.continuationType")
private ContinuationType continuationType = ContinuationType.NONE;

@Override
protected void execute( Wagon wagon )
throws WagonException
{
WagonFileSet fileSet = this.getWagonFileSet();
fileSet.setDownloadDirectory( this.toDir );

this.wagonDownload.download( wagon, fileSet, this.getLog() );
this.wagonDownload.download( wagon, fileSet, this.getLog(), continuationType );
}

}
11 changes: 10 additions & 1 deletion src/main/java/org/codehaus/mojo/wagon/UploadMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.maven.shared.model.fileset.FileSet;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.WagonException;
import org.codehaus.mojo.wagon.shared.ContinuationType;
import org.codehaus.mojo.wagon.shared.WagonUpload;
import org.codehaus.plexus.util.StringUtils;

Expand Down Expand Up @@ -85,6 +86,14 @@ public class UploadMojo
@Component
protected WagonUpload wagonUpload;

/**
* Configure the continuation type
* When continuation type is ONLY_MISSING, upload files that do not exist in target Wagon
* When continuation type is NONE, upload all files
*/
@Parameter( property = "wagon.continuationType" )
private ContinuationType continuationType = ContinuationType.NONE;

@Override
protected void execute( Wagon wagon )
throws WagonException, IOException
Expand All @@ -109,7 +118,7 @@ protected void execute( Wagon wagon )

fileSet.setOutputDirectory( toDir );

this.wagonUpload.upload( wagon, fileSet, optimize );
this.wagonUpload.upload( wagon, fileSet, optimize, continuationType );
}

}
12 changes: 12 additions & 0 deletions src/main/java/org/codehaus/mojo/wagon/shared/ContinuationType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.codehaus.mojo.wagon.shared;

/**
* Continuation type is used to configure the download/upload continuation
*/
public enum ContinuationType {
/** no continuation (old default)*/
NONE,
/** skip existing files */
ONLY_MISSING

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class DefaultWagonCopy
private WagonUpload uploader;

@Override
public void copy( Wagon src, WagonFileSet wagonFileSet, Wagon target, boolean optimize, Log logger )
public void copy(Wagon src, WagonFileSet wagonFileSet, Wagon target, boolean optimize, Log logger, ContinuationType continuationType)
throws WagonException, IOException
{
if ( wagonFileSet == null )
Expand All @@ -64,13 +64,13 @@ public void copy( Wagon src, WagonFileSet wagonFileSet, Wagon target, boolean op

try
{
this.downloader.download( src, wagonFileSet, logger );
this.downloader.download( src, wagonFileSet, logger, continuationType );

FileSet localFileSet = new FileSet();
localFileSet.setDirectory( wagonFileSet.getDownloadDirectory().getAbsolutePath() );
localFileSet.setOutputDirectory( wagonFileSet.getOutputDirectory() );

this.uploader.upload( target, localFileSet, optimize );
this.uploader.upload( target, localFileSet, optimize, continuationType );
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List getFileList( Wagon wagon, WagonFileSet fileSet, Log logger )
}

@Override
public void download( Wagon wagon, WagonFileSet remoteFileSet, Log logger )
public void download( Wagon wagon, WagonFileSet remoteFileSet, Log logger, ContinuationType continuationType )
throws WagonException
{
List fileList = this.getFileList( wagon, remoteFileSet, logger );
Expand All @@ -82,12 +82,25 @@ public void download( Wagon wagon, WagonFileSet remoteFileSet, Log logger )
remoteFile = remoteFileSet.getDirectory() + "/" + remoteFile;
}

logger.info( "Downloading " + url + remoteFile + " to " + destination + " ..." );

wagon.get( remoteFile, destination );
if( continuationType.equals(ContinuationType.ONLY_MISSING) && destination.exists())
{
logger.info( "Skipping download " + url + remoteFile + " to " + destination + " ...Destination already exist" );
}
else
{
logger.info( "Downloading " + url + remoteFile + " to " + destination + " ..." );
wagon.get(remoteFile, destination);
}
}
}

@Override
public void download( Wagon wagon, WagonFileSet remoteFileSet, Log logger)
throws WagonException
{
download(wagon, remoteFileSet, logger, ContinuationType.NONE);
}

@Override
public boolean exists( Wagon wagon, String resource )
throws WagonException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class DefaultWagonUpload
@Requirement
private ArchiverManager archiverManager;

public void upload( Wagon wagon, FileSet fileset )
public void uploadBasic(Wagon wagon, FileSet fileset, ContinuationType continuationType)
throws WagonException
{

Expand Down Expand Up @@ -76,9 +76,14 @@ public void upload( Wagon wagon, FileSet fileset )

File source = new File( fileset.getDirectory(), file );

LOG.info( "Uploading " + source + " to " + url + relativeDestPath + " ..." );

wagon.put( source, relativeDestPath );
if ( continuationType.equals(ContinuationType.ONLY_MISSING) && wagon.resourceExists(relativeDestPath) )
{
LOG.info("Skipping upload " + source + " to " + url + relativeDestPath + " ... Destination already exist");
} else
{
LOG.info("Uploading " + source + " to " + url + relativeDestPath + " ...");
wagon.put(source, relativeDestPath);
}
}

}
Expand All @@ -87,9 +92,16 @@ public void upload( Wagon wagon, FileSet fileset )
public void upload( Wagon wagon, FileSet fileset, boolean optimize )
throws WagonException, IOException
{
if ( !optimize )
upload(wagon, fileset, optimize, ContinuationType.NONE);
}

@Override
public void upload( Wagon wagon, FileSet fileset, boolean optimize, ContinuationType continuationType)
throws WagonException, IOException
{
if (!optimize)
{
upload( wagon, fileset );
uploadBasic( wagon, fileset, continuationType);
return;
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/codehaus/mojo/wagon/shared/WagonCopy.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ public interface WagonCopy
/**
* Transfer files between 2 Wagon URLs. If download directory is not given in the fileset a temporary one will be
* created.
*
*
* @param fromWagon - source Wagon
* @param fileset - file set to copy
* @param toWagon - target Wagon
* @param optimize - locally compressed and remotely uncompress for scp only
* @param logger - logger used
* @param continuationType - continuation type.
* When continuation type is ONLY_MISSING, download file from source Wagon that do not
* exist in downloadDirectory and copy files that do not exist in target Wagon
* When continuation type is NONE, copy all files
* @throws WagonException if any wagon error
* @throws IOException if any io error
*/
void copy( Wagon fromWagon, WagonFileSet fileset, Wagon toWagon, boolean optimize, Log logger )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not be backward compatible change

throws WagonException, IOException;

void copy( Wagon fromWagon, WagonFileSet fileset, Wagon toWagon, boolean optimize, Log logger, ContinuationType continuationType )
throws WagonException, IOException;
}
16 changes: 15 additions & 1 deletion src/main/java/org/codehaus/mojo/wagon/shared/WagonDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,29 @@ public interface WagonDownload
*/
List getFileList( Wagon wagon, WagonFileSet fileSet, Log logger )
throws WagonException;
/**
* @param wagon - a Wagon instance
* @param remoteFileSet - Criteria to build the list
* @param logger - logger used
* @param continuationType - continuation type.
* When ONLY_MISSING, download only files that do not already exist in destination
* When continuation type is NONE, download all files
* @throws WagonException if any wagon error
*/
void download( Wagon wagon, WagonFileSet remoteFileSet, Log logger, ContinuationType continuationType )
throws WagonException;

/**
* @param wagon - a Wagon instance
* @param remoteFileSet - Criteria to build the list
* @param logger - logger used
*
* @throws WagonException if any wagon error
*/
void download( Wagon wagon, WagonFileSet remoteFileSet, Log logger )
throws WagonException;
throws WagonException;



/**
* @param wagon - a Wagon instance
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/org/codehaus/mojo/wagon/shared/WagonUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ public interface WagonUpload

/**
* Upload a set of files via FileSet interface to a remote repository via Wagon
*
*
* @param wagon - a Wagon instance
* @param fileset file set to upload
* @param optimize locally compressed and uncompress at the remote site if scp is use
* @param continuationType continuation type. Incremental upload will only upload resources that doesn't exist
* @throws WagonException if nay wagon exception
* @throws IOException if any io exception
*/
void upload( Wagon wagon, FileSet fileset, boolean optimize, ContinuationType continuationType )
throws WagonException, IOException;

/**
* Upload a set of files via FileSet interface to a remote repository via Wagon
*
* @param wagon - a Wagon instance
* @param fileset file set to upload
* @param optimize locally compressed and uncompress at the remote site if scp is use
Expand Down