Groovy Gradle - Do SVN Commands without having SVN installed.


/ Published in: Groovy
Save to your folder(s)

Sample SVN call from gradle: doSvnMain( 'your', 'svn', 'args', 'go', 'here' );


Copy this code and paste it in your HTML
  1. /*
  2. File : helperSvn.gradle
  3. Author: Laurence Toenjes
  4. Date : 3/31/2013
  5.  
  6. Example of how to use:
  7. 1. Put this file in the same directory as your build.gradle file.
  8.  
  9. 2. Near the very top of your build.gradle source file add this line:
  10. apply from: 'helperSvn.gradle'
  11.  
  12. 3. You can now do svn commands like:
  13.  
  14. doSvnMain( 'export', 'http://svn.codehaus.org/gmod/gsql/tags/gsql-1.5.0/', 'build/svnExport' );
  15.  
  16. doSvnMain( 'help' );
  17.  
  18. ... etc. ...
  19.  
  20. Note: each command line arg you would normally supply to a svn command should be an arg passed to doSvnMain
  21. (since we are not using the OS shell you should probably not have to double quote any of the args).
  22. */
  23.  
  24. import org.tmatesoft.svn.cli.SVN;
  25.  
  26. buildscript {
  27. repositories { mavenCentral() }
  28. dependencies { classpath( 'org.tmatesoft.svnkit:svnkit:1.7.8', 'org.tmatesoft.svnkit:svnkit-cli:1.7.8' ) }
  29. }
  30.  
  31. project.ext.SVN = SVN; /* for certain scenarios might be useful to share this project var */
  32.  
  33. def _disableSystemExitCall = {
  34. System.setSecurityManager(
  35. @Override public void checkPermission(java.security.Permission perm) {}
  36. @Override public void checkExit(int status) { throw new SecurityException(); }
  37. }
  38. );
  39. };
  40.  
  41. def _enableSystemExitCall = { System.setSecurityManager(null); };
  42.  
  43. /* for certain scenarios might be useful to share these closures with build */
  44. project.ext.disableSystemExitCall = _disableSystemExitCall;
  45. project.ext.enableSystemExitCall = _enableSystemExitCall;
  46.  
  47. /* key method/closure - used as: doSvnMain( 'your', 'svn', 'args', 'go', 'here' ); */
  48. project.ext.doSvnMain = { String... aSvnArgs ->
  49. _disableSystemExitCall(); /* stop SVN.main from doing a System.exit call */
  50. try {
  51. SVN.main( aSvnArgs as String[] );
  52. } finally {
  53. _enableSystemExitCall();
  54. }
  55. } ;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.