Skip to content

Commit b4c99cc

Browse files
MsBuild: keep warnings from bare task names like EXEC
When MSBuild's Exec task runs an external tool, it prefixes any output lines that lack a file name with the task name in upper-case (e.g. EXEC). isToolName() was treating these the same as executable names (.exe) and discarding the whole warning via Optional.empty(). This caused NuGet vulnerability warnings (NU1902, NU1903, etc.) to be silently dropped and never appear in the Jenkins Warnings plugin. Fix: split the isToolName branch. Executable names (.exe) and pseudo-file placeholders like <command line option> are still dropped. Bare MSBuild task names (EXEC, NMAKE, CSC, cl, rs, ...) now produce an issue with fileName set to '-' so the warning still shows up in the report. Fixes #1512
1 parent 059dc20 commit b4c99cc

3 files changed

Lines changed: 73 additions & 10 deletions

File tree

src/main/java/edu/hm/hafner/analysis/parser/MsBuildParser.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,14 @@ public class MsBuildParser extends LookaheadParser {
8181
+ PROJECT_DIR_PATTERN
8282
+ "))$";
8383

84-
/**
85-
* Pattern to identify bare tool names that should be ignored (without path separators).
86-
* Only matches tool names when they appear alone, not as part of a path.
87-
*/
84+
/** Tool-like tokens: bare task names, .exe files, and pseudo-file placeholders. */
8885
private static final Pattern TOOL_NAME_PATTERN = Pattern.compile(
8986
"^(?:EXEC|NMAKE|LINK|MSBUILD|CSC|MSBuild|link|nmake|msbuild|cl|rs)$|"
9087
+ "^[^/\\\\]*\\.exe$|"
9188
+ "^<[^>]+>$",
9289
Pattern.CASE_INSENSITIVE);
9390

91+
9492
/**
9593
* Pattern to identify compiler/linker parameters (e.g., /INCREMENTAL, /OPT:ICF, -Wall).
9694
* These should not be treated as filenames.
@@ -137,9 +135,14 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre
137135
if (isLinkerParameter(fileName)) {
138136
fileName = "-";
139137
}
140-
// Skip if this is a tool name (executable or tool without proper source extension)
141138
else if (isToolName(fileName)) {
142-
return Optional.empty();
139+
if (isBareToolName(fileName)) {
140+
// EXEC/NMAKE etc. prefix real tool output - keep these as fileName "-"
141+
fileName = "-";
142+
}
143+
else {
144+
return Optional.empty();
145+
}
143146
}
144147

145148
// Check if this is a Delphi warning/hint where the actual file is in the message
@@ -276,6 +279,20 @@ private boolean isToolName(final String fileName) {
276279
return TOOL_NAME_PATTERN.matcher(baseFileName).matches();
277280
}
278281

282+
// Checks if fileName is a bare MSBuild task name like EXEC or NMAKE.
283+
private boolean isBareToolName(final String fileName) {
284+
if (StringUtils.isBlank(fileName) || "-".equals(fileName) || "unknown.file".equals(fileName)) {
285+
return false;
286+
}
287+
288+
var baseFileName = FilenameUtils.getName(fileName).trim();
289+
290+
baseFileName = baseFileName.replaceAll("^\\d{1,2}:\\d{2}:\\d{2}\\s+", "");
291+
292+
return !StringUtils.endsWithIgnoreCase(baseFileName, ".exe")
293+
&& !(baseFileName.startsWith("<") && baseFileName.endsWith(">"));
294+
}
295+
279296
/**
280297
* Determines the name of the file that is the cause of the warning.
281298
*

src/test/java/edu/hm/hafner/analysis/parser/MsBuildParserTest.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,61 @@ void shouldRemoveAnsiColors() {
5656
*/
5757
@Test
5858
void issue56613() {
59-
assertThat(parse("issue56613.txt")).isEmpty();
59+
var warnings = parse("issue56613.txt");
60+
61+
// ConsoleTranslator.exe is an executable name and is still dropped.
62+
// EXEC, NMAKE and rs are bare MSBuild task names: their warnings are now surfaced
63+
// with fileName "-" rather than silently discarded (see issue #1512).
64+
assertThat(warnings).hasSize(4);
65+
assertThatReportHasSeverities(warnings, 3, 0, 1, 0);
6066
}
6167

6268
/**
63-
* Extended test for issue 56613 - ensures tool names are properly ignored.
64-
* Tests that executables (.exe) and tool names without extensions (NMAKE, rs, cl) are skipped.
69+
* Extended test for issue 56613 - ensures tool names are properly handled.
70+
* Executable names (.exe) and pseudo-file placeholders are still dropped.
71+
* Bare task names (EXEC, NMAKE, CSC, MSBuild, rs) now produce issues with fileName "-".
6572
*
6673
* @see <a href="https://issues.jenkins.io/browse/JENKINS-56613">Issue 56613</a>
6774
*/
6875
@Test
6976
void issue56613Extended() {
70-
assertThat(parse("issue56613-extended.txt")).isEmpty();
77+
var warnings = parse("issue56613-extended.txt");
78+
79+
assertThat(warnings).hasSize(6);
80+
assertThatReportHasSeverities(warnings, 3, 0, 3, 0);
81+
}
82+
83+
/**
84+
* Warnings prefixed by a bare task name like EXEC should not be dropped.
85+
*
86+
* @see <a href="https://github.com/jenkinsci/analysis-model/issues/1512">Issue #1512</a>
87+
*/
88+
@Test
89+
void issue1512() {
90+
var warnings = parse("issue1512.txt");
91+
92+
assertThat(warnings).hasSize(3);
93+
assertThatReportHasSeverities(warnings, 0, 0, 3, 0);
94+
95+
try (var softly = new SoftAssertions()) {
96+
softly.assertThat(warnings.get(0))
97+
.hasFileName("-")
98+
.hasCategory("NU1902")
99+
.hasSeverity(Severity.WARNING_NORMAL)
100+
.hasMessage("Package 'Microsoft.IdentityModel.JsonWebTokens' 6.11.1 has a known moderate severity vulnerability, https://github.com/advisories/GHSA-59j7-ghrg-fj52");
101+
102+
softly.assertThat(warnings.get(1))
103+
.hasFileName("-")
104+
.hasCategory("NU1903")
105+
.hasSeverity(Severity.WARNING_NORMAL)
106+
.hasMessage("Package 'Microsoft.Owin' 4.2.0 has a known high severity vulnerability, https://github.com/advisories/GHSA-3rq8-h3gj-r5c6");
107+
108+
softly.assertThat(warnings.get(2))
109+
.hasFileName("-")
110+
.hasCategory("NU1902")
111+
.hasSeverity(Severity.WARNING_NORMAL)
112+
.hasMessage("Package 'System.IdentityModel.Tokens.Jwt' 6.11.1 has a known moderate severity vulnerability, https://github.com/advisories/GHSA-59j7-ghrg-fj52");
113+
}
71114
}
72115

73116
/**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
EXEC : warning : NU1902: Package 'Microsoft.IdentityModel.JsonWebTokens' 6.11.1 has a known moderate severity vulnerability, https://github.com/advisories/GHSA-59j7-ghrg-fj52 [C:\jenkins\workspace\project\ci.msbuildproj]
2+
EXEC : warning : NU1903: Package 'Microsoft.Owin' 4.2.0 has a known high severity vulnerability, https://github.com/advisories/GHSA-3rq8-h3gj-r5c6 [C:\jenkins\workspace\project\ci.msbuildproj]
3+
EXEC : warning : NU1902: Package 'System.IdentityModel.Tokens.Jwt' 6.11.1 has a known moderate severity vulnerability, https://github.com/advisories/GHSA-59j7-ghrg-fj52 [C:\jenkins\workspace\project\ci.msbuildproj]

0 commit comments

Comments
 (0)