Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EA] Add support of multi-lines error messages #995

Merged
merged 28 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
35fe274
take new warning Out parameter into account
Stargazer1998 Jan 5, 2024
9b2b0e9
new test case for new category
Stargazer1998 Jan 5, 2024
d28475f
take multiple lines of warning, error messages into account
Stargazer1998 Jan 5, 2024
5eeb455
add new test case to logger file
Stargazer1998 Jan 5, 2024
51b8117
change_regex
Stargazer1998 Jan 5, 2024
38c2f61
Merge pull request #994 from Stargazer1998/ee_parser_new_warning_style
uhafner Jan 9, 2024
8a0c4fc
Bump kentaro-m/auto-assign-action from 1.2.5 to 1.2.6
dependabot[bot] Jan 9, 2024
bfe11e1
Add reference to quality-monitor.
uhafner Jan 9, 2024
90b14c3
Bump slf4j.version from 2.0.10 to 2.0.11
dependabot[bot] Jan 9, 2024
f8f0bbd
changes for style checks
Stargazer1998 Jan 10, 2024
dc12408
Merge pull request #997 from jenkinsci/dependabot/maven/slf4j.version…
uhafner Jan 11, 2024
91836d4
Merge pull request #996 from jenkinsci/dependabot/github_actions/kent…
uhafner Jan 11, 2024
867b235
changes to use stream for parsing
Stargazer1998 Jan 11, 2024
dd5553c
resolve checkStyle issues
Stargazer1998 Jan 11, 2024
135ff60
take multiple lines of warning, error messages into account
Stargazer1998 Jan 5, 2024
30853ca
add new test case to logger file
Stargazer1998 Jan 5, 2024
40c10e8
changes for style checks
Stargazer1998 Jan 10, 2024
58a3276
changes to use stream for parsing
Stargazer1998 Jan 11, 2024
a85a445
resolve checkStyle issues
Stargazer1998 Jan 11, 2024
92fac3a
Merge branch 'take_multipleline_messages' of https://github.com/Starg…
Stargazer1998 Jan 11, 2024
d973fd9
changes for test cases
Stargazer1998 Jan 11, 2024
a0f8cab
correct test case
Stargazer1998 Jan 11, 2024
4fa4305
resolve rebase issues
Stargazer1998 Jan 11, 2024
f7f8a91
check style
Stargazer1998 Jan 11, 2024
ca26ebc
update EEParser
Stargazer1998 Jan 11, 2024
726f072
fix style check
Stargazer1998 Jan 11, 2024
3c1ebd2
add new catch step
Stargazer1998 Jan 11, 2024
422eee4
create iterator correctly
Stargazer1998 Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package edu.hm.hafner.analysis.parser;

import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
Expand All @@ -22,13 +24,16 @@
*/
public class EmbeddedEngineerParser extends IssueParser {
private static final long serialVersionUID = -1251248150731418714L;

private static final Pattern LOG_BEGINNING_PATTERN = Pattern.compile("\\[.*?\\].*");
private static final Pattern HEADER_PATTERN = Pattern.compile(
"^([^\\(Start)]*)(Starting code generation for)\\s(?<file>.*\\})");
private static final Pattern SPECIAL_WARNING_PATTERN = Pattern.compile(
"^\\[([^\\]]*)\\]\\s(?<severity>Warn)\\s-\\s(?<description>[^']*)'(?<module>[^']*)"
+ "'\\s(?<details>\\(?[^{]*)(?<serial>[^)]*\\})");

private static final Pattern WARNING_PATTERN = Pattern.compile(
"^\\[([^\\]]*)\\]\\s(?<severity>Error|Warn)\\s-\\s(?<category>.+):\\s(?<description>.+)");
"^\\[([^\\]]*)\\]\\s(?<severity>Error|Warn)\\s-\\s(?<category>[^:]*)" + "(:\\s|\\s\\()(?<description>.+)");

@Override
public Report parse(final ReaderFactory reader) throws ParsingException {
Expand All @@ -40,28 +45,47 @@ public Report parse(final ReaderFactory reader) throws ParsingException {
}
}

private List<String> readLogInfo(final Iterator<String> lineIterator) {
List<String> logInfo = new ArrayList<>();

while (lineIterator.hasNext()) {
String currentLine = lineIterator.next();
Matcher logBeginningMatcher = LOG_BEGINNING_PATTERN.matcher(currentLine);
if (logBeginningMatcher.matches()) {
logInfo.add(currentLine);
}
else {
int lastIdx = logInfo.size() - 1;
Stargazer1998 marked this conversation as resolved.
Show resolved Hide resolved
StringBuilder multiLineInfo = new StringBuilder(logInfo.get(lastIdx));
multiLineInfo.append(" ").append(currentLine);
logInfo.set(lastIdx, multiLineInfo.toString());
}
}
return logInfo;
Stargazer1998 marked this conversation as resolved.
Show resolved Hide resolved
}

private Report parse(final Stream<String> lines) {
try (IssueBuilder builder = new IssueBuilder()) {
Iterator<String> lineIterator = lines.iterator();
String file = parseFileName(lineIterator);
Report report = new Report();

while (lineIterator.hasNext()) {
String line = lineIterator.next();
Matcher matcher = SPECIAL_WARNING_PATTERN.matcher(line);
Matcher warningMatcher = WARNING_PATTERN.matcher(line);
List<String> logLines = this.readLogInfo(lineIterator);
for (String logLine:logLines) {
Matcher matcher = SPECIAL_WARNING_PATTERN.matcher(logLine);
Matcher warningMatcher = WARNING_PATTERN.matcher(logLine);

if (matcher.matches() || warningMatcher.matches()) {
String group;
String description;
if (matcher.matches()) {
group = matcher.group("severity");

description = String.format("%s'%s' %s%s",
matcher.group("description"),
matcher.group("module"),
matcher.group("details"),
matcher.group("serial"));
builder.setCategory(setCategory(line));
builder.setCategory(setCategory(logLine));
builder.setModuleName(matcher.group("module"));
}
else {
Expand All @@ -71,7 +95,7 @@ private Report parse(final Stream<String> lines) {
warningMatcher.group("category"),
warningMatcher.group("description"));
}
Severity priority = mapPriority(line, group);
Severity priority = mapPriority(logLine, group);
builder.setDescription(description);
builder.setFileName(file);
builder.setSeverity(priority);
Expand Down Expand Up @@ -121,4 +145,4 @@ else if (group.contains("Error")) {
}
return Severity.WARNING_NORMAL;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected EmbeddedEngineerParser createParser() {

@Override
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
softly.assertThat(report).hasSize(8);
softly.assertThat(report).hasSize(9);
softly.assertThat(report.get(0))
.hasModuleName("index_module")
.hasDescription("Complex type definition without referenced element found 'index_module' (uint8_t); {98CF1FE6-EC9C-43f1-e476-40EFCD63cA8D}")
Expand All @@ -45,6 +45,30 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti
.hasCategory("Error loading plugins from")
.hasDescription("Error loading plugins from C:\\file1\\idc\\sample_ext.x64.dll")
.hasSeverity(Severity.ERROR);
softly.assertThat(report.get(8))
.hasCategory("Error loading plugins from")
.hasDescription("Error loading plugins from C:\\file1\\idc\\sample_ext.x64.dll File name: "
+ "'file:///C:\\AA\\BB\\System.Text.Json.dll' ---> System.NotSupportedException: "
+ "An attempt was made to load an assembly from a network location which would have caused the "
+ "assembly to be sandboxed in previous versions of the .NET Framework. "
+ "This release of the .NET Framework does not enable CAS policy by default, "
+ "so this load may be dangerous. If this load is not intended to sandbox the assembly,"
+ " please enable the loadFromRemoteSources switch. "
+ "See http://go.microsoft.com/fwlink/?LinkId=155569 for more information. "
+ " at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase,"
+ " Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, "
+ "IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, "
+ "Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly."
+ "InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, "
+ "RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, "
+ "Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) "
+ "at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, "
+ "Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, "
+ "Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) "
+ " at System.Reflection.Assembly.LoadFrom(String assemblyFile) "
+ "at A.A`1.a(String , Predicate`1 , Object[] ) "
+ "at A.A`1.A(String , Predicate`1 , Object[] )")
.hasSeverity(Severity.ERROR);
}
}

10 changes: 9 additions & 1 deletion src/test/resources/edu/hm/hafner/analysis/parser/ea.log
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@
[2023-03-10 12:04:25.0777] Warn - Code generation for element 'Module1' failed. Could not start code generation ; {ffeee99-9BD1-12345678}
[2023-03-10 12:04:25.0777] Warn - Code generation for element 'Module1' passed. Could not start code generation ; {ffeee99-9BD1-12345678}
[2023-03-10 12:04:25.1377] Warn - SampleValidation: no requirement linked to final node 'Module1_Node'.
[2023-03-10 12:04:22.1045] Error - Error loading plugins from: C:\file1\idc\sample_ext.x64.dll
[2023-03-10 12:04:22.1045] Error - Error loading plugins from: C:\file1\idc\sample_ext.x64.dll
[2023-04-10 12:04:22.1045] Error - Error loading plugins from: C:\file1\idc\sample_ext.x64.dll
File name: 'file:///C:\AA\BB\System.Text.Json.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at A.A`1.a(String , Predicate`1 , Object[] )
at A.A`1.A(String , Predicate`1 , Object[] )
Loading