2000-06-09 10:33:25 +04:00
|
|
|
#!/perl
|
|
|
|
|
2000-08-05 00:25:42 +04:00
|
|
|
# make-jars [-d <destPath>] < <jar.mn>
|
2000-06-09 10:33:25 +04:00
|
|
|
|
2000-07-28 09:08:08 +04:00
|
|
|
use Getopt::Std;
|
|
|
|
use Cwd;
|
2000-08-11 09:16:15 +04:00
|
|
|
use File::stat;
|
|
|
|
use Time::localtime;
|
2000-07-28 09:08:08 +04:00
|
|
|
|
2000-08-11 09:16:15 +04:00
|
|
|
@cleanupList = ();
|
|
|
|
$IS_DIR = 1;
|
|
|
|
$IS_FILE = 2;
|
2000-08-05 00:25:42 +04:00
|
|
|
|
2000-08-11 09:16:15 +04:00
|
|
|
sub Cleanup
|
2000-08-04 00:58:31 +04:00
|
|
|
{
|
2000-08-11 09:16:15 +04:00
|
|
|
while (true) {
|
|
|
|
my $isDir = pop(@cleanupList);
|
|
|
|
if ($isDir == undef) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
my $path = pop(@cleanupList);
|
|
|
|
if ($isDir == $IS_DIR) {
|
|
|
|
rmdir($path) || die "can't remove dir $path: $!";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unlink($path) || die "can't remove file $path: $!";
|
|
|
|
}
|
2000-08-04 00:58:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
sub JarIt
|
|
|
|
{
|
2000-07-19 05:38:09 +04:00
|
|
|
my ($jarfile, $args) = @_;
|
2000-09-09 09:46:29 +04:00
|
|
|
system "zip -u $jarfile $args\n" || die "zip failed";
|
2000-07-28 08:46:45 +04:00
|
|
|
my $cwd = cwd();
|
|
|
|
print "+++ jarred $cwd => $jarfile\n";
|
2000-08-11 09:16:15 +04:00
|
|
|
Cleanup();
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub MkDirs
|
|
|
|
{
|
2000-08-11 09:16:15 +04:00
|
|
|
my ($path, $containingDir) = @_;
|
|
|
|
#print "MkDirs $path $containingDir\n";
|
2000-06-09 10:33:25 +04:00
|
|
|
if ($path =~ /([\w\d.\-]+)[\\\/](.*)/) {
|
|
|
|
my $dir = $1;
|
|
|
|
$path = $2;
|
|
|
|
if (!-e $dir) {
|
2000-08-11 09:16:15 +04:00
|
|
|
#print "making dir $containingDir/$dir\n";
|
2000-06-09 10:33:25 +04:00
|
|
|
mkdir($dir, 0777) || die "error: can't create '$dir': $!";
|
2000-08-11 09:16:15 +04:00
|
|
|
push(@cleanupList, "$containingDir/$dir");
|
|
|
|
push(@cleanupList, $IS_DIR);
|
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
chdir $dir;
|
2000-08-11 09:16:15 +04:00
|
|
|
MkDirs($path, "$containingDir/$dir");
|
2000-06-09 10:33:25 +04:00
|
|
|
chdir "..";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my $dir = $path;
|
2000-08-11 09:16:15 +04:00
|
|
|
if ($dir eq "") { return 0; }
|
2000-06-09 10:33:25 +04:00
|
|
|
if (!-e $dir) {
|
2000-08-11 09:16:15 +04:00
|
|
|
#print "making dir $containingDir/$dir\n";
|
2000-06-09 10:33:25 +04:00
|
|
|
mkdir($dir, 0777) || die "error: can't create '$dir': $!";
|
2000-08-11 09:16:15 +04:00
|
|
|
push(@cleanupList, "$containingDir/$dir");
|
|
|
|
push(@cleanupList, $IS_DIR);
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub CopyFile
|
|
|
|
{
|
|
|
|
my ($from, $to) = @_;
|
2000-08-11 09:16:15 +04:00
|
|
|
#print "copying $from to $to\n";
|
2000-06-09 10:33:25 +04:00
|
|
|
open(OUT, ">$to") || die "error: can't open '$to': $!";
|
|
|
|
open(IN, "<$from") || die "error: can't open '$from': $!";
|
2000-08-25 08:38:43 +04:00
|
|
|
binmode IN;
|
|
|
|
binmode OUT;
|
|
|
|
my $len;
|
|
|
|
my $buf;
|
|
|
|
while ($len = sysread(IN, $buf, 4096)) {
|
|
|
|
if (!defined $len) {
|
|
|
|
next if $! =~ /^Interrupted/;
|
|
|
|
die "System read error: $!\n";
|
|
|
|
}
|
|
|
|
my $offset = 0;
|
|
|
|
while ($len) {
|
|
|
|
my $written = syswrite(OUT, $buf, $len, $offset);
|
|
|
|
die "System write error: $!\n" unless defined $written;
|
|
|
|
$len -= $written;
|
|
|
|
$offset += $written;
|
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
|
|
|
close(IN) || die "error: can't close '$from': $!";
|
|
|
|
close(OUT) || die "error: can't close '$to': $!";
|
2000-08-11 09:16:15 +04:00
|
|
|
|
|
|
|
# fix the mod date so we don't jar everything (is this faster than just jarring everything?)
|
|
|
|
my $atime = stat($from)->atime || die $!;
|
|
|
|
my $mtime = stat($from)->mtime || die $!;
|
|
|
|
utime($atime, $mtime, $to);
|
|
|
|
|
|
|
|
push(@cleanupList, "$to");
|
|
|
|
push(@cleanupList, $IS_FILE);
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub EnsureFileInDir
|
|
|
|
{
|
2000-07-19 05:38:09 +04:00
|
|
|
my ($destPath, $srcPath) = @_;
|
2000-07-11 10:40:09 +04:00
|
|
|
|
|
|
|
if (!-e $destPath) {
|
2000-07-12 11:50:37 +04:00
|
|
|
my $dir = "";
|
|
|
|
my $file;
|
|
|
|
if ($destPath =~ /([\w\d.\-\\\/]+)[\\\/]([\w\d.\-]+)/) {
|
|
|
|
$dir = $1;
|
|
|
|
$file = $2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$file = $destPath;
|
|
|
|
}
|
2000-07-11 10:40:09 +04:00
|
|
|
|
|
|
|
if ($srcPath) {
|
|
|
|
$file = $srcPath;
|
|
|
|
}
|
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
if (!-e $file) {
|
2000-07-11 10:40:09 +04:00
|
|
|
die "error: file '$file' doesn't exist\n";
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
2000-08-11 09:16:15 +04:00
|
|
|
MkDirs($dir, ".");
|
2000-07-19 05:38:09 +04:00
|
|
|
CopyFile($file, $destPath);
|
2000-06-09 10:33:25 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-08-04 00:58:31 +04:00
|
|
|
getopt("d:");
|
2000-06-09 10:33:25 +04:00
|
|
|
|
|
|
|
my $destPath = ".";
|
|
|
|
if (defined($opt_d)) {
|
|
|
|
$destPath = $opt_d;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (<>) {
|
|
|
|
chomp;
|
|
|
|
start:
|
|
|
|
if (/^([\w\d.\-\\\/]+)\:\s*$/) {
|
2000-09-09 09:46:29 +04:00
|
|
|
my $jarfileDest = $1;
|
|
|
|
my $jarfile = "$destPath/$jarfileDest";
|
|
|
|
$jarfileDest =~ s/[^\/]+$//;
|
|
|
|
if ( ! -e "$destPath/$jarfileDest" ) {
|
|
|
|
my $currentDir = cwd();
|
|
|
|
chdir($destPath);
|
|
|
|
MkDirs($jarfileDest,".");
|
|
|
|
chdir($currentDir);
|
|
|
|
@cleanupList = ();
|
|
|
|
}
|
2000-07-11 10:40:09 +04:00
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
my $args = "";
|
|
|
|
while (<>) {
|
2000-07-11 10:40:09 +04:00
|
|
|
if (/^\s+([\w\d.\-\\\/]+)\s*(\([\w\d.\-\\\/]+\))?$\s*/) {
|
2000-08-04 00:58:31 +04:00
|
|
|
my $dest = $1;
|
2000-07-11 10:40:09 +04:00
|
|
|
my $srcPath = $2;
|
|
|
|
|
|
|
|
if ( $srcPath ) {
|
|
|
|
$srcPath = substr($srcPath,1,-1);
|
|
|
|
}
|
|
|
|
|
2000-07-19 05:38:09 +04:00
|
|
|
EnsureFileInDir($dest, $srcPath);
|
2000-07-11 10:40:09 +04:00
|
|
|
$args = "$args$dest ";
|
2000-06-09 10:33:25 +04:00
|
|
|
} elsif (/^\s*$/) {
|
|
|
|
# end with blank line
|
|
|
|
last;
|
|
|
|
} else {
|
2000-08-11 09:16:15 +04:00
|
|
|
JarIt($jarfile, $args);
|
2000-06-09 10:33:25 +04:00
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
}
|
2000-07-19 05:38:09 +04:00
|
|
|
JarIt($jarfile, $args);
|
2000-08-11 09:16:15 +04:00
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
} elsif (/^\s*\#.*$/) {
|
|
|
|
# skip comments
|
|
|
|
} elsif (/^\s*$/) {
|
|
|
|
# skip blank lines
|
|
|
|
} else {
|
|
|
|
close;
|
|
|
|
die "bad jar rule head at: $_";
|
|
|
|
}
|
2000-08-11 09:16:15 +04:00
|
|
|
}
|