solenv/bin/modules/installer.pm | 72 ----------------------------- solenv/bin/modules/installer/profiles.pm | 45 +++++++----------- solenv/bin/modules/installer/ziplist.pm | 73 ++++++++++++++++++++++++++++++ solenv/bin/modules/t/installer-profiles.t | 60 ++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 96 deletions(-)
New commits: commit 5cc1d5ca954a594129bd81159a87f8dfb9bbffe7 Author: Tim Retout <t...@retout.co.uk> Date: Sun Sep 30 13:23:43 2012 +0100 installer::profiles: Test and rewrite sorting_profile Change-Id: Ie3c9bddcb4760d2fe2195c1ca0de7520e57d705f diff --git a/solenv/bin/modules/installer/profiles.pm b/solenv/bin/modules/installer/profiles.pm index 7b621f7..3b99973 100644 --- a/solenv/bin/modules/installer/profiles.pm +++ b/solenv/bin/modules/installer/profiles.pm @@ -42,40 +42,33 @@ use installer::systemactions; # Sorting the content of a profile ####################################################### -sub sorting_profile -{ +sub sorting_profile { my ($profilesref) = @_; - my @profile = (); - my @definedsections = (); + my @sections; + my %section_content; - for ( my $i = 0; $i <= $#{$profilesref}; $i++ ) - { + for ( my $i = 0; $i < @{$profilesref}; $i++ ) { my $line = ${$profilesref}[$i]; - if ( $line =~ /^\s*(\[.*\])\s*$/ ) # this is a section (every second line) - { - my $section = $1; + # Skip unless this is a section (every second line) + next unless ( $line =~ /^\s*(\[.*\])\s*$/ ); - if (! grep {$_ eq $section} @definedsections) - { - my $sectionline = $section . "\n"; - push(@definedsections, $section); - push(@profile, $sectionline); + my $section = $1; + my $next_line = ${$profilesref}[$i+1]; - for ( my $j = 0; $j <= $#{$profilesref}; $j++ ) - { - my $oneline = ${$profilesref}[$j]; - installer::remover::remove_leading_and_ending_whitespaces(\$oneline); - - if ( $oneline eq $section ) - { - my $nextline = ${$profilesref}[$j+1]; - push(@profile, $nextline); - } - } - } + if ( ! exists $section_content{$section} ) { + push @sections, $section; } + + push @{ $section_content{$section} }, $next_line; + } + + my @profile; + + for my $section (@sections) { + push @profile, "$section\n"; + push @profile, @{ $section_content{$section} }; } return \@profile; diff --git a/solenv/bin/modules/t/installer-profiles.t b/solenv/bin/modules/t/installer-profiles.t new file mode 100644 index 0000000..841af14 --- /dev/null +++ b/solenv/bin/modules/t/installer-profiles.t @@ -0,0 +1,60 @@ +# 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 <t...@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 Test::More; + +use lib '.'; + +use installer::profiles; + +my @input = map { "$_\n" } split "\n", <<'END'; + [foo] +1 +NOT SEEN + [bar] +3 + [foo] +2 +[bar] +4 +END + +my @expected = map { "$_\n" } split "\n", <<'END'; +[foo] +1 +2 +[bar] +3 +4 +END + +my $result = installer::profiles::sorting_profile(\@input); + +is_deeply($result, \@expected); + +done_testing(); commit 665785c073f695922603854a9d2d5ecab4061ff0 Author: Tim Retout <t...@retout.co.uk> Date: Sun Sep 30 13:15:23 2012 +0100 installer: Create new read_ziplist function. Change-Id: Ie91376bf9c52238febdc15720bb7f4cd62ee2e08 diff --git a/solenv/bin/modules/installer.pm b/solenv/bin/modules/installer.pm index 54b64b0..4c50d3b 100644 --- a/solenv/bin/modules/installer.pm +++ b/solenv/bin/modules/installer.pm @@ -82,7 +82,7 @@ use installer::windows::strip; use installer::windows::update; use installer::windows::upgrade; use installer::worker; -use installer::ziplist; +use installer::ziplist qw(read_ziplist); our @EXPORT_OK = qw(main); @@ -163,75 +163,7 @@ sub run { # Analyzing the settings and variables in zip.lst ################################################### - installer::logger::globallog("zip list file: $installer::globals::ziplistname"); - - my $ziplistref = installer::files::read_file($installer::globals::ziplistname); - - installer::logger::print_message( "... analyzing $installer::globals::ziplistname ... \n" ); - - my ($productblockref, $parent) = installer::ziplist::getproductblock($ziplistref, $installer::globals::product, 1); # product block from zip.lst - - my ($settingsblockref, undef) = installer::ziplist::getproductblock($productblockref, "Settings", 0); # settings block from zip.lst - - $settingsblockref = installer::ziplist::analyze_settings_block($settingsblockref); # select data from settings block in zip.lst - - my $allsettingsarrayref = installer::ziplist::get_settings_from_ziplist($settingsblockref); - - my $allvariablesarrayref = installer::ziplist::get_variables_from_ziplist($settingsblockref); - - my ($globalproductblockref, undef) = installer::ziplist::getproductblock($ziplistref, $installer::globals::globalblock, 0); # global product block from zip.lst - - while (defined $parent) - { - my $parentproductblockref; - ($parentproductblockref, $parent) = installer::ziplist::getproductblock( - $ziplistref, $parent, 1); - my ($parentsettingsblockref, undef) = installer::ziplist::getproductblock( - $parentproductblockref, "Settings", 0); - $parentsettingsblockref = installer::ziplist::analyze_settings_block( - $parentsettingsblockref); - my $allparentsettingsarrayref = - installer::ziplist::get_settings_from_ziplist($parentsettingsblockref); - my $allparentvariablesarrayref = - installer::ziplist::get_variables_from_ziplist($parentsettingsblockref); - $allsettingsarrayref = - installer::converter::combine_arrays_from_references_first_win( - $allsettingsarrayref, $allparentsettingsarrayref) - if $#{$allparentsettingsarrayref} > -1; - $allvariablesarrayref = - installer::converter::combine_arrays_from_references_first_win( - $allvariablesarrayref, $allparentvariablesarrayref) - if $#{$allparentvariablesarrayref} > -1; - } - - if ( $#{$globalproductblockref} > -1 ) - { - my ($globalsettingsblockref, undef) = installer::ziplist::getproductblock($globalproductblockref, "Settings", 0); # settings block from zip.lst - - $globalsettingsblockref = installer::ziplist::analyze_settings_block($globalsettingsblockref); # select data from settings block in zip.lst - - my $allglobalsettingsarrayref = installer::ziplist::get_settings_from_ziplist($globalsettingsblockref); - - my $allglobalvariablesarrayref = installer::ziplist::get_variables_from_ziplist($globalsettingsblockref); - - if ( $#{$allglobalsettingsarrayref} > -1 ) { $allsettingsarrayref = installer::converter::combine_arrays_from_references_first_win($allsettingsarrayref, $allglobalsettingsarrayref); } - if ( $#{$allglobalvariablesarrayref} > -1 ) { $allvariablesarrayref = installer::converter::combine_arrays_from_references_first_win($allvariablesarrayref, $allglobalvariablesarrayref); } - } - - $allsettingsarrayref = installer::ziplist::remove_multiples_from_ziplist($allsettingsarrayref); # the settings from the zip.lst - - $allvariablesarrayref = installer::ziplist::remove_multiples_from_ziplist($allvariablesarrayref); - - installer::ziplist::replace_variables_in_ziplist_variables($allvariablesarrayref); - - my $allvariableshashref = installer::converter::convert_array_to_hash($allvariablesarrayref); # the variables from the zip.lst - - installer::ziplist::set_default_productversion_if_required($allvariableshashref); - - installer::ziplist::add_variables_to_allvariableshashref($allvariableshashref); - - installer::ziplist::overwrite_branding( $allvariableshashref ); - + my ($allsettingsarrayref, $allvariableshashref) = read_ziplist($installer::globals::ziplistname); ######################################################## # Check if this is simple packaging mechanism diff --git a/solenv/bin/modules/installer/ziplist.pm b/solenv/bin/modules/installer/ziplist.pm index 95b5638..4a3e476 100644 --- a/solenv/bin/modules/installer/ziplist.pm +++ b/solenv/bin/modules/installer/ziplist.pm @@ -27,14 +27,87 @@ package installer::ziplist; +use base 'Exporter'; + use File::Spec::Functions qw(rel2abs); +use installer::converter; use installer::exiter; +use installer::files; use installer::globals; use installer::logger; use installer::remover; use installer::systemactions; +our @EXPORT_OK = qw(read_ziplist); + +sub read_ziplist { + my $ziplistname = shift; + + installer::logger::globallog("zip list file: $ziplistname"); + + my $ziplistref = installer::files::read_file($ziplistname); + + installer::logger::print_message( "... analyzing $ziplistname ... \n" ); + + my ($productblockref, $parent) = getproductblock($ziplistref, $installer::globals::product, 1); # product block from zip.lst + + my ($settingsblockref, undef) = getproductblock($productblockref, "Settings", 0); # settings block from zip.lst + $settingsblockref = analyze_settings_block($settingsblockref); # select data from settings block in zip.lst + + my $allsettingsarrayref = get_settings_from_ziplist($settingsblockref); + my $allvariablesarrayref = get_variables_from_ziplist($settingsblockref); + + my ($globalproductblockref, undef) = getproductblock($ziplistref, $installer::globals::globalblock, 0); # global product block from zip.lst + + while (defined $parent) { + my $parentproductblockref; + ($parentproductblockref, $parent) = getproductblock($ziplistref, $parent, 1); + my ($parentsettingsblockref, undef) = getproductblock($parentproductblockref, "Settings", 0); + $parentsettingsblockref = analyze_settings_block($parentsettingsblockref); + my $allparentsettingsarrayref = get_settings_from_ziplist($parentsettingsblockref); + my $allparentvariablesarrayref = get_variables_from_ziplist($parentsettingsblockref); + $allsettingsarrayref = + installer::converter::combine_arrays_from_references_first_win( + $allsettingsarrayref, $allparentsettingsarrayref) + if $#{$allparentsettingsarrayref} > -1; + $allvariablesarrayref = + installer::converter::combine_arrays_from_references_first_win( + $allvariablesarrayref, $allparentvariablesarrayref) + if $#{$allparentvariablesarrayref} > -1; + } + + if ( @{$globalproductblockref} ) { + my ($globalsettingsblockref, undef) = getproductblock($globalproductblockref, "Settings", 0); # settings block from zip.lst + + $globalsettingsblockref = analyze_settings_block($globalsettingsblockref); # select data from settings block in zip.lst + + my $allglobalsettingsarrayref = get_settings_from_ziplist($globalsettingsblockref); + + my $allglobalvariablesarrayref = get_variables_from_ziplist($globalsettingsblockref); + + if ( @{$allglobalsettingsarrayref} ) { + $allsettingsarrayref = installer::converter::combine_arrays_from_references_first_win($allsettingsarrayref, $allglobalsettingsarrayref); + } + if ( @{$allglobalvariablesarrayref} ) { + $allvariablesarrayref = installer::converter::combine_arrays_from_references_first_win($allvariablesarrayref, $allglobalvariablesarrayref); + } + } + + $allsettingsarrayref = remove_multiples_from_ziplist($allsettingsarrayref); + $allvariablesarrayref = remove_multiples_from_ziplist($allvariablesarrayref); + + replace_variables_in_ziplist_variables($allvariablesarrayref); + + my $allvariableshashref = installer::converter::convert_array_to_hash($allvariablesarrayref); + + set_default_productversion_if_required($allvariableshashref); + add_variables_to_allvariableshashref($allvariableshashref); + overwrite_branding( $allvariableshashref ); + + return $allsettingsarrayref, $allvariableshashref; +} + ################################################# # Getting data from path file and zip list file ################################################# _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits