Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-19122] Parse and set column of Checkstyle warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Aug 9, 2013
1 parent d67d52e commit eb83c50
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-core</artifactId>
<version>1.50</version>
<version>1.51</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
@@ -1,10 +1,5 @@
package hudson.plugins.checkstyle.parser;

import hudson.plugins.analysis.core.AbstractAnnotationParser;
import hudson.plugins.analysis.util.PackageDetectors;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.Priority;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand All @@ -16,6 +11,11 @@
import org.apache.commons.lang.StringUtils;
import org.xml.sax.SAXException;

import hudson.plugins.analysis.core.AbstractAnnotationParser;
import hudson.plugins.analysis.util.PackageDetectors;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.Priority;

/**
* A parser for Checkstyle XML files.
*
Expand Down Expand Up @@ -117,6 +117,7 @@ else if ("info".equalsIgnoreCase(error.getSeverity())) {
warning.setModuleName(moduleName);
warning.setFileName(file.getName());
warning.setPackageName(packageName);
warning.setColumnPosition(error.getColumn());

try {
warning.setContextHashCode(createContextHashCode(file.getName(), error.getLine()));
Expand Down
57 changes: 11 additions & 46 deletions src/main/java/hudson/plugins/checkstyle/parser/Error.java
Expand Up @@ -5,86 +5,51 @@
*
* @author Ulli Hafner
*/
public class Error {
// CHECKSTYLE:OFF
/** Source of warning. */
@SuppressWarnings("javadoc")
public class Error {
private String source;
/** Priority of warning. */
private String severity;
/** Message of warning. */
private String message;
/** The first line of the warning range. */
private int line;
// CHECKSTYLE:ON
private int column;

public int getColumn() {
return column;
}

public void setColumn(final int column) {
this.column = column;
}

/**
* Returns the source.
*
* @return the source
*/
public String getSource() {
return source;
}

/**
* Sets the source to the specified value.
*
* @param source the value to set
*/
public void setSource(final String source) {
this.source = source;
}

/**
* Returns the severity.
*
* @return the severity
*/
public String getSeverity() {
return severity;
}

/**
* Sets the severity to the specified value.
*
* @param severity the value to set
*/
public void setSeverity(final String severity) {
this.severity = severity;
}

/**
* 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 line.
*
* @return the line
*/
public int getLine() {
return line;
}

/**
* Sets the line to the specified value.
*
* @param line the value to set
*/
public void setLine(final int line) {
this.line = line;
}
Expand Down
Expand Up @@ -8,8 +8,10 @@
import java.util.Iterator;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.junit.Test;

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 All @@ -21,7 +23,23 @@
*/
public class CheckStyleParserTest {
/**
* Tests parsing of file with Scala style warnings.
* Tests parsing of file with some warnings that are in the same line but different column.
*
* @throws InvocationTargetException Signals that an I/O exception has occurred
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-19122">Issue 19122</a>
*/
@Test
public void testColumnPositions() throws InvocationTargetException {
Collection<FileAnnotation> annotations = parse("issue19122.xml");

assertEquals("Wrong number of annotations detected.", 58, annotations.size());

ParserResult withoutDuplicates = new ParserResult(annotations);
assertEquals("Wrong number of annotations detected.", 58, withoutDuplicates.getNumberOfAnnotations());
}

/**
* Tests parsing of a file with Scala style warnings.
*
* @throws InvocationTargetException Signals that an I/O exception has occurred
* @see <a href="http://www.scalastyle.org">Scala Style Homepage</a>
Expand Down Expand Up @@ -71,7 +89,7 @@ public void analyseCheckStyleFile() throws InvocationTargetException {
"Checks that classes are designed for extension."));
assertEquals(
"Wrong message detected.",
"Die Methode 'detectPackageName' ist nicht fr Vererbung entworfen - muss abstract, final oder leer sein.",
StringEscapeUtils.escapeXml("Die Methode 'detectPackageName' ist nicht fr Vererbung entworfen - muss abstract, final oder leer sein."),
warning.getMessage());
hasChecked = true;
}
Expand Down
97 changes: 97 additions & 0 deletions src/test/resources/hudson/plugins/checkstyle/parser/issue19122.xml
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="5.0">
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \net\ssl\SSLUtil.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \net\ssl\WSBase64Util.java">
<error line="26" column="47" severity="warning" message="&apos;64&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="27" column="28" severity="warning" message="El nombre &apos;SIXTY_FOUR&apos; debe coincidir con el patrón &apos;^[a-z][a-zA-Z0-9]*$&apos;." source="com.puppycrawl.tools.checkstyle.checks.naming.StaticVariableNameCheck"/>
<error line="27" column="41" severity="warning" message="&apos;64&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="103" column="40" severity="warning" message="&apos;4&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="103" column="44" severity="warning" message="&apos;2&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="103" column="49" severity="warning" message="&apos;3&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="105" column="37" severity="warning" message="&apos;2&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="105" column="42" severity="warning" message="&apos;3&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="105" column="47" severity="warning" message="&apos;4&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="115" column="45" severity="warning" message="&apos;0xff&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="117" column="57" severity="warning" message="&apos;0xff&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="119" column="57" severity="warning" message="&apos;0xff&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="121" column="41" severity="warning" message="&apos;2&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="123" column="41" severity="warning" message="&apos;3&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="123" column="47" severity="warning" message="&apos;4&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="123" column="60" severity="warning" message="&apos;4&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="125" column="41" severity="warning" message="&apos;0xf&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="125" column="49" severity="warning" message="&apos;2&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="125" column="62" severity="warning" message="&apos;6&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="127" column="39" severity="warning" message="&apos;0x3F&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="194" column="9" severity="warning" message="La complejidad ciclomática es 17 (máxima permitida es 10)." source="com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck"/>
<error line="198" severity="warning" message="La construcción &apos;if&apos; debe usar &apos;{}&apos; (llaves)." source="com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck"/>
<error line="198" column="28" severity="warning" message="&apos;4&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="201" severity="warning" message="La construcción &apos;while&apos; debe usar &apos;{}&apos; (llaves)." source="com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck"/>
<error line="204" column="36" severity="warning" message="&apos;3&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="204" column="41" severity="warning" message="&apos;4&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="222" column="34" severity="warning" message="&apos;127&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="222" column="46" severity="warning" message="&apos;127&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="222" column="58" severity="warning" message="&apos;127&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="222" column="70" severity="warning" message="&apos;127&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="240" column="41" severity="warning" message="&apos;2&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="240" column="54" severity="warning" message="&apos;4&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="242" column="41" severity="warning" message="&apos;0xf&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="242" column="49" severity="warning" message="&apos;4&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="242" column="62" severity="warning" message="&apos;2&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="244" column="41" severity="warning" message="&apos;3&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
<error line="244" column="47" severity="warning" message="&apos;6&apos; es un número mágico." source="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"/>
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\client\DynamicClient.java">
<error line="22" column="1" severity="warning" message="Importación de un paquete ilegal - sun.net.www.protocol.https.HttpsURLConnectionImpl." source="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck"/>
<error line="123" column="16" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="145" column="16" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="166" column="16" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="188" column="16" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="210" column="16" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="234" column="16" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="266" column="21" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="348" column="35" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="375" column="35" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="402" column="35" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="431" column="35" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="463" column="9" severity="warning" message="La complejidad ciclomática es 11 (máxima permitida es 10)." source="com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck"/>
<error line="463" column="35" severity="warning" message="Más de 7 parámetros." source="com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck"/>
<error line="500" severity="warning" message="La línea es mayor de 121 caracteres." source="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"/>
<error line="717" severity="warning" message="La línea es mayor de 121 caracteres." source="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"/>
<error line="729" severity="warning" message="La línea es mayor de 121 caracteres." source="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"/>
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\client\****SOAPSimpleMessage.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\exception\****SOAPExceptionEnvelope.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\handler\****AuthenticationInjectorHandler.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\handler\****AuthenticationValidatorHandler.java">
<error line="89" column="9" severity="warning" message="La complejidad ciclomática es 11 (máxima permitida es 10)." source="com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck"/>
<error line="114" column="37" severity="warning" message="El nombre &apos;http_headers&apos; debe coincidir con el patrón &apos;^[a-z][a-zA-Z0-9]*$&apos;." source="com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck"/>
<error line="145" severity="warning" message="La línea es mayor de 121 caracteres." source="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"/>
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\server\DynamicServer.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\server\Service.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \net\ssl\SSLUtil.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \net\ssl\WSBase64Util.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\client\DynamicClient.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\client\****SOAPSimpleMessage.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\exception\****SOAPExceptionEnvelope.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\handler\****AuthenticationInjectorHandler.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\handler\****AuthenticationValidatorHandler.java">
<error line="50" severity="warning" message="Se encontraron 45 líneas duplicadas en E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\handler\****AuthenticationInjectorHandler.java, comenzando en la línea 39" source="com.puppycrawl.tools.checkstyle.checks.duplicates.StrictDuplicateCodeCheck"/>
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\server\DynamicServer.java">
</file>
<file name="E:\Service\jenkins\jobs\ -ws\workspace\ -ws\src\main\java\com\****\ \xml\ws\server\Service.java">
</file>
</checkstyle>

0 comments on commit eb83c50

Please sign in to comment.