Author: rdonkin
Date: Mon Dec  9 06:15:27 2013
New Revision: 1549482

URL: http://svn.apache.org/r1549482
Log:
Revert "Delete not used Class."

This reverts commit 2d8e116d2053218594c4d9c87ea24336ba3f3570.

Added:
    
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CopyrightHeader.java
    
creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CopyrightHeaderTest.java

Added: 
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CopyrightHeader.java
URL: 
http://svn.apache.org/viewvc/creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CopyrightHeader.java?rev=1549482&view=auto
==============================================================================
--- 
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CopyrightHeader.java
 (added)
+++ 
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CopyrightHeader.java
 Mon Dec  9 06:15:27 2013
@@ -0,0 +1,148 @@
+/*
+ * 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.analysis.license;
+
+import java.util.regex.Pattern;
+
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.api.Document;
+import org.apache.rat.api.MetaData.Datum;
+import org.apache.rat.api.domain.LicenseFamily;
+
+/**
+ * Matches a typical Copyright header line only based on a regex pattern which
+ * allows for one (starting) year or year range, and a configurable copyright
+ * owner.
+ * 
+ * <p>
+ * The matching is done case insensitive
+ * </p>
+ * 
+ * <ul>
+ * Example supported Copyright header lines, using copyright owner "FooBar"
+ * <li>* Copyright 2010 FooBar. *</li>
+ * <li>* Copyright 2010-2012 FooBar. *</li>
+ * <li>*copyright 2012 foobar*</li>
+ * </ul>
+ * 
+ * <p>
+ * Note also that the copyright owner is appended to the regex pattern, so can
+ * support additional regex but also requires escaping where needed,<br/>
+ * e.g. use "FooBar \(www\.foobar\.com\)" for matching "FooBar 
(www.foobar.com)"
+ * </p>
+ * 
+ * @since Rat 0.9
+ */
+public class CopyrightHeader extends BaseLicense implements IHeaderMatcher {
+
+       /** The Constant COPYRIGHT_PREFIX_PATTERN_DEFN. */
+       public static final String COPYRIGHT_PREFIX_PATTERN_DEFN = ".*Copyright 
[0-9]{4}(\\-[0-9]{4})? ";
+
+       /** The copyright pattern. */
+       private Pattern copyrightPattern;
+       
+       /** The copyright owner. */
+       private String copyrightOwner;
+       
+       /** The copyright match. */
+       private boolean copyrightMatch;
+       
+       /**
+        * Constructs a license indicated by the given patterns.
+        * 
+        * @param pLicenseFamily
+        *            not null
+        * @param copyrightOwner
+        *            not null
+        */
+       protected CopyrightHeader(final LicenseFamily pLicenseFamily,
+                       final String copyrightOwner) {
+               super(pLicenseFamily);
+               setCopyrightOwner(copyrightOwner);
+       }
+
+       // Called by ctor, so must not be overridden
+       /**
+        * Sets the copyright owner.
+        *
+        * @param copyrightOwner the new copyright owner
+        */
+       public final void setCopyrightOwner(final String copyrightOwner) {
+               this.copyrightOwner = copyrightOwner;
+               this.copyrightPattern = 
Pattern.compile(COPYRIGHT_PREFIX_PATTERN_DEFN
+                               + copyrightOwner + ".*", 
Pattern.CASE_INSENSITIVE);
+       }
+
+       /**
+        * Gets the copy right owner.
+        *
+        * @return the copy right owner
+        */
+       public String getCopyRightOwner() {
+               return copyrightOwner;
+       }
+
+       /**
+        * Checks for copyright pattern.
+        *
+        * @return true, if successful
+        */
+       public boolean hasCopyrightPattern() {
+               return copyrightPattern != null;
+       }
+
+       /**
+        * Checks if is copyright match.
+        *
+        * @return true, if is copyright match
+        */
+       protected boolean isCopyrightMatch() {
+               return copyrightMatch;
+       }
+
+       /**
+        * Match copyright.
+        *
+        * @param s the s
+        * @return true, if successful
+        */
+       protected boolean matchCopyright(final String text) {
+               if (!copyrightMatch) {
+                       copyrightMatch = 
copyrightPattern.matcher(text).matches();
+               }
+               return copyrightMatch;
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.apache.rat.analysis.IHeaderMatcher#match(org.apache.rat.api.Document, 
java.lang.String)
+        */
+       public boolean match(final Document subject, final String text) {
+               if (!copyrightMatch && matchCopyright(text)) {
+                       reportOnLicense(subject);
+               }
+               return copyrightMatch;
+       }
+
+       /* (non-Javadoc)
+        * @see org.apache.rat.analysis.IHeaderMatcher#reset()
+        */
+       public void reset() {
+               copyrightMatch = false;
+       }
+}

Added: 
creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CopyrightHeaderTest.java
URL: 
http://svn.apache.org/viewvc/creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CopyrightHeaderTest.java?rev=1549482&view=auto
==============================================================================
--- 
creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CopyrightHeaderTest.java
 (added)
+++ 
creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CopyrightHeaderTest.java
 Mon Dec  9 06:15:27 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.analysis.license;
+
+import static org.apache.rat.api.domain.RatLicenseFamily.APACHE;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.rat.api.Document;
+import org.apache.rat.document.MockLocation;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The Class CopyrightHeaderTest.
+ */
+public class CopyrightHeaderTest {
+
+       /** The Constant MATCHING_HEADERS. */
+       private static final String[] MATCHING_HEADERS = {
+                       "/*  Copyright 2012 FooBar.*/", "/*  copyright 2012 
foobar.*/",
+                       "/*  Copyright 2012-2013 FooBar.*/" };
+
+       /** The Constant NON_MATCHING_HEADERS. */
+       private static final String[] NON_MATCHING_HEADERS = { "/*  
Copyright*/",
+                       "/*  Copyright FooBar.*/", "/*  Copyright 2013*/",
+                       "/*  Copyright 123a*/", "/*  Copyright 123f oobar*/",
+                       "/*  Copyright 2013FooBar*/", "/*  Copyright 2012 2013 
FooBar.*/" };
+
+       /** The header. */
+       private CopyrightHeader header;
+
+       /** The subject. */
+       private Document subject = new MockLocation("subject");
+
+       /**
+        * Sets the up.
+        * 
+        * @throws Exception
+        *             the exception
+        */
+       @Before
+       public void setUp() throws Exception {
+               header = new CopyrightHeader(APACHE.licenseFamily(), "FooBar");
+               subject = new MockLocation("subject");
+       }
+
+       /**
+        * Test match copyright header.
+        */
+       @Test
+       public void testMatchCopyrightHeader() {
+               for (String line : MATCHING_HEADERS) {
+                       assertTrue("Copyright Header should be matched",
+                                       header.match(subject, line));
+                       header.reset();
+               }
+       }
+
+       /**
+        * Test no match copyright header.
+        */
+       @Test
+       public void testNoMatchCopyrightHeader() {
+               for (String line : NON_MATCHING_HEADERS) {
+                       assertFalse("Copyright Header shouldn't be matched",
+                                       header.match(subject, line));
+                       header.reset();
+               }
+       }
+}


Reply via email to