Index: jrst2/src/test/org/codelutin/jrst/Compare.java diff -u jrst2/src/test/org/codelutin/jrst/Compare.java:1.6 jrst2/src/test/org/codelutin/jrst/Compare.java:1.7 --- jrst2/src/test/org/codelutin/jrst/Compare.java:1.6 Thu May 31 18:46:25 2007 +++ jrst2/src/test/org/codelutin/jrst/Compare.java Wed Jun 20 13:59:18 2007 @@ -1,10 +1,14 @@ +/** + * Class de test pour comparer le XML de DocUtils avec celui du JRST + * + */ package org.codelutin.jrst; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; +import java.io.StringReader; import java.io.StringWriter; import java.net.URL; import java.util.LinkedList; @@ -25,144 +29,143 @@ import sdoc.*; public class Compare { - static boolean[] bColorRst ; - static boolean[] bColorPython; - private static final String PATH="/home/letellier/PROJET/jrst2/"; // a - // redefinir - // manuelement - static public void main(String [] args) throws Exception { - File source = null; - if (args.length>0){ - source = new File(args[0]); - if (source != null) - parser(source); - } - else - System.err.println("Argument source manquant"); - } - private static void parser(File source) throws Exception { - URL url = source.toURL(); - Reader in = new InputStreamReader(url.openStream()); + static boolean[] bColorRst; + + static boolean[] bColorPython; + + private static final String PATH = "/home/letellier/PROJET/jrst2/"; // a + + // redefinir + // manuelement + static public void main(String[] args) throws Exception { + File source = null; + if (args.length > 0) { + source = new File(args[0]); + if (source != null) + parser(source); + } else + System.err.println("Argument source manquant"); + } + + @SuppressWarnings("deprecation") + private static void parser(File source) throws Exception { + URL url = source.toURL(); + Reader in = new InputStreamReader(url.openStream()); JRSTReader jrst = new JRSTReader(); Document docRst = jrst.read(in); // JRST - String cmd = "rst2xml "+PATH+source.getPath()+" "+PATH+"src/test/org/codelutin/jrst/comparePython.xml"; - Runtime.getRuntime().exec("rm "+PATH+"src/test/org/codelutin/jrst/comparePython.xml"); - final Process p =Runtime.getRuntime().exec(cmd); // Python - Thread t = new Thread() { - public void run() { - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream())); - String line = ""; - try { - while((line = reader.readLine()) != null) { - System.err.println(line); // Pour rediriger la - // sortie des érreurs - } - } finally { - reader.close(); - } - } catch(IOException ioe) { - ioe.printStackTrace(); - } - } - }; + String cmd = "rst2xml " + source.getPath(); + Process p = Runtime.getRuntime().exec(cmd); // Python + ThreadRedirection t = new ThreadRedirection(p); t.start(); - while(t.isAlive()); // On attend que le processus ce termine + p.waitFor(); // On attend que le processus ce termine + String strPython=t.getSortit().replaceAll("null",""); t.stop(); p.destroy(); - File xml = new File("src/test/org/codelutin/jrst/comparePython.xml"); - SAXReader sr= new SAXReader(); - Document docPython = sr.read(xml); + SAXReader sr = new SAXReader(); + Document docPython = sr.read(new StringReader(t.getSortit())); String diff = test(docRst, docPython); - String sDocRst = indent(docRst); // On indente + String sDocRst = indent(docRst); // On indente String sDocPython = indent(docPython); compare(sDocRst, sDocPython, diff); - } - private static String test(Document docRst, Document docPython) throws Exception { - String[] sDocRst = indent(docRst).split("\n"); + } + + private static String test(Document docRst, Document docPython) + throws Exception { + String[] sDocRst = indent(docRst).split("\n"); bColorRst = new boolean[sDocRst.length]; - for (int i=0;i names = new LinkedList(); LinkedList rgs = new LinkedList(); - while (matcher2.find()){ - names.add(matcher2.group().substring(1,matcher2.group().indexOf("["))); - rgs.add(Integer.valueOf(matcher2.group().substring(matcher2.group().indexOf("[")+1,matcher2.group().indexOf("]")))); + while (matcher2.find()) { + names.add(matcher2.group().substring(1, + matcher2.group().indexOf("["))); + rgs.add(Integer.valueOf(matcher2.group().substring( + matcher2.group().indexOf("[") + 1, + matcher2.group().indexOf("]")))); } - int cntName=0; - int nbLine=0; - for (String name : names){ - int trouve=0; - for (int i=nbLine;i