View | Details | Raw Unified | Return to bug 24545
Collapse All | Expand All

(-)a/xt/find-license-problems (-68 lines)
Lines 1-68 Link Here
1
#!/usr/bin/perl
2
#
3
# Find copyright and license problems in Koha source files. At this
4
# time it only looks for references to the old FSF address in GPLv2
5
# license notices, but it might in the future be extended to look for
6
# other things, too.
7
#
8
# Copyright 2010 Catalyst IT Ltd
9
#
10
# This file is part of Koha.
11
#
12
# This program is free software; you can redistribute it and/or modify
13
# it under the terms of the GNU General Public License as published by
14
# the Free Software Foundation; either version 2 of the License, or
15
# (at your option) any later version.
16
#
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
# GNU General Public License for more details.
21
#
22
# You should have received a copy of the GNU General Public License along
23
# with this program; if not, write to the Free Software Foundation, Inc.,
24
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26
27
use Modern::Perl;
28
29
use File::Find;
30
31
32
my @files;
33
sub wanted {
34
    my $name = $File::Find::name;
35
    push @files, $name
36
        unless $name =~ /\/(\.git|koha-tmpl)(\/.*)?$/ ||
37
               $name =~ /\.(gif|jpg|odt|ogg|pdf|png|po|psd|svg|swf|zip)$/ ||
38
               ! -f $name;
39
}
40
41
42
sub has_gpl2plus_and_current_fsf_address {
43
    my ($name) = @_;
44
    my $hascopyright;
45
    my $hasgpl;
46
    my $hasv2;
47
    my $hasorlater;
48
    my $hasfranklinst;
49
    open(FILE, $name) || return 0;
50
    while (my $line = <FILE>) {
51
        $hascopyright = 1 if ($line =~ /Copyright.*\d\d/);
52
        $hasgpl = 1 if ($line =~ /GNU General Public License/);
53
        $hasv2 = 1 if ($line =~ /either version 2/);
54
        $hasorlater = 1 if ($line =~ /any later version/ ||
55
                            $line =~ /at your option/);
56
        $hasfranklinst = 1 if ($line =~ /51 Franklin Street/);
57
    }
58
    return ! $hascopyright ||
59
           ($hasgpl && $hasv2 && $hasorlater && $hasfranklinst);
60
}
61
62
63
find({ wanted => \&wanted, no_chdir => 1 }, @ARGV);
64
foreach my $name (@files) {
65
    if (! has_gpl2plus_and_current_fsf_address($name)) {
66
        print "$name\n";
67
    }
68
}
(-)a/xt/find-license-problems.t (-1 / +67 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# Find copyright and license problems in Koha source files. At this
4
# time it only looks for references to the old FSF address in GPLv2
5
# license notices, but it might in the future be extended to look for
6
# other things, too.
7
#
8
# Copyright 2010 Catalyst IT Ltd
9
# Copyright 2020 Koha Development Team
10
#
11
# This file is part of Koha.
12
#
13
# Koha is free software; you can redistribute it and/or modify it
14
# under the terms of the GNU General Public License as published by
15
# the Free Software Foundation; either version 3 of the License, or
16
# (at your option) any later version.
17
#
18
# Koha is distributed in the hope that it will be useful, but
19
# WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
22
#
23
# You should have received a copy of the GNU General Public License
24
# along with Koha; if not, see <http://www.gnu.org/licenses>.
25
26
use Modern::Perl;
27
use Test::More;
28
29
use File::Spec;
30
use File::Find;
31
32
my @files;
33
sub wanted {
34
    my $name = $File::Find::name;
35
    push @files, $name
36
        unless $name =~ /\/(\.git|koha-tmpl|node_modules|swagger-ui)(\/.*)?$/ ||
37
               $name =~ /\.(gif|jpg|odt|ogg|pdf|png|po|psd|svg|swf|zip|patch)$/ ||
38
               $name =~ m[(xt/find-license-problems|xt/fix-old-fsf-address)] ||
39
               ! -f $name;
40
}
41
42
find({ wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir());
43
44
foreach my $name (@files) {
45
    open( FILE, $name ) || return 0;
46
    my ( $hascopyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense,
47
        $hasfranklinst, $is_not_us ) = (0)x7;
48
    while ( my $line = <FILE> ) {
49
        $hascopyright = 1 if ( $line =~ /^(#|--)?\s*Copyright.*\d\d/ );
50
        $hasgpl       = 1 if ( $line =~ /GNU General Public License/ );
51
        $hasv3        = 1 if ( $line =~ /either version 3/ );
52
        $hasorlater   = 1
53
          if ( $line =~ /any later version/
54
            || $line =~ /at your option/ );
55
        $haslinktolicense = 1 if $line =~ m|http://www\.gnu\.org/licenses|;
56
        $hasfranklinst    = 1 if ( $line =~ /51 Franklin Street/ );
57
        $is_not_us        = 1 if $line =~ m|This file is part of the Zebra server|;
58
    }
59
    next unless $hascopyright;
60
    next if $is_not_us;
61
    is(    $hasgpl
62
        && $hasv3
63
        && $hasorlater
64
        && $haslinktolicense
65
        && !$hasfranklinst,  1 ) or diag(sprintf "File %s has wrong copyright: hasgpl=%s, hasv3=%s, hasorlater=%s, haslinktolicense=%s, hasfranklinst=%s", $name, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst);
66
}
67
done_testing;

Return to bug 24545