Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

lukewpatterson, groovy maven plugin

By: a guest on Sep 18th, 2010  |  syntax: Groovy  |  size: 4.32 KB  |  views: 95  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import org.apache.maven.project.MavenProject
  2. import org.apache.maven.scm.provider.ScmUrlUtils
  3. import org.codehaus.gmaven.mojo.GroovyMojo
  4.  
  5. /**
  6.  * @goal commit-projects
  7.  */
  8. public class CommitProjectsMojo extends GroovyMojo
  9. {
  10.     /**
  11.      * @parameter expression="${project}"
  12.      * @required
  13.      * @readonly
  14.      */
  15.     MavenProject project
  16.  
  17.     /**
  18.      * The SCM connection URL for developers.
  19.      *
  20.      * @parameter default-value="${project.scm.developerConnection}"
  21.      * @required
  22.      */
  23.     private String developerConnectionUrl;
  24.  
  25.     /**
  26.      * @parameter expression="${commit-projects.svnUserName}"
  27.      */
  28.     private String svnUsername;
  29.  
  30.     /**
  31.      * @parameter expression="${commit-projects.svnPassword}"
  32.      */
  33.     private String svnPassword;
  34.  
  35.     void execute() {
  36.         if (!ScmUrlUtils.isValid(developerConnectionUrl)) {
  37.             log.info('developerConnectionUrl is not valid: ' + developerConnectionUrl)
  38.             log.info('skipping...')
  39.             return
  40.         }
  41.         def providerSpecificPart = ScmUrlUtils.getProviderSpecificPart(developerConnectionUrl)
  42.  
  43.         if(svnUsername == null) {
  44.             ant.input(message: 'SVN Username: ', addproperty: 'commit-projects.svnUserName')
  45.             svnUsername = ant.project.properties.'commit-projects.svnUserName'
  46.             System.properties.setProperty('commit-projects.svnUserName', svnUsername)
  47.         }
  48.         if(svnPassword == null) {
  49.             ant.input(message: 'SVN Password: ', addproperty: 'commit-projects.svnPassword') {
  50.                 handler(classname: "org.apache.tools.ant.input.SecureInputHandler")
  51.             }
  52.             svnPassword = ant.project.properties.'commit-projects.svnPassword'
  53.             System.properties.setProperty('commit-projects.svnPassword', svnPassword)
  54.         }
  55.  
  56.         log.info('Getting ready to create: ' + providerSpecificPart)
  57.         ant.input(message: 'Press Return key to continue...')
  58.  
  59.         ant.exec(executable: 'svn', dir: project.basedir, failonerror: true) {
  60.             arg(value: 'mkdir')
  61.             arg(value: '--parents')
  62.             arg(value: '-m')
  63.             arg(value: '[wizard-archetype-maven-plugin] Create project directory.')
  64.             arg(value: providerSpecificPart)
  65.             arg(value: '--username')
  66.             arg(value: svnUsername)
  67.             arg(value: '--password')
  68.             arg(value: svnPassword)
  69.         }
  70.  
  71.         log.info('Checking out: ' + providerSpecificPart)
  72.         ant.exec(executable: 'svn', dir: project.basedir, failonerror: true) {
  73.             arg(value: 'checkout')
  74.             arg(value: providerSpecificPart)
  75.             arg(value: '-r')
  76.             arg(value: 'HEAD')
  77.             arg(value: '--depth=immediates')
  78.             arg(value: '--force')
  79.             arg(value: '--username')
  80.             arg(value: svnUsername)
  81.             arg(value: '--password')
  82.             arg(value: svnPassword)
  83.             arg(value: project.basedir)
  84.         }
  85.  
  86.         log.info('Adding src')
  87.         ant.exec(executable: 'svn', dir: project.basedir, failonerror: true) {
  88.             arg(value: 'add')
  89.             arg(value: 'src')
  90.             arg(value: '--force')
  91.         }
  92.  
  93.         log.info('Adding pom.xml')
  94.         ant.exec(executable: 'svn', dir: project.basedir, failonerror: true) {
  95.             arg(value: 'add')
  96.             arg(value: 'pom.xml')
  97.             arg(value: '--force')
  98.         }
  99.  
  100.         def CrLf = "\r\n";
  101.         def ignores = '.checkstyle' + CrLf + '.classpath' + CrLf + '.fbprefs' + CrLf + '.project' + CrLf + '.settings' + CrLf + 'META-INF' + CrLf + 'bin' + CrLf + 'plugin.xml' + CrLf + 'target' + CrLf + 'OSGI-INF'
  102.         log.info('Ignoring: ' + ignores)
  103.         ant.exec(executable: 'svn', dir: project.basedir, failonerror: true) {
  104.             arg(value: 'propset')
  105.             arg(value: 'svn:ignore')
  106.             arg(value: ignores)
  107.             arg(value: project.basedir)
  108.         }
  109.  
  110.         log.info('Committing project')
  111.         ant.exec(executable: 'svn', dir: project.basedir) {
  112.             arg(value: 'commit')
  113.             arg(value: '-m')
  114.             arg(value: '[wizard-archetype-maven-plugin] Create initial project.')
  115.             arg(value: '--username')
  116.             arg(value: svnUsername)
  117.             arg(value: '--password')
  118.             arg(value: svnPassword)
  119.         }
  120.  
  121.     }
  122. }
clone this paste RAW Paste Data