[Libreoffice-commits] .: solenv/bin

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Sep 1 11:55:31 PDT 2012


 solenv/bin/modules/installer.pm              |    2 
 solenv/bin/modules/installer/scpzipfiles.pm  |   63 ++++++-----------------
 solenv/bin/modules/t/installer-scpzipfiles.t |   71 +++++++++++++++++++++++++++
 3 files changed, 88 insertions(+), 48 deletions(-)

New commits:
commit b08f8494e67bb433686853328df68f377c45e019
Author: Tim Retout <tim at retout.co.uk>
Date:   Wed Aug 22 18:41:10 2012 +0100

    installer: Second attempt at scpzipfiles interpolation functions.
    
    Call "replace_all_ziplistvariables_in_rtffile" with a hashref rather
    than arrayref.
    
    Also rewrite implementation of installer::scpzipfiles variable
    replacement functions, and add test case.  Note that unknown
    variables should be ignored rather than replaced with an empty string.
    
    Change-Id: Ic4548b9df8c50cbf2d3049052c637e859542a1e8

diff --git a/solenv/bin/modules/installer.pm b/solenv/bin/modules/installer.pm
index 656bfb9..d5d0be5 100644
--- a/solenv/bin/modules/installer.pm
+++ b/solenv/bin/modules/installer.pm
@@ -1634,7 +1634,7 @@ sub main {
                 {
                     my $licensefilesource = installer::windows::idtglobal::get_rtflicensefilesource($onelanguage, $includepatharrayref_lang);
                     my $licensefile = installer::files::read_file($licensefilesource);
-                    installer::scpzipfiles::replace_all_ziplistvariables_in_rtffile($licensefile, $allvariablesarrayref, $onelanguage, $loggingdir);
+                    installer::scpzipfiles::replace_all_ziplistvariables_in_rtffile($licensefile, $allvariableshashref);
                     my $controltablename = $languageidtdir . $installer::globals::separator . "Control.idt";
                     my $controltable = installer::files::read_file($controltablename);
                     installer::windows::idtglobal::add_licensefile_to_database($licensefile, $controltable);
diff --git a/solenv/bin/modules/installer/scpzipfiles.pm b/solenv/bin/modules/installer/scpzipfiles.pm
index cb0e640..b1dc8a5 100644
--- a/solenv/bin/modules/installer/scpzipfiles.pm
+++ b/solenv/bin/modules/installer/scpzipfiles.pm
@@ -33,66 +33,35 @@ use installer::logger;
 use installer::pathanalyzer;
 use installer::systemactions;
 
-########################################################################################
-# Replacing all zip list variables in setup script and files with flag scpzip_replace
-########################################################################################
+# Replacing all zip list variables.
+# Called for setup script as well as files with flag scpzip_replace.
 
 sub replace_all_ziplistvariables_in_file
 {
-    my ( $fileref, $variableshashref ) = @_;
+    my ( $fileref, $variablesref ) = @_;
 
-    for ( my $i = 0; $i <= $#{$fileref}; $i++ )
+    for my $line ( @{$fileref} )
     {
-        my $line = ${$fileref}[$i];
-
-        if ( $line =~ /^.*\$\{\w+\}.*$/ )   # only occurrence of ${abc}
-        {
-            my $key;
-
-            foreach $key (keys %{$variableshashref})
-            {
-                my $value = $variableshashref->{$key};
-                $key = '${' . $key . '}';
-                $line =~ s/\Q$key\E/$value/g;
-                ${$fileref}[$i] = $line;
-            }
-        }
+        # Avoid removing variables we do not recognise.
+        $line =~ s/\$\{(\w+)\}/defined $variablesref->{$1}
+                                     ? $variablesref->{$1}
+                                     : $&/eg;
     }
 }
 
-########################################################################################
-# Replacing all zip list variables in rtf files. In rtf files
-# the brackets are masked.
-########################################################################################
+# Replacing all zip list variables in rtf files.
 
 sub replace_all_ziplistvariables_in_rtffile
 {
-    my ( $fileref, $variablesref, $onelanguage, $loggingdir ) = @_;
+    my ( $fileref, $variablesref ) = @_;
 
-    for ( my $i = 0; $i <= $#{$fileref}; $i++ )
+    for my $line ( @{$fileref} )
     {
-        my $line = ${$fileref}[$i];
-
-        if ( $line =~ /^.*\$\\\{\w+\\\}.*$/ )   # only occurrence of $\{abc\}
-        {
-            for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
-            {
-                my $variableline = ${$variablesref}[$j];
-
-                my ($key, $value);
-
-                if ( $variableline =~ /^\s*([\w-]+?)\s+(.*?)\s*$/ )
-                {
-                    $key = $1;
-                    $value = $2;
-                    $key = '$\{' . $key . '\}';
-                }
-
-                $line =~ s/\Q$key\E/$value/g;
-
-                ${$fileref}[$i] = $line;
-            }
-        }
+        # In rtf files the braces are backslash-escaped.
+        # Avoid removing variables we do not recognise.
+        $line =~ s/\$\\\{(\w+)\\\}/defined $variablesref->{$1}
+                                         ? $variablesref->{$1}
+                                         : $&/eg;
     }
 }
 
diff --git a/solenv/bin/modules/t/installer-scpzipfiles.t b/solenv/bin/modules/t/installer-scpzipfiles.t
new file mode 100644
index 0000000..e523d57
--- /dev/null
+++ b/solenv/bin/modules/t/installer-scpzipfiles.t
@@ -0,0 +1,71 @@
+# Version: MPL 1.1 / GPLv3+ / LGPLv3+
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License or as specified alternatively below. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# Major Contributor(s):
+# [ Copyright (C) 2012 Tim Retout <tim at retout.co.uk> (initial developer) ]
+#
+# All Rights Reserved.
+#
+# For minor contributions see the git repository.
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+# instead of those above.
+
+use strict;
+use warnings;
+
+use lib '.';
+
+use Test::More;
+
+use installer::scpzipfiles;
+
+my $vars = { foo => "bar" };
+
+my %lines;
+my $i = 0;
+while (<DATA>) {
+	push @{ $lines{$i++ % 3} }, $_;
+}
+
+my @file1 = @{ $lines{0} };
+my @file2 = @{ $lines{0} };
+
+# FIXME - Some of the files acted on by these methods contain variables
+# of the form "${foo}" which are currently ignored - but if "foo" was ever
+# added to the product list variables, they would suddenly start to be
+# replaced.
+#
+# We ought to come up with a better escaping mechanism, and change those
+# files to use it...
+
+installer::scpzipfiles::replace_all_ziplistvariables_in_file(\@file1, $vars);
+installer::scpzipfiles::replace_all_ziplistvariables_in_rtffile(\@file2, $vars);
+
+is_deeply(\@file1, $lines{1}, 'replace_all_ziplistvariables_in_file works');
+is_deeply(\@file2, $lines{2}, 'replace_all_ziplistvariables_in_rtffile works');
+
+done_testing();
+
+__DATA__
+This is a test
+This is a test
+This is a test
+A test of ${foo} replacement ${foo} but not ${bar}.
+A test of bar replacement bar but not ${bar}.
+A test of ${foo} replacement ${foo} but not ${bar}.
+A test of RTF $\{foo\} replacement $\{foo\} but not $\{bar\} or ${bar}.
+A test of RTF $\{foo\} replacement $\{foo\} but not $\{bar\} or ${bar}.
+A test of RTF bar replacement bar but not $\{bar\} or ${bar}.


More information about the Libreoffice-commits mailing list