`
julylin
  • 浏览: 49550 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

CruiseControl中添加FindBugs的总结报告和结果标签

阅读更多
相关资料:http://confluence.public.thoughtworks.org/display/CC/Home
1:在X:\cruisecontrol-bin-2.8.4\webapps\cruisecontrol目录的main.jsp中添加:
<cruisecontrol:tabsheet>

              <cruisecontrol:tab name="buildResults" label="Build Results" >
                <%@ include file="buildresults.jsp" %>
              </cruisecontrol:tab>

			  <cruisecontrol:tab name="findbugs" label="FindBugs" >
					 <%@ include file="findbugs.jsp" %>
			  </cruisecontrol:tab>


2:新建findbugs.jsp文件
<%@ taglib uri="/WEB-INF/cruisecontrol-jsp11.tld" prefix="cruisecontrol"%>
<cruisecontrol:xsl xslFile="/xsl/findbugs-details.xsl"/>


3:在cruisecontrol.css添加格式信息:
.findbugs-oddrow { background-color:#CCCCCC }
.findbugs-data { font-family:arial,helvetica,sans-serif; font-size:8pt; color:#000000; }
.findbugs-sectionheader { background-color:#000066; font-family:arial,helvetica,sans-serif; font-size:10pt; 

color:#FFFFFF; }
.findbugs-tablerow0 { font-family:arial,helvetica,sans-serif; font-size:8pt; color:#000000; background-color: 

#FFFFFF; }
.findbugs-tablerow1 { font-family:arial,helvetica,sans-serif; font-size:8pt; color:#000000; background-

color:#CCCCCC; }
.findbugs-detailrow0 { font-family:arial,helvetica,sans-serif; font-size:8pt; color:#000000; background-color: 

#FFFFFF; }
.findbugs-detailrow1 { font-family:arial,helvetica,sans-serif; font-size:8pt; color:#000000; background-

color:#CCCCCC; }
.findbugs-tableheader { font-family:arial,helvetica,sans-serif; font-size:9pt; font-weight: bold; color:#000080; 

background-color:#CCDDDD; }
.findbugs-warningtable tr.findbugs-tablerow0:hover, .findbugs-warningtable tr.findbugs-tablerow1:hover { 

background-color: #aaffaa; }
.findbugs-priority-1 { color: red; font-weight: bold; }
.findbugs-priority-2 { color: orange; font-weight: bold; }
.findbugs-priority-3 { color: green; font-weight: bold; }
.findbugs-priority-4 { color: blue; font-weight: bold; }


4:在xsl目录下创建findbugs-details.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<!--
  FindBugs - Find bugs in Java programs
  Copyright (C) 2004,2005 University of Maryland
  Copyright (C) 2005, Chris Nappin

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-->

<!--
  A simple XSLT stylesheet to transform FindBugs XML results
  annotated with messages into HTML.

  If you want to experiment with modifying this stylesheet,
  or write your own, you need to generate XML output from FindBugs
  using a special option which lets it know to include
  human-readable messages in the XML.  Invoke the findbugs script
  as follows:

    findbugs -textui -xml:withMessages -project myProject.fb > results.xml

  Then you can use your favorite XSLT implementation to transform
  the XML output into HTML. (But don't use xsltproc. It generates well-nigh
  unreadable output, and generates incorrect output for the
  <script> element.)

  Authors:
  David Hovemeyer
  Chris Nappin (summary table)
  Nicholas Cull (adapted for CruiseControl)
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="html" />

<xsl:template match="/">
	<xsl:apply-templates select="." mode="findbugs"/>
</xsl:template>

<xsl:template match="/" mode="findbugs">
	<xsl:variable name="unique-catkey" select="/cruisecontrol/BugCollection/BugCategory/@category"/>

	<script type="text/javascript">
		function toggleRow(elid) {
			if (document.getElementById) {
				element = document.getElementById(elid);
				if (element) {
					if (element.style.display == 'none') {
						element.style.display = 'block';
						//window.status = 'Toggle on!';
					} else {
						element.style.display = 'none';
						//window.status = 'Toggle off!';
					}
				}
			}
		}
	</script>

	<xsl:if test="count(cruisecontrol/BugCollection) = 0">
		FindBugs was not run against this project.
	</xsl:if>

	<xsl:if test="count(cruisecontrol/BugCollection) &gt; 0">
	<table class="header" align="center" border="0" cellpadding="8" cellspacing="0" width="98%">
		<tr>
			<th class="big">FindBugs Report</th>
		</tr>
	</table>

	<table align="center" cellpadding="8" cellspacing="0" border="0" width="98%">
		<tr>
			<td class="findbugs-sectionheader">Metrics</td>
		</tr>
		<xsl:apply-templates select="/cruisecontrol/BugCollection/FindBugsSummary" mode="findbugs"/>
		<tr>
			<td>&#160;</td>
		</tr>
		<tr>
			<td class="findbugs-sectionheader">Summary</td>
		</tr>
		<tr>
			<td>

	<table width="500" cellpadding="5" cellspacing="2">
		<tr class="findbugs-tableheader">
			<th align="left">Warning Type</th>
			<th align="right">Number</th>
		</tr>

		<xsl:for-each select="$unique-catkey">
			<xsl:sort select="." order="ascending"/>
			<xsl:variable name="catkey" select="."/>
			<xsl:variable name="catdesc" select="/cruisecontrol/BugCollection/BugCategory

[@category=$catkey]/Description"/>
			<xsl:variable name="styleclass">
				<xsl:choose>
					<xsl:when test="position() mod 2 = 1">findbugs-tablerow0</xsl:when>
					<xsl:otherwise>findbugs-tablerow1</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>

			<tr class="{$styleclass}">
				<td><xsl:value-of select="$catdesc"/> Warnings</td>
				<td align="right"><xsl:value-of select="count

(/cruisecontrol/BugCollection/BugInstance[@category=$catkey])"/></td>
			</tr>
		</xsl:for-each>

		<xsl:variable name="styleclass">
			<xsl:choose>
				<xsl:when test="count($unique-catkey) mod 2 = 0">findbugs-tablerow0</xsl:when>
				<xsl:otherwise>findbugs-tablerow1</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<tr class="{$styleclass}">
			<td><b>Total</b></td>
			<td align="right"><b><xsl:value-of select="count

(/cruisecontrol/BugCollection/BugInstance)"/></b></td>
		</tr>
	</table>

			</td>
		</tr>
		<tr>
			<td>&#160;</td>
		</tr>
		<tr>
			<td class="findbugs-sectionheader">Warnings</td>
		</tr>
		<tr class="findbugs-tablerow0">
			<td>Click on a warning row to see full context information.</td>
		</tr>
		<tr>
			<td>

	<table align="center" cellpadding="8" cellspacing="0" border="0" width="98%">
		<xsl:for-each select="$unique-catkey">
			<xsl:sort select="." order="ascending"/>
			<xsl:variable name="catkey" select="."/>
			<xsl:variable name="catdesc" select="/cruisecontrol/BugCollection/BugCategory

[@category=$catkey]/Description"/>

			<xsl:call-template name="generateWarningTable">
				<xsl:with-param name="warningSet" select="/cruisecontrol/BugCollection/BugInstance

[@category=$catkey]"/>
				<xsl:with-param name="sectionTitle"><xsl:value-of select="$catdesc"/> 

Warnings</xsl:with-param>
				<xsl:with-param name="sectionId">Warnings_<xsl:value-of 

select="$catkey"/></xsl:with-param>
			</xsl:call-template>
		</xsl:for-each>
	</table>

			</td>
		</tr>
		<tr>
			<td>&#160;</td>
		</tr>
		<tr>
			<td class="findbugs-sectionheader"><a name="Details">Details</a></td>
		</tr>
		<xsl:apply-templates select="/cruisecontrol/BugCollection/BugPattern" mode="findbugs">
			<xsl:sort select="@abbrev"/>
			<xsl:sort select="ShortDescription"/>
		</xsl:apply-templates>
		<tr>
			<td>&#160;</td>
		</tr>
	</table>
	</xsl:if>
</xsl:template>

<xsl:template match="BugInstance" mode="findbugs">
	<xsl:variable name="warningId"><xsl:value-of select="generate-id()"/></xsl:variable>

	<tr class="findbugs-tablerow{position() mod 2}" onclick="toggleRow('{$warningId}');">
		<td>
			<span>
				<xsl:attribute name="class">findbugs-priority-<xsl:value-of 

select="@priority"/></xsl:attribute>
				<xsl:value-of select="@abbrev"/>
			</span>
		</td>
		<td>
			<xsl:value-of select="LongMessage"/>
		</td>
	</tr>

	<!-- Add bug annotation elements: Class, Method, Field, SourceLine, Field -->
	<tr class="findbugs-detailrow{position() mod 2}">
		<td/>
		<td>
			<p id="{$warningId}" style="display: none;">
				Bug type <xsl:value-of select="@type"/>
				<xsl:for-each select="./*/Message">
					<br/><xsl:value-of select="text()" disable-output-escaping="no"/>
				</xsl:for-each>
			</p>
		</td>
	</tr>
</xsl:template>

<xsl:template match="BugPattern" mode="findbugs">
	<tr>
		<td>
			<table width="100%" cellspacing="0">
				<tr class="findbugs-tableheader">
					<td><a name="{@type}"><xsl:value-of select="@type"/>: <xsl:value-of 

select="ShortDescription"/></a></td>
				</tr>
				<tr>
					<td class="findbugs-tablerow0">
						<xsl:value-of select="Details" disable-output-escaping="yes"/>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</xsl:template>

<xsl:template name="generateWarningTable">
	<xsl:param name="warningSet"/>
	<xsl:param name="sectionTitle"/>
	<xsl:param name="sectionId"/>

	<tr>
		<td class="findbugs-sectionheader">
			<a name="{$sectionId}"><xsl:value-of select="$sectionTitle"/></a>
		</td>
	</tr>
	<tr>
		<td>

	<table class="findbugs-warningtable" width="100%" cellspacing="0">
		<tr class="findbugs-tableheader">
			<th align="left">Code&#160;</th>
			<th align="left">Warning</th>
		</tr>
		<xsl:apply-templates select="$warningSet" mode="findbugs">
			<xsl:sort select="@abbrev"/>
			<xsl:sort select="Class/@classname"/>
		</xsl:apply-templates>
	</table>

		</td>
	</tr>
</xsl:template>

<xsl:template match="FindBugsSummary" mode="findbugs">
	<xsl:variable name="kloc" select="@total_size div 1000.0"/>
	<xsl:variable name="format" select="'#######0.00'"/>

	<tr class="findbugs-tablerow0">
		<td>
			<xsl:value-of select="@total_size"/> lines of code analysed,
			in <xsl:value-of select="@total_classes"/> classes,
			in <xsl:value-of select="@num_packages"/> packages.
		</td>
	</tr>
	<tr>
		<td>

	<table width="500" cellpadding="5" cellspacing="2">
		<tr class="findbugs-tableheader">
			<th align="left">Metric</th>
			<th align="right">Total</th>
			<th align="right">Density*</th>
		</tr>
		<tr class="findbugs-tablerow0">
			<td>High Priority Warnings</td>
			<td align="right"><xsl:value-of select="@priority_1"/></td>
			<td align="right"><xsl:value-of select="format-number(@priority_1 div $kloc, 

$format)"/></td>
		</tr>
		<tr class="findbugs-tablerow1">
			<td>Medium Priority Warnings</td>
			<td align="right"><xsl:value-of select="@priority_2"/></td>
			<td align="right"><xsl:value-of select="format-number(@priority_2 div $kloc, 

$format)"/></td>
		</tr>

		<xsl:if test="@priority_3">
			<tr class="findbugs-tablerow0">
				<td>Low Priority Warnings</td>
				<td align="right"><xsl:value-of select="@priority_3"/></td>
				<td align="right"><xsl:value-of select="format-number(@priority_3 div $kloc, 

$format)"/></td>
			</tr>
		</xsl:if>

		<xsl:variable name="totalClass">
			<xsl:choose>
				<xsl:when test="@priority_3"><xsl:text>findbugs-tablerow1</xsl:text></xsl:when>
				<xsl:otherwise><xsl:text>findbugs-tablerow0</xsl:text></xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<tr class="{$totalClass}">
			<td><b>Total Warnings</b></td>
			<td align="right"><b><xsl:value-of select="@total_bugs"/></b></td>
			<td align="right"><b><xsl:value-of select="format-number(@total_bugs div $kloc, 

$format)"/></b></td>
		</tr>
	</table>

		</td>
	</tr>
	<tr class="findbugs-tablerow0">
		<td><i>(* Defects per Thousand lines of non-commenting source statements)</i></td>
	</tr>
</xsl:template>

</xsl:stylesheet>


5:在buildresults.xsl中修改下面这两段 分别是findbugs的总结报告和结果标签:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:import href="maven.xsl"/>
  <xsl:import href="nant.xsl"/>
  <xsl:import href="checkstyle.xsl"/>
  <xsl:import href="pmd.xsl"/>
  <xsl:import href="findbugs.xsl"/>
.
.
.
  <xsl:template match="/">
    <p><xsl:apply-templates select="$cruisecontrol.list" mode="maven"/></p>
    <p><xsl:apply-templates select="$cruisecontrol.list" mode="nant"/></p>
    <p><xsl:apply-templates select="$cruisecontrol.list" mode="checkstyle"/></p>
    <p><xsl:apply-templates select="$cruisecontrol.list" mode="pmd"/></p>
    <p><xsl:apply-templates select="$cruisecontrol.list" mode="findbugs"/></p>
.


6:在xsl文件夹下创建findbugs.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>

    <!-- Any FindBugs error with a priority below this threshold are considered
         warnings and not errors
    -->
    <xsl:param name="findbugs.warning.threshold" select="3"/>

    <xsl:template match="/" mode="findbugs">
		<xsl:apply-templates select="/cruisecontrol/BugCollection" mode="findbugs"/>
    </xsl:template>

    <xsl:template match="BugCollection" mode="findbugs">
        <xsl:variable name="total.error.count" select="count(BugInstance[@priority &lt; 

$findbugs.warning.threshold])" />
        <xsl:variable name="total.warning.count" select="count(BugInstance)" />
        <table align="center" cellpadding="2" cellspacing="0" border="0" width="98%">
          <colgroup>
              <col width="45%"></col>
              <col width="5%"></col>
              <col width="50%"></col>
          </colgroup>
          <tr>
            <td class="findbugs-sectionheader" colspan="3">
                FindBugs errors/warnings (<xsl:value-of select="$total.error.count"/>
                / <xsl:value-of select="$total.warning.count"/>)
            </td>
          </tr>
            <xsl:for-each select="BugInstance">
              <tr>
                <xsl:if test="position() mod 2 = 1">
                  <xsl:attribute name="class">findbugs-oddrow</xsl:attribute>
                </xsl:if>
                <td class="findbugs-data"><xsl:value-of select="Class/@classname" /></td>
                <td class="findbugs-data" align="right"><xsl:value-of select="SourceLine[1]/@start" /></td>
                <td class="findbugs-data"><xsl:value-of select="ShortMessage/text()" /></td>
              </tr>
            </xsl:for-each>
        </table>
    </xsl:template>

    <xsl:template match="*" mode="findbugs"/>

    <xsl:template match="/">
        <xsl:apply-templates select="." mode="findbugs"/>
    </xsl:template>
</xsl:stylesheet>


7:编辑metrics.jsp页面添加findbugs统计图表:
<jsp:useBean id="xpathData" class="net.sourceforge.cruisecontrol.chart.XPathChartData" />
<%
    xpathData.add("CheckStyle", "count(/cruisecontrol/checkstyle/file/error)");
    xpathData.add("PMD", "count(/cruisecontrol/pmd/file/violation)");
    xpathData.add("FindBugs", "count(/cruisecontrol/BugCollection/BugInstance)");
    xpathData.add("Javadoc", "count(/cruisecontrol/build//target/task[@name='javadoc']/message[@priority='warn' or 

@priority='error'])");
%>
分享到:
评论

相关推荐

    [CruiseControl]binary安装和启动

    - **启动脚本**:`cruisecontrol.bat` 和 `cruisecontrol.sh` 脚本用于启动 CruiseControl 服务。它们会调用 `config.xml` 和 `dashboard-config.xml` 文件中的配置信息。 - **SSH 支持**:如果使用基于 SSH 的 CVS ...

    cruisecontrol配置定时运行

    在`cruisecontrol.xml`文件中,添加以下配置来设置每小时运行一次的定时任务: ```xml &lt;interval&gt;3600000&lt;/interval&gt; &lt;!-- 每1小时运行一次,单位为毫秒 --&gt; ... ``` 这里,`interval`属性定义了两次...

    cruisecontrol配置文件.rar

    总结来说,"cruisecontrol配置文件.rar" 包含了CruiseControl运行所需的关键组件:`main.jsp` 提供用户友好的Web界面,`build.xml` 定义了构建流程,而`config.xml` 是整个系统的灵魂,控制着CruiseControl的行为。...

    CruiseControl简介及使用举例

    在命令行中执行`cruisecontrol.bat`后,程序会进入监听状态,并生成构建结果,这些结果通常保存在`artifacts`目录下。 CruiseControl还提供了Web界面,通过访问`http://127.0.0.1:8080/`可以查看构建状态和项目信息...

    CruiseControl使用总结

    **CruiseControl 使用总结** CruiseControl 是一个开源的持续集成工具,主要用于自动化软件构建、测试和部署过程。它的核心理念是通过频繁地构建项目,及时发现并解决代码中的问题,从而提高软件开发效率和质量。这...

    持续集成之CruiseControl.rb

    **持续集成之CruiseControl.rb**...总结来说,CruiseControl.rb是一款针对Ruby开发的强大持续集成工具,它通过自动化构建和测试过程,提高了团队协作效率和软件质量。对于Ruby开发者来说,它是实现持续集成的得力助手。

    cruisecontrol+maven2配置

    - **配置文件修改**:在`%CruiseControl_Home%/config.xml`中,定义了CruiseControl的核心配置,包括项目名称、监听器、启动程序、修改集、调度、日志记录和发布者等。例如: - `&lt;property&gt;`标签用于设置环境变量。...

    CruiseControl使用指南.rar

    6. **向CruiseControl中加入新项目**:"CruiseControl step by step(3)"部分可能详细介绍了如何添加新的项目到CruiseControl服务器,包括项目配置文件的修改和项目构建规则的设定。 7. **了解CruiseControl的配置...

    持续集成及CruiseControl技术交流

    主题:持续集成及CruiseControl技术交流 在提升软件质量、降低研发风险、拒绝浪费方面,处于敏捷实践领域的持续集成(Continuous Integration,CI)起到重要作用。持续集成能够解决研发工作中的80%任务(日常),...

    利用CruiseControl软件进行持续集成

    CruiseControl是一种持续集成框架,提供了邮件通知、ANT和各种源码控制工具的插件,并提供了Web接口,用于查看当前和以前的build结果。CruiseControl系统的架构图中,我们可以看到,CruiseControl系统的主体是Build ...

    pyant及Cruisecontrol中的试用

    【标题】"pyant及Cruisecontrol中的试用"涉及到的是两个重要的持续集成工具——PyAnt和CruiseControl,它们在Python开发环境中扮演着关键角色。 PyAnt是Apache Ant的一个扩展,Ant是Java世界中广泛使用的构建工具,...

    CruiseControl.NET

    CruiseControl.NET 是 .NET...CruiseControl是一个针对持续构建程序(项目持续集成)的框架,它包括一个email通知的插件,Ant和各种各样的CVS工具。CruiseControl提供了一个Web接口, 可随时查看当前的编译状况和历史状况。

    CruiseControl学习教程.pdf

    每次提交后,CruiseControl会自动触发构建,构建结果会实时显示在Web界面中。 1.7 总结 CruiseControl的使用可以帮助团队保持代码的持续集成,及时发现并解决问题,提高软件开发的效率和质量。通过熟悉其架构、配置...

    CruiseControl-2.8.4.exe

    CruiseControl-2.8.4.exe

    cruisecontrol简介

    cruisecontrol简介

    CruiseControl笔记

    CruiseControl.net是一种流行的持续集成(CI)工具,它可以帮助软件团队自动构建、测试和部署代码,从而提高开发效率和软件质量。本篇文章将围绕CruiseControl.net的配置进行详细介绍。 #### 二、配置文件ccnet....

    CruiseControl及ant配置

    通过本文档,我们可以了解到CruiseControl和Ant在持续集成中的应用。CruiseControl作为一个强大的CI工具,可以帮助团队自动化构建流程,提高软件开发效率。而Ant作为构建工具,则负责具体的构建任务执行。两者结合...

Global site tag (gtag.js) - Google Analytics