License reporting and modification

Experimenting with a license requirements tool

RAT (version 0.6) : http://code.google.com/p/arat/

The tool checks source code for licensing. Java based, extendable and has a future. The tool can find files without the correct license and add a license whenever ordered to do so.

Note: There are 6 attachments to this page including the modified Java and the application itself.

RECIPE

svn co http://svn.apache.org/repos/asf/incubator/rat/main/trunk/rat/

After modifying the code for the Sakai license mentioned next:

mvn -Dmaven.test.skip=true install
cd rat-app/target
java -jar rat-app-0.6-SNAPSHOT.jar /path_to_source > info.txt

The full set of commands are:

Options

-a,--addLicence        Add the default licence header to any file with an
unknown licence that is not in the exclusion list. By default new files
will be created with the licence header, to force the modification of

existing files use the --force option.
-c,--copyright <arg>   The copyright message to use in the licence

headers, usually in the form of "Copyright 2008 Foo"
-f,--force             Forces any changes in files to be written without

confirmation
-h,--help              Print help for the RAT command line interface and exit

-x,--xml               Output the report in XML format

DETAILS

Top dir is /rat-core/src/main/java/org/apache/rat/

The out of the box licenses checked need to be modified. The list of licenses can be found in Defaults.java. I added a Sakai License and removed others, (classes included as attachments) E.G:

public static final IHeaderMatcher\[\] DEFAULT_MATCHERS =

new IHeaderMatcher\[\]
{  new JavaDocLicenseNotRequired(),  new GeneratedLicenseNotRequired(),  new SakaiLicense()  }
;

analysis/SakaiLicense.java checks each line for the URL http://www.osedu.org/licenses/ECL-2.0

The code looks like

public final class SakaiLicense extends BaseLicense implements

IHeaderMatcher {

public static final String LICENSE_REFERENCE_LINE = "http://www.osedu.org/licenses/ECL-2.0";

public SakaiLicense()
{  super(Claims.SAK_CODE, SakaiLicenseFamily.SAKAI_SOFTWARE_LICENSE_NAME, "");  }
public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {

final boolean result = matches(line);

if (result)
{  reportOnLicense(subject, reporter);  }
return result;

}

boolean matches(String line)
{  return line.indexOf(LICENSE_REFERENCE_LINE, 0) >= 0;  }
public void reset() {

}

}

I needed to add a license family (under the license directory):

package org.apache.rat.license;

public final class SakaiLicenseFamily implements ILicenseFamily {

public static final String SAKAI_SOFTWARE_LICENSE_NAME = "Educational License 2.0";

public String getFamilyName()
{  return SAKAI_SOFTWARE_LICENSE_NAME;  }
}

And update an entry in analysis/Claims.java

public static final String SAK_CODE = "ECL2 ";

Finally I modified the report generation default XSL to include a Sakai count.

Example Report Snippet

 *****************************************************
Summary
-------
Notes: 208
Binaries: 2882
Archives: 16
Standards: 11337

SAKAI Licensed: 3490
Generated Documents: 7

JavaDocs are generated and so license header is optional
Generated files do not required license headers

7840 Unknown Licenses

*******************************

Archives (+ indicates readable, $ unreadable):

 + /home/aberg/sakai/src_one/sakai_2-6-0/osp/reports/api-impl/src/resources/org/theospi/portfolio/reports/xsl/osp/matrix/EvaluationResultsForm.zip
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/docs/image-templates/sakai-2.5-site-tabs/images_fr_SAK-11782.zip
 $ /home/aberg/sakai/src_one/sakai_2-6-0/reference/docs/loadtesting/jmeter/test_upload/TestTar.gz
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/dojo/dojo-release-0.9.0/dojox/off/demos/editor/server/editor.jar
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/dojo/dojo-release-0.9.0/dojox/off/demos/editor/server/lib/commons-beanutils.jar
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/dojo/dojo-release-0.9.0/dojox/off/demos/editor/server/lib/commons-lang-2.2.jar
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/dojo/dojo-release-0.9.0/dojox/off/demos/editor/server/lib/derby.jar
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/dojo/dojo-release-0.9.0/dojox/off/demos/editor/server/lib/ezmorph-1.0.jar
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/dojo/dojo-release-0.9.0/dojox/off/demos/editor/server/lib/jetty-6.1.3.jar
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/dojo/dojo-release-0.9.0/dojox/off/demos/editor/server/lib/jetty-util-6.1.3.jar
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/dojo/dojo-release-0.9.0/dojox/off/demos/editor/server/lib/json-lib-1.0b2-jdk13.jar
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/dojo/dojo-release-0.9.0/dojox/off/demos/editor/server/lib/servlet-api-2.5-6.1.3.jar
 + /home/aberg/sakai/src_one/sakai_2-6-0/reference/library/src/webapp/schedule/CalendarTemplate.zip
 + /home/aberg/sakai/src_one/sakai_2-6-0/reports/reports-tool/tool/src/webapp/WEB-INF/reportxsls/osp/matrix/EvaluationResultsForm.zip
 + /home/aberg/sakai/src_one/sakai_2-6-0/sam/docs/facade_html.zip
 + /home/aberg/sakai/src_one/sakai_2-6-0/webservices/axis/test/basic/axis.jar
 
*****************************************************
  Files with AL headers will be marked L
  Binary files (which do not require AL headers) will be marked B
  Compressed archives will be marked A
  Notices, licenses etc will be marked N
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/.externals
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/.svnignore
 !ECL2  /home/aberg/sakai/src_one/sakai_2-6-0/ECLv2.txt
 !ECL2  /home/aberg/sakai/src_one/sakai_2-6-0/pom.xml
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/access/pom.xml
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/access/access-impl/.classpath
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/access/access-impl/.project
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/access/access-impl/impl/pom.xml
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/access/access-impl/impl/src/bundle/access.metaprops
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/access/access-impl/impl/src/bundle/access.properties
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/access/access-impl/impl/src/bundle/access_ar.properties
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/access/access-impl/impl/src/bundle/access_ca.metaprops
 !????? /home/aberg/sakai/src_one/sakai_2-6-0/access/access-impl/impl/src/bundle/access_ca.properties