From rat-commits-returncassielucas@example.net Tue Jun 16 19:26:44 2009
Return-Path: <rat-commits-returncassielucas@example.net>
Delivered-To: cassielucas@example.net
Received: (qmail 31238 invoked from network); 16 Jun 2009 19:26:40 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155)
  by minotaur.apache.org with SMTP; 16 Jun 2009 19:26:40 -0000
Received: (qmail 43858 invoked by uid 500); 16 Jun 2009 19:26:51 -0000
Delivered-To: cassielucas@example.net
Received: (qmail 43835 invoked by uid 500); 16 Jun 2009 19:26:51 -0000
Mailing-List: contact cassielucas@example.net; run by ezmlm
Precedence: bulk
List-Help: <mailto:cassielucas@example.net>
List-Unsubscribe: <mailto:cassielucas@example.net>
List-Post: <mailto:cassielucas@example.net>
List-Id: <rat-commits.incubator.apache.org>
Reply-To: cassielucas@example.net
Delivered-To: mailing list cassielucas@example.net
Received: (qmail 43806 invoked by uid 99); 16 Jun 2009 19:26:47 -0000
Received: from athena.apache.org (HELO athena.apache.org) (83.161.120.155)
    by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jun 2009 19:26:47 +0000
X-ASF-Spam-Status: No, hits=-1998.9 required=10.0
	tests=ALL_TRUSTED,FB_GET_MEDS
X-Spam-Check-By: apache.org
Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155)
    by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jun 2009 19:26:45 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
	id 6B352238889D; Tue, 16 Jun 2009 19:26:25 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r785348 -
 /incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/Report.java
Date: Tue, 16 Jun 2009 19:26:25 -0000
To: cassielucas@example.net
From: cassielucas@example.net
X-Mailer: svnmailer-1.0.8
Message-Id: <cassielucas@example.net>
X-Virus-Checked: Checked by ClamAV on apache.org

Author: rdonkin
Date: Tue Jun 16 19:26:25 2009
New Revision: 785348

URL: http://svn.apache.org/viewvc?rev=785348&view=rev
Log:
RAT-2 Correct indentation https://issues.apache.org/jira/browse/RAT-2

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=785348&r1=785347&r2=785348&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 16 19:26:25 2009
@@ -58,143 +58,143 @@
 
 public class Report {
 
-	//@SuppressWarnings("unchecked")
-  public static final void main(String args[]) throws Exception {
-	  Options opts = new Options();
+    //@SuppressWarnings("unchecked")
+    public static final void main(String args[]) throws Exception {
+        Options opts = new Options();
 
-    Option help = new Option("h", "help", false,
+        Option help = new Option("h", "help", false,
         "Print help for the RAT command line interface and exit");
-    opts.addOption(help);
+        opts.addOption(help);
 
-    Option addLicence = new Option(
-        "a",
-        "addLicence",
-        false,
+        Option addLicence = new Option(
+                "a",
+                "addLicence",
+                false,
         "Add the default licence header to any file with an unknown licence that is not in the exclusion list. By default new files will be created with the licence header, to force the modification of existing files use the --force option.");
-    opts.addOption(addLicence);
-    
-    Option write = new Option(
-        "f",
-        "force",
-        false,
+        opts.addOption(addLicence);
+
+        Option write = new Option(
+                "f",
+                "force",
+                false,
         "Forces any changes in files to be written without confirmation");
-    opts.addOption(write);
+        opts.addOption(write);
 
-    Option copyright = new Option(
-        "c",
-        "copyright",
-        true,
+        Option copyright = new Option(
+                "c",
+                "copyright",
+                true,
         "The copyright message to use in the licence headers, usually in the form of \"Copyright 2008 Foo\"");
-    opts.addOption(copyright);
-    
-    Option xml = new Option(
-        "x",
-        "xml",
-        false,
+        opts.addOption(copyright);
+
+        Option xml = new Option(
+                "x",
+                "xml",
+                false,
         "Output the report in XML format");
-    opts.addOption(xml);
-    
-    PosixParser parser = new PosixParser();
-    CommandLine cl = null;
-    try {
-      cl = parser.parse(opts, args);
-    } catch (ParseException e) {
-      System.err.println("Please use the \"--help\" option to see a list of valid commands and options");
-      System.exit(1);
-    }
-
-    if (cl.hasOption('h')) {
-      printUsage(opts);
-    }
-    
-    
-    args = cl.getArgs();
-    if (args == null || args.length != 1) {
-			printUsage(opts);
-		} else {
-      Report report = new Report(args[0]);
-      
-      if (cl.hasOption('a')) {
-        OutputStream reportOutput = new ByteArrayOutputStream();
-        PrintStream stream = new PrintStream(reportOutput, true);
-        report.report(stream);
-        
-        AbstractLicenceAppender  appender;
-        String copyrightMsg = cl.getOptionValue("c");
-        if ( copyrightMsg != null) {
-          appender = new ApacheV2LicenceAppender(copyrightMsg);
-        } else {
-          appender = new ApacheV2LicenceAppender();
-        }
-        if (cl.hasOption("f")) {
-          appender.setForce(true);
+        opts.addOption(xml);
+
+        PosixParser parser = new PosixParser();
+        CommandLine cl = null;
+        try {
+            cl = parser.parse(opts, args);
+        } catch (ParseException e) {
+            System.err.println("Please use the \"--help\" option to see a list of valid commands and options");
+            System.exit(1);
         }
-        
-        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        factory.setValidating(false);
-        ByteArrayInputStream xmlStream = new ByteArrayInputStream(reportOutput.toString().getBytes("UTF-8"));
-        Document doc = factory.newDocumentBuilder().parse(xmlStream);
-        
-        NodeList resourceHeaders = doc.getElementsByTagName("header-type");
-        String value = null;
-        for (int i = 0; i < resourceHeaders.getLength(); i++) {
-          Node headerType = resourceHeaders.item(i).getAttributes().getNamedItem("name");
-          if(headerType != null) {
-            value = headerType.getNodeValue();
-          } else {
-            value = null;
-          }
-          if (value != null &&value.equals("?????")) {
-            Node resource = resourceHeaders.item(i).getParentNode();
-            String filename = resource.getAttributes().getNamedItem("name").getNodeValue();
-            File document = new File(filename);
-            appender.append(document);
-          }
+
+        if (cl.hasOption('h')) {
+            printUsage(opts);
         }
-      }
-      
-      if (cl.hasOption('x')) {
-			  report.report(System.out);
-		  } else {
-        report.styleReport(System.out);
-		  }		  
-		} 
-	}
-	
-	private static final void printUsage(Options opts) {
-	    HelpFormatter f = new HelpFormatter();
-	    String header = "Options";
-    
-	    StringBuffer footer = new StringBuffer("\n");
-	    footer.append("NOTE:\n");
-	    footer.append("RAT is really little more than a grep ATM\n");
-	    footer.append("RAT is also rather memory hungry ATM\n");
-	    footer.append("RAT is very basic ATM\n");
-	    footer.append("RAT ATM runs on unpacked releases\n");
-	    footer.append("RAT highlights possible issues\n");
-	    footer.append("RAT reports require intepretation\n");
-	    footer.append("RAT often requires some tuning before it runs well against a project\n");
-	    footer.append("RAT relies on heuristics: it may miss issues\n");
-
-	    f.printHelp("java rat.report [options] [DIR]",
-	            header, opts, footer.toString(), false);
-	    System.exit(0);
-	}
-	
-	private final String baseDirectory;
-	
-	private Report(String baseDirectory) {
-		this.baseDirectory = baseDirectory;
-	}
-	
-	public ClaimStatistic report(PrintStream out) throws Exception {
+
+
+        args = cl.getArgs();
+        if (args == null || args.length != 1) {
+            printUsage(opts);
+        } else {
+            Report report = new Report(args[0]);
+
+            if (cl.hasOption('a')) {
+                OutputStream reportOutput = new ByteArrayOutputStream();
+                PrintStream stream = new PrintStream(reportOutput, true);
+                report.report(stream);
+
+                AbstractLicenceAppender  appender;
+                String copyrightMsg = cl.getOptionValue("c");
+                if ( copyrightMsg != null) {
+                    appender = new ApacheV2LicenceAppender(copyrightMsg);
+                } else {
+                    appender = new ApacheV2LicenceAppender();
+                }
+                if (cl.hasOption("f")) {
+                    appender.setForce(true);
+                }
+
+                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+                factory.setValidating(false);
+                ByteArrayInputStream xmlStream = new ByteArrayInputStream(reportOutput.toString().getBytes("UTF-8"));
+                Document doc = factory.newDocumentBuilder().parse(xmlStream);
+
+                NodeList resourceHeaders = doc.getElementsByTagName("header-type");
+                String value = null;
+                for (int i = 0; i < resourceHeaders.getLength(); i++) {
+                    Node headerType = resourceHeaders.item(i).getAttributes().getNamedItem("name");
+                    if(headerType != null) {
+                        value = headerType.getNodeValue();
+                    } else {
+                        value = null;
+                    }
+                    if (value != null &&value.equals("?????")) {
+                        Node resource = resourceHeaders.item(i).getParentNode();
+                        String filename = resource.getAttributes().getNamedItem("name").getNodeValue();
+                        File document = new File(filename);
+                        appender.append(document);
+                    }
+                }
+            }
+
+            if (cl.hasOption('x')) {
+                report.report(System.out);
+            } else {
+                report.styleReport(System.out);
+            }		  
+        } 
+    }
+
+    private static final void printUsage(Options opts) {
+        HelpFormatter f = new HelpFormatter();
+        String header = "Options";
+
+        StringBuffer footer = new StringBuffer("\n");
+        footer.append("NOTE:\n");
+        footer.append("RAT is really little more than a grep ATM\n");
+        footer.append("RAT is also rather memory hungry ATM\n");
+        footer.append("RAT is very basic ATM\n");
+        footer.append("RAT ATM runs on unpacked releases\n");
+        footer.append("RAT highlights possible issues\n");
+        footer.append("RAT reports require intepretation\n");
+        footer.append("RAT often requires some tuning before it runs well against a project\n");
+        footer.append("RAT relies on heuristics: it may miss issues\n");
+
+        f.printHelp("java rat.report [options] [DIR]",
+                header, opts, footer.toString(), false);
+        System.exit(0);
+    }
+
+    private final String baseDirectory;
+
+    private Report(String baseDirectory) {
+        this.baseDirectory = baseDirectory;
+    }
+
+    public ClaimStatistic report(PrintStream out) throws Exception {
         DirectoryWalker base = getDirectory(out);
         if (base != null) {
             return report(base, new OutputStreamWriter(out), Defaults.createDefaultMatcher(), null);
         }
         return null;
-	}
-    
+    }
+
     private DirectoryWalker getDirectory(PrintStream out) {
         DirectoryWalker result = null;
         File base = new File(baseDirectory);
@@ -211,7 +211,7 @@
         }
         return result;
     }
-    
+
     /**
      * Output a report in the default style and default licence
      * header matcher. 
@@ -242,8 +242,8 @@
      */
     public static void report(PrintStream out, IReportable base, final InputStream style, final IHeaderMatcher matcher,
             final ILicenseFamily[] approvedLicenseNames) 
-           throws IOException, TransformerConfigurationException, 
-           InterruptedException, RatException {
+    throws IOException, TransformerConfigurationException, 
+    InterruptedException, RatException {
         report(new OutputStreamWriter(out), base, style, matcher, approvedLicenseNames);
     }
 
@@ -264,7 +264,7 @@
      */
     public static ClaimStatistic report(Writer out, IReportable base, final InputStream style, 
             final IHeaderMatcher matcher, final ILicenseFamily[] approvedLicenseNames) 
-                throws IOException, TransformerConfigurationException, FileNotFoundException, InterruptedException, RatException {
+    throws IOException, TransformerConfigurationException, FileNotFoundException, InterruptedException, RatException {
         PipedReader reader = new PipedReader();
         PipedWriter writer = new PipedWriter(reader);
         ReportTransformer transformer = new ReportTransformer(out, style, reader);
@@ -276,7 +276,7 @@
         transformerThread.join();
         return statistic;
     }
-    
+
     /**
      * 
      * @param container the files or directories to report on
@@ -287,7 +287,7 @@
      * @throws RatException
      */
     public static ClaimStatistic report(final IReportable container, final Writer out, final IHeaderMatcher matcher,
-             final ILicenseFamily[] approvedLicenseNames) throws IOException, RatException {
+            final ILicenseFamily[] approvedLicenseNames) throws IOException, RatException {
         IXmlWriter writer = new XmlWriter(out);
         final ClaimStatistic statistic = new ClaimStatistic();
         RatReport report = XmlReportFactory.createStandardReport(writer, matcher, approvedLicenseNames, statistic);  



From rat-commits-returncassielucas@example.net Tue Jun 16 19:28:10 2009
Return-Path: <rat-commits-returncassielucas@example.net>
Delivered-To: cassielucas@example.net
Received: (qmail 31499 invoked from network); 16 Jun 2009 19:28:10 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155)
  by minotaur.apache.org with SMTP; 16 Jun 2009 19:28:10 -0000
Received: (qmail 47900 invoked by uid 500); 16 Jun 2009 19:28:22 -0000
Delivered-To: cassielucas@example.net
Received: (qmail 47881 invoked by uid 500); 16 Jun 2009 19:28:22 -0000
Mailing-List: contact cassielucas@example.net; run by ezmlm
Precedence: bulk
List-Help: <mailto:cassielucas@example.net>
List-Unsubscribe: <mailto:cassielucas@example.net>
List-Post: <mailto:cassielucas@example.net>
List-Id: <rat-commits.incubator.apache.org>
Reply-To: cassielucas@example.net
Delivered-To: mailing list cassielucas@example.net
Received: (qmail 47872 invoked by uid 99); 16 Jun 2009 19:28:22 -0000
Received: from athena.apache.org (HELO athena.apache.org) (83.161.120.155)
    by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jun 2009 19:28:22 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=10.0
	tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155)
    by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jun 2009 19:28:20 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
	id C8A50238889D; Tue, 16 Jun 2009 19:27:59 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r785349 - in
 /incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat:
 DirectoryWalker.java Report.java
Date: Tue, 16 Jun 2009 19:27:59 -0000
To: cassielucas@example.net
From: cassielucas@example.net
X-Mailer: svnmailer-1.0.8
Message-Id: <cassielucas@example.net>
X-Virus-Checked: Checked by ClamAV on apache.org

Author: rdonkin
Date: Tue Jun 16 19:27:59 2009
New Revision: 785349

URL: http://svn.apache.org/viewvc?rev=785349&view=rev
Log:
RAT-2 Switch to using FilenameFilter to ignore input files https://issues.apache.org/jira/browse/RAT-2

Modified:
    incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/DirectoryWalker.java
    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/DirectoryWalker.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/DirectoryWalker.java?rev=785349&r1=785348&r2=785349&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/DirectoryWalker.java (original)
+++ incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/DirectoryWalker.java Tue Jun 16 19:27:59 2009
@@ -20,6 +20,7 @@
 package org.apache.rat;
 
 import java.io.File;
+import java.io.FilenameFilter;
 import java.util.Arrays;
 import java.util.regex.Pattern;
 
@@ -34,35 +35,61 @@
  */
 public class DirectoryWalker implements IReportable {
 
+    private static FilenameFilter regexFilter(final Pattern pattern) {
+        return new FilenameFilter() {
+            public boolean accept(File dir, String name) {
+                final boolean result;
+                if (pattern == null) {
+                    result = true;
+                } else {
+                    result = !pattern.matcher(name).matches();
+                }
+                return result;
+            }
+        };
+    }
+    
     private static final FileNameComparator COMPARATOR = new FileNameComparator();
     
     protected final File file;
     protected final String name;
 
-    private final Pattern ignoreNameRegex;;
+    private final FilenameFilter filter;
     
 	public DirectoryWalker(File file) {
-            this(file, null);
+	    this(file, (FilenameFilter) null);
 	}
 	
+    /**
+     * Constructs a walker.
+     * @param file not null
+     * @param filter filters input files (optional), 
+     * or null when no filtering should be performed
+     */
+    public DirectoryWalker(File file, final FilenameFilter filter) {
+        this(file.getPath(), file, filter);
+    }
+    
     public DirectoryWalker(File file, final Pattern ignoreNameRegex) {
-        this(file.getPath(), file, ignoreNameRegex);
+        this(file.getPath(), file, regexFilter(ignoreNameRegex));
     }
 
-    private DirectoryWalker(final String name, final File file, final Pattern ignoreNameRegex) {
+    private DirectoryWalker(final String name, final File file, final FilenameFilter filter) {
         this.name = name;
         this.file = file;
-        this.ignoreNameRegex = ignoreNameRegex;
+        this.filter = filter;
     }
 	
     public boolean isRestricted() {
         return false;
     }
 
-    protected final boolean ignored(final String name) {
+    protected final boolean ignored(final File file) {
         boolean result = false;
-        if (ignoreNameRegex != null) {
-            result = ignoreNameRegex.matcher(name).matches();
+        final String name = file.getName();
+        final File dir = file.getParentFile();
+        if (filter != null) {
+            result = !filter.accept(dir, name);
         }
         return result;
     }
@@ -125,8 +152,7 @@
     private void processDirectories(final RatReport report, final File[] files) throws RatException {
         for (int i = 0; i < files.length; i++) {
             final File file = files[i];
-            final String name = file.getName();
-            if (!ignored(name)) {
+            if (!ignored(file)) {
                 if (file.isDirectory()) {
                     processDirectory(report, file);
                 }
@@ -144,8 +170,7 @@
     private void processNonDirectories(final RatReport report, final File[] files) throws RatException {
         for (int i = 0; i < files.length; i++) {
             final File file = files[i];
-            final String name = file.getName();
-            if (!ignored(name)) {
+            if (!ignored(file)) {
                 if (!file.isDirectory()) {
                     report(report, file);
                 }

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=785349&r1=785348&r2=785349&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 16 19:27:59 2009
@@ -22,6 +22,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -182,13 +183,31 @@
     }
 
     private final String baseDirectory;
+    
+    private FilenameFilter inputFileFilter = null;
 
     private Report(String baseDirectory) {
         this.baseDirectory = baseDirectory;
     }
+    
+    /**
+     * Gets the current filter used to select files.
+     * @return current file filter, or null when no filter has been set
+     */
+    public FilenameFilter getInputFileFilter() {
+        return inputFileFilter;
+    }
+
+    /**
+     * Sets the current filter used to select files.
+     * @param inputFileFilter filter, or null when no filter has been set
+     */
+    public void setInputFileFilter(FilenameFilter inputFileFilter) {
+        this.inputFileFilter = inputFileFilter;
+    }
 
     public ClaimStatistic report(PrintStream out) throws Exception {
-        DirectoryWalker base = getDirectory(out);
+        final DirectoryWalker base = getDirectory(out);
         if (base != null) {
             return report(base, new OutputStreamWriter(out), Defaults.createDefaultMatcher(), null);
         }
@@ -207,7 +226,7 @@
             out.print(baseDirectory);
             out.print(" must be a directory.\n");
         } else {
-            result = new DirectoryWalker(base);
+            result = new DirectoryWalker(base, inputFileFilter);
         }
         return result;
     }
@@ -220,7 +239,7 @@
      * @throws Exception
      */
     public void styleReport(PrintStream out) throws Exception {
-        DirectoryWalker base = getDirectory(out);
+        final DirectoryWalker base = getDirectory(out);
         if (base != null) {
             InputStream style = Defaults.getDefaultStyleSheet();
             report(out, base, style, Defaults.createDefaultMatcher(), null);



From rat-commits-returncassielucas@example.net Tue Jun 16 20:26:52 2009
Return-Path: <rat-commits-returncassielucas@example.net>
Delivered-To: cassielucas@example.net
Received: (qmail 54394 invoked from network); 16 Jun 2009 20:26:52 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155)
  by minotaur.apache.org with SMTP; 16 Jun 2009 20:26:52 -0000
Received: (qmail 31183 invoked by uid 500); 16 Jun 2009 20:27:03 -0000
Delivered-To: cassielucas@example.net
Received: (qmail 31162 invoked by uid 500); 16 Jun 2009 20:27:03 -0000
Mailing-List: contact cassielucas@example.net; run by ezmlm
Precedence: bulk
List-Help: <mailto:cassielucas@example.net>
List-Unsubscribe: <mailto:cassielucas@example.net>
List-Post: <mailto:cassielucas@example.net>
List-Id: <rat-commits.incubator.apache.org>
Reply-To: cassielucas@example.net
Delivered-To: mailing list cassielucas@example.net
Received: (qmail 31153 invoked by uid 99); 16 Jun 2009 20:27:03 -0000
Received: from athena.apache.org (HELO athena.apache.org) (83.161.120.155)
    by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jun 2009 20:27:03 +0000
X-ASF-Spam-Status: No, hits=-1998.9 required=10.0
	tests=ALL_TRUSTED,FB_GET_MEDS
X-Spam-Check-By: apache.org
Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155)
    by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jun 2009 20:27:01 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
	id 2B42A238885B; Tue, 16 Jun 2009 20:26:41 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r785376 - in /incubator/rat/main/trunk/apache-rat-core: pom.xml
 src/main/java/org/apache/rat/Report.java
Date: Tue, 16 Jun 2009 20:26:40 -0000
To: cassielucas@example.net
From: cassielucas@example.net
X-Mailer: svnmailer-1.0.8
Message-Id: <cassielucas@example.net>
X-Virus-Checked: Checked by ClamAV on apache.org

Author: rdonkin
Date: Tue Jun 16 20:26:40 2009
New Revision: 785376

URL: http://svn.apache.org/viewvc?rev=785376&view=rev
Log:
RAT-56 Support Commons IO file filter wildcards https://issues.apache.org/jira/browse/RAT-56

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

Modified: incubator/rat/main/trunk/apache-rat-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/pom.xml?rev=785376&r1=785375&r2=785376&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/pom.xml (original)
+++ incubator/rat/main/trunk/apache-rat-core/pom.xml Tue Jun 16 20:26:40 2009
@@ -61,6 +61,11 @@
       <version>2.1</version>
     </dependency>
     <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.4</version>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>

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=785376&r1=785375&r2=785376&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 16 20:26:40 2009
@@ -30,17 +30,23 @@
 import java.io.PipedReader;
 import java.io.PipedWriter;
 import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerConfigurationException;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
+import org.apache.commons.io.filefilter.AndFileFilter;
+import org.apache.commons.io.filefilter.NotFileFilter;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
 import org.apache.rat.analysis.IHeaderMatcher;
 import org.apache.rat.annotation.AbstractLicenceAppender;
 import org.apache.rat.annotation.ApacheV2LicenceAppender;
@@ -55,12 +61,57 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
 
 
 public class Report {
 
+    private static final char EXCLUDE_CLI = 'e';
+
     //@SuppressWarnings("unchecked")
     public static final void main(String args[]) throws Exception {
+        Options opts = buildOptions();
+        
+        PosixParser parser = new PosixParser();
+        CommandLine cl = null;
+        try {
+            cl = parser.parse(opts, args);
+        } catch (ParseException e) {
+            System.err.println("Please use the \"--help\" option to see a list of valid commands and options");
+            System.exit(1);
+        }
+
+        if (cl.hasOption('h')) {
+            printUsage(opts);
+        }
+
+        args = cl.getArgs();
+        if (args == null || args.length != 1) {
+            printUsage(opts);
+        } else {
+            Report report = new Report(args[0]);
+
+            if (cl.hasOption('a')) {
+                configureForAddLicense(cl, report);
+            }
+
+            if (cl.hasOption(EXCLUDE_CLI)) {
+                String[] excludes = cl.getOptionValues(EXCLUDE_CLI);
+                if (excludes != null) {
+                    final FilenameFilter filter = new NotFileFilter(new WildcardFileFilter(excludes));
+                    report.setInputFileFilter(filter);
+                }
+            }
+            
+            if (cl.hasOption('x')) {
+                report.report(System.out);
+            } else {
+                report.styleReport(System.out);
+            }	
+        } 
+    }
+
+    private static Options buildOptions() {
         Options opts = new Options();
 
         Option help = new Option("h", "help", false,
@@ -87,7 +138,7 @@
                 true,
         "The copyright message to use in the licence headers, usually in the form of \"Copyright 2008 Foo\"");
         opts.addOption(copyright);
-
+        
         Option xml = new Option(
                 "x",
                 "xml",
@@ -95,71 +146,63 @@
         "Output the report in XML format");
         opts.addOption(xml);
 
-        PosixParser parser = new PosixParser();
-        CommandLine cl = null;
-        try {
-            cl = parser.parse(opts, args);
-        } catch (ParseException e) {
-            System.err.println("Please use the \"--help\" option to see a list of valid commands and options");
-            System.exit(1);
-        }
-
-        if (cl.hasOption('h')) {
-            printUsage(opts);
-        }
-
+        final Option exclude = OptionBuilder
+                            .withArgName("expression")
+                            .withLongOpt("exclude")
+                            .hasArgs()
+                            .withDescription("Excludes files matching <expression>. " +
+                                    "Note that --dir is required when using this parameter. " +
+                                    "Allows multiple arguments.")
+                            .create(EXCLUDE_CLI);
+        opts.addOption(exclude);
+        
+        Option dir = new Option(
+                "d",
+                "dir",
+                false,
+        "Used to indicate source when using --exclude");
+        opts.addOption(dir);
+        
+        return opts;
+    }
 
-        args = cl.getArgs();
-        if (args == null || args.length != 1) {
-            printUsage(opts);
+    private static void configureForAddLicense(CommandLine cl, Report report) throws Exception, UnsupportedEncodingException, SAXException, IOException, ParserConfigurationException {
+        OutputStream reportOutput = new ByteArrayOutputStream();
+        PrintStream stream = new PrintStream(reportOutput, true);
+        report.report(stream);
+
+        AbstractLicenceAppender  appender;
+        String copyrightMsg = cl.getOptionValue("c");
+        if ( copyrightMsg != null) {
+            appender = new ApacheV2LicenceAppender(copyrightMsg);
         } else {
-            Report report = new Report(args[0]);
-
-            if (cl.hasOption('a')) {
-                OutputStream reportOutput = new ByteArrayOutputStream();
-                PrintStream stream = new PrintStream(reportOutput, true);
-                report.report(stream);
-
-                AbstractLicenceAppender  appender;
-                String copyrightMsg = cl.getOptionValue("c");
-                if ( copyrightMsg != null) {
-                    appender = new ApacheV2LicenceAppender(copyrightMsg);
-                } else {
-                    appender = new ApacheV2LicenceAppender();
-                }
-                if (cl.hasOption("f")) {
-                    appender.setForce(true);
-                }
-
-                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-                factory.setValidating(false);
-                ByteArrayInputStream xmlStream = new ByteArrayInputStream(reportOutput.toString().getBytes("UTF-8"));
-                Document doc = factory.newDocumentBuilder().parse(xmlStream);
-
-                NodeList resourceHeaders = doc.getElementsByTagName("header-type");
-                String value = null;
-                for (int i = 0; i < resourceHeaders.getLength(); i++) {
-                    Node headerType = resourceHeaders.item(i).getAttributes().getNamedItem("name");
-                    if(headerType != null) {
-                        value = headerType.getNodeValue();
-                    } else {
-                        value = null;
-                    }
-                    if (value != null &&value.equals("?????")) {
-                        Node resource = resourceHeaders.item(i).getParentNode();
-                        String filename = resource.getAttributes().getNamedItem("name").getNodeValue();
-                        File document = new File(filename);
-                        appender.append(document);
-                    }
-                }
-            }
+            appender = new ApacheV2LicenceAppender();
+        }
+        if (cl.hasOption("f")) {
+            appender.setForce(true);
+        }
 
-            if (cl.hasOption('x')) {
-                report.report(System.out);
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setValidating(false);
+        ByteArrayInputStream xmlStream = new ByteArrayInputStream(reportOutput.toString().getBytes("UTF-8"));
+        Document doc = factory.newDocumentBuilder().parse(xmlStream);
+
+        NodeList resourceHeaders = doc.getElementsByTagName("header-type");
+        String value = null;
+        for (int i = 0; i < resourceHeaders.getLength(); i++) {
+            Node headerType = resourceHeaders.item(i).getAttributes().getNamedItem("name");
+            if(headerType != null) {
+                value = headerType.getNodeValue();
             } else {
-                report.styleReport(System.out);
-            }		  
-        } 
+                value = null;
+            }
+            if (value != null &&value.equals("?????")) {
+                Node resource = resourceHeaders.item(i).getParentNode();
+                String filename = resource.getAttributes().getNamedItem("name").getNodeValue();
+                File document = new File(filename);
+                appender.append(document);
+            }
+        }
     }
 
     private static final void printUsage(Options opts) {




{'source': 'Apache Software Foundation Public Mail Archives'}