forked from robaho/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutputAnalyzer.java
More file actions
768 lines (702 loc) · 25.1 KB
/
OutputAnalyzer.java
File metadata and controls
768 lines (702 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
/*
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.test.lib.process;
import jdk.test.lib.Asserts;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class OutputAnalyzer {
private static final String jvmwarningmsg = ".* VM warning:.*";
private static final String deprecatedmsg = ".* VM warning:.* deprecated.*";
private final OutputBuffer buffer;
/**
* Create an OutputAnalyzer, a utility class for verifying output and exit
* value from a Process
*
* @param process Process to analyze
* @param cs The charset used to convert stdout/stderr from bytes to chars
* or null for the default charset.
* @throws IOException If an I/O error occurs.
*/
public OutputAnalyzer(Process process, Charset cs) throws IOException {
buffer = OutputBuffer.of(process, cs);
}
/**
* Create an OutputAnalyzer, a utility class for verifying output and exit
* value from a Process
*
* @param process Process to analyze
* @throws IOException If an I/O error occurs.
*/
public OutputAnalyzer(Process process) throws IOException {
buffer = OutputBuffer.of(process);
}
/**
* Create an OutputAnalyzer, a utility class for verifying output
*
* @param buf String buffer to analyze
*/
public OutputAnalyzer(String buf) {
buffer = OutputBuffer.of(buf, buf);
}
/**
* Create an OutputAnalyzer, a utility class for verifying output
*
* @param file File to analyze
*/
public OutputAnalyzer(Path file) throws IOException {
this(Files.readString(file));
}
/**
* Create an OutputAnalyzer, a utility class for verifying output
*
* @param stdout stdout buffer to analyze
* @param stderr stderr buffer to analyze
*/
public OutputAnalyzer(String stdout, String stderr) {
buffer = OutputBuffer.of(stdout, stderr);
}
/**
* Create an OutputAnalyzer, a utility class for verifying output
*
* @param stdout stdout buffer to analyze
* @param stderr stderr buffer to analyze
* @param stderr exitValue result to analyze
*/
public OutputAnalyzer(String stdout, String stderr, int exitValue)
{
buffer = OutputBuffer.of(stdout, stderr, exitValue);
}
/**
* Verify that the stdout contents of output buffer is empty
*
* @throws RuntimeException
* If stdout was not empty
*/
public OutputAnalyzer stdoutShouldBeEmpty() {
if (!getStdout().isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stdout was not empty");
}
return this;
}
/**
* Verify that the stderr contents of output buffer is empty
*
* @throws RuntimeException
* If stderr was not empty
*/
public OutputAnalyzer stderrShouldBeEmpty() {
if (!getStderr().isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
return this;
}
/**
* Verify that the stderr contents of output buffer is empty,
* after filtering out the Hotspot warning messages
*
* @throws RuntimeException
* If stderr was not empty
*/
public OutputAnalyzer stderrShouldBeEmptyIgnoreVMWarnings() {
if (!getStderr().replaceAll(jvmwarningmsg + "\\R", "").isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
return this;
}
/**
* Verify that the stderr contents of output buffer is empty,
* after filtering out all messages matching "warning" (case insensitive)
*
* @throws RuntimeException
* If stderr was not empty
*/
public OutputAnalyzer stderrShouldBeEmptyIgnoreWarnings() {
if (!getStderr().replaceAll("(?i).*warning.*\\R", "").isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
return this;
}
/**
* Verify that the stderr contents of output buffer is empty,
* after filtering out the Hotspot deprecation warning messages
*
* @throws RuntimeException
* If stderr was not empty
*/
public OutputAnalyzer stderrShouldBeEmptyIgnoreDeprecatedWarnings() {
if (!getStderr().replaceAll(deprecatedmsg + "\\R", "").isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
return this;
}
/**
* Verify that the stdout contents of output buffer is not empty
*
* @throws RuntimeException
* If stdout was empty
*/
public OutputAnalyzer stdoutShouldNotBeEmpty() {
if (getStdout().isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stdout was empty");
}
return this;
}
/**
* Verify that the stderr contents of output buffer is not empty
*
* @throws RuntimeException
* If stderr was empty
*/
public OutputAnalyzer stderrShouldNotBeEmpty() {
if (getStderr().isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was empty");
}
return this;
}
/**
* Verify that the stdout and stderr contents of output buffer contains the string
*
* @param expectedString String that buffer should contain
* @throws RuntimeException If the string was not found
*/
public OutputAnalyzer shouldContain(String expectedString) {
String stdout = getStdout();
String stderr = getStderr();
if (!stdout.contains(expectedString) && !stderr.contains(expectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString + "' missing from stdout/stderr");
}
return this;
}
/**
* Verify that the stdout contents of output buffer contains the string
*
* @param expectedString String that buffer should contain
* @throws RuntimeException If the string was not found
*/
public OutputAnalyzer stdoutShouldContain(String expectedString) {
String stdout = getStdout();
if (!stdout.contains(expectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString + "' missing from stdout");
}
return this;
}
/**
* Verify that the stderr contents of output buffer contains the string
*
* @param expectedString String that buffer should contain
* @throws RuntimeException If the string was not found
*/
public OutputAnalyzer stderrShouldContain(String expectedString) {
String stderr = getStderr();
if (!stderr.contains(expectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + expectedString + "' missing from stderr");
}
return this;
}
/**
* Verify that the stdout and stderr contents of output buffer does not contain the string
*
* @param notExpectedString String that the buffer should not contain
* @throws RuntimeException If the string was found
*/
public OutputAnalyzer shouldNotContain(String notExpectedString) {
String stdout = getStdout();
String stderr = getStderr();
if (stdout.contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString + "' found in stdout");
}
if (stderr.contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString + "' found in stderr");
}
return this;
}
/**
* Verify that the stdout and stderr contents of output buffer are empty
*
* @throws RuntimeException If the stdout and stderr are not empty
*/
public OutputAnalyzer shouldBeEmpty() {
String stdout = getStdout();
String stderr = getStderr();
if (!stdout.isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stdout was not empty");
}
if (!stderr.isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
return this;
}
/**
* Verify that the stdout contents of output buffer does not contain the string
*
* @param notExpectedString String that the buffer should not contain
* @throws RuntimeException If the string was found
*/
public OutputAnalyzer stdoutShouldNotContain(String notExpectedString) {
String stdout = getStdout();
if (stdout.contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString + "' found in stdout");
}
return this;
}
/**
* Verify that the stderr contents of output buffer does not contain the string
*
* @param notExpectedString String that the buffer should not contain
* @throws RuntimeException If the string was found
*/
public OutputAnalyzer stderrShouldNotContain(String notExpectedString) {
String stderr = getStderr();
if (stderr.contains(notExpectedString)) {
reportDiagnosticSummary();
throw new RuntimeException("'" + notExpectedString + "' found in stderr");
}
return this;
}
/**
* Verify that the stdout and stderr contents of output buffer matches
* the pattern
*
* @param regexp
* @throws RuntimeException If the pattern was not found
*/
public OutputAnalyzer shouldMatch(String regexp) {
String stdout = getStdout();
String stderr = getStderr();
Pattern pattern = Pattern.compile(regexp, Pattern.MULTILINE);
Matcher stdoutMatcher = pattern.matcher(stdout);
Matcher stderrMatcher = pattern.matcher(stderr);
if (!stdoutMatcher.find() && !stderrMatcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' missing from stdout/stderr");
}
return this;
}
/**
* Verify that the stdout contents of output buffer matches the
* pattern
*
* @param regexp
* @throws RuntimeException If the pattern was not found
*/
public OutputAnalyzer stdoutShouldMatch(String regexp) {
String stdout = getStdout();
Matcher matcher = Pattern.compile(regexp, Pattern.MULTILINE).matcher(stdout);
if (!matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' missing from stdout");
}
return this;
}
/**
* Verify that the stderr contents of output buffer matches the
* pattern
*
* @param pattern
* @throws RuntimeException If the pattern was not found
*/
public OutputAnalyzer stderrShouldMatch(String pattern) {
String stderr = getStderr();
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
if (!matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern
+ "' missing from stderr");
}
return this;
}
/**
* Verify that the stdout and stderr contents of output buffer does not
* match the pattern
*
* @param regexp
* @throws RuntimeException If the pattern was found
*/
public OutputAnalyzer shouldNotMatch(String regexp) {
String stdout = getStdout();
Pattern pattern = Pattern.compile(regexp, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(stdout);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' found in stdout: '" + matcher.group() + "'");
}
String stderr = getStderr();
matcher = pattern.matcher(stderr);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' found in stderr: '" + matcher.group() + "'");
}
return this;
}
/**
* Verify that the stdout contents of output buffer does not match the
* pattern
*
* @param regexp
* @throws RuntimeException If the pattern was found
*/
public OutputAnalyzer stdoutShouldNotMatch(String regexp) {
String stdout = getStdout();
Matcher matcher = Pattern.compile(regexp, Pattern.MULTILINE).matcher(stdout);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' found in stdout");
}
return this;
}
/**
* Verify that the stderr contents of output buffer does not match the
* pattern
*
* @param regexp
* @throws RuntimeException If the pattern was found
*/
public OutputAnalyzer stderrShouldNotMatch(String regexp) {
String stderr = getStderr();
Matcher matcher = Pattern.compile(regexp, Pattern.MULTILINE).matcher(stderr);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' found in stderr");
}
return this;
}
/**
* Get the captured group of the first string matching the pattern.
* stderr is searched before stdout.
*
* @param regexp The multi-line pattern to match
* @param group The group to capture
* @return The matched string or null if no match was found
*/
public String firstMatch(String regexp, int group) {
Pattern pattern = Pattern.compile(regexp, Pattern.MULTILINE);
String stderr = getStderr();
Matcher stderrMatcher = pattern.matcher(stderr);
if (stderrMatcher.find()) {
return stderrMatcher.group(group);
}
String stdout = getStdout();
Matcher stdoutMatcher = pattern.matcher(stdout);
if (stdoutMatcher.find()) {
return stdoutMatcher.group(group);
}
return null;
}
/**
* Get the first string matching the pattern.
* stderr is searched before stdout.
*
* @param pattern The multi-line pattern to match
* @return The matched string or null if no match was found
*/
public String firstMatch(String pattern) {
return firstMatch(pattern, 0);
}
/**
* Verify the exit value of the process
*
* @param expectedExitValue Expected exit value from process
* @throws RuntimeException If the exit value from the process did not match the expected value
*/
public OutputAnalyzer shouldHaveExitValue(int expectedExitValue) {
if (getExitValue() != expectedExitValue) {
reportDiagnosticSummary();
throw new RuntimeException("Expected to get exit value of ["
+ expectedExitValue + "], exit value is: [" + getExitValue() + "]");
}
return this;
}
/**
* Verify the exit value of the process
*
* @param notExpectedExitValue Unexpected exit value from process
* @throws RuntimeException If the exit value from the process did match the expected value
*/
public OutputAnalyzer shouldNotHaveExitValue(int notExpectedExitValue) {
if (getExitValue() == notExpectedExitValue) {
reportDiagnosticSummary();
throw new RuntimeException("Unexpected to get exit value of ["
+ notExpectedExitValue + "]");
}
return this;
}
/**
* Report summary that will help to diagnose the problem
* Currently includes:
* - standard input produced by the process under test
* - standard output
* - exit code
* Note: the command line is printed by the ProcessTools
*/
public void reportDiagnosticSummary() {
String msg =
" stdout: [" + getStdout() + "];\n" +
" stderr: [" + getStderr() + "]\n" +
" exitValue = " + getExitValue() + "\n";
System.err.println(msg);
}
/**
* Print the stdout buffer to the given {@code PrintStream}.
*
* @return this OutputAnalyzer
*/
public OutputAnalyzer outputTo(PrintStream out) {
out.println(getStdout());
return this;
}
/**
* Print the stderr buffer to the given {@code PrintStream}.
*
* @return this OutputAnalyzer
*/
public OutputAnalyzer errorTo(PrintStream out) {
out.println(getStderr());
return this;
}
/**
* Get the contents of the output buffer (stdout and stderr)
*
* @return Content of the output buffer
*/
public String getOutput() {
return getStdout() + getStderr();
}
/**
* Get the contents of the stdout buffer
*
* @return Content of the stdout buffer
*/
public String getStdout() {
return buffer.getStdout();
}
/**
* Get the contents of the stderr buffer
*
* @return Content of the stderr buffer
*/
public String getStderr() {
return buffer.getStderr();
}
/**
* Get the process exit value
*
* @return Process exit value
*/
public int getExitValue() {
return buffer.getExitValue();
}
/**
* Get the process' pid
*
* @return pid
*/
public long pid() {
return buffer.pid();
}
/**
* Get the contents of the output buffer (stdout and stderr) as list of strings.
* Output will be split by newlines.
*
* @return Contents of the output buffer as list of strings
*/
public List<String> asLines() {
return asLines(getOutput());
}
private List<String> asLines(String buffer) {
return Arrays.asList(buffer.split("\\R"));
}
/**
* Verifies that the stdout and stderr contents of output buffer are empty, after
* filtering out the HotSpot warning messages.
*
* @throws RuntimeException If the stdout and stderr are not empty
*/
public OutputAnalyzer shouldBeEmptyIgnoreVMWarnings() {
String stdout = getStdout();
String stderr = getStderr();
if (!stdout.isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stdout was not empty");
}
if (!stderr.replaceAll(jvmwarningmsg + "\\R", "").isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
return this;
}
/**
* Verify that the stderr contents of output buffer matches the pattern,
* after filtering out the Hotespot warning messages
*
* @param pattern
* @throws RuntimeException If the pattern was not found
*/
public OutputAnalyzer stderrShouldMatchIgnoreVMWarnings(String pattern) {
String stderr = getStderr().replaceAll(jvmwarningmsg + "\\R", "");
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
if (!matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + pattern
+ "' missing from stderr");
}
return this;
}
/**
* Returns the contents of the output buffer (stdout and stderr), without those
* JVM warning msgs, as list of strings. Output is split by newlines.
*
* @return Contents of the output buffer as list of strings
*/
public List<String> asLinesWithoutVMWarnings() {
return Arrays.stream(getOutput().split("\\R"))
.filter(Pattern.compile(jvmwarningmsg).asPredicate().negate())
.collect(Collectors.toList());
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
public OutputAnalyzer shouldMatchByLine(String pattern) {
return shouldMatchByLine(null, null, pattern);
}
/**
* @see #stdoutShouldMatchByLine(String, String, String)
*/
public OutputAnalyzer stdoutShouldMatchByLine(String pattern) {
return stdoutShouldMatchByLine(null, null, pattern);
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
public OutputAnalyzer shouldMatchByLineFrom(String from, String pattern) {
return shouldMatchByLine(from, null, pattern);
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
public OutputAnalyzer shouldMatchByLineTo(String to, String pattern) {
return shouldMatchByLine(null, to, pattern);
}
/**
* Verify that the stdout and stderr contents of output buffer match the
* {@code pattern} line by line. The whole output could be matched or
* just a subset of it.
*
* @param from
* The line (excluded) from where output will be matched.
* Set {@code from} to null for matching from the first line.
* @param to
* The line (excluded) until where output will be matched.
* Set {@code to} to null for matching until the last line.
* @param pattern
* Matching pattern
*/
public OutputAnalyzer shouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getOutput(), from, to, pattern);
}
/**
* Verify that the stdout contents of output buffer matches the
* {@code pattern} line by line. The whole stdout could be matched or
* just a subset of it.
*
* @param from
* The line (excluded) from where stdout will be matched.
* Set {@code from} to null for matching from the first line.
* @param to
* The line (excluded) until where stdout will be matched.
* Set {@code to} to null for matching until the last line.
* @param pattern
* Matching pattern
*/
public OutputAnalyzer stdoutShouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getStdout(), from, to, pattern);
}
private OutputAnalyzer shouldMatchByLine(String buffer, String from, String to, String pattern) {
List<String> lines = asLines(buffer);
int fromIndex = 0;
if (from != null) {
fromIndex = indexOf(lines, from, 0) + 1; // + 1 -> apply 'pattern' to lines after 'from' match
Asserts.assertGreaterThan(fromIndex, 0,
"The line/pattern '" + from + "' from where the output should match can not be found");
}
int toIndex = lines.size();
if (to != null) {
toIndex = indexOf(lines, to, fromIndex);
Asserts.assertGreaterThan(toIndex, fromIndex,
"The line/pattern '" + to + "' until where the output should match can not be found");
}
List<String> subList = lines.subList(fromIndex, toIndex);
Asserts.assertFalse(subList.isEmpty(), "There are no lines to check:"
+ " range " + fromIndex + ".." + toIndex + ", subList = " + subList);
subList.stream()
.filter(Pattern.compile(pattern).asPredicate().negate())
.findAny()
.ifPresent(line -> Asserts.fail(
"The line '" + line + "' does not match pattern '" + pattern + "'"));
return this;
}
/**
* Check if there is a line matching {@code regexp} and return its index
*
* @param regexp Matching pattern
* @param fromIndex Start matching after so many lines skipped
* @return Index of first matching line
*/
private int indexOf(List<String> lines, String regexp, int fromIndex) {
Pattern pattern = Pattern.compile(regexp);
for (int i = fromIndex; i < lines.size(); i++) {
if (pattern.matcher(lines.get(i)).matches()) {
return i;
}
}
return -1;
}
}