blob: 1c8805c80a4c2b2d66dc8b4468e49cbf3f4082af [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.11.1 from src/site/apt/examples/custom-license.apt.vm at 2024-05-07
| Rendered using Apache Maven Default Skin
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 1.11.1" />
<title>Apache Rat™ Plugin for Apache Maven &#x2013; Custom License Matchers</title>
<link rel="stylesheet" href="../css/maven-base.css" />
<link rel="stylesheet" href="../css/maven-theme.css" />
<link rel="stylesheet" href="../css/site.css" />
<link rel="stylesheet" href="../css/print.css" media="print" />
<link href="https://creadur.apache.org/font/matesc.css" type="text/css" rel="stylesheet" />
</head>
<body class="composite">
<div id="banner">
<a href="https://www.apache.org/" id="bannerLeft"><img src="https://www.apache.org/img/asf_logo.png" alt="The Apache Software Foundation" title="The Apache Software Foundation"/></a> <div class="clear">
<hr/>
</div>
</div>
<div id="breadcrumbs">
<div class="xleft">
<span id="publishDate">Last Published: 2024-05-07</span>
| <span id="projectVersion">Version: 0.17-SNAPSHOT</span>
| <a href="https://www.apache.org/" class="externalLink" title="Apache">Apache</a> &gt;
<a href="https://creadur.apache.org/" class="externalLink" title="Creadur">Creadur</a> &gt;
<a href="https://creadur.apache.org/rat/" class="externalLink" title="Rat">Rat</a> &gt;
<a href="../index.html" title="Apache Rat™ Plugin for Apache Maven">Apache Rat™ Plugin for Apache Maven</a> &gt;
Custom License Matchers
</div>
<div class="xright"> </div>
<div class="clear">
<hr/>
</div>
</div>
<div id="leftColumn">
<div id="navcolumn">
<h5>Parent Project</h5>
<ul>
<li class="none"><a href="../../index.html" title="Apache Creadur Rat">Apache Creadur Rat</a></li>
</ul>
<h5>Overview</h5>
<ul>
<li class="none"><a href="../index.html" title="Introduction">Introduction</a></li>
<li class="none"><a href="../plugin-info.html" title="Goals">Goals</a></li>
<li class="none"><a href="../usage.html" title="Usage">Usage</a></li>
<li class="none"><a href="../faq.html" title="FAQ">FAQ</a></li>
</ul>
<h5>Examples</h5>
<ul>
<li class="none"><a href="../examples/basic.html" title="Basic use">Basic use</a></li>
<li class="none"><a href="../examples/verify.html" title="Running the plugin automatically">Running the plugin automatically</a></li>
<li class="none"><a href="../examples/site.html" title="Adding a report to the site">Adding a report to the site</a></li>
<li class="none"><strong>Custom license</strong></li>
</ul>
<h5>Project Documentation</h5>
<ul>
<li class="collapsed"><a href="../project-info.html" title="Project Information">Project Information</a></li>
<li class="collapsed"><a href="../project-reports.html" title="Project Reports">Project Reports</a></li>
</ul>
<h5>Apache Rat™</h5>
<ul>
<li class="none"><a href="../../index.html" title="Introducing Rat">Introducing Rat</a></li>
<li class="none"><a href="../../apidocs/index.html" title="Javadocs">Javadocs</a></li>
<li class="none"><a href="../../download_rat.cgi" title="Downloads">Downloads</a></li>
<li class="none"><a href="../../RELEASE_NOTES.txt" title="Changes">Changes</a></li>
</ul>
<h5>Running Rat</h5>
<ul>
<li class="none"><a href="../../apache-rat/index.html" title="From The Command Line">From The Command Line</a></li>
<li class="none"><a href="../../apache-rat-tasks/index.html" title="With Ant">With Ant</a></li>
<li class="none"><a href="../../apache-rat-plugin/index.html" title="With Maven">With Maven</a></li>
</ul>
<h5>Apache Creadur™</h5>
<ul>
<li class="none"><a href="https://creadur.apache.org" class="externalLink" title="Creadur Project Home">Creadur Project Home</a></li>
<li class="none"><a href="https://creadur.apache.org/tentacles" class="externalLink" title="Apache Tentacles">Apache Tentacles</a></li>
<li class="none"><a href="https://creadur.apache.org/whisker" class="externalLink" title="Apache Whisker">Apache Whisker</a></li>
<li class="none"><a href="https://www.apache.org/security/" class="externalLink" title="Security">Security</a></li>
<li class="none"><a href="https://www.apache.org/licenses/" class="externalLink" title="License">License</a></li>
<li class="none"><a href="https://privacy.apache.org/policies/privacy-policy-public.html" class="externalLink" title="Privacy">Privacy</a></li>
<li class="none"><a href="https://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Sponsorship">Sponsorship</a></li>
<li class="none"><a href="https://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks">Thanks</a></li>
</ul>
<h5>The Apache Software Foundation</h5>
<ul>
<li class="none"><a href="https://www.apache.org/foundation" class="externalLink" title="About the Foundation">About the Foundation</a></li>
<li class="none"><a href="https://projects.apache.org" class="externalLink" title="The projects">The projects</a></li>
<li class="none"><a href="https://people.apache.org" class="externalLink" title="The people">The people</a></li>
<li class="none"><a href="https://www.apache.org/foundation/how-it-works.html" class="externalLink" title="How we work">How we work</a></li>
<li class="none"><a href="https://www.apache.org/foundation/how-it-works.html#history" class="externalLink" title="Our history">Our history</a></li>
<li class="none"><a href="https://blogs.apache.org/foundation/" class="externalLink" title="News">News</a></li>
</ul>
<h5>Contribute</h5>
<ul>
<li class="none"><a href="https://www.apache.org/foundation/getinvolved.html" class="externalLink" title="Get Involved">Get Involved</a></li>
</ul>
<h5>Committer Info</h5>
<ul>
<li class="none"><a href="https://www.apache.org/dev/committers.html" class="externalLink" title="ASF Committers' FAQ">ASF Committers' FAQ</a></li>
<li class="none"><a href="https://www.apache.org/dev/new-committers-guide.html" class="externalLink" title="New Committers Guide">New Committers Guide</a></li>
<li class="none"><a href="../../site-publish.html" title="Howto publish this site">Howto publish this site</a></li>
<li class="none"><a href="https://community.apache.org/" class="externalLink" title="Community">Community</a></li>
<li class="none"><a href="https://www.apache.org/legal/" class="externalLink" title="Legal">Legal</a></li>
<li class="none"><a href="https://www.apache.org/foundation/marks/" class="externalLink" title="Branding">Branding</a></li>
<li class="none"><a href="https://www.apache.org/press/" class="externalLink" title="Media Relations">Media Relations</a></li>
</ul>
<a href="https://maven.apache.org/" title="Maven" class="poweredBy">
<img class="poweredBy" alt="Maven" src="https://maven.apache.org/images/logos/maven-feather.png" />
</a>
</div>
</div>
<div id="bodyColumn">
<div id="contentBox">
<section>
<h2><a name="Custom_License_Matchers"></a>Custom License Matchers</h2>
<p>Rat comes with a set of predefined license matchers, that can be used on typical licenses. However, they will not always be sufficient. In such cases, you may configure a custom license matcher.</p>
<p>The simplest way to create a license check is to create an XML file describing the new license and add it to the processing with the additionalLicenseFiles option.</p>
<p>The second option is to define the custom license directly in the POM. Unlike earlier version (before 0.16) no custom implementations are required to define custom licenses.</p>
<p>There is a file that defines all of the standard licenses: <a class="externalLink" href="https://github.com/apache/creadur-rat/blob/master/apache-rat-core/src/main/resources/org/apache/rat/default.xml">default.xml</a></p>
<p>Please be aware that custom licenses need to have <b>unique names</b>, otherwise a warning is issued and your custom definitions are ignored in favour of the standard license definitions.</p>
<div>
<pre> /**
* Yet Another Software License, 1.0
*
* Lots of text, specifying the users rights, and whatever ...
*/</pre></div>
<p>A very easy way to search for such headers would be to scan for the string &quot;Yet Another Software License, 1.0&quot;. And here's how you would do that in your POM:</p>
<div>
<pre> &lt;build&gt;
&lt;plugins&gt;
...
&lt;plugin&gt;
&lt;groupId&gt;org.apache.rat&lt;/groupId&gt;
&lt;artifactId&gt;apache-rat-plugin&lt;/artifactId&gt;
&lt;version&gt;0.17-SNAPSHOT&lt;/version&gt;
&lt;configuration&gt;
&lt;licenses&gt;
&lt;license&gt;
&lt;family&gt;YASL1&lt;/family&gt;
&lt;notes&gt;&lt;/notes&gt;
&lt;text&gt;Yet Another Software License, 1.0&lt;/text&gt;
&lt;/license&gt;
&lt;/licenses&gt;
&lt;families&gt;
&lt;family&gt;
&lt;id&gt;YASL1&lt;/id&gt;
&lt;name&gt;Yet Another Software License&lt;/name&gt;
&lt;/family&gt;
&lt;/families&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
...
&lt;/plugins&gt;
&lt;/build&gt;</pre></div>
<p>This is very similar to the XML format for defining the configuration.</p></section><section>
<h2><a name="Approved_License_Families"></a>Approved License Families</h2>
<p>By default all POM defined licenses are considered approved, this is a change from pre 0.16 versions. If there are families that are defined in the pom but that should not be considered approved then a list of approved license families must be provided.</p>
<p>In the following example, we define YASL1 and BAD1 and then indicate that BAD1 is bad by specifying that YASL1 is good.</p>
<div>
<pre> &lt;build&gt;
&lt;plugins&gt;
...
&lt;plugin&gt;
&lt;groupId&gt;org.apache.rat&lt;/groupId&gt;
&lt;artifactId&gt;apache-rat-plugin&lt;/artifactId&gt;
&lt;version&gt;0.17-SNAPSHOT&lt;/version&gt;
&lt;configuration&gt;
&lt;licenses&gt;
&lt;license&gt;
&lt;family&gt;YASL1&lt;/family&gt;
&lt;notes&gt;&lt;/notes&gt;
&lt;text&gt;Yet Another Software License, 1.0&lt;/text&gt;
&lt;/license&gt;
&lt;/licenses&gt;
&lt;families&gt;
&lt;family&gt;
&lt;id&gt;YASL1&lt;/id&gt;
&lt;name&gt;Yet Another Software License&lt;/name&gt;
&lt;/family&gt;
&lt;family&gt;
&lt;id&gt;BAD1&lt;/id&gt;
&lt;name&gt;A Bad Sofware License&lt;/name&gt;
&lt;/family&gt;
&lt;/families&gt;
&lt;approvedLicenses&gt;
&lt;id&gt;YASL1&lt;/id&gt;
&lt;/approvedLicenses&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
...
&lt;/plugins&gt;
&lt;/build&gt;</pre></div></section><section>
<h2><a name="Overview_of_configuration_options"></a>Overview of configuration options</h2>
<p>When defining custom licenses, remember the following architecture constraints:</p>
<ul>
<li>Each license is associated with a family. Multiple licenses can be associated with a family.</li>
<li>Each license may have a notes element.</li>
<li>Each license has one matcher.</li></ul><section>
<h3><a name="Matcher_details"></a>Matcher details</h3>
<p><b>all</b> - A collection of matchers in which all enclosed matchers have to be true for the matcher to report true.</p>
<div>
<pre>&lt;all&gt;
&lt;text&gt;This text is required&lt;/text&gt;
&lt;text&gt;as is this text, both have to trigger before 'all' will be true&lt;/text&gt;
&lt;/all&gt;</pre></div>
<p><b>any</b> - A collection of matchers that will report true if any enclosed matcher is true.</p>
<div>
<pre>&lt;any&gt;
&lt;text&gt;This text will trigger a match all by itself&lt;/text&gt;
&lt;text&gt;So will this text.&lt;/text&gt;
&lt;/any&gt;</pre></div>
<p><b>copyright</b> - A matcher that matches Copyright text. This uses regular expressions and so should only be used when looking for copyrights with specific patterns that are not caught by a standard text matcher. This matcher will match <code>&quot;(C)&quot;</code>, <code>&quot;copyright&quot;</code>, or <code>&quot;&#xa9;&quot;</code>. (text is not case sensitive). It will also match things like <code>Copyright (c) joe 1995</code> as well as <code>Copyright (C) 1995 joe</code> and <code>Copyright (C) joe 1995</code>. Copyright has 3 child elements:</p>
<ul>
<li><b>start</b> - the starting date of the copyright or the only date.</li>
<li><b>end</b> - the ending date of the copyright. Only valid if the starting date is provided.</li>
<li><b>owner</b> - the copyright owner.
<div>
<pre>
&lt;copyright&gt; &lt;!-- this will match (c) 1995-1996 joe, or (c) joe 1995-1996 --&gt;
&lt;start&gt;1995&lt;/text&gt;
&lt;end&gt;1996&lt;/end&gt;
&lt;owner&gt;joe&lt;/owner&gt;
&lt;/copyright&gt;
&lt;copyright&gt; &lt;!-- this will match (c) 1995 joe, or (c) joe 1995 --&gt;
&lt;start&gt;1995&lt;/text&gt;
&lt;owner&gt;joe&lt;/owner&gt;
&lt;/copyright&gt;
&lt;copyright&gt; &lt;!-- this will match (c) nnnn joe, or (c) joe nnnn, where nnnn is a 4 digit year --&gt;
&lt;owner&gt;joe&lt;/owner&gt;
&lt;/copyright&gt;
&lt;copyright&gt; &lt;!-- this will match (c) nnnn, where nnnn is a 4 digit year --&gt;
&lt;/copyright&gt;
</pre></div></li></ul>
<p><b>not</b> - A matcher that wraps one matcher and negates its value. Not matchers require that the entire header be read before it can report true or false. This may significantly slow processing.</p>
<div>
<pre>&lt;not&gt;
&lt;text&gt;This text must not be present&lt;/text&gt;
&lt;/not&gt;</pre></div>
<p><b>regex</b> - A matcher that matches a regex string.</p>
<div>
<pre>&lt;regex&gt;[H|h]ello\s[W|w]orld&lt;/regex&gt;</pre></div>
<p><b>spdx</b> - A matcher that matches SPDX tags. SPDX tags have the form: <code>SPDX-License-Identifier: short-name</code>, where short-name matches the regex pattern <code>&quot;[A-Za-z0-9\.-]+&quot;.</code> spdx takes the short name as an argument.</p>
<div>
<pre>&lt;spdx&gt;Apache-2.0&lt;/spdx&gt;</pre></div><section>
<h4><a name="Combining_the_examples_together"></a>Combining the examples together</h4>
<div>
<pre>&lt;all&gt;
&lt;any&gt; &lt;!-- HINT: any of the enclosed matchers will cause a match --&gt;
&lt;all&gt; &lt;!-- must have both 'This text is required' and a copyright statement --&gt;
&lt;text&gt;This text is required&lt;/text&gt;
&lt;copyright /&gt;
&lt;/all&gt;
&lt;copyright&gt; &lt;!-- accept any file that has a copyright by joe --&gt;
&lt;owner&gt;joe&lt;/owner&gt;
&lt;/copyright&gt;
&lt;!-- accept any file with &quot;Hello World&quot; --&gt;
&lt;regex&gt;[H|h]ello\s[W|w]orld&lt;/regex&gt;
&lt;!-- accept any file with 'SPDX-License-Identifier: Apache-2.0' --&gt;
&lt;spdx&gt;Apache-2.0&lt;/spdx&gt;
&lt;/any&gt;
&lt;!-- make sure the text 'This text must not be present' is not present --&gt;
&lt;not&gt;
&lt;text&gt;This text must not be present&lt;/text&gt;
&lt;/not&gt;
&lt;/all&gt;</pre></div></section></section></section>
</div>
</div>
<div class="clear">
<hr/>
</div>
<div id="footer">
<div class="xright">
Copyright &copy; 2016-2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0.
Apache Creadur, Creadur, Apache Rat, Apache Tentacles, Apache Whisker, Apache and the Apache feather logo are trademarks
of The Apache Software Foundation.
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
All other marks mentioned may be trademarks or registered trademarks of their respective owners.
</div>
<div class="clear">
<hr/>
</div>
</div>
</body>
</html>