Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking on FxCop results in Jenkins Violations plugin leads to blank page

Tags:

jenkins

fxcop

I have a Jenkins job where I specify something like the following FxCop command:

FxCopCmd.exe"/file:"test.dll" /out:"FxCop_Output.xml" /ignoregeneratedcode /project:"C:\Jenkins\extra\Modified_Rules.FxCop" /s /searchgac

When the Jenkins job is run it finds a number of code violations, and displays a graph as well as a list of file names with the number of violations in the file. However, if I click on a non-C-Sharp file, I get taken to a page with an exclamation point in a red triangle, however there is no code displayed, nor is there a list of FxCop errors.

http://i.stack.imgur.com/VNKF6.jpg

Is there some sort of FxCop configuration I'm missing? How can I get the Violations plugin to display the code violations for these files?

like image 586
jeff_hughes Avatar asked Apr 09 '13 14:04

jeff_hughes


1 Answers

I ended up downloading and modifying the Violations plugin code to display a table of violations for files that do not have source code and then recompiling the Violations plugin (and manually loading my modified plugin into Jenkins).

The filename was also not showing up as you can see by my original screen shot, the "getFileNameAlt" function just properly gets the name and the "File: ${it.fileNameAlt}" line in the jelly script below displays it (see link to screenshot below).

I added the following to ~\violations\src\main\java\hudson\plugins\violations\render\FileModelProxy.java, to render the table:

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();
}

And then updated the ~\violations\target\classes\hudson\plugins\violations\render\FileModelProxy\index.jelly file adding it just above the code that would display the violations within the source code (which was working for me), it is the "" summary line below:

<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>

Finally I played with the style.css file a little, adding a table style definition called "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;
}

The picture below shows the resulting table for a file that does not have source code. In my case the file does not end in ".cs"

http://i.stack.imgur.com/StChP.jpg

like image 103
jeff_hughes Avatar answered Oct 11 '22 18:10

jeff_hughes