Create a Dashboard Report

The Dashboard Plugin is designed for extension. We provide a simple interface, DashboardReport , that can be implemented to add new statistics to the dashboard table.

To write your own addition to the Dashboard report and use it in your site do the following four steps:

  1. Create a Maven project. The project should be a jar project. The example below is a very simple pom.xml.
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.xebia.maven.plugins</groupId>
        <artifactId>test-maven-dashboard-report</artifactId>
        <packaging>jar</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>test-maven-dashboard-report Maven Mojo</name>
        <url>http://maven.apache.org</url>
        <dependencies>
            <dependency>
                <groupId>com.xebia.mojo</groupId>
                <artifactId>maven-dashboard-plugin</artifactId>
                <version>1.0-alpha2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </project>

    The dependency on maven-dashboard-plugin is necessary for the next step.

  2. Add an implementation of DashboardReport to the source tree of the project. The example below is a simple implementation that will add a column to the dashboard table with the text "This is a test" in all columns.
    package com.xebia.maven.plugins;
    
    import java.util.Collections;
    
    import org.apache.maven.plugin.MojoExecutionException;
    import org.apache.maven.project.MavenProject;
    import org.dom4j.DocumentHelper;
    import org.dom4j.Node;
    
    import com.xebia.mojo.dashboard.DashboardReport;
    
    public class TestDashboardReport implements DashboardReport {
    
        public boolean canExecute(MavenProject arg0) {
            return true;
        }
    
        public Node getContent(MavenProject arg0, String arg1) throws MojoExecutionException {
            return DocumentHelper.createText("This is a test");
        }
    
        public String getHeaderForColumn(String arg0) {
            return null;
        }
    
        public String getLinkLocation() {
            return null;
        }
    
        public List getColumnNames() {
            return Collections.singletonList("test");
        }
    
        public String title() {
            return "Test";
        }
    }
  3. Build the project and install it in your maven repository.
  4. Add the following to the configuration of the dashboard report in your pom.xml
        <build>
        ...
            <plugins>
            ...
                <plugin>
                    <groupId>com.xebia.mojo</groupId>
                    <artifactId>maven-dashboard-plugin</artifactId>
                    <configuration>
                    ...
                        <reports>
                        ...
                            <report>com.xebia.maven.plugins.TestDashboardReport</report>
                        </reports>
                    ...
                    </configuration>
                </plugin>
            </plugins>
        </build>

    Adding your own report makes adding other dashboard reports to the configuration mandatory. Other configuration options, like the columns option will also apply to your own dashboard report. You cannot use an alias for your custom dashboard report.

Useful classes

There are a few useful classes for when you want to extend the Maven Dashboard Plugin.

  1. The com.xebia.mojo.dashboard.reports.AbstractDashboardReport class. This class contains base functionality for a Dashboard Report. A report that is based upon a file (generated by one of the reporting plugins configured for the project) can extend this base class to use its (very basic) functionality.
  2. The com.xebia.mojo.dashboard.reports.HtmlFileXPathReport . This class can be used to process a (X)HTML file and extract nodes for the dashboard by XPath.
  3. The com.xebia.mojo.dashboard.util.XmlUtil interface and its implementation based on Tidy and Dom4J . This class provides utility methods for working with DOM nodes and XPath expressions.