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

agwa-guest pushed a commit to branch master
in repository strip-nondeterminism.

commit daae69112a4816bc88e56865bdfd34c4f0b38443
Author: Andrew Ayer <a...@andrewayer.name>
Date:   Sat Sep 13 16:53:27 2014 -0700

    Add javadoc handler
    
    For now it only handles standalone html files, not html files embedded
    in a Jar file.
---
 lib/StripNondeterminism.pm                  |  6 +++
 lib/StripNondeterminism/handlers/javadoc.pm | 66 +++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/lib/StripNondeterminism.pm b/lib/StripNondeterminism.pm
index b01d673..5a225dd 100644
--- a/lib/StripNondeterminism.pm
+++ b/lib/StripNondeterminism.pm
@@ -24,6 +24,7 @@ use warnings;
 use StripNondeterminism::handlers::ar;
 use StripNondeterminism::handlers::gzip;
 use StripNondeterminism::handlers::jar;
+use StripNondeterminism::handlers::javadoc;
 use StripNondeterminism::handlers::zip;
 
 our($VERSION);
@@ -57,6 +58,10 @@ sub get_normalizer_for_file {
        if (m/\.jar$/ && _get_file_type($_) =~ m/Zip archive data/) {
                return \&StripNondeterminism::handlers::jar::normalize;
        }
+       # javadoc
+       if (m/\.html$/ && 
StripNondeterminism::handlers::javadoc::is_javadoc_file($_)) {
+               return \&StripNondeterminism::handlers::javadoc::normalize;
+       }
        # zip
        if (m/\.zip$/ && _get_file_type($_) =~ m/Zip archive data/) {
                return \&StripNondeterminism::handlers::zip::normalize;
@@ -69,6 +74,7 @@ sub get_normalizer_by_name {
        return \&StripNondeterminism::handlers::ar::normalize if $_ eq 'ar';
        return \&StripNondeterminism::handlers::gzip::normalize if $_ eq 'gzip';
        return \&StripNondeterminism::handlers::jar::normalize if $_ eq 'jar';
+       return \&StripNondeterminism::handlers::javadoc::normalize if $_ eq 
'javadoc';
        return \&StripNondeterminism::handlers::zip::normalize if $_ eq 'zip';
        return undef;
 }
diff --git a/lib/StripNondeterminism/handlers/javadoc.pm 
b/lib/StripNondeterminism/handlers/javadoc.pm
new file mode 100644
index 0000000..94ad012
--- /dev/null
+++ b/lib/StripNondeterminism/handlers/javadoc.pm
@@ -0,0 +1,66 @@
+#
+# Copyright 2014 Andrew Ayer
+#
+# This file is part of strip-nondeterminism.
+#
+# strip-nondeterminism is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# strip-nondeterminism is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with strip-nondeterminism.  If not, see <http://www.gnu.org/licenses/>.
+#
+package StripNondeterminism::handlers::javadoc;
+
+use strict;
+use warnings;
+
+use File::Temp qw/tempfile/;
+use File::Basename;
+
+sub is_javadoc_file {
+       my ($filename) = @_;
+
+       # If this is a javadoc file, '<!-- Generated by javadoc' should appear 
in first 1kb
+       my $fh;
+       my $str;
+       return open($fh, '<', $filename) && read($fh, $str, 1024) && $str =~ 
/\<!-- Generated by javadoc/;
+}
+
+sub normalize {
+       my ($filename) = @_;
+
+       open(my $fh, '<', $filename) or die "Unable to open $filename for 
reading: $!";
+       my ($out_fh, $out_filename) = tempfile(DIR => dirname($filename), 
UNLINK => 1);
+
+       # Strip the javadoc comment, which contains a timestamp.
+       # It should appear within first 10 lines.
+       while (defined(my $line = <$fh>) && $. <= 10) {
+               if ($line =~ /\<!-- Generated by javadoc .* --\>/) {
+                       $line =~ s/\<!-- Generated by javadoc .* --\>//g;
+                       print $out_fh $line unless $line =~ /^\s*$/; # elide 
lines that are now whitespace-only
+
+                       # Copy through rest of file
+                       my $bytes_read;
+                       my $buf;
+                       while ($bytes_read = read($fh, $buf, 4096)) {
+                               print $out_fh $buf;
+                       }
+                       defined($bytes_read) or die "$filename: read failed: 
$!";
+
+                       # Rename temporary file over the file
+                       chmod((stat($fh))[2] & 07777, $out_filename);
+                       rename($out_filename, $filename) or die "$filename: 
unable to overwrite: rename: $!";
+                       last;
+               }
+               print $out_fh $line;
+       }
+}
+
+1;

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/reproducible/strip-nondeterminism.git

_______________________________________________
Reproducible-builds mailing list
Reproducible-builds@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reproducible-builds

Reply via email to