~ubuntu-branches/ubuntu/oneiric/javatools/oneiric

« back to all changes in this revision

Viewing changes to jh_generateorbitdir

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Johnson, Niels Thykier, Matthew Johnson
  • Date: 2010-03-30 00:11:37 UTC
  • mfrom: (6.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100330001137-ihh6lyi8omhx6dun
Tags: 0.30
[ Niels Thykier ]
* Added myself to uploaders.
* Created debhelper-like scripts for building eclipse features and
  added a dh7 sequence.
* Added Vcs-* fields.
* Replaced references to "dh_clean -k" with "dh_prep" in the tutorial.
  (Closes: #571097)
* Added DM-Upload-Allowed.
* Bumped Standards-Version to 3.8.4 - no changes required.

[ Matthew Johnson ]
* Make it a 3.0 (native) package

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
=head1 NAME
 
4
 
 
5
jh_generateorbitdir - Creates and populates an orbit dir used by pde-build for third-party jar files.
 
6
 
 
7
=cut
 
8
 
 
9
use strict;
 
10
use Debian::Debhelper::Dh_Lib;
 
11
use Debian::Javahelper::Eclipse;
 
12
 
 
13
=head1 SYNOPSIS
 
14
 
 
15
B<jh_generateorbitdir> [S<I<debhelper options>>] [B<--orbit-dir=>I<dir>] [S<I<orbit-dep [...]>>]
 
16
 
 
17
=head1 DESCRIPTION
 
18
 
 
19
jh_generateorbitdir is a javahelper program that handles creation
 
20
of an orbit dependency dir. This directory has to be populated with
 
21
non-eclipse jar files. However, eclipse refers to these jars by
 
22
their "symbolic name". jh_generateorbitdir can extract this name
 
23
from the jar's manifest (provided it has the OSGi metadata) and
 
24
create a symlink to it.
 
25
 
 
26
jh_generateorbitdir will replace regular files with symlinks
 
27
if they are present in the orbit dir and clash with the name
 
28
of one of the orbit jars. If an orbit jar name clashes with a
 
29
symlink in the orbit dir, then jh_generateorbitdir will assume
 
30
that the given jar has already been symlinked and skip it.
 
31
 
 
32
jh_generateorbitdir will also check the default installation for
 
33
jar files on Debian systems (at the time of writing /usr/share/java),
 
34
if it cannot find the jar in the current dir.
 
35
 
 
36
=head1 FILES
 
37
 
 
38
=over 4
 
39
 
 
40
=item debian/eclipse.orbitdeps
 
41
 
 
42
List of orbit dependencies - one per line. This can be used as an
 
43
alternative to passing it per command line.
 
44
 
 
45
=back
 
46
 
 
47
=head1 OPTIONS
 
48
 
 
49
=over 4
 
50
 
 
51
=item B<--orbit-dir=dir>
 
52
 
 
53
Specifies the directory from where the orbit-dir is or should be
 
54
created. Defauls to "debian/.eclipse_build/orbitdeps".
 
55
 
 
56
=back
 
57
 
 
58
=cut
 
59
 
 
60
my $orbitdir = undef;
 
61
my $cachefile = 'debian/orbitdeps.debhelper';
 
62
my $infile = 'debian/eclipse.orbitdeps';
 
63
my @orbitdeps;
 
64
my @include = ('.', '/usr/share/java');
 
65
my $tmpdir = undef;
 
66
 
 
67
init(options => {
 
68
    "orbit-dir=s" => \$orbitdir,
 
69
});
 
70
 
 
71
$orbitdir = "debian/.eclipse-build/orbitdeps" unless(defined($orbitdir));
 
72
 
 
73
@orbitdeps = @ARGV;
 
74
 
 
75
if( -e $infile){
 
76
    push(@orbitdeps, filearray($infile));
 
77
}
 
78
 
 
79
 
 
80
 
 
81
# If there is nothing to do then do not bother continuing.
 
82
exit(0) unless(scalar(@orbitdeps) > 0);
 
83
 
 
84
# make sure we always clean up our tmpdir in case of common signals.
 
85
$SIG{'INT'} = \&sighandler;
 
86
$SIG{'TERM'} = \&sighandler;
 
87
 
 
88
if( ! $dh{NO_ACT}){
 
89
    open(ORBIT_CACHE, ">>", $cachefile) or error("$cachefile: $!");
 
90
}
 
91
 
 
92
doit("mkdir", "-p", $orbitdir);
 
93
 
 
94
foreach my $jar (findJars(@orbitdeps)){
 
95
    my $fields = readFields($jar, EOB_SYM_NAME, EOB_BUNDLE_VERSION);
 
96
    my $symName = $fields->{${\EOB_SYM_NAME}};
 
97
    my $version = $fields->{${\EOB_BUNDLE_VERSION}};
 
98
    if($dh{NO_ACT} ){
 
99
        $symName = '<bundle-name>';
 
100
        $version = '<bundle-version>';
 
101
    }
 
102
    error("$jar did not have any OSGi metadata") unless(defined($symName) && defined($version));
 
103
    if( -l "$orbitdir/${symName}_${version}.jar"){
 
104
        my $ltarget = readlink("$orbitdir/${symName}_${version}.jar");
 
105
        if(defined($ltarget)){
 
106
            #Use target
 
107
            print ORBIT_CACHE "$ltarget, $symName, $version\n" unless($dh{NO_ACT});
 
108
        } else {
 
109
            warning("Cannot determine target of $orbitdir/${symName}_${version}.jar; jh_installeclipse will not be able to replace this post-install." );
 
110
        }
 
111
        # skip if already linked
 
112
        next;
 
113
    }
 
114
    error("No touching $orbitdir/${symName}_${version}.jar - it is a dir") if( -d "$orbitdir/${symName}_${version}.jar");
 
115
    doit("rm", "-f", "$orbitdir/${symName}_${version}.jar") if( -e "$orbitdir/${symName}_${version}.jar");
 
116
    print ORBIT_CACHE "$jar, $symName, $version\n" unless($dh{NO_ACT});
 
117
    doit("ln", "-s", $jar, "$orbitdir/${symName}_${version}.jar");
 
118
}
 
119
 
 
120
if( ! $dh{NO_ACT}){
 
121
    close(ORBIT_CACHE) or error("$cachefile: $!");
 
122
}
 
123
 
 
124
exit 0;
 
125
 
 
126
sub readFields {
 
127
    my $jar = shift;
 
128
    my $fields = {};
 
129
    if(! $dh{NO_ACT} ){
 
130
        chomp($tmpdir = `mktemp -d`);
 
131
    } else {
 
132
        $tmpdir = '<tmpdir>';
 
133
    }
 
134
    eval {
 
135
        doit("unzip", "-qq", "-n", "-d", $tmpdir, $jar);
 
136
        my $findmancmd = "find $tmpdir -iwholename '*/META-INF/MANIFEST.MF' 2>/dev/null";
 
137
        if( ! $dh{NO_ACT} ){
 
138
            my $manifest;
 
139
            verbose_print($findmancmd);
 
140
            chomp($manifest = `$findmancmd`);
 
141
            if( $manifest eq '' or ! -e $manifest){
 
142
                error("Cannot find the MANIFEST in $jar");
 
143
            }
 
144
            foreach my $f (@_) {
 
145
                my $cmd = "bash -c \". /usr/share/javahelper/jh_lib.sh && extractline $manifest $f\" 2>/dev/null";
 
146
                my $val;
 
147
                verbose_print($cmd);
 
148
                error("Could not read the MANIFEST of $jar") if($? != 0);
 
149
                chomp($val = `$cmd`);
 
150
                $fields->{$f} = $val;
 
151
            }
 
152
        } else {
 
153
            # print what we would have done.
 
154
            verbose_print($findmancmd);
 
155
            foreach my $f (@_) {
 
156
                verbose_print("bash -c \". /usr/share/javahelper/jh_lib.sh && extractline <manifest> $f\" 2>/dev/null");
 
157
            }
 
158
        }
 
159
    };
 
160
    doit("rm", "-fr", $tmpdir);
 
161
    $tmpdir = undef;
 
162
    if($@){
 
163
        #propagate the error.
 
164
        error($@);
 
165
    }
 
166
    return $fields;
 
167
}
 
168
 
 
169
sub sighandler {
 
170
    my $sig = shift;
 
171
    doit("rm", "-fr", $tmpdir) if(defined($tmpdir));
 
172
    error("Caught signal $sig");
 
173
}
 
174
 
 
175
sub findJars{
 
176
    my @inc = ('.', '/usr/share/java');
 
177
    my @res = ();
 
178
    foreach my $globpattern (@_){
 
179
        my @i = @inc;
 
180
        my $found = 0;
 
181
        # Only use inc-path if there is no path.
 
182
        @i = ('.') if($globpattern =~ m@/@o);
 
183
        glob_loop: foreach my $p (@inc){
 
184
            foreach my $s (''. '.jar') {
 
185
                my @matches = glob("$p/$globpattern$s");
 
186
                # skip if nothing matched or it was not a glob and the file does not exist.
 
187
                next if(scalar(@matches) == 0 or ! -e $matches[0]);
 
188
                push(@res, @matches);
 
189
                $found = 1;
 
190
                last glob_loop;
 
191
            }
 
192
        }
 
193
        die("Could not find any matches for $globpattern") unless($found);
 
194
    }
 
195
    return @res;
 
196
}
 
197
 
 
198
=head1 EXAMPLE
 
199
 
 
200
  jh_generateorbitdir --orbit-dir orbit asm3 oro
 
201
 
 
202
Will generate a folder called orbit with two symlinks based on asm3 and
 
203
oro's symbolic name.
 
204
 
 
205
=head1 SEE ALSO
 
206
 
 
207
L<debhelper(7)>
 
208
 
 
209
This program is a part of javahelper and uses debhelper as backend. There are
 
210
also tutorials in /usr/share/javahelper.
 
211
 
 
212
=head1 AUTHOR
 
213
 
 
214
Niels Thykier <niels@thykier.net>
 
215
 
 
216
=head1 COPYRIGHT AND LICENSE
 
217
 
 
218
Copyright 2010 by Niels Thykier
 
219
 
 
220
This tool is free software; you may redistribute it and/or modify
 
221
it under the terms of GNU GPL 2.
 
222
 
 
223
=cut