[devscripts] 02/04: licensecheck: extract © owner when © and owners are specified on 2 lines.

dod at debian.org dod at debian.org
Sun Jun 21 10:34:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

dod pushed a commit to branch master
in repository devscripts.

commit 7d394fa70060a5b1c12c70e8c12936525a59b715
Author: Dominique Dumont <dod at debian.org>
Date:   Fri Jun 19 08:32:00 2015 +0200

    licensecheck: extract © owner when © and owners are specified on 2 lines.
    
    this is done in the new extract_copyright function. When a copyright line
    ends with year spec, the owner is retrieved from the following line
---
 debian/changelog                |  6 ++++++
 scripts/licensecheck.pl         | 29 +++++++++++++++++++++++------
 test/licensecheck/bsd-regents.c | 30 ++++++++++++++++++++++++++++++
 test/test_licensecheck          |  2 +-
 4 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index ca568aa..4edea9a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+devscripts (2.15.6) UNRELEASED; urgency=low
+
+  * licensecheck: extract © owner when © and owners are specified on 2 lines.
+
+ -- Dominique Dumont <dod at debian.org>  Fri, 19 Jun 2015 07:42:55 +0200
+
 devscripts (2.15.5) unstable; urgency=low
 
   [ Cyril Brulebois ]
diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index eb1cad1..b2e7250 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -318,7 +318,6 @@ while (@files) {
     my $copyright_match;
     my $copyright = '';
     my $license = '';
-    my %copyrights;
 
     # Encode::Guess does not work well, use good old file command to get file encoding
     my $mime = `file -bi $file`;
@@ -337,13 +336,10 @@ while (@files) {
         last if ($. > $OPT{'lines'});
         my $data = decode($charset,$_);
         $content .= $data;
-        $copyright_match = parse_copyright($data);
-        if ($copyright_match) {
-            $copyrights{lc("$copyright_match")} = "$copyright_match";
-        }
     }
     close($F);
 
+    my %copyrights = extract_copyright($content);
     $copyright = join(" / ", reverse sort values %copyrights);
 
     print qq(----- $file header -----\n$content----- end header -----\n\n)
@@ -365,13 +361,34 @@ while (@files) {
     }
 }
 
+sub extract_copyright {
+    my $content = shift;
+    my @c = split /\n/, clean_comments($content);
+
+    my %copyrights;
+
+    while (@c) {
+	my $line = shift @c ;
+	my $copyright_match = parse_copyright($line) ;
+        if ($copyright_match) {
+	    if ($copyright_match =~ /\d[,.]?\s*$/) {
+		# looks like copyright end with a year, assume the owner is on next line
+		$copyright_match .= ' '. shift @c;
+	    }
+	    $copyright_match =~ s/\s+/ /g;
+	    $copyrights{lc("$copyright_match")} = "$copyright_match";
+        }
+    }
+    return %copyrights;
+}
+
 sub parse_copyright {
     my $data = shift ;
     my $copyright = '';
     my $match;
 
     if ( $data !~ $copyright_predisindicator_regex) {
-
+	#print "match against ->$data<-\n";
         if ($data =~ $copyright_indicator_regex_with_capture) {
             $match = $1;
 
diff --git a/test/licensecheck/bsd-regents.c b/test/licensecheck/bsd-regents.c
new file mode 100644
index 0000000..931ea6a
--- /dev/null
+++ b/test/licensecheck/bsd-regents.c
@@ -0,0 +1,30 @@
+/*      $NetBSD: getopt.c,v 1.26 2003/08/07 16:43:40 agc Exp $  */
+
+/*
+ * Copyright (c) 1987, 1993, 1994
+ *      The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
diff --git a/test/test_licensecheck b/test/test_licensecheck
index 1dc26c3..a92d448 100755
--- a/test/test_licensecheck
+++ b/test/test_licensecheck
@@ -55,7 +55,7 @@ testBSD() {
     license "bsd-1-clause-1.c" "BSD"
     license "bsd-3-clause.cpp" "BSD (3 clause)"
     license "bsd-3-clause-authorsany.c" "BSD (3 clause)"
-    license2 "-m --copyright" "bsd-regents.c" "BSD (3 clause)	1987, 1993, 1994  The Regents of the University of California.  All rights reserved."
+    license2 "-m --copyright" "bsd-regents.c" "BSD (3 clause)	1987, 1993, 1994 The Regents of the University of California. All rights reserved."
 }
 
 testLGPL() {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/devscripts.git



More information about the devscripts-devel mailing list