This file is indexed.

/usr/share/perl5/Debian/Javahelper/Java.pm is in javahelper 0.45ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package Debian::Javahelper::Java;

=head1 NAME

Debian::Javahelper::Java - Javahelper core library.

=cut

use strict;
use warnings;
use autodie;

use Cwd 'abs_path';
use Exporter qw(import);
use File::Spec;

use Debian::Javahelper::Manifest();

our @EXPORT_OK = qw(scan_javadoc
                    find_package_for_existing_files
                    write_manifest_fd
                    parse_manifest_fd
);

=head1 SYNOPSIS

 use Debian::Javahelper::Java;
 
 my @paths = scan_javadoc("/usr/share/doc/libfreemarker-doc/api/");
 print "Freemarker is linked to the following APIs: \n - ",
       join("\n - ", @paths), "\n";
 my @packnames = find_package_for_existing_files("/bin/ls",
                 "/bin/bash");
 print "/bin/ls and /bin/bash are installed via: ",
       join(", ", @packnames), "\n";

=head1 DESCRIPTION

This module is used by various javahelpers to share common code.

Please note this API is not stable and backwards compatibility is not
guaranteed at the current time. Please contact the maintainers if you
are interested in a stable API.

=head2 Methods

=over 4

=item scan_javadoc($path)

Scans the javadoc at B<$path> and returns a list of javadocs it is
linked to on the system.

Currently it ignores all javadocs linked via other locations than
I</usr/share/doc> and it also makes an assumption that the linked
javadoc is in /usr/share/doc/<package>/<dir-or-symlink>. Of course,
all Java Policy compliant packages provide their javadoc from there.

If /usr/share/doc/<package>/<dir-or-symlink> appears to be a symlink,
then it is followed (except for default-jdk-doc).

=item find_package_for_existing_files(@files)

Consults L<dpkg(1)> to see which packages provides B<@files> and
returns this list. All entries in B<@files> must exists (but is
not required to be files) and should not be used on a directory.

Furthermore all entries must be given with absolute path.

=item parse_manifest_fd($fd, $filename)

Parses a manifest from B<$fd>, which must be a readable filehandle,
and returns a
L<Debian::Javahelper::Manifest|Debian::Javahelper::Manifest>.

B<$filename> is only used to report parsing errors and should be
something that identifies the source of B<$fd>.

=item write_manifest_fd($manifest, $fd, $filename)

Writes B<$manifest> to the writable filehandle B<$fd>. B<$manifest>
must be a
L<Debian::Javahelper::Manifest|Debian::Javahelper::Manifest>.

B<$filename> is only used to report errors and should be something
that identifies B<$fd>.

=item write_manifest_section_fd($section, $fd, $filename)

Writes B<$section> to the writable filehandle B<$fd>. B<$section>
must be a
L<Debian::Javahelper::ManifestSection|Debian::Javahelper::ManifestSection>.

B<$filename> is only used to report errors and should be something
that identifies B<$fd>.

NB: Helper - Not exported.

=item slurp_file($file)

Reads all lines in B<$file> and returns them as a list.

NB: Helper - Not exported.

=back

=cut

sub scan_javadoc{
    my $docloc = shift;
    my %phash;
    my @packages = slurp_file("$docloc/package-list");
    # For each package in package-list (replacing "." with "/")
    foreach my $pack ( map { s@\.@/@go; $_; } @packages) {
        opendir(my $dir, "$docloc/$pack");
        # For each html file in $dir
        foreach my $file ( grep { m/\.html$/iox } readdir($dir)){
            open(my $htfile, '<', "$docloc/$pack/$file");
            while( my $line = <$htfile> ){
                my $target;
                my $packname;
                my $apif;
                next unless($line =~ m@ href=" (/usr/share/doc/[^.]++\.html) @oxi);
                $target = $1;
                $target =~ m@/usr/share/doc/([^/]++)/([^/]++)/@o;
                $packname = $1;
                $apif = $2;
                if(!defined($packname)){
                    print STDERR "Ignoring weird URL target ($target).\n";
                    next;
                }
                $phash{"/usr/share/doc/$packname/$apif"} = 1;
            }
            close($htfile);
        }
        closedir($dir);
    }
    return keys(%phash);
}

sub slurp_file{
    my $file = shift;
    my @data;
    open(my $handle, '<', $file);
    while(my $line = <$handle> ){
        chomp($line);
        $line =~ s/\r$//o;
        push(@data, $line);
    }
    close($handle);
    return @data;
}

sub find_package_for_existing_files{
    my %pkgs;
    my %files;
    foreach my $file (@_){
        die("$file must be given with absolute path.") unless( $file =~ m@^/@o );
        die("$file does not exist") unless( -e $file );
        $file =~ s@/{2,}@/@og;
        $file =~ s@[/]+$@@og;
        $files{$file} = 1;
    }
    open(my $dpkg, '-|', 'dpkg', '-S',  @_);
    while( my $line = <$dpkg> ){
        my ($pkg, $file) = split(/:\s++/ox, $line);
        chomp($file);
        $pkgs{$pkg} = 1 if(exists($files{$file}));
    }
    close($dpkg);
    return keys(%pkgs);
}

sub parse_manifest_fd{
    my $fd = shift;
    my $name = shift;
    my $manifest = Debian::Javahelper::Manifest->new();
    my $sec = $manifest->get_section(Debian::Javahelper::Manifest::MAIN_SECTION, 1);
    my $atname = '';
    my $atval = '';
    while( my $line = <$fd> ){
        $line =~ s/[\r]?[\n]$//og;
        if($line =~ m/^ /o){
            # extension to a value.
            die("Unexpected \"extension line\" in $name,") unless($atname);
            $atval .= substr($line, 1);
            next;
        }
        if($line ne ''){
            if($atname){
                if(!defined($sec)){
                    $sec = $manifest->get_section($atval, 1);
                } else {
                    $sec->set_value($atname, $atval);
                }
            }
            ($atname, $atval) = split(/ :\s /ox, $line, 2);
            if(!$atval){
                die("Expected <attr>: <val> pair in $name,")
                    unless($line =~ m/ :\s /ox);
                $atval = '';
            }
            if(!defined($sec)){
                die("A section must start with the Name attribute in $name,")
                    unless(lc($atname) eq 'name');
            }
            next;
        }
        if($atname) {
            if(!defined($sec)){
                $sec = $manifest->get_section($atval, 1);
            } else {
                $sec->set_value($atname, $atval);
            }
        }
        $atname = '';
        $sec = undef;
    }

    $sec->set_value($atname, $atval) if($atname);
    return $manifest;
}

sub write_manifest_section_fd{
    my $sec = shift;
    my $fd = shift;
    my $name = shift;
    # return manifest-version and name first
    foreach my $entry ($sec->get_values()) {
        my $line = join(': ', @$entry);
        # Extend long lines.  Technically this is incorrect since the
        # rules says "bytes" and not "characters".
        #
        # (for future reference this is: Insert '\n ' after every 72
        # chars, but only if there is a 73rd character following them)
        #
        # If you change this, remember to change jh_build as well,
        # which also have this.
        $line =~ s/(.{72})(?=.)/$1\n /go;
        print {$fd} $line, "\n";
    }
    print $fd "\n";
    1;
}

sub write_manifest_fd{
    my $manifest = shift;
    my $fd = shift;
    my $name = shift;
    # returns main section first.
    foreach my $sec ($manifest->get_sections()){
        write_manifest_section_fd($sec, $fd, $name);
    }
    # must end with two empty lines.
    print $fd "\n";
    1;
}

# For length
# s/(.{$len})/$1\n /g; s/^ \n(\w)/$1/g

1;
__END__

=head1 SEE ALSO

L<Debian::Javahelper::Manifest(3)>
L<Debian::Javahelper::ManifestSection(3)>

=head1 AUTHOR

Niels Thykier <niels@thykier.net>

=head1 COPYRIGHT AND LICENSE

Copyright 2010 by Niels Thykier

This module is free software; you may redistribute it and/or modify
it under the terms of GNU GPL 2.

=cut