Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
[FIXED JENKINS-12801] Added column support for PMD warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Feb 20, 2012
1 parent 828311c commit c311e09
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .classpath
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="src" output="target/classes" path="target/generated-sources/localizer">
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-core</artifactId>
<version>1.36</version>
<version>1.38-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/hudson/plugins/pmd/parser/PmdParser.java
Expand Up @@ -112,6 +112,7 @@ else if (warning.getPriority() > PMD_PRIORITY_MAPPED_TO_LOW_PRIORITY) {
bug.setPackageName(warning.getPackage());
bug.setModuleName(moduleName);
bug.setFileName(file.getName());
bug.setColumnPosition(warning.getBegincolumn(), warning.getEndcolumn());

try {
bug.setContextHashCode(createContextHashCode(file.getName(), warning.getBeginline()));
Expand Down
102 changes: 16 additions & 86 deletions src/main/java/hudson/plugins/pmd/parser/Violation.java
Expand Up @@ -10,145 +10,75 @@ public class Violation {
private String rule;
/** Category of warning. */
private String ruleset;
/** Category of warning. */

private String externalInfoUrl;
/** Package of warning. */
private String javaPackage;
/** Priority of warning. */
private int priority;
/** Message of warning. */
private String message;
/** The first line of the warning range. */
private int beginline;
/** The last line of the warning range. */
private int endline;
/**
* Returns the rule.
*
* @return the rule
*/
private int begincolumn;
private int endcolumn;

public String getRule() {
return rule;
}
/**
* Sets the rule to the specified value.
*
* @param rule the value to set
*/
public void setRule(final String rule) {
this.rule = rule;
}
/**
* Returns the ruleset.
*
* @return the ruleset
*/
public String getRuleset() {
return ruleset;
}
/**
* Sets the ruleset to the specified value.
*
* @param ruleset the value to set
*/
public void setRuleset(final String ruleset) {
this.ruleset = ruleset;
}
/**
* Returns the externalInfoUrl.
*
* @return the externalInfoUrl
*/
public String getExternalInfoUrl() {
return externalInfoUrl;
}
/**
* Sets the externalInfoUrl to the specified value.
*
* @param externalInfoUrl the value to set
*/
public void setExternalInfoUrl(final String externalInfoUrl) {
this.externalInfoUrl = externalInfoUrl;
}
/**
* Returns the javaPackage.
*
* @return the javaPackage
*/
public String getPackage() {
return javaPackage;
}
/**
* Sets the javaPackage to the specified value.
*
* @param packageName the value to set
*/
public void setPackage(final String packageName) {
javaPackage = packageName;
}
/**
* Returns the priority.
*
* @return the priority
*/
public int getPriority() {
return priority;
}
/**
* Sets the priority to the specified value.
*
* @param priority the value to set
*/
public void setPriority(final int priority) {
this.priority = priority;
}
/**
* Returns the message.
*
* @return the message
*/
public String getMessage() {
return message;
}
/**
* Sets the message to the specified value.
*
* @param message the value to set
*/
public void setMessage(final String message) {
this.message = message;
}
/**
* Returns the beginline.
*
* @return the beginline
*/
public int getBeginline() {
return beginline;
}
/**
* Sets the beginline to the specified value.
*
* @param beginline the value to set
*/
public void setBeginline(final int beginline) {
this.beginline = beginline;
}
/**
* Returns the endline.
*
* @return the endline
*/
public int getEndline() {
return endline;
}
/**
* Sets the endline to the specified value.
*
* @param endline the value to set
*/
public void setEndline(final int endline) {
this.endline = endline;
}
public int getEndcolumn() {
return endcolumn;
}
public void setEndcolumn(final int endcolumn) {
this.endcolumn = endcolumn;
}
public int getBegincolumn() {
return begincolumn;
}
public void setBegincolumn(final int begincolumn) {
this.begincolumn = begincolumn;
}
}

21 changes: 20 additions & 1 deletion src/test/java/hudson/plugins/pmd/parser/PmdParserTest.java
@@ -1,6 +1,7 @@
package hudson.plugins.pmd.parser;

import static org.junit.Assert.*;
import static junit.framework.Assert.*;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.MavenModule;
import hudson.plugins.analysis.util.model.Priority;
Expand Down Expand Up @@ -40,6 +41,24 @@ private Collection<FileAnnotation> parseFile(final String fileName) throws Invoc
}
}

/**
* Parses a warning log with 15 warnings.
*
* @throws InvocationTargetException
* if the file could not be read
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-12801">Issue 12801</a>
*/
@Test
public void issue12801() throws InvocationTargetException {
String fileName = "issue12801.xml";
Collection<FileAnnotation> annotations = parseFile(fileName);

assertEquals(ERROR_MESSAGE, 2, annotations.size());
ParserResult result = new ParserResult(annotations);
assertEquals(ERROR_MESSAGE, 2, result.getNumberOfAnnotations());

}

/**
* Checks whether we correctly detect all 669 warnings.
*
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/hudson/plugins/pmd/parser/issue12801.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<pmd version="4.1" timestamp="2008-03-18T22:17:01.031">
<file name="C:\Build\Results\jobs\ADT-Base\workspace\com.avaloq.adt.ui\src\main\java\com\avaloq\adt\env\internal\ui\actions\CopyToClipboard.java">
<violation beginline="216" endline="216" begincolumn="32" endcolumn="46" rule="CompareObjectsWithEquals" ruleset="Design Rules" package="com.myapplication.util.collections" class="SingleSet$SingleSetIterator" method="hasNext" externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#CompareObjectsWithEquals" priority="3">
Use equals() to compare object references.
</violation>
<violation beginline="216" endline="216" begincolumn="51" endcolumn="65" rule="CompareObjectsWithEquals" ruleset="Design Rules" package="com.myapplication.util.collections" class="SingleSet$SingleSetIterator" method="hasNext" externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#CompareObjectsWithEquals" priority="3">
Use equals() to compare object references.
</violation>
</file>
</pmd>

0 comments on commit c311e09

Please sign in to comment.