michael@0: #! /usr/local/bin/perl michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: michael@0: require('coreconf.pl'); michael@0: michael@0: #######-- read in variables on command line into %var michael@0: michael@0: $use_jar = 1; michael@0: $ZIP = "$ENV{JAVA_HOME}/bin/jar"; michael@0: michael@0: if ( $ENV{JAVA_HOME} eq "" ) { michael@0: $ZIP = "zip"; michael@0: $use_jar = 0; michael@0: } michael@0: michael@0: michael@0: &parse_argv; michael@0: michael@0: michael@0: ######-- Do the packaging of jars. michael@0: michael@0: foreach $jarfile (split(/ /,$var{FILES}) ) { michael@0: print STDERR "---------------------------------------------\n"; michael@0: print STDERR "Packaging jar file $jarfile....\n"; michael@0: michael@0: $jarinfo = $var{$jarfile}; michael@0: michael@0: ($jardir,$jaropts) = split(/\|/,$jarinfo); michael@0: michael@0: if ( $use_jar ) { michael@0: $zipoptions = "-cvf"; michael@0: } else { michael@0: $zipoptions = "-T -r"; michael@0: if ($jaropts =~ /a/) { michael@0: if ($var{OS_ARCH} eq 'WINNT') { michael@0: $zipoptions .= ' -ll'; michael@0: } michael@0: } michael@0: } michael@0: michael@0: # just in case the directory ends in a /, remove it michael@0: if ($jardir =~ /\/$/) { michael@0: chop $jardir; michael@0: } michael@0: michael@0: $dirdepth --; michael@0: michael@0: print STDERR "jardir = $jardir\n"; michael@0: system("ls $jardir"); michael@0: michael@0: if (-d $jardir) { michael@0: michael@0: michael@0: # count the number of slashes michael@0: michael@0: $slashes =0; michael@0: michael@0: foreach $i (split(//,$jardir)) { michael@0: if ($i =~ /\//) { michael@0: $slashes++; michael@0: } michael@0: } michael@0: michael@0: $dotdots =0; michael@0: michael@0: foreach $i (split(m|/|,$jardir)) { michael@0: if ($i eq '..') { michael@0: $dotdots ++; michael@0: } michael@0: } michael@0: michael@0: $dirdepth = ($slashes +1) - (2*$dotdots); michael@0: michael@0: print STDERR "changing dir $jardir\n"; michael@0: chdir($jardir); michael@0: print STDERR "making dir META-INF\n"; michael@0: mkdir("META-INF",0755); michael@0: michael@0: $filelist = ""; michael@0: opendir(DIR,"."); michael@0: while ($_ = readdir(DIR)) { michael@0: if (! ( ($_ eq '.') || ($_ eq '..'))) { michael@0: if ( $jaropts =~ /i/) { michael@0: if (! /^include$/) { michael@0: $filelist .= "$_ "; michael@0: } michael@0: } michael@0: else { michael@0: $filelist .= "$_ "; michael@0: } michael@0: } michael@0: } michael@0: closedir(DIR); michael@0: michael@0: print STDERR "$ZIP $zipoptions $jarfile $filelist\n"; michael@0: system("$ZIP $zipoptions $jarfile $filelist"); michael@0: rmdir("META-INF"); michael@0: for $i (1 .. $dirdepth) { michael@0: chdir(".."); michael@0: print STDERR "chdir ..\n"; michael@0: } michael@0: } michael@0: else { michael@0: print STDERR "Directory $jardir doesn't exist\n"; michael@0: } michael@0: michael@0: } michael@0: