Maven Plugins
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Maven Plugins

on

  • 5,280 views

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

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

Statistics

Views

Total Views
5,280
Views on SlideShare
2,001
Embed Views
3,279

Actions

Likes
0
Downloads
26
Comments
0

4 Embeds 3,279

http://evgeny-goldin.com 3273
http://www.linkedin.com 4
http://translate.googleusercontent.com 1
http://webcache.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Maven Plugins Presentation Transcript

  • 1. Maven Plugins
    EvgenyGoldin
  • 2. evgeny-goldin.com/wiki/Maven-plugins
    evgeny-goldin.org/artifactory/plugins-releases
    evgeny-goldin.org/artifactory/libs-releases
    <groupId>com.goldin.plugins</groupId>
    <artifactId>maven-xyz-plugin</artifactId>
    <version>0.2.1</version>
  • 3. maven-copy-plugin
    Copies, packs, unpacks, downloads, uploads ..
    .. files, archives, Maven <dependencies>
    maven-properties-plugin
    Creates new Maven properties at run-time ..
    .. evaluating Groovy expressions!
    maven-hudson-plugin
    Generates Hudson jobs
    Organizes them hierarchically in a single POM
  • 4. maven-assert-plugin
    Verifies files exist, properties defined, etc.
    Verifies any Groovy expression!
    maven-mail-plugin
    Sends e-mails with attachments from Maven
    Works great for build-time reports
    maven-spring-batch-plugin
    Invokes Spring Batch job as part of Maven build
  • 5. maven-copy-plugin
  • 6. Copies, packs, unpacks, downloads, uploads ..
    .. files, archives, Maven <dependencies>
    Filters and replaces content
    Updates archives
    Unpacks Zip entries
    Downloads and uploadsfrom/to HTTP, SCP, FTP
    Built-in Groovy support
  • 7. <groupId>com.goldin.plugins</groupId>
    <artifactId>maven-copy-plugin</artifactId>
    <version>0.2.1</version>
  • 8. <configuration>:
    <configuration>
    <resources>
    <resource>..</resource>
    <resource>..</resource>
    </resources>
    <configuration>
  • 9. Copy files:
    <resource>
    <targetPath>target directory</targetPath>
    <directory>base directory</directory>
    <include>**/*.xml, *.txt, **/lib/*.jar</include>
    <exclude>**/*-template.xml</exclude>
    </resource>
  • 10. Copy file:
    <resource>
    <targetPath>target directory</targetPath>
    <file>file to copy</file>
    </resource>
  • 11. Filter files:
    <resource>
    <targetPath>..</targetPath>
    <directory>..</directory>
    <include>..</include>
    <filtering>true</filtering>
    </resource>
  • 12. Replace content – single <replace>:
    <resource>
    <targetPath>..</targetPath>
    <file>..</file>
    <replace>
    <from>regular expression</from>
    <to>replacement content</to>
    </replace>
    </resource>
  • 13. Replace content - multiple <replaces>:
    <resource>
    <targetPath>..</targetPath>
    <file>..</file>
    <replaces>
    <replace>..</replace>
    <replace>..</replace>
    </replaces>
    </resource>
  • 14. <filter> + <replace>:
    <resource>
    <targetPath>..</targetPath>
    <file>..</file>
    <filtering>true</filtering>
    <replace>..</replaces>
    </resource>
  • 15. Copy <dependency>:
    <resource>
    <targetPath>..</targetPath>
    <dependency>
    <groupId>..</groupId>
    <artifactId>..</artifactId>
    </dependency>
    </resource>
  • 16. Copy <dependencies>:
    <resource>
    <targetPath>..</targetPath>
    <dependencies>
    <dependency>..</dependency>
    <dependency>..</dependency>
    </dependencies>
    </resource>
  • 17. Pack archive:
    <resource>
    <targetPath>path/file.zip</targetPath>
    <directory>..</directory>
    <include>..</include>
    <pack>true</pack>
    </resource>
  • 18. Formats supported:
    Zip, jar, war, ear, hpi
    Tar, tar.gz, tgz
    Tar.bz2, tzp, tbz2
    Ant + TrueZip
  • 19. Update archive:
    <resource>
    <targetPath>path/file.zip</targetPath>
    <directory>..</directory>
    <include>..</include>
    <pack>true</pack>
    <update>true</update>
    </resource>
  • 20. Attachartifact:
    <resource>
    <targetPath>path/file.zip</targetPath>
    <directory>..</directory>
    <include>..</include>
    <pack>true</pack>
    <attachArtifact>true</attachArtifact>
    </resource>
  • 21. Deployartifact:
    <resource>
    <targetPath>path/file.zip</targetPath>
    <directory>..</directory>
    <include>..</include>
    <pack>true</pack>
    <deploy>repoUrl|groupId|artifactId|version</deploy>
    </resource>
  • 22. Unpack archive:
    <resource>
    <targetPath>..</targetPath>
    <file>some/file.zip</directory>
    <unpack>true</unpack>
    </resource>
  • 23. Formats supported:
    Zip, jar, war, ear, hpi
    Tar, tar.gz, tgz
    Tar.bz2, tzp, tbz2
    Ant + TrueZip
  • 24. Unpack archives:
    <resource>
    <targetPath>..</targetPath>
    <directory>..</directory>
    <include>*.jar, *.zip, *.tar.gz</include>
    <unpack>true</unpack>
    </resource>
  • 25. Unpack <dependency>:
    <resource>
    <targetPath>..</targetPath>
    <dependency>
    <groupId>..</groupId>
    <artifactId>..</artifactId>
    </dependency>
    <unpack>true</unpack>
    </resource>
  • 26. Unpack <dependencies>:
    <resource>
    <targetPath>..</targetPath>
    <dependencies>
    <dependency>..</dependency>
    <dependency>..</dependency>
    </dependencies>
    <unpack>true</unpack>
    </resource>
  • 27. Unpack Zip entry:
    <resource>
    <targetPath>..</targetPath>
    <file>path/file.zip</file>
    <zipEntry>entry/path/file.txt</zipEntry>
    <unpack>true</unpack>
    </resource>
  • 28. Unpack Zip entries (1):
    <resource>
    <targetPath>..</targetPath>
    <file>path/file.zip</file>
    <zipEntry>entry/**/*.txt</zipEntry>
    <unpack>true</unpack>
    </resource>
  • 29. Unpack Zip entries (2):
    <resource>
    <zipEntries>
    <zipEntry>..</zipEntry>
    <zipEntry>..</zipEntry>
    </zipEntries>
    <unpack>true</unpack>
    </resource>
  • 30. Download files – network drive:
    <resource>
    <targetPath>..</targetPath>
    <directory>networkdrive</directory>
    <include>..</include>
    <exclude>..</exclude>
    </resource>
  • 31. Download file – HTTP:
    <resource>
    <targetPath>..</targetPath>
    <file>http://host/file</file>
    </resource>
  • 32. Download file – SCP:
    <resource>
    <targetPath>..</targetPath>
    <directory>scp://user:pass@host:/file</directory>
    </resource>
  • 33. Download files – FTP:
    <resource>
    <targetPath>..</targetPath>
    <directory>ftp://user:pass@host:/path</directory>
    <include>..</include>
    <exclude>..</exclude>
    </resource>
  • 34. Download files – FTP + wget:
    <resource>
    <targetPath>..</targetPath>
    <directory>ftp://user:pass@host:/path</directory>
    <include>..</include>
    <wget>wget.exe</wget>
    </resource>
  • 35. Download + unpack:
    <resource>
    <targetPath>..</targetPath>
    http / scp / ftp
    <unpack>true</unpack>
    </resource>
  • 36. Upload files – network drive:
    <resource>
    <targetPath>networkdrive</targetPath>
    <directory>..</directory>
    <include>..</include>
    </resource>
  • 37. Upload files – SCP:
    <resource>
    <targetPath>scp://user:pass@host:/dir</targetPath>
    <directory>..</directory>
    <include>..</include>
    </resource>
  • 38. Upload files – FTP:
    <resource>
    <targetPath>ftp://user:pass@host:/dir</targetPath>
    <directory>..</directory>
    <include>..</include>
    </resource>
  • 39. Delete files:
    <resource>
    <directory>..</directory>
    <include>..</include>
    <clean>true</clean>
    <cleanEmptyDirectories>true</cleanEmptyDirectories>
    </resource>
  • 40. Create file (= copy other file + <replace>):
    <resource>
    <targetPath>..</targetPath>
    <file>${project.basedir}/pom.xml</file>
    <replace><to>new content</to></replace>
    <destFileName>newName.txt</destFileName>
    </resource>
  • 41. Create directory:
    <resource>
    <targetPath>..</targetPath>
    <mkdir>true</mkdir>
    </resource>
  • 42. Groovy support - <runIf>:
    <configuration>
    <runIf>{{ Groovy Expression }}</runIf>
    <resource>
    <runIf>{{ Groovy Expression }}</runIf>
    // Boolean.valueOf( String.valueOf( returnValue ))
    </resource>
    </configuration>
  • 43. Groovy support - <description>:
    <resource>
    <description>Time: {{ new Date() }}</description>

    </resource>
    Logs <resource> start, end, and execution time in ms
  • 44. Groovy support - <replace>:
    <resource>

    <replace>
    <to>File updated at: {{ new Date() }}</to>
    <groovy>true</groovy>
    </replace>
    </resource>
  • 45. Groovy support – FTP download + <listFilter>:
    <resource>
    FTP download
    <wget>wget.exe</wget>
    <listFilter>{{ files.keySet().findAll{ .. } }}</listFilter>
    </resource>
    Filters files to download.
  • 46. Groovy support - <filter>:
    <resource>
    <targetPath>..</targetPath>

    <filter>{{ files.findAll{ .. } }}</filter>
    </resource>
    Filters files to copy, pack, unpack, etc.
  • 47. Groovy support - <process>:
    <resource>
    <targetPath>..</targetPath>

    <process>{{ println “Files: $files” }}</process>
    </resource>
    Processes files after they are copied, packed, etc.
  • 48. Groovy support - context:
    “project” - org.apache.maven.project.MavenProject
    “session” - org.apache.maven.execution.MavenSession
    “mavenVersion”
    All Maven and System properties
    <this-property> => “thisProperty”
    “os.name” => “osName”
    {{ new File( project.basedir, “pom.xml” ) }}
  • 49. maven-properties-plugin
  • 50. Creates new Mavenpropertiesatrun time ..
    .. evaluatingGroovy expressions!
    Works best in combinationwith <runIf>
    Allowscreatingdynamic content for the mail plugin
  • 51. <groupId>com.goldin.plugins</groupId>
    <artifactId>maven-properties-plugin</artifactId>
    <version>0.2.1</version>
  • 52. <configuration>:
    <configuration>
    <properties>
    <property>..</property>
    <property>..</property>
    </properties>
    </configuration>
  • 53. <property>:
    <property>
    <name>propertyTrue</name>
    <value>{{ 't' + 'r' + 'u' + 'e' }}</value>
    </property>

    <runIf>{{ propertyTrue }}</runIf>
    <runIf>{{ ! Boolean.valueOf( propertyTrue ) }}</runIf>
  • 54. Groovycontext:
    “project” - org.apache.maven.project.MavenProject
    “session” - org.apache.maven.execution.MavenSession
    “mavenVersion”
    All Maven and System properties
    <this-property> => “thisProperty”
    “os.name” => “osName”
    {{ project.basedir.canonicalPath }}
  • 55. maven-hudson-plugin
  • 56. Generates Hudson jobs
    Definesthem in a single POM
    Jobs canformhierarchicall groups (reuse!)
    Supports jobs invocation
    Supports Artifactory deployment
  • 57. <groupId>com.goldin.plugins</groupId>
    <artifactId>maven-hudson-plugin</artifactId>
    <version>0.2.1</version>
  • 58. <configuration> :
    <configuration>
    <outputDirectory>.hudson/jobs</outputDirectory>
    <jobs>
    <job>..</job>
    <job>..</job>
    </jobs>
    </configuration>
  • 59. <job> :
    <job>
    <id>jobName</id>
    <mavenName>apache-maven-2.2.1</mavenName> <mavenOpts>-Xmx256m</mavenOpts>
    <mavenGoals>–e –B –U clean install</mavenGoals>

    </job>
  • 60. <job> :
    <jdkName>
    <pom>
    <repositories>
    <privateRepository>
    <mail>

    All standard job configuration options.
  • 61. Extending <job> (1):
    <job>
    <id>baseJob</id>
    <abstract>true</abstract>
    <jdkName>..</jdkName>
    <mavenName>..</mavenName>
    <mavenGoals>..</mavenGoals>
    </job>
  • 62. Extending <job> (2):
    <job>
    <id>jobName</id>
    <parent>baseJob</parent>
    <repository>..</repository>
    </job>
    Only job-specific values are specified.
  • 63. Description Table:
  • 64. Invoking jobs:
    <job>
    <id>jobName</id>…
    <invoke>
    <jobs>jobA, jobB, jobC</jobs>
    </invoke>
    </job>
  • 65. Invoking jobs - conditions:
    <invoke>
    <jobs>jobA, jobB, jobC</jobs>
    <always>false</always>
    <stable>true</stable>
    <unstable>false</unstable>
    <failed>false</failed>
    </invoke>
  • 66. Artifactory deployment:
    <job>
    <artifactory>
    <name>http://host/artifactory</name>
    <user>deployer</user>
    <scrambledPassword>..</scrambledPassword>
    </artifactory>
    </job>
  • 67. Environments supported:
    SCM: Subversion, Git, CVS, NullSCM (none)
    Maven jobs
    Free-style jobs
    Plugins required:
    “Parameterized Trigger Plugin” v2.4 or higher
    “ArtifactoryPlugin” v1.3.4 or higher
  • 68. maven-assert-plugin
  • 69. Buildassertions!
    Propertiesdefined
    Files exist
    Directories identical
    Groovy expressions evaluate to true
    Wasdriven by plugins tests
  • 70. <groupId>com.goldin.plugins</groupId>
    <artifactId>maven-assert-plugin</artifactId>
    <version>0.2.1</version>
  • 71. <configuration> :
    <configuration>
    <assertProperties>..</assertProperties>
    <assertFiles>..</assertFiles>
    <assertEqual>..</assertEqual>
    <assertGroovy>..</assertGroovy>
    </configuration>
  • 72. <assertProperties> :
    <assertProperties>
    job-parameter
    BUILD_NUMBER
    HUDSON_URL
    </assertProperties>
    Makes sure all job parameters are specified.
  • 73. <assertFiles> :
    <assertFiles>
    ${data-files}/*.xml
    ${project.build.directory}/setup.tar.gz
    ${project.build.directory}/ini
    </assertFiles>
    Makes sure all files and directories are created.
  • 74. <assertEqual> :
    <assertEqual>
    ${dir}/expected|${outputDir}/result
    ${dir}/expected|${outputDir}/result|**/*.xml
    </assertEqual>
    Makes sure directories are identical (+/- pattern).
  • 75. <assertGroovy> :
    <assertGroovy>
    project.basedir.directorySize() > 0
    timestamp ==~ /^d{2} w+ d{4}, d{2}:d{2}:d{2}$/
    </assertGroovy>
    Evaluates «assertline» for each line (power assert!)
  • 76. Groovycontext:
    File.directorySize()
    Object.splitWith() – see GCommons
    “project” - org.apache.maven.project.MavenProject
    “session” - org.apache.maven.execution.MavenSession
    “mavenVersion”
    All Maven and System properties
  • 77. maven-mail-plugin
  • 78. Sends e-mails with attachments from Maven
    Works great for build-time reports
    Properties plugin allows for dynamic content
  • 79. <groupId>com.goldin.plugins</groupId>
    <artifactId>maven-mail-plugin</artifactId>
    <version>0.2.1</version>
  • 80. <configuration>:
    <configuration>
    <smtp>..</smtp>
    <from>..</from>
    <mails><to>..</to></mails>
    <subject>..</subject>
    <text>..</text>
    </configuration>
  • 81. <mails>:
    <mails>
    <to>user@mail; user2@mail</to>
    <cc>User Name &lt;user@mail&gt;;</cc>
    <bcc>..</bcc>
    </mails>
    Use &lt;user@mail&gt; or CDATA
    Addresses are «;»-separated to allowspaces in names
  • 82. Attaching files:
    <configuration>
    <textFile>..</textFile>
    <files>
    <file>..</file>
    <file>..</file>
    </files>
    </configuration>
  • 83. maven-spring-batch-plugin
  • 84. Invokes SpringBatch job as part of Maven build
    Maven is a good platform for batch processes!
  • 85. <groupId>com.goldin.plugins</groupId>
    <artifactId>maven-spring-batch-plugin</artifactId>
    <version>0.2.1</version>
  • 86. <configuration>:
    <configuration>
    <jobId>jobId</jobId>
    <configLocations>
    classpath:/springbatch/infra/job-launcher.xml
    file:/job/context.xml
    </configLocations>
    </configuration>
  • 87. Properties:
    <configuration>
    <props>
    name = value
    classpath:/springbatch/infra/job-runner.properties
    file:/job/context.properties
    </props>
    </configuration>
  • 88. evgeny-goldin.com/wiki/Maven-plugins
    maven-plugins.994461.n3.nabble.com
    evgeny-goldin.org/artifactory/plugins-releases
    evgeny-goldin.org/artifactory/libs-releases
    evgeny-goldin.org/youtrack/issues/pl
    @evgeny_goldin
    evgenyg@gmail.com