Advertisement
KosIvantsov

svn_status.groovy

Jul 13th, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 3.18 KB | None | 0 0
  1. /*
  2.  * #Purpose:    Check SVN status of project files
  3.  *
  4.  * @author:     Kos Ivantsov
  5.  * @date:       2013-07-13
  6.  * @version:    0.1
  7.  *
  8.  */
  9.  
  10. import static javax.swing.JOptionPane.*
  11. import static org.omegat.util.Platform.*
  12. import org.omegat.core.team.SVNRemoteRepository
  13. import org.tmatesoft.svn.core.*
  14. import org.tmatesoft.svn.core.wc.*
  15.  
  16. def prop = project.getProjectProperties()
  17. if (!prop) {
  18.     final def title = 'SVN status'
  19.     final def msg   = 'Please try again after you open a project.'
  20.     showMessageDialog null, msg, title, INFORMATION_MESSAGE
  21.     return
  22. }
  23.  
  24. if (project.isProjectLoaded()) {
  25.     def folder = new File(prop.getProjectRoot())
  26.     def projsav = new File(prop.getProjectRoot() + "omegat", "project_save.tmx")
  27.     def glos = new File(prop.writeableGlossary)
  28.     def curfile = new File(prop.getSourceRoot() + editor.getCurrentFile())
  29.     def curfile_svn = 'none'
  30.     if (SVNRemoteRepository.isSVNDirectory(folder)) {
  31.         def clientManager = SVNClientManager.newInstance();
  32.         try {
  33.             folder_status_r = clientManager.getStatusClient().doStatus(folder, true, true);
  34.         } catch (SVNException e) {
  35.             if (e.getErrorMessage().getErrorCode().getCode()==175002) {
  36.                         //no connection to host
  37.                         console.println "No connection to host"
  38.                         final def title = 'SVN status'
  39.                         final def msg   = 'No connection to host.'
  40.                         showMessageDialog null, msg, title, INFORMATION_MESSAGE
  41.                         return
  42.                     }else throw e
  43.             }
  44.         projsav_status_r = clientManager.getStatusClient().doStatus(projsav, true, true);
  45.         glos_status_r  = clientManager.getStatusClient().doStatus(glos, true, true);
  46.         try {
  47.             curfile_status_r = clientManager.getStatusClient().doStatus(curfile, true, true);
  48.         } catch (SVNException e) {
  49.             if (e.getErrorMessage().getErrorCode().getCode()==155007) {
  50.                     //file is outside repository, so not under version control.
  51.                     curfile_statusType = "not under version control"
  52.                     curfile_svn = 'notundersvn'
  53.                     cfstat = curfile_statusType
  54.                 } else throw e
  55.             }
  56.         if (curfile_svn != 'notundersvn' ) {
  57.             curfile_status_r = clientManager.getStatusClient().doStatus(curfile, true, true)
  58.             SVNStatusType curfile_statusType = curfile_status_r.getContentsStatus()
  59.             cfstat = curfile_statusType
  60.         }
  61.         SVNStatusType folder_statusType = folder_status_r.getContentsStatus();
  62.         SVNStatusType projsav_statusType = projsav_status_r.getContentsStatus();
  63.         SVNStatusType glos_statusType = glos_status_r.getContentsStatus();
  64.         console.println "\n"
  65.         console.println "Project folder status: " +folder_statusType+"\n"
  66.         console.println "project_save.tmx status: "+projsav_statusType+"\n"
  67.         console.println "Glossary status: "+glos_statusType+"\n"
  68.         console.println "Current file status: "+cfstat
  69.         final def title = 'SVN status'
  70.         final def msg   = "Project folder status: " +folder_statusType+"\n"+"project_save.tmx status: "+projsav_statusType+"\n"+"Glossary status: "+glos_statusType+"\n"+"Current file status: " + cfstat
  71.         showMessageDialog null, msg, title, INFORMATION_MESSAGE
  72.         return
  73.     }else{
  74.     console.println "Not a Team project" }
  75.     final def title = 'SVN status'
  76.     final def msg   = 'Status unavailable.\nNot a Team project.'
  77.     showMessageDialog null, msg, title, INFORMATION_MESSAGE
  78.     return
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement