You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/08/26 16:53:08 UTC

svn commit: r240253 - /xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BatchDiffer.java

Author: jeremias
Date: Fri Aug 26 07:53:01 2005
New Revision: 240253

URL: http://svn.apache.org/viewcvs?rev=240253&view=rev
Log:
Two new config values: stop-on-exception and create-diffs.

Modified:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BatchDiffer.java

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BatchDiffer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BatchDiffer.java?rev=240253&r1=240252&r2=240253&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BatchDiffer.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BatchDiffer.java Fri Aug 26 07:53:01 2005
@@ -61,6 +61,8 @@
  *   <max-files>10</max-files>
  *   <target-directory>C:/Temp/diff-out</target-directory>
  *   <resolution>100</resolution>
+ *   <stop-on-exception>false</stop-on-exception>
+ *   <create-diffs>false</create-diffs>
  *   <stylesheet>C:/Dev/FOP/trunk/test/layoutengine/testcase2fo.xsl</stylesheet>
  *   <producers>
  *     <producer classname="org.apache.fop.visual.BitmapProducerJava2D">
@@ -82,6 +84,12 @@
  * The optional "resolution" element controls the requested bitmap resolution in dpi for the
  * generated bitmaps. Defaults to 72dpi.
  * <p>
+ * The optional "stop-on-exception" element controls whether the batch should be aborted when
+ * an exception is caught. Defaults to true.
+ * <p>
+ * The optional "create-diffs" element controls whether the diff images should be created.
+ * Defaults to true.
+ * <p>
  * The optional "stylesheet" element allows you to supply an XSLT stylesheet to preprocess all
  * source files with. Default: no stylesheet, identity transform.
  * <p>
@@ -168,6 +176,9 @@
             }
             context.setTargetDir(targetDir);
             
+            boolean stopOnException = cfg.getChild("stop-on-exception").getValueAsBoolean(true);
+            boolean createDiffs = cfg.getChild("create-diffs").getValueAsBoolean(true);
+            
             //RUN!
             BufferedImage[] bitmaps = new BufferedImage[producers.length];
             
@@ -181,29 +192,42 @@
             Collection files = FileUtils.listFiles(srcDir, filter, null);
             Iterator i = files.iterator();
             while (i.hasNext()) {
-                File f = (File)i.next();
-                log.info("---=== " + f + " ===---");
-                for (int j = 0; j < producers.length; j++) {
-                    bitmaps[j] = producers[j].produce(f, context);
-                }
-                //Create combined image
-                if (bitmaps[0] == null) {
-                    throw new RuntimeException("First producer didn't return a bitmap."
-                            + " Cannot continue.");
-                }
-                BufferedImage combined = BitmapComparator.buildCompareImage(bitmaps);
-                
-                //Save combined bitmap as PNG file
-                File outputFile = new File(targetDir, f.getName() + "._combined.png");
-                saveAsPNG(combined, outputFile);
-
-                for (int k = 1; k < bitmaps.length; k++) {
-                    BufferedImage diff = BitmapComparator.buildDiffImage(bitmaps[0], bitmaps[k]);
-                    outputFile = new File(targetDir, f.getName() + "._diff" + k + ".png");
-                    saveAsPNG(diff, outputFile);
-                    bitmaps[k] = null;
+                try {
+                    File f = (File)i.next();
+                    log.info("---=== " + f + " ===---");
+                    for (int j = 0; j < producers.length; j++) {
+                        bitmaps[j] = producers[j].produce(f, context);
+                    }
+                    //Create combined image
+                    if (bitmaps[0] == null) {
+                        throw new RuntimeException("First producer didn't return a bitmap."
+                                + " Cannot continue.");
+                    }
+                    BufferedImage combined = BitmapComparator.buildCompareImage(bitmaps);
+                    
+                    //Save combined bitmap as PNG file
+                    File outputFile = new File(targetDir, f.getName() + "._combined.png");
+                    saveAsPNG(combined, outputFile);
+
+                    if (createDiffs) {
+                        for (int k = 1; k < bitmaps.length; k++) {
+                            BufferedImage diff = BitmapComparator.buildDiffImage(
+                                    bitmaps[0], bitmaps[k]);
+                            outputFile = new File(targetDir, f.getName() + "._diff" + k + ".png");
+                            saveAsPNG(diff, outputFile);
+                        }
+                    }
+                    //Release memory as soon as possible. These images are huge!
+                    for (int k = 0; k < bitmaps.length; k++) {
+                        bitmaps[k] = null;
+                    }
+                } catch (RuntimeException e) {
+                    System.out.println("Catching RE: " + e.getMessage());
+                    if (stopOnException) {
+                        System.out.println("rethrowing...");
+                        throw e;
+                    }
                 }
-                bitmaps[0] = null;
                 maxfiles = (maxfiles < 0 ? maxfiles : maxfiles - 1);
                 if (maxfiles == 0) {
                     break;



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org