Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2011 JFrog Ltd.
   *
   * Licensed 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.jfrog.hudson.release.scm.svn;
 
 
 import java.io.File;
Performs commit operations on Subversion repository configured for the project.

Author(s):
Yossi Shaul
 
     private static Logger debuggingLogger = Logger.getLogger(SubversionManager.class.getName());
 
     public SubversionManager(AbstractBuild<?, ?> abstractBuildTaskListener buildListener) {
         super(abstractBuildbuildListener);
     }
 
     public void prepare() {
         // nothing to do here
     }

    
Commits the working copy.

Parameters:
commitMessage@return The commit info upon successful operation.
Throws:
java.io.IOException On IO of SVN failure
 
     public void commitWorkingCopy(final String commitMessagethrows IOExceptionInterruptedException {
         .getWorkspace().act(new SVNCommitWorkingCopyCallable(commitMessagegetLocation(),
                 getSvnAuthenticationProvider(), ));
     }

    
Creates a tag directly from the working copy.

Parameters:
tagUrl The URL of the tag to create.
commitMessage Commit message
Returns:
The commit info upon successful operation.
Throws:
java.io.IOException On IO of SVN failure
 
     public void createTag(final String tagUrlfinal String commitMessage)
             throws IOExceptionInterruptedException {
         .getWorkspace()
                 .act(new SVNCreateTagCallable(tagUrlcommitMessagegetLocation(), getSvnAuthenticationProvider(),
                         ));
     }

    
Revert all the working copy changes.
 
     public void revertWorkingCopy() throws IOExceptionInterruptedException {
         .getWorkspace()
                 .act(new RevertWorkingCopyCallable(getLocation(), getSvnAuthenticationProvider(), ));
     }

    
Attempts to revert the working copy. In case of failure it just logs the error.
 
     public void safeRevertWorkingCopy() {
         try {
             revertWorkingCopy();
         } catch (Exception e) {
             .log(."Failed to revert working copy"e);
             log("Failed to revert working copy: " + e.getLocalizedMessage());
             Throwable cause = e.getCause();
             if (!(cause instanceof SVNException)) {
                 return;
             }
             SVNException svnException = (SVNExceptioncause;
            if (svnException.getErrorMessage().getErrorCode() == .) {
                // work space locked attempt cleanup and try to revert again
                try {
                    cleanupWorkingCopy();
                } catch (Exception unlockException) {
                    .log(."Failed to cleanup working copy"e);
                    log("Failed to cleanup working copy: " + e.getLocalizedMessage());
                    return;
                }
                try {
                    revertWorkingCopy();
                } catch (Exception revertException) {
                    log("Failed to revert working copy on the 2nd attempt: " + e.getLocalizedMessage());
                }
            }
        }
    }
    private void cleanupWorkingCopy() throws IOExceptionInterruptedException {
    }
    public void safeRevertTag(String tagUrlString commitMessageSuffix) {
        try {
            log("Reverting subversion tag: " + tagUrl);
            SVNURL svnUrl = SVNURL.parseURIEncoded(tagUrl);
            SVNCommitClient commitClient = new SVNCommitClient(createAuthenticationManager(), null);
            SVNCommitInfo commitInfo = commitClient.doDelete(new SVNURL[]{svnUrl},
                     + commitMessageSuffix);
            SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
            if (errorMessage != null) {
                log("Failed to revert '" + tagUrl + "': " + errorMessage.getFullMessage());
            }
        } catch (SVNException e) {
            log("Failed to revert '" + tagUrl + "': " + e.getLocalizedMessage());
        }
    }
    public String getRemoteUrl() {
        return getLocation().;
    }
        return getJenkinsScm().getLocations()[0];
    }
        sam.setAuthenticationProvider(sap);
        return sam;
    }
        if (sap == null) {
            throw new AbortException("Subversion authentication info is not set.");
        }
        return sap;
    }
    private static class SVNCommitWorkingCopyCallable implements FilePath.FileCallable<Object> {
        private final String commitMessage;
        private final SubversionSCM.ModuleLocation location;
        private final ISVNAuthenticationProvider authProvider;
        private final TaskListener buildListener;
        public SVNCommitWorkingCopyCallable(String commitMessageSubversionSCM.ModuleLocation location,
                                            ISVNAuthenticationProvider providerTaskListener listener) {
            this. = commitMessage;
            this. = location;
             = provider;
             = listener;
        }
        public Object invoke(File wsVirtualChannel channelthrows IOExceptionInterruptedException {
            File workingCopy = new File(ws.getLocalDir()).getCanonicalFile();
            try {
                ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
                sam.setAuthenticationProvider();
                SVNCommitClient commitClient = new SVNCommitClient(samnull);
                .getLogger().println("[RELEASE] " + );
                .fine(String.format("Committing working copy: '%s'"workingCopy));
                SVNCommitInfo commitInfo = commitClient.doCommit(new File[]{workingCopy}, true,
                        nullnulltruetrue.);
                SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
                if (errorMessage != null) {
                    throw new IOException("Failed to commit working copy: " + errorMessage.getFullMessage());
                }
                return null;
            } catch (SVNException e) {
                throw new IOException(e.getMessage());
            }
        }
        private static final long serialVersionUID = 1L;
    }

    
Creates a tag directly from the working copy.
    private static class SVNCreateTagCallable implements FilePath.FileCallable<Object> {
        private final String tagUrl;
        private final String commitMessage;
        private final SubversionSCM.ModuleLocation location;
        private final ISVNAuthenticationProvider authProvider;
        private final TaskListener buildListener;
        public SVNCreateTagCallable(String tagUrlString commitMessageSubversionSCM.ModuleLocation location,
                                    ISVNAuthenticationProvider providerTaskListener listener) {
            this. = tagUrl;
            this. = commitMessage;
            this. = location;
             = provider;
             = listener;
        }
        public Object invoke(File wsVirtualChannel channelthrows IOExceptionInterruptedException {
            File workingCopy = new File(ws.getLocalDir()).getCanonicalFile();
            try {
                SVNURL svnUrl = SVNURL.parseURIEncoded();
                ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
                sam.setAuthenticationProvider();
                SVNCopyClient copyClient = new SVNCopyClient(samnull);
                .getLogger().println("[RELEASE] Creating subversion tag: " + );
                SVNCopySource source = new SVNCopySource(..workingCopy);
                SVNCommitInfo commitInfo = copyClient.doCopy(new SVNCopySource[]{source},
                        svnUrlfalsetruetruenew SVNProperties());
                SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
                if (errorMessage != null) {
                    throw new IOException("Failed to create tag: " + errorMessage.getFullMessage());
                }
                return null;
            } catch (SVNException e) {
                throw new IOException("Subversion tag creation failed: " + e.getMessage());
            }
        }
    }
    private static class RevertWorkingCopyCallable implements FilePath.FileCallable<Object> {
        private final SubversionSCM.ModuleLocation location;
        private final ISVNAuthenticationProvider authProvider;
        private final TaskListener listener;
        public RevertWorkingCopyCallable(SubversionSCM.ModuleLocation locationISVNAuthenticationProvider authProvider,
                                         TaskListener listener) {
            this. = location;
            this. = authProvider;
            this. = listener;
        }
        public Object invoke(File wsVirtualChannel channelthrows IOExceptionInterruptedException {
            File workingCopy = new File(ws.getLocalDir()).getCanonicalFile();
            try {
                log("Reverting working copy: " + workingCopy);
                ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
                sam.setAuthenticationProvider();
                SVNWCClient wcClient = new SVNWCClient(samnull);
                wcClient.doRevert(new File[]{workingCopy}, .null);
                return null;
            } catch (SVNException e) {
                throw new IOException(e.getMessage());
            }
        }
    }
    private static class CleanupCallable implements FilePath.FileCallable<Object> {
        private final SubversionSCM.ModuleLocation location;
        private final ISVNAuthenticationProvider authProvider;
        private final TaskListener listener;
        private CleanupCallable(SubversionSCM.ModuleLocation locationISVNAuthenticationProvider authProvider,
                                TaskListener listener) {
            this. = location;
            this. = authProvider;
            this. = listener;
        }
        public Object invoke(File wsVirtualChannel channelthrows IOExceptionInterruptedException {
            File workingCopy = new File(ws.getLocalDir()).getCanonicalFile();
            try {
                log("Cleanup working copy: " + workingCopy);
                ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
                sam.setAuthenticationProvider();
                SVNWCClient wcClient = new SVNWCClient(samnull);
                wcClient.doCleanup(workingCopy);
                return null;
            } catch (SVNException e) {
                throw new IOException(e.getMessage());
            }
        }
    }
New to GrepCode? Check out our FAQ X