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

Commit

Permalink
[FIXED JENKINS-38215] Detect MSBuild command line warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 3, 2017
1 parent ef518f5 commit 4834ebc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
17 changes: 11 additions & 6 deletions src/main/java/hudson/plugins/warnings/parser/MsBuildParser.java
@@ -1,14 +1,12 @@
package hudson.plugins.warnings.parser;

import java.util.regex.Matcher;
import java.io.File;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.jvnet.localizer.Localizable;

import hudson.Extension;

import hudson.plugins.analysis.util.model.Priority;

/**
Expand All @@ -21,7 +19,8 @@ public class MsBuildParser extends RegexpLineParser {
private static final long serialVersionUID = -2141974437420906595L;
static final String WARNING_TYPE = "MSBuild";
private static final String MS_BUILD_WARNING_PATTERN = ANT_TASK + "(?:\\s*\\d+>)?(?:(?:(?:(.*)\\((\\d*)(?:,(\\d+))?.*\\)|.*LINK)\\s*:|(.*):)\\s*([A-z-_]*\\s?(?:[Nn]ote|[Ii]nfo|[Ww]arning|(?:fatal\\s*)?[Ee]rror))\\s*:?\\s*([A-Za-z0-9]+)\\s*:\\s(?:\\s*([A-Za-z0-9.]+)\\s*:)?\\s*(.*?)(?: \\[([^\\]]*)[/\\\\][^\\]\\\\]+\\])?"
+ "|(.*)\\s*:.*error\\s*(LNK[0-9]+):\\s*(.*))$";
+ "|(.*)\\s*:.*error\\s*(LNK[0-9]+):\\s*(.*))"
+ "|(?:.*)Command line warning ([A-Za-z0-9]+):\\s*(.*)\\s*\\[(.*)\\]" + "$";

/**
* Creates a new instance of {@link MsBuildParser}.
Expand Down Expand Up @@ -49,7 +48,10 @@ public MsBuildParser(final Localizable parserName, final Localizable linkName, f
@Override
protected Warning createWarning(final Matcher matcher) {
String fileName = determineFileName(matcher);
if (StringUtils.isNotBlank(matcher.group(10))) {
if (StringUtils.isNotBlank(matcher.group(13))) {
return createWarning(fileName, 0, matcher.group(13), matcher.group(14), Priority.NORMAL);
}
else if (StringUtils.isNotBlank(matcher.group(10))) {
return createWarning(fileName, 0, matcher.group(11), matcher.group(12), Priority.HIGH);
}
else {
Expand Down Expand Up @@ -80,7 +82,10 @@ protected Warning createWarning(final Matcher matcher) {
*/
private String determineFileName(final Matcher matcher) {
String fileName;
if (StringUtils.isNotBlank(matcher.group(4))) {
if (StringUtils.isNotBlank(matcher.group(15))) {
fileName = matcher.group(15);
}
else if (StringUtils.isNotBlank(matcher.group(4))) {
fileName = matcher.group(4);
}
else if (StringUtils.isNotBlank(matcher.group(10))) {
Expand Down
@@ -1,7 +1,5 @@
package hudson.plugins.warnings.parser;

import static org.junit.Assert.*;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
Expand All @@ -10,13 +8,35 @@
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import static org.junit.Assert.*;

import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.Priority;

/**
* Tests the class {@link MsBuildParser}.
*/
public class MsBuildParserTest extends ParserTester {
/**
* MSBuildParser should make relative paths absolute, based on the project name listed in the message.
* @throws IOException
* if the stream could not be read
*
* @see <a href="https://issues.jenkins-ci.org/browse/JENKINS-38215">Issue 38215</a>
*/
@Test
public void issue38215() throws IOException {
Collection<FileAnnotation> warnings = new MsBuildParser().parse(openFile("issue38215.txt"));

assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 1, warnings.size());
Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation annotation = iterator.next();
checkWarning(annotation,
0,
"ignoring unknown option '-std=c++11'",
"C:/J/workspace/ci_windows/ws/build/rmw/test/test_error_handling.vcxproj",
MsBuildParser.WARNING_TYPE, "D9002", Priority.NORMAL);
}

/**
* MSBuildParser should make relative paths absolute, based on the project name listed in the message.
Expand Down
@@ -0,0 +1,2 @@
19:30:15 11>cl : Command line warning D9002: ignoring unknown option '-std=c++11' [C:\J\workspace\ci_windows\ws\build\rmw\test\test_error_handling.vcxproj]

0 comments on commit 4834ebc

Please sign in to comment.