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

Add line matching for multi-line pattern parse #178

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -35,6 +35,7 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -318,7 +319,7 @@ private static List<FoundFailureCause> convertToFoundFailureCauses(Map<FailureCa
* @return a FoundIndication if we find the pattern, null if not.
* @throws IOException if problems occur in the reader handling.
*/
protected FoundIndication scanMultiLineOneFile(Run build, BufferedReader reader, String currentFile)
protected FoundIndication scanMultiLineOneFile(Run build, LineNumberReader reader, String currentFile)
throws IOException {
TimerThread timerThread = new TimerThread(Thread.currentThread(), TIMEOUT_BLOCK);
FoundIndication foundIndication = null;
Expand All @@ -338,7 +339,7 @@ protected FoundIndication scanMultiLineOneFile(Run build, BufferedReader reader,
Matcher matcher = pattern.matcher(new InterruptibleCharSequence(searchBuffer.toString()));
if (matcher.find()) {
foundIndication = new FoundIndication(build, pattern.pattern(), currentFile,
removeConsoleNotes(matcher.group()), -1);
removeConsoleNotes(matcher.group()), reader.getLineNumber());
break;
}
searchBuffer.delete(0, BUF_SIZE_BYTES - OVERLAP_BYTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package com.sonyericsson.jenkins.plugins.bfa.model;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.PrintStream;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -62,9 +62,9 @@ public MultilineBuildLogFailureReader(MultilineBuildLogIndication indication) {
*/
@Override
public FoundIndication scan(Run build) throws IOException {
BufferedReader reader = null;
LineNumberReader reader = null;
try {
reader = new BufferedReader(build.getLogReader());
reader = new LineNumberReader(build.getLogReader());
return scanMultiLineOneFile(build, reader, "log");
} finally {
if (reader != null) {
Expand All @@ -88,10 +88,10 @@ public FoundIndication scan(Run build) throws IOException {
*/
public FoundIndication scan(Run build, PrintStream buildLog) {
FoundIndication foundIndication = null;
BufferedReader reader = null;
LineNumberReader reader = null;
long start = System.currentTimeMillis();
try {
reader = new BufferedReader(build.getLogReader());
reader = new LineNumberReader(build.getLogReader());
foundIndication = scanMultiLineOneFile(build, reader, "log");
} catch (IOException ioe) {
logger.log(Level.SEVERE, "[BFA] I/O problems during indication analysis: ", ioe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintStream;
import java.io.SequenceInputStream;
import java.io.StringReader;
Expand Down Expand Up @@ -180,13 +181,14 @@ public void testScanOneFileWithFileTimeout() throws Exception {
@Test
public void testScanMultiLineOneFile() throws Exception {
FailureReader reader = new TestReader(new MultilineBuildLogIndication(".*scan for me please.*"));
BufferedReader br = new BufferedReader(new StringReader("scan for me please will you!\nA second line"));
LineNumberReader br = new LineNumberReader(new StringReader("scan for me please will you!\nA second line"));
long startTime = System.currentTimeMillis();
FoundIndication indication = reader.scanMultiLineOneFile(null, br, "test");
long elapsedTime = System.currentTimeMillis() - startTime;
br.close();
assertTrue("Unexpected long time to parse log: " + elapsedTime, elapsedTime <= 1000);
assertNotNull("Expected to find an indication", indication);
assertEquals(indication.getMatchingLine(), 1);
}

/**
Expand All @@ -197,7 +199,7 @@ public void testScanMultiLineOneFile() throws Exception {
public void testScanMultiLineOneFileWithBlockTimeout() throws Exception {
// Evil input + expression. Will timeout every time.
FailureReader reader = new TestReader(new MultilineBuildLogIndication("^(([a-z])+.)+[A-Z]([a-z])+$"));
BufferedReader br = new BufferedReader(new InputStreamReader(
LineNumberReader br = new LineNumberReader(new InputStreamReader(
new ByteArrayInputStream("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".getBytes())));
long startTime = System.currentTimeMillis();
FoundIndication indication = reader.scanMultiLineOneFile(null, br, "test");
Expand All @@ -221,7 +223,7 @@ public void testScanMultilineOneFileWithFileTimeout() throws Exception {
zipStream.getNextEntry();
inStream = new SequenceInputStream(inStream, zipStream);
}
BufferedReader br = new QuadrupleDupleLineReader(new BufferedReader(new InputStreamReader(inStream)));
LineNumberReader br = new QuadrupleDupleLineReader(new BufferedReader(new InputStreamReader(inStream)));
long startTime = System.currentTimeMillis();
FoundIndication indication = reader.scanMultiLineOneFile(null, br, "test");
long elapsedTime = System.currentTimeMillis() - startTime;
Expand All @@ -236,7 +238,7 @@ public void testScanMultilineOneFileWithFileTimeout() throws Exception {
* and constructs the same line 15 times on top of the original.
* This so that the scanning has more to work on and can timeout
*/
static class QuadrupleDupleLineReader extends BufferedReader {
static class QuadrupleDupleLineReader extends LineNumberReader {

/**
* Standard constructor
Expand Down