2000-07-24 21:47:51 +00:00
|
|
|
#!perl -w
|
|
|
|
# make-jars [-d <destPath>] < <manifest.jr>
|
|
|
|
|
|
|
|
package MozJar;
|
|
|
|
|
|
|
|
require 5.004;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Cwd;
|
|
|
|
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
|
|
|
|
use Moz;
|
|
|
|
|
|
|
|
use vars qw( @ISA @EXPORT );
|
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
|
|
|
@EXPORT = qw(ProcessJarManifest);
|
|
|
|
|
2000-08-26 04:36:57 +00:00
|
|
|
sub _addToJar($$$$$)
|
2000-07-24 21:47:51 +00:00
|
|
|
{
|
2000-08-26 04:36:57 +00:00
|
|
|
my($thing, $srcPath, $jarManDir, $zip, $compress) = @_;
|
|
|
|
#print "_addToJar($thing, $srcPath, $jarManDir, $zip, $compress)\n";
|
2000-07-24 21:47:51 +00:00
|
|
|
|
2000-08-26 04:36:57 +00:00
|
|
|
my $existingMember = $zip->memberNamed($thing);
|
|
|
|
if ($existingMember) {
|
|
|
|
my $modtime = $existingMember->lastModTime();
|
|
|
|
print "already have $thing at $modtime\n"; # XXX need to check mod time here!
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $filepath = "$jarManDir:$srcPath";
|
2000-07-24 21:47:51 +00:00
|
|
|
$filepath =~ s|/|:|g;
|
2000-08-26 04:36:57 +00:00
|
|
|
|
|
|
|
if (!-e $filepath) {
|
|
|
|
$srcPath =~ /([\w\d.:\-\\\/]+)[:\\\/]([\w\d.\-]+)/;
|
|
|
|
$filepath = "$jarManDir:$2";
|
|
|
|
if (!-e $filepath) {
|
|
|
|
die "$filepath does not exist\n";
|
|
|
|
}
|
2000-07-24 21:47:51 +00:00
|
|
|
}
|
2000-08-26 04:36:57 +00:00
|
|
|
|
|
|
|
my $member = Archive::Zip::Member->newFromFile($filepath);
|
|
|
|
die "Failed to create zip file member $filepath\n" unless $member;
|
2000-07-24 21:47:51 +00:00
|
|
|
|
2000-08-26 04:36:57 +00:00
|
|
|
$member->fileName($thing);
|
2000-07-24 21:47:51 +00:00
|
|
|
|
2000-08-26 04:36:57 +00:00
|
|
|
print "Adding $filepath as $thing\n";
|
2000-07-24 21:47:51 +00:00
|
|
|
|
2000-08-26 04:36:57 +00:00
|
|
|
if ($compress) {
|
|
|
|
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_DEFLATED);
|
|
|
|
} else {
|
|
|
|
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_STORED);
|
2000-07-24 21:47:51 +00:00
|
|
|
}
|
2000-08-26 04:36:57 +00:00
|
|
|
|
|
|
|
$zip->addMember($member);
|
2000-07-24 21:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub JarIt($$)
|
|
|
|
{
|
|
|
|
my ($jarfile, $zip) = @_;
|
2000-07-28 09:28:10 +00:00
|
|
|
#print "+++ jarring $jarfile\n";
|
2000-07-24 21:47:51 +00:00
|
|
|
#flush();
|
|
|
|
#system "zip -u $jarfile $args\n";
|
|
|
|
my $jarTempFile = $jarfile . ".temp";
|
|
|
|
$zip->writeToFileNamed($jarTempFile) == AZ_OK
|
|
|
|
|| die "zip writeToFileNamed $jarTempFile failed";
|
|
|
|
|
|
|
|
# set the file type/creator to something reasonable
|
|
|
|
MacPerl::SetFileInfo("ZIP ", "ZIP ", $jarTempFile);
|
|
|
|
rename($jarTempFile, $jarfile);
|
2000-07-28 09:28:10 +00:00
|
|
|
print "+++ finished jarring $jarfile\n";
|
2000-07-24 21:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub ProcessJarManifest($$)
|
|
|
|
{
|
|
|
|
my ($jarManPath, $destPath) = @_;
|
|
|
|
|
|
|
|
$jarManPath = Moz::full_path_to($jarManPath);
|
|
|
|
$destPath = Moz::full_path_to($destPath);
|
|
|
|
#print "ProcessJarManifest($jarManPath, $destPath)\n";
|
|
|
|
|
2000-07-28 09:28:10 +00:00
|
|
|
print "+++ jarring $jarManPath\n";
|
2000-07-24 21:47:51 +00:00
|
|
|
|
|
|
|
my $jarManDir = "";
|
|
|
|
my $jarManFile = "";
|
|
|
|
if ($jarManPath =~ /([\w\d.:\-\\\/]+)[:\\\/]([\w\d.\-]+)/) {
|
|
|
|
$jarManDir = $1;
|
|
|
|
$jarManFile = $2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die "bad jar.mn specification";
|
|
|
|
}
|
|
|
|
|
|
|
|
open(FILE, "<$jarManPath") || die "could not open $jarManPath: $!";
|
|
|
|
while (<FILE>) {
|
|
|
|
chomp;
|
|
|
|
start:
|
|
|
|
if (/^([\w\d.\-\\\/]+)\:\s*$/) {
|
|
|
|
my $jarfile = "$destPath/$1";
|
|
|
|
$jarfile =~ s|/|:|g;
|
|
|
|
#my $args = "";
|
|
|
|
|
|
|
|
my $zip = Archive::Zip->new();
|
|
|
|
#print "new jar $jarfile\n";
|
|
|
|
if (-e $jarfile) {
|
2000-07-28 09:28:10 +00:00
|
|
|
#print "=====> $jarfile exists\n";
|
2000-07-24 21:47:51 +00:00
|
|
|
my $ok = $zip->read($jarfile);
|
|
|
|
if ($ok != AZ_OK) {
|
|
|
|
die "zip read $jarfile failed: $ok";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (<FILE>) {
|
|
|
|
if (/^\s+([\w\d.\-\\\/]+)\s*(\([\w\d.\-\\\/]+\))?$\s*/) {
|
|
|
|
my $dest = $1;
|
|
|
|
my $srcPath = $2;
|
|
|
|
if ( $srcPath ) {
|
|
|
|
$srcPath = substr($srcPath,1,-1);
|
|
|
|
}
|
2000-08-26 04:36:57 +00:00
|
|
|
else {
|
|
|
|
$srcPath = ":" . $dest;
|
|
|
|
}
|
|
|
|
$srcPath =~ s|/|:|g;
|
2000-07-24 21:47:51 +00:00
|
|
|
|
2000-08-26 04:36:57 +00:00
|
|
|
_addToJar($dest, $srcPath, $jarManDir, $zip, 1);
|
2000-07-24 21:47:51 +00:00
|
|
|
} elsif (/^\s*$/) {
|
|
|
|
# end with blank line
|
|
|
|
last;
|
|
|
|
} else {
|
|
|
|
JarIt($jarfile, $zip);
|
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JarIt($jarfile, $zip);
|
|
|
|
|
|
|
|
} elsif (/^\s*\#.*$/) {
|
|
|
|
# skip comments
|
|
|
|
} elsif (/^\s*$/) {
|
|
|
|
# skip blank lines
|
|
|
|
} else {
|
|
|
|
close;
|
|
|
|
die "bad jar rule head at: $_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(FILE);
|
|
|
|
}
|
|
|
|
|