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: print STDERR "import.pl\n"; michael@0: michael@0: require('coreconf.pl'); michael@0: michael@0: michael@0: $returncode =0; michael@0: michael@0: michael@0: #######-- read in variables on command line into %var michael@0: michael@0: $var{UNZIP} = "unzip -o"; michael@0: michael@0: &parse_argv; michael@0: michael@0: if (! ($var{IMPORTS} =~ /\w/)) { michael@0: print STDERR "nothing to import\n"; michael@0: } michael@0: michael@0: ######-- Do the import! michael@0: michael@0: foreach $import (split(/ /,$var{IMPORTS}) ) { michael@0: michael@0: print STDERR "\n\nIMPORTING .... $import\n-----------------------------\n"; michael@0: michael@0: michael@0: # if a specific version specified in IMPORT variable michael@0: # (if $import has a slash in it) michael@0: michael@0: if ($import =~ /\//) { michael@0: # $component=everything before the first slash of $import michael@0: michael@0: $import =~ m|^([^/]*)/|; michael@0: $component = $1; michael@0: michael@0: $import =~ m|^(.*)/([^/]*)$|; michael@0: michael@0: # $path=everything before the last slash of $import michael@0: $path = $1; michael@0: michael@0: # $version=everything after the last slash of $import michael@0: $version = $2; michael@0: michael@0: if ($var{VERSION} ne "current") { michael@0: $version = $var{VERSION}; michael@0: } michael@0: } michael@0: else { michael@0: $component = $import; michael@0: $path = $import; michael@0: $version = $var{VERSION}; michael@0: } michael@0: michael@0: $releasejardir = "$var{RELEASE_TREE}/$path"; michael@0: if ($version eq "current") { michael@0: print STDERR "Current version specified. Reading 'current' file ... \n"; michael@0: michael@0: open(CURRENT,"$releasejardir/current") || die "NO CURRENT FILE\n"; michael@0: $version = ; michael@0: $version =~ s/(\r?\n)*$//; # remove any trailing [CR/]LF's michael@0: close(CURRENT); michael@0: print STDERR "Using version $version\n"; michael@0: if ( $version eq "") { michael@0: die "Current version file empty. Stopping\n"; michael@0: } michael@0: } michael@0: michael@0: $releasejardir = "$releasejardir/$version"; michael@0: if ( ! -d $releasejardir) { michael@0: die "$releasejardir doesn't exist (Invalid Version?)\n"; michael@0: } michael@0: foreach $jarfile (split(/ /,$var{FILES})) { michael@0: michael@0: ($relpath,$distpath,$options) = split(/\|/, $var{$jarfile}); michael@0: michael@0: if ($var{'OVERRIDE_IMPORT_CHECK'} eq 'YES') { michael@0: $options =~ s/v//g; michael@0: } michael@0: michael@0: if ( $relpath ne "") { $releasejarpathname = "$releasejardir/$relpath";} michael@0: else { $releasejarpathname = $releasejardir; } michael@0: michael@0: # If a component doesn't have IDG versions, import the DBG ones michael@0: if( ! -e "$releasejarpathname/$jarfile" ) { michael@0: if( $relpath =~ /IDG\.OBJ$/ ) { michael@0: $relpath =~ s/IDG.OBJ/DBG.OBJ/; michael@0: $releasejarpathname = "$releasejardir/$relpath"; michael@0: } elsif( $relpath =~ /IDG\.OBJD$/ ) { michael@0: $relpath =~ s/IDG.OBJD/DBG.OBJD/; michael@0: $releasejarpathname = "$releasejardir/$relpath"; michael@0: } michael@0: } michael@0: michael@0: if (-e "$releasejarpathname/$jarfile") { michael@0: print STDERR "\nWorking on jarfile: $jarfile\n"; michael@0: michael@0: if ($distpath =~ m|/$|) { michael@0: $distpathname = "$distpath$component"; michael@0: } michael@0: else { michael@0: $distpathname = "$distpath"; michael@0: } michael@0: michael@0: michael@0: #the block below is used to determine whether or not the xp headers have michael@0: #already been imported for this component michael@0: michael@0: $doimport = 1; michael@0: if ($options =~ /v/) { # if we should check the imported version michael@0: print STDERR "Checking if version file exists $distpathname/version\n"; michael@0: if (-e "$distpathname/version") { michael@0: open( VFILE, "<$distpathname/version") || michael@0: die "Cannot open $distpathname/version for reading. Permissions?\n"; michael@0: $importversion = ; michael@0: close (VFILE); michael@0: $importversion =~ s/\r?\n$//; # Strip off any trailing CR/LF michael@0: if ($version eq $importversion) { michael@0: print STDERR "$distpathname version '$importversion' already imported. Skipping...\n"; michael@0: $doimport =0; michael@0: } michael@0: } michael@0: } michael@0: michael@0: if ($doimport == 1) { michael@0: if (! -d "$distpathname") { michael@0: &rec_mkdir("$distpathname"); michael@0: } michael@0: # delete the stuff in there already. michael@0: # (this should really be recursive delete.) michael@0: michael@0: if ($options =~ /v/) { michael@0: $remheader = "\nREMOVING files in '$distpathname/' :"; michael@0: opendir(DIR,"$distpathname") || michael@0: die ("Cannot read directory $distpathname\n"); michael@0: @filelist = readdir(DIR); michael@0: closedir(DIR); michael@0: foreach $file ( @filelist ) { michael@0: if (! ($file =~ m!/.?.$!) ) { michael@0: if (! (-d $file)) { michael@0: $file =~ m!([^/]*)$!; michael@0: print STDERR "$remheader $1"; michael@0: $remheader = " "; michael@0: unlink "$distpathname/$file"; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: print STDERR "\n\n"; michael@0: michael@0: print STDERR "\nExtracting jarfile '$jarfile' to local directory $distpathname/\n"; michael@0: michael@0: print STDERR "$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname\n"; michael@0: system("$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname"); michael@0: michael@0: $r = $?; michael@0: michael@0: if ($options =~ /v/) { michael@0: if ($r == 0) { michael@0: unlink ("$distpathname/version"); michael@0: if (open(VFILE,">$distpathname/version")) { michael@0: print VFILE "$version\n"; michael@0: close(VFILE); michael@0: } michael@0: } michael@0: else { michael@0: print STDERR "Could not create '$distpathname/version'. Permissions?\n"; michael@0: $returncode ++; michael@0: } michael@0: } michael@0: } # if (doimport) michael@0: } # if (-e releasejarpathname/jarfile) michael@0: } # foreach jarfile) michael@0: } # foreach IMPORT michael@0: michael@0: michael@0: michael@0: exit($returncode); michael@0: michael@0: michael@0: michael@0: michael@0: