/** Compiles all the patterns from {@link #getLogPattern()} */ private List<Pattern> createPatternsList() { String logPattern = getLogPattern(); if (logPattern == null || logPattern.isEmpty()) { return Collections.emptyList(); } List<Pattern> result = new LinkedList<Pattern>(); Scanner scanner = new Scanner(logPattern); while (scanner.hasNextLine()) { String line = scanner.nextLine(); Pattern pattern = Pattern.compile(line); result.add(pattern); } return result; }
/** * Checks if the logs of the given run match any of the given patterns, line-by-line. * * @param matrixRun The run to be considered. * @param patterns The patterns to match with. * @return True if at least one line of the logs match at least one of the given patterns. * @throws IOException If there's a problem reading the log file. */ private boolean matchesPattern(MatrixRun matrixRun, List<Pattern> patterns) throws IOException { if (patterns == null || patterns.isEmpty()) { return true; // No specific patterns specified. Accept everything. } BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream(matrixRun.getLogFile()), matrixRun.getCharset())); try { for (String line = reader.readLine(); line != null; line = reader.readLine()) { for (Pattern pattern : patterns) { Matcher matcher = pattern.matcher(line); if (matcher.find()) { return true; } } } } finally { reader.close(); } return false; }