Skip to content

Instantly share code, notes, and snippets.

@romain-grecourt
Last active June 11, 2020 01:19
Show Gist options
  • Save romain-grecourt/8cf44138fda0b50be0a6d5fc21d46c33 to your computer and use it in GitHub Desktop.
Save romain-grecourt/8cf44138fda0b50be0a6d5fc21d46c33 to your computer and use it in GitHub Desktop.
Helidon Stager Maven Plugin

Helidon Stager Maven Plugin

The stager Maven plugin allows to stage a directory. This is somehow similar to the maven-assembly-plugin but more compact and specific to our needs.

<!-- Maven properties used below -->
<properties>
    <site.output.dir>${project.build.directory}/site</site.output.dir>
    <cname>helidon.io</cname>
    <docs.1.version>1.4.4</docs.1.version>
    <docs.2.version>2.0.0-RC1</docs.2.version>
    <docs.latest.version>${docs.1.version}</docs.latest.version>
    <cli.data.latest.version>2.0.0-RC1</cli.data.latest.version>
    <cli.maven.plugin.version>2.0.0-RC1</cli.maven.plugin.version>
    <cli.latest.version>2.0.0-RC1</cli.latest.version>
    <build-tools.download.url>https://github.com/oracle/helidon-build-tools/releases/download/</build-tools.download.url>
</properties>

<!-- plugin configuration -->
<configuration>
    <directory target="${site.output.dir}">
        <unpack-artifacts>
            <unpack-artifact 
                groupId="io.helidon"
                artifactId="helidon-docs"
                version="{version}"
                excludes="META-INF/**"
                target="docs/{version}"> 
                <iterators>
                    <variables>
                        <variable name="version">
                            <value>${docs.1.version}</value>
                            <value>1.4.3</value>
                            <value>1.4.2</value>
                            <value>1.4.1</value>
                            <value>1.4.0</value>
                            <value>1.3.1</value>
                            <value>1.3.0</value>
                            <value>1.2.1</value>
                            <value>1.1.2</value>
                            <value>1.0.3</value>
                            <value>0.11.1</value>
                            <value>0.10.6</value>
                            <value>0.9.1</value>
                        </variable>
                    </variables>
                <iterators>
            </unpack-artifact>
            <unpack-artifact 
                groupId="io.helidon"
                artifactId="helidon-docs"
                version="{version}"
                classifier="site"
                excludes="META-INF/**"
                target="docs/{version}"> 
                <iterators>
                    <variables>
                        <variable name="version">
                            <value>${docs.2.version}</value>
                        </variable>
                    </variables>
                <iterators>
            </unpack-artifact>
        </unpack-artifacts>
        <symlinks>
            <symlink resource="./${docs.latest.version}" link="docs/latest"/>
            <symlink resource="./${docs.1.version}" link="docs/v1"/>
            <symlink resource="./${docs.2.version}" link="docs/v2"/>
            <symlink resource="./${cli.latest.version}" link="cli/latest"/>
        </symlinks>
        <downloads>
            <download
                url="https://helidon.io/cli-data/{version}/cli-data.zip" 
                target="cli-data/{version}/cli-data.zip">
                <iterators>
                    <variables>
                        <variable name="version">
                            <value>2.0.0-M1</value>
                        </variable>
                    </variables>
                <iterators>
            </download>
            <download
                url="${build-tools.download.url}/{version}/helidon-cli-{platform}-amd64"
                target="cli/{version}"
                <iterators>
                    <variables>
                        <variable name="platform">
                            <value>darwin</value>
                            <value>linux</value>
                        </variable>
                        <variable name="version">
                            <value>${cli.latest.version}</value>
                            <value>2.0.0-M4</value>
                        </variable>
                    </variables>
                <iterators>
            </download>
        </downloads>
        <archives>
            <archive target="cli-data/${cli.data.latest.version}/cli-data.zip">
                <unpack-artifacts>
                    <unpack-artifact
                        groupId="io.helidon.archetypes"
                        artifactId="helidon-archetype-catalog"
                        version="${cli.data.latest.version}"
                        type="zip"
                        target="." />
                    </unpack-artifact>
                </unpack-artifacts>
                <templates>
                    <template source="src/cli-metadata.properties.mustache" target="metadata.properties">
                        <variables>
                            <variable name="helidonVersion" value="${cli.data.latest.version}" />
                            <variable name="buildtoolsVersion" value="${cli.maven.plugin.version}" />
                            <variable name="cliVersion" value="${cli.latest.version>}" />
                            <variable name="cliUpdateMessages">
                                <value>
                                    <variable name="version"  value="2.0.0-M2" />
                                    <variable name="message"  value="Major dev command enhancements" />
                                </value>
                                <value>
                                    <variable name="version"  value="2.0.0-M4" />
                                    <variable name="message"  value="Helidon archetype support" />
                                <value>
                                <value>
                                    <variable name="version"  value="2.0.0-RC1" />
                                    <variable name="message"  value="Performance improvements" />
                                </value>
                            </variable>
                        </variables>
                    </template>
                </templates>
            <archive>
        </archives>
        <templates>
            <template source="src/redirect.html.mustache" target="docs/index.html">
                <variables>
                    <variable name="location" value="./latest/index.html" />
                    <variable name="title" value="Helidon Documentation" />
                    <variable name="description" value="Helidon Documentation" />
                    <variable name="og-url" value="https://helidon.io/docs" />
                    <variable name="og-description" value="Documentation" />
                </variables>
            </template>
            <template source="src/redirect.html.mustache" target="guides/index.html">
                <variables>
                    <variable name="location" value="../docs/latest/index.html#/guides/01_overview" />
                    <variable name="title" value="Helidon Guides" />
                    <variable name="description" value="Helidon Guides" />
                    <variable name="og-url" value="https://helidon.io/guides" />
                    <variable name="og-description" value="Guides" />
                </variables>
            </template>
            <template source="src/redirect.html.mustache" target="javadocs/index.html">
                <variables>
                    <variable name="location" value="../docs/latest/apidocs/index.html?overview-summary.html" />
                    <variable name="title" value="Helidon Javadocs" />
                    <variable name="description" value="Helidon Javadocs" />
                    <variable name="og-url" value="https://helidon.io/javadocs" />
                    <variable name="og-description" value="Javadocs" />
                </variables>
            </template>
        </templates>
        <files>
            <file target="CNAME">${cname}</file>
            <file target="cli-data/latest">${cli.data.latest.version}</file>
            <!-- file should also support a source attribute to copy a file or maven resource -->
        </files>
    </directory>
</configuration>

Variables

Variables is a binding to build a map. It is not named properties to avoid confusion with Maven properties. The "variables" are used to implement pseudo for-loop with substitutions as well as mustache templates properties.

<variables> contains nested <variable> elements which must have a name attribute.

The value of a variable can be passed with: - the value attribute, in which case the variable is a simple entry with a string value. - nested <value> elements, in which case the variable is a list of values

<value> can contain: - text to express a string - nested <variable> elements to express map entries

E.g. Variables with a list of string values:

<variables>
    <variable name="versions">
        <value>1.0</value>
        <value>2.0</value>
    </variables>
</variables>

E.g. Variables with a list of entries:

<variables>
    <variable name="versionNames">
        <value>
            <variable name="version" value="1.0" />
            <variable name="versionName" value="El primero" />
        </value>
        <value>
            <variable name="version" value="2.0" />
            <variable name="versionName" value="El secundo" />
        </value>
    </variables>
</variables>

Iterators

Iterators are a pseudo for-loop mechanism to repeat an action for a given set of variables. <iterators> contains nested <variables> elements that defines variables to use for distinct set of iterations.

For each iteration the current variable value is substituted using {} as a pattern.

<iterators> elements are nested on actions that support it, E.g. <unpack-artifact>, <copy-artifact>, <download>. The substitutions are defined on the actions itself.

E.g. Unpack two version of an artifacts in separate directories named after each version:

<unpack-artifact 
    groupId="com.acme"
    artifactId="foo"
    version="{version}"
    target="my-dir/{version}"> 
    <iterators>
        <variables>
            <variable name="version">
                <value>1.0</value>
                <value>2.0</value>
            </variable>
        </variables>
    <iterators>
</unpack-artifact>

Result:

my-dir/1.0
my-dir/2.0

If the variables map contains multiple entries, the iterators will iterator over the possibles variants.

E.g. Unpack two version of two artifacts in separate directories named after each version and artifact:

<unpack-artifact 
    groupId="com.acme"
    artifactId="{artifact}"
    version="{version}"
    target="my-dir/{version}"> 
    <iterators>
        <variables>
            <variable name="artifact">
                <value>foo</value>
                <value>bar</value>
            </variable>
            <variable name="version">
                <value>1.0</value>
                <value>2.0</value>
            </variable>
        </variables>
    <iterators>
</unpack-artifact>

Result:

my-dir/foo-1.0
my-dir/foo-2.0
my-dir/bar-1.0
my-dir/bar-2.0

E.g. Unpack two different versions of two artifacts in separate directories named after each version and artifact:

<unpack-artifact 
    groupId="com.acme"
    artifactId="{artifact}"
    version="{version}"
    target="my-dir/{version}"> 
    <iterators>
        <variables>
            <variable name="artifact">
                <value>foo</value>
            </variable>
            <variable name="version">
                <value>1.0</value>
                <value>2.0</value>
            </variable>
        </variables>
        <variables>
            <variable name="artifact">
                <value>bar</value>
            </variable>
            <variable name="version">
                <value>v1</value>
                <value>v2</value>
            </variable>
        </variables>
    <iterators>
</unpack-artifact>

Result:

my-dir/foo-1.0
my-dir/foo-2.0
my-dir/bar-v1
my-dir/bar-v2

Cli metadata template

cli-metadata.properties.mustache

helidon.version={{helidonVersion}}
build-tools.version={{buildtoolsVersion}}
cli.version={{cliVersion}}
{{#cliUpdateMessages}}
cli.{{version}}.message={{message}}
{{/cliUpdateMessages}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment