You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by bo...@apache.org on 2010/06/01 10:10:34 UTC

svn commit: r949962 - /incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/Report.java

Author: bodewig
Date: Tue Jun  1 08:10:34 2010
New Revision: 949962

URL: http://svn.apache.org/viewvc?rev=949962&view=rev
Log:
add a cli option for a custom XSLT stylesheet.  RAT-75

Modified:
    incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/Report.java

Modified: incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/Report.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/Report.java?rev=949962&r1=949961&r2=949962&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/Report.java (original)
+++ incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/Report.java Tue Jun  1 08:10:34 2010
@@ -21,6 +21,7 @@ package org.apache.rat;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
 import java.io.IOException;
@@ -68,6 +69,7 @@ import org.xml.sax.SAXException;
 public class Report {
 
     private static final char EXCLUDE_CLI = 'e';
+    private static final char STYLESHEET_CLI = 's';
 
     //@SuppressWarnings("unchecked")
     public static final void main(String args[]) throws Exception {
@@ -107,9 +109,27 @@ public class Report {
             if (cl.hasOption('x')) {
                 report.report(System.out);
             } else {
-                report.styleReport(System.out);
+                if (!cl.hasOption(STYLESHEET_CLI)) {
+                    report.styleReport(System.out);
+                } else {
+                    String[] style = cl.getOptionValues(STYLESHEET_CLI);
+                    if (style.length != 1) {
+                        System.err.println("please specify a single stylesheet");
+                        System.exit(1);
+                    }
+                    try {
+                        report.report(System.out,
+                                      report.getDirectory(System.out),
+                                      new FileInputStream(style[0]),
+                                      Defaults.createDefaultMatcher(), null);
+                    } catch (FileNotFoundException fnfe) {
+                        System.err.println("stylesheet " + style[0]
+                                           + " doesn't exist");
+                        System.exit(1);
+                    }
+                }
             }
-        } 
+        }
     }
 
     private static Options buildOptions() {
@@ -164,6 +184,12 @@ public class Report {
         "Used to indicate source when using --exclude");
         opts.addOption(dir);
 
+        Option xslt = new Option(String.valueOf(STYLESHEET_CLI),
+                                 "stylesheet",
+                                 true,
+                                 "XSLT stylesheet to use when creating the"
+                                 + " report");
+        opts.addOption(xslt);
         return opts;
     }