# HG changeset patch # User Peter Mehlitz # Date 1426123232 25200 # Node ID a51545ab397e976299743ce7fdef49dab71bf25c # Parent ca88bd8e918cf67fe40e0f9947df11df05e71699 modified PathOutputMonitor to allow in-situ path specs. If the pom.{all|any|none} value starts with a double quote it is taken as the output spec. Also added a VerbatimOutputSpec in case we don't want regex matching diff -r ca88bd8e918c -r a51545ab397e src/main/gov/nasa/jpf/listener/PathOutputMonitor.java --- a/src/main/gov/nasa/jpf/listener/PathOutputMonitor.java Wed Feb 25 13:03:40 2015 -0800 +++ b/src/main/gov/nasa/jpf/listener/PathOutputMonitor.java Wed Mar 11 18:20:32 2015 -0700 @@ -56,8 +56,8 @@ */ public class PathOutputMonitor extends PropertyListenerAdapter { - static final String SEPARATOR = "~~~~~"; - static final String ELLIPSIS = ". . ."; + static final String SEPARATOR = "~~~"; + static final String ELLIPSIS = "..."; static Logger log = JPF.getLogger("gov.nasa.jpf.listener.PathOutputMonitor"); @@ -65,6 +65,53 @@ boolean add (String spec); boolean matches (String[] output); void printOn (PrintWriter pw); + boolean isEmpty(); + } + + static class VerbatimOutputSpec implements PathOutputSpec { + ArrayList patterns = new ArrayList(); + + @Override + public boolean add (String spec) { + patterns.add(spec); + return true; + } + + @Override + public boolean matches (String[] output) { + if ((output != null) && (output.length > 0)) { + Iterator it = patterns.iterator(); + for (String line : output) { + if (it.hasNext()) { + String p = it.next(); + if (!p.equals(line)){ + return false; + } + } else { + return false; + } + } + + return !it.hasNext(); + + } else { + return patterns.isEmpty(); + } + } + + // sometimes, duck typing would be nice.. + + @Override + public void printOn (PrintWriter pw) { + for (String p : patterns) { + pw.println(p.toString()); + } + } + + @Override + public boolean isEmpty(){ + return patterns.isEmpty(); + } } // simple regular expression matchers (could be a more sophisticated parser) @@ -72,7 +119,7 @@ ArrayList patterns = new ArrayList(); @Override - public boolean add (String spec) { + public boolean add (String spec) { try { Pattern p = Pattern.compile(spec); patterns.add(p); @@ -84,7 +131,7 @@ } @Override - public boolean matches (String[] output) { + public boolean matches (String[] output) { if ((output != null) && (output.length > 0)) { Iterator it = patterns.iterator(); @@ -113,11 +160,16 @@ } @Override - public void printOn (PrintWriter pw) { + public void printOn (PrintWriter pw) { for (Pattern p : patterns) { pw.println(p.toString()); } } + + @Override + public boolean isEmpty(){ + return patterns.isEmpty(); + } } //---- our instance data @@ -163,13 +215,22 @@ List loadSpecs(Config conf, String key) { - String fname = conf.getString(key); - if (fname != null) { - File file = new File(fname); - if (file.exists()) { - return readPathPatterns(file); - } else { - log.warning("pattern file not found: " + fname); + String spec = conf.getString(key); + if (spec != null) { + if (spec.startsWith("\"")){ // spec is in-situ content (convenience method for test classes) + spec = spec.substring(1, spec.length()-1); + BufferedReader br = new BufferedReader( new StringReader(spec)); + return readPathPatterns(br); + + } else { // spec is pathname of output sepc file + File file = new File(spec); + try { + BufferedReader br = new BufferedReader( new FileReader(file)); + return readPathPatterns(br); + + } catch (FileNotFoundException fnfx){ + log.warning("pattern file not found: " + spec); + } } } @@ -185,22 +246,23 @@ } } - List readPathPatterns (File f){ + + + List readPathPatterns (BufferedReader br){ ArrayList results = new ArrayList(); // prefix pattern goes into file try { - FileReader fr = new FileReader(f); - BufferedReader br = new BufferedReader(fr); - PathOutputSpec ps = createPathOutputSpec(); + int lineno = 0; for (String line=br.readLine(); true; line = br.readLine()) { if (line == null) { results.add(ps); break; } + lineno++; if (line.startsWith(SEPARATOR)) { results.add(ps);