Parasoft Test Maven Plugin
This topic covers the Parasoft Test Maven plugin that allows you to configure Parasoft testing and build analysis actions to be invoked from Maven. It assumes a basic familiarity with Maven usage.
Sections include:
For general help on configuring Maven plugins, see http://maven.apache.org/guides/mini/guide-configuring-plugins.html
Prerequisites
The Parasoft Test Maven plugin requires:
There are no minimum requirements for disk space or memory space.
Setup
Before you can use the Parasoft Test Maven plugin, you need to add the http://build.parasoft.com/maven repository to your POM or repository manager. For instance:
<project>
   ... 
  <pluginRepositories>
      <pluginRepository>
          <id>Parasoft</id>
          <url>http://build.parasoft.com/maven</url>
      </pluginRepository>
  </pluginRepositories>
   ...
</project>
If you will be performing Jtest unit testing from Maven, you also need to add the build artifacts in the http://build.parasoft.com/maven/Parasoft/jtest repository to your POM or repository manager. For instance:
<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>Parasoft</groupId>
      <artifactId>jtest</artifactId>
      <version>9.5.0/version> <!-- See below for available versions -->
    </dependency>
    ...
  </dependencies>
   ...
  <repositories>
      <repository>
          <id>Parasoft</id>
          <url>http://build.parasoft.com/maven/</url>
      </repository>
  </repositories>
   ...
</project>
 
The Jtest versions you can specify in <version> are:
Configuration
There are three main ways to configure execution of the Parasoft plugin:
Option 1: Extend the POM
If you extend the POM, the specified goals will always be run at a particular phase of the build lifecycle. This allows you to specify your configuration once, and have it used every time that Maven builds the configured project.
First, specify the plugin version. For example:
<project>
  ...
  <build>
    <!-- To define the plugin version in your parent POM -->
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>Parasoft</groupId>
          <artifactId>maven-parasoft-plugin</artifactId>
          <version>3.0</version>
        </plugin>
        ...
      </plugins>
    </pluginManagement>
    <!-- To use the plugin goals in your POM or parent POM -->
    <plugins>
      <plugin>
        <groupId>Parasoft</groupId>
        <artifactId>maven-parasoft-plugin</artifactId>
        <version>3.0</version>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>
 
Next, specify goals and configuration parameters. For example, the following runs the eclipse and jtest goals during the test lifecycle phase (Jtest is run with the built-in Static Analysis Test Configuration):
<project>
  ...
  <build>
      <plugins>
          <plugin>
              <groupId>Parasoft</groupId>
              <artifactId>maven-parasoft-plugin</artifactId>
              <version>3.0</version>
              <configuration>
                  <config>builtin://Static Analysis</config>
              </configuration>
              <executions>
                  <execution>
                     <phase>test</phase>
                      <goals>
                          <goal>eclipse</goal>
                          <goal>jtest</goal>
                      </goals>
                  </execution>
              </executions>
          </plugin>
  </build>
  ...
</project>
 
You can run multiple goals; for instance, a team using Jtest might want to generate a local settings file, then run static analysis and unit testing.
Option 2: Configure the Plugin from the Command Line
The most direct way to execute the plugin is to configure the plugin execution details completely from the command line. For example, to invoke the jtest goal from the sample POM (above), you would go to the project’s command line and use
mvn ... Parasoft:maven-parasoft-plugin:jtest -Dparasoft.config="builtin://Static Analysis"
If you choose this approach, you will need to specify the appropriate options during every command line invocation.
Simplifying the Command Line
To simplify calling the plugin from the command line, we strongly recommend that you modify the settings.xml file (~/.m2/settings.xml) to include a Parasoft plugin group that specifies the appropriate groupids, artifactids, and goals. For example:
<settings>
    <pluginGroups>
    	<pluginGroup>Parasoft</pluginGroup>
    </pluginGroups>
</settings>
 
This will tell Maven where to search for the plugin—allowing you to shorten the above command line invocation to
mvn ... parasoft:jtest -Dparasoft.config="builtin://Static Analysis"
 
For general help on using Maven plugin prefix mappings, see http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html.
Another tip for simplifying your command line invocation is to specify some options in the POM. For instance, if you are invoking jtest-global from the command line, you could set the desired test configuration, localsettings file, etc. in the POM.
Option 3: Configure the Plugin as a Profile Switch
A third option is to add a switch within a profile, then run with the appropriate switch when you want to apply one of the Parasoft goals. You can configure any number of switches with different goals and parameters. This approach is useful for when you want to set plugin execution details in the POM, but you do not want it permanently attached to a lifecycle phase. It is also useful if you want configure a set of different plugin configurations, then select the appropriate one at the command line invocation.
For example, you can add a jtest profile to the build as follows:
 <profiles>
      <profile>
      <id>jtest</id>
          <build>
              <plugins>
                  <plugin>
                      <groupId>Parasoft</groupId>
                      <artifactId>maven-parasoft-plugin</artifactId>
                      <configuration>
                          <config>builtin://Static Analysis</config>
                      </configuration>
                      <executions>
                          <execution>
                              <phase>test</phase>
                              <goals>
                                  <goal>eclipse</goal>
                                  <goal>jtest</goal>
                              </goals>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>
      </profile>
  </profiles>
You can then use mvn install -Pjtest to run the jtest profile.
 
For general help on using Maven profiles, see http://maven.apache.org/guides/introduction/introduction-to-profiles.html.
Available Goals
See the plugin reference page.
Environment Variables
Environment variables can be used for options that will remain constant for all builds on a specific machine.
Each Parasoft Test product has its own OPTS variable:
For options that will be used for all Parasoft Test products, use PARASOFT_OPTS.
For options that will be used only in the project import phase, use IMPORT_OPTS.
These options are typically used when running the plugin via the command line—because some parameters can't be set in the command line (like those of type List). For example, the vmargs parameter of parasoft:jtest is of type List and can be used for things like changing the user name or increasing Java memory.
For example:
1.
2.
Usage Tips
This section provides tips for using the goals described in the plugin reference page.
Preparing for Jtest or SOAtest Execution
In order to execute Jtest, you need to have .classpath and .project files that work in the server environment. In order to execute SOAtest, you need to have a .project file that works in the server environment. To generate the files that Eclipse requires, use parasoft:eclipse.
If you have decided to store localsettings for Jtest and SOAtest execution on Concerto (as described in the Concerto documentation)—and/or if you are specifying localsettings options in the POM—parasoft:localsettings will generate a localsettings file with these options, then save it in the project so that it can easily be used for your Maven-driven tests.
Running Jtest Once for a Multi-Module Project
If you have a multi-module project (with modules that get built individually), the parasoft:jtest goal will run once for each project module. If you want a single Jtest run to analyze your entire project (for instance, for more accurate application of project-wide static analysis rules or to optimize execution time), use parasoft:jtest-global instead of parasoft:jtest.
Note that jtest-global must be invoked at the command line since it can’t be bound to any specific Maven lifecycle phase.
For Monitoring the Build
The parasoft:compile goal executes the Parasoft Build Monitor, which analyzes your build and sends Parasoft Concerto data regarding build warnings, errors, and the number of files successfully compiled. This is performed as part of the compile lifecycle phase.
When using this goal, be sure to specify the Concerto host, port, and project name.
To use this goal, go to your project’s POM file and add the following plugin instruction to your <build><plugins> node:
            <plugin>
                <groupId>Parasoft</groupId>
                <artifactId>maven-parasoft-plugin/artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <source>1.4</source>
                    <target>1.4</target>
                    <enableGRS>true</enableGRS>
                    <showDeprecation>true</showDeprecation>
                    <grsServerName>server.parasoft.com</grsServerName>
                    <grsServerPort>32323</grsServerPort>
                    <grsAttributes>
                        <attribute>test1=value1</attribute>
                        <attribute>test2=value2</attribute>
                        <attribute>test3=value3</attribute>
                    </grsAttributes>
                </configuration>
            </plugin>
 
To invoke Build Monitor with a compiler, run mvn parasoft:compile. 
 
Notes:
This extends the official compiler—enabling it to send build results to Parasoft Concerto.
Currently, Build Monitor only supports one source root (compileSourceRoots). Therefore, all project components are related to the first SourceRoot entry.