我有一个Jenkins工作,我指定类似下面的FxCop命令:
FxCopCmd.exe"/file:"test.dll" /out:"FxCop_Output.xml" /ignoregeneratedcode /project:"C:\Jenkins\extra\Modified_Rules.FxCop" /s /searchgac
Run Code Online (Sandbox Code Playgroud)
运行Jenkins作业时,它会发现许多代码违规,并显示一个图表以及文件名列表,其中包含文件中的违规次数.但是,如果我点击非C-Sharp文件,我会被带到一个红色三角形中带有感叹号的页面,但是没有显示代码,也没有FxCop错误列表.
http://i.stack.imgur.com/VNKF6.jpg
我缺少某种FxCop配置吗?如何让Violations插件显示这些文件的代码违规?
我最终下载并修改了 Violations 插件代码,以显示没有源代码的文件的违规表,然后重新编译 Violations 插件(并手动将修改后的插件加载到 Jenkins 中)。
文件名也没有显示,正如您在我的原始屏幕截图中看到的那样,“getFileNameAlt”函数只是正确获取名称,并且下面的果冻脚本中的“File:$ {it.fileNameAlt}”行显示它(请参阅链接截图如下)。
我将以下内容添加到 ~\violations\src\main\java\hudson\plugins\violations\render\FileModelProxy.java 中,以呈现表:
public String getFileNameAlt() {
return new File(fileModel.getDisplayName()).getName();
}
public String getSummaryTable() {
StringBuilder gst = new StringBuilder();
int count = 0;
gst.append(" <table class='violations' width='100%'>\n");
gst.append(" <tr>\n");
gst.append(" <td class='violations-header'> # </td>\n");
gst.append(" <td class='violations-header'> Type </td>\n");
gst.append(" <td class='violations-header'> Class</td>\n");
gst.append(" <td class='violations-header'> Message</td>\n");
gst.append(" <td class='violations-header'> Description</td>\n");
gst.append(" </tr>\n");
Set<Violation> violations = fileModel.getLineViolationMap().get(0);
for (Violation v: violations) {
++count;
gst.append(" <tr>\n");
gst.append(" <td class='violations'>");
gst.append(count);
gst.append("</td>\n");
gst.append(" <td class='violations'>");
gst.append(v.getType());
gst.append("</td>\n");
gst.append(" <td class='violations'>");
gst.append(v.getSource());
gst.append("</td>\n");
gst.append(" <td class='violations'>");
gst.append(v.getMessage());
gst.append("</td>\n");
gst.append(" <td class='violations'>");
gst.append(v.getPopupMessage());
gst.append("</td>\n");
gst.append(" </tr>\n");
}
//}
gst.append(" </table>\n");
gst.append("<p><br>\n");
gst.append("<h3>Total Number of violations: \n");
gst.append(count);
gst.append("</h3><p>\n");
return gst.toString();
}
Run Code Online (Sandbox Code Playgroud)
然后更新了 ~\violations\target\classes\hudson\plugins\violations\render\FileModelProxy\index.jelly 文件,将其添加到显示源代码中的违规行为的代码上方(这对我有用),它是下面的“”摘要行:
<j:set
var="iconDir"
value="${rootURL}/plugin/violations/images/16x16"/>
<j:set var="href" value="${it.showLines}"/>
<h1><img src="${image}"/> File: ${it.fileNameAlt}</h1>
<j:out value="${it.summaryTable}"/>
<j:forEach var="t" items="${model.typeMap.entrySet()}">
<table class="pane">
<tbody>
<tr><td class="pane-header" colspan="5"><j:out value="${it.typeLine(t.key)}"/></td></tr>
<j:forEach var="v" items="${t.value}">
<tr>
<td class="pane">
<j:if test="${href}">
<a href="#line${v.line}">${v.line}</a>
</j:if>
<j:if test="${!href}">
${v.line}
</j:if>
</td>
<!--<td class="pane">${v.source}</td> -->
<td class="pane"><j:out value="${it.severityColumn(v)}"/></td>
<td class="pane" width="99%">${v.message}</td>
</tr>
</j:forEach>
</tbody>
</table>
<p></p>
</j:forEach>
Run Code Online (Sandbox Code Playgroud)
最后我稍微研究了一下 style.css 文件,添加了一个名为“violations”的表格样式定义(~\violations\target\violations\css\style.css):
.violations {
margin-top: 4px;
}
.violations td {
padding: 4px 4px 3px 4px;
}
table.violations {
width: 100%;
border-collapse: collapse;
border: 1px #bbb solid;
}
table.violations > tbody > tr > td:last-child {
border-right: 1px #bbb solid;
}
td.violations {
border: 1px #bbb solid;
padding: 3px 4px 3px 4px;
vertical-align: middle;
}
td.violations-header {
border: 1px #bbb solid;
border-right: none;
border-left: none;
background-color: #f0f0f0;
font-weight: bold;
}
th.violations {
border: 1px #bbb solid;
font-weight: bold;
}
Run Code Online (Sandbox Code Playgroud)
下图显示了没有源代码的文件的结果表。就我而言,文件不以“.cs”结尾
https://i.stack.imgur.com/StChP.jpg
| 归档时间: |
|
| 查看次数: |
2334 次 |
| 最近记录: |