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