2000-09-19 00:54:48 +04:00
|
|
|
|
#!perl -w
|
2000-10-26 02:20:22 +04:00
|
|
|
|
package Moz::Jar;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Module for creating jar files, either using a jar manifest, or
|
|
|
|
|
# simply jarring up folders on disk.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
require 5.004;
|
|
|
|
|
require Exporter;
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
use Archive::Zip;
|
|
|
|
|
use File::Path;
|
|
|
|
|
|
|
|
|
|
use Mac::Files;
|
|
|
|
|
|
2000-10-26 02:20:22 +04:00
|
|
|
|
use Moz::Moz;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
use vars qw( @ISA @EXPORT );
|
|
|
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
2000-10-26 07:53:51 +04:00
|
|
|
|
@EXPORT = qw(
|
|
|
|
|
CreateJarFileFromDirectory
|
|
|
|
|
CreateJarFromManifest
|
|
|
|
|
WriteOutJarFiles
|
|
|
|
|
SanityCheckJarOptions
|
|
|
|
|
);
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# Add the contents of a directory to the zip file
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
sub _addDirToJar($$$$)
|
|
|
|
|
{
|
|
|
|
|
my($dir, $jar_root, $zip, $compress) = @_;
|
|
|
|
|
|
2000-10-24 22:21:47 +04:00
|
|
|
|
opendir(DIR, $dir) or die "Error: Cannot open dir $dir\n";
|
2000-09-19 00:54:48 +04:00
|
|
|
|
my @files = readdir(DIR);
|
|
|
|
|
closedir DIR;
|
|
|
|
|
|
|
|
|
|
my $unix_jar_root = $jar_root;
|
|
|
|
|
$unix_jar_root =~ s|:|/|g; # colon to slash conversion
|
|
|
|
|
|
|
|
|
|
my $file;
|
|
|
|
|
|
|
|
|
|
foreach $file (@files)
|
|
|
|
|
{
|
|
|
|
|
my $filepath = $dir.":".$file;
|
|
|
|
|
|
|
|
|
|
if (-d $filepath)
|
|
|
|
|
{
|
|
|
|
|
print "Adding files to jar from $filepath\n";
|
|
|
|
|
_addDirToJar($filepath, $jar_root, $zip, $compress);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
my $member = Archive::Zip::Member->newFromFile($filepath);
|
2000-10-24 22:21:47 +04:00
|
|
|
|
die "Error: Failed to create zip file member $filepath\n" unless $member;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
my $unixName = $filepath;
|
|
|
|
|
$unixName =~ s|:|/|g; # colon to slash conversion
|
|
|
|
|
$unixName =~ s|^$unix_jar_root||; # relativise
|
|
|
|
|
|
|
|
|
|
$member->fileName($unixName);
|
|
|
|
|
|
|
|
|
|
# print "Adding $file as $unixName\n";
|
|
|
|
|
|
|
|
|
|
if ($compress) {
|
|
|
|
|
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_DEFLATED);
|
|
|
|
|
} else {
|
|
|
|
|
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_STORED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$zip->addMember($member);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# Add the contents of a directory to the zip file
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
sub CreateJarFileFromDirectory($$$)
|
|
|
|
|
{
|
|
|
|
|
my($srcdir, $jarpath, $compress) = @_;
|
|
|
|
|
|
|
|
|
|
my $zip = Archive::Zip->new();
|
|
|
|
|
|
|
|
|
|
_addDirToJar($srcdir, $srcdir, $zip, $compress);
|
|
|
|
|
|
|
|
|
|
print "Saving zip file...\n";
|
|
|
|
|
my $status = $zip->writeToFileNamed($jarpath);
|
|
|
|
|
if ($status == 0) {
|
|
|
|
|
print "Zipping completed successfully\n";
|
|
|
|
|
} else {
|
|
|
|
|
print "Error saving zip file\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# set the file type/creator to something reasonable
|
|
|
|
|
MacPerl::SetFileInfo("ZIP ", "ZIP ", $jarpath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# printZipContents
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
sub printZipContents($)
|
|
|
|
|
{
|
|
|
|
|
my($zip) = @_;
|
|
|
|
|
|
|
|
|
|
my(@members) = $zip->memberNames();
|
|
|
|
|
|
|
|
|
|
print "Zip contains:\n";
|
|
|
|
|
|
|
|
|
|
my($member);
|
|
|
|
|
foreach $member (@members)
|
|
|
|
|
{
|
|
|
|
|
print " $member\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# safeSaveJarFile
|
|
|
|
|
#
|
|
|
|
|
# Archive::Zip has a problem where you cannot save a zip file on top of
|
|
|
|
|
# an existing zip file that it has open, because it holds references
|
|
|
|
|
# into that zip. So we have to save to a temp file, then do a swap.
|
|
|
|
|
#
|
|
|
|
|
# Note that the zip will become invalid after this operation.
|
|
|
|
|
# If you want to do further operations on it, you'll have to reread it.
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
sub safeSaveJarFile($$)
|
|
|
|
|
{
|
|
|
|
|
my($zip, $full_dest_path) = @_;
|
|
|
|
|
|
|
|
|
|
my($temp_file_name) = $full_dest_path."_temp";
|
|
|
|
|
|
2000-10-24 22:21:47 +04:00
|
|
|
|
($zip->writeToFileNamed($temp_file_name) == Archive::Zip::AZ_OK) || die "Error: died writing jar to temp file $temp_file_name\n";
|
2000-10-20 05:58:10 +04:00
|
|
|
|
|
|
|
|
|
unlink $full_dest_path;
|
|
|
|
|
|
2000-10-24 22:21:47 +04:00
|
|
|
|
(rename $temp_file_name, $full_dest_path) || die "Error: Failed to rename $temp_file_name\n";
|
2000-10-20 05:58:10 +04:00
|
|
|
|
|
|
|
|
|
MacPerl::SetFileInfo("ZIP ", "ZIP ", $full_dest_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-19 00:54:48 +04:00
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# addToJarFile
|
|
|
|
|
#
|
|
|
|
|
# Add a file to a jar file
|
|
|
|
|
#
|
|
|
|
|
# Parameters:
|
|
|
|
|
# 1. Jar ID. Unix path of jar file inside chrome.
|
|
|
|
|
# 2. Abs path to jar.mn file (i.e. source) (mac breaks)
|
|
|
|
|
# 3. File source, relative to jar.mn path (mac breaks)
|
|
|
|
|
# 4. Abs path to the resulting .jar file (mac breaks)
|
|
|
|
|
# 5. Relative file path within the jar (unix breaks)
|
|
|
|
|
# 6. Reference to hash of jar files
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
sub addToJarFile($$$$$$$)
|
2000-09-19 00:54:48 +04:00
|
|
|
|
{
|
2000-10-20 05:58:10 +04:00
|
|
|
|
my($jar_id, $jar_man_dir, $file_src, $jar_path, $file_jar_path, $override, $jars) = @_;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
# print "addToJarFile with:\n $jar_man_dir\n $file_src\n $jar_path\n $file_jar_path\n";
|
|
|
|
|
|
2000-10-24 22:21:47 +04:00
|
|
|
|
unless ($jar_path =~ m/(.+:)([^:]+)$/) { die "Error: Bad jar path $jar_path\n"; }
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
my($target_dir) = $1;
|
|
|
|
|
my($jar_name) = $2;
|
|
|
|
|
|
|
|
|
|
$target_dir =~ s/[^:]+$//;
|
|
|
|
|
|
|
|
|
|
# print "<22> $target_dir $jar_name\n";
|
|
|
|
|
|
|
|
|
|
# find the source file
|
|
|
|
|
my($src) = $jar_man_dir.":".$file_src;
|
|
|
|
|
if ((!-e $src) && ($file_src =~ m/.+:([^:]+)$/)) # src does not exist. Fall back to looking for src in jar.mn dir
|
|
|
|
|
{
|
|
|
|
|
$file_src = $1;
|
|
|
|
|
$src = $jar_man_dir.":".$file_src;
|
|
|
|
|
|
|
|
|
|
if (!-e $src) {
|
2000-10-24 22:21:47 +04:00
|
|
|
|
die "Error: Can't find chrome file $src\n";
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
if ($main::options{chrome_jars})
|
2000-09-19 00:54:48 +04:00
|
|
|
|
{
|
|
|
|
|
my($zip) = $jars->{$jar_id};
|
2000-10-24 22:21:47 +04:00
|
|
|
|
unless ($zip) { die "Error: Can't find Zip entry for $jar_id\n"; }
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
# print "Adding $file_src to jar file $jar_path at $file_jar_path\n";
|
|
|
|
|
my($member) = Archive::Zip::Member->newFromFile($src);
|
2000-10-24 22:21:47 +04:00
|
|
|
|
unless ($member) { die "Error: Failed to create zip file member $src\n"; }
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
$member->fileName($file_jar_path);
|
|
|
|
|
|
|
|
|
|
my($compress) = 1;
|
|
|
|
|
if ($compress) {
|
|
|
|
|
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_DEFLATED);
|
2000-10-20 05:58:10 +04:00
|
|
|
|
$member->desiredCompressionLevel(Archive::Zip::COMPRESSION_LEVEL_DEFAULT); # defaults to 6
|
2000-09-19 00:54:48 +04:00
|
|
|
|
} else {
|
|
|
|
|
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_STORED);
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
my($old_member) = $zip->memberNamed($file_jar_path);
|
|
|
|
|
|
|
|
|
|
if ($override)
|
|
|
|
|
{
|
|
|
|
|
if ($old_member)
|
|
|
|
|
{
|
|
|
|
|
# print "Overriding $file_jar_path in jar file $jar_id\n";
|
|
|
|
|
# need to compare mod dates or use the + here
|
|
|
|
|
$zip->removeMember($old_member);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$zip->addMember($member);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ($old_member)
|
|
|
|
|
{
|
|
|
|
|
#compare dates here
|
|
|
|
|
my($member_moddate) = $old_member->lastModTime();
|
|
|
|
|
my($file_moddate) = GetFileModDate($src);
|
|
|
|
|
|
|
|
|
|
if ($file_moddate > $member_moddate)
|
|
|
|
|
{
|
|
|
|
|
print "Updating older file $file_jar_path in $jar_id\n";
|
|
|
|
|
$zip->removeMember($old_member);
|
|
|
|
|
$zip->addMember($member);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
print "File $file_jar_path in $jar_id is more recent. Not updating.\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$zip->addMember($member);
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
2000-10-20 05:58:10 +04:00
|
|
|
|
|
|
|
|
|
if ($main::options{chrome_files}) # we install raw files too
|
2000-09-19 00:54:48 +04:00
|
|
|
|
{
|
|
|
|
|
my($rel_path) = $file_jar_path;
|
|
|
|
|
$rel_path =~ s|/|:|g; # slash to colons
|
|
|
|
|
|
|
|
|
|
my($dir_name) = $jar_name;
|
|
|
|
|
$dir_name =~ s/\.jar$//;
|
|
|
|
|
|
|
|
|
|
my($dst) = $target_dir.$dir_name.":".$rel_path;
|
|
|
|
|
|
|
|
|
|
# print "Aliassing $src\n to\n$dst\n";
|
2000-10-20 05:58:10 +04:00
|
|
|
|
if ($override)
|
|
|
|
|
{
|
|
|
|
|
unlink $dst;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
MakeAlias($src, $dst); # don't check errors, otherwise we fail on replacement
|
2000-10-20 05:58:10 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (-e $dst)
|
|
|
|
|
{
|
|
|
|
|
#compare dates here
|
|
|
|
|
my($dst_moddate) = GetFileModDate($dst);
|
|
|
|
|
my($file_moddate) = GetFileModDate($src);
|
|
|
|
|
|
|
|
|
|
if ($file_moddate > $dst_moddate)
|
|
|
|
|
{
|
|
|
|
|
print "Updating older file $rel_path in $dir_name\n";
|
|
|
|
|
unlink $dst;
|
|
|
|
|
MakeAlias($src, $dst);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
print "File $file_jar_path in $jar_id is more recent. Not updating.\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MakeAlias($src, $dst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# setupJarFile
|
|
|
|
|
#
|
|
|
|
|
# setup a zip for writing
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
sub setupJarFile($$$)
|
|
|
|
|
{
|
2000-10-20 05:58:10 +04:00
|
|
|
|
my($jar_id, $dest_path, $jar_hash) = @_;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
# print "Creating jar file $jar_id at $jar_path\n";
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
my($jar_file) = $jar_id;
|
|
|
|
|
$jar_file =~ s|/|:|g; # slash to colons
|
2000-10-26 07:53:51 +04:00
|
|
|
|
my($full_jar_path) = full_path_to($dest_path.":".$jar_file);
|
2000-10-20 05:58:10 +04:00
|
|
|
|
|
|
|
|
|
if ($main::options{chrome_jars})
|
2000-09-19 00:54:48 +04:00
|
|
|
|
{
|
|
|
|
|
my($zip) = $jar_hash->{$jar_id};
|
|
|
|
|
if (!$zip) # if we haven't made it already, do so
|
|
|
|
|
{
|
|
|
|
|
my($zip) = Archive::Zip->new();
|
|
|
|
|
$jar_hash->{$jar_id} = $zip;
|
2000-10-20 05:58:10 +04:00
|
|
|
|
|
|
|
|
|
# does the jar file exist already? If so, read it in
|
|
|
|
|
if (-e $full_jar_path)
|
|
|
|
|
{
|
|
|
|
|
print "Reading in jar file $jar_id\n";
|
2000-10-24 22:21:47 +04:00
|
|
|
|
if ($zip->read($full_jar_path) != Archive::Zip::AZ_OK) { die "Error: Failed to re-read $full_jar_path\n"; }
|
2000-10-20 05:58:10 +04:00
|
|
|
|
|
|
|
|
|
# printZipContents($zip);
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
# installing files.
|
|
|
|
|
# nothing to do. MakeAlias creates dirs as needed.
|
|
|
|
|
|
|
|
|
|
# add this jar to the list
|
|
|
|
|
$jar_hash->{$jar_id} = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# closeJarFile
|
|
|
|
|
#
|
|
|
|
|
# We're done with this jar file _for this jar.mn_. We may add more entries
|
|
|
|
|
# to it later, so keep it open in the hash.
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
sub closeJarFile($$)
|
|
|
|
|
{
|
|
|
|
|
my($jar_path, $jar_hash) = @_;
|
|
|
|
|
|
|
|
|
|
# print "Closing jar file $jar_path\n";
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
if ($main::options{chrome_jars})
|
2000-09-19 00:54:48 +04:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
# installing files.
|
|
|
|
|
# nothing to do
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# WriteOutJarFiles
|
|
|
|
|
#
|
|
|
|
|
# Now we dump out the jars
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
sub WriteOutJarFiles($$)
|
|
|
|
|
{
|
|
|
|
|
my($chrome_dir, $jars) = @_;
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
unless ($main::options{chrome_jars}) { return; }
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
2000-10-26 07:53:51 +04:00
|
|
|
|
my($full_chrome_path) = full_path_to($chrome_dir);
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
my($key);
|
|
|
|
|
foreach $key (keys %$jars)
|
|
|
|
|
{
|
|
|
|
|
my($zip) = $jars->{$key};
|
|
|
|
|
|
|
|
|
|
my($rel_path) = $key;
|
|
|
|
|
$rel_path =~ s/\//:/g;
|
|
|
|
|
|
|
|
|
|
my($output_path) = $full_chrome_path.":".$rel_path;
|
|
|
|
|
|
|
|
|
|
print "Writing zip file $key to $output_path\n";
|
|
|
|
|
|
|
|
|
|
# ensure the target dirs exist
|
|
|
|
|
my($path) = $output_path;
|
2000-10-20 05:58:10 +04:00
|
|
|
|
$path =~ s/[^:]+$//;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
mkpath($path);
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
# unlink $output_path; # remove any existing jar
|
|
|
|
|
safeSaveJarFile($zip, $output_path);
|
|
|
|
|
# $zip is invalid after this operation, so nuke it here
|
|
|
|
|
$jars->{$key} = 0;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# registerChromePackage
|
|
|
|
|
#
|
|
|
|
|
# Enter a chrome package into the installed-chrome.txt file
|
|
|
|
|
#-------------------------------------------------------------------------------
|
2000-10-20 05:58:10 +04:00
|
|
|
|
sub registerChromePackage($$$$$$)
|
2000-09-19 00:54:48 +04:00
|
|
|
|
{
|
2000-10-20 05:58:10 +04:00
|
|
|
|
my($jar_file, $file_path, $chrome_dir, $jar_hash, $chrome_type, $pkg_name) = @_;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
my($manifest_subdir) = $jar_file;
|
|
|
|
|
$manifest_subdir =~ s/:/\//g;
|
|
|
|
|
|
|
|
|
|
my($chrome_entry);
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
if ($main::options{use_jars}) {
|
|
|
|
|
$chrome_entry = "$chrome_type,install,url,jar:resource:/chrome/$manifest_subdir!/$chrome_type/$pkg_name";
|
2000-09-19 00:54:48 +04:00
|
|
|
|
} else {
|
2000-10-20 05:58:10 +04:00
|
|
|
|
$manifest_subdir =~ s/\.jar$//;
|
|
|
|
|
$chrome_entry = "$chrome_type,install,url,resource:/chrome/$manifest_subdir/$chrome_type/$pkg_name";
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
# print "Entering $chrome_entry in installed-chrome.txt\n";
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
# ensure chrome_dir exists
|
|
|
|
|
mkpath($chrome_dir);
|
|
|
|
|
|
|
|
|
|
my($inst_chrome) = ${chrome_dir}.":installed-chrome.txt";
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
if (open(CHROMEFILE, "<$inst_chrome")) {
|
|
|
|
|
while (<CHROMEFILE>) {
|
|
|
|
|
chomp;
|
|
|
|
|
if ($_ eq $chrome_entry) {
|
|
|
|
|
# $chrome_entry already appears in installed-chrome.txt file
|
|
|
|
|
# just update the mod date
|
|
|
|
|
my $now = time;
|
2000-10-24 22:21:47 +04:00
|
|
|
|
utime($now, $now, $inst_chrome) || die "Error: Couldn't touch $inst_chrome";
|
2000-10-20 05:58:10 +04:00
|
|
|
|
print "+++ updating chrome $inst_chrome\n+++\t\t$chrome_entry\n";
|
2000-10-24 22:21:47 +04:00
|
|
|
|
close(CHROMEFILE) || die "Error: can't close $inst_chrome: $!";
|
2000-10-20 05:58:10 +04:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-10-24 22:21:47 +04:00
|
|
|
|
close(CHROMEFILE) || die "Error: can't close $inst_chrome: $!";
|
2000-10-20 05:58:10 +04:00
|
|
|
|
}
|
2000-10-24 22:21:47 +04:00
|
|
|
|
open(CHROMEFILE, ">>${inst_chrome}") || die "Error: Failed to open $inst_chrome\n";
|
2000-10-20 05:58:10 +04:00
|
|
|
|
print(CHROMEFILE "${chrome_entry}\n");
|
2000-10-24 22:21:47 +04:00
|
|
|
|
close(CHROMEFILE) || die "Error: Failed to close $inst_chrome\n";
|
2000-10-20 05:58:10 +04:00
|
|
|
|
print "+++ adding chrome $inst_chrome\n+++\t\t$chrome_entry\n";
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
# Create or add to a jar file from a jar.mn file.
|
|
|
|
|
# Both arguments are relative to the mozilla root dir.
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
sub CreateJarFromManifest($$$)
|
|
|
|
|
{
|
|
|
|
|
my($jar_man_path, $dest_path, $jars) = @_;
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
if ($main::options{chrome_jars}) {
|
2000-09-19 00:54:48 +04:00
|
|
|
|
print "Jarring from $jar_man_path\n";
|
2000-10-20 05:58:10 +04:00
|
|
|
|
}
|
|
|
|
|
if ($main::options{chrome_files}) {
|
2000-09-19 00:54:48 +04:00
|
|
|
|
print "Installing files from $jar_man_path\n";
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-26 07:53:51 +04:00
|
|
|
|
$jar_man_path = full_path_to($jar_man_path);
|
|
|
|
|
$dest_path = full_path_to($dest_path);
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
# if the jars hash is empty, nuke installed-chrome.txt
|
|
|
|
|
if (! scalar(%$jars))
|
|
|
|
|
{
|
2000-10-20 05:58:10 +04:00
|
|
|
|
print "Nuking installed-chrome.txt\n";
|
2000-09-19 00:54:48 +04:00
|
|
|
|
my($installed_chrome) = $dest_path.":installed-chrome.txt";
|
|
|
|
|
# unlink $installed_chrome;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $jar_man_dir = "";
|
|
|
|
|
my $jar_man_file = "";
|
|
|
|
|
|
|
|
|
|
if ($jar_man_path =~ /(.+):([^:]+)$/)
|
|
|
|
|
{
|
|
|
|
|
$jar_man_dir = $1; # no trailing :
|
|
|
|
|
$jar_man_file = $2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Keep a hash of jar files, keyed on relative jar path (e.g. "packages/core.jar")
|
|
|
|
|
# Entries are open Archive::Zips (if zipping), and installed-chrome entries.
|
|
|
|
|
|
|
|
|
|
my($jar_id) = ""; # Current foo/bar.jar from jar.mn file
|
|
|
|
|
my($jar_file) = ""; # relative path to jar file (from $dest_path), with mac separators
|
|
|
|
|
my($full_jar_path);
|
|
|
|
|
|
2000-10-24 22:21:47 +04:00
|
|
|
|
open(FILE, "<$jar_man_path") || die "Error: could not open \"$jar_man_path\": $!";
|
2000-09-19 00:54:48 +04:00
|
|
|
|
while (<FILE>)
|
|
|
|
|
{
|
|
|
|
|
my($line) = $_;
|
|
|
|
|
chomp($line);
|
|
|
|
|
|
|
|
|
|
# print "$line\n";
|
|
|
|
|
|
|
|
|
|
if ($line =~ /^\s*\#.*$/) { # skip comments
|
|
|
|
|
next;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
if ($line =~/^([\w\d.\-\_\\\/]+)\:\s*$/) # line start jar file entries
|
2000-09-19 00:54:48 +04:00
|
|
|
|
{
|
|
|
|
|
$jar_id = $1;
|
|
|
|
|
$jar_file = $jar_id;
|
|
|
|
|
$jar_file =~ s|/|:|g; # slash to colons
|
|
|
|
|
$full_jar_path = $dest_path.":".$jar_file;
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
setupJarFile($jar_id, $dest_path, $jars);
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
}
|
2000-10-20 05:58:10 +04:00
|
|
|
|
elsif ($line =~ /^(\+?)\s+([\w\d.\-\_\\\/]+)\s*(\([\w\d.\-\_\\\/]+\))?$\s*/) # jar file entry
|
2000-09-19 00:54:48 +04:00
|
|
|
|
{
|
2000-10-20 05:58:10 +04:00
|
|
|
|
my($override) = ($1 eq "+");
|
|
|
|
|
my($file_dest) = $2;
|
|
|
|
|
my($file_src) = $3;
|
2000-09-19 00:54:48 +04:00
|
|
|
|
|
|
|
|
|
if ($file_src) {
|
|
|
|
|
$file_src = substr($file_src, 1, -1); #strip the ()
|
|
|
|
|
} else {
|
|
|
|
|
$file_src = $file_dest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$file_src =~ s|/|:|g;
|
|
|
|
|
|
|
|
|
|
if ($jar_file ne "") # if jar is open, add to jar
|
|
|
|
|
{
|
2000-10-20 05:58:10 +04:00
|
|
|
|
if ($file_dest =~ /([\w\d.\-\_]+)\/([\w\d.\-\_\\\/]+)contents.rdf/)
|
2000-09-19 00:54:48 +04:00
|
|
|
|
{
|
2000-10-20 05:58:10 +04:00
|
|
|
|
my $chrome_type = $1;
|
|
|
|
|
my $pkg_name = $2;
|
|
|
|
|
registerChromePackage($jar_file, $file_dest, $dest_path, $jars, $chrome_type, $pkg_name);
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-20 05:58:10 +04:00
|
|
|
|
addToJarFile($jar_id, $jar_man_dir, $file_src, $full_jar_path, $file_dest, $override, $jars);
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-10-24 22:21:47 +04:00
|
|
|
|
die "Error: bad jar.mn format at $line\n";
|
2000-09-19 00:54:48 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
elsif ($line =~ /^\s*$/ ) # blank line
|
|
|
|
|
{
|
|
|
|
|
if ($jar_file ne "") #if a jar file is open, close it
|
|
|
|
|
{
|
|
|
|
|
closeJarFile($full_jar_path, $jars);
|
|
|
|
|
|
|
|
|
|
$jar_file = "";
|
|
|
|
|
$full_jar_path = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(FILE);
|
|
|
|
|
|
|
|
|
|
if ($jar_file ne "") #if a jar file is open, close it
|
|
|
|
|
{
|
|
|
|
|
closeJarFile($full_jar_path, $jars);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|