rev 11958 - in people/modax/copyright-helper/trunk: . licenses parsers
Modestas Vainius
modax-guest at alioth.debian.org
Wed Aug 20 23:43:12 UTC 2008
Author: modax-guest
Date: 2008-08-20 23:43:12 +0000 (Wed, 20 Aug 2008)
New Revision: 11958
Modified:
people/modax/copyright-helper/trunk/CHCopyright.pm
people/modax/copyright-helper/trunk/CHCore.pm
people/modax/copyright-helper/trunk/copyright-helper.pl
people/modax/copyright-helper/trunk/licenses/gnugpl.pm
people/modax/copyright-helper/trunk/licenses/gnulgpl.pm
people/modax/copyright-helper/trunk/parsers/c_cpp.pm
people/modax/copyright-helper/trunk/parsers/numsign.pm
Log:
More enhancements and fixes
Modified: people/modax/copyright-helper/trunk/CHCopyright.pm
===================================================================
--- people/modax/copyright-helper/trunk/CHCopyright.pm 2008-08-20 21:12:56 UTC (rev 11957)
+++ people/modax/copyright-helper/trunk/CHCopyright.pm 2008-08-20 23:43:12 UTC (rev 11958)
@@ -214,7 +214,6 @@
sub CHCopyright::Author::getYears($) {
return shift->{years};
-
}
sub CHCopyright::Author::closeYears($) {
@@ -624,6 +623,28 @@
}
}
+# Merge duplicate authors (same full name)
+sub CHCopyright::AuthorCollection::merge_duplicates {
+ my $self = shift;
+
+ my @sortedauthors =
+ sort { $a->getFullName() cmp $b->getFullName() } @{$self->getAuthors()};
+ my @authors;
+ my $prev;
+ foreach my $author (@sortedauthors) {
+ if (defined($prev) &&
+ $author->getFullName() eq $prev->getFullName() &&
+ $author->getEmail() eq $prev->getEmail() ) {
+
+ $prev->addYear($author->getAllYears());
+ } else {
+ push @authors, $author;
+ }
+ $prev = $author;
+ }
+ $self->{authors} = \@authors if (scalar(@authors) < $self->getAuthorCount());
+}
+
sub CHCopyright::AuthorCollection::complete($) {
my $self = shift;
my $authors = $self->getAuthors();
@@ -677,8 +698,11 @@
# $$authors[0]->setEmail("");
# }
}
+
+ $self->merge_duplicates();
}
+
sub __process_copyright_statement(\@$$$) {
my ($results, $p, $uniqOnly, $strict) = @_;
Modified: people/modax/copyright-helper/trunk/CHCore.pm
===================================================================
--- people/modax/copyright-helper/trunk/CHCore.pm 2008-08-20 21:12:56 UTC (rev 11957)
+++ people/modax/copyright-helper/trunk/CHCore.pm 2008-08-20 23:43:12 UTC (rev 11958)
@@ -33,8 +33,8 @@
my $self = {
"name" => $filename,
"directory" => $directory,
- "license" => 0,
"copyrights" => [],
+ "license" => undef,
"depth" => 0,
};
$self->{depth} = ($directory->getDepth() + 1) if ($directory);
@@ -142,6 +142,7 @@
# Save our discoveries if there are any
$self->{copyrights} = \@copyrights if (@copyrights);
$self->{license} = $license if ($license);
+ $self->{scanned} = 1;
return 1;
}
@@ -151,6 +152,10 @@
return (@{$self->{copyrights}} || $self->{license});
}
+sub CHCore::File::isScanned($) {
+ return exists shift()->{scanned};
+}
+
sub CHCore::File::toStringDepth($) {
return " " x (shift()->getDepth() * 4);
}
@@ -393,6 +398,7 @@
# Save our discoveries if there are any
$self->{copyrights} = \@copyrights if (@copyrights);
$self->{license} = $license if ($license);
+ $self->{scanned} = 1;
return 1;
}
@@ -431,8 +437,9 @@
sub CHCore::Directory::printAll($) {
my $self = shift;
- CHCore::File::printAll($self);
+ CHCore::File::printAll($self) unless($self->isInherited("license"));
+
for my $f (@{$self->getFiles()}) {
$f->printAll();
}
@@ -854,23 +861,25 @@
my $licenses = $self->{licenses};
if (my $lic = $f->getLicense()) {
- if ($f->isInherited("license")) {
- push @{$self->{implicit}}, $f;
- } else {
- push @{$self->{explicit}}, $f;
+ unless($f->isDirectory() && $f->isInherited("license")) {
+ if ($f->isInherited("license")) {
+ push @{$self->{implicit}}, $f;
+ } else {
+ push @{$self->{explicit}}, $f;
+ }
+ my $id = $lic->getID();
+ my $val;
+ my $count = 0;
+ if (exists($licenses->{$id})) {
+ $val = $licenses->{$id};
+ } else {
+ $val = [ $lic, [] ];
+ $licenses->{$id} = $val;
+ $count = 1;
+ }
+ push @{$val->[1]}, $f;
+ return $count;
}
- my $id = $lic->getID();
- my $val;
- my $count = 0;
- if (exists($licenses->{$id})) {
- $val = $licenses->{$id};
- } else {
- $val = [ $lic, [] ];
- $licenses->{$id} = $val;
- $count = 1;
- }
- push @{$val->[1]}, $f;
- return $count;
}
return 0;
@@ -890,43 +899,61 @@
sub CHCore::LicenseSummary::__toStringLicense($$) {
my ($self, $lic, $files, $i_lvl1, $i_lvl2) = @_;
my $str = $i_lvl1 . "* " . $lic->getFullLicenseString() . "\n";
+ $str .= $i_lvl2;
+ my $fstr = "";
if (@$files) {
- $str .= $i_lvl2 . sprintf("The files (%d) below are licensed under this license:\n", scalar(@$files));
+ my $inherited_count = 0;
for my $f (@$files) {
- $str .= $i_lvl2 . "- " . $f->getPathWithoutRoot() . "\n";
+ $fstr .= $i_lvl2;
+ if ($f->isInherited("license")) {
+ $fstr .= "? ";
+ $inherited_count++;
+ } else {
+ $fstr .= "- ";
+ }
+ $fstr .= $f->getPathWithoutRoot() . "\n";
}
+ if ($inherited_count == scalar(@$files)) {
+ $str .= sprintf("However, the license for the following file(s) (%d) was not explicitly specified:\n",
+ scalar(@$files));
+ } else {
+ $str .= sprintf("%d file(s) listed below are licensed under this license:\n", scalar(@$files));
+ }
}
- return $str;
+ return $str . $fstr;
}
sub CHCore::LicenseSummary::toString {
my ($self, $indent_lvl1, $indent_lvl2, $indent_lvl3) = @_;
my ($i_lvl1, $i_lvl2, $i_lvl3) =
__handle_indent_args($indent_lvl1, $indent_lvl2, $indent_lvl3);
- my $maxlic = 0;
- my $maxfiles = 0;
+ my $maxlic;
+ my $maxfiles = [];
my $str = "";
if ($self->getLicenseCount() == 1) {
my @values = values(%{$self->{licenses}});
my $lic_array = $values[0];
- my $maxlic = $lic_array->[0];
+ $maxlic = $lic_array->[0];
+ $maxfiles = $lic_array->[1];
+ my @files = grep { $->isScanned() && $_->isInherited("license") } @$maxfiles;
$str .= $i_lvl1 . "License for all components is:\n";
- $str .= $self->__toStringLicense($maxlic, [], $i_lvl2, $i_lvl3);
+ $str .= $self->__toStringLicense($maxlic, \@files, $i_lvl2, $i_lvl3);
return $str;
} else {
for my $lic_array (values(%{$self->{licenses}})) {
my $lic = $lic_array->[0];
my $files = $lic_array->[1];
- if (scalar(@$files) > $maxfiles) {
- $maxfiles = scalar(@$files);
+ if (scalar(@$files) > scalar(@$maxfiles)) {
+ $maxfiles = $files;
$maxlic = $lic;
}
}
$str .= $i_lvl1 . "License for all components unless stated otherwise:\n";
- $str .= $self->__toStringLicense($maxlic, [], $i_lvl2, $i_lvl3);
+ my @files = grep { $_->isScanned() && $_->isInherited("license") } @$maxfiles;
+ $str .= $self->__toStringLicense($maxlic, \@files, $i_lvl2, $i_lvl3);
$str .= "\n";
$str .= $i_lvl1 . "Other used licenses:\n";
Modified: people/modax/copyright-helper/trunk/copyright-helper.pl
===================================================================
--- people/modax/copyright-helper/trunk/copyright-helper.pl 2008-08-20 21:12:56 UTC (rev 11957)
+++ people/modax/copyright-helper/trunk/copyright-helper.pl 2008-08-20 23:43:12 UTC (rev 11958)
@@ -221,7 +221,7 @@
}
# Entry point
-${main::VERSION}='0.4.6';
+${main::VERSION}='0.4.7';
print_msg "\n";
print_msg "Copyright Helper v${main::VERSION}\n";
print_msg "Extracts copyright and license information from source code\n\n";
Modified: people/modax/copyright-helper/trunk/licenses/gnugpl.pm
===================================================================
--- people/modax/copyright-helper/trunk/licenses/gnugpl.pm 2008-08-20 21:12:56 UTC (rev 11957)
+++ people/modax/copyright-helper/trunk/licenses/gnugpl.pm 2008-08-20 23:43:12 UTC (rev 11958)
@@ -20,21 +20,25 @@
sub matchCopyrightedFile($\@) {
my ($self, $text) = @_;
+ my $i = 0;
for my $p (@$text) {
# Preamle is usually like:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
- if ($p =~ m/redistribute.*modify.*GNU General Public License as published(.*)/so) {
+ if ($p =~ m/(?:distribute.*modif.*|used.*)GNU\s+General\s+Public\s+License\s+(.*)/so) {
+
my $version = $1;
my $license = new CHLicenses::gnugpl;
# Check for version and later clause (optional)
- if ($version =~ m/version (.+) of the License(.*)/soi) {
+ if ($version =~ m/version\s+([\d.]+)\W+(.*)/soi) {
$license->{"version"} = $1;
$version = $2;
- $license->{"later"} = 1 if ($version =~ m/any\slater\sversion/);
+ # Strip .0 from the end of the version
+ $license->{"version"} =~ s/\.0+$//;
+ $license->{"later"} = 1 if ($version =~ m/any\s+later\s+version/);
}
$license->{"foundInText"} = $p;
return $license;
Modified: people/modax/copyright-helper/trunk/licenses/gnulgpl.pm
===================================================================
--- people/modax/copyright-helper/trunk/licenses/gnulgpl.pm 2008-08-20 21:12:56 UTC (rev 11957)
+++ people/modax/copyright-helper/trunk/licenses/gnulgpl.pm 2008-08-20 23:43:12 UTC (rev 11958)
@@ -25,15 +25,16 @@
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 2.1 or 3 of the License.
- if ($p =~ m/redistribute.*modify.*GNU\sLesser\sGeneral\sPublic\sLicense\sas\spublished(.*)/so ||
- $p =~ m/redistribute.*modify.*GNU\sLibrary\sGeneral\sPublic\sLicense(.*)/so) {
+ if ($p =~ m/distribute.*modif.*GNU\s+(?:(?:Lesser|Library)\W+)+General\s+Public\s+License(.*)/so) {
my $version = $1;
my $license = new CHLicenses::gnulgpl;
# Check for version and later clause (optional)
- if ($version =~ m/version (.+) (?:of the License|as published)(.*)/soi) {
+ if ($version =~ m/version\s+([\d.]+)\W+(.*)/soi) {
$license->{"version"} = $1;
$version = $2;
- $license->{"later"} = 1 if ($version =~ m/any\slater\sversion/);
+ # Strip .0 from the end of the version
+ $license->{"version"} =~ s/\.0+$//;
+ $license->{"later"} = 1 if ($version =~ m/any\s+later\s+version/);
}
$license->{"foundInText"} = $p;
return $license;
@@ -100,6 +101,6 @@
}
sub getLongName($) {
- "GNU Lesser General Public License";
+ "GNU Library/Lesser General Public License";
}
Modified: people/modax/copyright-helper/trunk/parsers/c_cpp.pm
===================================================================
--- people/modax/copyright-helper/trunk/parsers/c_cpp.pm 2008-08-20 21:12:56 UTC (rev 11957)
+++ people/modax/copyright-helper/trunk/parsers/c_cpp.pm 2008-08-20 23:43:12 UTC (rev 11958)
@@ -115,6 +115,6 @@
return @parags;
}
-sub extensions {
- return qw( c cpp h cc );
+sub extensions {
+ return qw( c cpp cxx h cc java js );
}
Modified: people/modax/copyright-helper/trunk/parsers/numsign.pm
===================================================================
--- people/modax/copyright-helper/trunk/parsers/numsign.pm 2008-08-20 21:12:56 UTC (rev 11957)
+++ people/modax/copyright-helper/trunk/parsers/numsign.pm 2008-08-20 23:43:12 UTC (rev 11958)
@@ -32,7 +32,7 @@
my @comment = ();
while (<$fh>) {
# Beginning of the comment
- if (m/#\s*(.*)$/) {
+ if (m/\s*#(?!!\/)\s*(.*)$/) {
if ($1) {
push @comment, $1;
} else {
@@ -50,11 +50,26 @@
my $self = shift;
my @text = @{shift()};
my @parags = ();
-
foreach $_ (@text) {
my @lines = split(/\n/);
- map s/\s+/ /g, @lines;
- push @parags, @lines;
+ my @parag;
+ my $i = 0;
+ foreach my $l (@lines) {
+ $l =~ s/\s+/ /g;
+ $l =~ s/^\s*#+//;
+ $l =~ s/#+\s*$//;
+ if ($#lines == $i) {
+ push @parag, $l if ($l !~ /^\s*$/);
+ $l = "";
+ }
+ if ($l =~ /^\s*$/) {
+ push @parags, join("\n", @parag) if (@parag);
+ @parag = ();
+ } else {
+ push @parag, $l;
+ }
+ $i++;
+ }
}
return @parags;
}
@@ -65,5 +80,5 @@
}
sub extensions {
- return qw( pl py cmake );
+ return qw( pl py cmake rb );
}
More information about the pkg-kde-commits
mailing list