Skip to content

Commit 6418f3e

Browse files
[JENKINS-62454] Fix parsing of Gcc warnings when there are new lines between description lines (#1285)
1 parent d85827b commit 6418f3e

File tree

6 files changed

+87
-9
lines changed

6 files changed

+87
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre
5252
builder.setLineStart(matcher.group(4));
5353
}
5454

55-
while (lookahead.hasNext() && Gcc4CompilerParser.isMessageContinuation(lookahead)) {
55+
while (lookahead.hasNext() && Gcc4CompilerParser.isMessageContinuation(lookahead, false)) {
5656
message.append('\n');
5757
message.append(lookahead.next());
5858
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre
5050
}
5151

5252
var completeMessage = new StringBuilder(messageContent);
53-
while (lookahead.hasNext() && Gcc4CompilerParser.isMessageContinuation(lookahead)) {
53+
while (lookahead.hasNext() && Gcc4CompilerParser.isMessageContinuation(lookahead, false)) {
5454
completeMessage.append(' ');
5555
completeMessage.append(lookahead.next());
5656
}

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre
6161

6262
setCategory(builder, originalMessage);
6363

64-
while (lookahead.hasNext() && isMessageContinuation(lookahead)) {
64+
boolean hasCodeSnippet = false;
65+
while (lookahead.hasNext() && isMessageContinuation(lookahead, hasCodeSnippet)) {
66+
var continuation = lookahead.next();
67+
if (continuation.length() > 0 && Character.isWhitespace(continuation.charAt(0))) {
68+
hasCodeSnippet = true;
69+
}
6570
message.append('\n');
66-
message.append(lookahead.next());
71+
message.append(continuation);
6772
}
6873

6974
var notes = getNotes(lookahead);
@@ -143,20 +148,26 @@ private String getNotes(final LookaheadStream lookahead) {
143148
}
144149

145150
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
146-
static boolean isMessageContinuation(final LookaheadStream lookahead) {
151+
static boolean isMessageContinuation(final LookaheadStream lookahead, final boolean hasCodeSnippet) {
147152
var peek = lookahead.peekNext();
148153
if (peek.length() < 3) {
149154
return false;
150155
}
156+
return !startsWithInvalidCharacter(peek, hasCodeSnippet)
157+
&& !Strings.CI.containsAny(peek, "arning", "rror", "make");
158+
}
159+
160+
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
161+
private static boolean startsWithInvalidCharacter(final String peek, final boolean hasCodeSnippet) {
151162
if (peek.charAt(0) == '/' || peek.charAt(0) == '[' || peek.charAt(0) == '<' || peek.charAt(0) == '=') {
152-
return false;
163+
return true;
153164
}
154165
if (peek.charAt(1) == ':') {
155-
return false;
166+
return true;
156167
}
157168
if (peek.charAt(2) == '/' || peek.charAt(0) == '\\') {
158-
return false;
169+
return true;
159170
}
160-
return !Strings.CI.containsAny(peek, "arning", "rror", "make");
171+
return hasCodeSnippet && peek.startsWith("In file included from");
161172
}
162173
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.function.Predicate;
55

66
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.ValueSource;
79

810
import edu.hm.hafner.analysis.Issue;
911
import edu.hm.hafner.analysis.Report;
@@ -763,4 +765,45 @@ void issue56815() {
763765
.hasSeverity(Severity.ERROR);
764766
}
765767
}
768+
769+
/**
770+
* Parses a warning log with consecutive warnings from different compilation units.
771+
* The "In file included from" lines should not be treated as message continuation.
772+
*
773+
* @param fileName the name of the test file to parse
774+
* @see <a href="https://issues.jenkins-ci.org/browse/JENKINS-62454">Issue 62454</a>
775+
*/
776+
@ParameterizedTest(name = "[{index}] Parse {0}")
777+
@ValueSource(strings = {"gcc4-issue62454-1.txt", "gcc4-issue62454-2.txt"})
778+
@org.junitpioneer.jupiter.Issue("JENKINS-62454")
779+
void issue62454(final String fileName) {
780+
var warnings = parse(fileName);
781+
782+
assertThat(warnings).hasSize(3);
783+
784+
Iterator<? extends Issue> iterator = warnings.iterator();
785+
786+
try (var softly = new SoftAssertions()) {
787+
softly.assertThat(iterator.next())
788+
.hasLineStart(84)
789+
.hasLineEnd(84)
790+
.hasMessage("comparison between signed and unsigned integer expressions [-Wsign-compare]\n if (SYSTIME_DIFF(now, lastResult) > MS2ST(SAMPLING_TIME_IN_MS)) {")
791+
.hasFileName("src/ledpwm/PWMLedManager.cpp")
792+
.hasSeverity(Severity.WARNING_NORMAL);
793+
794+
softly.assertThat(iterator.next())
795+
.hasLineStart(96)
796+
.hasLineEnd(96)
797+
.hasMessage("comparison between signed and unsigned integer expressions [-Wsign-compare]\n if(S2ST(lightSamplingTime) < SYSTIME_DIFF(now, lastStoredResult)) {")
798+
.hasFileName("src/ledpwm/PWMLedManager.cpp")
799+
.hasSeverity(Severity.WARNING_NORMAL);
800+
801+
softly.assertThat(iterator.next())
802+
.hasLineStart(26)
803+
.hasLineEnd(26)
804+
.hasMessage("'virtual void idata::AbstractThreadBase::initialize()' was hidden [-Woverloaded-virtual]\n virtual void initialize();\n ^~~~~~~~~~")
805+
.hasFileName("common/thread/abstract_thread.h")
806+
.hasSeverity(Severity.WARNING_NORMAL);
807+
}
808+
}
766809
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
src/ledpwm/PWMLedManager.cpp: In member function 'void PWMLedManager::updateLightSensorValue(int32_t)':
2+
src/ledpwm/PWMLedManager.cpp:84:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
3+
if (SYSTIME_DIFF(now, lastResult) > MS2ST(SAMPLING_TIME_IN_MS)) {
4+
src/ledpwm/PWMLedManager.cpp:96:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
5+
if(S2ST(lightSamplingTime) < SYSTIME_DIFF(now, lastStoredResult)) {
6+
In file included from common/obudisplay/UD/internalStateStorerThread.h:4:0,
7+
from src/services.h:21,
8+
from src/keyboard.cpp:16:
9+
common/thread/abstract_thread.h:26:15: warning: 'virtual void idata::AbstractThreadBase::initialize()' was hidden [-Woverloaded-virtual]
10+
virtual void initialize();
11+
^~~~~~~~~~
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
src/ledpwm/PWMLedManager.cpp: In member function 'void PWMLedManager::updateLightSensorValue(int32_t)':
2+
src/ledpwm/PWMLedManager.cpp:84:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
3+
if (SYSTIME_DIFF(now, lastResult) > MS2ST(SAMPLING_TIME_IN_MS)) {
4+
src/ledpwm/PWMLedManager.cpp:96:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
5+
if(S2ST(lightSamplingTime) < SYSTIME_DIFF(now, lastStoredResult)) {
6+
7+
8+
In file included from common/obudisplay/UD/internalStateStorerThread.h:4:0,
9+
from src/services.h:21,
10+
from src/keyboard.cpp:16:
11+
common/thread/abstract_thread.h:26:15: warning: 'virtual void idata::AbstractThreadBase::initialize()' was hidden [-Woverloaded-virtual]
12+
virtual void initialize();
13+
^~~~~~~~~~

0 commit comments

Comments
 (0)