org.codehaus.mojo.chronos.HelpMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chronos-surefire-maven-plugin Show documentation
Show all versions of chronos-surefire-maven-plugin Show documentation
This plugin enables you to track and the executiontimes of a selection of Your unittests (JUnit or TestNG).
One usage is to regard some of your automatic testcases as performancetests, tracking their executiontimes.
Another usage is simply to monitor Your automatic tests to discover reasons for slow build times.
The newest version!
package org.codehaus.mojo.chronos;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/**
* Display help information on chronos-surefire-maven-plugin.
Call mvn chronos-surefire:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
*
* @version generated on Thu Aug 23 10:27:15 CEST 2012
* @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.9)
* @goal help
* @requiresProject false
* @threadSafe
*/
public class HelpMojo
extends AbstractMojo
{
/**
* If true
, display all settable properties for each goal.
*
* @parameter expression="${detail}" default-value="false"
*/
private boolean detail;
/**
* The name of the goal for which to show help. If unspecified, all goals will be displayed.
*
* @parameter expression="${goal}"
*/
private java.lang.String goal;
/**
* The maximum length of a display line, should be positive.
*
* @parameter expression="${lineLength}" default-value="80"
*/
private int lineLength;
/**
* The number of spaces per indentation level, should be positive.
*
* @parameter expression="${indentSize}" default-value="2"
*/
private int indentSize;
/** {@inheritDoc} */
public void execute()
throws MojoExecutionException
{
if ( lineLength <= 0 )
{
getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." );
lineLength = 80;
}
if ( indentSize <= 0 )
{
getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." );
indentSize = 2;
}
StringBuffer sb = new StringBuffer();
append( sb, "org.codehaus.mojo:chronos-surefire-maven-plugin:1.1.0", 0 );
append( sb, "", 0 );
append( sb, "Chronos Surefire", 0 );
append( sb, "This plugin enables you to track and the executiontimes of a selection of Your unittests (JUnit or TestNG). One usage is to regard some of your automatic testcases as performancetests, tracking their executiontimes. Another usage is simply to monitor Your automatic tests to discover reasons for slow build times.", 1 );
append( sb, "", 0 );
if ( goal == null || goal.length() <= 0 )
{
append( sb, "This plugin has 2 goals:", 0 );
append( sb, "", 0 );
}
if ( goal == null || goal.length() <= 0 || "collect".equals( goal ) )
{
append( sb, "chronos-surefire:collect", 0 );
append( sb, "Goal which collects the execution of each performed unittest, and compares the execution time to previous measured\nexecution times for the same test.\nIf the new execution time is larger then the old ones, the build will fail with a list of non-complient tests.", 1 );
append( sb, "", 0 );
if ( detail )
{
append( sb, "Available parameters:", 1 );
append( sb, "", 0 );
append( sb, "chronosdir", 2 );
append( sb, "The directory to store chronos timing output.", 3 );
append( sb, "Expression: ${basedir}/target/chronos", 3 );
append( sb, "", 0 );
append( sb, "dataid (Default: performancetest)", 2 );
append( sb, "The id of the data, to create a report from.", 3 );
append( sb, "", 0 );
append( sb, "discrepancy (Default: 5)", 2 );
append( sb, "The maximum difference allowed between two measurements in percentage.\nSetting this to 0 (or less) will cause many failed builds, since there will almost always be a small discrepancy between two identical runs.", 3 );
append( sb, "", 0 );
append( sb, "excludes", 2 );
append( sb, "List of test cases to exclude from reporting and validation", 3 );
append( sb, "", 0 );
append( sb, "failbuild (Default: true)", 2 );
append( sb, "Instructs chronos-timing to either fail or ignore the descrepancy (if any).", 3 );
append( sb, "", 0 );
append( sb, "includes", 2 );
append( sb, "List of test cases to include in reporting and validation", 3 );
append( sb, "", 0 );
append( sb, "maxnumberofresults (Default: 200)", 2 );
append( sb, "The number of (latest) results to include in the final graphs.\nThe more result - the longer processing time!", 3 );
append( sb, "", 0 );
append( sb, "minimumexecutiontime (Default: 100)", 2 );
append( sb, "Many unittests only takes a short time (< 100 m.seconds). Such tests will usually fail in chronos-surefire,\nbecause the default discrepancy of 50 m.seconds is 5 m.seconds, which is below the precision of the execution time recorder.\nIn order to prevent such problems, chronos-timing will per default filter out tests with an execution time less the a certain minimum execution time.", 3 );
append( sb, "", 0 );
append( sb, "reports", 2 );
append( sb, "List of test cases to exclude from discrepancy tests.\nChronos will still collect and report the execution time, but will not fail the build.", 3 );
append( sb, "", 0 );
append( sb, "surefiredir", 2 );
append( sb, "The directory where surefire reports results are stored.", 3 );
append( sb, "Expression: ${basedir}/target/surefire-reports", 3 );
append( sb, "", 0 );
append( sb, "testSourceDirectory", 2 );
append( sb, "(no description available)", 3 );
append( sb, "Expression: ${project.build.testSourceDirectory}", 3 );
append( sb, "", 0 );
}
}
if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
{
append( sb, "chronos-surefire:help", 0 );
append( sb, "Display help information on chronos-surefire-maven-plugin.\nCall\n\u00a0\u00a0mvn\u00a0chronos-surefire:help\u00a0-Ddetail=true\u00a0-Dgoal=\nto display parameter details.", 1 );
append( sb, "", 0 );
if ( detail )
{
append( sb, "Available parameters:", 1 );
append( sb, "", 0 );
append( sb, "detail (Default: false)", 2 );
append( sb, "If true, display all settable properties for each goal.", 3 );
append( sb, "Expression: ${detail}", 3 );
append( sb, "", 0 );
append( sb, "goal", 2 );
append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
append( sb, "Expression: ${goal}", 3 );
append( sb, "", 0 );
append( sb, "indentSize (Default: 2)", 2 );
append( sb, "The number of spaces per indentation level, should be positive.", 3 );
append( sb, "Expression: ${indentSize}", 3 );
append( sb, "", 0 );
append( sb, "lineLength (Default: 80)", 2 );
append( sb, "The maximum length of a display line, should be positive.", 3 );
append( sb, "Expression: ${lineLength}", 3 );
append( sb, "", 0 );
}
}
if ( getLog().isInfoEnabled() )
{
getLog().info( sb.toString() );
}
}
/**
* Repeat a String n
times to form a new string.
*
* @param str String to repeat
* @param repeat number of times to repeat str
* @return String with repeated String
* @throws NegativeArraySizeException if repeat < 0
* @throws NullPointerException if str is null
*/
private static String repeat( String str, int repeat )
{
StringBuffer buffer = new StringBuffer( repeat * str.length() );
for ( int i = 0; i < repeat; i++ )
{
buffer.append( str );
}
return buffer.toString();
}
/**
* Append a description to the buffer by respecting the indentSize and lineLength parameters.
* Note: The last character is always a new line.
*
* @param sb The buffer to append the description, not null
.
* @param description The description, not null
.
* @param indent The base indentation level of each line, must not be negative.
*/
private void append( StringBuffer sb, String description, int indent )
{
for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
{
sb.append( it.next().toString() ).append( '\n' );
}
}
/**
* Splits the specified text into lines of convenient display length.
*
* @param text The text to split into lines, must not be null
.
* @param indent The base indentation level of each line, must not be negative.
* @param indentSize The size of each indentation, must not be negative.
* @param lineLength The length of the line, must not be negative.
* @return The sequence of display lines, never null
.
* @throws NegativeArraySizeException if indent < 0
*/
private static List toLines( String text, int indent, int indentSize, int lineLength )
{
List lines = new ArrayList();
String ind = repeat( "\t", indent );
String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
for ( int i = 0; i < plainLines.length; i++ )
{
toLines( lines, ind + plainLines[i], indentSize, lineLength );
}
return lines;
}
/**
* Adds the specified line to the output sequence, performing line wrapping if necessary.
*
* @param lines The sequence of display lines, must not be null
.
* @param line The line to add, must not be null
.
* @param indentSize The size of each indentation, must not be negative.
* @param lineLength The length of the line, must not be negative.
*/
private static void toLines( List lines, String line, int indentSize, int lineLength )
{
int lineIndent = getIndentLevel( line );
StringBuffer buf = new StringBuffer( 256 );
String[] tokens = line.split( " +" );
for ( int i = 0; i < tokens.length; i++ )
{
String token = tokens[i];
if ( i > 0 )
{
if ( buf.length() + token.length() >= lineLength )
{
lines.add( buf.toString() );
buf.setLength( 0 );
buf.append( repeat( " ", lineIndent * indentSize ) );
}
else
{
buf.append( ' ' );
}
}
for ( int j = 0; j < token.length(); j++ )
{
char c = token.charAt( j );
if ( c == '\t' )
{
buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
}
else if ( c == '\u00A0' )
{
buf.append( ' ' );
}
else
{
buf.append( c );
}
}
}
lines.add( buf.toString() );
}
/**
* Gets the indentation level of the specified line.
*
* @param line The line whose indentation level should be retrieved, must not be null
.
* @return The indentation level of the line.
*/
private static int getIndentLevel( String line )
{
int level = 0;
for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
{
level++;
}
for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
{
if ( line.charAt( i ) == '\t' )
{
level++;
break;
}
}
return level;
}
}