You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by se...@apache.org on 2013/07/22 00:36:09 UTC
svn commit: r1505488 - in /creadur/rat/trunk: ./
apache-rat-core/src/main/java/org/apache/rat/
apache-rat-core/src/main/java/org/apache/rat/analysis/license/
apache-rat-core/src/main/java/org/apache/rat/api/
apache-rat-core/src/main/java/org/apache/rat...
Author: sebb
Date: Sun Jul 21 22:36:08 2013
New Revision: 1505488
URL: http://svn.apache.org/r1505488
Log:
RAT-129 - Add support for CDDL 1.0
Added:
creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CDDL1License.java (with props)
creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/license/CDDL1LicenseFamily.java (with props)
creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CDDL1LicenseTest.java (with props)
Modified:
creadur/rat/trunk/RELEASE_NOTES.txt
creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/api/MetaData.java
creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/policy/DefaultPolicy.java
Modified: creadur/rat/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/RELEASE_NOTES.txt?rev=1505488&r1=1505487&r2=1505488&view=diff
==============================================================================
--- creadur/rat/trunk/RELEASE_NOTES.txt (original)
+++ creadur/rat/trunk/RELEASE_NOTES.txt Sun Jul 21 22:36:08 2013
@@ -10,6 +10,8 @@ The main change is RAT-138 - Rat 0.9 cou
* [RAT-138] RAT runs very slowly on some input
* [RAT-140] OASISLicense allows invalid Copyright line
* [RAT-139] FullTextMatchingLicense.prune uses inefficient deleteAtChar
+ * Improvements:
+ * [RAT-129] Add support for CDDL 1.0
* Updated dependencies and plugins
* Fixed up generics and annotations
Modified: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java?rev=1505488&r1=1505487&r2=1505488&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java (original)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java Sun Jul 21 22:36:08 2013
@@ -34,6 +34,7 @@ import org.apache.rat.analysis.license.W
import org.apache.rat.analysis.util.HeaderMatcherMultiplexer;
import java.io.InputStream;
+import org.apache.rat.analysis.license.CDDL1License;
@@ -60,7 +61,8 @@ public class Defaults {
new JavaDocLicenseNotRequired(),
new GeneratedLicenseNotRequired(),
new DojoLicenseHeader(),
- new TMF854LicenseHeader()
+ new TMF854LicenseHeader(),
+ new CDDL1License(),
};
public static final String PLAIN_STYLESHEET = "org/apache/rat/plain-rat.xsl";
Added: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CDDL1License.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CDDL1License.java?rev=1505488&view=auto
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CDDL1License.java (added)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CDDL1License.java Sun Jul 21 22:36:08 2013
@@ -0,0 +1,73 @@
+/*
+ * 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.commons.lang.ArrayUtils;
+import org.apache.rat.api.MetaData;
+
+/**
+ * Base CDDL 1.0 license.
+ */
+public class CDDL1License extends SimplePatternBasedLicense {
+
+ public static final String LICENSE_LINE =
+ "The contents of this file are subject to the terms of the Common Development[\\\\r\\\\n\\\\s]+"
+ + "and Distribution License(\"CDDL\") (the \"License\"). You may not use this file[\\\\r\\\\n\\\\s]+"
+ + "except in compliance with the License.";
+
+ public static final String LICENSE_URL =
+ ".*https://oss.oracle.com/licenses/CDDL.*";
+
+ public CDDL1License() {
+ super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_CDLL1,
+ MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_CDDL1,
+ "", new String[]{LICENSE_LINE, LICENSE_URL});
+ }
+
+ private Pattern[] getRegExPatterns() {
+ final Pattern[] result;
+ final String[] pttrns = getPatterns();
+ if (ArrayUtils.isEmpty(pttrns)) {
+ result = new Pattern[0];
+ } else {
+ result = new Pattern[pttrns.length];
+ for (int i = 0; i < pttrns.length; i++) {
+ result[i] = Pattern.compile(pttrns[i]);
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ protected boolean matches(final String pLine) {
+ if (pLine != null) {
+ final String[] pttrns = getPatterns();
+ if (pttrns != null) {
+ for (Pattern pttrn : getRegExPatterns()) {
+ if (pttrn.matcher(pLine).find()) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
Propchange: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CDDL1License.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/CDDL1License.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/api/MetaData.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/api/MetaData.java?rev=1505488&r1=1505487&r2=1505488&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/api/MetaData.java (original)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/api/MetaData.java Sun Jul 21 22:36:08 2013
@@ -64,6 +64,7 @@ public class MetaData {
public static final String RAT_LICENSE_FAMILY_CATEGORY_VALUE_GPL2 ="GPL2 ";
public static final String RAT_LICENSE_FAMILY_CATEGORY_VALUE_GPL3 = "GPL3 ";
public static final String RAT_LICENSE_FAMILY_CATEGORY_VALUE_MIT = "MIT ";
+ public static final String RAT_LICENSE_FAMILY_CATEGORY_VALUE_CDDL1 = "CDDL1";
public static final Datum RAT_LICENSE_FAMILY_CATEGORY_DATUM_GEN = new Datum(RAT_URL_LICENSE_FAMILY_CATEGORY, RAT_LICENSE_FAMILY_CATEGORY_VALUE_GEN);
public static final Datum RAT_LICENSE_FAMILY_CATEGORY_DATUM_UNKNOWN = new Datum(RAT_URL_LICENSE_FAMILY_CATEGORY, RAT_LICENSE_FAMILY_CATEGORY_VALUE_UNKNOWN);
@@ -77,6 +78,7 @@ public class MetaData {
public static final Datum RAT_LICENSE_FAMILY_CATEGORY_DATUM_GPL2 = new Datum(RAT_URL_LICENSE_FAMILY_CATEGORY,RAT_LICENSE_FAMILY_CATEGORY_VALUE_GPL2);
public static final Datum RAT_LICENSE_FAMILY_CATEGORY_DATUM_GPL3 = new Datum(RAT_URL_LICENSE_FAMILY_CATEGORY,RAT_LICENSE_FAMILY_CATEGORY_VALUE_GPL3);
public static final Datum RAT_LICENSE_FAMILY_CATEGORY_DATUM_MIT = new Datum(RAT_URL_LICENSE_FAMILY_CATEGORY,RAT_LICENSE_FAMILY_CATEGORY_VALUE_MIT);
+ public static final Datum RAT_LICENSE_FAMILY_CATEGORY_DATUM_CDLL1 = new Datum(RAT_URL_LICENSE_FAMILY_CATEGORY,RAT_LICENSE_FAMILY_CATEGORY_VALUE_CDDL1);
// License Family Standard Names
public static final String RAT_URL_LICENSE_FAMILY_NAME= RAT_BASE_URL + "#LicenseFamilyName";
@@ -93,6 +95,8 @@ public class MetaData {
"GNU General Public License, version 3";
public static final String RAT_LICENSE_FAMILY_NAME_VALUE_MIT =
"The MIT License";
+ public static final String RAT_LICENSE_FAMILY_NAME_VALUE_CDDL1 =
+ "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0";
public static final String RAT_LICENSE_FAMILY_NAME_VALUE_ACADEMIC_FREE_LICENSE_VERSION_2_1 = "Academic Free License, Version 2.1";
public static final String RAT_LICENSE_FAMILY_NAME_VALUE_UNKNOWN = "?????";
public static final Datum RAT_LICENSE_FAMILY_NAME_DATUM_W3C_SOFTWARE_COPYRIGHT
@@ -113,6 +117,8 @@ public class MetaData {
RAT_LICENSE_FAMILY_NAME_DATUM_GPL_VERSION_3 = new Datum(RAT_URL_LICENSE_FAMILY_NAME, RAT_LICENSE_FAMILY_NAME_VALUE_GPL_VERSION_3);
public static final Datum
RAT_LICENSE_FAMILY_NAME_DATUM_MIT = new Datum(RAT_URL_LICENSE_FAMILY_NAME, RAT_LICENSE_FAMILY_NAME_VALUE_MIT);
+ public static final Datum
+ RAT_LICENSE_FAMILY_NAME_DATUM_CDDL1 = new Datum(RAT_URL_LICENSE_FAMILY_NAME, RAT_LICENSE_FAMILY_NAME_VALUE_CDDL1);
public static final Datum RAT_LICENSE_FAMILY_NAME_DATUM_ACADEMIC_FREE_LICENSE_VERSION_2_1
= new Datum(RAT_URL_LICENSE_FAMILY_NAME, RAT_LICENSE_FAMILY_NAME_VALUE_ACADEMIC_FREE_LICENSE_VERSION_2_1);
public static final Datum RAT_LICENSE_FAMILY_NAME_DATUM_UNKNOWN
Added: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/license/CDDL1LicenseFamily.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/license/CDDL1LicenseFamily.java?rev=1505488&view=auto
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/license/CDDL1LicenseFamily.java (added)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/license/CDDL1LicenseFamily.java Sun Jul 21 22:36:08 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.license;
+
+import org.apache.rat.api.MetaData;
+
+/**
+ * Base implementation for CDDL 1.0 licenses.
+ */
+public class CDDL1LicenseFamily extends SimpleLicenseFamily {
+
+ public CDDL1LicenseFamily() {
+ super(MetaData.RAT_LICENSE_FAMILY_NAME_VALUE_CDDL1);
+ }
+}
Propchange: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/license/CDDL1LicenseFamily.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/license/CDDL1LicenseFamily.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/policy/DefaultPolicy.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/policy/DefaultPolicy.java?rev=1505488&r1=1505487&r2=1505488&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/policy/DefaultPolicy.java (original)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/policy/DefaultPolicy.java Sun Jul 21 22:36:08 2013
@@ -35,6 +35,7 @@ public class DefaultPolicy implements ID
MetaData.RAT_LICENSE_FAMILY_NAME_VALUE_W3C_DOCUMENT_COPYRIGHT,
MetaData.RAT_LICENSE_FAMILY_NAME_VALUE_MODIFIED_BSD_LICENSE,
MetaData.RAT_LICENSE_FAMILY_NAME_VALUE_MIT,
+ MetaData.RAT_LICENSE_FAMILY_NAME_VALUE_CDDL1,
};
private static final String[] toNames(final ILicenseFamily[] approvedLicenses) {
Added: creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CDDL1LicenseTest.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CDDL1LicenseTest.java?rev=1505488&view=auto
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CDDL1LicenseTest.java (added)
+++ creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CDDL1LicenseTest.java Sun Jul 21 22:36:08 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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.api.Document;
+import org.apache.rat.document.MockLocation;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CDDL1LicenseTest {
+
+ private static final String LICENSE_LINE =
+ " DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.\n\n"
+ + "Copyright 2011-2013 Tirasa. All rights reserved.\n\n"
+ + "The contents of this file are subject to the terms of the Common Development\n"
+ + "and Distribution License(\"CDDL\") (the \"License\"). You may not use this file\n"
+ + "except in compliance with the License.\n\n"
+ + "You can obtain a copy of the License at https://oss.oracle.com/licenses/CDDL\n"
+ + "See the License for the specific language governing permissions and limitations\n"
+ + "under the License.";
+
+ /**
+ * To ease testing provide a map with a given license version and the string to test for.
+ */
+ private static Map<IHeaderMatcher, String> licenseStringMap;
+
+ private Document subject;
+
+ @BeforeClass
+ public static void initLicencesUnderTest() {
+ licenseStringMap = new HashMap<IHeaderMatcher, String>();
+ licenseStringMap.put(new CDDL1License(), LICENSE_LINE);
+ assertEquals(1, licenseStringMap.entrySet().size());
+ }
+
+ @Before
+ public final void initSubject() {
+ this.subject = new MockLocation("subject");
+ }
+
+ @Test
+ public void testNegativeMatches() throws Exception {
+ for (Map.Entry<IHeaderMatcher, String> licenceUnderTest : licenseStringMap.entrySet()) {
+ assertFalse(licenceUnderTest.getKey().match(subject, "'Behold, Telemachus! (nor fear the sight,)"));
+ }
+ }
+
+ @Test
+ public void testPositiveMatchInDocument() throws Exception {
+ for (Map.Entry<IHeaderMatcher, String> licenceUnderTest : licenseStringMap.entrySet()) {
+ assertTrue(licenceUnderTest.getKey().match(subject, "\t" + licenceUnderTest.getValue()));
+ assertTrue(licenceUnderTest.getKey().match(subject, " " + licenceUnderTest.getValue()));
+ assertTrue(licenceUnderTest.getKey().match(subject, licenceUnderTest.getValue()));
+ assertTrue(licenceUnderTest.getKey().match(subject, " * " + licenceUnderTest.getValue()));
+ assertTrue(licenceUnderTest.getKey().match(subject, " // " + licenceUnderTest.getValue()));
+ assertTrue(licenceUnderTest.getKey().match(subject, " /* " + licenceUnderTest.getValue()));
+ assertTrue(licenceUnderTest.getKey().match(subject, " /** " + licenceUnderTest.getValue()));
+ assertTrue(licenceUnderTest.getKey().match(subject, " " + licenceUnderTest.getValue()));
+ assertTrue(licenceUnderTest.getKey().match(subject, " ## " + licenceUnderTest.getValue()));
+ assertTrue(licenceUnderTest.getKey().match(subject, " ## " + licenceUnderTest.getValue() + " ##"));
+ }
+ }
+}
Propchange: creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CDDL1LicenseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/CDDL1LicenseTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision