forked from ome/bioformats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-links.pl
executable file
·95 lines (84 loc) · 2.24 KB
/
check-links.pl
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
#!/usr/bin/perl
use strict;
# check-links.pl - Verifies existence and correctness of source code links.
my $cmd = "find components -name '*.java'" .
" | grep -v '/build/'" .
" | grep -v '/forks/'" .
" | grep -v '/bio-formats/doc/'" .
" | grep -v '/ome-xml/src/ome/xml/model/'" .
" | grep -v '/ome-xml/src/ome/xml/r2003fc/'";
my @src = `$cmd`;
my $allOK = 1;
for my $f (@src) {
chop $f;
open FILE, "$f" or die "$f: $!";
my @lines = <FILE>;
close(FILE);
my $tracActual = '';
my $gitwebActual = '';
my $tagIndex = 0;
my $codeIndex = 0;
my $lineNo = 0;
for my $line (@lines) {
chop $line;
$lineNo++;
if ($line =~ />Trac</) {
$tracActual = $line;
$tracActual =~ s/.*(http:.*)".*/$1/;
$codeIndex = $lineNo;
}
elsif ($line =~ />Gitweb</) {
$gitwebActual = $line;
$gitwebActual =~ s/.*(http:.*)".*/$1/;
$codeIndex = $lineNo;
}
elsif ($line =~ /^ \* @/ && $tagIndex == 0) {
$tagIndex = $lineNo;
}
}
# check header
my $headerOK = 1;
my $filename = $f;
$filename =~ s/.*\///;
my $headerExpected = "// $filename";
my $headerActual = $headerExpected;
if ($lines[0] ne '//' || $lines[1] ne $headerExpected || $lines[2] ne '//') {
$headerOK = 0;
}
# check comment annotations
my $commentOK = 1;
if ($tagIndex > 0 && $tagIndex < $codeIndex) {
$commentOK = 0;
}
my $tracExpected = "http://trac.openmicroscopy.org.uk/" .
"ome/browser/bioformats.git/$f";
my $gitwebExpected = "http://git.openmicroscopy.org/" .
"?p=bioformats.git;a=blob;f=$f;hb=HEAD";
if (!$headerOK || !$commentOK || $tracActual ne $tracExpected ||
$gitwebActual ne $gitwebExpected)
{
print "$f:\n";
$allOK = 0;
}
if (!$headerOK) {
print " incorrect header\n";
}
if (!$commentOK) {
print " misplaced comment annotation\n";
}
if ($tracActual eq '') {
print " no Trac link (should be $tracExpected)\n";
}
elsif ($tracActual ne $tracExpected) {
print " wrong Trac link: $tracActual\n";
}
if ($gitwebActual eq '') {
print " no Gitweb link (should be $gitwebExpected)\n";
}
elsif ($gitwebActual ne $gitwebExpected) {
print " wrong Gitweb link: $gitwebActual\n";
}
}
if ($allOK) {
print "All source files OK!\n";
}