diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineIterator.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineIterator.java new file mode 100644 index 0000000000000000000000000000000000000000..9ad1f288a55201efc6d89e60277222fe982b8cd1 --- /dev/null +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineIterator.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2017, 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 com.oracle.truffle.r.test.packages.analyzer; + +import java.io.BufferedReader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.NoSuchElementException; + +public class FileLineIterator extends LineIterator { + + /** Maximum number of lines that will be analyzed. */ + public static final int MAX_LINES = 500000; + + private int cnt = 0; + private BufferedReader reader; + private String lookahead = null; + + public FileLineIterator(Path p) { + try { + this.reader = Files.newBufferedReader(p); + nextLine(); + } catch (IOException e) { + // ignore + } + } + + @Override + public void close() throws IOException { + if (reader != null) { + reader.close(); + } + } + + private String nextLine() { + + if (cnt++ >= MAX_LINES) { + return null; + } + String line = lookahead; + try { + lookahead = reader.readLine(); + } catch (IOException e) { + + } + return line; + } + + @Override + public boolean hasNext() { + return cnt < MAX_LINES && lookahead != null; + } + + @Override + public String next() { + if (hasNext()) { + return nextLine(); + } + throw new NoSuchElementException(); + } +} diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineListReader.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineListReader.java index aabc942a40aa414441796a234694b635441d8c69..1dfe699153fcb01cebda5888f8355966a9adc860 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineListReader.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineListReader.java @@ -28,31 +28,38 @@ import java.util.List; public class FileLineListReader extends FileLineReader { - private final Iterator<String> it; - private final boolean empty; + private final List<String> l; public FileLineListReader(List<String> lines) { - Iterator<String> iterator = lines.iterator(); - this.it = iterator; - this.empty = !iterator.hasNext(); - } - - @Override - public String readLine() throws IOException { - if (!it.hasNext()) { - return null; - } - return it.next(); + this.l = lines; } @Override public boolean isEmpty() { - return empty; + return l.isEmpty(); } @Override - public Iterator<String> iterator() { - return it; + public LineIterator iterator() { + return new LineIterator() { + + private final Iterator<String> it = l.iterator(); + + @Override + public void close() throws IOException { + // nothing to do + } + + @Override + public String next() { + return it.next(); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + }; } } diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineReader.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineReader.java index adfc223aa69679a94a19e0a3cc5a4b97aad9d7bb..e8200cbcad560e6541b9d2cc91b49754605c5331 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineReader.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineReader.java @@ -22,12 +22,11 @@ */ package com.oracle.truffle.r.test.packages.analyzer; -import java.io.IOException; - public abstract class FileLineReader implements Iterable<String> { - public abstract String readLine() throws IOException; - public abstract boolean isEmpty(); + @Override + public abstract LineIterator iterator(); + } diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineStreamReader.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineStreamReader.java index 0589724e9fb9c91050ab770b982b341a2ae151a0..bdb7d03bd63f060e83598983353d37f6636a9dbb 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineStreamReader.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/FileLineStreamReader.java @@ -22,71 +22,31 @@ */ package com.oracle.truffle.r.test.packages.analyzer; -import java.io.BufferedReader; import java.io.IOException; -import java.util.Iterator; -import java.util.NoSuchElementException; +import java.nio.file.Files; +import java.nio.file.Path; public class FileLineStreamReader extends FileLineReader { - /** Maximum number of lines that will be analyzed. */ - public static final int MAX_LINES = 50000; - private final BufferedReader reader; - private int cnt = 0; - private String lookahead = null; - private boolean empty; + private final Path p; - public FileLineStreamReader(BufferedReader in) { - this.reader = in; - empty = true; - try { - nextLine(); - empty = lookahead == null; - } catch (IOException e) { - // ignore - } - - } - - private String nextLine() throws IOException { - if (cnt++ >= MAX_LINES) { - throw new IOException("File is too large for analysis."); - } - String line = lookahead; - lookahead = reader.readLine(); - return line; - } + public FileLineStreamReader(Path p) { + this.p = p; - @Override - public String readLine() throws IOException { - return nextLine(); } @Override public boolean isEmpty() { - return empty; + try { + return Files.size(p) == 0; + } catch (IOException e) { + } + return true; } @Override - public Iterator<String> iterator() { - return new Iterator<String>() { - - @Override - public boolean hasNext() { - return lookahead != null; - } - - @Override - public String next() { - if (hasNext()) { - try { - return nextLine(); - } catch (IOException e) { - } - } - throw new NoSuchElementException(); - } - }; + public LineIterator iterator() { + return new FileLineIterator(p); } } diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/LineIterator.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/LineIterator.java new file mode 100644 index 0000000000000000000000000000000000000000..c84f3f133dd3acd000597d104fbcf2cf34087c1d --- /dev/null +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/LineIterator.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017, 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 com.oracle.truffle.r.test.packages.analyzer; + +import java.io.Closeable; +import java.util.Iterator; + +public abstract class LineIterator implements Iterator<String>, Closeable { + +} diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/ConfigureErrorDetector.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/ConfigureErrorDetector.java index 324fa59d33fac1628784716f48f032b0f5636d6d..2b7621d8b7439bb80a36b7f59eec1a853a94f524 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/ConfigureErrorDetector.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/ConfigureErrorDetector.java @@ -22,9 +22,11 @@ */ package com.oracle.truffle.r.test.packages.analyzer.detectors; +import java.io.IOException; import java.util.Collection; import java.util.LinkedList; +import com.oracle.truffle.r.test.packages.analyzer.LineIterator; import com.oracle.truffle.r.test.packages.analyzer.FileLineReader; import com.oracle.truffle.r.test.packages.analyzer.Location; import com.oracle.truffle.r.test.packages.analyzer.Problem; @@ -49,13 +51,18 @@ public class ConfigureErrorDetector extends LineDetector { Collection<Problem> problems = new LinkedList<>(); assert body.isEmpty() || startLocation != null; int lineNr = startLocation != null ? startLocation.lineNr : 0; - for (String line : body) { - if (line.startsWith(PREFIX)) { - String message = line.substring(PREFIX.length()); - problems.add(new ConfigureErrorProblem(pkgTestRun, this, new Location(startLocation.file, lineNr), message)); - + try (LineIterator it = body.iterator()) { + while (it.hasNext()) { + String line = it.next(); + if (line.startsWith(PREFIX)) { + String message = line.substring(PREFIX.length()); + problems.add(new ConfigureErrorProblem(pkgTestRun, this, new Location(startLocation.file, lineNr), message)); + + } + ++lineNr; } - ++lineNr; + } catch (IOException e) { + // ignore } return problems; } diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/Detector.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/Detector.java index c31440649cba71515cdc2b3320fb2bd790d327f7..f1e22de6a12f4e0b06fa4dd04b0af61fa424561a 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/Detector.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/Detector.java @@ -61,6 +61,6 @@ public abstract class Detector<T> { * @param body The content to analyze (e.g. a list of lines in a file). * @return A list of detected problems (must not be {@code null}). */ - public abstract Collection<Problem> detect(RPackageTestRun pkgTestRun, Location startLineLocation, T body) throws IOException; + public abstract Collection<Problem> detect(RPackageTestRun pkgTestRun, Location startLineLocation, T body); } diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/InstallationProblemDetector.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/InstallationProblemDetector.java index d975a8a359080371bf40d8ae8b7725e2d2bef31b..8e4cb00b9fa85a76ac71111f1ed670636628619e 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/InstallationProblemDetector.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/InstallationProblemDetector.java @@ -22,11 +22,13 @@ */ package com.oracle.truffle.r.test.packages.analyzer.detectors; +import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.oracle.truffle.r.test.packages.analyzer.LineIterator; import com.oracle.truffle.r.test.packages.analyzer.FileLineReader; import com.oracle.truffle.r.test.packages.analyzer.Location; import com.oracle.truffle.r.test.packages.analyzer.Problem; @@ -49,12 +51,17 @@ public class InstallationProblemDetector extends LineDetector { @Override public Collection<Problem> detect(RPackageTestRun pkg, Location startLocation, FileLineReader body) { int lineNr = startLocation.lineNr; - for (String line : body) { - Matcher matcher = pattern.matcher(line); - if (matcher.matches()) { - return Collections.singletonList(new PackageInstallationProblem(pkg, this, new Location(startLocation.file, lineNr), line)); + try (LineIterator it = body.iterator()) { + while (it.hasNext()) { + String line = it.next(); + Matcher matcher = pattern.matcher(line); + if (matcher.matches()) { + return Collections.singletonList(new PackageInstallationProblem(pkg, this, new Location(startLocation.file, lineNr), line)); + } + ++lineNr; } - ++lineNr; + } catch (IOException e) { + // ignore } return Collections.emptyList(); } diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/RErrorDetector.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/RErrorDetector.java index 1a586f6eed723694f11b41398f7de8e3efc4e712..59a4525d2c205b472a588d79ab3d888677462f45 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/RErrorDetector.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/RErrorDetector.java @@ -22,12 +22,13 @@ */ package com.oracle.truffle.r.test.packages.analyzer.detectors; +import java.io.IOException; import java.util.Collection; -import java.util.Iterator; import java.util.LinkedList; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.oracle.truffle.r.test.packages.analyzer.LineIterator; import com.oracle.truffle.r.test.packages.analyzer.FileLineReader; import com.oracle.truffle.r.test.packages.analyzer.Location; import com.oracle.truffle.r.test.packages.analyzer.Problem; @@ -55,21 +56,24 @@ public class RErrorDetector extends LineDetector { int lineOffset = startLocation != null ? startLocation.lineNr : 0; int i = -1; - Iterator<String> it = body.iterator(); - while (it.hasNext()) { - String line = it.next(); - ++i; - Matcher matcher = PATTERN.matcher(line); - if (matcher.matches()) { - String callString = matcher.group("CALLSTR"); - String message = matcher.group("MSG"); - if (message.trim().isEmpty() && it.hasNext()) { - // message could be in the next line - message = it.next(); - ++i; + try (LineIterator it = body.iterator()) { + while (it.hasNext()) { + String line = it.next(); + ++i; + Matcher matcher = PATTERN.matcher(line); + if (matcher.matches()) { + String callString = matcher.group("CALLSTR"); + String message = matcher.group("MSG"); + if (message.trim().isEmpty() && it.hasNext()) { + // message could be in the next line + message = it.next(); + ++i; + } + problems.add(new RErrorProblem(pkg, this, new Location(startLocation.file, i + lineOffset), callString, message)); } - problems.add(new RErrorProblem(pkg, this, new Location(startLocation.file, i + lineOffset), callString, message)); } + } catch (IOException e) { + // ignore } return problems; diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/RInternalErrorDetector.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/RInternalErrorDetector.java index 6283bc19d5cf83a8d093988c69b0ca2eb7a50fa0..5f570e0344f312c95a30cd9031d2006e0b4cb5be 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/RInternalErrorDetector.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/RInternalErrorDetector.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.util.Collection; import java.util.LinkedList; +import com.oracle.truffle.r.test.packages.analyzer.LineIterator; import com.oracle.truffle.r.test.packages.analyzer.FileLineReader; import com.oracle.truffle.r.test.packages.analyzer.Location; import com.oracle.truffle.r.test.packages.analyzer.Problem; @@ -42,22 +43,25 @@ public class RInternalErrorDetector extends LineDetector { @Override public String getName() { - // TODO Auto-generated method stub return null; } @Override - public Collection<Problem> detect(RPackageTestRun pkg, Location startLocation, FileLineReader body) throws IOException { + public Collection<Problem> detect(RPackageTestRun pkg, Location startLocation, FileLineReader body) { Collection<Problem> problems = new LinkedList<>(); int lineNr = startLocation != null ? startLocation.lineNr : 0; - String line = null; - while ((line = body.readLine()) != null) { - int indexOf = line.indexOf(P); - if (indexOf != -1) { - String message = line.substring(indexOf + P.length()); - problems.add(new RInternalErrorProblem(pkg, this, new Location(startLocation.file, lineNr), message)); + try (LineIterator it = body.iterator()) { + while (it.hasNext()) { + String line = it.next(); + int indexOf = line.indexOf(P); + if (indexOf != -1) { + String message = line.substring(indexOf + P.length()); + problems.add(new RInternalErrorProblem(pkg, this, new Location(startLocation.file, lineNr), message)); + } + ++lineNr; } - ++lineNr; + } catch (IOException e) { + // ignore } return problems; } diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/SegfaultDetector.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/SegfaultDetector.java index 0c601f37f252b59979f74febc933c0fa9da55ce3..be6844240ffdaf2adbdc26444659bab33bb73b5c 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/SegfaultDetector.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/SegfaultDetector.java @@ -22,9 +22,11 @@ */ package com.oracle.truffle.r.test.packages.analyzer.detectors; +import java.io.IOException; import java.util.Collection; import java.util.Collections; +import com.oracle.truffle.r.test.packages.analyzer.LineIterator; import com.oracle.truffle.r.test.packages.analyzer.FileLineReader; import com.oracle.truffle.r.test.packages.analyzer.Location; import com.oracle.truffle.r.test.packages.analyzer.Problem; @@ -50,22 +52,27 @@ public class SegfaultDetector extends LineDetector { assert body.isEmpty() || startLocation != null; int lineNr = startLocation != null ? startLocation.lineNr : 0; boolean takeNextLine = false; - for (String line : body) { - if (line.contains(SIGSEGV_START)) { - collect = true; - } - if (collect) { - if (takeNextLine) { - segfaultMessage.append(line); - takeNextLine = false; + try (LineIterator it = body.iterator()) { + while (it.hasNext()) { + String line = it.next(); + if (line.contains(SIGSEGV_START)) { + collect = true; } - if (line.contains("Problematic frame")) { - takeNextLine = true; - } else if (!line.contains("#")) { - break; + if (collect) { + if (takeNextLine) { + segfaultMessage.append(line); + takeNextLine = false; + } + if (line.contains("Problematic frame")) { + takeNextLine = true; + } else if (!line.contains("#")) { + break; + } } + ++lineNr; } - ++lineNr; + } catch (IOException e) { + // ignore } if (collect) { return Collections.singleton(new SegfaultProblem(pkg, this, new Location(startLocation.file, lineNr), segfaultMessage.toString())); diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/SymbolLookupErrorDetector.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/SymbolLookupErrorDetector.java index 4676780e54482e8a526a42bbb4c53a032920dc6d..d69f84bd3b0ee83b91d3bb7cff7e18b4e6955888 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/SymbolLookupErrorDetector.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/SymbolLookupErrorDetector.java @@ -22,11 +22,13 @@ */ package com.oracle.truffle.r.test.packages.analyzer.detectors; +import java.io.IOException; import java.util.Collection; import java.util.LinkedList; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.oracle.truffle.r.test.packages.analyzer.LineIterator; import com.oracle.truffle.r.test.packages.analyzer.FileLineReader; import com.oracle.truffle.r.test.packages.analyzer.Location; import com.oracle.truffle.r.test.packages.analyzer.Problem; @@ -50,14 +52,19 @@ public final class SymbolLookupErrorDetector extends LineDetector { public Collection<Problem> detect(RPackageTestRun pkgTestRun, Location startLocation, FileLineReader body) { Collection<Problem> problems = new LinkedList<>(); int lineNr = startLocation != null ? startLocation.lineNr : 0; - for (String line : body) { - Matcher matcher = PATTERN.matcher(line); - if (matcher.matches()) { - String message = matcher.group("MSG"); - problems.add(new SymbolLookupErrorProblem(pkgTestRun, this, new Location(startLocation.file, lineNr), message)); - + try (LineIterator it = body.iterator()) { + while (it.hasNext()) { + String line = it.next(); + Matcher matcher = PATTERN.matcher(line); + if (matcher.matches()) { + String message = matcher.group("MSG"); + problems.add(new SymbolLookupErrorProblem(pkgTestRun, this, new Location(startLocation.file, lineNr), message)); + + } + ++lineNr; } - ++lineNr; + } catch (IOException e) { + // ignore } return problems; } diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/UnsupportedSpecializationDetector.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/UnsupportedSpecializationDetector.java index 260e7a09cb992670a7778797997e245285caacc6..d5a3ea7b2ee5be3048ab1b4f6a3bdd3dddb47575 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/UnsupportedSpecializationDetector.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/detectors/UnsupportedSpecializationDetector.java @@ -22,11 +22,13 @@ */ package com.oracle.truffle.r.test.packages.analyzer.detectors; +import java.io.IOException; import java.util.Collection; import java.util.LinkedList; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.oracle.truffle.r.test.packages.analyzer.LineIterator; import com.oracle.truffle.r.test.packages.analyzer.FileLineReader; import com.oracle.truffle.r.test.packages.analyzer.Location; import com.oracle.truffle.r.test.packages.analyzer.Problem; @@ -55,14 +57,19 @@ public class UnsupportedSpecializationDetector extends LineDetector { assert body.isEmpty() || startLocation != null; int lineNr = startLocation != null ? startLocation.lineNr : 0; int problemStartLine = lineNr; - for (String line : body) { - Matcher matcher = PATTERN.matcher(line); - if (matcher.find()) { - message = matcher.group("MSG"); - problemStartLine = lineNr; - problems.add(new UnsupportedSpecializationProblem(pkg, this, new Location(startLocation.file, problemStartLine), message)); + try (LineIterator it = body.iterator()) { + while (it.hasNext()) { + String line = it.next(); + Matcher matcher = PATTERN.matcher(line); + if (matcher.find()) { + message = matcher.group("MSG"); + problemStartLine = lineNr; + problems.add(new UnsupportedSpecializationProblem(pkg, this, new Location(startLocation.file, problemStartLine), message)); + } + ++lineNr; } - ++lineNr; + } catch (IOException e) { + // ignore } return problems; } diff --git a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/parser/LogFileParser.java b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/parser/LogFileParser.java index 25abcbbc3eccf890dcd5a94514530a5d4c3b1d99..bc3d8810a570fa4edee155a745f8ba12b6bb73b9 100644 --- a/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/parser/LogFileParser.java +++ b/com.oracle.truffle.r.test.packages.analyzer/src/com/oracle/truffle/r/test/packages/analyzer/parser/LogFileParser.java @@ -32,7 +32,6 @@ import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -179,23 +178,15 @@ public class LogFileParser { if (Files.isReadable(outputFile)) { ignoreFiles.add(outputFile); - try (BufferedReader in = Files.newBufferedReader(outputFile)) { - checkResults.problems.addAll(applyDetectors(Token.OUTPUT_MISMATCH_FASTR, outputFile, 0, new FileLineStreamReader(in))); - } catch (IOException e) { - // silently ignore - } + checkResults.problems.addAll(applyDetectors(Token.OUTPUT_MISMATCH_FASTR, outputFile, 0, new FileLineStreamReader(outputFile))); } else { // try to find the file anywhere in the test run directory (there were some // cases) Optional<Path> findFirst = null; findFirst = Files.find(logFile.path.getParent(), 3, (path, attr) -> path.getFileName().equals(outputFile.getFileName())).findFirst(); if (findFirst.isPresent()) { - try (BufferedReader in = Files.newBufferedReader(findFirst.get())) { - ignoreFiles.add(findFirst.get()); - checkResults.problems.addAll(applyDetectors(Token.OUTPUT_MISMATCH_FASTR, findFirst.get(), 0, new FileLineStreamReader(in))); - } catch (IOException e) { - // silently ignore - } + ignoreFiles.add(findFirst.get()); + checkResults.problems.addAll(applyDetectors(Token.OUTPUT_MISMATCH_FASTR, findFirst.get(), 0, new FileLineStreamReader(findFirst.get()))); } if (findFirst == null || !findFirst.isPresent()) { LOGGER.warning("Cannot read output file " + outputFile); @@ -314,15 +305,11 @@ public class LogFileParser { // apply detectors to diff chunks testing.problems.addAll(applyTestResultDetectors(diffResult)); diffResult.stream().forEach(chunk -> { - try { - if (!chunk.getLeft().isEmpty()) { - testing.problems.addAll(applyDetectors(Token.RUNNING_SPECIFIC_TESTS, chunk.getLeftFile(), chunk.getLeftStartLine(), new FileLineListReader(chunk.getLeft()))); - } - if (!chunk.getRight().isEmpty()) { - testing.problems.addAll(applyDetectors(Token.RUNNING_SPECIFIC_TESTS, chunk.getRightFile(), chunk.getRightStartLine(), new FileLineListReader(chunk.getRight()))); - } - } catch (IOException e) { - // ignore, since this won't happen here + if (!chunk.getLeft().isEmpty()) { + testing.problems.addAll(applyDetectors(Token.RUNNING_SPECIFIC_TESTS, chunk.getLeftFile(), chunk.getLeftStartLine(), new FileLineListReader(chunk.getLeft()))); + } + if (!chunk.getRight().isEmpty()) { + testing.problems.addAll(applyDetectors(Token.RUNNING_SPECIFIC_TESTS, chunk.getRightFile(), chunk.getRightStartLine(), new FileLineListReader(chunk.getRight()))); } }); @@ -344,7 +331,6 @@ public class LogFileParser { if (laMatches("Running ")) { consumeLine(); } - // TODO anything more to parse ? testing.problems.addAll(applyDetectors(Token.RUNNING_VIGNETTES, logFile.path, collectBody(Token.END_TESTING))); } @@ -437,11 +423,7 @@ public class LogFileParser { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (endsWith(file, ".Rout", ".fail") && includeCheck.test(file)) { - try (BufferedReader in = Files.newBufferedReader(file)) { - outputCheck.problems.addAll(applyDetectors(Token.BEGIN_CHECKING, file, 0, new FileLineStreamReader(in))); - } catch (IOException e) { - LOGGER.severe(String.format("Error analyzing output file %s: %s", file, e.getMessage())); - } + outputCheck.problems.addAll(applyDetectors(Token.BEGIN_CHECKING, file, 0, new FileLineStreamReader(file))); } return FileVisitResult.CONTINUE; } @@ -468,7 +450,7 @@ public class LogFileParser { }); } - private Collection<Problem> applyDetectors(Token start, Path file, List<Line> body) throws IOException { + private Collection<Problem> applyDetectors(Token start, Path file, List<Line> body) { if (!body.isEmpty()) { Line firstLine = body.get(0); List<String> strBody = body.stream().map(l -> l.text).collect(Collectors.toList()); @@ -477,7 +459,7 @@ public class LogFileParser { return new LinkedList<>(); } - private Collection<Problem> applyDetectors(Token start, Path file, int startLineNr, FileLineReader body) throws IOException { + private Collection<Problem> applyDetectors(Token start, Path file, int startLineNr, FileLineReader body) { assert Files.isRegularFile(file); Location startLocation = null; if (!body.isEmpty()) { @@ -506,12 +488,7 @@ public class LogFileParser { private Collection<Problem> applyTestResultDetectors(List<DiffChunk> diffChunk) { return testResultDetectors.stream().map(detector -> { - try { - return detector.detect(pkg, null, diffChunk); - } catch (IOException e) { - // just abort, won't happen here - } - return Collections.<Problem> emptyList(); + return detector.detect(pkg, null, diffChunk); }).flatMap(l -> l.stream()).collect(Collectors.toList()); }