1 | #!/usr/bin/perl |
---|
2 | use strict; |
---|
3 | |
---|
4 | # check-links.pl - Verifies existence and correctness of source code links. |
---|
5 | |
---|
6 | my $cmd = "find legacy projects -name '*.java'"; |
---|
7 | my @src = `$cmd`; |
---|
8 | my $allOK = 1; |
---|
9 | |
---|
10 | for my $f (@src) { |
---|
11 | chop $f; |
---|
12 | |
---|
13 | open FILE, "$f" or die "$f: $!"; |
---|
14 | my @lines = <FILE>; |
---|
15 | close(FILE); |
---|
16 | |
---|
17 | my $tracActual = ''; |
---|
18 | my $svnActual = ''; |
---|
19 | my $tagIndex = 0; |
---|
20 | my $codeIndex = 0; |
---|
21 | my $lineNo = 0; |
---|
22 | for my $line (@lines) { |
---|
23 | chop $line; |
---|
24 | $lineNo++; |
---|
25 | if ($line =~ />Trac</) { |
---|
26 | $tracActual = $line; |
---|
27 | $tracActual =~ s/.*(http:.*)".*/$1/; |
---|
28 | $codeIndex = $lineNo; |
---|
29 | } |
---|
30 | elsif ($line =~ />SVN</) { |
---|
31 | $svnActual = $line; |
---|
32 | $svnActual =~ s/.*(http:.*)".*/$1/; |
---|
33 | $codeIndex = $lineNo; |
---|
34 | } |
---|
35 | elsif ($line =~ /^ \* @/ && $tagIndex == 0) { |
---|
36 | $tagIndex = $lineNo; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | # check header |
---|
41 | my $headerOK = 1; |
---|
42 | my $filename = $f; |
---|
43 | $filename =~ s/.*\///; |
---|
44 | my $headerExpected = "// $filename"; |
---|
45 | my $headerActual = $headerExpected; |
---|
46 | if ($lines[0] ne '//' || $lines[1] ne $headerExpected || $lines[2] ne '//') { |
---|
47 | $headerOK = 0; |
---|
48 | } |
---|
49 | |
---|
50 | # check comment annotations |
---|
51 | my $commentOK = 1; |
---|
52 | if ($tagIndex > 0 && $tagIndex < $codeIndex) { |
---|
53 | $commentOK = 0; |
---|
54 | } |
---|
55 | |
---|
56 | my $tracExpected = "http://dev.loci.wisc.edu/trac/software/browser/trunk/$f"; |
---|
57 | my $svnExpected = "http://dev.loci.wisc.edu/svn/software/trunk/$f"; |
---|
58 | |
---|
59 | if (!$headerOK || !$commentOK || $tracActual ne $tracExpected || |
---|
60 | $svnActual ne $svnExpected) |
---|
61 | { |
---|
62 | print "$f:\n"; |
---|
63 | $allOK = 0; |
---|
64 | } |
---|
65 | |
---|
66 | if (!$headerOK) { |
---|
67 | print " incorrect header\n"; |
---|
68 | } |
---|
69 | if (!$commentOK) { |
---|
70 | print " misplaced comment annotation\n"; |
---|
71 | } |
---|
72 | if ($tracActual eq '') { |
---|
73 | print " no Trac link (should be $tracExpected)\n"; |
---|
74 | } |
---|
75 | elsif ($tracActual ne $tracExpected) { |
---|
76 | print " wrong Trac link: $tracActual\n"; |
---|
77 | #my $tracSed = $tracExpected; |
---|
78 | #$tracSed =~ s/\//\\\//g; |
---|
79 | #`sed -i '' -e "s/http.*>Trac<\\\/a>/$tracSed\\\">Trac<\\\/a>/" $f`; |
---|
80 | #print " fixed wrong Trac link\n"; |
---|
81 | } |
---|
82 | if ($svnActual eq '') { |
---|
83 | print " no SVN link (should be $svnExpected)\n"; |
---|
84 | } |
---|
85 | elsif ($svnActual ne $svnExpected) { |
---|
86 | print " wrong SVN link: $svnActual\n"; |
---|
87 | #my $svnSed = $svnExpected; |
---|
88 | #$svnSed =~ s/\//\\\//g; |
---|
89 | #`sed -i '' -e "s/http.*>SVN<\\\/a>/$svnSed\\\">SVN<\\\/a>/" $f`; |
---|
90 | #print " fixed wrong SVN link\n"; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | if ($allOK) { |
---|
95 | print "All source files OK!\n"; |
---|
96 | } |
---|