Index
Introduction
Usage
Introduction
Makeopensource is a simple Ant task that copies an existing project
directory to a target directory and performs the following translations:
- For nominated file types perform the following:
- Prefix each file of a set of named file types with a licence
header (such as the Apache 2.0 licence header)
- Translate each line that matches a regular expression to an
output line. This is typically used to modify an existing
copyright line to new copyright line
- else (eg for all other filetypes)
- Binary copy the file from source to destination directory
Usage
Prerequisites:
Makeopensource is an Ant
task. It will require both Ant and the Java JDK 1.5 (or above).
Usage:
- Edit the run/build.xml file and modify the source directory, file
extension, and licence file location
- Type "ant" in the run directory
- Lines that contain the word 'copyright' but that don't match the
translation regular expression are printed out as
'informational'. This can be used to either modify the regular
expression, or - if it's easier - to modify the copyright line to match
the existing regexp.
makeopensource was initially used to translate existing Cotsec copyright notices in order to
open-source the codebase.
Build.xml overview
Build.xml is a Jakarta Ant artifact that specifies the translation
steps as follows:
<project name="Test Makeopen" default="makeopen">
<!-- Note: You may well have to alter this
classpath! -->
<taskdef
name="makeopen"
classname="com.cotsec.projects.makeopensource.AntTask"
classpath="../target/classes"/>
<target name="makeopen"
description="Add appropriate open source licences to your code,
translate existing copyright notices">
<makeopen
newlicencetextfile="licencefile.txt"
fileextensions="java"
sourcedir="C:/cs/csworkspace/com.cotsec.commons"
ignorefile="ignore_patterns.txt"
replaceregexp="copyright.*?([0-9- ]+)\s(.*?)\s+all
rights reserved"
replacewith="
* Donated to the Open Source community by {2} in 2006 (copyright transferred)"
destdir="output"
>
</makeopen>
</target>
</project>
- newlicencetextfile - location of the new header file to be
prefixed to each translated file, for example the header at the bottom
of the Apache 2.0 license file here: http://www.apache.org/licenses/LICENSE-2.0.html
- fileextensions - a comma separated list of file extensions to
look for copyright notices and translate
- sourcedir - Where the source code / project lies
- ignorefile - a list of filename regular expressions to ignore -
eg "CVS" or ".*~"
- replaceregexp - A regexp to scan for copyright patterns
- replacewith - A string to output instead of the original
copyright pattern
- {1} is the first bracketted sub-pattern; {2} is the second
pattern, etc. In the example above the two bolded items will copy
the donaters name from the original line to the output line as part of
the translation.
- destdir - Output directory of the project copy / update
Download
Download makeopensource here
Example
An example input file is:
package
com.cotsec.projects.makeopensource;
/**
* Example code to be open-sourced
*
* Leave the author line and remove the copyright line. Add
a standard and short header to the top
* of the file
*
* @author David Ford
* @copyright (C) Copyright 2002
David Ford all rights reserved
*/
public class AntTask extends TaskBase {
public static void main(String[] args) {
System.out.println("Example code
to be open-sourced...");
}
}
And output:
/**
* I am an example licence text
file that will be inserted at the top
* of the file.
*/
package com.cotsec.projects.makeopensource;
/**
* Example code to be open-sourced
*
* Leave the author line and remove the copyright line. Add
a standard and short header to the top
* of the file
*
* @author David Ford
* Donated to the Open Source
community by David Ford in 2006 (copyright transferred)
*/
public class AntTask extends TaskBase {
public static void main(String[] args) {
System.out.println("Example code
to be open-sourced...");
}
}
Bold indicates the modified
lines by the translation process.