Sander Striker wrote:
Please find instructions on how to apply the new license at
http://www.apache.org/dev/apply-license.html
I've been using the attached relicense.pl rather than the python script in
the committers directory, because it preserves the copyright years. It does
even more, adding the year 2004 automatically.
Questions:
- Does anyone already have a forrested version of LICENSE.txt?
- Does anyone already have a Docbook version of LICENSE.txt?
Regards,
Jochen
#!/usr/bin/perl -w
#
# This file takes as input a directory of source files.
# It scans the directory for files matching the regular
# expression $searchRe. In fact this means, that the
# file must contain a line beginning with
#
#" * The Apache Software License, Version 1.1"
#
# followed by another line ending with
#
#"SUCH DAMAGE."
#
# If such a pattern is detected and it contains a copyright year
# (like 2003, or 2002-2003, or 2001, 2003), then the pattern is
# replaces with the string $NEW_LICENSE, indented by " * ".
# In other words, it handles C or Java style comments.
#
# The script updates the copyright year in the following sense:
# - If the year 2004 is already included, the year is copied
#verbatimly.
# - If the year 2004 is not yet included, but ends with
#",2003", then the string "-2004" is included.
# - Otherwise the year is copied and the string ",2004" is
#appended.
#
use strict;
my $NEW_LICENSE = <<'LICENSE';
Copyright 2003 The Apache Software Foundation
Licensed 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.
LICENSE
require File::Find;
my $searchRe =
'(\s+\*\s+)The\s+Apache\s+Software\s+License,\s+Version\s+1.1\s+(.*?)SUCH
DAMAGE.\s*?';
my $dir = $ARGV[0] || die "Usage: $0 \n";
File::Find::find({wanted => \&update,
no_chdir => 1
}, $dir);
sub update() {
my $file;
{
no warnings "all"; # Avoid 'used only once' warning
$file = $File::Find::name;
}
return unless -f $file;
local $/;
open(my $fh, $file) || die "Failed to open $file: $!";
my $contents = <$fh>;
die "Failed to read $file: $!" unless defined($contents);
close($fh) || die "Failed to close $file: $!";
$contents = updateContents($file, $contents);
if (defined($contents)) {
my $new = "$file.new";
my $bak = "$file.bak";
open(my $fh, ">$new") || die "Failed to create $new: $!";
(print $fh $contents) || die "Failed to write $new: $!";
close($fh) || die "Failed to close $new: $!";
(rename $file, $bak) || die "Failed to rename $file to $bak: $!";
(rename $new, $file) || die "Failed to rename $new to $file: $!";
}
}
sub updateContents($$) {
my($file, $contents) = @_;
if ($contents =~ /^$searchRe$/sm) {
my $inner = $&;
my $intro = $1;
# Identify the years of the copyright
my $reYear = qr/\d\d\d\d/;
my $reRange = qr/$reYear(?:\-$reYear)?/;
my $reRanges = qr/$reRange(?:\s*\,\s*$reRange)*/;
if ($inner =~ /$reRanges/) {
my $years = $&;
my $newYears;
if ($years =~ /2004$/) {
$newYears = $years;
} else {
if ($years =~ /\,\s*2003$/) {
$newYears .= $years . "-2004";
} else {
$newYears = $years . ", 2004";
}
}
my $replacement = $NEW_LICENSE;
$replacement =~ s/2003/$newYears/;
$replacement =~ s/^/$intro/mg;
print "Match: $file\n";
my $result = $contents;
$result =~ s/^$searchRe$/$replacement/sm;
return $result;
} else {
print STDERR "Failed to parse years of copyright in $file.\n";
}
}
return undef;
}
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]