POM

Configure the plugin in your pom.xml.

<plugin>
  <groupId>de.smartics.maven.plugin</groupId>
  <artifactId>alias-maven-plugin</artifactId>
  <version>0.3.4</version>
  <executions>
    <execution>
      <id>alias</id>
      <goals>
        <goal>alias</goal>
      </goals>
    </execution>
  </executions>
</plugin>

For configuration options please refer to alias:alias.

Alias Script Generation

Alias XML

Provide an XML file with your aliases (per default in src/main/resources/alias.xml) that follows the rules specified by the alias XSD (the alias XSD is bundled with the plugin JAR).

<aliases
  xmlns="http://smartics.de/alias/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <group name="mvn">
    <alias>
      <name>i</name>
      <command>mvn -T 4 clean install</command>
      <comment>Installs a project with Maven. Requires a valid Maven-POM.</comment>
    </alias>
    <alias>
      <name>s</name>
      <command>mvn -T 4 initialize site</command>
      <comment>Creates Maven site. Requires a valid Maven-POM.</comment>
    </alias>
    <alias>
      <name>l</name>
      <command>mvn initialize license:format</command>
      <comment>Formats licensen headers. Requires a valid Maven-POM.</comment>
    </alias>
  </group>

  <group name="integration">
    <alias>
      <name>b</name>
      <command>mvn bugzilla:sync</command>
      <comment>Syncs Bugzilla product with Maven-POM.</comment>
    </alias>
    <alias>
      <name>bi</name>
      <command>mvn bugzilla:init</command>
      <comment>Creates product in Bugzilla based on Maven-POM.</comment>
    </alias>
    <alias>
      <name>chj</name>
      <command>mvn hudson:createJobs</command>
      <comment>Creates Hudson job based on Maven-POM.</comment>
    </alias>
    <alias>
      <name>dhj</name>
      <command>mvn hudson:deleteJobs</command>
      <comment>Deletes Hudson job based on Maven-POM.</comment>
    </alias>
  </group>

  <group name="java">
    <alias env="windows">
      <name>j6</name>
      <command passArgs="false">set JAVA_HOME=%JAVA_HOME_6%</command>
      <comment>Sets environment variable JAVA_HOME to existing JAVA_HOME_6.</comment>
    </alias>
    <alias env="windows">
      <name>j7</name>
      <command passArgs="false">set JAVA_HOME=%JAVA_HOME_7%</command>
      <comment>Sets environment variable JAVA_HOME to existing JAVA_HOME_7.</comment>
    </alias>
  </group>
</aliases>

The group element allows to group aliases to separate them visually in the help listing. The alias requires a name and a command. The comment is optional and not presented in the console listing (see below).

The attribute passArgs of the command element allows to pass additional arguments to the alias call. Per default this is always true.

The attribute env of the alias element allows to tag aliases to be only valid in a specific environment. In the example the windows environment will show the java elements, since these aliases a Windows specific.

Generated Windows Script

This is the generated alias script for the windows environment:

@echo off
REM Add this script to the registry to be called on each instantiation of the command shell:
REM reg add "hkcu\software\microsoft\command processor" /v Autorun /t reg_sz /d D:\mypath\aliases.cmd
REM
REM D:\>h
REM  i   = mvn -T 4 clean install [args]
REM  s   = mvn -T 4 initialize site [args]
REM  l   = mvn initialize license:format [args]
REM ---
REM  b   = mvn bugzilla:sync [args]
REM  bi  = mvn bugzilla:init [args]
REM  chj = mvn hudson:createJobs [args]
REM  cdj = mvn hudson:deleteJobs [args]
REM ---
REM  j6  = Set JAVA_HOME to JAVA_HOME_6
REM  j7  = Set JAVA_HOME to JAVA_HOME_7
REM ---
REM  h   = This help.

doskey i   = mvn -T 4 clean install $*
doskey s   = mvn -T 4 initialize site $*
doskey l   = mvn initialize license:format $*
doskey b   = mvn bugzilla:sync $*
doskey bi  = mvn bugzilla:init $*
doskey chj = mvn hudson:createJobs $*
doskey cdj = mvn hudson:deleteJobs $*
doskey j6  = set JAVA_HOME=%JAVA_HOME_6%
doskey j7  = set JAVA_HOME=%JAVA_HOME_7%
doskey h =echo  i   = mvn -T 4 clean install [args] ^& echo  s   = mvn -T 4 initialize site [args] ^& echo  l   = mvn initialize license:format [args] ^& echo --- ^& echo  b   = mvn bugzilla:sync [args] ^& echo  bi  = mvn bugzilla:init [args] ^& echo  hcj = mvn hudson:createJobs [args] ^& echo  hdj = mvn hudson:deleteJobs [args] ^& echo --- ^& echo  j6  = Set JAVA_HOME to JAVA_HOME_6 ^& echo  j7  = Set JAVA_HOME to JAVA_HOME_7 ^& echo --- ^&  echo  h   = This help.
@echo on

Console Output

The example above creates a script that defines the following aliases. They can be viewed from the command line by typing 'h' for 'help'.

PROMPT>h
 --- mvn
 i   = mvn -T 4 clean install [args]
 s   = mvn -T 4 initialize site [args]
 l   = mvn initialize license:format [args]
 --- integration
 b   = mvn bugzilla:sync [args]
 bi  = mvn bugzilla:init [args]
 chj = mvn hudson:createJobs [args]
 dhj = mvn hudson:deleteJobs [args]
 --- java
 j6  = set JAVA_HOME=D:\java\jdk1.6.0_25x64
 j7  = set JAVA_HOME=D:\java\jdk1.7.0
 --- help
 h   = This help.

Additional Information

It is often convenient for a user to have a link for additional information in case the brief information printed to the command line is not of much help. Provide a docUrl parameter to further information.

It is also convenient to help the user install the script so that the aliases are available in every command shell. This is activated by default via the addInstallationComment parameter.

To provide this additional information for the Windows script you may add the following to add a reference to your project's index page.:

<plugin>
  <groupId>de.smartics.maven.plugin</groupId>
  <artifactId>alias-maven-plugin</artifactId>
  <version>0.3.4</version>
  <executions>
    <execution>
      <id>alias</id>
      <goals>
        <goal>alias</goal>
      </goals>
    </execution>
    <configuration>
      <docUrl>${project.url}</docUrl>
    </configuration>
  </executions>
</plugin>

Replace ${project.url} by any absolute URL if your documentation page exists elsewhere. Per default, no URL information is added.

The documentation URL will be rendered like this (using the example from above):

PROMPT>h
 --- mvn
 i   = mvn -T 4 clean install [args]
 s   = mvn -T 4 initialize site [args]
 l   = mvn initialize license:format [args]
 --- integration
 b   = mvn bugzilla:sync [args]
 bi  = mvn bugzilla:init [args]
 chj = mvn hudson:createJobs [args]
 dhj = mvn hudson:deleteJobs [args]
 --- java
 j6  = set JAVA_HOME=D:\java\jdk1.6.0_25x64
 j7  = set JAVA_HOME=D:\java\jdk1.7.0
 --- help
 h   = This help.
 For additional information please refer to:
   http://your.intranet.org/your/path/

Include generated Scripts

Per default the generated scripts are not added to the generated JAR. If this should be done, add the generated folder as a resource like this:

<build>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
    </resource>
    <resource>
      <directory>target/alias-scripts</directory>
      <targetPath>alias-scripts</targetPath>
    </resource>
  </resources>