Class 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 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
    • Constructor Detail

      • ScmWagon

        public ScmWagon()
    • Method Detail

      • getScmManager

        public org.apache.maven.scm.manager.ScmManager getScmManager()
        Get the ScmManager used in this Wagon
        Returns:
        the ScmManager
      • setScmManager

        public void setScmManager​(org.apache.maven.scm.manager.ScmManager scmManager)
        Set the ScmManager used 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.NoSuchScmProviderException
        Convenience method to get the ScmProvider implementation to handle the provided SCM type
        Parameters:
        scmType - type of SCM, eg. svn, cvs
        Returns:
        the ScmProvider that will handle provided SCM type
        Throws:
        org.apache.maven.scm.manager.NoSuchScmProviderException - if there is no ScmProvider able to handle that SCM type
      • createCheckoutDirectory

        private java.io.File createCheckoutDirectory()
      • 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.ScmRepositoryException
        org.apache.maven.scm.manager.NoSuchScmProviderException
      • 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.IOException
        Returns 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:
        TransferFailedException
        java.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.ScmException
        Add 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 provider
        scmRepository - SCM repository
        basedir - local directory corresponding to scmRepository
        scmFilePath - 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
      • supportsPartialCheckout

        private boolean supportsPartialCheckout​(org.apache.maven.scm.provider.ScmProvider scmProvider)
      • isAlwaysRecursive

        private boolean isAlwaysRecursive​(org.apache.maven.scm.provider.ScmProvider scmProvider)
      • checkScmResult

        private void checkScmResult​(org.apache.maven.scm.ScmResult result)
                             throws org.apache.maven.scm.ScmException
        Check that the ScmResult was a successful operation
        Parameters:
        result -
        Throws:
        TransferFailedException - if result was not a successful operation
        org.apache.maven.scm.ScmException
      • 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.ScmException
        java.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,
                                                            AuthorizationException
        Description copied from interface: Wagon

        Returns a List of 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 throws ResourceDoesNotExistException. Otherwise a List of 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:
        getFileList in interface Wagon
        Overrides:
        getFileList in class AbstractWagon
        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 side
        ResourceDoesNotExistException - if destinationDirectory does not exist or is not a directory
        AuthorizationException - if not authorized to list the contents of the directory
        See Also:
        AbstractWagon.getFileList(java.lang.String)
      • getDirname

        private java.lang.String getDirname​(java.lang.String resourceName)