Class ScmWagon
- java.lang.Object
-
- org.apache.maven.wagon.AbstractWagon
-
- org.apache.maven.wagon.providers.scm.ScmWagon
-
- All Implemented Interfaces:
Wagon
public class ScmWagon extends AbstractWagon
Wagon provider to get and put files from and to SCM systems, using Maven-SCM as underlying transport. TODO it probably creates problems if the same wagon is used in two different SCM protocols, as instance variables can keep incorrect state. TODO: For doing releases, we either have to be able to add files with checking out the repository structure which may not be possible, or the checkout directory needs to be a constant. Doing releases won't scale if you have to checkout the whole repository structure in order to add 3 files.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.FilecheckoutDirectoryprivate booleanhaveRecursiveCOprivate java.lang.StringpartCOSubdirEmpty string or subdir ending with slash.private org.apache.maven.scm.manager.ScmManagerscmManagerprivate java.lang.StringscmVersionThe SCM version, if any.private java.lang.StringscmVersionTypeThe SCM version type, if any.-
Fields inherited from class org.apache.maven.wagon.AbstractWagon
authenticationInfo, BUFFER_SEGMENT_SIZE, DEFAULT_BUFFER_SIZE, interactive, MAXIMUM_BUFFER_SIZE, MINIMUM_AMOUNT_OF_TRANSFER_CHUNKS, proxyInfo, repository, sessionEventSupport, transferEventSupport
-
Fields inherited from interface org.apache.maven.wagon.Wagon
DEFAULT_CONNECTION_TIMEOUT, DEFAULT_READ_TIMEOUT, ROLE
-
-
Constructor Summary
Constructors Constructor Description ScmWagon()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private intaddFiles(org.apache.maven.scm.provider.ScmProvider scmProvider, org.apache.maven.scm.repository.ScmRepository scmRepository, java.io.File basedir, java.lang.String scmFilePath)Add a file or directory to a SCM repository.private org.apache.maven.scm.command.checkout.CheckOutScmResultcheckOut(org.apache.maven.scm.provider.ScmProvider scmProvider, org.apache.maven.scm.repository.ScmRepository scmRepository, org.apache.maven.scm.ScmFileSet fileSet, boolean recursive)private booleancheckoutDirExists(org.apache.maven.scm.provider.ScmProvider scmProvider)private voidcheckScmResult(org.apache.maven.scm.ScmResult result)Check that the ScmResult was a successful operationvoidcloseConnection()private java.io.FilecreateCheckoutDirectory()private voiddeleteCheckoutDirectory()private java.lang.StringensureDirs(org.apache.maven.scm.provider.ScmProvider scmProvider, org.apache.maven.scm.repository.ScmRepository scmRepository, java.lang.String targetName, Resource resource, boolean recursiveArg)Returns the relative path to targetName in the checkout dir.voidget(java.lang.String resourceName, java.io.File destination)Downloads specified resource from the repository to given file.java.io.FilegetCheckoutDirectory()Get the directory where Wagon will checkout files from SCM.private java.lang.StringgetDirname(java.lang.String resourceName)java.util.List<java.lang.String>getFileList(java.lang.String resourcePath)Returns aListof strings naming the files and directories in the directory denoted by this abstract pathname.booleangetIfNewer(java.lang.String resourceName, java.io.File destination, long timestamp)Not implementedorg.apache.maven.scm.manager.ScmManagergetScmManager()Get theScmManagerused in this Wagonorg.apache.maven.scm.provider.ScmProvidergetScmProvider(java.lang.String scmType)Convenience method to get theScmProviderimplementation to handle the provided SCM typeprivate org.apache.maven.scm.repository.ScmRepositorygetScmRepository(java.lang.String url)java.lang.StringgetScmVersion()Get the scmVersion used in this Wagonjava.lang.StringgetScmVersionType()Get the scmVersionType used in this Wagonprivate booleanisAlwaysRecursive(org.apache.maven.scm.provider.ScmProvider scmProvider)private org.apache.maven.scm.ScmVersionmakeScmVersion()Construct the ScmVersion to use for operations.private org.apache.maven.scm.CommandParametersmkBinaryFlag()private static voidmkdirsThrow(java.io.File f, java.util.List<java.io.File> createdDirs)voidopenConnectionInternal()This will cleanup the checkout directoryvoidput(java.io.File source, java.lang.String targetName)Copy a file from local system to remotevoidputDirectory(java.io.File sourceDirectory, java.lang.String destinationDirectory)Copy a directory from local system to remoteprivate voidputInternal(java.io.File source, java.lang.String targetName)Puts both files and directoriesprivate voidremoveCheckoutDirectory()booleanresourceExists(java.lang.String resourceName)Check if a remote resource existsvoidsetCheckoutDirectory(java.io.File checkoutDirectory)Set the directory where Wagon will checkout files from SCM.voidsetScmManager(org.apache.maven.scm.manager.ScmManager scmManager)Set theScmManagerused in this WagonvoidsetScmVersion(java.lang.String scmVersion)Set the scmVersionvoidsetScmVersionType(java.lang.String scmVersionType)Set the scmVersionTypebooleansupportsDirectoryCopy()Flag indicating if this wagon supports directory copy operations.private booleansupportsPartialCheckout(org.apache.maven.scm.provider.ScmProvider scmProvider)private org.apache.maven.scm.ScmResulttryPartialCheckout(java.lang.String subdir, boolean recursiveArg)-
Methods inherited from class org.apache.maven.wagon.AbstractWagon
addSessionListener, addTransferListener, cleanupGetTransfer, cleanupPutTransfer, connect, connect, connect, connect, connect, connect, createParentDirectories, disconnect, finishGetTransfer, finishPutTransfer, fireGetCompleted, fireGetInitiated, fireGetStarted, firePutCompleted, firePutInitiated, firePutStarted, fireSessionConnectionRefused, fireSessionDebug, fireSessionDisconnected, fireSessionDisconnecting, fireSessionError, fireSessionLoggedIn, fireSessionLoggedOff, fireSessionOpened, fireSessionOpening, fireTransferDebug, fireTransferError, fireTransferProgress, getAuthenticationInfo, getBufferCapacityForTransfer, getPath, getPermissionsOverride, getProxyInfo, getProxyInfo, getReadTimeout, getRepository, getSessionEventSupport, getTimeout, getTransfer, getTransfer, getTransfer, getTransfer, getTransfer, getTransfer, getTransferEventSupport, hasSessionListener, hasTransferListener, isInteractive, openConnection, postProcessListeners, putTransfer, putTransfer, removeSessionListener, removeTransferListener, setInteractive, setPermissionsOverride, setReadTimeout, setSessionEventSupport, setTimeout, setTransferEventSupport, transfer, transfer, transfer, transfer
-
-
-
-
Field Detail
-
scmManager
private volatile org.apache.maven.scm.manager.ScmManager scmManager
-
scmVersion
private java.lang.String scmVersion
The SCM version, if any.
-
scmVersionType
private java.lang.String scmVersionType
The SCM version type, if any. Defaults to "branch".
-
partCOSubdir
private java.lang.String partCOSubdir
Empty string or subdir ending with slash.
-
haveRecursiveCO
private boolean haveRecursiveCO
-
checkoutDirectory
private java.io.File checkoutDirectory
-
-
Method Detail
-
getScmManager
public org.apache.maven.scm.manager.ScmManager getScmManager()
Get theScmManagerused in this Wagon- Returns:
- the
ScmManager
-
setScmManager
public void setScmManager(org.apache.maven.scm.manager.ScmManager scmManager)
Set theScmManagerused in this Wagon- Parameters:
scmManager-
-
getScmVersion
public java.lang.String getScmVersion()
Get the scmVersion used in this Wagon- Returns:
- the scmVersion
-
setScmVersion
public void setScmVersion(java.lang.String scmVersion)
Set the scmVersion- Parameters:
scmVersion- the scmVersion to set
-
getScmVersionType
public java.lang.String getScmVersionType()
Get the scmVersionType used in this Wagon- Returns:
- the scmVersionType
-
setScmVersionType
public void setScmVersionType(java.lang.String scmVersionType)
Set the scmVersionType- Parameters:
scmVersionType- the scmVersionType to set
-
getCheckoutDirectory
public java.io.File getCheckoutDirectory()
Get the directory where Wagon will checkout files from SCM. This directory will be deleted!- Returns:
- directory
-
setCheckoutDirectory
public void setCheckoutDirectory(java.io.File checkoutDirectory)
Set the directory where Wagon will checkout files from SCM. This directory will be deleted!- Parameters:
checkoutDirectory-
-
getScmProvider
public org.apache.maven.scm.provider.ScmProvider getScmProvider(java.lang.String scmType) throws org.apache.maven.scm.manager.NoSuchScmProviderExceptionConvenience method to get theScmProviderimplementation to handle the provided SCM type- Parameters:
scmType- type of SCM, eg.svn,cvs- Returns:
- the
ScmProviderthat will handle provided SCM type - Throws:
org.apache.maven.scm.manager.NoSuchScmProviderException- if there is noScmProviderable to handle that SCM type
-
openConnectionInternal
public void openConnectionInternal() throws ConnectionExceptionThis will cleanup the checkout directory- Specified by:
openConnectionInternalin classAbstractWagon- Throws:
ConnectionException
-
createCheckoutDirectory
private java.io.File createCheckoutDirectory()
-
removeCheckoutDirectory
private void removeCheckoutDirectory() throws ConnectionException- Throws:
ConnectionException
-
makeScmVersion
private org.apache.maven.scm.ScmVersion makeScmVersion()
Construct the ScmVersion to use for operations.If scmVersion is supplied, scmVersionType must also be supplied to take effect.
-
getScmRepository
private org.apache.maven.scm.repository.ScmRepository getScmRepository(java.lang.String url) throws org.apache.maven.scm.repository.ScmRepositoryException, org.apache.maven.scm.manager.NoSuchScmProviderException- Throws:
org.apache.maven.scm.repository.ScmRepositoryExceptionorg.apache.maven.scm.manager.NoSuchScmProviderException
-
put
public void put(java.io.File source, java.lang.String targetName) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationExceptionDescription copied from interface:WagonCopy a file from local system to remote- Parameters:
source- the local filetargetName- the remote destination- Throws:
TransferFailedExceptionResourceDoesNotExistExceptionAuthorizationException
-
putInternal
private void putInternal(java.io.File source, java.lang.String targetName) throws TransferFailedExceptionPuts both files and directories- Parameters:
source-targetName-- Throws:
TransferFailedException
-
ensureDirs
private java.lang.String ensureDirs(org.apache.maven.scm.provider.ScmProvider scmProvider, org.apache.maven.scm.repository.ScmRepository scmRepository, java.lang.String targetName, Resource resource, boolean recursiveArg) throws TransferFailedException, java.io.IOExceptionReturns the relative path to targetName in the checkout dir. If the targetName already exists in the scm, this will be the empty string.- Parameters:
scmProvider-scmRepository-targetName-- Returns:
- Throws:
TransferFailedExceptionjava.io.IOException
-
mkdirsThrow
private static void mkdirsThrow(java.io.File f, java.util.List<java.io.File> createdDirs) throws java.io.IOException- Throws:
java.io.IOException
-
addFiles
private int addFiles(org.apache.maven.scm.provider.ScmProvider scmProvider, org.apache.maven.scm.repository.ScmRepository scmRepository, java.io.File basedir, java.lang.String scmFilePath) throws org.apache.maven.scm.ScmExceptionAdd a file or directory to a SCM repository. If it's a directory all its contents are added recursively. TODO this is less than optimal, SCM API should provide a way to add a directory recursively- Parameters:
scmProvider- SCM providerscmRepository- SCM repositorybasedir- local directory corresponding to scmRepositoryscmFilePath- path of the file or directory to add, relative to basedir- Returns:
- the number of files added.
- Throws:
org.apache.maven.scm.ScmException
-
checkOut
private org.apache.maven.scm.command.checkout.CheckOutScmResult checkOut(org.apache.maven.scm.provider.ScmProvider scmProvider, org.apache.maven.scm.repository.ScmRepository scmRepository, org.apache.maven.scm.ScmFileSet fileSet, boolean recursive) throws org.apache.maven.scm.ScmException- Throws:
org.apache.maven.scm.ScmException
-
mkBinaryFlag
private org.apache.maven.scm.CommandParameters mkBinaryFlag() throws org.apache.maven.scm.ScmException- Throws:
org.apache.maven.scm.ScmException
-
supportsDirectoryCopy
public boolean supportsDirectoryCopy()
Description copied from interface:WagonFlag indicating if this wagon supports directory copy operations.- Specified by:
supportsDirectoryCopyin interfaceWagon- Overrides:
supportsDirectoryCopyin classAbstractWagon- Returns:
- true
-
supportsPartialCheckout
private boolean supportsPartialCheckout(org.apache.maven.scm.provider.ScmProvider scmProvider)
-
isAlwaysRecursive
private boolean isAlwaysRecursive(org.apache.maven.scm.provider.ScmProvider scmProvider)
-
putDirectory
public void putDirectory(java.io.File sourceDirectory, java.lang.String destinationDirectory) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationExceptionDescription copied from interface:WagonCopy a directory from local system to remote- Specified by:
putDirectoryin interfaceWagon- Overrides:
putDirectoryin classAbstractWagon- Parameters:
sourceDirectory- the local directorydestinationDirectory- the remote destination- Throws:
TransferFailedExceptionResourceDoesNotExistExceptionAuthorizationException
-
checkScmResult
private void checkScmResult(org.apache.maven.scm.ScmResult result) throws org.apache.maven.scm.ScmExceptionCheck that the ScmResult was a successful operation- Parameters:
result-- Throws:
TransferFailedException- if result was not a successful operationorg.apache.maven.scm.ScmException
-
closeConnection
public void closeConnection() throws ConnectionException- Specified by:
closeConnectionin classAbstractWagon- Throws:
ConnectionException
-
getIfNewer
public boolean getIfNewer(java.lang.String resourceName, java.io.File destination, long timestamp) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationExceptionNot implemented- Returns:
trueif newer resource has been downloaded,falseif resource in the repository is older or has the same age.- Throws:
java.lang.UnsupportedOperationException- alwaysTransferFailedExceptionResourceDoesNotExistExceptionAuthorizationException
-
get
public void get(java.lang.String resourceName, java.io.File destination) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationExceptionDescription copied from interface:WagonDownloads specified resource from the repository to given file.
-
tryPartialCheckout
private org.apache.maven.scm.ScmResult tryPartialCheckout(java.lang.String subdir, boolean recursiveArg) throws org.apache.maven.scm.ScmException, java.io.IOException- Throws:
org.apache.maven.scm.ScmExceptionjava.io.IOException
-
deleteCheckoutDirectory
private void deleteCheckoutDirectory() throws java.io.IOException- Throws:
java.io.IOException
-
checkoutDirExists
private boolean checkoutDirExists(org.apache.maven.scm.provider.ScmProvider scmProvider)
-
getFileList
public java.util.List<java.lang.String> getFileList(java.lang.String resourcePath) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationExceptionDescription copied from interface:WagonReturns aListof strings naming the files and directories in the directory denoted by this abstract pathname. If this abstract pathname does not denote a directory, or does not exist, then this method throwsResourceDoesNotExistException. Otherwise aListof strings is returned, one for each file or directory in the directory. Names denoting the directory itself and the directory's parent directory are not included in the result. Each string is a file name rather than a complete path. There is no guarantee that the name strings in the resulting list will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.- Specified by:
getFileListin interfaceWagon- Overrides:
getFileListin classAbstractWagon- Parameters:
resourcePath- directory to list contents of- Returns:
- a List<String> with filenames/directories at the resourcepath.
- Throws:
TransferFailedException- if there's an error trying to access the remote sideResourceDoesNotExistException- if destinationDirectory does not exist or is not a directoryAuthorizationException- if not authorized to list the contents of the directory- See Also:
AbstractWagon.getFileList(java.lang.String)
-
resourceExists
public boolean resourceExists(java.lang.String resourceName) throws TransferFailedException, AuthorizationExceptionDescription copied from interface:WagonCheck if a remote resource exists- Specified by:
resourceExistsin interfaceWagon- Overrides:
resourceExistsin classAbstractWagon- Returns:
- whether the resource exists or not
- Throws:
TransferFailedException- if there's an error trying to access the remote sideAuthorizationException- if not authorized to verify the existence of the resource
-
getDirname
private java.lang.String getDirname(java.lang.String resourceName)
-
-