Maven Finisher Extension

Maven extension to find and execute finishing tasks after session build completion

License

License

Categories

Categories

ORM Data
GroupId

GroupId

com.igormaznitsa
ArtifactId

ArtifactId

mvn-finisher-extension
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Maven Finisher Extension
Maven extension to find and execute finishing tasks after session build completion
Project URL

Project URL

https://github.com/raydac/mvn-finisher
Project Organization

Project Organization

Igor Maznitsa
Source Code Management

Source Code Management

https://github.com/raydac/mvn-finisher

Download mvn-finisher-extension

How to add to project

<plugin>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>mvn-finisher-extension</artifactId>
    <version>1.1.1</version>
</plugin>

Dependencies

compile (1)

Group / Artifact Type Version
org.apache.maven.shared : maven-invoker jar 3.0.1

provided (3)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.3
org.apache.maven : maven-plugin-api jar 3.3.1
org.apache.maven : maven-core jar 3.3.1

Project Modules

There are no modules declared in this project.

License Apache 2.0 Java 8.0+ Maven central Maven 3.3.1+ PayPal donation Yandex.Money donation

banner

Changelog

1.1.1 (08-feb-2020)

  • added property for finish task timeout mvn.finisher.task.timeout in seconds, by default 120 seconds
  • added property to skip execution mvn.finisher.skip
  • added properties mvn.finisher.log.save and mvn,finisher.log.folder to save finish task log
  • minor improvements and bug fixing

1.1.0 (02-feb-2020)

  • finish tasks started as external processes

1.0.1 (31-jan-2020)

  • added catch of JVM shutdown, its phase finish-force

1.0.0 (29-sep-2019)

  • initial release

What is it

Small maven extesion adds three new phases into build process:

  • finish is called in any case if session is started (also called in JVM shutdown)
  • finish-ok is called only if session is built without errors (called in JVM shutdown only if session build completed)
  • finish-error is called only if session is built with errors (called in JVM shutdown only if session buuld completed)
  • finish-force is called only if JVM shutdown (press CTRL+C for instance)

It's behavior very similar to well-known try...catch...finally mechanism where finish-error situated in the catch section and finish situated in the finally section, finish-ok will be called as the last ones in the body.

How to add in a project?

Just add extension into the build extensions section

<build>
    <extensions>
        <extension>
            <groupId>com.igormaznitsa</groupId>
                <artifactId>mvn-finisher-extension</artifactId>
                <version>1.1.1</version>
        </extension>
    </extensions>
</build>

after end of session build, the extenstion finds finishing tasks in all session projects, for instance task to print some message into console:

<plugin>
    <groupId>com.github.ekryd.echo-maven-plugin</groupId>
    <artifactId>echo-maven-plugin</artifactId>
    <version>1.2.0</version>
    <executions>
        <execution>
            <id>print-echo</id>
            <phase>finish</phase>
            <goals>
                <goal>echo</goal>
            </goals>
            <configuration>
                <message>Hello World from finishing task</message>
            </configuration>
        </execution>
    </executions>
</plugin>

in the code snippet above, there is print-echo task to be executed during finish phase. If the maven build process was interrupted then force finish is activated.
Since 1.1.0 all finishing tasks are executed as external processes through call of maven.

If defined several finishing tasks then they will be sorted in such manner:

  • list of projects in order provided in maven session project list
  • only projects with provided build status will be processed
  • if any error in session build then execution order is:
    • finish-error
    • finish
  • if session build is ok then execution order is:
    • finish-ok
    • finish
  • if session canceled (for instance by CTRL+C) then execution order is:
    • finish-force
    • finish

Each detected task is called separately in its own maven request so that all them will be executed even if some of them can be error.

Extension properties

mvn.finisher.skip

It is a boolean property and can be either true or false. By default it is false. If it is true then execution of the extension will be skipped.

mvn.finisher.log.save

Flag to save log of finishing tasks as text files with name pattern artifactId_finishTaskId.log. By default is false.

mvn.finisher.log.folder

Folder to save log files. By defaul it is mvn.finisher.logs in the project build folder.

mvn.finisher.task.timeout

It allows to define finish task timeout in seconds. By default it is 120 seconds.

Example

Below you can see some example of extension use. The example starts some docker image and then stop and remove it in finishing tasks.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.igormaznitsa</groupId>
    <artifactId>mvn-finisher-test-docker</artifactId>
    <version>0.0.0-SNAPSHOT</version>

    <packaging>jar</packaging>

    <build>
        <extensions>
            <extension>
                <groupId>com.igormaznitsa</groupId>
                <artifactId>mvn-finisher-extension</artifactId>
                <version>1.1.1</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.31.0</version>
                <executions>
                    <execution>
                        <id>start-docker-container</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <containerNamePattern>test-container-finisher</containerNamePattern>
                            <showLogs>true</showLogs>
                            <images>
                                <image>
                                    <name>docker.bintray.io/jfrog/artifactory-oss:latest</name>
                                    <run>
                                        <wait>
                                            <time>60000</time>
                                            <log>#+\s*Artifactory successfully started \([0-9.]+ seconds\)\s*#+</log>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-docker-container</id>
                        <phase>finish</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <configuration>
                            <stopNamePattern>test-container-finisher</stopNamePattern>
                            <allContainers>true</allContainers>
                            <removeVolumes>true</removeVolumes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>remove-docker-container</id>
                        <phase>finish</phase>
                        <goals>
                            <goal>remove</goal>
                        </goals>
                        <configuration>
                            <removeMode>run</removeMode>
                            <removeNamePattern>test-container-finisher</removeNamePattern>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Versions

Version
1.1.1
1.1.0
1.0.1
1.0.0