incubator-rat-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r636144 [2/7] - in /incubator/rat/import: ./ rat/ rat/src/ rat/src/java/ rat/src/java/rat/ rat/src/java/rat/analysis/ rat/src/java/rat/analysis/generation/ rat/src/java/rat/analysis/license/ rat/src/java/rat/analysis/util/ rat/src/java/rat/...
Date Tue, 11 Mar 2008 23:09:27 GMT
Added: incubator/rat/import/rat/src/java/rat/analysis/generation/JavaDocLicenseNotRequired.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/analysis/generation/JavaDocLicenseNotRequired.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/analysis/generation/JavaDocLicenseNotRequired.java (added)
+++ incubator/rat/import/rat/src/java/rat/analysis/generation/JavaDocLicenseNotRequired.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.analysis.generation;
+
+import java.util.regex.Pattern;
+
+import rat.analysis.Claims;
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.report.RatReportFailedException;
+import rat.report.claim.IClaimReporter;
+
+/**
+ * JavaDocs are generated and so no license is required.
+ * It is useful to not these separately.
+ */
+public class JavaDocLicenseNotRequired implements IHeaderMatcher {
+
+    private static final String JAVADOC_REGEX_DEFN = ".*Generated by javadoc.*";
+    
+    private static final Pattern JAVADOC_REGEX = Pattern.compile(JAVADOC_REGEX_DEFN);
+    
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = JAVADOC_REGEX.matcher(line).matches();
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    private void reportOnLicense(String subject, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        try {
+            Claims.reportGeneratedClaims(subject, "JavaDocs are generated and so license header is optional", reporter);
+        } catch (RatReportFailedException e) {
+            throw new RatHeaderAnalysisException("Cannot write claims", e);
+        }
+    }
+    
+    public void reset() {
+        // stateless
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/analysis/license/ApacheSoftwareLicense20.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/analysis/license/ApacheSoftwareLicense20.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/analysis/license/ApacheSoftwareLicense20.java (added)
+++ incubator/rat/import/rat/src/java/rat/analysis/license/ApacheSoftwareLicense20.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.analysis.license;
+
+import rat.analysis.Claims;
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.license.Apache20LicenseFamily;
+import rat.report.claim.IClaimReporter;
+
+/**
+ * Matches Apache Software License, Version 2.0
+ *
+ */
+public final class ApacheSoftwareLicense20 extends BaseLicense implements
+		IHeaderMatcher {
+
+	public static final String FIRST_LICENSE_LINE = "Licensed under the Apache License, Version 2.0 (the \"License\")";
+	public static final String LICENSE_REFERENCE_LINE = "http://www.apache.org/licenses/LICENSE-2.0";
+	
+	public ApacheSoftwareLicense20() {
+		super(Claims.ASL_CODE, Apache20LicenseFamily.APACHE_SOFTWARE_LICENSE_NAME, "");
+	}
+	
+	public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        final boolean result = matches(line);
+		if (result) {
+			reportOnLicense(subject, reporter);
+		}
+        return result;
+	}
+
+	boolean matches(String line) {
+		return line.indexOf(FIRST_LICENSE_LINE, 0) >= 0 
+		|| line.indexOf(LICENSE_REFERENCE_LINE, 0) >= 0;
+	}
+	
+	public void reset() {	
+	}
+}

Added: incubator/rat/import/rat/src/java/rat/analysis/license/BaseLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/analysis/license/BaseLicense.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/analysis/license/BaseLicense.java (added)
+++ incubator/rat/import/rat/src/java/rat/analysis/license/BaseLicense.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.analysis.license;
+
+import rat.analysis.Claims;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.report.RatReportFailedException;
+import rat.report.claim.IClaimReporter;
+
+public class BaseLicense {
+	private final String code;
+	private final String name;
+	private final String notes;
+	
+	public BaseLicense(final String code, final String name, final String notes)
+	{
+		this.code = code;
+		this.name = name;
+		this.notes = notes;
+	}
+    
+    public final void reportOnLicense(String subject, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        final String name = getName();
+        final String code = getCode();
+        final String notes = getNotes();
+        try {
+            Claims.reportStandardClaims(subject, notes, code, name, reporter);
+
+        } catch (RatReportFailedException e) {
+            // Cannot recover
+            throw new RatHeaderAnalysisException("Cannot report on license information", e);
+        }
+    }
+
+    public String getCode() {
+		return code;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public String getNotes() {
+		return notes;
+	}
+}

Added: incubator/rat/import/rat/src/java/rat/analysis/license/DojoLicenseHeader.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/analysis/license/DojoLicenseHeader.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/analysis/license/DojoLicenseHeader.java (added)
+++ incubator/rat/import/rat/src/java/rat/analysis/license/DojoLicenseHeader.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.analysis.license;
+
+import rat.analysis.Claims;
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.license.ModifiedBSDLicenseFamily;
+import rat.report.claim.IClaimReporter;
+
+
+public class DojoLicenseHeader extends BaseLicense implements IHeaderMatcher {
+    
+    private static final String LICENSE_URL 
+    = "http://dojotoolkit.org/community/licensing.shtml";
+    
+    //  Copyright (c) 2004-2006, The Dojo Foundation
+    // All Rights Reserved.
+    //
+    // Licensed under the Academic Free License version 2.1 or above OR the
+    // modified BSD license. For more information on Dojo licensing, see:
+    //
+    //    http://dojotoolkit.org/community/licensing.shtml
+
+    public DojoLicenseHeader() {
+        // TODO: support for dual licensing
+        // TODO: support for or higher clauses
+        super(Claims.DOJO, ModifiedBSDLicenseFamily.MODIFIED_BSD_LICENSE_NAME, "Dual license AFL/BSD");
+    }
+
+
+    public void reset() {
+
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        final boolean result = matches(line);
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    boolean matches(String line) {
+        boolean result = (line != null && line.indexOf(LICENSE_URL) != -1);
+        return result;
+    }
+    
+}

Added: incubator/rat/import/rat/src/java/rat/analysis/license/OASISLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/analysis/license/OASISLicense.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/analysis/license/OASISLicense.java (added)
+++ incubator/rat/import/rat/src/java/rat/analysis/license/OASISLicense.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.analysis.license;
+
+import java.util.regex.Pattern;
+
+import rat.analysis.Claims;
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.license.OASISLicenseFamily;
+import rat.report.claim.IClaimReporter;
+
+/**
+ * Looks for documents contain the OASIS copyright claim plus derivative work clause.
+ * Perhaps need to match more.
+ */
+public class OASISLicense extends BaseLicense implements IHeaderMatcher {
+
+    private static final String COPYRIGHT_PATTERN_DEFN = ".*Copyright.*OASIS Open.*";
+    private static final String CLAUSE_DEFN
+    = ".*thisdocumentandtranslationsofitmaybecopiedandfurnishedtoothersandderivativeworks" +
+            "thatcommentonorotherwiseexplainitorassistinitsimplementationmaybeprepared" +
+            "copiedpublishedanddistributed.*";
+    
+    private static final Pattern COPYRIGHT_PATTERN = Pattern.compile(COPYRIGHT_PATTERN_DEFN);
+    private static final Pattern CLAUSE_PATTERN = Pattern.compile(CLAUSE_DEFN);
+
+    boolean copyrightMatch = false;
+    final StringBuffer buffer = new StringBuffer();
+    
+    public OASISLicense() {
+        super(Claims.OASIS_CODE, OASISLicenseFamily.OASIS_OPEN_LICENSE_NAME, "No modifications allowed");
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = false;
+        if (copyrightMatch) {
+            line = line.toLowerCase();
+            buffer.append(line);
+            prune(buffer); 
+            final boolean clauseMatch = CLAUSE_PATTERN.matcher(buffer).matches();
+            if (clauseMatch) {
+                result = true;
+                reportOnLicense(subject, reporter);
+            }
+            
+        } else {
+            copyrightMatch = COPYRIGHT_PATTERN.matcher(line).matches();
+        }
+        return result;
+    }
+    
+    private void prune(final StringBuffer buffer) {
+        final int length = buffer.length();
+        for (int i=length;i>0;) {
+            char at = buffer.charAt(--i);
+            if (at < 'a' || at > 'z')
+            {
+                buffer.deleteCharAt(i);
+            }
+        }
+    }
+
+    public void reset() {
+        copyrightMatch = false;
+        buffer.delete(0, buffer.length());
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/analysis/license/TMF854LicenseHeader.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/analysis/license/TMF854LicenseHeader.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/analysis/license/TMF854LicenseHeader.java (added)
+++ incubator/rat/import/rat/src/java/rat/analysis/license/TMF854LicenseHeader.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2007 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.analysis.license;
+
+import rat.analysis.Claims;
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.license.ModifiedBSDLicenseFamily;
+import rat.report.claim.IClaimReporter;
+
+
+public class TMF854LicenseHeader extends BaseLicense implements IHeaderMatcher {
+    
+    private static final String COPYRIGHT_HEADER 
+    = "TMF854 Version 1.0 - Copyright TeleManagement Forum";
+    
+    //  TMF854 Version 1.0 - Copyright TeleManagement Forum 
+
+    public TMF854LicenseHeader() {
+        super(Claims.TMF854, ModifiedBSDLicenseFamily.MODIFIED_BSD_LICENSE_NAME, "BSD");
+    }
+
+
+    public void reset() {
+
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        final boolean result = matches(line);
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    boolean matches(String line) {
+        boolean result = (line != null && line.indexOf(COPYRIGHT_HEADER) != -1);
+        return result;
+    }
+    
+}

Added: incubator/rat/import/rat/src/java/rat/analysis/license/W3CDocLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/analysis/license/W3CDocLicense.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/analysis/license/W3CDocLicense.java (added)
+++ incubator/rat/import/rat/src/java/rat/analysis/license/W3CDocLicense.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2006 Guillaume Nodet
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.analysis.license;
+
+import rat.analysis.Claims;
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.license.W3CDocumentLicenseFamily;
+import rat.report.claim.IClaimReporter;
+
+public class W3CDocLicense extends BaseLicense implements IHeaderMatcher {
+
+    private static final String NOTES 
+        = "Note that W3CD does not allow modifications. See http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231.";
+    private static final String COPYRIGHT_URL 
+    = "http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231";
+    
+    public W3CDocLicense() {
+        super(Claims.W3CD_CODE, W3CDocumentLicenseFamily.W3C_DOCUMENT_COPYRIGHT_NAME,  NOTES);
+        
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = line != null && line.indexOf(COPYRIGHT_URL) != -1;
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    public void reset() {
+        // Matcher is not stateful 
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/analysis/license/W3CLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/analysis/license/W3CLicense.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/analysis/license/W3CLicense.java (added)
+++ incubator/rat/import/rat/src/java/rat/analysis/license/W3CLicense.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.analysis.license;
+
+import rat.analysis.Claims;
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.license.W3CSoftwareLicenseFamily;
+import rat.report.claim.IClaimReporter;
+
+public class W3CLicense extends BaseLicense implements IHeaderMatcher {
+
+    private static final String NOTES 
+        = "Note that W3C requires a NOTICE. All modifications require notes. See http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.";
+    private static final String COPYRIGHT_URL 
+    = "http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231";
+    
+    public W3CLicense() {
+        super(Claims.W3C_CODE, W3CSoftwareLicenseFamily.W3C_SOFTWARE_COPYRIGHT_NAME,  NOTES);
+        
+    }
+
+    public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = line != null && line.indexOf(COPYRIGHT_URL) != -1;
+        if (result) {
+            reportOnLicense(subject, reporter);
+        }
+        return result;
+    }
+
+    public void reset() {
+        // Matcher is not stateful 
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/analysis/util/HeaderMatcherMultiplexer.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/analysis/util/HeaderMatcherMultiplexer.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/analysis/util/HeaderMatcherMultiplexer.java (added)
+++ incubator/rat/import/rat/src/java/rat/analysis/util/HeaderMatcherMultiplexer.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.analysis.util;
+
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.RatHeaderAnalysisException;
+import rat.report.claim.IClaimReporter;
+
+/**
+ * Delegates to an ordered set of matchers.
+ *
+ */
+public final class HeaderMatcherMultiplexer implements IHeaderMatcher {
+
+	private final IHeaderMatcher[] matchers;
+	private final int numberOfMatchers;
+	
+	public HeaderMatcherMultiplexer(final IHeaderMatcher[] matchers) {
+		this.matchers = matchers;
+		numberOfMatchers = matchers.length;
+	}
+	
+	public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
+        boolean result = false;
+		for (int i=0;i<numberOfMatchers;i++) {
+			result = matchers[i].match(subject, line, reporter);
+            if (result) {
+                break;
+            }
+		}
+        return result;
+	}
+
+	public void reset() {
+		for (int i=0;i<numberOfMatchers;i++) {
+			matchers[i].reset();
+		}
+	}
+
+}

Added: incubator/rat/import/rat/src/java/rat/anttasks/Report.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/anttasks/Report.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/anttasks/Report.java (added)
+++ incubator/rat/import/rat/src/java/rat/anttasks/Report.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.anttasks;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.LogOutputStream;
+import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.Union;
+import org.apache.tools.ant.util.FileUtils;
+
+import rat.Defaults;
+import rat.analysis.IHeaderMatcher;
+import rat.analysis.util.HeaderMatcherMultiplexer;
+import rat.license.ILicenseFamily;
+import rat.report.RatReportFailedException;
+
+/**
+ * A basic Ant task that generates a report on all files specified by
+ * the nested resource collection(s).
+ *
+ * <p>ILicenseMatcher(s) can be specified as nested elements as well.</p>
+ */
+public class Report extends Task {
+
+    /**
+     * will hold any nested resource collection
+     */
+    private Union nestedResources;
+    /**
+     * The licenses we want to match on.
+     */
+    private ArrayList licenseMatchers = new ArrayList();
+    
+    private ArrayList licenseNames = new ArrayList();
+    
+    /**
+     * Whether to add the default list of license matchers.
+     */
+    private boolean addDefaultLicenseMatchers = true;
+    /**
+     * Where to send the report.
+     */
+    private File reportFile;
+
+    /**
+     * Adds resources that will be checked.
+     */
+    public void add(ResourceCollection rc) {
+        if (nestedResources == null) {
+            nestedResources = new Union();
+        }
+        nestedResources.add(rc);
+    }
+
+    /**
+     * Adds a license matcher.
+     */
+    public void add(IHeaderMatcher matcher) {
+        licenseMatchers.add(matcher);
+    }
+    
+    public void add(ILicenseFamily license) {
+        licenseNames.add(license);
+    }
+
+    /**
+     * Whether to add the default list of license matchers.
+     */
+    public void setAddDefaultLicenseMatchers(boolean b) {
+        addDefaultLicenseMatchers = b;
+    }
+
+    /**
+     * Where to send the report to.
+     */
+    public void setReportFile(File f) {
+        reportFile = f;
+    }
+
+    /**
+     * Generates the report.
+     */
+    public void execute() {
+        validate();
+
+        PrintWriter out = null;
+        try {
+            if (reportFile == null) {
+                out = new PrintWriter(
+                          new OutputStreamWriter(
+                              new LogOutputStream(this, Project.MSG_INFO)
+                              )
+                          );
+            } else {
+                out = new PrintWriter(new FileWriter(reportFile));
+            }
+            createReport(out);
+            out.flush();
+        } catch (IOException ioex) {
+            throw new BuildException(ioex);
+        } catch (TransformerException e) {
+            throw new BuildException(e);
+        } catch (InterruptedException e) {
+            throw new BuildException(e);
+        } catch (RatReportFailedException e) {
+            throw new BuildException(e);
+        } finally {
+            if (reportFile != null) {
+                FileUtils.close(out);
+            }
+        }
+    }
+
+    /**
+     * validates the task's configuration.
+     */
+    private void validate() {
+        if (nestedResources == null) {
+            throw new BuildException("You must specify at least one file to"
+                                     + " create the report for.");
+        }
+        if (!addDefaultLicenseMatchers && licenseMatchers.size() == 0) {
+            throw new BuildException("You must specify at least one license"
+                                     + " matcher");
+        }
+    }
+
+    /**
+     * Writes the report to the given stream.
+     * @throws InterruptedException 
+     * @throws TransformerException 
+     * @throws RatReportFailedException 
+     */
+    private void createReport(PrintWriter out) throws IOException, TransformerException, InterruptedException, RatReportFailedException {
+        HeaderMatcherMultiplexer m = new HeaderMatcherMultiplexer(getLicenseMatchers());
+        ResourceCollectionContainer rcElement =
+            new ResourceCollectionContainer(nestedResources);
+        rat.Report.report(out, rcElement, Defaults.getDefaultStyleSheet(), m, getApprovedLicenseNames());
+    }
+
+    /**
+     * Flattens all nested matchers plus the default matchers (if
+     * required) into a single array.
+     */
+    private IHeaderMatcher[] getLicenseMatchers() {
+        IHeaderMatcher[] matchers = null;
+        if (addDefaultLicenseMatchers) {
+            int nestedSize = licenseMatchers.size();
+            if (nestedSize == 0) {
+                matchers = Defaults.DEFAULT_MATCHERS;
+            } else {
+                matchers = new IHeaderMatcher[Defaults.DEFAULT_MATCHERS.length
+                                               + nestedSize];
+                licenseMatchers.toArray(matchers);
+                System.arraycopy(Defaults.DEFAULT_MATCHERS, 0, matchers,
+                                 nestedSize, Defaults.DEFAULT_MATCHERS.length);
+            }
+        } else {
+            matchers = (IHeaderMatcher[])
+                licenseMatchers.toArray(new IHeaderMatcher[0]);
+        }
+        return matchers;
+    }
+    
+    private ILicenseFamily[] getApprovedLicenseNames() {
+        // TODO: add support for adding default licenses
+        ILicenseFamily[] results = null;
+        if (licenseNames.size() > 0) {
+            results = (ILicenseFamily[]) licenseNames.toArray(new ILicenseFamily[0]);
+        }
+        return results;
+    }
+}

Propchange: incubator/rat/import/rat/src/java/rat/anttasks/Report.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rat/import/rat/src/java/rat/anttasks/ResourceCollectionContainer.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/anttasks/ResourceCollectionContainer.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/anttasks/ResourceCollectionContainer.java (added)
+++ incubator/rat/import/rat/src/java/rat/anttasks/ResourceCollectionContainer.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.anttasks;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Iterator;
+
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.FileResource;
+
+import rat.document.IDocument;
+import rat.document.IDocumentCollection;
+import rat.document.UnreadableArchiveException;
+import rat.document.impl.DocumentImplUtils;
+import rat.document.impl.zip.ZipDocumentFactory;
+import rat.report.IReportable;
+import rat.report.RatReport;
+import rat.report.RatReportFailedException;
+
+/**
+ * Implementation of IElement that traverses over a resource
+ * collection internally.
+ */
+class ResourceCollectionContainer implements IReportable {
+    private final ResourceCollection rc;
+
+    ResourceCollectionContainer(ResourceCollection rc) {
+        this.rc = rc;
+    }
+
+    public void run(RatReport report) throws RatReportFailedException {
+        ResourceDocument document = new ResourceDocument();
+        for (Iterator iter = rc.iterator(); iter.hasNext(); ) {
+            Resource r = (Resource) iter.next();
+            if (r.isDirectory()) {
+                // do nothing
+            } else {
+                document.setResource(r);
+                report.report(document);
+            }
+        }
+    }
+    private class ResourceDocument implements IDocument {
+
+        private Resource resource;
+        
+        public Resource getResource() {
+            return resource;
+        }
+
+        public void setResource(Resource resource) {
+            this.resource = resource;
+        }
+
+        public IDocumentCollection readArchive() throws IOException {
+            IDocumentCollection results = null;
+            if (resource instanceof FileResource) {
+                final FileResource fileResource = (FileResource) resource;
+                final File file = fileResource.getFile();
+                results = ZipDocumentFactory.load(file);
+            }
+            else
+            {
+                throw new UnreadableArchiveException();
+            }
+            return results;
+        }
+
+        public Reader reader() throws IOException {
+            final InputStream in = resource.getInputStream();
+            final Reader result = new InputStreamReader(in);
+            return result;
+        }
+
+        public String getName() {
+            // TODO: reconsider names
+            String result = null;
+            if (resource instanceof FileResource) {
+                final FileResource fileResource = (FileResource) resource;
+                final File file = fileResource.getFile();
+                result = DocumentImplUtils.toName(file);
+            } else {
+                result = resource.getName();
+            }
+            return result;
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/rat/import/rat/src/java/rat/anttasks/ResourceCollectionContainer.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rat/import/rat/src/java/rat/anttasks/antlib.xml
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/anttasks/antlib.xml?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/anttasks/antlib.xml (added)
+++ incubator/rat/import/rat/src/java/rat/anttasks/antlib.xml Tue Mar 11 16:08:58 2008
@@ -0,0 +1,45 @@
+<?xml version='1.0'?>
+<!--
+
+ Copyright 2006 Robert Burrell Donkin
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+
+<antlib>
+  <taskdef name="report" classname="rat.anttasks.Report"/>
+
+  <!-- typedef the built-in license matchers -->
+  <typedef name="asl20"
+    classname="rat.analysis.license.ApacheSoftwareLicense20"/>
+  <typedef name="generated"
+    classname="rat.analysis.generation.GeneratedLicenseNotRequired"/>
+  <typedef name="javadoc"
+    classname="rat.analysis.generation.JavaDocLicenseNotRequired"/>
+  <typedef name="oasis"
+    classname="rat.analysis.license.OASISLicense"/>
+  <typedef name="w3c"
+    classname="rat.analysis.license.W3CLicense"/>
+  <typedef name="w3c-doc"
+    classname="rat.analysis.license.W3CDocLicense"/>
+  <typedef name="w3c-doc-license"
+    classname="rat.license.W3CDocumentLicenseFamily"/>
+  <typedef name="w3c-soft-license"
+    classname="rat.license.W3CSoftwareLicenseFamily"/>
+  <typedef name="oasis-license"
+    classname="rat.license.OASISLicenseFamily"/>
+  <typedef name="apache20-license"
+    classname="rat.license.Apache20LicenseFamily"/> 
+    
+</antlib>
\ No newline at end of file

Propchange: incubator/rat/import/rat/src/java/rat/anttasks/antlib.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rat/import/rat/src/java/rat/document/CompositeDocumentException.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/CompositeDocumentException.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/CompositeDocumentException.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/CompositeDocumentException.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+import java.io.IOException;
+
+/**
+ * Indicates that the document is a composite archive 
+ * and cannot be read.
+ */
+public class CompositeDocumentException extends IOException {
+
+    private static final long serialVersionUID = -8874256971728263295L;
+
+    public CompositeDocumentException() {
+        super("This document must be read as an archive.");
+    }
+
+    public CompositeDocumentException(String s) {
+        super(s);
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/DocumentUtils.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/DocumentUtils.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/DocumentUtils.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/DocumentUtils.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Transformer;
+
+public final class DocumentUtils {
+
+    private static final Transformer TO_NAME_TRANSFORMER = new ToNameTransformer();
+    
+    public static final Transformer toNameTransformer() {
+        return TO_NAME_TRANSFORMER;
+    }
+    
+    /**
+     * Collects all the documents contained in the collection tree.
+     * @param documentCollection <code>IDocumentCollection</code>, not null
+     * @return <code>Collection</code> of <code>IDocument</code>
+     */
+    public static final Collection documentsContained(IDocumentCollection documentCollection) {
+        final Collection results = new ArrayList();
+        addContents(documentCollection, results);
+        return results;
+    }
+    
+    /**
+     * Depth first traversal.
+     * @param documentCollection <code>IDocumentCollection</code>, not null
+     * @param contents <code>Collection</code> of <code>IDocument</code>'s, not null
+     */
+    private static final void addContents(IDocumentCollection documentCollection, Collection contents) {
+        for (Iterator it=documentCollection.subcollectionIterator();it.hasNext();) {
+            IDocumentCollection subCollection = (IDocumentCollection) it.next();
+            addContents(subCollection, contents);
+        }
+        CollectionUtils.addAll(contents, documentCollection.documentIterator());
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/document/IDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/IDocument.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/IDocument.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/IDocument.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+import java.io.IOException;
+import java.io.Reader;
+
+public interface IDocument extends IResource {
+
+    /**
+     * Reads the content of this document.
+     * @return <code>Reader</code> not null
+     * @throws IOException if this document cannot be read
+     * @throws CompositeDocumentException if this document can only be read as
+     * a composite archive
+     */
+	public Reader reader() throws IOException;
+    
+    /**
+     * Reads contents of composite document.
+     * @return <code>IDocumentCollection</code>, not null
+     * @throws IOException if the document cannot be read
+     * @throws UnreadableArchiveException if this document is not an archive
+     * or if this document is unreadable
+     */
+    public IDocumentCollection readArchive() throws IOException;
+}

Added: incubator/rat/import/rat/src/java/rat/document/IDocumentAnalyser.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/IDocumentAnalyser.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/IDocumentAnalyser.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/IDocumentAnalyser.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+
+public interface IDocumentAnalyser {
+
+    public void analyse(IDocument document) throws RatDocumentAnalysisException;
+}

Added: incubator/rat/import/rat/src/java/rat/document/IDocumentCollection.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/IDocumentCollection.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/IDocumentCollection.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/IDocumentCollection.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+import java.util.Iterator;
+
+/**
+ * Collects documents.
+ * May contain subcollections.
+ */
+public interface IDocumentCollection extends IResource {
+
+	/**
+	 * Iterates <code>IDocument</code>'s contained.
+	 * @return <code>Iterator</code>, not null
+	 */
+	public Iterator documentIterator();
+	
+	/**
+	 * Iterates <code>IDocumentCollection</code>'s contained.
+	 * @return <code>Iterator</code>, not null
+	 */
+	public Iterator subcollectionIterator();
+}

Added: incubator/rat/import/rat/src/java/rat/document/IDocumentMatcher.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/IDocumentMatcher.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/IDocumentMatcher.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/IDocumentMatcher.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+
+public interface IDocumentMatcher {
+
+    public boolean matches(final IDocument document) throws RatDocumentAnalysisException;
+}

Added: incubator/rat/import/rat/src/java/rat/document/IFileUnarchiver.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/IFileUnarchiver.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/IFileUnarchiver.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/IFileUnarchiver.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Reads documents from file archives.
+ *
+ */
+public interface IFileUnarchiver {
+
+    /**
+     * Unarchives the file.
+     * @param file <code>File</code>, not null
+     * @return <code>IDocumentCollection</code> describing the archived
+     * documents contained
+     * @throws UnreadableArchiveException if the file cannot be unarchived
+     */
+    public IDocumentCollection unarchive(File file) throws IOException;
+}

Added: incubator/rat/import/rat/src/java/rat/document/IResource.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/IResource.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/IResource.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/IResource.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package rat.document;
+
+public interface IResource {
+
+	public String getName();
+
+}
\ No newline at end of file

Added: incubator/rat/import/rat/src/java/rat/document/RatDocumentAnalysisException.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/RatDocumentAnalysisException.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/RatDocumentAnalysisException.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/RatDocumentAnalysisException.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+import org.apache.commons.lang.exception.NestableException;
+
+public class RatDocumentAnalysisException extends NestableException {
+
+    private static final long serialVersionUID = 2339068944003517510L;
+
+    public RatDocumentAnalysisException() {
+    }
+
+    public RatDocumentAnalysisException(String msg) {
+        super(msg);
+    }
+
+    public RatDocumentAnalysisException(Throwable cause) {
+        super(cause);
+    }
+
+    public RatDocumentAnalysisException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/ToNameTransformer.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/ToNameTransformer.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/ToNameTransformer.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/ToNameTransformer.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+import org.apache.commons.collections.Transformer;
+
+class ToNameTransformer implements Transformer {
+
+    public Object transform(Object subject) {
+        Object result = null;
+        if (subject != null && subject instanceof IResource) {
+            IResource location = (IResource) subject;
+            result = location.getName();
+        }
+        return result;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/document/UnreadableArchiveException.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/UnreadableArchiveException.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/UnreadableArchiveException.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/UnreadableArchiveException.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+import org.apache.commons.lang.exception.Nestable;
+import org.apache.commons.lang.exception.NestableDelegate;
+
+/**
+ * Indicates that an archive is unreadable.
+ *
+ */
+public class UnreadableArchiveException extends IOException implements Nestable {
+
+    private static final String MESSAGE = "Archive is unreadable";
+
+    private static final long serialVersionUID = -1556313036805276658L;
+
+    private final NestableDelegate delegate = new NestableDelegate(this);
+    private final Throwable cause;
+    
+    public UnreadableArchiveException() {
+        this(MESSAGE, null);
+    }
+
+    public UnreadableArchiveException(String s) {
+        this(s, null);
+    }
+    
+    public UnreadableArchiveException(Throwable cause) {
+        this(MESSAGE, cause);
+    }
+    
+    public UnreadableArchiveException(String s, Throwable cause) {
+        super(s);
+        this.cause = cause;
+    }
+    
+    public Throwable getCause() {
+        return cause;
+    }
+    
+    public String getMessage() {
+        final String result = super.getMessage();
+        return result;
+    }
+    
+    public String getMessage(int index) {
+        String result = null;
+        if (index == 0) {
+            result = getMessage();
+        } else {
+            result = delegate.getMessage(index);
+        }
+        return result;
+    }
+
+    public String[] getMessages() {
+        final String[] messages = delegate.getMessages();
+        return messages;
+    }
+
+    public Throwable getThrowable(int index) {
+        final Throwable result = delegate.getThrowable(index);
+        return result;
+    }
+
+    public int getThrowableCount() {
+        final int throwableCount = delegate.getThrowableCount();
+        return throwableCount;
+    }
+
+    public Throwable[] getThrowables() {
+        final Throwable[] throwables = delegate.getThrowables();
+        return throwables;
+    }
+
+    public int indexOfThrowable(Class type) {
+        final int result = delegate.indexOfThrowable(type, 0);
+        return result;
+    }
+
+    public int indexOfThrowable(Class type, int fromIndex) {
+        final int result = delegate.indexOfThrowable(type, fromIndex);
+        return result;
+    }
+
+    public void printStackTrace() {
+        delegate.printStackTrace();
+    }
+
+    public void printStackTrace(PrintStream s) {
+        delegate.printStackTrace(s);
+    }
+
+    public void printStackTrace(PrintWriter s) {
+        delegate.printStackTrace(s);
+    }
+
+    public void printPartialStackTrace(PrintWriter out) {
+        super.printStackTrace(out);
+    }
+}    

Added: incubator/rat/import/rat/src/java/rat/document/UnsuitableDocumentException.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/UnsuitableDocumentException.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/UnsuitableDocumentException.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/UnsuitableDocumentException.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document;
+
+/**
+ * Indicates that the document was unsuitable for analysis.
+ *
+ */
+public class UnsuitableDocumentException extends RatDocumentAnalysisException {
+
+    private static final long serialVersionUID = 4202800209654402733L;
+
+    public UnsuitableDocumentException() {
+        super("This document is unsuitable for analysis");
+    }
+
+    public UnsuitableDocumentException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+    public UnsuitableDocumentException(String msg) {
+        super(msg);
+    }
+
+    public UnsuitableDocumentException(Throwable cause) {
+        super(cause);
+    }
+
+    
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/CompositeDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/CompositeDocument.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/CompositeDocument.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/CompositeDocument.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import rat.document.CompositeDocumentException;
+import rat.document.IDocument;
+
+/**
+ * Composed from a set of archived documents.
+ *
+ */
+public abstract class CompositeDocument implements IDocument {
+
+    private final String name;
+    
+    public CompositeDocument(final String name) {
+        super();
+        this.name = name;
+    }
+
+    public Reader reader() throws IOException {
+        throw new CompositeDocumentException();
+    }
+
+    public String getName() {
+        return name;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/DocumentImplUtils.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/DocumentImplUtils.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/DocumentImplUtils.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/DocumentImplUtils.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl;
+
+import java.io.File;
+
+public class DocumentImplUtils {
+
+    public final static String toName(File file) {
+        String path = file.getPath();
+        String normalisedPath = path.replace('\\', '/');
+        return normalisedPath;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/FileDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/FileDocument.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/FileDocument.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/FileDocument.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import rat.document.IDocument;
+import rat.document.IDocumentCollection;
+import rat.document.IFileUnarchiver;
+
+/**
+ * Document wrapping a file of undetermined composition.
+ *
+ */
+public class FileDocument implements IDocument {
+
+    private final File file;
+    private final String name;
+    private IFileUnarchiver unarchiver;
+    
+    public FileDocument(final File file, IFileUnarchiver unarchiver) {
+        super();
+        this.file = file;
+        this.unarchiver = unarchiver;
+        name = DocumentImplUtils.toName(file);
+    }
+
+    public IDocumentCollection readArchive() throws IOException {
+        final IDocumentCollection result = unarchiver.unarchive(file);
+        return result;
+    }
+
+    public Reader reader() throws IOException {
+        return new FileReader(file);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/MonolithicFileDocument.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/MonolithicFileDocument.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/MonolithicFileDocument.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/MonolithicFileDocument.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import rat.document.IDocument;
+import rat.document.IDocumentCollection;
+import rat.document.UnreadableArchiveException;
+
+public class MonolithicFileDocument implements IDocument {
+
+    
+    private final File file;
+    private final String name;
+    
+    public MonolithicFileDocument(final File file) {
+        super();
+        this.file = file;
+        name = DocumentImplUtils.toName(file);
+    }
+
+    public IDocumentCollection readArchive() throws IOException {
+        throw new UnreadableArchiveException("This file is not an archive");
+    }
+
+    public Reader reader() throws IOException {
+        return new FileReader(file);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/guesser/ArchiveGuesser.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/guesser/ArchiveGuesser.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/guesser/ArchiveGuesser.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/guesser/ArchiveGuesser.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl.guesser;
+
+import java.util.Locale;
+
+import rat.document.IDocument;
+import rat.document.IDocumentMatcher;
+
+public class ArchiveGuesser implements IDocumentMatcher {
+    
+    public static final String[] ARCHIVE_EXTENSIONS = {
+        "jar", "gz",
+        "zip", "tar",
+        "bz", "bz2",
+        "rar", "war",
+    };
+
+    public boolean matches(final IDocument document) {
+        
+        final String name = document.getName();
+        final boolean result = isArchive(name);
+        return result;
+    }
+
+    /**
+     * Is a file by that name an archive?
+     */
+    public static final boolean isArchive(final String name) {
+        if (name == null) {return false;}
+        String nameToLower = name.toLowerCase(Locale.US);
+        boolean result = false;
+        for (int i = 0; !result && i < ArchiveGuesser.ARCHIVE_EXTENSIONS.length; i++) {
+            result = nameToLower.endsWith("." + ArchiveGuesser.ARCHIVE_EXTENSIONS[i]);
+        }
+        return result;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/guesser/BinaryGuesser.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/guesser/BinaryGuesser.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/guesser/BinaryGuesser.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/guesser/BinaryGuesser.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,284 @@
+/*
+ * Copyright 2006-2007 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl.guesser;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Locale;
+
+import rat.document.IDocument;
+import rat.document.IDocumentMatcher;
+
+/**
+ * TODO: factor into MIME guesser and MIME->binary guesser
+ */
+public class BinaryGuesser implements IDocumentMatcher {
+
+    private static boolean isBinary(IDocument document) {
+        boolean result = false;
+        Reader reader = null;
+        try
+        {
+            reader = document.reader();
+            result = isBinary(reader);
+        }
+        catch (IOException e)
+        {
+            result = false;
+        }
+        finally
+        {
+            try
+            {
+                if (reader != null)
+                {
+                    reader.close();
+                }
+            }
+            catch (IOException e)
+            {
+                // SWALLOW
+            }   
+        }
+        return result;
+    }
+    
+    /**
+     * Do the first few bytes of the stream hint at a binary file?
+     */
+    public static boolean isBinary(Reader in) {
+        boolean result = false;
+        char[] taste = new char[100];
+        try {
+            int bytesRead = in.read(taste);
+            if (bytesRead > 0) {
+                int highBytes = 0;
+                for (int i=0;i<bytesRead;i++) {
+                    if (taste[i] > BinaryGuesser.NON_ASCII_THREASHOLD
+                        || taste[i] <= BinaryGuesser.ASCII_CHAR_THREASHOLD) {
+                        highBytes++;
+                    }
+                }
+                if (highBytes * BinaryGuesser.HIGH_BYTES_RATIO
+                    > bytesRead * BinaryGuesser.TOTAL_READ_RATIO) {
+                    result = true;
+                }
+            }
+        } catch (IOException e) {
+            // SWALLOW 
+        }
+        return result;
+    }
+
+    public static final boolean isBinaryData(final String name) {
+        return extensionMatches(name, DATA_EXTENSIONS);
+    }
+
+    /**
+     * Is a file by that name a known non-binary file?
+     */
+    public static final boolean isNonBinary(final String name) {
+        if (name == null) {return false;}
+        return extensionMatches(name.toUpperCase(Locale.US),
+                                BinaryGuesser.NON_BINARY_EXTENSIONS);
+    }
+
+    public static final boolean isExecutable(final String name) {
+        return name.equals(BinaryGuesser.JAVA) || extensionMatches(name, EXE_EXTENSIONS)
+            || containsExtension(name, EXE_EXTENSIONS);
+    }
+
+    public static boolean containsExtension(final String name,
+                                             final String[] exts) {
+        boolean result = false;
+        for (int i = 0; !result && i < exts.length; i++) {
+            result = name.indexOf("." + exts[i] + ".") >= 0;
+        }
+        return result;
+    }
+
+    public static boolean extensionMatches(final String name,
+                                            final String[] exts) {
+        boolean result = false;
+        for (int i = 0; !result && i < exts.length; i++) {
+            result = name.endsWith("." + exts[i]);
+        }
+        return result;
+    }
+
+    public static boolean isBytecode(final String name) {
+        return BinaryGuesser.extensionMatches(name, BYTECODE_EXTENSIONS);
+    }
+
+    public static final boolean isImage(final String name) {
+        return BinaryGuesser.extensionMatches(name, IMAGE_EXTENSIONS);
+    }
+
+    public static final boolean isKeystore(final String name) {
+        return BinaryGuesser.extensionMatches(name, KEYSTORE_EXTENSIONS);
+    }
+    
+    /**
+     * Is a file by that name a known binary file?
+     */
+    public static final boolean isBinary(final String name) {
+        if (name == null) {return false;}
+        String normalisedName = GuessUtils.normalise(name);
+        return BinaryGuesser.JAR_MANIFEST.equals(name) || BinaryGuesser.isImage(normalisedName)
+            || BinaryGuesser.isKeystore(normalisedName) || BinaryGuesser.isBytecode(normalisedName)
+            || BinaryGuesser.isBinaryData(normalisedName) || BinaryGuesser.isExecutable(normalisedName);
+    }
+
+    public static final String[] DATA_EXTENSIONS = {
+        "DAT", "DOC",
+        "NCB", "IDB",
+        "SUO", "XCF",
+        "RAJ", "CERT",
+        "KS", "TS",
+    };
+    public static final String[] EXE_EXTENSIONS = {
+        "EXE", "DLL",
+        "LIB", "SO",
+        "A", "EXP",
+    };
+    public static final String[] KEYSTORE_EXTENSIONS = {
+        "JKS", "KEYSTORE", "PEM", "CRL"
+    };
+    public static final String[] IMAGE_EXTENSIONS = {
+        "PNG", "PDF",
+        "GIF", "GIFF",
+        "TIF", "TIFF",
+        "JPG", "JPEG",
+        "ICO",
+    };
+    public static final String[] BYTECODE_EXTENSIONS = {
+        "CLASS", "PYD",
+        "OBJ", "PYC",
+    };
+    
+    /**
+     * Based on http://www.apache.org/dev/svn-eol-style.txt
+     */
+    public static final String[] NON_BINARY_EXTENSIONS = {
+        "AART",
+        "AC",
+        "AM",
+        "BAT",
+        "C",
+        "CAT",
+        "CGI",
+        "CLASSPATH",
+        "CMD",
+        "CONFIG",
+        "CPP",
+        "CSS",
+        "CWIKI",
+        "DATA",
+        "DCL",
+        "DTD",
+        "EGRM",
+        "ENT",
+        "FT", 
+        "FN",
+        "FV", 
+        "GRM",
+        "G",
+        "H",
+        "HTACCESS",
+        "HTML",
+        "IHTML",
+        "IN",
+        "JAVA",
+        "JMX", 
+        "JSP",
+        "JS",
+        "JUNIT",
+        "JX", 
+        "MANIFEST",
+        "M4",
+        "MF",
+        "MF",
+        "META",
+        "MOD",
+        "N3",
+        "PEN",
+        "PL",
+        "PM",
+        "POD",
+        "POM",
+        "PROJECT",
+        "PROPERTIES",
+        "PY",
+        "RB",
+        "RDF",
+        "RNC",
+        "RNG",
+        "RNX",
+        "ROLES",
+        "RSS",
+        "SH",
+        "SQL",
+        "SVG",
+        "TLD",
+        "TXT",
+        "TYPES",
+        "VM",
+        "VSL",
+        "WSDD",
+        "WSDL",
+        "XARGS",
+        "XCAT",
+        "XCONF",
+        "XEGRM",
+        "XGRM",
+        "XLEX",
+        "XLOG",
+        "XMAP",
+        "XML",
+        "XROLES",
+        "XSAMPLES",
+        "XSD",
+        "XSL",
+        "XSLT",
+        "XSP",
+        "XUL",
+        "XWEB",
+        "XWELCOME",
+    };
+    public static final String JAR_MANIFEST = "MANIFEST.MF";
+    public static final String JAVA = "JAVA";
+    public static final int HIGH_BYTES_RATIO = 100;
+    public static final int TOTAL_READ_RATIO = 30;
+    public static final int NON_ASCII_THREASHOLD = 256;
+    public static final int ASCII_CHAR_THREASHOLD = 8;
+
+    public boolean matches(final IDocument document) {
+        // TODO: reimplement the binary test algorithm?
+        // TODO: more efficient to move into standard analysis
+        // TODO: then use binary as default
+        final String name = document.getName();
+        boolean result = isBinary(name);
+        if (!result)
+        {
+            // try a taste
+            result = isBinary(document);
+        }
+        return result;
+    }
+
+
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/guesser/GuessUtils.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/guesser/GuessUtils.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/guesser/GuessUtils.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/guesser/GuessUtils.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl.guesser;
+
+import java.util.Locale;
+
+import org.apache.commons.lang.StringUtils;
+
+public class GuessUtils {
+    
+    private static final String[] SEPARATORS = {"/", "\\"};
+    
+    /**
+     * Converts name to upper case and strips any path.
+     * @param name
+     * @return
+     */
+    public static final String normalise(final String name) {
+        String result = name.toUpperCase(Locale.US);
+        final int lastSeparatorIndex = StringUtils.lastIndexOfAny(result, SEPARATORS);
+        final int length = result.length();
+        if (lastSeparatorIndex >= 0 && lastSeparatorIndex < length) {
+            result = result.substring(lastSeparatorIndex + 1);
+        }
+        return result;
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/guesser/NoteGuesser.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/guesser/NoteGuesser.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/guesser/NoteGuesser.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/guesser/NoteGuesser.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl.guesser;
+
+import java.util.Arrays;
+import java.util.List;
+
+import rat.document.IDocument;
+import rat.document.IDocumentMatcher;
+
+public class NoteGuesser implements IDocumentMatcher {
+
+
+    public static final String[] NOTE_FILE_NAMES = {
+    "NOTICE", "LICENSE",
+        "LICENSE.TXT", "NOTICE.TXT", 
+        "INSTALL", "INSTALL.TXT",
+        "README", "README.TXT", 
+        "NEWS", "NEWS.TXT",
+        "AUTHOR", "AUTHOR.TXT",
+        "AUTHORS", "AUTHORS.txt",
+        "CHANGELOG", "CHANGELOG.TXT",
+        "DISCLAIMER", "DISCLAIMER.TXT",
+        "KEYS", "KEYS.TXT",
+        "RELEASE-NOTES", "RELEASE-NOTES.TXT",
+        "RELEASE_NOTES", "RELEASE_NOTES.TXT",
+        "UPGRADE", "UPGRADE.TXT",
+        "STATUS", "STATUS.TXT",
+        "THIRD_PARTY_NOTICES", "THIRD_PARTY_NOTICES.TXT",
+        "COPYRIGHT", "COPYRIGHT.TXT",
+        "BUILDING", "BUILDING.TXT",
+    };
+    public static final String[] NOTE_FILE_EXTENSIONS = {
+        "LICENSE", "LICENSE.TXT",
+        "NOTICE", "NOTICE.TXT",
+    };
+    
+    /**
+     * Is a file by that name a note file?
+     */
+    public static final boolean isNote(final String name) {
+        if (name == null) {return false;}
+    
+        List l = Arrays.asList(NoteGuesser.NOTE_FILE_NAMES);
+        String normalisedName = GuessUtils.normalise(name);
+        
+        boolean result = l.contains(name) || l.contains(normalisedName);
+        for (int i = 0; !result && i < NoteGuesser.NOTE_FILE_EXTENSIONS.length; i++) {
+            result = normalisedName.endsWith("." + NoteGuesser.NOTE_FILE_EXTENSIONS[i]);
+        }
+        return result;
+    }
+
+    public boolean matches(final IDocument document) {
+        final String name = document.getName();
+        final boolean result = isNote(name);
+        return result;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/util/ConditionalAnalyser.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/util/ConditionalAnalyser.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/util/ConditionalAnalyser.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/util/ConditionalAnalyser.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl.util;
+
+import rat.document.IDocument;
+import rat.document.IDocumentAnalyser;
+import rat.document.IDocumentMatcher;
+import rat.document.RatDocumentAnalysisException;
+
+/**
+ * Analyses documents matching given condition.
+ *
+ */
+public class ConditionalAnalyser implements IDocumentMatcher, IDocumentAnalyser {
+
+    private final IDocumentMatcher matcher;
+    private final IDocumentAnalyser analyser;
+    
+    public ConditionalAnalyser(final IDocumentMatcher matcher, final IDocumentAnalyser analyser) {
+        super();
+        this.matcher = matcher;
+        this.analyser = analyser;
+    }
+
+    public boolean matches(final IDocument document) throws RatDocumentAnalysisException {
+        final boolean result = matcher.matches(document);
+        if (result) {
+            analyser.analyse(document);
+        }
+        return result;
+    }
+
+    public void analyse(final IDocument document) throws RatDocumentAnalysisException {
+        matches(document);
+    }
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/util/DocumentAnalyserMultiplexer.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/util/DocumentAnalyserMultiplexer.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/util/DocumentAnalyserMultiplexer.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/util/DocumentAnalyserMultiplexer.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl.util;
+
+import rat.document.IDocument;
+import rat.document.IDocumentAnalyser;
+import rat.document.RatDocumentAnalysisException;
+
+public class DocumentAnalyserMultiplexer implements IDocumentAnalyser {
+
+    private final IDocumentAnalyser[] analysers;
+    
+    public DocumentAnalyserMultiplexer(final IDocumentAnalyser[] analysers) {
+        super();
+        this.analysers = analysers;
+    }
+
+    public void analyse(IDocument document) throws RatDocumentAnalysisException {
+        final int length = analysers.length;
+        for (int i=0;i<length;i++) {
+            analysers[i].analyse(document);
+        }
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/util/DocumentMatcherMultiplexer.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/util/DocumentMatcherMultiplexer.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/util/DocumentMatcherMultiplexer.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/util/DocumentMatcherMultiplexer.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl.util;
+
+import rat.document.IDocument;
+import rat.document.IDocumentMatcher;
+import rat.document.RatDocumentAnalysisException;
+
+/**
+ * Calls all the matchers in turn until one returns true.
+ *
+ */
+public class DocumentMatcherMultiplexer implements IDocumentMatcher {
+    
+    private final IDocumentMatcher[] matchers;
+    
+    public DocumentMatcherMultiplexer(final IDocumentMatcher[] matchers) {
+        super();
+        this.matchers = matchers;
+    }
+
+    public boolean matches(IDocument document) throws RatDocumentAnalysisException {
+        boolean result = false;
+        final int length = matchers.length;
+        for (int i=0;i<length;i++) {
+            if (matchers[i].matches(document)) {
+                result = true;
+                break;
+            }
+        }
+        return result;
+    }
+
+}

Added: incubator/rat/import/rat/src/java/rat/document/impl/util/MatchNegator.java
URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/java/rat/document/impl/util/MatchNegator.java?rev=636144&view=auto
==============================================================================
--- incubator/rat/import/rat/src/java/rat/document/impl/util/MatchNegator.java (added)
+++ incubator/rat/import/rat/src/java/rat/document/impl/util/MatchNegator.java Tue Mar 11 16:08:58 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2006 Robert Burrell Donkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package rat.document.impl.util;
+
+import rat.document.IDocument;
+import rat.document.IDocumentMatcher;
+import rat.document.RatDocumentAnalysisException;
+
+/**
+ * Negatives the result of the given matcher.
+ *
+ */
+public final class MatchNegator implements IDocumentMatcher {
+
+    private final IDocumentMatcher matcher;
+    
+    public MatchNegator(final IDocumentMatcher matcher) {
+        super();
+        this.matcher = matcher;
+    }
+
+    public boolean matches(IDocument document) throws RatDocumentAnalysisException {
+        return !matcher.matches(document);
+    }
+
+}



Mime
View raw message