Skip to content

Commit

Permalink
Item2041: Keep release branch in sync with trunk - support gzipping .…
Browse files Browse the repository at this point in the history
…js and .css

git-svn-id: http://svn.foswiki.org/branches/Release01x00@5105 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelTempest authored and MichaelTempest committed Sep 22, 2009
1 parent dc92778 commit d558c9d
Showing 1 changed file with 88 additions and 33 deletions.
121 changes: 88 additions & 33 deletions BuildContrib/lib/Foswiki/Contrib/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ my @stageFilters = (
my @compressFilters = (
{ RE => qr/\.js$/, filter => 'build_js' },
{ RE => qr/\.css$/, filter => 'build_css' },
{ RE => qr/\.gz$/, filter => 'build_gz' },
);

my @tidyFilters = ( { RE => qr/\.pl$/ }, { RE => qr/\.pm$/ }, );
Expand Down Expand Up @@ -879,18 +880,17 @@ won't fail if a source or target isn't missing.

sub target_compress {
my $this = shift;
FILE:
foreach my $file ( @{ $this->{files} } ) {
my %file_ok;
foreach my $filter (@compressFilters) {
FILE:
foreach my $file ( @{ $this->{files} } ) {
next FILE if $file_ok{$file};

# Find files that match the build filter and try to update
# them
foreach my $filter (@compressFilters) {
if ( $file->{name} =~ /$filter->{RE}/ ) {
my $fn = $filter->{filter};
my $ok = $this->$fn( $this->{basedir} . '/' . $file->{name} );
if ($ok) {
next FILE;
}
$file_ok{$file} = $this->$fn( $this->{basedir} . '/' . $file->{name} );
}
}
}
Expand Down Expand Up @@ -1164,6 +1164,50 @@ sub build_css {

=begin TML
---++++ build_gz
Uses Compress::Zlib to gzip files
* xxx.yyy -> xxx.yyy.gz
=cut

sub build_gz {
my ( $this, $to ) = @_;

unless ( eval { require Compress::Zlib } ) {
print STDERR "Cannot gzip $to: $@\n";
return 0;
}

my $from = $to;
$from =~ s/\.gz$// or return 0;
return 0 unless -e $from;

open( IF, '<', $from ) || die $!;
local $/ = undef;
my $text = <IF>;
close(IF);

$text = Compress::Zlib::memGzip( $text );

unless ( $this->{-n} ) {
if ( open( IF, '<', $to ) ) {
binmode IF;
my $ot = <IF>;
close($ot);
return 1 if $text eq $ot; # no changes?
}
open( OF, '>', $to ) || die "$to: $!";
binmode OF;
print OF $text;
close(OF);
print STDERR "Generated $to from $from\n";
}
return 1;
}

=begin TML
---++++ filter_pm($from, $to)
Filters expanding SVN rev number with correct version from repository
Note: unlike subversion, this puts in the version number of the whole
Expand Down Expand Up @@ -1643,6 +1687,26 @@ sub target_upload {

my $to = $this->{project};

my $topicText;
local $/ = undef; # set to read to EOF
if ( open( IN_FILE, '<', $this->{basedir} . '/' . $to . '.txt' ) ) {
print "Basing new topic on "
. $this->{basedir} . '/'
. $to . '.txt' . "\n";
$topicText = <IN_FILE>;
close(IN_FILE);
}
else {
print STDERR 'Failed to open base topic: ' . $!;
$topicText = <<END;
Release $to
END
print "Basing new topic on some default text:\n$topicText\n";
}
my @attachments;
$topicText =~ s/%META:FILEATTACHMENT(.*)%/
push(@attachments, $1);''/ge;

while (1) {
print <<END;
Preparing to upload to:
Expand Down Expand Up @@ -1675,15 +1739,27 @@ END
$this->_saveConfig();
}

$this->build('release');
my $userAgent =
new Foswiki::Contrib::Build::UserAgent( $this->{UPLOADTARGETSCRIPT},
$this );
$userAgent->agent( 'ContribBuild/' . $VERSION . ' ' );
$userAgent->cookie_jar( {} );

my $topic = $this->_getTopicName();

# Ask for username and password
my ( $user, $pass ) = $this->getCredentials( $this->{UPLOADTARGETSCRIPT} );

# Ask what the user wants to upload
my $doUploadArchivesAndInstallers = ask( "Do you want to upload the archives and installers?", 1 );

my $doUploadAttachments = scalar(@attachments)
&& ask( "Do you want to upload the attachments?", 1 );

# No more questions after this point

$this->build('release');

$this->_login($userAgent, $user, $pass);

my $url =
Expand Down Expand Up @@ -1724,26 +1800,9 @@ END
$newform{TopicClassification} ||= $1 . 'Package';
}
}
local $/ = undef; # set to read to EOF
if ( open( IN_FILE, '<', $this->{basedir} . '/' . $to . '.txt' ) ) {
print "Basing new topic on "
. $this->{basedir} . '/'
. $to . '.txt' . "\n";
$newform{'text'} = <IN_FILE>;
close(IN_FILE);
}
else {
print STDERR 'Failed to open base topic: ' . $!;
$newform{'text'} = <<END;
Release $to
END
print "Basing new topic on some default text:\n$newform{text}\n";
}
$newform{text} = $topicText;

$this->_uploadTopic( $userAgent, $user, $pass, $topic, \%newform );
my @attachments;
$newform{text} =~ s/%META:FILEATTACHMENT(.*)%/
push(@attachments, $1);''/ge;

# Upload any 'Var*.txt' topics published by the extension
my $dataDir = $this->{basedir} . '/data/System';
Expand All @@ -1765,10 +1824,7 @@ END
# attachments to the topic on t.o. will still be there.
my %uploaded; # flag already uploaded

my $doupattachements = scalar(@attachments)
&& ask( "Do you want to upload the attachments?", 1 );

if ($doupattachements) {
if ($doUploadAttachments) {
foreach my $a (@attachments) {
$a =~ /name="([^"]*)"/;
my $name = $1;
Expand All @@ -1795,8 +1851,7 @@ END
}
}

my $doup = ask( "Do you want to upload the archives and installers?", 1 );
return unless $doup;
return unless $doUploadArchivesAndInstallers;

# Upload the standard files
foreach my $ext qw(.zip .tgz _installer .md5 .sha1) {
Expand Down Expand Up @@ -1902,7 +1957,7 @@ sub _uploadAttachment {
# send an edit request to get a validation key
my $response = $userAgent->get("$this->{UPLOADTARGETSCRIPT}/edit$this->{UPLOADTARGETSUFFIX}/$this->{UPLOADTARGETWEB}/$this->{project}");
unless ( $response->is_success ) {
die 'Failed to edit form '. $response->request->uri.
die 'Request to edit '.$this->{UPLOADTARGETWEB}.'/'.$this->{project}.' failed '. $response->request->uri.
' -- '. $response->status_line. "\n";
}
Expand Down

0 comments on commit d558c9d

Please sign in to comment.