File: check-java-style.pl

package info (click to toggle)
libsvn-hooks-perl 1.19-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 372 kB
  • sloc: perl: 1,443; makefile: 7
file content (40 lines) | stat: -rwxr-xr-x 1,046 bytes parent folder | download | duplicates (5)
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
# Check if every added/changed Java file passes our code quality
# standards.

PRE_COMMIT {
    my ($svnlook) = @_;

    # CONFIG: Uncomment the following return to disable all checks
    # return;

    use autodie qw(:all);
    use Cwd;
    use File::Temp;
    use IO::Handle;

    my @javas = grep {/\.java$/} ($svnlook->added(), $svnlook->updated());
    return unless @javas;

    # CONFIG: Set $limit to 0 to have no limits on the number of files to be checked.
    if (my $limit = 10) {
	splice @javas, $limit if @javas > $limit;
    }

    # Create a copy of each java file in a temporary directory.
    my $dir = File::Temp->newdir();
    foreach my $java (@javas) {
	(my $file = $java) =~ tr:/:_:; # flaten the java file name
	open my $fh, '>', "$dir/$file";
	$fh->print($svnlook->cat($java));
    }

    my $cwd = cwd();
    chdir '/ha/subversion/admin/hooks/dsb';

    # Invoke the code quality tool on all saved java files
    system('java', '-jar', 'code-quality-hook-1.0-SNAPSHOT.jar', glob("$dir/*.java"));

    chdir $cwd;
};

1;