You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by jo...@apache.org on 2011/04/09 03:58:24 UTC
svn commit: r1090507 - in /incubator/rat/main/trunk:
apache-rat-core/src/main/java/org/apache/rat/analysis/license/
apache-rat-plugin/ apache-rat-plugin/src/main/filtered-resources/
apache-rat-plugin/src/main/filtered-resources/org/ apache-rat-plugin/s...
Author: jochen
Date: Sat Apr 9 01:58:23 2011
New Revision: 1090507
URL: http://svn.apache.org/viewvc?rev=1090507&view=rev
Log:
Adding preliminary support for configurable custom license matchers.
Added:
incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
incubator/rat/main/trunk/apache-rat-plugin/src/main/filtered-resources/org/
incubator/rat/main/trunk/apache-rat-plugin/src/main/filtered-resources/org/apache/
incubator/rat/main/trunk/apache-rat-plugin/src/main/filtered-resources/org/apache/rat/
incubator/rat/main/trunk/apache-rat-plugin/src/main/filtered-resources/org/apache/rat/mp/
incubator/rat/main/trunk/apache-rat-plugin/src/main/filtered-resources/org/apache/rat/mp/rat-report.properties
- copied unchanged from r1082434, incubator/rat/main/trunk/apache-rat-plugin/src/main/filtered-resources/rat-report.properties
incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/examples/custom-license.apt.vm
incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/
incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/
incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/invoker.properties
incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/pom.xml
incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/src.apt
incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/verify.bsh
incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/settings.xml
Removed:
incubator/rat/main/trunk/apache-rat-plugin/src/main/filtered-resources/rat-report.properties
incubator/rat/main/trunk/apache-rat-plugin/src/main/resources/org/apache/rat/mp/rat-report.properties
Modified:
incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/ApacheSoftwareLicense20.java
incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java
incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/DojoLicenseHeader.java
incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/TMF854LicenseHeader.java
incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CDocLicense.java
incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CLicense.java
incubator/rat/main/trunk/apache-rat-plugin/pom.xml
incubator/rat/main/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/index.apt
incubator/rat/main/trunk/apache-rat-plugin/src/site/fml/faq.fml
incubator/rat/main/trunk/apache-rat-plugin/src/site/site.xml
Modified: incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/ApacheSoftwareLicense20.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/ApacheSoftwareLicense20.java?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/ApacheSoftwareLicense20.java (original)
+++ incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/ApacheSoftwareLicense20.java Sat Apr 9 01:58:23 2011
@@ -18,38 +18,18 @@
*/
package org.apache.rat.analysis.license;
-import org.apache.rat.analysis.IHeaderMatcher;
-import org.apache.rat.analysis.RatHeaderAnalysisException;
-import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;
/**
* Matches Apache Software License, Version 2.0
*
*/
-public final class ApacheSoftwareLicense20 extends BaseLicense implements
- IHeaderMatcher {
-
+public final class ApacheSoftwareLicense20 extends SimplePatternBasedLicense {
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(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_ASL, MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_APACHE_LICENSE_VERSION_2_0, "");
- }
-
- public boolean match(Document subject, String line) throws RatHeaderAnalysisException {
- final boolean result = matches(line);
- if (result) {
- reportOnLicense(subject);
- }
- return result;
- }
-
- boolean matches(String line) {
- return line.indexOf(FIRST_LICENSE_LINE, 0) >= 0
- || line.indexOf(LICENSE_REFERENCE_LINE, 0) >= 0;
- }
-
- public void reset() {
+ super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_ASL, MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_APACHE_LICENSE_VERSION_2_0,
+ "", new String[]{FIRST_LICENSE_LINE, LICENSE_REFERENCE_LINE});
}
}
Modified: incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java (original)
+++ incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java Sat Apr 9 01:58:23 2011
@@ -33,7 +33,7 @@ public class BaseLicense {
this.licenseFamilyName = licenseFamilyName;
this.notes = notes;
}
-
+
public final void reportOnLicense(Document subject) throws RatHeaderAnalysisException {
final MetaData metaData = subject.getMetaData();
metaData.set(new MetaData.Datum(MetaData.RAT_URL_HEADER_SAMPLE, notes));
Modified: incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/DojoLicenseHeader.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/DojoLicenseHeader.java?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/DojoLicenseHeader.java (original)
+++ incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/DojoLicenseHeader.java Sat Apr 9 01:58:23 2011
@@ -18,16 +18,11 @@
*/
package org.apache.rat.analysis.license;
-import org.apache.rat.analysis.IHeaderMatcher;
-import org.apache.rat.analysis.RatHeaderAnalysisException;
-import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;
-public class DojoLicenseHeader extends BaseLicense implements IHeaderMatcher {
-
- private static final String LICENSE_URL
- = "http://dojotoolkit.org/community/licensing.shtml";
+public class DojoLicenseHeader extends SimplePatternBasedLicense {
+ private static final String LICENSE_URL = "http://dojotoolkit.org/community/licensing.shtml";
// Copyright (c) 2004-2006, The Dojo Foundation
// All Rights Reserved.
@@ -40,25 +35,7 @@ public class DojoLicenseHeader extends B
public DojoLicenseHeader() {
// TODO: support for dual licensing
// TODO: support for or higher clauses
- super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_DOJO, MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_MODIFIED_BSD_LICENSE, "Dual license AFL/BSD");
- }
-
-
- public void reset() {
-
+ super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_DOJO, MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_MODIFIED_BSD_LICENSE, "Dual license AFL/BSD",
+ new String[]{LICENSE_URL});
}
-
- public boolean match(Document subject, String line) throws RatHeaderAnalysisException {
- final boolean result = matches(line);
- if (result) {
- reportOnLicense(subject);
- }
- return result;
- }
-
- boolean matches(String line) {
- boolean result = (line != null && line.indexOf(LICENSE_URL) != -1);
- return result;
- }
-
}
Added: incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java?rev=1090507&view=auto
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java (added)
+++ incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java Sat Apr 9 01:58:23 2011
@@ -0,0 +1,119 @@
+/*
+ * 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 org.apache.rat.analysis.IHeaderMatcher;
+import org.apache.rat.analysis.RatHeaderAnalysisException;
+import org.apache.rat.api.Document;
+import org.apache.rat.api.MetaData;
+import org.apache.rat.api.MetaData.Datum;
+
+
+public class SimplePatternBasedLicense implements IHeaderMatcher {
+ private String licenseFamilyCategory;
+ private String licenseFamilyName;
+ private String notes;
+ private String[] patterns;
+
+ public SimplePatternBasedLicense() {
+ }
+
+ protected SimplePatternBasedLicense(Datum pLicenseFamilyCategory, Datum pLicenseFamilyName,
+ String pNotes, String[] pPatterns) {
+ if (!MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY.equals(pLicenseFamilyCategory.getName())) {
+ throw new IllegalStateException("Expected " + MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY
+ + ", got " + pLicenseFamilyCategory.getName());
+ }
+ setLicenseFamilyCategory(pLicenseFamilyCategory.getValue());
+ if (!MetaData.RAT_URL_LICENSE_FAMILY_NAME.equals(pLicenseFamilyName.getName())) {
+ throw new IllegalStateException("Expected " + MetaData.RAT_URL_LICENSE_FAMILY_NAME
+ + ", got " + pLicenseFamilyName.getName());
+ }
+ setLicenseFamilyName(pLicenseFamilyName.getValue());
+ setNotes(pNotes);
+ setPatterns(pPatterns);
+ }
+
+ public String[] getPatterns() {
+ return patterns;
+ }
+
+ public void setPatterns(String[] pPatterns) {
+ patterns = pPatterns;
+ }
+
+ public String getLicenseFamilyCategory() {
+ return licenseFamilyCategory;
+ }
+
+ public void setLicenseFamilyCategory(String pDocumentCategory) {
+ licenseFamilyCategory = pDocumentCategory;
+ }
+
+ public String getLicenseFamilyName() {
+ return licenseFamilyName;
+ }
+
+ public void setLicenseFamilyName(String pLicenseFamilyCategory) {
+ licenseFamilyName = pLicenseFamilyCategory;
+ }
+
+ public String getNotes() {
+ return notes;
+ }
+
+ public void setNotes(String pNotes) {
+ notes = pNotes;
+ }
+
+ protected void reportOnLicense(Document subject) throws RatHeaderAnalysisException {
+ final MetaData metaData = subject.getMetaData();
+ metaData.set(new MetaData.Datum(MetaData.RAT_URL_HEADER_SAMPLE, notes));
+ final String licFamilyCategory = getLicenseFamilyCategory();
+ metaData.set(new MetaData.Datum(MetaData.RAT_URL_HEADER_CATEGORY, licFamilyCategory));
+ metaData.set(new MetaData.Datum(MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY, licFamilyCategory));
+ metaData.set(new Datum(MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY, getLicenseFamilyCategory()));
+ }
+
+ protected boolean matches(String pLine) {
+ if (pLine != null) {
+ final String[] pttrns = getPatterns();
+ if (pttrns != null) {
+ for (int i = 0; i < pttrns.length; i++) {
+ if (pLine.indexOf(pttrns [i], 0) >= 0) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public void reset() {
+ // Nothing to do
+ }
+
+ public boolean match(Document pSubject, String pLine) throws RatHeaderAnalysisException {
+ final boolean result = matches(pLine);
+ if (result) {
+ reportOnLicense(pSubject);
+ }
+ return result;
+ }
+}
Modified: incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/TMF854LicenseHeader.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/TMF854LicenseHeader.java?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/TMF854LicenseHeader.java (original)
+++ incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/TMF854LicenseHeader.java Sat Apr 9 01:58:23 2011
@@ -18,40 +18,18 @@
*/
package org.apache.rat.analysis.license;
-import org.apache.rat.analysis.IHeaderMatcher;
-import org.apache.rat.analysis.RatHeaderAnalysisException;
-import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;
-public class TMF854LicenseHeader extends BaseLicense implements IHeaderMatcher {
+public class TMF854LicenseHeader extends SimplePatternBasedLicense {
- private static final String COPYRIGHT_HEADER
- = "TMF854 Version 1.0 - Copyright TeleManagement Forum";
+ private static final String COPYRIGHT_HEADER = "TMF854 Version 1.0 - Copyright TeleManagement Forum";
// TMF854 Version 1.0 - Copyright TeleManagement Forum
public TMF854LicenseHeader() {
super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_TMF,
- MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_MODIFIED_BSD_LICENSE, "BSD");
+ MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_MODIFIED_BSD_LICENSE, "BSD",
+ new String[]{COPYRIGHT_HEADER});
}
-
-
- public void reset() {
-
- }
-
- public boolean match(Document subject, String line) throws RatHeaderAnalysisException {
- final boolean result = matches(line);
- if (result) {
- reportOnLicense(subject);
- }
- return result;
- }
-
- boolean matches(String line) {
- boolean result = (line != null && line.indexOf(COPYRIGHT_HEADER) != -1);
- return result;
- }
-
}
Modified: incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CDocLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CDocLicense.java?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CDocLicense.java (original)
+++ incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CDocLicense.java Sat Apr 9 01:58:23 2011
@@ -18,12 +18,9 @@
*/
package org.apache.rat.analysis.license;
-import org.apache.rat.analysis.IHeaderMatcher;
-import org.apache.rat.analysis.RatHeaderAnalysisException;
-import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;
-public class W3CDocLicense extends BaseLicense implements IHeaderMatcher {
+public class W3CDocLicense extends SimplePatternBasedLicense {
private static final String NOTES
= "Note that W3CD does not allow modifications. See http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231.";
@@ -32,20 +29,7 @@ public class W3CDocLicense extends BaseL
public W3CDocLicense() {
super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_W3CD,
- MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_W3C_DOCUMENT_COPYRIGHT, NOTES);
-
+ MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_W3C_DOCUMENT_COPYRIGHT, NOTES,
+ new String[]{COPYRIGHT_URL});
}
-
- public boolean match(Document subject, String line) throws RatHeaderAnalysisException {
- boolean result = line != null && line.indexOf(COPYRIGHT_URL) != -1;
- if (result) {
- reportOnLicense(subject);
- }
- return result;
- }
-
- public void reset() {
- // Matcher is not stateful
- }
-
}
Modified: incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CLicense.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CLicense.java?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CLicense.java (original)
+++ incubator/rat/main/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/W3CLicense.java Sat Apr 9 01:58:23 2011
@@ -18,12 +18,9 @@
*/
package org.apache.rat.analysis.license;
-import org.apache.rat.analysis.IHeaderMatcher;
-import org.apache.rat.analysis.RatHeaderAnalysisException;
-import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;
-public class W3CLicense extends BaseLicense implements IHeaderMatcher {
+public class W3CLicense extends SimplePatternBasedLicense {
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.";
@@ -32,20 +29,8 @@ public class W3CLicense extends BaseLice
public W3CLicense() {
super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_W3C,
- MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_W3C_SOFTWARE_COPYRIGHT, NOTES);
+ MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_W3C_SOFTWARE_COPYRIGHT, NOTES,
+ new String[]{COPYRIGHT_URL});
}
-
- public boolean match(Document subject, String line) throws RatHeaderAnalysisException {
- boolean result = line != null && line.indexOf(COPYRIGHT_URL) != -1;
- if (result) {
- reportOnLicense(subject);
- }
- return result;
- }
-
- public void reset() {
- // Matcher is not stateful
- }
-
}
Modified: incubator/rat/main/trunk/apache-rat-plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/pom.xml?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/pom.xml (original)
+++ incubator/rat/main/trunk/apache-rat-plugin/pom.xml Sat Apr 9 01:58:23 2011
@@ -54,6 +54,32 @@
</includes>
</resource>
</resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>1.5</version>
+ <configuration>
+ <projectsDirectory>src/test/invoker</projectsDirectory>
+ <cloneProjectsTo>${project.build.directory}/invoker</cloneProjectsTo>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+ <settingsFile>src/test/invoker/settings.xml</settingsFile>
+ <postBuildHookScript>verify.bsh</postBuildHookScript>
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>install</goal>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
</build>
<dependencies>
@@ -94,7 +120,7 @@
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
- <version>1.0-beta-1</version>
+ <version>1.1</version>
</dependency>
</dependencies>
Modified: incubator/rat/main/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java (original)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java Sat Apr 9 01:58:23 2011
@@ -79,18 +79,35 @@ public abstract class AbstractRatMojo ex
protected File basedir;
/**
- * The licenses we want to match on.
+ * Specifies the licenses to accept. Deprecated, use {@link #licenses} instead.
*
* @parameter
+ * @deprecated Use {@link #licenses} instead.
*/
private HeaderMatcherSpecification[] licenseMatchers;
/**
+ * Specifies the licenses to accept. By default, these are added to the default
+ * licenses, unless you set {@link #addDefaultLicenseMatchers} to true.
+ * @parameter
+ * @since 0.8
+ */
+ private IHeaderMatcher[] licenses;
+
+ /**
* The set of approved license family names.
+ * @deprecated Use {@link #licenseFamilies} instead.
*/
private LicenseFamilySpecification[] licenseFamilyNames;
/**
+ * Specifies the license families to accept.
+ * @parameter
+ * @since 0.8
+ */
+ private ILicenseFamily[] licenseFamilies;
+
+ /**
* Whether to add the default list of license matchers.
*
* @parameter expression="${rat.addDefaultLicenseMatchers}" default-value="true"
@@ -178,6 +195,11 @@ public abstract class AbstractRatMojo ex
protected IHeaderMatcher[] getLicenseMatchers() throws MojoFailureException, MojoExecutionException
{
final List list = new ArrayList();
+ if ( licenses != null )
+ {
+ list.addAll( Arrays.asList( licenses ) );
+ }
+
if ( licenseMatchers != null )
{
for ( int i = 0; i < licenseMatchers.length; i++ )
@@ -377,17 +399,24 @@ public abstract class AbstractRatMojo ex
private ILicenseFamily[] getApprovedLicenseNames() throws MojoExecutionException, MojoFailureException
{
- if ( licenseFamilyNames == null || licenseFamilyNames.length == 0 )
+ final List list = new ArrayList();
+ if ( licenseFamilies != null )
{
- return null;
+ list.addAll( Arrays.asList( licenseFamilies ) );
}
- ILicenseFamily[] results = new ILicenseFamily[licenseFamilyNames.length];
- for ( int i = 0; i < licenseFamilyNames.length; i++ )
+ if ( licenseFamilyNames != null)
{
- LicenseFamilySpecification spec = licenseFamilyNames[i];
- ILicenseFamily licenseFamily = (ILicenseFamily) newInstance( ILicenseFamily.class, spec.getClassName() );
- results[i] = licenseFamily;
+ for ( int i = 0; i < licenseFamilyNames.length; i++ )
+ {
+ LicenseFamilySpecification spec = licenseFamilyNames[i];
+ list.add( newInstance( ILicenseFamily.class, spec.getClassName() ) );
+ }
+ }
+
+ if ( list.isEmpty() )
+ {
+ return null;
}
- return results;
+ return (ILicenseFamily[]) list.toArray( new ILicenseFamily[ list.size() ] );
}
}
Added: incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/examples/custom-license.apt.vm
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/examples/custom-license.apt.vm?rev=1090507&view=auto
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/examples/custom-license.apt.vm (added)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/examples/custom-license.apt.vm Sat Apr 9 01:58:23 2011
@@ -0,0 +1,82 @@
+~~ 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.
+
+ -----------------------
+ Custom License Matchers
+ -----------------------
+
+Custom License Matchers
+
+ Rat comes with a set of predefined license matchers, that can be used
+ some typical licenses. However, they will not always be sufficient.
+ In such cases, you may use a custom license matcher.
+
+ A custom license matcher is an implementation of
+ <<<org.apache.rat.analysis.IHeaderMatcher>>>. Suggest that your
+ source files must contain a header like the following:
+
+------------------------------------------------------------------
+ /**
+ * Yet Another Software License, 1.0
+ *
+ * Lots of text, specifying the users rights, and whatever ...
+ */
+------------------------------------------------------------------
+
+ A very easy way to search for such headers would be to scan
+ for the string "Yet Another Software License, 1.0". And here's
+ how you would do that in your POM:
+
+------------------------------------------------------------------
+ <build>
+ <plugins>
+ ...
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>${currentVersion}</version>
+ <configuration>
+ <licenses>
+ <license implementation="org.apache.rat.analysis.license.SimplePatternBasedLicense">
+ <licenseFamilyCategory>YASL1</licenseFamilyCategory>
+ <licenseFamilyName>Yet Another Software License (YASL) 1.0</licenseFamilyName>
+ <notes></notes>
+ <patterns>
+ <pattern>Yet Another Software License, 1.0</pattern>
+ </patterns>
+ </license>
+ </licenses>
+ </configuration>
+ </plugin>
+ ...
+ </plugins>
+ </build>
+------------------------------------------------------------------
+
+ The following terms are used in the example:
+
+*-----------------------+-----------+
+| licenseFamilyCategory | The license family category is a very short string (exactly 5 characters, preferrably no blanks),
+| | which identifies the license. For example, this could be <<<ASL20>>> to identify the Apache
+| | Software License, 2.0.
+*-----------------------+-----------+
+| licenseFamilyName | The license family name is a longer string, which gives the licenses full name. For example,
+| | this could be <<<Apache Software License, 2.0>>>.
+*-----------------------+-----------+
+| notes | You might specify additional notes here, like "Dual licensed GPL/MPL".
+*-----------------------+-----------+
+| patterns | Specifies a set of patterns being searched. The source file is assumed to contain the
+| | license header, if at least one of these patterns is found.
+*-----------------------+-----------+
Modified: incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/index.apt?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/index.apt (original)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/site/apt/index.apt Sat Apr 9 01:58:23 2011
@@ -51,3 +51,5 @@ The RAT Maven Plugin
when the project is built.
* Adding the report to the {{{examples/site.html}generated site}}.
+
+ * Applying a {{{examples/custom-license.html}custom license}}.
Modified: incubator/rat/main/trunk/apache-rat-plugin/src/site/fml/faq.fml
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/site/fml/faq.fml?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/site/fml/faq.fml (original)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/site/fml/faq.fml Sat Apr 9 01:58:23 2011
@@ -67,5 +67,11 @@
to false.</p>
</answer>
</faq>
+ <faq id="customLicense">
+ <question>Can I use Rat to validate against a custom license header?</question>
+ <answer>
+ <p>See <a href="examples/custom-license.html">this example</a> to see how.</p>
+ </answer>
+ </faq>
</part>
</faqs>
Modified: incubator/rat/main/trunk/apache-rat-plugin/src/site/site.xml
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/site/site.xml?rev=1090507&r1=1090506&r2=1090507&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/site/site.xml (original)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/site/site.xml Sat Apr 9 01:58:23 2011
@@ -29,6 +29,7 @@
<item name="Basic use" href="examples/basic.html"/>
<item name="Running the plugin automatically" href="examples/verify.html"/>
<item name="Adding a report to the site" href="examples/site.html"/>
+ <item name="Custom license" href="examples/custom-license.html"/>
</menu>
<menu ref="reports"/>
Added: incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/invoker.properties
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/invoker.properties?rev=1090507&view=auto
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/invoker.properties (added)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/invoker.properties Sat Apr 9 01:58:23 2011
@@ -0,0 +1 @@
+invoker.goals = clean org.apache.rat:apache-rat-plugin::check
Added: incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/pom.xml
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/pom.xml?rev=1090507&view=auto
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/pom.xml (added)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/pom.xml Sat Apr 9 01:58:23 2011
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.rat.test</groupId>
+ <artifactId>it1</artifactId>
+ <version>1.0</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>@pom.version@</version>
+ <configuration>
+ <licenses>
+ <license implementation="org.apache.rat.analysis.license.SimplePatternBasedLicense">
+ <licenseFamilyCategory>YAL__</licenseFamilyCategory>
+ <licenseFamilyName>Yet Another Software License</licenseFamilyName>
+ <notes></notes>
+ <patterns>
+ <pattern>Yet Another License</pattern>
+ </patterns>
+ </license>
+ </licenses>
+ <includes>
+ <include>src.apt</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/src.apt
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/src.apt?rev=1090507&view=auto
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/src.apt (added)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/src.apt Sat Apr 9 01:58:23 2011
@@ -0,0 +1,12 @@
+~~ Yet Another License, just for test purposes
+
+ --------------
+ Some text file
+ --------------
+
+Some text file
+
+ This is a text file, which intentionally has no Apache License Header.
+ Instead, it contains a dummy license header. The RAT plugin should
+ accept it with a proper custom license matcher.
+
Added: incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/verify.bsh
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/verify.bsh?rev=1090507&view=auto
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/verify.bsh (added)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/it1/verify.bsh Sat Apr 9 01:58:23 2011
@@ -0,0 +1,23 @@
+import java.io.*;
+
+File f = new File(basedir, "target/rat.txt").getAbsoluteFile();
+FileInputStream fis = new FileInputStream(f);
+Reader r = new InputStreamReader(fis);
+BufferedReader br = new BufferedReader(r);
+boolean found = false;
+for (;;) {
+ String line = br.readLine();
+ if (line == null) {
+ break;
+ }
+ if (line.indexOf("YAL__ src.apt") >= 0) {
+ found = true;
+ break;
+ }
+}
+br.close();
+r.close();
+fis.close();
+if (!found) {
+ throw new IllegalStateException("Expecting Yet Another License for src.apt");
+}
\ No newline at end of file
Added: incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/settings.xml
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/settings.xml?rev=1090507&view=auto
==============================================================================
--- incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/settings.xml (added)
+++ incubator/rat/main/trunk/apache-rat-plugin/src/test/invoker/settings.xml Sat Apr 9 01:58:23 2011
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<settings>
+ <profiles>
+ <profile>
+ <id>it-repo</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <repositories>
+ <repository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</settings>