Maven Plugins

5,325 views
5,202 views

Published on

Overview of Evgeny Goldin Maven plugins, available at http://evgeny-goldin.com/wiki/Main_Page

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,325
On SlideShare
0
From Embeds
0
Number of Embeds
3,281
Actions
Shares
0
Downloads
32
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Maven Plugins

  1. 1. Maven Plugins<br />EvgenyGoldin<br />
  2. 2. evgeny-goldin.com/wiki/Maven-plugins<br />evgeny-goldin.org/artifactory/plugins-releases<br />evgeny-goldin.org/artifactory/libs-releases<br /><groupId>com.goldin.plugins</groupId><br /><artifactId>maven-xyz-plugin</artifactId><br /><version>0.2.1</version><br />
  3. 3. maven-copy-plugin<br />Copies, packs, unpacks, downloads, uploads ..<br /> .. files, archives, Maven <dependencies><br />maven-properties-plugin<br />Creates new Maven properties at run-time ..<br />.. evaluating Groovy expressions! <br />maven-hudson-plugin<br />Generates Hudson jobs<br />Organizes them hierarchically in a single POM <br />
  4. 4. maven-assert-plugin<br />Verifies files exist, properties defined, etc.<br />Verifies any Groovy expression!<br />maven-mail-plugin<br />Sends e-mails with attachments from Maven<br />Works great for build-time reports<br />maven-spring-batch-plugin<br />Invokes Spring Batch job as part of Maven build<br />
  5. 5. maven-copy-plugin<br />
  6. 6. Copies, packs, unpacks, downloads, uploads ..<br /> .. files, archives, Maven <dependencies><br />Filters and replaces content<br />Updates archives<br />Unpacks Zip entries<br />Downloads and uploadsfrom/to HTTP, SCP, FTP<br />Built-in Groovy support<br />
  7. 7. <groupId>com.goldin.plugins</groupId><br /><artifactId>maven-copy-plugin</artifactId><br /><version>0.2.1</version><br />
  8. 8. <configuration>:<br /><configuration><br /><resources><br /> <resource>..</resource><br /> <resource>..</resource><br /></resources><br /><configuration><br />
  9. 9. Copy files:<br /><resource><br /><targetPath>target directory</targetPath><br /><directory>base directory</directory><br /><include>**/*.xml, *.txt, **/lib/*.jar</include><br /><exclude>**/*-template.xml</exclude><br /></resource><br />
  10. 10. Copy file:<br /><resource><br /> <targetPath>target directory</targetPath><br /><file>file to copy</file><br /></resource><br />
  11. 11. Filter files:<br /><resource><br /> <targetPath>..</targetPath><br /> <directory>..</directory><br /> <include>..</include><br /><filtering>true</filtering><br /></resource><br />
  12. 12. Replace content – single <replace>:<br /><resource><br /> <targetPath>..</targetPath><br /> <file>..</file><br /><replace><br /> <from>regular expression</from><br /> <to>replacement content</to><br /> </replace><br /></resource><br />
  13. 13. Replace content - multiple <replaces>:<br /><resource><br /> <targetPath>..</targetPath><br /> <file>..</file><br /><replaces><br /> <replace>..</replace><br /> <replace>..</replace><br /> </replaces><br /></resource><br />
  14. 14. <filter> + <replace>:<br /><resource><br /> <targetPath>..</targetPath><br /> <file>..</file><br /><filtering>true</filtering><br /><replace>..</replaces><br /></resource><br />
  15. 15. Copy <dependency>:<br /><resource><br /> <targetPath>..</targetPath><br /><dependency><br /> <groupId>..</groupId><br /> <artifactId>..</artifactId><br /></dependency><br /></resource><br />
  16. 16. Copy <dependencies>:<br /><resource><br /> <targetPath>..</targetPath><br /><dependencies><br /> <dependency>..</dependency><br /> <dependency>..</dependency><br /></dependencies><br /></resource><br />
  17. 17. Pack archive:<br /><resource><br /> <targetPath>path/file.zip</targetPath><br /> <directory>..</directory><br /> <include>..</include><br /><pack>true</pack><br /></resource><br />
  18. 18. Formats supported:<br />Zip, jar, war, ear, hpi<br />Tar, tar.gz, tgz<br />Tar.bz2, tzp, tbz2<br />Ant + TrueZip<br />
  19. 19. Update archive:<br /><resource><br /> <targetPath>path/file.zip</targetPath><br /> <directory>..</directory><br /> <include>..</include><br /> <pack>true</pack><br /> <update>true</update><br /></resource><br />
  20. 20. Attachartifact:<br /><resource><br /> <targetPath>path/file.zip</targetPath><br /> <directory>..</directory><br /> <include>..</include><br /> <pack>true</pack><br /> <attachArtifact>true</attachArtifact><br /></resource><br />
  21. 21. Deployartifact:<br /><resource><br /> <targetPath>path/file.zip</targetPath><br /> <directory>..</directory><br /> <include>..</include><br /> <pack>true</pack><br /><deploy>repoUrl|groupId|artifactId|version</deploy><br /></resource><br />
  22. 22. Unpack archive:<br /><resource><br /> <targetPath>..</targetPath><br /> <file>some/file.zip</directory><br /> <unpack>true</unpack><br /></resource><br />
  23. 23. Formats supported:<br />Zip, jar, war, ear, hpi<br />Tar, tar.gz, tgz<br />Tar.bz2, tzp, tbz2<br />Ant + TrueZip<br />
  24. 24. Unpack archives:<br /><resource><br /> <targetPath>..</targetPath><br /> <directory>..</directory><br /> <include>*.jar, *.zip, *.tar.gz</include><br /> <unpack>true</unpack><br /></resource><br />
  25. 25. Unpack <dependency>:<br /><resource><br /> <targetPath>..</targetPath><br /><dependency><br /> <groupId>..</groupId><br /> <artifactId>..</artifactId><br /></dependency><br /> <unpack>true</unpack><br /></resource><br />
  26. 26. Unpack <dependencies>:<br /><resource><br /> <targetPath>..</targetPath><br /><dependencies><br /> <dependency>..</dependency><br /> <dependency>..</dependency><br /></dependencies><br /> <unpack>true</unpack><br /></resource><br />
  27. 27. Unpack Zip entry:<br /><resource><br /> <targetPath>..</targetPath><br /> <file>path/file.zip</file><br /><zipEntry>entry/path/file.txt</zipEntry><br /> <unpack>true</unpack><br /></resource><br />
  28. 28. Unpack Zip entries (1):<br /><resource><br /> <targetPath>..</targetPath><br /> <file>path/file.zip</file><br /><zipEntry>entry/**/*.txt</zipEntry><br /> <unpack>true</unpack><br /></resource><br />
  29. 29. Unpack Zip entries (2):<br /><resource><br /> <zipEntries><br /><zipEntry>..</zipEntry><br /><zipEntry>..</zipEntry><br /></zipEntries><br /> <unpack>true</unpack><br /></resource><br />
  30. 30. Download files – network drive:<br /><resource><br /> <targetPath>..</targetPath><br /><directory>networkdrive</directory><br /> <include>..</include><br /> <exclude>..</exclude><br /></resource><br />
  31. 31. Download file – HTTP:<br /><resource><br /> <targetPath>..</targetPath><br /><file>http://host/file</file><br /></resource><br />
  32. 32. Download file – SCP:<br /><resource><br /> <targetPath>..</targetPath><br /> <directory>scp://user:pass@host:/file</directory><br /></resource><br />
  33. 33. Download files – FTP:<br /><resource><br /> <targetPath>..</targetPath><br /> <directory>ftp://user:pass@host:/path</directory><br /><include>..</include><br /><exclude>..</exclude><br /></resource><br />
  34. 34. Download files – FTP + wget:<br /><resource><br /> <targetPath>..</targetPath><br /> <directory>ftp://user:pass@host:/path</directory><br /><include>..</include><br /><wget>wget.exe</wget><br /></resource><br />
  35. 35. Download + unpack:<br /><resource><br /> <targetPath>..</targetPath><br /> http / scp / ftp<br /><unpack>true</unpack><br /></resource><br />
  36. 36. Upload files – network drive:<br /><resource><br /> <targetPath>networkdrive</targetPath><br /> <directory>..</directory><br /> <include>..</include><br /></resource><br />
  37. 37. Upload files – SCP:<br /><resource><br /> <targetPath>scp://user:pass@host:/dir</targetPath><br /> <directory>..</directory><br /> <include>..</include><br /></resource><br />
  38. 38. Upload files – FTP:<br /><resource><br /> <targetPath>ftp://user:pass@host:/dir</targetPath><br /> <directory>..</directory><br /> <include>..</include><br /></resource><br />
  39. 39. Delete files:<br /><resource><br /> <directory>..</directory><br /> <include>..</include><br /><clean>true</clean><br /> <cleanEmptyDirectories>true</cleanEmptyDirectories><br /></resource><br />
  40. 40. Create file (= copy other file + <replace>):<br /><resource><br /> <targetPath>..</targetPath><br /> <file>${project.basedir}/pom.xml</file><br /><replace><to>new content</to></replace><br /> <destFileName>newName.txt</destFileName><br /></resource><br />
  41. 41. Create directory:<br /><resource><br /> <targetPath>..</targetPath><br /><mkdir>true</mkdir><br /></resource><br />
  42. 42. Groovy support - <runIf>:<br /><configuration><br /><runIf>{{ Groovy Expression }}</runIf><br /> <resource><br /><runIf>{{ Groovy Expression }}</runIf><br /> // Boolean.valueOf( String.valueOf( returnValue ))<br /> </resource><br /></configuration><br />
  43. 43. Groovy support - <description>:<br /><resource><br /> <description>Time: {{ new Date() }}</description><br /> … <br /></resource><br />Logs <resource> start, end, and execution time in ms<br />
  44. 44. Groovy support - <replace>:<br /><resource><br /> …<br /> <replace><br /><to>File updated at: {{ new Date() }}</to><br /> <groovy>true</groovy><br /> </replace><br /></resource><br />
  45. 45. Groovy support – FTP download + <listFilter>:<br /><resource><br /> FTP download<br /> <wget>wget.exe</wget><br /><listFilter>{{ files.keySet().findAll{ .. } }}</listFilter><br /></resource><br />Filters files to download.<br />
  46. 46. Groovy support - <filter>:<br /><resource><br /> <targetPath>..</targetPath><br /> …<br /><filter>{{ files.findAll{ .. } }}</filter><br /></resource><br />Filters files to copy, pack, unpack, etc.<br />
  47. 47. Groovy support - <process>:<br /><resource><br /> <targetPath>..</targetPath><br /> …<br /><process>{{ println “Files: $files” }}</process><br /></resource><br />Processes files after they are copied, packed, etc.<br />
  48. 48. Groovy support - context:<br />“project” - org.apache.maven.project.MavenProject<br />“session” - org.apache.maven.execution.MavenSession<br />“mavenVersion”<br />All Maven and System properties<br /><this-property> => “thisProperty”<br />“os.name” => “osName”<br />{{ new File( project.basedir, “pom.xml” ) }}<br />
  49. 49. maven-properties-plugin<br />
  50. 50. Creates new Mavenpropertiesatrun time ..<br /> .. evaluatingGroovy expressions!<br />Works best in combinationwith <runIf><br />Allowscreatingdynamic content for the mail plugin<br />
  51. 51. <groupId>com.goldin.plugins</groupId><br /><artifactId>maven-properties-plugin</artifactId><br /><version>0.2.1</version><br />
  52. 52. <configuration>:<br /><configuration><br /> <properties><br /><property>..</property><br /><property>..</property><br /> </properties><br /></configuration><br />
  53. 53. <property>:<br /><property><br /> <name>propertyTrue</name><br /><value>{{ 't' + 'r' + 'u' + 'e' }}</value><br /></property><br />…<br /><runIf>{{ propertyTrue }}</runIf><br /><runIf>{{ ! Boolean.valueOf( propertyTrue ) }}</runIf><br />
  54. 54. Groovycontext:<br />“project” - org.apache.maven.project.MavenProject<br />“session” - org.apache.maven.execution.MavenSession<br />“mavenVersion”<br />All Maven and System properties<br /><this-property> => “thisProperty”<br />“os.name” => “osName”<br />{{ project.basedir.canonicalPath }}<br />
  55. 55. maven-hudson-plugin<br />
  56. 56. Generates Hudson jobs<br />Definesthem in a single POM<br />Jobs canformhierarchicall groups (reuse!)<br />Supports jobs invocation<br />Supports Artifactory deployment<br />
  57. 57. <groupId>com.goldin.plugins</groupId><br /><artifactId>maven-hudson-plugin</artifactId><br /><version>0.2.1</version><br />
  58. 58. <configuration> :<br /><configuration><br /> <outputDirectory>.hudson/jobs</outputDirectory><br /> <jobs><br /><job>..</job><br /><job>..</job><br /> </jobs><br /></configuration><br />
  59. 59. <job> :<br /><job><br /><id>jobName</id><br /> <mavenName>apache-maven-2.2.1</mavenName> <mavenOpts>-Xmx256m</mavenOpts><br /> <mavenGoals>–e –B –U clean install</mavenGoals><br /> …<br /></job><br />
  60. 60. <job> :<br /><jdkName><br /><pom><br /><repositories><br /><privateRepository><br /><mail><br />…<br />All standard job configuration options.<br />
  61. 61. Extending <job> (1):<br /><job><br /><id>baseJob</id><br /><abstract>true</abstract><br /> <jdkName>..</jdkName> <br /> <mavenName>..</mavenName><br /> <mavenGoals>..</mavenGoals><br /></job><br />
  62. 62. Extending <job> (2):<br /><job><br /> <id>jobName</id><br /><parent>baseJob</parent><br /> <repository>..</repository><br /></job><br />Only job-specific values are specified.<br />
  63. 63. Description Table:<br />
  64. 64. Invoking jobs:<br /><job><br /> <id>jobName</id>…<br /><invoke><br /> <jobs>jobA, jobB, jobC</jobs><br /> </invoke><br /></job><br />
  65. 65. Invoking jobs - conditions:<br /><invoke><br /> <jobs>jobA, jobB, jobC</jobs><br /> <always>false</always><br /><stable>true</stable><br /><unstable>false</unstable><br /><failed>false</failed><br /></invoke><br />
  66. 66. Artifactory deployment:<br /><job><br /><artifactory><br /> <name>http://host/artifactory</name><br /> <user>deployer</user><br /> <scrambledPassword>..</scrambledPassword><br /></artifactory><br /></job><br />
  67. 67. Environments supported:<br />SCM: Subversion, Git, CVS, NullSCM (none)<br />Maven jobs<br />Free-style jobs<br />Plugins required:<br />“Parameterized Trigger Plugin” v2.4 or higher<br />“ArtifactoryPlugin” v1.3.4 or higher<br />
  68. 68. maven-assert-plugin<br />
  69. 69. Buildassertions!<br />Propertiesdefined<br />Files exist<br />Directories identical<br />Groovy expressions evaluate to true<br />Wasdriven by plugins tests<br />
  70. 70. <groupId>com.goldin.plugins</groupId><br /><artifactId>maven-assert-plugin</artifactId><br /><version>0.2.1</version><br />
  71. 71. <configuration> :<br /><configuration><br /> <assertProperties>..</assertProperties><br /> <assertFiles>..</assertFiles><br /> <assertEqual>..</assertEqual><br /> <assertGroovy>..</assertGroovy><br /></configuration><br />
  72. 72. <assertProperties> :<br /><assertProperties><br /> job-parameter<br /> BUILD_NUMBER<br /> HUDSON_URL<br /></assertProperties><br />Makes sure all job parameters are specified.<br />
  73. 73. <assertFiles> :<br /><assertFiles><br /> ${data-files}/*.xml<br /> ${project.build.directory}/setup.tar.gz<br /> ${project.build.directory}/ini<br /></assertFiles><br />Makes sure all files and directories are created.<br />
  74. 74. <assertEqual> :<br /><assertEqual> <br /> ${dir}/expected|${outputDir}/result<br /> ${dir}/expected|${outputDir}/result|**/*.xml<br /></assertEqual><br />Makes sure directories are identical (+/- pattern).<br />
  75. 75. <assertGroovy> :<br /><assertGroovy> <br />project.basedir.directorySize() > 0<br /> timestamp ==~ /^d{2} w+ d{4}, d{2}:d{2}:d{2}$/<br /></assertGroovy><br />Evaluates «assertline» for each line (power assert!)<br />
  76. 76. Groovycontext:<br />File.directorySize()<br />Object.splitWith() – see GCommons<br />“project” - org.apache.maven.project.MavenProject<br />“session” - org.apache.maven.execution.MavenSession<br />“mavenVersion”<br />All Maven and System properties<br />
  77. 77. maven-mail-plugin<br />
  78. 78. Sends e-mails with attachments from Maven<br />Works great for build-time reports<br />Properties plugin allows for dynamic content<br />
  79. 79. <groupId>com.goldin.plugins</groupId><br /><artifactId>maven-mail-plugin</artifactId><br /><version>0.2.1</version><br />
  80. 80. <configuration>:<br /><configuration><br /><smtp>..</smtp><br /> <from>..</from><br /> <mails><to>..</to></mails><br /> <subject>..</subject><br /> <text>..</text><br /></configuration><br />
  81. 81. <mails>:<br /><mails><br /><to>user@mail; user2@mail</to><br /><cc>User Name &lt;user@mail&gt;;</cc><br /><bcc>..</bcc><br /></mails><br />Use &lt;user@mail&gt; or CDATA<br />Addresses are «;»-separated to allowspaces in names<br />
  82. 82. Attaching files:<br /><configuration><br /><textFile>..</textFile><br /><files><br /> <file>..</file><br /> <file>..</file><br /></files><br /></configuration><br />
  83. 83. maven-spring-batch-plugin<br />
  84. 84. Invokes SpringBatch job as part of Maven build<br />Maven is a good platform for batch processes!<br />
  85. 85. <groupId>com.goldin.plugins</groupId><br /><artifactId>maven-spring-batch-plugin</artifactId><br /><version>0.2.1</version><br />
  86. 86. <configuration>:<br /><configuration><br /><jobId>jobId</jobId><br /> <configLocations><br />classpath:/springbatch/infra/job-launcher.xml<br />file:/job/context.xml<br /> </configLocations><br /></configuration><br />
  87. 87. Properties:<br /><configuration><br /><props><br /> name = value<br />classpath:/springbatch/infra/job-runner.properties<br />file:/job/context.properties<br /></props><br /></configuration><br />
  88. 88. evgeny-goldin.com/wiki/Maven-plugins<br />maven-plugins.994461.n3.nabble.com<br />evgeny-goldin.org/artifactory/plugins-releases<br />evgeny-goldin.org/artifactory/libs-releases<br />evgeny-goldin.org/youtrack/issues/pl<br />@evgeny_goldin<br />evgenyg@gmail.com<br />

×