pjs/config/make-jars.pl

122 строки
2.5 KiB
Perl
Исходник Обычный вид История

#!/perl
# make-jars [-d <destPath>] < <manifest.jr>
sub JarIt
{
my ($jarfile, $args) = @_;
system "zip -u $jarfile $args\n";
2000-07-28 08:46:45 +04:00
my $cwd = cwd();
print "+++ jarred $cwd => $jarfile\n";
}
sub MkDirs
{
my ($path) = @_;
if ($path =~ /([\w\d.\-]+)[\\\/](.*)/) {
my $dir = $1;
$path = $2;
if (!-e $dir) {
mkdir($dir, 0777) || die "error: can't create '$dir': $!";
}
chdir $dir;
MkDirs($path);
chdir "..";
}
else {
my $dir = $path;
2000-07-28 08:46:45 +04:00
if ($dir eq "") { return 0; }
if (!-e $dir) {
mkdir($dir, 0777) || die "error: can't create '$dir': $!";
}
}
}
sub CopyFile
{
my ($from, $to) = @_;
open(OUT, ">$to") || die "error: can't open '$to': $!";
open(IN, "<$from") || die "error: can't open '$from': $!";
while (<IN>) {
print OUT $_;
}
close(IN) || die "error: can't close '$from': $!";
close(OUT) || die "error: can't close '$to': $!";
}
sub EnsureFileInDir
{
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;
}
if (!-e $file) {
2000-07-11 10:40:09 +04:00
die "error: file '$file' doesn't exist\n";
}
MkDirs($dir);
CopyFile($file, $destPath);
return 1;
}
return 0;
}
use Getopt::Std;
2000-07-11 10:40:09 +04:00
getopt("d:o:");
my $destPath = ".";
if (defined($opt_d)) {
$destPath = $opt_d;
}
while (<>) {
chomp;
start:
if (/^([\w\d.\-\\\/]+)\:\s*$/) {
2000-07-11 10:40:09 +04:00
my $jarfile = "$destPath/$1";
my $args = "";
while (<>) {
2000-07-11 10:40:09 +04:00
if (/^\s+([\w\d.\-\\\/]+)\s*(\([\w\d.\-\\\/]+\))?$\s*/) {
my $dest = $1;
my $srcPath = $2;
if ( $srcPath ) {
$srcPath = substr($srcPath,1,-1);
}
EnsureFileInDir($dest, $srcPath);
2000-07-11 10:40:09 +04:00
$args = "$args$dest ";
} elsif (/^\s*$/) {
# end with blank line
last;
} else {
2000-07-21 02:28:01 +04:00
JarIt($jarfile, $args);
goto start;
}
}
JarIt($jarfile, $args);
} elsif (/^\s*\#.*$/) {
# skip comments
} elsif (/^\s*$/) {
# skip blank lines
} else {
close;
die "bad jar rule head at: $_";
}
}