[SCM] UNNAMED PROJECT branch, master, updated. 0.30-31-gd411570

Niels Thykier nthykier-guest at alioth.debian.org
Sun Jul 4 22:59:01 UTC 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "UNNAMED PROJECT".

The branch, master has been updated
       via  d411570f5734f4996a6ec788a8133f9a929e66bb (commit)
       via  2774eccf8385cffcb7f5c9bad02c784883af1b9a (commit)
       via  533e68290256ddb1202b1c38fe7a4e0014691311 (commit)
      from  930c284ff119ed46f28cf2b3926477ec41a65940 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d411570f5734f4996a6ec788a8133f9a929e66bb
Author: Niels Thykier <niels at thykier.net>
Date:   Mon Jul 5 00:58:16 2010 +0200

    Rewrote jh_manifest, removed all depends on python.

commit 2774eccf8385cffcb7f5c9bad02c784883af1b9a
Author: Niels Thykier <niels at thykier.net>
Date:   Mon Jul 5 00:47:03 2010 +0200

    Added modules manifest handling.

commit 533e68290256ddb1202b1c38fe7a4e0014691311
Author: Niels Thykier <niels at thykier.net>
Date:   Mon Jul 5 00:45:29 2010 +0200

    Fixed a formatting issue and added missing entry in the changelog.

-----------------------------------------------------------------------

Summary of changes:
 Java.pm                    |   74 +++++++-
 Manifest.pm                |   53 +++++
 ManifestSection.pm         |   62 ++++++
 debian/changelog           |    6 +
 debian/control             |    6 +-
 debian/javahelper.install  |    2 +
 debian/javahelper.manpages |    1 -
 debian/rules               |    3 +
 jh_compilefeatures         |   12 +-
 jh_generateorbitdir        |    2 +-
 jh_installeclipse          |    4 +-
 jh_manifest                |  491 ++++++++++++++++++++------------------------
 jh_manifest.1              |   35 ---
 jh_setupenvironment        |    2 +-
 tests/tests.sh             |   10 +-
 15 files changed, 448 insertions(+), 315 deletions(-)

diff --git a/Java.pm b/Java.pm
index 63e6b4d..9f201e8 100644
--- a/Java.pm
+++ b/Java.pm
@@ -12,9 +12,10 @@ use warnings;
 use Cwd 'abs_path';
 use File::Spec;
 use Exporter;
+use Debian::Javahelper::Manifest();
 use vars qw(@ISA @EXPORT);
 @ISA = qw(Exporter);
- at EXPORT = qw(&scan_javadoc &find_package_for_existing_files);
+ at EXPORT = qw(&scan_javadoc &find_package_for_existing_files &write_manifest_fd &parse_manifest_fd);
 
 =head1 SYNOPSIS
 
@@ -135,6 +136,77 @@ sub find_package_for_existing_files{
     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 ''){
+	    $sec->set_value($atname, $atval) if($atname);
+	    ($atname, $atval) = split(/ :\s /ox, $line);
+	    die("Expected <attr>: <val> pair in $name,") unless($atval);
+	    if(!defined($sec)){
+		die("A section must start with the Name attribute in $name,")
+		    unless(lc($atname) eq 'name');
+		$sec = $manifest->get_section($atval, 1);
+		$atname = '';
+	    }
+	    next;
+	}
+	$sec->set_value($atname, $atval) if($atname);
+	$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 $atname = lc($entry->[0]);
+	my $line = join(": ", @$entry);
+	# Technically this is incorrect since the rules says "bytes" and not "characters"
+	die("Value for Name attribute in $name is too long,") if($atname eq 'name' && length($line) > 72);
+	# extend long lines.
+	$line =~ s/(.{72})/$1\n /go;
+	$line =~ s/^ \n(\w)/$1/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__
 
diff --git a/Manifest.pm b/Manifest.pm
new file mode 100644
index 0000000..8eb4bb7
--- /dev/null
+++ b/Manifest.pm
@@ -0,0 +1,53 @@
+package Debian::Javahelper::Manifest;
+
+use strict;
+use warnings;
+
+use Debian::Javahelper::ManifestSection;
+use base qw(Exporter);
+# pass it on to others.
+our @EXPORT = qw(MAIN_SECTION);
+
+sub new {
+    my $type = shift;
+    my $this = bless({}, $type);
+    return $this;
+}
+
+sub get_section {
+    my $this = shift;
+    my $sname = shift;
+    my $create = shift//0;
+    my $sec = $this->{$sname}; 
+    if(!defined($sec) && $create){
+	$sec = Debian::Javahelper::ManifestSection->new($sname);
+	$this->{$sname} = $sec;
+    }
+    return $sec;
+}
+
+sub get_sections {
+    my $this = shift;
+    # There is always a main section.
+    my $main = $this->get_section(MAIN_SECTION, 1);
+    my @sections = ($main);
+    while( my ($name, $sec) = each(%$this) ){
+	next if($name eq MAIN_SECTION);
+	push(@sections, $sec);
+    }
+    return @sections;
+}
+
+sub merge {
+    my $this = shift;
+    my $other = shift;
+    while( my ($osname, $osec) = each(%$other) ){
+	my $tsec = $this->get_section($osname, 1);
+	foreach my $val ($osec->get_values()){
+	    $tsec->set_value($val->[0], $val->[1]);
+	}
+    }
+    1;
+}
+
+1;
diff --git a/ManifestSection.pm b/ManifestSection.pm
new file mode 100644
index 0000000..d2c350f
--- /dev/null
+++ b/ManifestSection.pm
@@ -0,0 +1,62 @@
+package Debian::Javahelper::ManifestSection;
+
+use strict;
+use warnings;
+use base qw(Exporter);
+our @EXPORT = qw(MAIN_SECTION);
+
+use constant {
+    MAIN_SECTION => 'MAIN'
+};
+
+sub new{
+    my $type = shift;
+    my $name = shift;
+    my $this = bless({}, $type);
+    if($name eq MAIN_SECTION){
+	$this->set_value('Manifest-Version', '1.0');
+    } else {
+	$this->set_value('Name', $name);
+    }
+    return $this;
+}
+
+sub set_value {
+    my $this = shift;
+    my $name = shift;
+    my $value = shift;
+    # Store the name with the original case for later.
+    $this->{lc($name)} = [$name, $value];
+    1;
+}
+
+sub get_value {
+    my $this = shift;
+    my $name = shift;
+    my $empty = shift//0;
+    my $val = $this->{lc($name)};
+    if(defined($val)){
+	return $val->[1];
+    }
+    return '' if($empty);
+    return undef;
+}
+
+sub get_values {
+    my $this = shift;
+    my @values = ();
+    # These go first
+    foreach my $var (qw(manifest-version name)){
+	my $val = $this->{$var};
+	push(@values, $val) if(defined($val));
+    }
+    # any order is okay for the rest.
+    while( my ($name, $val) = each(%$this)){
+	# we already got these
+	next if($name eq 'manifest-version' or $name eq 'name');
+	push(@values, $val);
+    }
+    return @values;
+}
+
+1;
diff --git a/debian/changelog b/debian/changelog
index d210b06..024cf50 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -26,6 +26,12 @@ javatools (0.32) UNRELEASED; urgency=low
   * jh_depends now generates a dependency list for javadocs based on
     which system javadocs they have been linked against. These packages
     are added to the new ${java:Recommends} variable.
+  * jh_installeclipse now always emits ${orbit:Depends} even if it
+    would be empty.
+  * Fixed a formatting issue in the eclipse helpers.
+  * Rewrote jh_manifest using debhelper as backend.
+    - it now produces deterministic output (Closes: #574029)
+    - removed all depends on python.
 
   [ Matthew Johnson ]
   * If jars aren't specified by absolute path try finding them under
diff --git a/debian/control b/debian/control
index 5b4aa26..6f9ca72 100644
--- a/debian/control
+++ b/debian/control
@@ -22,9 +22,9 @@ Description: Run executable Java .jar files
 
 Package: javahelper
 Architecture: all
-Depends: ${misc:Depends}, fastjar, debhelper, python, python-debian,
-         python-scriptutil, devscripts, bsdmainutils, dpkg-dev,
-         dctrl-tools
+Depends: ${misc:Depends}, fastjar, debhelper, devscripts,
+         bsdmainutils, dpkg-dev, dctrl-tools,
+         libarchive-zip-perl
 Suggests: cvs,
           gawk,
           tofrodos,
diff --git a/debian/javahelper.install b/debian/javahelper.install
index 6251f08..e54eb42 100644
--- a/debian/javahelper.install
+++ b/debian/javahelper.install
@@ -24,3 +24,5 @@ javahelper.pm /usr/share/perl5/Debian/Debhelper/Sequence
 eclipse_helper.pm /usr/share/perl5/Debian/Debhelper/Sequence
 Eclipse.pm /usr/share/perl5/Debian/Javahelper/
 Java.pm /usr/share/perl5/Debian/Javahelper/
+Manifest.pm /usr/share/perl5/Debian/Javahelper/
+ManifestSection.pm /usr/share/perl5/Debian/Javahelper/
diff --git a/debian/javahelper.manpages b/debian/javahelper.manpages
index 34bc7c2..2724230 100644
--- a/debian/javahelper.manpages
+++ b/debian/javahelper.manpages
@@ -4,7 +4,6 @@ jh_exec.1
 jh_installlibs.1
 jh_installjavadoc.1
 jh_makepkg.1
-jh_manifest.1
 jh_classpath.1
 jh_repack.1
 jh_linkjars.1
diff --git a/debian/rules b/debian/rules
index 164250f..433f971 100755
--- a/debian/rules
+++ b/debian/rules
@@ -15,10 +15,13 @@ override_dh_auto_build:
 	$(POD2MAN) jh_generateorbitdir tmp/jh_generateorbitdir.1
 	$(POD2MAN) jh_setupenvironment tmp/jh_setupenvironment.1
 	$(POD2MAN) jh_compilefeatures tmp/jh_compilefeatures.1
+	$(POD2MAN) jh_manifest tmp/jh_manifest.1
 	$(POD2MAN) fetch-eclipse-source.pod tmp/fetch-eclipse-source.1
 	$(POD2MAN) -s 1 jh_clean.pod tmp/jh_clean.1
 	$(POD2MAN) Eclipse.pm tmp/Debian::Javahelper::Eclipse.3
 	$(POD2MAN) Java.pm tmp/Debian::Javahelper::Java.3
+	$(POD2MAN) Manifest.pm tmp/Debian::Javahelper::Manifest.3
+	$(POD2MAN) ManifestSection.pm tmp/Debian::Javahelper::ManifestSection.3
 	# jarwrapper pod-based manpages
 	$(POD2MAN) -s 1 jarwrapper.pod tmp.jarwrapper/jarwrapper.1
 	$(POD2MAN) -s 1 jardetector.pod tmp.jarwrapper/jardetector.1
diff --git a/jh_compilefeatures b/jh_compilefeatures
index 9b860f7..5f7c585 100755
--- a/jh_compilefeatures
+++ b/jh_compilefeatures
@@ -64,18 +64,18 @@ eclipse's dropins folder or it has just been compiled.
 
 =over 4
 
-=item B<--pde-build-dir=dir>
+=item B<--pde-build-dir=>I<dir>
 
 Specifies the directory from where pde-build is to be run. Defauls to
 "debian/.eclipse_build".
 
-=item B<--feature-deps=deps>
+=item B<--feature-deps=>I<deps>
 
 A space separated list of dependencies. These dependencies will be used
 to compile all features passed by command-line. Features read from
 debian/eclipse.features are unaffected by this.
 
-=item B<--build-opts=args>
+=item B<--build-opts=>I<args>
 
 Pass args to the underlying builder. These options are passed to all
 features built.
@@ -83,17 +83,17 @@ features built.
 This defaults to "-DjavacTarget=1.5 -DjavacSource=1.5" if not set.
 This can be disabled by passing the empty string.
 
-=item B<--jvm-args=args>
+=item B<--jvm-args=>I<args>
 
 Pass args to the JVM. These options are passed to all
 features built.
 
-=item B<--orbit-dir=dir>
+=item B<--orbit-dir=>I<dir>
 
 Specifies where the Orbit dependencies can be found. This is only needed
 if the orbit dir is in an unusual location.
 
-=item B<--pde-build=cmd>
+=item B<--pde-build=>I<cmd>
 
 Use a non-standard pde-build command to compile the features.
 
diff --git a/jh_generateorbitdir b/jh_generateorbitdir
index 6bc331d..6f6f8e6 100755
--- a/jh_generateorbitdir
+++ b/jh_generateorbitdir
@@ -53,7 +53,7 @@ alternative to passing it per command line.
 
 =over 4
 
-=item B<--orbit-dir=dir>
+=item B<--orbit-dir=>I<dir>
 
 Specifies the directory from where the orbit-dir is or should be
 created. Defauls to "debian/.eclipse_build/orbitdeps".
diff --git a/jh_installeclipse b/jh_installeclipse
index aea360a..ef4bb0c 100755
--- a/jh_installeclipse
+++ b/jh_installeclipse
@@ -51,13 +51,13 @@ under the same name.
 
 =over 4
 
-=item B<--install-name=name>
+=item B<--install-name=>I<name>
 
 Specifies the name to install under if it is not given in the file. It
 is perfectly legal to install more than one feature under the same
 name.
 
-=item B<--pde-build-dir=dir>
+=item B<--pde-build-dir=>I<dir>
 
 Specifies the directory from where pde-build was run. Defauls to
 "debian/.eclipse_build".
diff --git a/jh_manifest b/jh_manifest
index 1cd7a0a..3fe4b8e 100755
--- a/jh_manifest
+++ b/jh_manifest
@@ -1,266 +1,229 @@
-#!/usr/bin/python
-
-import sys,getopt,debian.deb822,scriptutil,os,tempfile,copy
-
-def usage():
-   print "Usage: jh_manifest [options] [<jar> ...]"
-   print "Options:"
-   print "\t-h --help: show this text"
-   print "\t-v --verbose: show more information while running"
-   print "\t-V --version: print the version"
-   print "\t-n --no-act: don't actually do anything, just print the results"
-   print "When reading manifest files for packages:"
-   print "\t-i --indep: run for all Arch: all packages"
-   print "\t-a --arch: run for all Arch-specific packages"
-   print "\t-p<package> --package=<package>: package to act on (default=all)"  
-   print "\t-P<packagedir> --tmpdir=<package>: package directory (default=\$CWD/debian/package)"  
-   print "When acting on a jar from the command line:"
-   print "\t-c<classpath> --classpath=<classpath>: The classpath to set (space separated)"
-   print "\t-j</path/to/java/home> --java-home=</path/to/java/home>: The path to the JRE to use to execute the jar"
-   print "\t-m<class> --main=<class>: The class to run when executing the jar"
-   print "\t-o<options> --javaopts=<options>: Options passed to java when executing the jar"
-
-opts="vnihVap:P:c:j:m:o:"
-longopts=["version","help","verbose","no-act","indep","arch","package=","tmpdir=","classpath=","main=","javaopts=","with="]
-
-sys.argv.remove(sys.argv[0]);
-(parsed, notparsed) = getopt.getopt(sys.argv,opts,longopts);
-
-args={}
-
-def version():
-   print "javahelper version: ??"
-
-def findpackages(args):
-   packages = []
-   f = file("debian/control")
-   for pkg in debian.deb822.Deb822.iter_paragraphs(f):
-      if "Package" in pkg:
-         if "--package" in args:
-            if pkg["Package"] == args["--package"]:
-               packages.append(pkg["Package"])
-         elif "-p" in args:
-            if pkg["Package"] == args["-p"]:
-               packages.append(pkg["Package"])
-         elif "--arch" in args or "-a" in args:
-            if pkg["Architecture"] != "all":
-               packages.append(pkg["Package"])
-         elif "--indep" in args or "-i" in args:
-            if pkg["Architecture"] == "all":
-               packages.append(pkg["Package"])
-         else:
-             packages.append(pkg["Package"])
-
-   f.close()
-   return packages
-
-def updatejar(jar, manifest, args):
-
-   jar = os.path.realpath(jar)
-   if not os.path.exists(jar):
-      print "Warning: "+jar+" does not exist"
-      return
-
-   if "--verbose" in args or "-v" in args:
-      print "Updating manifest in "+jar
-
-   tempdir = tempfile.mkdtemp()
-
-   if os.path.exists(tempdir + "/META-INF/MANIFEST.MF"):
-      os.unlink(tempdir + "/META-INF/MANIFEST.MF")
-
-   os.system("cd '"+tempdir+"' ; fastjar -x -f '"+jar+"'")
-
-   manifest_override = 0
-   if {"top":{}} != manifest:
-     manifest_override = 1
-
-   manifest = parseManifest(tempdir + "/META-INF/MANIFEST.MF", None, manifest)
-
-   if not "Class-Path" in manifest["top"] and "CLASSPATH" in os.environ:
-      manifest["top"]["Class-Path"] = os.environ["CLASSPATH"].replace(":", " ")
-      manifest_override = 1
-
-   # No need to rewrite manifest if there are no overrides !
-   if manifest_override:
-     writeManifest(tempdir + "/MANIFEST.MF", manifest)
-
-   if "--no-act" in args or "-n" in args:
-      print jar+":"
-      print str(manifest)
-   elif manifest_override:
-   # No need to rewrite manifest if there are no overrides !
-      os.system("rm -f '"+jar+"' ")
-      os.system("cd '"+tempdir+"' ; ls -1 | egrep -v '^(META-INF|MANIFEST.MF)' | fastjar -c -f '"+jar+"' -m MANIFEST.MF -@")
-
-   os.system("rm -rf '"+tempdir+"' ")
-
-def findjars(path):
-   return scriptutil.ffind(path, shellglobs=['*.jar'])
-
-def splitWrite(f, line):
-   words = line.split()
-   i = 0
-   first = True
-   for w in words:
-      if i+len(w) > 71:
-         f.write("\n ")
-         i = 0
-      if len(w) > 71:
-         k = 0
-         while k < len(w):
-            if k % 72 == 71:
-               f.write("\n ")
-            f.write(w[k])
-            k = k + 1
-         i = i + (k % 72) + 1
-      else:
-         if first:
-            first = False
-         else:
-            f.write(" ")
-         f.write(w)
-         i = i + len(w) + 1
-   f.write("\n")
-
-def writeManifest(filename, manifest):
-   f = file(filename, 'w')
-   kvs = manifest["top"].items()
-   kvs.reverse()
-   for (k, v) in kvs:
-      splitWrite(f, k+": "+v)
-   splitWrite(f, "")
-   for (l, m) in manifest.items():
-      if l != "top":
-         if "Name" in m:
-            splitWrite(f, "Name: "+m["Name"])
-         for (k, v) in m.items():
-            if "Name" != k:
-               splitWrite(f, k+": "+v)
-         splitWrite(f, "")
-
-   f.flush()
-   f.close()
-
-def parseManifest(filename, jar, manifest):
-
-   if not os.path.exists(filename):
-      return manifest
-
-   f = file(filename)
-   if None == jar:
-      section = "top"
-      secno = 0
-      for sec in debian.deb822.Deb822.iter_paragraphs(f):
-         if "" == section:
-            if "Name" in sec:
-               section = sec["Name"]
-            else:
-                section = "anon"+str(secno)
-         if section not in manifest:
-            manifest[section] = {}
-         for i in sec:
-            if not i.strip() in manifest[section]:
-               manifest[section][i.strip()] = sec[i].strip().replace('\n ','')
-         section = ""
-   else:
-      lines = f.readlines()
-
-      section="top"
-      sec = 0
-      injar = True
-      for l in lines:
-         l = l.rstrip()
-         if None != jar:
-            if "" != l and (jar+":").endswith(l):
-               section = "top"
-               injar = True
-               continue
-            if not injar: continue
-            if "" != l and not l.startswith(" "): 
-               section = "top"
-               injar = False
-               continue
-         l = l.lstrip()
-         if "" == l:
-            section=""
-            continue
-         elif "" == section:
-            (k, v) = l.split(":", 1)
-            if "Name" == k: 
-               section = v.strip()
-            else:
-               section = "anon"+str(sec)
-               sec = sec + 1
-            if not section in manifest:
-               manifest[section] = {}
-         else:
-            (k, v) = l.split(":", 1)
-
-         if not k.strip() in manifest[section]:
-            manifest[section][k.strip()] = v.strip()
-
-   f.close()
-
-   return manifest
-
-for i in parsed:
-   (k, v) = i
-   args[k] = v
-
-if "--help" in args or "-h" in args:
-   usage()
-   sys.exit(0)
-if "--version" in args or "-V" in args:
-   version()
-   sys.exit(0)
-
-manifest = {"top":{}}
-if "--classpath" in args:
-   manifest["top"]["Class-Path"] = args["--classpath"]
-if "-c" in args:
-   manifest["top"]["Class-Path"] = args["-c"]
-if "--main" in args:
-   manifest["top"]["Main-Class"] = args["--main"]
-if "-m" in args:
-   manifest["top"]["Main-Class"] = args["-m"]
-if "--java-home" in args:
-   manifest["top"]["Debian-Java-Home"] = args["--java-home"]
-if "-j" in args:
-   manifest["top"]["Debian-Java-Home"] = args["-j"]
-if "--javaopts" in args:
-   manifest["top"]["Debian-Java-Parameters"] = args["--javaopts"]
-if "-o" in args:
-   manifest["top"]["Debian-Java-Parameters"] = args["-o"]
-
-if len(notparsed) > 0:
-   
-   for i in notparsed:
-      updatejar(i, manifest, args)
-
-else:
-
-   if not os.path.exists("debian/changelog"):
-      print "No debian/changelog, aborting"
-      sys.exit(1)
-
-   for p in findpackages(args):
-      tmpdir="debian/"+p
-      if "-P" in args:
-         tmpdir = args["-P"]
-      if "--tmpdir" in args:
-         tmpdir = args["--tmpdir"]
-   
-      for j in findjars(tmpdir):
-
-         tempmanifest = copy.deepcopy(manifest)
-         if os.path.exists("debian/"+p+".manifest"):
-            manifestfile = "debian/"+p+".manifest"
-            tempmanifest = parseManifest(manifestfile, j, tempmanifest)
-         if os.path.exists("debian/manifest"):
-            manifestfile = "debian/manifest"
-            tempmanifest = parseManifest(manifestfile, j, tempmanifest)
-
-         updatejar(j, tempmanifest, args)
+#!/usr/bin/perl
 
+=head1 NAME
+
+jh_manifest - Adds or/and modifies manifests for jars
+
+=cut
+
+use strict;
+use warnings;
+
+use File::Find;
+use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
+use Debian::Debhelper::Dh_Lib;
+use Debian::Javahelper::Java;
+use Debian::Javahelper::Manifest( qw(MAIN_SECTION) );
+
+=head1 SYNOPSIS
+
+B<jh_manifest>  [S<I<debhelper options>>]  [S<I<options>>]  I<jar1> ... I<jarN>
+B<jh_manifest>  [S<I<debhelper options>>]  [S<I<options>>]
+
+=head1 DESCRIPTION
+
+Javahelper tool to add or update manifests in a jar file. It can be
+used in two modes. If passed jar files, it will only process these jar
+files. Otherwise it will update all jar files in the packages it acts
+on.
+
+When processing a package, the L<debhelper(7)> exclude option will
+make B<jh_manifest> ignore matching jar files.
+
+=head1 FILES
+
+=over 4
+
+=item debian/I<package>.manifest (or debian/manifest)
+
+All the entries in this manifest will be merged into every jar file
+processed in the given package. If an attribute exists in the same
+section of this manifest and the original in the jar file, then the
+attribute in this manifest will be used.
+
+Note: attributes set via command line options will overrule attributes
+in either manifest.
+
+This file is ignored if B<jh_manifest> is passed jar files via command
+line.
+
+=back
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-c> I<classpath>, B<--classpath=>I<classpath>
+
+Sets the Class-Path attribute of all processed jar files to
+I<classpath>.
+
+If not passed, then the CLASSPATH environment variable will be used in
+the given jar file do not have a Class-Path attribute.
+
+=item B<-m> I<class>, B<--main=>I<class>
+
+Sets the Main-Class attribute to I<class> in all processed jar files.
+
+=item B<-o> I<options>, B<--javaopts=>I<options>
+
+Sets the Debian-Java-Parameters to I<options> in all processed jar
+files. This attribute is used by jarwrapper to start java with extra
+options (e.g. to make more memory available).
+
+=item B<-j> I</path/to/java/home>, B<--java-home=>I</path/to/java/home>
+
+Sets the Debian-Java-Home attribute to I</path/to/java/home> in all
+processed jars. This attribute is used by jarwrapper to determine
+which JVM to use.
+
+=back
+
+=cut
+
+my $cp = '';
+my $mcl = '';
+my $jvm = '';
+my $jopt = '';
+my $envcp = 0;
+
+init(options => {
+    # -o clashes debhelper's "only scripts"
+    "javaopts|o=s" => \$jopt,
+    "java-home|j=s" => \$jvm,
+    "main|m=s" => \$mcl,
+    "classpath|c=s" => \$cp,
+    "version|V" => sub { print STDERR "Version has been removed - please stop using it\n"; exit(0) },
+     });
+
+if(!$cp && $ENV{'CLASSPATH'}//'' ne ''){
+    $cp = $ENV{'CLASSPATH'};
+    $cp =~ s/:/ /go;
+    $envcp = 1;
+}
+
+if(@ARGV){
+    foreach my $jar (@ARGV){
+	update_jar($jar, undef);
+    }
+    inhibit_log();
+    # behave like the old jh_manifest.
+    exit(0);
+}
+
+foreach my $package (@{$dh{DOPACKAGES}}) {
+    my $man = pkgfile($package, "manifest");
+    my $dir = tmpdir($package);
+    my $manifest = undef;
+    my $find_cmd="find $dir ";
+    my $err;
+    # skip if it does not exist.
+    if( ! -d $dir ){
+	verbose_print("Skipping $package - $dir does not exist (or is not a dir).");
+	next;
+    }
+    if($man){
+	open(my $mfd, "<", $man) or die("$man: $!");
+	$manifest = parse_manifest_fd($mfd, $man);
+	close($mfd);
+    }
+    if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne ''){
+	$find_cmd.=" '!' \\( $dh{EXCLUDE_FIND} \\) -a ";
+    }
+    $find_cmd .= " '!' -type l -a -name '*.jar'";
+    verbose_print("$find_cmd");
+    open(my $jarfiles, "-|", "$find_cmd") or error("$find_cmd: $!");
+    while( my $jar = <$jarfiles> ) {
+	chomp($jar);
+	update_jar($jar, $manifest);
+    }
+    close($jarfiles);
+    # Shame on me - using internal subs from Dh_Lib - but it works.
+    #   It will error out if invoked.
+    Debian::Debhelper::Dh_Lib::_error_exitcode($find_cmd) if($?);
+}
+
+exit(0);
+
+sub update_jar{
+    my $jar = shift;
+    my $merge = shift;
+    my $zip = Archive::Zip->new();
+    my $con;
+    my $manifest;
+    my $stat;
+    my $dirty = 0;
+    my $main;
+    my $new_manifest = 0;
+    # stringify or $zip will make a call back that fails.
+    $zip->read( "$jar" ) == AZ_OK or error("Could not read $jar: $!");
+    ($con, $stat) = $zip->contents( 'META-INF/MANIFEST.MF' );
+    die("Could not read manifest from $jar ($stat): $!") unless(!defined($stat) or $stat == AZ_OK);
+    if(defined($stat)) {
+	verbose_print("Reading manifest from $jar");
+	open(my $fd, "<", \$con) or error("open read string: $!");
+	$manifest = parse_manifest_fd($fd, $jar);
+	close($fd);
+    } else {
+	verbose_print("$jar does not have a manifest.");
+	$manifest = Debian::Javahelper::Manifest->new();
+	$new_manifest = 1;
+    }
+    if(defined($merge)){
+	$manifest->merge($merge);
+	$dirty = 1;
+    }
+    $main = $manifest->get_section(MAIN_SECTION, 1);
+    if($cp && (!$envcp || ($main->get_value('Class-Path')//'') eq '')){
+	$main->set_value('Class-Path', $cp);
+	$dirty = 1;
+    }
+    if($mcl){
+	$main->set_value('Main-Class', $mcl);
+	$dirty = 1;
+    }
+    if($jvm){
+	$main->set_value('Debian-Java-Home', $jvm);
+	$dirty = 1;
+    }
+    if($jopt){
+	$main->set_value('Debian-Java-Parameters', $jopt);
+	$dirty = 1;
+    }
+    if($dirty){
+	my $var;
+	open(my $fd, ">", \$var) or error("open write string: $!");
+	write_manifest_fd($manifest, $fd, $jar);
+	close($fd);
+	verbose_print("Updating manifest in $jar");
+	$zip->removeMember( 'META-INF/MANIFEST.MF' ) unless($new_manifest);
+	$zip->addString($var, 'META-INF/MANIFEST.MF');
+	# This on the other hand may fail.
+	$zip->overwrite() == AZ_OK or error("Writing modified jar ($jar) failed: $!");
+    } else {
+	verbose_print("No update of $jar required.");
+    }
+    1;
+}
+
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+This program is a part of javahelper and uses debhelper as backend. There are
+also tutorials in /usr/share/doc/javahelper.
+
+=head1 AUTHOR
+
+Niels Thykier <niels at thykier.net>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2010 by Niels Thykier
+
+This tool is free software; you may redistribute it and/or modify
+it under the terms of GNU GPL 2.
+
+=cut
 
diff --git a/jh_manifest.1 b/jh_manifest.1
deleted file mode 100644
index 09d7a77..0000000
--- a/jh_manifest.1
+++ /dev/null
@@ -1,35 +0,0 @@
-.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.36.
-.TH JAVAHELPER "1" "January 2008" "Javahelper Version 0.5" "User Commands"
-.SH NAME
-Javahelper \- Part of the Java Helper packaging tools
-Refer to the tutorials in /usr/share/doc/javahelper for more detail
-.SH SYNOPSIS
-.B jh_manifest
-[\fIoptions\fR] [\fI<jar> \fR...]
-.SH OPTIONS
-.HP
-\fB\-h\fR \fB\-\-help\fR: show this text
-.HP
-\fB\-v\fR \fB\-\-verbose\fR: show more information while running
-.HP
-\fB\-V\fR \fB\-\-version\fR: print the version
-.HP
-\fB\-n\fR \fB\-\-no\-act\fR: don't actually do anything, just print the results
-.SS "When reading manifest files for packages:"
-.HP
-\fB\-i\fR \fB\-\-indep\fR: run for all Arch: all packages
-.HP
-\fB\-a\fR \fB\-\-arch\fR: run for all Arch\-specific packages
-.HP
-\fB\-p\fR<package> \fB\-\-package=\fR<package>: package to act on (default=all)
-.HP
-\fB\-P\fR<packagedir> \fB\-\-tmpdir=\fR<package>: package directory (default=$CWD/debian/package)
-.SS "When acting on a jar from the command line:"
-.HP
-\fB\-c\fR<classpath> \fB\-\-classpath=\fR<classpath>: The classpath to set (space separated)
-.HP
-\fB\-j\fR</path/to/java/home> \fB\-\-java\-home=\fR</path/to/java/home>: The path to the JRE to use to execute the jar
-.HP
-\fB\-m\fR<class> \fB\-\-main=\fR<class>: The class to run when executing the jar
-.HP
-\fB\-o\fR<options> \fB\-\-javaopts=\fR<options>: Options passed to java when executing the jar
diff --git a/jh_setupenvironment b/jh_setupenvironment
index c56c5f3..ceba3d8 100755
--- a/jh_setupenvironment
+++ b/jh_setupenvironment
@@ -38,7 +38,7 @@ environment.
 
 =over 4
 
-=item B<--pde-build-dir=dir>
+=item B<--pde-build-dir=>I<dir>
 
 Specifies where the environment should be or is placed.
 
diff --git a/tests/tests.sh b/tests/tests.sh
index 40750f3..24bf6da 100755
--- a/tests/tests.sh
+++ b/tests/tests.sh
@@ -1,8 +1,16 @@
 #!/bin/bash --
 
 set -e
+_DIR=`pwd`
 . ../jh_lib.sh
 
+run_jh_manifest()
+{
+    cd ..
+    ./jh_manifest "$@"
+    cd "$_DIR"
+}
+
 # checkmanifest <source> <correct result> [parameters...]
 checkmanifest()
 {
@@ -13,7 +21,7 @@ checkmanifest()
 	shift
 	touch foo
 	jar cfm test.jar $source foo
-	../jh_manifest "$@" test.jar
+	run_jh_manifest "$@" "$_DIR/test.jar"
 	jar xf test.jar META-INF/MANIFEST.MF
 	if ! diff -u $verify META-INF/MANIFEST.MF > test.diff; then
 		error=1


hooks/post-receive
-- 
UNNAMED PROJECT



More information about the pkg-java-commits mailing list