[Libreoffice-commits] .: solenv/bin

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 22 14:31:46 PDT 2012


 solenv/bin/modules/installer.pm              |    2 
 solenv/bin/modules/installer/scpzipfiles.pm  |   50 +++------------------
 solenv/bin/modules/t/installer-scpzipfiles.t |   63 +++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 43 deletions(-)

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

    installer: Use hashref for replace_all_ziplistvariables_in_rtffile
    
    Also rewrite implementation of installer::scpzipfiles variable
    replacement functions, and add test case.
    
    Change-Id: Ic4548b9df8c50cbf2d3049052c637e859542a1e8

diff --git a/solenv/bin/modules/installer.pm b/solenv/bin/modules/installer.pm
index 24e0c4e..ceafede 100644
--- a/solenv/bin/modules/installer.pm
+++ b/solenv/bin/modules/installer.pm
@@ -1644,7 +1644,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..70283f2 100644
--- a/solenv/bin/modules/installer/scpzipfiles.pm
+++ b/solenv/bin/modules/installer/scpzipfiles.pm
@@ -39,60 +39,26 @@ use installer::systemactions;
 
 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;
-            }
-        }
+        $line =~ s/\$\{(\w+)\}/$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.
+        $line =~ s/\$\\\{(\w+)\\\}/$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..e98bfd0
--- /dev/null
+++ b/solenv/bin/modules/t/installer-scpzipfiles.t
@@ -0,0 +1,63 @@
+# 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} };
+
+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}.
+A test of bar replacement bar.
+A test of ${foo} replacement ${foo}.
+A test of RTF $\{foo\} replacement $\{foo\}.
+A test of RTF $\{foo\} replacement $\{foo\}.
+A test of RTF bar replacement bar.


More information about the Libreoffice-commits mailing list