From: Carlos S. <car...@us...> - 2005-11-08 18:19:27
|
carlossg 05/11/08 10:19:19 Added: history .cvsignore maven.xml plugin-project.xml plugin.jelly plugin.properties project.properties project.xml history/src/main/org/apache/maven/history/dashboard FileMerger.java PlotterTask.java Report.java ReportHandler.java history/src/main/org/apache/maven/history/report FileMerger.java PlotterTask.java Report.java ReportHandler.java history/xdocs goals.xml index.xml navigation.xml properties.xml Log: Added history plugin by Morten Kristiansen <mor...@ms...> Revision Changes Path 1.1 maven-plugins/history/.cvsignore Index: .cvsignore =================================================================== target velocity.log* bin 1.1 maven-plugins/history/maven.xml Index: maven.xml =================================================================== <?xml version="1.0" encoding="ISO-8859-1"?> <project xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:u="jelly:util" xmlns:maven="jelly:maven" xmlns:ant="jelly:ant" xmlns:log="jelly:log" xmlns:v="jelly:velocity"> <postGoal name="xdoc:jelly-transform"> <u:available file="${maven.docs.dest}/example1"> <j:set var="doExample1" value="false" /> </u:available> <j:if test="${doExample1 != 'false'}"> <maven:maven descriptor="${basedir}/src/example1/project.xml" goals="multiproject" ignoreFailures="false" /> <ant:mkdir dir="${maven.docs.dest}/example1" /> <ant:copy todir="${maven.docs.dest}/example1"> <fileset dir="${basedir}/src/example1/target/docs"/> </ant:copy> </j:if> <u:available file="${maven.docs.dest}/example2"> <j:set var="doExample2" value="false" /> </u:available> <j:if test="${doExample2 != 'false'}"> <maven:maven descriptor="${basedir}/src/example2/project.xml" goals="multiproject" ignoreFailures="false" /> <ant:mkdir dir="${maven.docs.dest}/example2" /> <ant:copy todir="${maven.docs.dest}/example2"> <fileset dir="${basedir}/src/example2/target/docs"/> </ant:copy> </j:if> <u:available file="${maven.docs.dest}/example3"> <j:set var="doExample3" value="false" /> </u:available> <j:if test="${doExample3 != 'false'}"> <maven:maven descriptor="${basedir}/src/example3/project.xml" goals="multiproject" ignoreFailures="false" /> <ant:mkdir dir="${maven.docs.dest}/example3" /> <ant:copy todir="${maven.docs.dest}/example3"> <fileset dir="${basedir}/src/example3/target/docs"/> </ant:copy> </j:if> </postGoal> </project> 1.1 maven-plugins/history/plugin-project.xml Index: plugin-project.xml =================================================================== <?xml version="1.0" encoding="ISO-8859-1"?> <project> <pomVersion>3</pomVersion> <artifactId>plugin-parent</artifactId> <name>Plugin Parent</name> <groupId>maven-plugins</groupId> <currentVersion>1.0</currentVersion> <organization> <name>SourceForge</name> <url>http://www.sourceforge.net/projects/maven-plugins/</url> <logo>http://sourceforge.net/sflogo.php?group_id=61626&type=5</logo> </organization> <url>http://maven-plugins.sourceforge.net</url> <inceptionYear>2002</inceptionYear> <package>org.apache.maven</package> <logo>http://maven-plugins.sourceforge.net/images/maven-plugins-logo.gif</logo> <issueTrackingUrl>http://sourceforge.net/tracker/?group_id=61626</issueTrackingUrl> <siteAddress>maven-plugins.sourceforge.net</siteAddress> <siteDirectory>/home/groups/${pom.groupId.substring(0,1)}/${pom.groupId.substring(0,2)}/${pom.groupId}/htdocs/${pom.artifactId}</siteDirectory> <distributionSite>shell1.maven-plugins.sf.net</distributionSite> <distributionDirectory>/home/groups/${pom.groupId.substring(0,1)}/${pom.groupId.substring(0,2)}/${pom.groupId}/htdocs/repository/</distributionDirectory> <repository> <connection>scm:cvs:pserver:ano...@cv...:/cvsroot/maven-plugins:maven-plugins</connection> <developerConnection>scm:cvs:ssh:use...@cv...:/cvsroot/maven-plugins:maven-plugins</developerConnection> <url>http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/maven-plugins/maven-plugins/</url> </repository> <mailingLists> <mailingList> <name>Maven-Plugins User List</name> <subscribe>${pom.groupId}-us...@li...</subscribe> <unsubscribe>${pom.groupId}-us...@li...</unsubscribe> <archive>http://sourceforge.net/mailarchive/forum.php?forum_id=11777</archive> </mailingList> <mailingList> <name>Maven-Plugins Developer List</name> <subscribe>${pom.groupId}-de...@li...</subscribe> <unsubscribe>${pom.groupId}-de...@li...</unsubscribe> <archive>http://sourceforge.net/mailarchive/forum.php?forum_id=11782</archive> </mailingList> <mailingList> <name>Maven-Plugins CVS Commits List</name> <subscribe>${pom.groupId}-cv...@li...</subscribe> <unsubscribe>${pom.groupId}-cv...@li...</unsubscribe> <archive>http://sourceforge.net/mailarchive/forum.php?forum_id=11781</archive> </mailingList> </mailingLists> <build> <sourceDirectory>${basedir}/src/main</sourceDirectory> <unitTestSourceDirectory>${basedir}/src/test</unitTestSourceDirectory> <unitTest> <includes> <include>**/*Test.java</include> </includes> </unitTest> <resources> <resource> <directory>${basedir}/src/plugin-resources</directory> <targetPath>plugin-resources</targetPath> </resource> <resource> <directory>${basedir}</directory> <includes> <include>plugin.jelly</include> <include>plugin.properties</include> <include>project.properties</include> <include>project.xml</include> </includes> </resource> </resources> </build> </project> 1.1 maven-plugins/history/plugin.jelly Index: plugin.jelly =================================================================== <?xml version="1.0"?> <project xmlns:define="jelly:define" xmlns:ant="jelly:ant" xmlns:j="jelly:core" xmlns:jsl="jelly:jsl" xmlns:doc="doc" xmlns:log="jelly:log" xmlns:x="jelly:xml" xmlns:assert="assert" xmlns:maven="jelly:maven" xmlns:u="jelly:util"> <!-- ####################################################### --> <!-- DASHBOARD HISTORY GOALS --> <!-- ####################################################### --> <!-- ############# REGISTER ############# --> <goal name="maven-dashboard-history-plugin:register"> <doc:registerReport name="Dashboard History" pluginName="dashboard-history" link="history/dashboard/dashboard-history" description="Dashboard history report"/> </goal> <!-- ############# DEREGISTER ############# --> <goal name="maven-dashboard-history-plugin:deregister"> <doc:deregisterReport name="Dashboard History"/> </goal> <!-- ############# REPORT ############# --> <goal name="dashboard-history:report" description="Run Dashboard history report"> <attainGoal name="_dashboard-history:merge" /> <attainGoal name="_dashboard-history:plot" /> <attainGoal name="_dashboard-history:site" /> </goal> <!-- ############# MERGE SUB GOAL ############# --> <goal name="_dashboard-history:merge"> <!-- Merge content from dashboard file to dashboard history file --> <j:set var="dashboardRaw" value="${context.getVariable('maven.dashboard.report.xml')}"/> <u:available file="${context.getVariable('dashboardRaw')}"> <ant:echo>Merging dashboard data from ${dashboardRaw} to ${maven.history.dashboard.file}</ant:echo> <j:useBean var="fileMerger" class="org.apache.maven.history.dashboard.FileMerger" location="${plugin.dir}" dashboardHistoryRaw="${maven.history.dashboard.file}" duration="${maven.history.dashboard.duration}" dashboardRaw="${dashboardRaw}" mavenBuildDir="${maven.build.dir}" encoding="${maven.docs.outputencoding}" /> <j:catch var="ex"> <j:invoke method="merge" on="${fileMerger}"/> </j:catch> <j:if test="${ex != null}"> <log:error>${ex.printStackTrace()}</log:error> <ant:fail>Dashboard history merge failed due to error</ant:fail> </j:if> </u:available> </goal> <!-- ############# PLOT SUB GOAL ############# --> <goal name="_dashboard-history:plot"> <u:available file="${maven.history.dashboard.file}"> <!-- Get dashboard aggregators to iterate over --> <j:set var="varMyReports" value="${maven.history.dashboard.reports}" /> <j:if test="${varMyReports == ''}"> <maven:get var="varMyReports" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregators"/> </j:if> <u:tokenize var="varReports" delim=",">${varMyReports}</u:tokenize> <!-- Plot images for aggregators --> <ant:echo>Plotting images for ${varMyReports}</ant:echo> <ant:mkdir dir="${maven.docs.dest}/history" /> <ant:mkdir dir="${maven.docs.dest}/history/dashboard" /> <ant:mkdir dir="${maven.docs.dest}/history/dashboard/images" /> <ant:mkdir dir="${maven.gen.docs}/history" /> <ant:mkdir dir="${maven.gen.docs}/history/dashboard" /> <path id="history.classpath"> <pathelement path="${plugin.dir}" /> <pathelement location="${plugin.getDependencyPath('jfreechart:jfreechart')}"/> <pathelement location="${plugin.getDependencyPath('jcommon:jcommon')}"/> </path> <ant:taskdef name="history-plotter" classname="org.apache.maven.history.dashboard.PlotterTask"> <classpath refid="history.classpath"/> </ant:taskdef> <ant:history-plotter historySrc="${maven.history.dashboard.file}" dateformat="${maven.history.dashboard.dateformat}" width="${maven.history.dashboard.graph.width}" height="${maven.history.dashboard.graph.height}" style="${maven.history.dashboard.style}" imageDest="${maven.docs.dest}/history/dashboard/images" /> </u:available> </goal> <!-- ############# SITE SUB GOAL ############# --> <goal name="_dashboard-history:site"> <u:available file="${maven.history.dashboard.file}"> <!-- SET STYLE --> <j:set var="styleValue" value="${maven.history.dashboard.style}" /> <j:choose> <j:when test="${styleValue == null or styleValue == ''}"> <j:set var="style" value="AGGREGATE" /> </j:when> <j:when test="${styleValue == 'single'}"> <j:set var="style" value="SINGLE" /> <maven:reactor basedir="${maven.dashboard.basedir}" banner="Gathering project list for" includes="${maven.dashboard.includes}" excludes="${maven.dashboard.excludes}" postProcessing="true" collectOnly="true" ignoreFailures="${maven.dashboard.ignoreFailures}"/> </j:when> <j:otherwise> <j:set var="style" value="GROUP" /> <u:tokenize var="varGroups" delim=",">${styleValue}</u:tokenize> </j:otherwise> </j:choose> <!-- TOKENIZE AGGREGATORS AND CREATE SITES --> <j:set var="varMyReports" value="${maven.history.dashboard.reports}" /> <j:if test="${varMyReports == ''}"> <maven:get var="varMyReports" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregators"/> </j:if> <u:tokenize var="varReports" delim=",">${varMyReports}</u:tokenize> <j:forEach var="varReport" items="${varReports}"> <maven:get var="descProperty" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregator.${varReport}.description"/> <ant:echo>Creating site ${maven.gen.docs}/history/dashboard/${varReport}.html</ant:echo> <j:file name="${maven.gen.docs}/history/dashboard/${varReport}.xml" prettyPrint="true"> <document> <properties> <title>Dashboard History Report</title> </properties> <body> <section name="${descProperty}"> <j:choose> <j:when test="${style == 'SINGLE'}"> <j:forEach var="reactorProject" items="${reactorProjects}"> <p><a name="${varReport}-${reactorProject.artifactId}"></a></p> <subsection name="${reactorProject.artifactId}"> <p><a href="dashboard-history.html">Back</a></p> <p><img src="images/${varReport}-${reactorProject.artifactId}.jpg" /></p> </subsection> </j:forEach> </j:when> <j:when test="${style == 'GROUP'}"> <j:forEach var="varGroup" items="${varGroups}"> <p><a name="${varReport}-${varGroup}"></a></p> <subsection name="${varGroup}"> <p><a href="dashboard-history.html">Back</a></p> <p><img src="images/${varReport}-${varGroup}.jpg" /></p> </subsection> </j:forEach> </j:when> <j:otherwise> <p><a href="dashboard-history.html">Back</a></p> <p><img src="images/${varReport}.jpg" /></p> </j:otherwise> </j:choose> </section> </body> </document> </j:file> </j:forEach> <ant:echo>Creating site ${maven.gen.docs}/history/dashboard/dashboard-history.html</ant:echo> <j:file name="${maven.gen.docs}/history/dashboard/dashboard-history.xml" prettyPrint="true"> <document> <properties> <title>Dashboard History Report</title> </properties> <body> <section name="Dashboard History Report"> <table> <tr> <j:choose> <j:when test="${style == 'SINGLE'}"> <th>Project</th> </j:when> <j:when test="${style == 'GROUP'}"> <th>Group</th> </j:when> </j:choose> <j:forEach var="varReport" items="${varReports}"> <maven:get var="labelProperty" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregator.${varReport}.label"/> <th><a href="${varReport}.html">${labelProperty}</a></th> </j:forEach> </tr> <j:choose> <j:when test="${style == 'SINGLE'}"> <j:forEach var="reactorProject" items="${reactorProjects}"> <tr> <td><a href="../../multiproject/${reactorProject.artifactId}/index.html">${reactorProject.name}</a></td> <j:forEach var="varReport" items="${varReports}"> <td><a href="${varReport}.html#${varReport}-${reactorProject.artifactId}"><img src="images/${varReport}-${reactorProject.artifactId}.jpg" width="200" height="140" /></a></td> </j:forEach> </tr> </j:forEach> </j:when> <j:when test="${style == 'GROUP'}"> <j:forEach var="varGroup" items="${varGroups}"> <tr> <td>${varGroup}</td> <j:forEach var="varReport" items="${varReports}"> <maven:get var="descProperty" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregator.${varReport}.description"/> <td><a href="${varReport}.html#${varReport}-${varGroup}"><img src="images/${varReport}-${varGroup}.jpg" width="200" height="140" /></a></td> </j:forEach> </tr> </j:forEach> </j:when> <j:otherwise> <tr> <j:forEach var="varReport" items="${varReports}"> <td><a href="${varReport}.html"><img src="images/${varReport}.jpg" width="200" height="140" /></a></td> </j:forEach> </tr> </j:otherwise> </j:choose> </table> </section> </body> </document> </j:file> </u:available> </goal> <!-- ####################################################### --> <!-- REPORT HISTORY GOALS --> <!-- ####################################################### --> <!-- ############# REGISTER ############# --> <goal name="maven-report-history-plugin:register"> <doc:registerReport name="Report History" pluginName="report-history" link="history/report-history" description="Report history report"/> </goal> <!-- ############# DEREGISTER ############# --> <goal name="maven-report-history-plugin:deregister"> <doc:deregisterReport name="Report History"/> </goal> <!-- ############# REPORT ############# --> <goal name="report-history:report" description="Run Report history report"> <attainGoal name="_report-history:merge" /> <attainGoal name="_report-history:plot" /> <attainGoal name="_report-history:site" /> </goal> <!-- ############# MERGE SUB GOAL ############# --> <goal name="_report-history:merge"> <!-- Get dashboard aggregators to iterate over --> <j:set var="varMyReports" value="${maven.history.report.reports}" /> <j:if test="${varMyReports == ''}"> <maven:get var="varMyReports" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregators"/> </j:if> <u:tokenize var="varReports" delim=",">${varMyReports}</u:tokenize> <ant:echo>Merging report data to ${maven.history.report.file}</ant:echo> <j:new var="myMap" className="java.util.HashMap" /> <j:forEach var="varReport" items="${varReports}"> <maven:get var="scriptProperty" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregator.${varReport}.script"/> <ant:echo>Merging data for ${varReport} using script ${scriptProperty}</ant:echo> <j:set var="value"> <j:import file="${scriptProperty}" inherit="true"/> </j:set> <j:catch var="ex"> <j:invoke method="put" on="${myMap}"> <j:arg value="${varReport}"/> <j:arg value="${value}"/> </j:invoke> </j:catch> </j:forEach> <j:useBean var="fileMerger" class="org.apache.maven.history.report.FileMerger" location="${plugin.dir}" reportHistoryRaw="${maven.history.report.file}" duration="${maven.history.report.duration}" map="${myMap}" mavenBuildDir="${maven.build.dir}" encoding="${maven.docs.outputencoding}" /> <j:catch var="ex"> <j:invoke method="merge" on="${fileMerger}"/> </j:catch> <j:if test="${ex != null}"> <log:error>${ex.printStackTrace()}</log:error> <ant:fail>Report history merge failed due to error</ant:fail> </j:if> </goal> <!-- ############# PLOT SUB GOAL ############# --> <goal name="_report-history:plot"> <u:available file="${maven.history.report.file}"> <!-- Get dashboard aggregators to iterate over --> <j:set var="varMyReports" value="${maven.history.report.reports}" /> <j:if test="${varMyReports == ''}"> <maven:get var="varMyReports" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregators"/> </j:if> <u:tokenize var="varReports" delim=",">${varMyReports}</u:tokenize> <!-- Plot images for aggregators --> <ant:echo>Plotting images for ${varMyReports}</ant:echo> <ant:mkdir dir="${maven.docs.dest}/history" /> <ant:mkdir dir="${maven.docs.dest}/history/images" /> <ant:mkdir dir="${maven.gen.docs}/history" /> <path id="history.classpath"> <pathelement path="${plugin.dir}" /> <pathelement location="${plugin.getDependencyPath('jfreechart:jfreechart')}"/> <pathelement location="${plugin.getDependencyPath('jcommon:jcommon')}"/> </path> <ant:taskdef name="history-plotter" classname="org.apache.maven.history.report.PlotterTask"> <classpath refid="history.classpath"/> </ant:taskdef> <ant:history-plotter historySrc="${maven.history.report.file}" dateformat="${maven.history.report.dateformat}" width="${maven.history.report.graph.width}" height="${maven.history.report.graph.height}" imageDest="${maven.docs.dest}/history/images" /> </u:available> </goal> <!-- ############# SITE SUB GOAL ############# --> <goal name="_report-history:site"> <u:available file="${maven.history.report.file}"> <!-- TOKENIZE AGGREGATORS AND CREATE SITE --> <j:set var="varMyReports" value="${maven.history.report.reports}" /> <j:if test="${varMyReports == ''}"> <maven:get var="varMyReports" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregators"/> </j:if> <u:tokenize var="varReports" delim=",">${varMyReports}</u:tokenize> <ant:echo>Creating site ${maven.gen.docs}/history/report-history.html</ant:echo> <j:file name="${maven.gen.docs}/history/report-history.xml" prettyPrint="true"> <maven:get var="descProperty" plugin="maven-dashboard-plugin" property="maven.dashboard.aggregator.${varReport}.description"/> <document> <properties> <title>Report History Report</title> </properties> <body> <section name="Report History Report"> <j:forEach var="varReport" items="${varReports}"> <subsection name="${descProperty}"> <p><img src="images/${varReport}.jpg" /></p> </subsection> </j:forEach> </section> </body> </document> </j:file> </u:available> </goal> </project> 1.1 maven-plugins/history/plugin.properties Index: plugin.properties =================================================================== # ------------------------------------------------------------------- # P L U G I N P R O P E R I E S # ------------------------------------------------------------------- # Default props maven.history.reports=cserrors,cswarnings,clovertpc,cloverloc,cloverncloc maven.history.duration=30 maven.history.dateformat=dd MMM maven.history.graph.width=750 maven.history.graph.height=450 # Dashboard History props maven.history.dashboard.file=${maven.src.dir}/dashboard-data-history.xml maven.history.dashboard.style= maven.history.dashboard.reports=${maven.history.reports} maven.history.dashboard.duration=${maven.history.duration} maven.history.dashboard.dateformat=${maven.history.dateformat} maven.history.dashboard.graph.width=${maven.history.graph.width} maven.history.dashboard.graph.height=${maven.history.graph.height} # Report History props maven.history.report.file=${maven.src.dir}/report-data-history.xml maven.history.report.reports=${maven.history.reports} maven.history.report.duration=${maven.history.duration} maven.history.report.dateformat=${maven.history.dateformat} maven.history.report.graph.width=${maven.history.graph.width} maven.history.report.graph.height=${maven.history.graph.height} 1.1 maven-plugins/history/project.properties Index: project.properties =================================================================== maven.license.licenseFile=${basedir}/../LICENSE.txt # WebSite definition maven.xdoc.version=${pom.currentVersion} maven.xdoc.date=left maven.ui.body.background=white maven.ui.body.foreground=black maven.ui.banner.background=white 1.1 maven-plugins/history/project.xml Index: project.xml =================================================================== <?xml version="1.0" encoding="ISO-8859-1"?> <project> <extend>${basedir}/plugin-project.xml</extend> <id>maven-history-plugin</id> <name>Maven History Plugin</name> <currentVersion>1.0-RC3</currentVersion> <inceptionYear>2005</inceptionYear> <description>Maven History Plugin</description> <shortDescription>Maven History Plugin</shortDescription> <siteDirectory>/home/groups/m/ma/maven-plugins/htdocs/history/</siteDirectory> <repository> <connection> scm:cvs:pserver:ano...@cv...:/cvsroot/maven-plugins:maven-plugins/history</connection> <url> http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/maven-plugins/maven-plugins/history/</url> </repository> <versions> <version> <id>1.0-RC3</id> <name>1.0-RC3</name> <tag>MAVEN_PLUGINS_HISTORY_1_0-RC3</tag> </version> </versions> <branches> </branches> <!-- mailingLists are in parent --> <dependencies> <dependency> <groupId>jfreechart</groupId> <artifactId>jfreechart</artifactId> <version>0.9.20</version> </dependency> <dependency> <groupId>jcommon</groupId> <artifactId>jcommon</artifactId> <version>0.9.5</version> </dependency> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>ant</groupId> <artifactId>ant</artifactId> <version>1.5.3-1</version> </dependency> </dependencies> <developers> <developer> <name>Morten Krisiansen</name> <id>mortenkr</id> <email>mo...@tr...</email> <roles> <role>Java Developer</role> </roles> </developer> </developers> <build/> <reports> <report>maven-javadoc-plugin</report> </reports> </project> 1.1 maven-plugins/history/src/main/org/apache/maven/history/dashboard/FileMerger.java Index: FileMerger.java =================================================================== package org.apache.maven.history.dashboard; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Iterator; import java.util.List; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.Node; import org.dom4j.io.OutputFormat; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; public class FileMerger { private String dashboardHistoryRaw = null; private String duration = null; private String dashboardRaw = null; private String mavenBuildDir = null; private String encoding = null; public void merge() throws IOException, DocumentException { Document newDocument = DocumentHelper.createDocument(); Element root = newDocument.addElement( "dashboards" ); SAXReader reader = new SAXReader(); File dashboardHistoryRawFile = new File( dashboardHistoryRaw ); if( dashboardHistoryRawFile.exists() ) { Document dashboardHistoryRawFileDoc = reader .read( new FileReader( dashboardHistoryRawFile ) ); String xpath = "//dashboard"; if( duration != null && !duration.trim().equals( "" ) ) { long fromDate = System.currentTimeMillis() - (Long.valueOf( duration ).longValue() * 86400000); xpath = xpath + "[@date > number('" + fromDate + "')]"; } List list = dashboardHistoryRawFileDoc.selectNodes( xpath ); for( Iterator iter = list.iterator(); iter.hasNext(); ) { Node node = (Node) iter.next(); root.add( node.detach() ); } } Element dashboard = root.addElement( "dashboard" ).addAttribute( "date", String.valueOf( System.currentTimeMillis() ) ); Document dashboardRawDoc = reader.read( new FileReader( dashboardRaw ) ); List list = dashboardRawDoc.selectNodes( "//project" ); for( Iterator iter = list.iterator(); iter.hasNext(); ) { Node project = (Node) iter.next(); dashboard.add( project.detach() ); } OutputFormat format = OutputFormat.createPrettyPrint(); if( encoding != null && !encoding.trim().equals( "" ) ) { format.setEncoding( encoding ); format.setOmitEncoding( false ); } XMLWriter writer = new XMLWriter( new FileWriter( dashboardHistoryRaw, false ), format ); writer.write( newDocument ); writer.close(); } public String getDashboardHistoryRaw() { return dashboardHistoryRaw; } public void setDashboardHistoryRaw( String dashboardHistoryRaw ) { this.dashboardHistoryRaw = dashboardHistoryRaw; } public String getDashboardRaw() { return dashboardRaw; } public void setDashboardRaw( String dashboardRaw ) { this.dashboardRaw = dashboardRaw; } public String getDuration() { return duration; } public void setDuration( String duration ) { this.duration = duration; } public String getEncoding() { return encoding; } public void setEncoding( String encoding ) { this.encoding = encoding; } public String getMavenBuildDir() { return mavenBuildDir; } public void setMavenBuildDir( String mavenBuildDir ) { this.mavenBuildDir = mavenBuildDir; } } 1.1 maven-plugins/history/src/main/org/apache/maven/history/dashboard/PlotterTask.java Index: PlotterTask.java =================================================================== package org.apache.maven.history.dashboard; import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.data.time.Millisecond; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; /** * <class description> * * @author <a href="mailto:mo...@tr...">Morten Kristiansen </a> */ public class PlotterTask extends Task { private static final int AGGREGATE = 1; private static final int SINGLE = 2; private static final int GROUP = 3; private List all = new ArrayList(); private List groups = new ArrayList(); private int style = -1; private String myHistorySrc = ""; private String myDateformat = ""; private String myImageDest = ""; private String myWidth = ""; private String myHeight = ""; private String myStyle = ""; /** * @throws org.apache.tools.ant.BuildException */ public void execute() throws BuildException { try { parseHistoryFile(); } catch( Throwable t ) { log( "Error parsing history file " + myHistorySrc + ": " + t.getMessage() ); return; } if( myStyle == null || myStyle.trim().equals( "" ) ) { style = AGGREGATE; } else if( myStyle.trim().equals( "single" ) ) { style = SINGLE; } else { style = GROUP; StringTokenizer tokens = new StringTokenizer( myStyle.trim(), "," ); while( tokens.hasMoreTokens() ) { groups.add( tokens.nextToken() ); } } try { Map aggrData = new HashMap(); for( Iterator iter = all.iterator(); iter.hasNext(); ) { Report reportData = (Report) iter.next(); String reportName = reportData.myReport; String projectName = reportData.myProjectName; if( style == SINGLE ) { reportName = reportName + "-" + projectName; } else { if( style == GROUP ) { String groupName = getGroup( projectName ); if( groupName == null ) { // If project not in group, filter out! continue; } reportName = reportName + "-" + groupName; } } TimeSeriesCollection dataset = new TimeSeriesCollection(); if( aggrData.containsKey( reportName ) ) { dataset = (TimeSeriesCollection) aggrData.get( reportName ); } TimeSeries data = dataset.getSeries( projectName ); if( data == null ) { data = new TimeSeries( projectName, Millisecond.class ); dataset.addSeries( data ); } try { data.add( new Millisecond( new Date( reportData.myTime ) ), reportData.myNumber ); } catch( Throwable t ) { log( "Error when adding data for reportName='" + reportName + "', projectName='" + projectName + "', time='" + reportData.myTime + "'. Trying addOrUpdate. Exception:" + t.getMessage(), Project.MSG_WARN ); try { data.addOrUpdate( new Millisecond( new Date( reportData.myTime ) ), reportData.myNumber ); } catch( Throwable t2 ) { log( "Failed again; skipping data. Exception: " + t.getMessage(), Project.MSG_WARN ); } } aggrData.put( reportName, dataset ); } for( Iterator iter = aggrData.keySet().iterator(); iter.hasNext(); ) { String reportName = (String) iter.next(); TimeSeriesCollection dataset = (TimeSeriesCollection) aggrData.get( reportName ); JFreeChart chart = ChartFactory.createTimeSeriesChart( getHeader( reportName ), "Date", "Value", dataset, true, true, false ); XYPlot plot = chart.getXYPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride( new SimpleDateFormat( myDateformat ) ); log( "Plotting image for " + reportName ); ChartUtilities.saveChartAsJPEG( new java.io.File( myImageDest + "/" + reportName + ".jpg" ), chart, Integer.parseInt( myWidth ), Integer.parseInt( myHeight ) ); } } catch( Throwable t ) { log( "Error when plotting jpg: " + t.getMessage() ); } } private String getHeader( String reportName ) { if( style != AGGREGATE ) { return reportName.substring( 0, reportName.indexOf( "-" ) ); } else { return reportName; } } private String getGroup( String projectName ) { for( Iterator iter = groups.iterator(); iter.hasNext(); ) { String group = (String) iter.next(); if( projectName.startsWith( group ) ) { return group; } } return null; } private void parseHistoryFile() throws Throwable { File file = new File( myHistorySrc ); SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); log( "Parsing dashboard history file: " + file.getAbsolutePath() ); ReportHandler handler = new ReportHandler(); parser.parse( file, handler ); all = handler.getResult(); } /** * @return */ public String getDateformat() { return myDateformat; } /** * @return */ public String getHistorySrc() { return myHistorySrc; } /** * @return */ public String getImageDest() { return myImageDest; } /** * @param string */ public void setDateformat( String string ) { myDateformat = string; } /** * @param string */ public void setHistorySrc( String string ) { myHistorySrc = string; } /** * @param string */ public void setImageDest( String string ) { myImageDest = string; } /** * @return */ public String getHeight() { return myHeight; } /** * @return */ public String getWidth() { return myWidth; } /** * @param string */ public void setHeight( String string ) { myHeight = string; } /** * @param string */ public void setWidth( String string ) { myWidth = string; } public String getStyle() { return myStyle; } public void setStyle( String style ) { myStyle = style; } } 1.1 maven-plugins/history/src/main/org/apache/maven/history/dashboard/Report.java Index: Report.java =================================================================== package org.apache.maven.history.dashboard; /** * <class description> * * @author <a href="mailto:mo...@tr...">Morten Kristiansen </a> */ public class Report { String myProjectName = ""; String myReport = ""; long myTime = -1; double myNumber = 0; } 1.1 maven-plugins/history/src/main/org/apache/maven/history/dashboard/ReportHandler.java Index: ReportHandler.java =================================================================== package org.apache.maven.history.dashboard; import java.util.ArrayList; import java.util.List; import org.xml.sax.Attributes; import org.xml.sax.helpers.DefaultHandler; public class ReportHandler extends DefaultHandler { private List all = new ArrayList(); private long currentTime = -1; private String currentProject = null; private String currentAggr = null; public void startElement(String uri, String localName, String qName, Attributes attributes) { if(qName.equals("dashboard")) { currentTime = Long.parseLong(attributes.getValue("date")); } else if(qName.equals("project")) { currentProject = attributes.getValue("artifactId"); } else if(qName.equals("aggregator")) { currentAggr = attributes.getValue("name"); } } public void characters (char ch[], int start, int length) { String tmp = new String(ch, start, length); double value = 0; try { if( tmp.endsWith( "%" ) ) { tmp = tmp.substring( 0, tmp.length() - 1 ); } value = Double.parseDouble(tmp); } catch (Throwable e) { return; } Report myCurrent = new Report(); myCurrent.myTime = currentTime; myCurrent.myProjectName = currentProject; myCurrent.myNumber = value; myCurrent.myReport = currentAggr; all.add(myCurrent); } public List getResult() { return all; } } 1.1 maven-plugins/history/src/main/org/apache/maven/history/report/FileMerger.java Index: FileMerger.java =================================================================== package org.apache.maven.history.report; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.Node; import org.dom4j.io.OutputFormat; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; public class FileMerger { private String reportHistoryRaw = null; private String duration = null; private Map map = null; private String mavenBuildDir = null; private String encoding = null; public void merge() throws IOException, DocumentException { Document newDocument = DocumentHelper.createDocument(); Element root = newDocument.addElement( "reports" ); SAXReader reader = new SAXReader(); File reportHistoryRawFile = new File( reportHistoryRaw ); if( reportHistoryRawFile.exists() ) { Document reportHistoryRawFileDoc = reader .read( new FileReader( reportHistoryRawFile ) ); String xpath = "//date"; if( duration != null && !duration.trim().equals( "" ) ) { long fromDate = System.currentTimeMillis() - (Long.valueOf( duration ).longValue() * 86400000); xpath = xpath + "[@value > number('" + fromDate + "')]"; } List list = reportHistoryRawFileDoc.selectNodes( xpath ); for( Iterator iter = list.iterator(); iter.hasNext(); ) { Node node = (Node) iter.next(); root.add( node.detach() ); } } Element date = root.addElement( "date" ).addAttribute( "value", String.valueOf( System.currentTimeMillis() ) ); for( Iterator iter = map.keySet().iterator(); iter.hasNext(); ) { String project = (String) iter.next(); String value = (String) map.get( project ); date.addElement( "report" ).addAttribute( "name", project ).addAttribute( "value", value ); } OutputFormat format = OutputFormat.createPrettyPrint(); if( encoding != null && !encoding.trim().equals( "" ) ) { format.setEncoding( encoding ); format.setOmitEncoding( false ); } XMLWriter writer = new XMLWriter( new FileWriter( reportHistoryRaw, false ), format ); writer.write( newDocument ); writer.close(); } public String getDuration() { return duration; } public void setDuration( String duration ) { this.duration = duration; } public String getEncoding() { return encoding; } public void setEncoding( String encoding ) { this.encoding = encoding; } public String getMavenBuildDir() { return mavenBuildDir; } public void setMavenBuildDir( String mavenBuildDir ) { this.mavenBuildDir = mavenBuildDir; } public Map getMap() { return map; } public void setMap( Map map ) { this.map = map; } public String getReportHistoryRaw() { return reportHistoryRaw; } public void setReportHistoryRaw( String reportHistoryRaw ) { this.reportHistoryRaw = reportHistoryRaw; } } 1.1 maven-plugins/history/src/main/org/apache/maven/history/report/PlotterTask.java Index: PlotterTask.java =================================================================== package org.apache.maven.history.report; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.data.time.Millisecond; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; /** * <class description> * * @author <a href="mailto:mo...@tr...">Morten Kristiansen </a> */ public class PlotterTask extends Task { private Map result = new HashMap(); private String historySrc = null; private String dateformat = null; private String width = null; private String height = null; private String imageDest = null; /** * @throws org.apache.tools.ant.BuildException */ public void execute() throws BuildException { try { parseHistoryFile(); } catch( Throwable t ) { log( "Error parsing history file " + historySrc + ": " + t.getMessage() ); return; } try { for( Iterator iter = result.keySet().iterator(); iter.hasNext(); ) { String reportName = (String) iter.next(); List reports = (List) result.get( reportName ); TimeSeries data = new TimeSeries( reportName, Millisecond.class ); for( Iterator iter2 = reports.iterator(); iter2.hasNext(); ) { Report element = (Report) iter2.next(); data.add( new Millisecond( new Date( element.myTime ) ), element.myNumber ); } TimeSeriesCollection dataset = new TimeSeriesCollection( data ); JFreeChart chart = ChartFactory.createTimeSeriesChart( reportName, "Date", "Value", dataset, true, true, false ); XYPlot plot = chart.getXYPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride( new SimpleDateFormat( dateformat ) ); log( "Plotting image for " + reportName ); ChartUtilities.saveChartAsJPEG( new java.io.File( imageDest + "/" + reportName + ".jpg" ), chart, Integer .parseInt( width ), Integer.parseInt( height ) ); } } catch( Throwable t ) { log( "Error when plotting jpg: " + t.getMessage() ); } } private void parseHistoryFile() throws Throwable { File file = new File( historySrc ); SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); log( "Parsing history file: " + file.getAbsolutePath() ); ReportHandler handler = new ReportHandler(); parser.parse( file, handler ); result = handler.getResult(); } public String getDateformat() { return dateformat; } public void setDateformat( String dateformat ) { this.dateformat = dateformat; } public String getHeight() { return height; } public void setHeight( String height ) { this.height = height; } public String getHistorySrc() { return historySrc; } public void setHistorySrc( String historySrc ) { this.historySrc = historySrc; } public String getImageDest() { return imageDest; } public void setImageDest( String imageDest ) { this.imageDest = imageDest; } public String getWidth() { return width; } public void setWidth( String width ) { this.width = width; } } 1.1 maven-plugins/history/src/main/org/apache/maven/history/report/Report.java Index: Report.java =================================================================== package org.apache.maven.history.report; /** * <class description> * * @author <a href="mailto:mo...@tr...">Morten Kristiansen </a> */ public class Report { long myTime = -1; double myNumber = 0; } 1.1 maven-plugins/history/src/main/org/apache/maven/history/report/ReportHandler.java Index: ReportHandler.java =================================================================== package org.apache.maven.history.report; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.xml.sax.Attributes; import org.xml.sax.helpers.DefaultHandler; public class ReportHandler extends DefaultHandler { private Map result = new HashMap(); private long currentTime = -1; public void startElement(String uri, String localName, String qName, Attributes attributes) { if(qName.equals("date")) { currentTime = Long.parseLong(attributes.getValue("value")); } else if(qName.equals("report")) { String reportName = attributes.getValue("name"); List values = new ArrayList(); if( result.containsKey( reportName ) ) { values = (List) result.get( reportName ); } String reportValue = attributes.getValue("value"); double value = 0; try { if( reportValue.endsWith( "%" ) ) { reportValue = reportValue.substring( 0, reportValue.length() - 1 ); } value = Double.parseDouble(reportValue); } catch (Throwable e) { return; } Report myCurrent = new Report(); myCurrent.myTime = currentTime; myCurrent.myNumber = value; values.add(myCurrent); result.put( reportName, values ); } } public Map getResult() { return result; } } 1.1 maven-plugins/history/xdocs/goals.xml Index: goals.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <document> <properties> <title>Maven History Plugin Goals</title> </properties> <body> <goals> <goal> <name>dashboard-history:report</name> <description>Run Dashboard History report</description> </goal> <goal> <name>report-history:report</name> <description>Run Report History report</description> </goal> </goals> </body> </document> 1.1 maven-plugins/history/xdocs/index.xml Index: index.xml =================================================================== <?xml version="1.0" encoding="ISO-8859-1"?> <document> <properties> <title>Maven History Plugin</title> </properties> <body> <section name="Maven History Plugin"> <p> This plugin provides functionality for adding history reports. It supports adding history on a report basis and on a dashboard report basis. <p> For more information on the functionality provided by this plugin, please see the <a href="goals.html">Goals</a> document. </p> <p> For more information on how to customise the functionality provided by this plugin, please see the <a href="properties.html">properties</a> document. </p> <subsection name="Dashboard History"> <p> Add the following to your POMs reports section (place it after the maven-dashboard-plugin): <source> <report>maven-dashboard-history-plugin</report> </source> </p> <p> Examples (different types are specified by property <code>maven.history.dashboard.style</code>): <ul> <li>For an example of report using a pr project history, click <a href="example1/history/dashboard/dashboard-history.html">here</a>.</li> <li>For an example of report using grouped pr project history, click <a href="example2/history/dashboard/dashboard-history.html">here</a>.</li> <li>For an example of report using aggregated history, click <a href="example3/history/dashboard/dashboard-history.html">here</a>.</li> </ul> </p> </subsection> <subsection name="Report History"> <p> This report is nice to have if your project does not use dashboard. The plugin only uses dashboard plugin (aggregators) to collect history data. Add the following to your POMs reports section (place it last in list of all reports): <source> <report>maven-report-history-plugin</report> </source> </p> <p> Examples: <ul> <li>For an example of report, click <a href="example1/multiproject/dashboard-test1-java/history/report-history.html">here</a>.</li> </ul> </p> </subsection> </p> </section> </body> </document> 1.1 maven-plugins/history/xdocs/navigation.xml Index: navigation.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <project name="Maven History Plugin"> <title>Maven History Plugin</title> <body> <links> <item href="http://maven.apache.org/" name="Maven"> </item> </links> <menu name="Overview"> <item href="/goals.html" name="Goals"> </item> <item href="/properties.html" name="Properties"> </item> </menu> </body> </project> 1.1 maven-plugins/history/xdocs/properties.xml Index: properties.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <document> <properties> <title>Maven History Plugin Properties</title> </properties> <body> <section name="Maven History Plugin Settings"> <table> <tr> <th>Property</th> <th>Optional?</th> <th>Description</th> </tr> <tr><td colspan="3"><b>Default properties</b></td></tr> <tr> <td>maven.history.reports</td> <td>Yes</td> <td> <p>Which reports to collect history data for. This applies to both Report History and Dashboard History. Default value is <code>cserrors,cswarnings,clovertpc,cloverloc,cloverncloc</code>.</p> </td> </tr> <tr> <td>maven.history.duration</td> <td>Yes</td> <td> <p>When collecting history, data older then this property will be cleaned. Set to blank to never clean. Default value is <code>30</code> days.</p> </td> </tr> <tr> <td>maven.history.dateformat</td> <td>Yes</td> <td> <p>Pattern used in dates in plotted graphs. Default value is <code>dd MMM</code>.</p> </td> </tr> <tr> <td>maven.history.graph.width</td> <td>Yes</td> <td> <p>Width of plotted graph images. Default value is <code>750</code>.</p> </td> </tr> <tr> <td>maven.history.graph.height</td> <td>Yes</td> <td> <p>Height of plotted graph images. Default value is <code>450</code>.</p> </td> </tr> <tr><td colspan="3"><b>Dashboard History properties</b></td></tr> <tr> <td>maven.history.dashboard.file</td> <td>Yes</td> <td> <p>Path to file where history data is recorded. Default value is <code>${maven.src.dir}/dashboard-data-history.xml</code>.</p> </td> </tr> <tr> <td>maven.history.dashboard.style</td> <td>Yes</td> <td> <p>States how data should be displayed/plotted: <ul> <li>Blank means aggregated view (plots one graph for each aggregator, with all modules in one graph)</li> <li>'single' (plots one graph pr module pr aggregator)</li> <li> You may also comma separate groups. Given modules: web-1, web-2, java-1, java-2. Set property to 'web,java' and you will have 2 images for each aggregator: one with all 'web' modules plotted and one with all 'java' modules. </li> </ul> Default value is blank(aggregated). </p> </td> </tr> <tr> <td>maven.history.dashboard.reports</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.reports}</code>.</p> </td> </tr> <tr> <td>maven.history.dashboard.duration</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.duration}</code>.</p> </td> </tr> <tr> <td>maven.history.dashboard.dateformat</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.dateformat}</code>.</p> </td> </tr> <tr> <td>maven.history.dashboard.graph.width</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.graph.width}</code>.</p> </td> </tr> <tr> <td>maven.history.dashboard.graph.height</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.graph.height}</code>.</p> </td> </tr> <tr><td colspan="3"><b>Report History properties</b></td></tr> <tr> <td>maven.history.report.file</td> <td>Yes</td> <td> <p>Path to file where history data is recorded. Default value is <code>${maven.src.dir}/report-data-history.xml</code>.</p> </td> </tr> <tr> <td>maven.history.report.reports</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.reports}</code>.</p> </td> </tr> <tr> <td>maven.history.report.duration</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.duration}</code>.</p> </td> </tr> <tr> <td>maven.history.report.dateformat</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.dateformat}</code>.</p> </td> </tr> <tr> <td>maven.history.report.graph.width</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.graph.width}</code>.</p> </td> </tr> <tr> <td>maven.history.report.graph.height</td> <td>Yes</td> <td> <p>Default value is <code>${maven.history.graph.height}</code>.</p> </td> </tr> </table> </section> </body> </document> |