xref: /aoo4110/main/sc/util/createExtPackage.pl (revision b1cdbd2c)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24use Archive::Zip qw(:ERROR_CODES);
25use File::Basename;
26
27my $zipName = shift || die 'must provide a ext name';
28my $rdbName = shift || die 'must provide a types library';
29my $libName = shift || die 'must provide a component library';
30
31die "can't access type library $rdbName" unless -f $rdbName;
32die "can't access component library $libName" unless -f $libName;
33
34# Read the zip
35my $zip = Archive::Zip->new();
36
37if ( -f $zipName )
38{
39    # be stupid and recreate zip every time
40    # in another iteration lets try to overwrite it instead
41    my $result = 0;
42    $result = unlink($zipName);
43    if ( result != 0 )
44    {
45        die 'can not delete old extension';
46    }
47}
48my $rdb = basename( $rdbName );
49my $lib = basename( $libName );
50
51my $content2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
52$content2 .= "<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n";
53$content2 .= "<manifest:manifest xmlns:manifest=\"http://openoffice.org/2001/manifest\">\n";
54$content2 .= "  <manifest:file-entry manifest:media-type=\"application/vnd.sun.star.uno-typelibrary;type=RDB\" manifest:full-path=\"$rdb\"/>\n";
55$content2 .= "  <manifest:file-entry manifest:media-type=\"application/vnd.sun.star.uno-component;type=native\"  manifest:full-path=\"$lib\"/>\n";
56$content2 .= "</manifest:manifest>\n";
57
58$zip->addFile( $rdbName, $rdb );
59$zip->addFile( $libName, $lib );
60$zip->addDirectory( "META-INF" );
61$zip->addFile( "META-INF/manifest.xml", "manifest.xml" );
62$zip->addString( $content2, "META-INF/manifest.xml" );
63exit( $zip->writeToFileNamed($zipName) );
64