1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
#!/usr/bin/perl
use strict;
use warnings;
my $assumed = "EPL-1.0";
my $dcp = 'IBM\s+Corporation\s*,?\s*and\s+others?';
my $curFile = '';
my $lic = {$assumed => {'IBM and others.' => ["2000-2009"]},
"Apache (v2.0)" => {"Apache Software Foundation" => [[], ["eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/bin/antrun.p[ly]",
"eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/bin/antRun.pl",
"eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/bin/complete-ant-cmd.pl"]]} };
my $lf = {'eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/bin' => [4, "Apache (v2.0)"] };
my $slash = '/';
my $at = '@';
open(CP, "licensecheck -r --copyright * | ") or choke("Cannot run licensecheck: $!");
while(my $line = <CP>){
chomp($line);
next if($line eq '');
$line =~ s/UNKNOWN/$assumed/og;
if($line !~ m/\*No copyright\*/){
my $cpline = <CP>;
my ($file, $license) = split(/:\s*+/o, $line);
my @cps = ();
$license =~ s/\s+$//o;
next if($license =~ m/GENERATED FILE/o);
next if($file =~ m@^debian/@o or $file =~ m@eclipse/plugins/org.eclipse.jdt.apt.core/src/com/sun/mirror/@o);
if($file =~m@eclipse/plugins/org.eclipse.swt/Eclipse SWT Mozilla/common/library/@){
#print "W: Handle $file manually\n";
next;
}
chomp($cpline);
$cpline =~ s/[^:]++:\s*+//o;
$cpline =~ s@^[^/]*holder[^/]*/@@o;
$cpline =~ s/All rights?\s*reser.*$//io;
$cpline =~ s/(\s*\.)?(\s*.?)?$//o;
$cpline =~ s@\{\s*/\s*has\s*/\s*@@o;
# Seriously - this should not be necessary!
if($cpline =~ m@\d{2}[^/]+/\s*\d{2}@) {
my @holders = split(/\s*\/\s*/o, $cpline);
my $rcp = '';
foreach my $holder (@holders){
my ($hcp, $hyears) = handleCP($holder);
if($hyears eq '?'){
print STDERR "W: Handle $file manually - cannot determine year - $holder ($hcp).\n";
@cps = ();
last;
}
if($hcp =~m/^\s*$/o){
print STDERR "W: Handle $file manually - cannot determine copyright holder.\n";
last;
}
push(@cps, [$hcp, $hyears]);
}
} else {
my $y;
($cpline, $y) = handleCP($cpline);
push(@cps, [$cpline, $y]);
if($y eq '?'){
print STDERR "W: Handle $file manually - cannot determine year - $cpline.\n";
next;
}
if($cpline =~m/^\s*$/o){
print STDERR "W: Handle $file manually - cannot determine copyright holder.\n";
next;
}
}
foreach my $val (@cps){
my $cp = $val->[0];
my $years = $val->[1];
my $folder = $file;
my $fl;
$folder =~ s@/[^/]+$@@o;
$fl = $lf->{$folder};
if(!defined($fl)){
$fl = [1, $license];
$lf->{$folder} = $fl;
} else {
if($fl->[1] eq $license && $fl->[0] != -1){
$fl->[0] = $fl->[0] + 1;
} else {
$fl->[0] = -1;
}
}
next if($license eq $assumed and ($cp =~ m/$dcp/o or $cp =~ m/IBM\s*,?\s*and\s+other/ ));
if($license eq $assumed){
my $hmap = $lic->{$license};
my $ylist;
if(!defined($hmap)){
$hmap = {};
$lic->{$license} = $hmap;
$ylist = [];
$hmap->{$cp} = $ylist;
} else {
$ylist = $hmap->{$cp};
if(!defined($ylist)){
$ylist = [];
$hmap->{$cp} = $ylist;
}
}
push(@$ylist, $years);
next;
}
my $hmap = $lic->{$license};
my $hdata = undef;
my $ylist;
my $flist;
if(!defined($hmap)){
$hmap = {};
$lic->{$license} = $hmap;
}
$hdata = $hmap->{$cp};
if(!defined($hdata)){
$hdata = [[], []];
$hmap->{$cp} = $hdata;
}
$ylist = $hdata->[0];
$flist = $hdata->[1];
push(@$ylist, $years);
push(@$flist, $file);
}
}
}
my $eplcp = mergeHolders($lic->{$assumed});
delete($lic->{$assumed});
print "Files: *\nCopyright: " . join("\n ", @$eplcp) . "\nLicense: $assumed\n\n";
while ( my ($license, $holderMap) = each(%$lic)){
my $files = [];
my $cr = [];
my $li = $license;
if($license =~ m/(\S+)\s*\([vV]([^\)]+)\)/o){
$li = "$1-$2";
}
while( my ($holder, $hdata) = each(%$holderMap) ){
my ($ylist, $flist) = @$hdata;
my $crdata = parseYears($ylist) . ", $holder";
push(@$cr, $crdata);
generateFileList($files, $flist);
}
print "Files: ". join(",\n ", unique(sort(@$files))) . "\n";
print "Copyright: " . join("\n ", @$cr) . "\nLicense: $li\n\n";
}
# hardcoded files.
print <<EOF
Files: eclipse/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerSortUtil.java
Copyright: 1994, Hewlett-Packard Company
1997, Silicon Graphics Computer Systems, Inc
License: other
Permission to use, copy, modify, distribute and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear
in supporting documentation. Hewlett-Packard Company makes no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied warranty.
.
Permission to use, copy, modify, distribute and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear
in supporting documentation. Silicon Graphics makes no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied warranty.
Files: eclipse/plugins/org.eclipse.jdt.apt.core/src/com/sun/mirror/*
Copyright: 2004, Sun Microsystems, Inc
License: other
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
.
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and${slash}or other materials provided with the distribution.
* Neither the name of the Sun Microsystems, Inc. nor the names of
its contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Files: debian/*
Copyright: 2010, Debian Orbital Alignment Team <pkg-java-maintainers${at}lists.alioth.debian.org>
License: EPL-1.0
EOF
;
close(CP);
exit(0);
sub choke{
my $msg = shift;
print STDERR "$msg\n";
exit(1);
}
sub generateFileList {
my $allFiles = shift;
my $toAdd = shift;
foreach my $file (@$toAdd){
my $dir = $file;
my $dirdata;
$dir =~ s@/[^/]++$@@o;
$dirdata = $lf->{$dir};
if($dirdata->[0] == 0){
next;
}
if($dirdata->[0] > 0){
# Use wildcard.
$file = "$dir/*";
$dirdata->[0] = 0;
}
if($file =~ m/[ \t]/o){
$file = "\"$file\"";
}
push(@$allFiles, $file);
}
return 1;
}
sub handleCP{
my $cp = shift;
my $years = $cp;
if($cp =~ m/^\s*+(\d+(?:\s*+[,-]\s*+\d+)*)/o){
$years = $1;
$cp =~ s/^\s*+\d+(?:\s*+[,-]\s*+\d+)*\s*+//;
} else {
if($cp =~ m/\((\d+(?:\s*+[,-]\s*+\d+)*)\)/o){
$years = $1;
$cp =~ s/\((\d+(?:\s*+[,-]\s*+\d+)*)\)//o;
} else {
$years = '?';
}
}
$cp =~ s/^s?\s+//o;
$cp =~ s/\bCorp\.?\b/Corporation/oi;
$cp =~ s@/\s*\|\|.+$@@o;
$cp =~ s/^\s*+(,|by|the)\s*+//oi;
$cp =~ s/\s*+$//o;
return ($cp, $years);
}
sub parseYears{
my $years = shift;
my $min = -1;
my $max = -1;
foreach my $line (@$years){
foreach my $e (split(/\s*,\s*/o, $line)){
if($e =~ m/(\d+)[ \t]*-[ \t]*(\d+)/o){
my $m1 = $1;
my $m2 = $2;
if($m2 < $1){
my $tmp = $m2;
$m2 = $m1;
$m1 = $tmp;
}
$min = $m1 if($min > $m1 or $min == -1);
$max = $m2 if($m2 > $max or $max == -1);
} else {
$min = $e if($min > $e or $min == -1);
$max = $e if($e > $max or $max == -1);
}
}
}
if($min == -1 or $max == -1){
choke("Cannot determine years " . join(" - ", @$years));
}
if($min == $max){
return $min;
}
return "$min-$max";
}
sub mergeHolders{
my $hmap = shift;
my $ret = [];
foreach my $holder (sort(keys(%$hmap))) {
my $ylist = $hmap->{$holder};
my $y = parseYears($ylist);
push(@$ret, "$y, $holder");
}
return $ret;
}
sub unique {
my @unique = ();
my %seen = ();
foreach my $elem ( @_ ) {
next if $seen{ $elem }++;
push @unique, $elem;
}
return @unique;
}
|