xref: /trunk/main/solenv/bin/modules/installer/windows/assembly.pm (revision dba1a2e414a893f42bf9be93b8f4e5f363e1113a)
19780544fSAndrew Rist#**************************************************************
2cdf0e10cSrcweir#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
19cdf0e10cSrcweir#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::windows::assembly;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse installer::files;
27cdf0e10cSrcweiruse installer::globals;
28cdf0e10cSrcweiruse installer::worker;
29cdf0e10cSrcweiruse installer::windows::idtglobal;
30cdf0e10cSrcweir
31*dba1a2e4SAndre Fischeruse strict;
32*dba1a2e4SAndre Fischer
33cdf0e10cSrcweir##############################################################
34cdf0e10cSrcweir# Returning the first module of a file from the
35cdf0e10cSrcweir# comma separated list of modules.
36cdf0e10cSrcweir##############################################################
37cdf0e10cSrcweir
38cdf0e10cSrcweirsub get_msiassembly_feature
39cdf0e10cSrcweir{
40cdf0e10cSrcweir    my ( $onefile ) = @_;
41cdf0e10cSrcweir
42cdf0e10cSrcweir    my $module = "";
43cdf0e10cSrcweir
44cdf0e10cSrcweir    if ( $onefile->{'modules'} ) { $module = $onefile->{'modules'}; }
45cdf0e10cSrcweir
46cdf0e10cSrcweir    # If modules contains a list of modules, only taking the first one.
47cdf0e10cSrcweir
48cdf0e10cSrcweir    if ( $module =~ /^\s*(.*?)\,/ ) { $module = $1; }
49cdf0e10cSrcweir
50cdf0e10cSrcweir    # Attention: Maximum feature length is 38!
51cdf0e10cSrcweir    installer::windows::idtglobal::shorten_feature_gid(\$module);
52cdf0e10cSrcweir
53cdf0e10cSrcweir    return $module;
54cdf0e10cSrcweir}
55cdf0e10cSrcweir
56cdf0e10cSrcweir##############################################################
57cdf0e10cSrcweir# Returning the component of a file.
58cdf0e10cSrcweir##############################################################
59cdf0e10cSrcweir
60cdf0e10cSrcweirsub get_msiassembly_component
61cdf0e10cSrcweir{
62cdf0e10cSrcweir    my ( $onefile ) = @_;
63cdf0e10cSrcweir
64cdf0e10cSrcweir    my $component = "";
65cdf0e10cSrcweir
66cdf0e10cSrcweir    $component = $onefile->{'componentname'};
67cdf0e10cSrcweir
68cdf0e10cSrcweir    return $component;
69cdf0e10cSrcweir}
70cdf0e10cSrcweir
71cdf0e10cSrcweir##############################################################
72cdf0e10cSrcweir# Returning the file name as manifest file
73cdf0e10cSrcweir##############################################################
74cdf0e10cSrcweir
75cdf0e10cSrcweirsub get_msiassembly_filemanifest
76cdf0e10cSrcweir{
77cdf0e10cSrcweir    my ( $onefile ) = @_;
78cdf0e10cSrcweir
79cdf0e10cSrcweir    my $filemanifest = "";
80cdf0e10cSrcweir
81cdf0e10cSrcweir    $filemanifest = $onefile->{'uniquename'};
82cdf0e10cSrcweir    # $filemanifest = $onefile->{'Name'};
83cdf0e10cSrcweir
84cdf0e10cSrcweir    return $filemanifest;
85cdf0e10cSrcweir}
86cdf0e10cSrcweir
87cdf0e10cSrcweir
88cdf0e10cSrcweir##############################################################
89cdf0e10cSrcweir# Returning the file application
90cdf0e10cSrcweir##############################################################
91cdf0e10cSrcweir
92cdf0e10cSrcweirsub get_msiassembly_fileapplication
93cdf0e10cSrcweir{
94cdf0e10cSrcweir    my ( $onefile ) = @_;
95cdf0e10cSrcweir
96cdf0e10cSrcweir    my $fileapplication = "";
97cdf0e10cSrcweir
98cdf0e10cSrcweir    return $fileapplication;
99cdf0e10cSrcweir}
100cdf0e10cSrcweir
101cdf0e10cSrcweir##############################################################
102cdf0e10cSrcweir# Returning the file attributes
103cdf0e10cSrcweir##############################################################
104cdf0e10cSrcweir
105cdf0e10cSrcweirsub get_msiassembly_attributes
106cdf0e10cSrcweir{
107cdf0e10cSrcweir    my ( $onefile ) = @_;
108cdf0e10cSrcweir
109cdf0e10cSrcweir    my $fileattributes = "";
110cdf0e10cSrcweir
111cdf0e10cSrcweir    if ( $onefile->{'Attributes'} ne "" ) { $fileattributes = $onefile->{'Attributes'}; }
112cdf0e10cSrcweir
113cdf0e10cSrcweir    return $fileattributes;
114cdf0e10cSrcweir}
115cdf0e10cSrcweir
116cdf0e10cSrcweir##############################################################
117cdf0e10cSrcweir# Returning the file object for the msiassembly table.
118cdf0e10cSrcweir##############################################################
119cdf0e10cSrcweir
120cdf0e10cSrcweirsub get_msiassembly_file
121cdf0e10cSrcweir{
122cdf0e10cSrcweir    my ( $filesref, $filename ) = @_;
123cdf0e10cSrcweir
124cdf0e10cSrcweir    my $foundfile = 0;
125cdf0e10cSrcweir    my $onefile;
126cdf0e10cSrcweir
127cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
128cdf0e10cSrcweir    {
129cdf0e10cSrcweir        $onefile = ${$filesref}[$i];
130cdf0e10cSrcweir        my $name = $onefile->{'Name'};
131cdf0e10cSrcweir
132cdf0e10cSrcweir        if ( $name eq $filename )
133cdf0e10cSrcweir        {
134cdf0e10cSrcweir            $foundfile = 1;
135cdf0e10cSrcweir            last;
136cdf0e10cSrcweir        }
137cdf0e10cSrcweir    }
138cdf0e10cSrcweir
139cdf0e10cSrcweir    # It does not need to exist. For example products that do not contain the libraries.
140cdf0e10cSrcweir    # if (! $foundfile ) { installer::exiter::exit_program("ERROR: No unique file name found for $filename !", "get_selfreg_file"); }
141cdf0e10cSrcweir
142cdf0e10cSrcweir    if (! $foundfile ) { $onefile  = ""; }
143cdf0e10cSrcweir
144cdf0e10cSrcweir    return $onefile;
145cdf0e10cSrcweir}
146cdf0e10cSrcweir
147cdf0e10cSrcweir##############################################################
148cdf0e10cSrcweir# Returning the file object for the msiassembly table.
149cdf0e10cSrcweir##############################################################
150cdf0e10cSrcweir
151cdf0e10cSrcweirsub get_msiassembly_file_by_gid
152cdf0e10cSrcweir{
153cdf0e10cSrcweir    my ( $filesref, $gid ) = @_;
154cdf0e10cSrcweir
155cdf0e10cSrcweir    my $foundfile = 0;
156cdf0e10cSrcweir    my $onefile;
157cdf0e10cSrcweir
158cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
159cdf0e10cSrcweir    {
160cdf0e10cSrcweir        $onefile = ${$filesref}[$i];
161cdf0e10cSrcweir        my $filegid = $onefile->{'gid'};
162cdf0e10cSrcweir
163cdf0e10cSrcweir        if ( $filegid eq $gid )
164cdf0e10cSrcweir        {
165cdf0e10cSrcweir            $foundfile = 1;
166cdf0e10cSrcweir            last;
167cdf0e10cSrcweir        }
168cdf0e10cSrcweir    }
169cdf0e10cSrcweir
170cdf0e10cSrcweir    # It does not need to exist. For example products that do not contain the libraries.
171cdf0e10cSrcweir    # if (! $foundfile ) { installer::exiter::exit_program("ERROR: No unique file name found for $filename !", "get_selfreg_file"); }
172cdf0e10cSrcweir
173cdf0e10cSrcweir    if (! $foundfile ) { $onefile  = ""; }
174cdf0e10cSrcweir
175cdf0e10cSrcweir    return $onefile;
176cdf0e10cSrcweir}
177cdf0e10cSrcweir
178cdf0e10cSrcweir####################################################################################
179cdf0e10cSrcweir# Creating the file MsiAssembly.idt dynamically
180cdf0e10cSrcweir# Content:
181cdf0e10cSrcweir# Component_    Feature_    File_Manifest   File_Application    Attributes
182cdf0e10cSrcweir# s72   s38 S72 S72 I2
183cdf0e10cSrcweir# MsiAssembly   Component_
184cdf0e10cSrcweir####################################################################################
185cdf0e10cSrcweir
186cdf0e10cSrcweirsub create_msiassembly_table
187cdf0e10cSrcweir{
188cdf0e10cSrcweir    my ($filesref, $basedir) = @_;
189cdf0e10cSrcweir
190cdf0e10cSrcweir    $installer::globals::msiassemblyfiles = installer::worker::collect_all_items_with_special_flag($filesref, "ASSEMBLY");
191cdf0e10cSrcweir
192cdf0e10cSrcweir    my @msiassemblytable = ();
193cdf0e10cSrcweir
194cdf0e10cSrcweir    installer::windows::idtglobal::write_idt_header(\@msiassemblytable, "msiassembly");
195cdf0e10cSrcweir
196cdf0e10cSrcweir    # Registering all libraries listed in $installer::globals::msiassemblyfiles
197cdf0e10cSrcweir
198cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$installer::globals::msiassemblyfiles}; $i++ )
199cdf0e10cSrcweir    {
200cdf0e10cSrcweir        my $onefile = ${$installer::globals::msiassemblyfiles}[$i];
201cdf0e10cSrcweir
202cdf0e10cSrcweir        my %msiassembly = ();
203cdf0e10cSrcweir
204cdf0e10cSrcweir        $msiassembly{'Component_'} = get_msiassembly_component($onefile);
205cdf0e10cSrcweir        $msiassembly{'Feature_'} = get_msiassembly_feature($onefile);
206cdf0e10cSrcweir        $msiassembly{'File_Manifest'} = get_msiassembly_filemanifest($onefile);
207cdf0e10cSrcweir        $msiassembly{'File_Application'} = get_msiassembly_fileapplication($onefile);
208cdf0e10cSrcweir        $msiassembly{'Attributes'} = get_msiassembly_attributes($onefile);
209cdf0e10cSrcweir
210cdf0e10cSrcweir        my $oneline = $msiassembly{'Component_'} . "\t" . $msiassembly{'Feature_'} . "\t" .
211cdf0e10cSrcweir                        $msiassembly{'File_Manifest'} . "\t" . $msiassembly{'File_Application'} . "\t" .
212cdf0e10cSrcweir                        $msiassembly{'Attributes'} . "\n";
213cdf0e10cSrcweir
214cdf0e10cSrcweir        push(@msiassemblytable, $oneline);
215cdf0e10cSrcweir    }
216cdf0e10cSrcweir
217cdf0e10cSrcweir    # Saving the file
218cdf0e10cSrcweir
219cdf0e10cSrcweir    my $msiassemblytablename = $basedir . $installer::globals::separator . "MsiAssem.idt";
220cdf0e10cSrcweir    installer::files::save_file($msiassemblytablename ,\@msiassemblytable);
221cdf0e10cSrcweir    my $infoline = "Created idt file: $msiassemblytablename\n";
222b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
223cdf0e10cSrcweir}
224cdf0e10cSrcweir
225cdf0e10cSrcweir####################################################################################
226cdf0e10cSrcweir# Returning the name for the table MsiAssemblyName
227cdf0e10cSrcweir####################################################################################
228cdf0e10cSrcweir
229*dba1a2e4SAndre Fischersub get_msiassemblyname_name ($)
230cdf0e10cSrcweir{
231*dba1a2e4SAndre Fischer    my ($number) = @_;
232cdf0e10cSrcweir
233cdf0e10cSrcweir    my $name = "";
234cdf0e10cSrcweir
235cdf0e10cSrcweir    if ( $number == 1 ) { $name = "name"; }
236cdf0e10cSrcweir    elsif ( $number == 2 ) { $name = "publicKeyToken"; }
237cdf0e10cSrcweir    elsif ( $number == 3 ) { $name = "version"; }
238cdf0e10cSrcweir    elsif ( $number == 4 ) { $name = "culture"; }
239cdf0e10cSrcweir
240cdf0e10cSrcweir    return $name;
241cdf0e10cSrcweir}
242cdf0e10cSrcweir
243cdf0e10cSrcweir####################################################################################
244cdf0e10cSrcweir# Creating the file MsiAssemblyName.idt dynamically
245cdf0e10cSrcweir# Content:
246cdf0e10cSrcweir# Component_    Name    Value
247cdf0e10cSrcweir# s72   s255    s255
248cdf0e10cSrcweir# MsiAssemblyName   Component_  Name
249cdf0e10cSrcweir####################################################################################
250cdf0e10cSrcweir
251cdf0e10cSrcweirsub create_msiassemblyname_table
252cdf0e10cSrcweir{
253cdf0e10cSrcweir    my ($filesref, $basedir) = @_;
254cdf0e10cSrcweir
255cdf0e10cSrcweir    my @msiassemblynametable = ();
256cdf0e10cSrcweir
257cdf0e10cSrcweir    installer::windows::idtglobal::write_idt_header(\@msiassemblynametable, "msiassemblyname");
258cdf0e10cSrcweir
259cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$installer::globals::msiassemblyfiles}; $i++ )
260cdf0e10cSrcweir    {
261cdf0e10cSrcweir        my $onefile = ${$installer::globals::msiassemblyfiles}[$i];
262cdf0e10cSrcweir
263cdf0e10cSrcweir        my $component = get_msiassembly_component($onefile);
264cdf0e10cSrcweir        my $oneline = "";
265cdf0e10cSrcweir
266cdf0e10cSrcweir        # Order: (Assembly)name, publicKeyToken, version, culture.
267cdf0e10cSrcweir
268cdf0e10cSrcweir        if ( $onefile->{'Assemblyname'} )
269cdf0e10cSrcweir        {
270cdf0e10cSrcweir            $oneline = $component . "\t" . "name" . "\t" . $onefile->{'Assemblyname'} . "\n";
271cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
272cdf0e10cSrcweir        }
273cdf0e10cSrcweir
274cdf0e10cSrcweir        if ( $onefile->{'PublicKeyToken'} )
275cdf0e10cSrcweir        {
276cdf0e10cSrcweir            $oneline = $component . "\t" . "publicKeyToken" . "\t" . $onefile->{'PublicKeyToken'} . "\n";
277cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
278cdf0e10cSrcweir        }
279cdf0e10cSrcweir
280cdf0e10cSrcweir        if ( $onefile->{'Version'} )
281cdf0e10cSrcweir        {
282cdf0e10cSrcweir            $oneline = $component . "\t" . "version" . "\t" . $onefile->{'Version'} . "\n";
283cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
284cdf0e10cSrcweir        }
285cdf0e10cSrcweir
286cdf0e10cSrcweir        if ( $onefile->{'Culture'} )
287cdf0e10cSrcweir        {
288cdf0e10cSrcweir            $oneline = $component . "\t" . "culture" . "\t" . $onefile->{'Culture'} . "\n";
289cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
290cdf0e10cSrcweir        }
291cdf0e10cSrcweir
292cdf0e10cSrcweir        if ( $onefile->{'ProcessorArchitecture'} )
293cdf0e10cSrcweir        {
294cdf0e10cSrcweir            $oneline = $component . "\t" . "processorArchitecture" . "\t" . $onefile->{'ProcessorArchitecture'} . "\n";
295cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
296cdf0e10cSrcweir        }
297cdf0e10cSrcweir    }
298cdf0e10cSrcweir
299cdf0e10cSrcweir    # Saving the file
300cdf0e10cSrcweir
301cdf0e10cSrcweir    my $msiassemblynametablename = $basedir . $installer::globals::separator . "MsiAsseN.idt";
302cdf0e10cSrcweir    installer::files::save_file($msiassemblynametablename ,\@msiassemblynametable);
303cdf0e10cSrcweir    my $infoline = "Created idt file: $msiassemblynametablename\n";
304b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
305cdf0e10cSrcweir
306cdf0e10cSrcweir}
307cdf0e10cSrcweir
308cdf0e10cSrcweir####################################################################################
309cdf0e10cSrcweir# setting an installation condition for the assembly libraries saved in
310cdf0e10cSrcweir# @installer::globals::msiassemblynamecontent
311cdf0e10cSrcweir####################################################################################
312cdf0e10cSrcweir
313cdf0e10cSrcweirsub add_assembly_condition_into_component_table
314cdf0e10cSrcweir{
315cdf0e10cSrcweir    my ($filesref, $basedir) = @_;
316cdf0e10cSrcweir
317cdf0e10cSrcweir    my $componenttablename = $basedir . $installer::globals::separator . "Componen.idt";
318cdf0e10cSrcweir    my $componenttable = installer::files::read_file($componenttablename);
319cdf0e10cSrcweir    my $changed = 0;
320cdf0e10cSrcweir
321*dba1a2e4SAndre Fischer    foreach my $onefile (@$installer::globals::msiassemblyfiles)
322cdf0e10cSrcweir    {
323cdf0e10cSrcweir        my $filecomponent = get_msiassembly_component($onefile);
324cdf0e10cSrcweir
325cdf0e10cSrcweir        for ( my $j = 0; $j <= $#{$componenttable}; $j++ )
326cdf0e10cSrcweir        {
327cdf0e10cSrcweir            my $oneline = ${$componenttable}[$j];
328cdf0e10cSrcweir
329cdf0e10cSrcweir            if ( $oneline =~ /(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)/ )
330cdf0e10cSrcweir            {
331cdf0e10cSrcweir                my $component = $1;
332cdf0e10cSrcweir                my $componentid = $2;
333cdf0e10cSrcweir                my $directory = $3;
334cdf0e10cSrcweir                my $attributes = $4;
335cdf0e10cSrcweir                my $condition = $5;
336cdf0e10cSrcweir                my $keypath = $6;
337cdf0e10cSrcweir
338cdf0e10cSrcweir                if ( $component eq $filecomponent )
339cdf0e10cSrcweir                {
340cdf0e10cSrcweir                    # setting the condition
341cdf0e10cSrcweir
342cdf0e10cSrcweir                    # $condition = "MsiNetAssemblySupport";
343cdf0e10cSrcweir                    $condition = "DOTNET_SUFFICIENT=1";
344*dba1a2e4SAndre Fischer                    $oneline = join("\t",
345*dba1a2e4SAndre Fischer                        $component,
346*dba1a2e4SAndre Fischer                        $componentid,
347*dba1a2e4SAndre Fischer                        $directory,
348*dba1a2e4SAndre Fischer                        $attributes,
349*dba1a2e4SAndre Fischer                        $condition,
350*dba1a2e4SAndre Fischer                        $keypath) . "\n";
351cdf0e10cSrcweir                    ${$componenttable}[$j] = $oneline;
352cdf0e10cSrcweir                    $changed = 1;
353*dba1a2e4SAndre Fischer                    $installer::logger::Lang->print("Changing %s :\n", $componenttablename);
354*dba1a2e4SAndre Fischer                    $installer::logger::Lang->print($oneline);
355cdf0e10cSrcweir                    last;
356cdf0e10cSrcweir                }
357cdf0e10cSrcweir            }
358cdf0e10cSrcweir        }
359cdf0e10cSrcweir    }
360cdf0e10cSrcweir
361cdf0e10cSrcweir    if ( $changed )
362cdf0e10cSrcweir    {
363cdf0e10cSrcweir        # Saving the file
364cdf0e10cSrcweir        installer::files::save_file($componenttablename ,$componenttable);
365*dba1a2e4SAndre Fischer        $installer::logger::Lang->print("Saved idt file: %s\n", $componenttablename);
366cdf0e10cSrcweir    }
367cdf0e10cSrcweir}
368cdf0e10cSrcweir
369cdf0e10cSrcweir1;
370