You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by rd...@apache.org on 2011/08/06 14:24:25 UTC

svn commit: r1154510 [2/4] - in /incubator/rat/whisker/trunk/legacy: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/rat/ src/main/java/org/apache/rat/whisker/ src/main/java/org/apache/rat/whisker/...

Added: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceNamesCollator.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceNamesCollator.java?rev=1154510&view=auto
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceNamesCollator.java (added)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceNamesCollator.java Sat Aug  6 12:24:24 2011
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.rat.whisker.legacy.out;
+
+import java.util.Collection;
+import java.util.TreeSet;
+
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+
+/**
+ * 
+ */
+public class ResourceNamesCollator extends Visitor {
+    
+    private final Collection<Pair<WithinDirectory, Resource>> resources = new TreeSet<Pair<WithinDirectory, Resource>>();
+    private final Collection<Pair<WithinDirectory, Resource>> duplicates = new TreeSet<Pair<WithinDirectory, Resource>>();
+    private WithinDirectory lastDirectory; 
+
+    /**
+     * @return the names
+     */
+    public Collection<String> getNames() {
+        final Collection<String> names = new TreeSet<String>();
+        for (Pair<WithinDirectory, Resource> pair: resources) {
+            names.add(pair.getRight().getName());
+        }
+        return names;
+    }
+
+    /**
+     * @return the duplicates
+     */
+    public Collection<Pair<WithinDirectory, Resource>> getDuplicates() {
+        return duplicates;
+    }
+
+    
+    
+    /**
+     * @see org.apache.rat.whisker.legacy.out.Visitor#visit(org.apache.rat.whisker.legacy.out.WithinDirectory)
+     */
+    @Override
+    public void visit(WithinDirectory directory) {
+        this.lastDirectory = directory;
+    }
+
+    /**
+     * @see org.apache.rat.whisker.legacy.out.Visitor#visit(org.apache.rat.whisker.legacy.out.Resource)
+     */
+    @Override
+    public void visit(Resource resource) {
+        if (resources.add(new ImmutablePair<WithinDirectory, Resource>(lastDirectory, resource))) {
+            // Fine
+        } else {
+            // Already added
+            if (lastDirectory == null) {
+                // Issue with logic which will result in a null pointer later
+                throw new IllegalArgumentException("Expected directory to be present");
+            }
+            duplicates.add(new ImmutablePair<WithinDirectory, Resource>(lastDirectory, resource));
+        }
+    }
+}

Propchange: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceNamesCollator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceSourceAuditor.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceSourceAuditor.java?rev=1154510&view=auto
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceSourceAuditor.java (added)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceSourceAuditor.java Sat Aug  6 12:24:24 2011
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.rat.whisker.legacy.out;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.TreeSet;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+
+/**
+ * 
+ */
+public class ResourceSourceAuditor extends Visitor {
+
+    private WithLicense lastLicense;
+    private WithinDirectory lastDirectory;
+    
+    private final Collection<Pair<WithinDirectory, Resource>> resourcesMissingSource 
+        = new TreeSet<Pair<WithinDirectory, Resource>>();
+    
+    private final Collection<Pair<WithinDirectory, Resource>> resourcesWithSource 
+    = new TreeSet<Pair<WithinDirectory, Resource>>();
+    
+    /**
+     * @see org.apache.rat.whisker.legacy.out.Visitor#traversePublicDomain()
+     */
+    @Override
+    public boolean traversePublicDomain() {
+        // TODO: no need to traverse public domain 
+        // TODO: think about API 
+        return false;
+    }
+
+    
+    /**
+     * @return the resourcesWithSource
+     */
+    public Collection<Pair<WithinDirectory, Resource>> getResourcesWithSource() {
+        return resourcesWithSource;
+    }
+
+    /**
+     * @return the resourcesMissingSource
+     */
+    public Collection<Pair<WithinDirectory, Resource>> getResourcesMissingSource() {
+        return resourcesMissingSource;
+    }
+
+    /**
+     * @see org.apache.rat.whisker.legacy.out.Visitor#visit(org.apache.rat.whisker.legacy.out.WithinDirectory)
+     */
+    @Override
+    public void visit(WithinDirectory directory) {
+        this.lastDirectory = directory;
+    }
+
+
+
+    /**
+     * @see org.apache.rat.whisker.legacy.out.Visitor#visit(org.apache.rat.whisker.legacy.out.WithLicense)
+     */
+    @Override
+    public void visit(WithLicense license) {
+        this.lastLicense = license;
+    }
+
+    /**
+     * @see org.apache.rat.whisker.legacy.out.Visitor#visit(org.apache.rat.whisker.legacy.out.Resource)
+     */
+    @Override
+    public void visit(Resource resource) {
+        if (lastLicense == null) {
+            throw new IllegalArgumentException("Last license unexpectedly null for resource " + resource);
+        } else if (lastLicense.isSourceRequired()) {
+            // TODO: Consider using ResourceDescription
+            final ImmutablePair<WithinDirectory, Resource> pair = new ImmutablePair<WithinDirectory, Resource>(lastDirectory, resource);
+            if (resource.hasSource()) {
+                resourcesWithSource.add(pair);
+            } else {
+                resourcesMissingSource.add(pair);
+            }
+        } else {
+            // Source not required
+        }
+    }
+
+
+    /**
+     * @return
+     */
+    public Collection<Resource> getResourcesRequiringSourceLinks() {
+        final Collection<Resource> results = new ArrayList<Resource>();
+        for (Pair<WithinDirectory, Resource> pair: resourcesWithSource) {
+            results.add(pair.getRight());
+        }
+        return results;
+    }
+    
+}

Propchange: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/ResourceSourceAuditor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Visitor.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Visitor.java?rev=1154510&view=auto
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Visitor.java (added)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Visitor.java Sat Aug  6 12:24:24 2011
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.rat.whisker.legacy.out;
+
+/**
+ * 
+ */
+public abstract class Visitor {
+
+    // Tune traversal
+    public boolean traversePublicDomain() {
+        return true;
+    }
+    
+    public boolean traverseWithLicense() {
+        return true;
+    }
+    
+    public boolean traverseByOrganisation() {
+        return true;
+    }
+    
+    public boolean traverseResource() {
+        return true;
+    }
+
+    // Classic visitor pattern
+    public void visit(final WithinDirectory directory) {};
+    public void visit(final WithLicense license) {};
+    public void visit(final ByOrganisation byOrganisation) {};
+    public void visit(final Resource resource) {};
+}

Propchange: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Visitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithLicense.java?rev=1154510&view=auto
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithLicense.java (added)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithLicense.java Sat Aug  6 12:24:24 2011
@@ -0,0 +1,151 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.rat.whisker.legacy.out;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jdom.Element;
+
+/**
+ * 
+ */
+public class WithLicense implements Comparable<WithLicense> {
+    
+    /**
+     * @param element
+     * @param licenses
+     * @return
+     */
+    private static License license(Element element,
+            Map<String, License> licenses) {
+        return licenses.get(element.getAttributeValue("id"));
+    }
+    
+    private final License license;
+    private final Element element;
+    private final Collection<ByOrganisation> organisations;
+    
+    public WithLicense(final Element element, final Map<String, License> licenses,
+            Map<String, Organisation> organisations) {
+        this(license(element, licenses), element, ByOrganisation.byOrganisation(element, organisations));
+    }
+        /**
+     * @param license
+     * @param element
+     */
+    public WithLicense(License license, Element element, 
+            final Collection<ByOrganisation> organisations) {
+        super();
+        this.license = license;
+        this.element = element;
+        this.organisations = organisations;
+    }
+
+    public String getCopyrightNotice() {
+        final String result;
+        final Element copyrightNoticeElement = element.getChild("copyright-notice");
+        if (copyrightNoticeElement == null) {
+            result = null;
+        } else {
+            result = copyrightNoticeElement.getTextTrim();
+        }
+        return result;
+    }
+    
+    public String getName() {
+        return license.getName();
+    }
+    
+    public String getURL() {
+        return license.getURL();
+    }
+    
+    public License getLicense() {
+        return license;
+    }
+    
+    public String getText() throws LicenseTemplateException {
+        return license.getText(parameters());
+    }
+    
+    /**
+     * @return
+     * @throws LicenseTemplateException 
+     */
+    @SuppressWarnings("unchecked")
+    private Map<String, String> parameters() throws LicenseTemplateException {
+        final Map<String, String> results = new HashMap<String, String>();
+        final Element licenseParametersElement = element.getChild("license-parameters");
+        if (licenseParametersElement != null) {
+            for (Element parameterElement: (List<Element>) licenseParametersElement.getChildren("parameter")) {
+                final String name = parameterElement.getChild("name").getTextTrim();
+                if (results.containsKey(name)) {
+                    throw LicenseTemplateException.duplicateParameterName(name);
+                }
+                results.put(name, 
+                        parameterElement.getChild("value").getTextTrim());
+            }   
+        }
+        return results;
+    }
+
+    public Collection<ByOrganisation> getOrganisations() {
+        return organisations;
+    }
+    
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return "WithLicense [element=" + element + "]";
+    }
+
+    /**
+     * TODO: incompatible with equals?
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    @Override
+    public int compareTo(WithLicense other) {
+        return getName().compareTo(other.getName());
+    }
+    
+
+    /**
+     * @param visitor
+     */
+    public void accept(Visitor visitor) {
+        if (visitor != null && visitor.traverseWithLicense()) {
+            visitor.visit(this);
+            for (final ByOrganisation organisation: getOrganisations()) {
+                organisation.accept(visitor);
+            }
+        }
+    }
+    /**
+     * @return
+     */
+    public boolean isSourceRequired() {
+        return license.isSourceRequired();
+    }
+    
+}

Propchange: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithLicense.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithinDirectory.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithinDirectory.java?rev=1154510&view=auto
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithinDirectory.java (added)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithinDirectory.java Sat Aug  6 12:24:24 2011
@@ -0,0 +1,153 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.rat.whisker.legacy.out;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.jdom.Element;
+
+/**
+ * 
+ */
+public class WithinDirectory implements Comparable<WithinDirectory> {
+
+
+    /**
+     * @param organisations
+     * @param element
+     * @return
+     */
+    private static Collection<ByOrganisation> publicDomain(
+            Map<String, Organisation> organisations, Element element) {
+        return ByOrganisation.byOrganisation(element.getChild("public-domain"), organisations);
+    }
+
+
+    /**
+     * @param licenses
+     * @param element
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    private static Collection<WithLicense> licenses(Map<String, License> licenses,
+            Map<String, Organisation> organisations, Element element) {
+        final List<WithLicense> results = new ArrayList<WithLicense>();
+        for (Element withLicenseElement: (List<Element>) element.getChildren("with-license")) {
+            results.add(new WithLicense(withLicenseElement, licenses, organisations));
+        }
+        Collections.sort(results);
+        return results;
+    }
+
+    
+    private final Element element;
+    private final Collection<WithLicense> licenses;
+    private final Collection<ByOrganisation> publicDomain;
+     
+    /**
+     * @param element
+     */
+    public WithinDirectory(Element element, Map<String, License> licenses, 
+            Map<String, Organisation> organisations) {
+        super();
+        this.element = element;
+        this.licenses = licenses(licenses, organisations, element);
+        this.publicDomain = publicDomain(organisations, element);
+    }
+    
+    /**
+     * @return the publicDomain
+     */
+    public Collection<ByOrganisation> getPublicDomain() {
+        return publicDomain;
+    }
+
+    public String getName() {
+        return element.getAttributeValue("dir");
+    }
+    
+    public Collection<WithLicense> getLicenses() {
+        return licenses;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return getName().hashCode();
+    }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final WithinDirectory other = (WithinDirectory) obj;
+        return getName().equals(other.getName());
+    }
+
+    /**
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    @Override
+    public int compareTo(WithinDirectory other) {
+        return getName().compareTo(other.getName());
+    }
+
+
+    /**
+     * @param directoryName
+     * @return
+     */
+    public boolean isNamed(String directoryName) {
+        return getName().equals(directoryName);
+    }
+
+
+    /**
+     * @param visitor
+     */
+    public void accept(Visitor visitor) {
+        if (visitor != null) {      
+            visitor.visit(this);
+            if (visitor.traversePublicDomain()) {
+                for (final ByOrganisation organisation: getPublicDomain()) {
+                    organisation.accept(visitor);
+                }        
+            }
+    
+            for (final WithLicense license: getLicenses()) {
+                license.accept(visitor);
+            }
+        }
+    }
+    
+    
+}

Propchange: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/WithinDirectory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Work.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Work.java?rev=1154510&view=auto
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Work.java (added)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Work.java Sat Aug  6 12:24:24 2011
@@ -0,0 +1,225 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.rat.whisker.legacy.out;
+
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jdom.Document;
+import org.jdom.Element;
+
+/**
+ * 
+ */
+public class Work {
+
+
+    /**
+     * @param document
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    private static Map<String, Organisation> mapOrganisations(Document document) {
+        final Map<String, Organisation> organisationsById = new HashMap<String, Organisation>();
+        
+        for (final Element element: 
+            (List<Element>) document.getRootElement().getChild("organisations").getChildren("organisation")) {
+            new Organisation(element).storeIn(organisationsById);
+        }
+        return Collections.unmodifiableMap(organisationsById);
+    }
+
+
+    /**
+     * @param document
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    private static Map<String, License> mapLicenses(Document document) {
+        Map<String, License> results = new HashMap<String, License>();
+        for (final Element element: (List<Element>) document.getRootElement().getChild("licenses").getChildren()) {
+            new License(element).storeIn(results);
+        }
+        return Collections.unmodifiableMap(results);
+    }
+    
+    
+    /**
+     * @param document
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    private static Map<String, String> mapNotices(Document document) {
+        Map<String, String> results = new HashMap<String, String>();
+        for (final Element element: (List<Element>) document.getRootElement().getChild("notices").getChildren()) {
+            results.put(element.getAttributeValue("id"), element.getTextTrim());
+        }
+        return results;
+    }
+
+    
+    /**
+     * @param document
+     * @return
+     */
+    private static License primaryLicense(final Document document, final Map<String, License> licenses) {
+        return licenses.get(document.getRootElement().getChild("primary-license").getAttributeValue("id"));
+    }
+    
+    private static String primaryNotice(final Document document) {
+        final String result;
+        final Element primaryNoticeElement = document.getRootElement().getChild("primary-notice");
+        if (primaryNoticeElement == null) {
+            result = null;
+        } else {
+            result = primaryNoticeElement.getText()
+                .replace("${year}", Integer.toString(Calendar.getInstance().get(Calendar.YEAR)));
+        }
+        return result;
+    }
+
+
+    /**
+     * @param document
+     * @return
+     */
+    private static String primaryOrganisationId(Document document) {
+        final String result;
+        final Element primaryOrganisationElement = document.getRootElement().getChild("primary-organisation");
+        if (primaryOrganisationElement == null) {
+            result = null;
+        } else {
+            result = primaryOrganisationElement.getAttributeValue("id");
+        }
+        return result;
+    }
+    
+    private final Document document;
+    private final License primaryLicense;
+    private final String primaryOrganisationId;
+    private final String primaryNotice;
+    private final Map<String, License> licenses;
+    private final Map<String, String> notices;
+    private final Map<String, Organisation> organisations;
+    
+    /**
+     * @param document
+     */
+    public Work(Document document) {
+        super();
+        this.document = document;
+        this.licenses = mapLicenses(document);
+        this.notices = mapNotices(document);
+        this.primaryLicense = primaryLicense(document, this.licenses);
+        this.primaryNotice = primaryNotice(document);
+        this.organisations = mapOrganisations(document);
+        this.primaryOrganisationId = primaryOrganisationId(document);
+    }
+
+
+    /**
+     * @return the primaryNotice
+     */
+    public String getPrimaryNotice() {
+        return primaryNotice;
+    }
+
+    public Map<String, Collection<Resource>> getResourceNotices() {
+        final NoticeCollator collator = new NoticeCollator();
+        traverse(collator);
+        return collator.resourceNotices(this.notices);
+    }
+    
+    public Set<String> getOtherNotices() {
+        final NoticeCollator collator = new NoticeCollator();
+        traverse(collator);
+        return collator.notices(notices);
+    }
+
+    public License license(final String id) {
+        return licenses.get(id);
+    }
+    
+    public License getPrimaryLicense() {
+        return primaryLicense;
+    }
+    
+    @SuppressWarnings("unchecked")
+    public Collection<WithinDirectory> getContents() {
+        final Collection<WithinDirectory> results = new TreeSet<WithinDirectory>();
+        for (Element element: (List<Element>)document.getRootElement().getChildren("within")) {
+            if (results.add(directory(element))) {
+                // OK System.out.println("Ok");
+            } else {
+                throw new IllegalArgumentException("Duplicate directory " + element.getAttribute("dir"));
+            }
+        }
+        return results;
+    }
+    
+    public boolean isPrimary( final License license) {
+        return this.primaryLicense.equals(license);
+    }
+    
+    public boolean isPrimary( final ByOrganisation byOrganisation ) {
+        return byOrganisation.getId().equals(primaryOrganisationId);
+    }
+    
+    public boolean isOnlyPrimary (final WithinDirectory directory) {
+        final LicenseAndOrganisationCollator collator = new LicenseAndOrganisationCollator();
+        directory.accept(collator);
+        return collator.isOnlyLicense(getPrimaryLicense()) && collator.isOnlyOrganisation(primaryOrganisationId);
+    }
+    
+    public boolean isOnlyPrimary (final WithLicense license) {
+        final LicenseAndOrganisationCollator collator = new LicenseAndOrganisationCollator();
+        license.accept(collator);
+        return collator.isOnlyLicense(getPrimaryLicense()) && collator.isOnlyOrganisation(primaryOrganisationId);
+    }
+    
+    private WithinDirectory directory(final Element element) {
+        return new WithinDirectory(element, this.licenses, this.organisations);
+    }
+
+    
+    public void traverse(final Visitor visitor) {
+        for (final WithinDirectory directory: getContents()) {
+            directory.accept(visitor);
+        }
+    }
+   
+    public void traverseDirectory(final Visitor visitor, final String directoryName) {
+        for (final WithinDirectory directory: getContents()) {
+            if (directory.isNamed(directoryName)) {
+                directory.accept(visitor);
+            }
+        }
+    }
+    public Collection<Resource> getResourcesRequiringSourceLinks() {
+        final ResourceSourceAuditor auditor = new ResourceSourceAuditor();
+        traverse(auditor);
+        return auditor.getResourcesRequiringSourceLinks();
+    }
+}

Propchange: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Work.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/Directory.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/Directory.java?rev=1154510&view=auto
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/Directory.java (added)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/Directory.java Sat Aug  6 12:24:24 2011
@@ -0,0 +1,118 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.rat.whisker.legacy.scan;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * 
+ */
+public class Directory implements Comparable<Directory> {
+
+    private String name;
+    private Set<String> contents = new TreeSet<String>();
+  
+    
+    /**
+     * @return the name
+     */
+    public String getName() {
+        return name;
+    }
+    /**
+     * @param name the name to set
+     */
+    public Directory setName(String name) {
+        this.name = name;
+        return this;
+    }
+    
+    /**
+     * @return the contents
+     */
+    public Set<String> getContents() {
+        return contents;
+    }
+    
+    /**
+     * @param contents the contents to set
+     */
+    public void setContents(Set<String> contents) {
+        this.contents = contents;
+    }
+    
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        return result;
+    }
+    
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Directory other = (Directory) obj;
+        if (name == null) {
+            if (other.name != null)
+                return false;
+        } else if (!name.equals(other.name))
+            return false;
+        return true;
+    }
+    
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return "Directory [name=" + name + "]";
+    }
+    
+    /**
+     * @param name
+     */
+    public void addResource(String name) {
+        contents.add(name);
+    }
+    
+    /**
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    @Override
+    public int compareTo(Directory other) {
+        if (other == null) {
+            return -1;
+        }
+        return this.name.compareTo(other.name);
+    }
+}
+

Propchange: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/Directory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/FromFileSystem.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/FromFileSystem.java?rev=1154510&view=auto
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/FromFileSystem.java (added)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/FromFileSystem.java Sat Aug  6 12:24:24 2011
@@ -0,0 +1,291 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.rat.whisker.legacy.scan;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.Set;
+import java.util.TreeSet;
+
+
+
+/**
+ * 
+ */
+public class FromFileSystem {
+    
+    /**
+     * @param base
+     */
+    public FromFileSystem() {
+        super();
+    }
+
+    public Collection<Directory> withBase(final String base) throws IOException {
+        return new Builder(base).build();
+    }
+    
+    private static class Builder {
+        /**
+         * 
+         */
+        private static final int DEFAULT_INITIAL_CAPACITY = 64;
+        
+        private final File base;
+        private final Set<Directory> directories;
+        private final Queue<Work> workInProgress;
+        private final Collection<Work> workDone;
+        
+        /**
+         * @param base
+         */
+        public Builder(String base) {
+            this(base, DEFAULT_INITIAL_CAPACITY);
+        }
+
+        /**
+         * @param base
+         */
+        public Builder(String base, int initialCapacity) {
+            super();
+            this.base = new File(base);
+            directories = new TreeSet<Directory>();
+            workInProgress = new LinkedList<Work>();
+            workDone = new ArrayList<Work>(initialCapacity);
+        }
+        
+        public Collection<Directory> build() throws IOException {
+            put(base).andWork().untilDone();
+            return directories;
+        }
+
+        /**
+         * 
+         */
+        private void untilDone() {
+            // TODO: wait until all threads done
+        }
+
+        private Builder put(File file) {
+            return put(new Work(file));
+        }
+        
+        /**
+         * @param base
+         */
+        private Builder put(Work work) {
+            if (work != null) {
+                if (workDone.contains(work)) {
+                    alreadyDone(work);
+                } else {
+                    this.workInProgress.add(work);
+                }
+            }
+            return this;
+        }
+        
+        /**
+         * @param work
+         */
+        private void alreadyDone(Work work) {
+            System.out.println("Already done " + work);
+        }
+
+        private Builder andWork() {
+            while (!workInProgress.isEmpty()) {
+                workDone.add(workOn(workInProgress.poll()));
+            }
+            return this;
+        }
+
+        /**
+         * @param poll
+         * @return
+         */
+        private Work workOn(final Work next) {
+            for (final String name: next.contents()) {
+                put(next.whenDirectory(name));
+            }
+            directories.add(next.build());
+            return next;
+        }
+        
+        
+        private static class Work {
+            
+            private static final String BASE_DIRECTORY = ".";
+            private final String name;
+            private final File file;
+            
+            /**
+             * @param file
+             */
+            public Work(File file) {
+                this(BASE_DIRECTORY, file);
+            }
+
+            /**
+             * @param name
+             * @param file
+             */
+            public Work(String name, File file) {
+                if (! file.exists()) {
+                    throw new IllegalArgumentException("Expected '"+ file.getAbsolutePath() + "' to exist");
+                }
+                if (! file.isDirectory()) {
+                    throw new IllegalArgumentException("Expected '"+ file.getAbsolutePath() + "' to be a directory");
+                }
+                this.name = name;
+                this.file = file;
+            }
+            
+            public String[] contents() {
+                final String[] contents = file.list();
+                if (contents == null) {
+                    throw new IllegalArgumentException("Cannot list content of " + file);
+                }
+                return contents;
+            }
+
+            /**
+             * @return
+             */
+            public Directory build() {
+                final Directory result = new Directory().setName(name);
+                for (final String name: contents()) {
+                    if (isResource(name)) {
+                        result.addResource(name);
+                    }
+                }
+                return result;
+            }
+
+            /**
+             * @param name
+             * @return
+             */
+            private boolean isResource(final String name) {
+                return !isDirectory(name);
+            }
+
+            /**
+             * @param name
+             * @return
+             */
+            private boolean isDirectory(final String name) {
+                return file(name).isDirectory();
+            }
+            
+            /**
+             * @param name
+             * @return
+             */
+            public Work whenDirectory(String name) {
+                final File file = file(name);
+                final Work result;
+                if (file.isDirectory()) {
+                    result = new Work(path(name), file);
+                } else {
+                    result = null;
+                }
+                return result;
+            }
+
+            /**
+             * @param name
+             * @return
+             */
+            private String path(String name) {
+                final String result;
+                if (isBaseDirectory()) {
+                    result = name;
+                } else {
+                    result = this.name + "/" + name;
+                }
+                return result;
+            }
+
+            /**
+             * @return
+             */
+            private boolean isBaseDirectory() {
+                return BASE_DIRECTORY.equals(this.name);
+            }
+
+            /**
+             * @param name
+             * @return
+             */
+            private File file(String name) {
+                return new File(this.file, name);
+            }
+
+            /**
+             * @see java.lang.Object#hashCode()
+             */
+            @Override
+            public int hashCode() {
+                final int prime = 31;
+                int result = 1;
+                result = prime * result
+                        + ((file == null) ? 0 : file.hashCode());
+                result = prime * result
+                        + ((name == null) ? 0 : name.hashCode());
+                return result;
+            }
+            
+            /**
+             * @see java.lang.Object#equals(java.lang.Object)
+             */
+            @Override
+            public boolean equals(Object obj) {
+                if (this == obj)
+                    return true;
+                if (obj == null)
+                    return false;
+                if (getClass() != obj.getClass())
+                    return false;
+                Work other = (Work) obj;
+                if (file == null) {
+                    if (other.file != null)
+                        return false;
+                } else if (!file.equals(other.file))
+                    return false;
+                if (name == null) {
+                    if (other.name != null)
+                        return false;
+                } else if (!name.equals(other.name))
+                    return false;
+                return true;
+            }
+            
+            /**
+             * @see java.lang.Object#toString()
+             */
+            @Override
+            public String toString() {
+                return "Work [name=" + name + ", file=" + file + "]";
+            }
+        }
+    }
+}

Propchange: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/scan/FromFileSystem.java
------------------------------------------------------------------------------
    svn:eol-style = native