1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cli_ure.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <stdio.h>
32*cdf0e10cSrcweir #include <vector>
33*cdf0e10cSrcweir #include <memory>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "climaker_share.h"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "sal/main.h"
38*cdf0e10cSrcweir #include "osl/process.h"
39*cdf0e10cSrcweir #include "osl/file.hxx"
40*cdf0e10cSrcweir #include "osl/thread.h"
41*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
42*cdf0e10cSrcweir #include "cppuhelper/shlib.hxx"
43*cdf0e10cSrcweir #include "cppuhelper/bootstrap.hxx"
44*cdf0e10cSrcweir #include "com/sun/star/lang/XInitialization.hpp"
45*cdf0e10cSrcweir #include "com/sun/star/lang/XSingleComponentFactory.hpp"
46*cdf0e10cSrcweir #include "com/sun/star/lang/XComponent.hpp"
47*cdf0e10cSrcweir #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
48*cdf0e10cSrcweir #include "com/sun/star/container/XSet.hpp"
49*cdf0e10cSrcweir #include "com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp"
50*cdf0e10cSrcweir #include "com/sun/star/registry/XSimpleRegistry.hpp"
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir using namespace ::std;
53*cdf0e10cSrcweir using namespace ::System::Reflection;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir using namespace ::rtl;
57*cdf0e10cSrcweir using namespace ::osl;
58*cdf0e10cSrcweir using namespace ::com::sun::star;
59*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir namespace climaker
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir //------------------------------------------------------------------------------
65*cdf0e10cSrcweir static char const s_usingText [] =
66*cdf0e10cSrcweir "\n"
67*cdf0e10cSrcweir "using: climaker <switches> [registry-file-1 registry-file-2 ...]\n"
68*cdf0e10cSrcweir "\n"
69*cdf0e10cSrcweir "switches:\n"
70*cdf0e10cSrcweir " -O, --out <output-file>       output assembly file;\n"
71*cdf0e10cSrcweir "                               defaults to cli_unotypes.dll if more than one\n"
72*cdf0e10cSrcweir "                               registry-file is given, else <registry-file>.dll\n"
73*cdf0e10cSrcweir " -T, --types                   types to be generated (if none is given,\n"
74*cdf0e10cSrcweir "   <type1[;type2;...]>         then all types of given registries are emitted\n"
75*cdf0e10cSrcweir " -X, --extra <rdb-file>        additional rdb to saturate referenced types in\n"
76*cdf0e10cSrcweir "                               given registry file(s); these types will not be\n"
77*cdf0e10cSrcweir "                               emitted into the output assembly file\n"
78*cdf0e10cSrcweir " -r, --reference               reference metadata from assembly file\n"
79*cdf0e10cSrcweir "   <assembly-file>\n"
80*cdf0e10cSrcweir " -k, --keyfile                 keyfile needed for strong name\n"
81*cdf0e10cSrcweir " --assembly-version <version>  sets assembly version\n"
82*cdf0e10cSrcweir " --assembly-description <text> sets assembly description text\n"
83*cdf0e10cSrcweir " --assembly-product <text>     sets assembly product name\n"
84*cdf0e10cSrcweir " --assembly-company <text>     sets assembly company\n"
85*cdf0e10cSrcweir " --assembly-copyright <text>   sets assembly copyright\n"
86*cdf0e10cSrcweir " --assembly-trademark <text>   sets assembly trademark\n"
87*cdf0e10cSrcweir " -v, --verbose                 verbose output to stdout\n"
88*cdf0e10cSrcweir " -h, --help                    this message\n"
89*cdf0e10cSrcweir "\n"
90*cdf0e10cSrcweir "example: climaker --out cli_mytypes.dll \\\n"
91*cdf0e10cSrcweir "                  --reference cli_uretypes.dll \\\n"
92*cdf0e10cSrcweir "                  --extra types.rdb \\\n"
93*cdf0e10cSrcweir "                  mytypes.rdb\n"
94*cdf0e10cSrcweir "\n";
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir struct OptionInfo
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     char const * m_name;
99*cdf0e10cSrcweir     sal_uInt32 m_name_length;
100*cdf0e10cSrcweir     sal_Unicode m_short_option;
101*cdf0e10cSrcweir     bool m_has_argument;
102*cdf0e10cSrcweir };
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir bool g_verbose = false;
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir //------------------------------------------------------------------------------
107*cdf0e10cSrcweir static const OptionInfo s_option_infos [] = {
108*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("out"), 'O', true },
109*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("types"), 'T', true },
110*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("extra"), 'X', true },
111*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("reference"), 'r', true },
112*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("keyfile"), 'k', true },
113*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("delaySign"), 'd', true },
114*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("assembly-version"), '\0', true },
115*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("assembly-description"), '\0', true },
116*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("assembly-product"), '\0', true },
117*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("assembly-company"), '\0', true },
118*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("assembly-copyright"), '\0', true },
119*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("assembly-trademark"), '\0', true },
120*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("verbose"), 'v', false },
121*cdf0e10cSrcweir     { RTL_CONSTASCII_STRINGPARAM("help"), 'h', false }
122*cdf0e10cSrcweir };
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir //==============================================================================
125*cdf0e10cSrcweir static OptionInfo const * get_option_info(
126*cdf0e10cSrcweir     OUString const & opt, sal_Unicode copt = '\0' )
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     for ( sal_Int32 pos = 0;
129*cdf0e10cSrcweir           pos < (sizeof (s_option_infos) / sizeof (OptionInfo));
130*cdf0e10cSrcweir           ++pos )
131*cdf0e10cSrcweir     {
132*cdf0e10cSrcweir         OptionInfo const & option_info = s_option_infos[ pos ];
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         if (opt.getLength() > 0)
135*cdf0e10cSrcweir         {
136*cdf0e10cSrcweir             if (opt.equalsAsciiL(
137*cdf0e10cSrcweir                     option_info.m_name, option_info.m_name_length ) &&
138*cdf0e10cSrcweir                 (copt == '\0' || copt == option_info.m_short_option))
139*cdf0e10cSrcweir             {
140*cdf0e10cSrcweir                 return &option_info;
141*cdf0e10cSrcweir             }
142*cdf0e10cSrcweir         }
143*cdf0e10cSrcweir         else
144*cdf0e10cSrcweir         {
145*cdf0e10cSrcweir             OSL_ASSERT( copt != '\0' );
146*cdf0e10cSrcweir             if (copt == option_info.m_short_option)
147*cdf0e10cSrcweir             {
148*cdf0e10cSrcweir                 return &option_info;
149*cdf0e10cSrcweir             }
150*cdf0e10cSrcweir         }
151*cdf0e10cSrcweir     }
152*cdf0e10cSrcweir     OSL_ENSURE(
153*cdf0e10cSrcweir         0, OUStringToOString( opt, osl_getThreadTextEncoding() ).getStr() );
154*cdf0e10cSrcweir     return 0;
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir //==============================================================================
158*cdf0e10cSrcweir static bool is_option(
159*cdf0e10cSrcweir     OptionInfo const * option_info, sal_uInt32 * pIndex )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     OSL_ASSERT( option_info != 0 );
162*cdf0e10cSrcweir     if (osl_getCommandArgCount() <= *pIndex)
163*cdf0e10cSrcweir         return false;
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     OUString arg;
166*cdf0e10cSrcweir     osl_getCommandArg( *pIndex, &arg.pData );
167*cdf0e10cSrcweir     sal_Int32 len = arg.getLength();
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     if (len < 2 || arg[ 0 ] != '-')
170*cdf0e10cSrcweir         return false;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     if (len == 2 && arg[ 1 ] == option_info->m_short_option)
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         ++(*pIndex);
175*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
176*cdf0e10cSrcweir         OSL_TRACE(
177*cdf0e10cSrcweir             __FILE__": identified option \'%c\'", option_info->m_short_option );
178*cdf0e10cSrcweir #endif
179*cdf0e10cSrcweir         return true;
180*cdf0e10cSrcweir     }
181*cdf0e10cSrcweir     if (arg[ 1 ] == '-' && rtl_ustr_ascii_compare(
182*cdf0e10cSrcweir             arg.pData->buffer + 2, option_info->m_name ) == 0)
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         ++(*pIndex);
185*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
186*cdf0e10cSrcweir         OSL_TRACE( __FILE__": identified option \'%s\'", option_info->m_name );
187*cdf0e10cSrcweir #endif
188*cdf0e10cSrcweir         return true;
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir     return false;
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir //==============================================================================
194*cdf0e10cSrcweir static inline bool read_option(
195*cdf0e10cSrcweir     bool * flag, OptionInfo const * option_info, sal_uInt32 * pIndex )
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir     bool ret = is_option( option_info, pIndex );
198*cdf0e10cSrcweir     if (ret)
199*cdf0e10cSrcweir         *flag = true;
200*cdf0e10cSrcweir     return ret;
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir //==============================================================================
204*cdf0e10cSrcweir static bool read_argument(
205*cdf0e10cSrcweir     OUString * pValue, OptionInfo const * option_info, sal_uInt32 * pIndex )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     if (is_option( option_info, pIndex ))
208*cdf0e10cSrcweir     {
209*cdf0e10cSrcweir         if (*pIndex < osl_getCommandArgCount())
210*cdf0e10cSrcweir         {
211*cdf0e10cSrcweir             osl_getCommandArg( *pIndex, &pValue->pData );
212*cdf0e10cSrcweir             ++(*pIndex);
213*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
214*cdf0e10cSrcweir             OString cstr_val(
215*cdf0e10cSrcweir                 OUStringToOString( *pValue, osl_getThreadTextEncoding() ) );
216*cdf0e10cSrcweir             OSL_TRACE( __FILE__": argument value: %s\n", cstr_val.getStr() );
217*cdf0e10cSrcweir #endif
218*cdf0e10cSrcweir             return true;
219*cdf0e10cSrcweir         }
220*cdf0e10cSrcweir         --(*pIndex);
221*cdf0e10cSrcweir     }
222*cdf0e10cSrcweir     return false;
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir //==============================================================================
226*cdf0e10cSrcweir static OUString const & path_get_working_dir()
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir     static OUString s_workingDir;
229*cdf0e10cSrcweir     if (! s_workingDir.getLength())
230*cdf0e10cSrcweir         osl_getProcessWorkingDir( &s_workingDir.pData );
231*cdf0e10cSrcweir     return s_workingDir;
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir //==============================================================================
235*cdf0e10cSrcweir static OUString path_make_absolute_file_url( OUString const & path )
236*cdf0e10cSrcweir {
237*cdf0e10cSrcweir     OUString file_url;
238*cdf0e10cSrcweir     oslFileError rc = osl_getFileURLFromSystemPath(
239*cdf0e10cSrcweir         path.pData, &file_url.pData );
240*cdf0e10cSrcweir     if (osl_File_E_None == rc)
241*cdf0e10cSrcweir     {
242*cdf0e10cSrcweir         OUString abs;
243*cdf0e10cSrcweir         rc = osl_getAbsoluteFileURL(
244*cdf0e10cSrcweir             path_get_working_dir().pData, file_url.pData, &abs.pData );
245*cdf0e10cSrcweir         if (osl_File_E_None == rc)
246*cdf0e10cSrcweir         {
247*cdf0e10cSrcweir             return abs;
248*cdf0e10cSrcweir         }
249*cdf0e10cSrcweir         else
250*cdf0e10cSrcweir         {
251*cdf0e10cSrcweir             throw RuntimeException(
252*cdf0e10cSrcweir                 OUSTR("cannot make absolute: ") + file_url,
253*cdf0e10cSrcweir                 Reference< XInterface >() );
254*cdf0e10cSrcweir         }
255*cdf0e10cSrcweir     }
256*cdf0e10cSrcweir     else
257*cdf0e10cSrcweir     {
258*cdf0e10cSrcweir         throw RuntimeException(
259*cdf0e10cSrcweir             OUSTR("cannot get file url from system path: ") + path,
260*cdf0e10cSrcweir             Reference< XInterface >() );
261*cdf0e10cSrcweir     }
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir //==============================================================================
265*cdf0e10cSrcweir Reference< registry::XSimpleRegistry > open_registries(
266*cdf0e10cSrcweir     vector< OUString > const & registries,
267*cdf0e10cSrcweir     Reference< XComponentContext > xContext )
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir     if (registries.empty())
270*cdf0e10cSrcweir     {
271*cdf0e10cSrcweir         throw RuntimeException(
272*cdf0e10cSrcweir             OUSTR("no registries given!"),
273*cdf0e10cSrcweir             Reference< XInterface >() );
274*cdf0e10cSrcweir     }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir     Reference< registry::XSimpleRegistry > xSimReg;
277*cdf0e10cSrcweir     for ( size_t nPos = registries.size(); nPos--; )
278*cdf0e10cSrcweir     {
279*cdf0e10cSrcweir         Reference< registry::XSimpleRegistry > xReg(
280*cdf0e10cSrcweir             xContext->getServiceManager()->createInstanceWithContext(
281*cdf0e10cSrcweir                 OUSTR("com.sun.star.registry.SimpleRegistry"), xContext ),
282*cdf0e10cSrcweir             UNO_QUERY_THROW );
283*cdf0e10cSrcweir         xReg->open( registries[ nPos ], sal_True, sal_False );
284*cdf0e10cSrcweir         if (! xReg->isValid())
285*cdf0e10cSrcweir         {
286*cdf0e10cSrcweir             throw RuntimeException(
287*cdf0e10cSrcweir                 OUSTR("invalid registry: ") + registries[ nPos ],
288*cdf0e10cSrcweir                 Reference< XInterface >() );
289*cdf0e10cSrcweir         }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir         if (xSimReg.is()) // nest?
292*cdf0e10cSrcweir         {
293*cdf0e10cSrcweir             Reference< registry::XSimpleRegistry > xNested(
294*cdf0e10cSrcweir                 xContext->getServiceManager()->createInstanceWithContext(
295*cdf0e10cSrcweir                     OUSTR("com.sun.star.registry.NestedRegistry"), xContext ),
296*cdf0e10cSrcweir                 UNO_QUERY_THROW );
297*cdf0e10cSrcweir             Reference< lang::XInitialization > xInit(
298*cdf0e10cSrcweir                 xNested, UNO_QUERY_THROW );
299*cdf0e10cSrcweir             Sequence< Any > args( 2 );
300*cdf0e10cSrcweir             args[ 0 ] <<= xReg;
301*cdf0e10cSrcweir             args[ 1 ] <<= xSimReg;
302*cdf0e10cSrcweir             xInit->initialize( args );
303*cdf0e10cSrcweir             xSimReg = xNested;
304*cdf0e10cSrcweir         }
305*cdf0e10cSrcweir         else
306*cdf0e10cSrcweir         {
307*cdf0e10cSrcweir             xSimReg = xReg;
308*cdf0e10cSrcweir         }
309*cdf0e10cSrcweir     }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir     return xSimReg;
312*cdf0e10cSrcweir }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir using namespace ::climaker;
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir //##############################################################################
319*cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir     sal_uInt32 nCount = osl_getCommandArgCount();
322*cdf0e10cSrcweir     if (0 == nCount)
323*cdf0e10cSrcweir     {
324*cdf0e10cSrcweir         printf( s_usingText );
325*cdf0e10cSrcweir         return 0;
326*cdf0e10cSrcweir     }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 	int ret = 0;
329*cdf0e10cSrcweir     Reference< XComponentContext > xContext;
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	try
332*cdf0e10cSrcweir 	{
333*cdf0e10cSrcweir         OptionInfo const * info_help =
334*cdf0e10cSrcweir             get_option_info( OUSTR("help") );
335*cdf0e10cSrcweir         OptionInfo const * info_verbose =
336*cdf0e10cSrcweir             get_option_info( OUSTR("verbose") );
337*cdf0e10cSrcweir         OptionInfo const * info_out =
338*cdf0e10cSrcweir             get_option_info( OUSTR("out") );
339*cdf0e10cSrcweir         OptionInfo const * info_types =
340*cdf0e10cSrcweir             get_option_info( OUSTR("types") );
341*cdf0e10cSrcweir         OptionInfo const * info_reference =
342*cdf0e10cSrcweir             get_option_info( OUSTR("reference") );
343*cdf0e10cSrcweir         OptionInfo const * info_extra =
344*cdf0e10cSrcweir             get_option_info( OUSTR("extra") );
345*cdf0e10cSrcweir         OptionInfo const * info_keyfile =
346*cdf0e10cSrcweir             get_option_info( OUSTR("keyfile") );
347*cdf0e10cSrcweir         OptionInfo const * info_delaySign =
348*cdf0e10cSrcweir             get_option_info( OUSTR("delaySign") );
349*cdf0e10cSrcweir         OptionInfo const * info_version =
350*cdf0e10cSrcweir             get_option_info( OUSTR("assembly-version") );
351*cdf0e10cSrcweir         OptionInfo const * info_product =
352*cdf0e10cSrcweir             get_option_info( OUSTR("assembly-product") );
353*cdf0e10cSrcweir         OptionInfo const * info_description =
354*cdf0e10cSrcweir             get_option_info( OUSTR("assembly-description") );
355*cdf0e10cSrcweir         OptionInfo const * info_company =
356*cdf0e10cSrcweir             get_option_info( OUSTR("assembly-company") );
357*cdf0e10cSrcweir         OptionInfo const * info_copyright =
358*cdf0e10cSrcweir             get_option_info( OUSTR("assembly-copyright") );
359*cdf0e10cSrcweir         OptionInfo const * info_trademark =
360*cdf0e10cSrcweir             get_option_info( OUSTR("assembly-trademark") );
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir         OUString output;
363*cdf0e10cSrcweir         vector< OUString > mandatory_registries;
364*cdf0e10cSrcweir         vector< OUString > extra_registries;
365*cdf0e10cSrcweir         vector< OUString > extra_assemblies;
366*cdf0e10cSrcweir         vector< OUString > explicit_types;
367*cdf0e10cSrcweir         OUString version, product, description, company, copyright, trademark,
368*cdf0e10cSrcweir             keyfile, delaySign;
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir         OUString cmd_arg;
371*cdf0e10cSrcweir 		for ( sal_uInt32 nPos = 0; nPos < nCount; )
372*cdf0e10cSrcweir 		{
373*cdf0e10cSrcweir             // options
374*cdf0e10cSrcweir 			if (is_option( info_help, &nPos ))
375*cdf0e10cSrcweir 			{
376*cdf0e10cSrcweir                 printf( s_usingText );
377*cdf0e10cSrcweir                 return 0;
378*cdf0e10cSrcweir 			}
379*cdf0e10cSrcweir 			else if (read_argument( &cmd_arg, info_types, &nPos ))
380*cdf0e10cSrcweir 			{
381*cdf0e10cSrcweir                 sal_Int32 index = 0;
382*cdf0e10cSrcweir                 do
383*cdf0e10cSrcweir                 {
384*cdf0e10cSrcweir                     explicit_types.push_back(
385*cdf0e10cSrcweir                         cmd_arg.getToken( 0, ';', index ) );
386*cdf0e10cSrcweir                 }
387*cdf0e10cSrcweir                 while (index >= 0);
388*cdf0e10cSrcweir 			}
389*cdf0e10cSrcweir             else if (read_argument( &cmd_arg, info_extra, &nPos ))
390*cdf0e10cSrcweir             {
391*cdf0e10cSrcweir                 extra_registries.push_back(
392*cdf0e10cSrcweir                     path_make_absolute_file_url( cmd_arg ) );
393*cdf0e10cSrcweir             }
394*cdf0e10cSrcweir             else if (read_argument( &cmd_arg, info_reference, &nPos ))
395*cdf0e10cSrcweir             {
396*cdf0e10cSrcweir                 extra_assemblies.push_back(
397*cdf0e10cSrcweir                     path_make_absolute_file_url( cmd_arg ) );
398*cdf0e10cSrcweir             }
399*cdf0e10cSrcweir             else if (!read_option( &g_verbose, info_verbose, &nPos ) &&
400*cdf0e10cSrcweir                      !read_argument( &output, info_out, &nPos ) &&
401*cdf0e10cSrcweir                      !read_argument( &version, info_version, &nPos ) &&
402*cdf0e10cSrcweir                      !read_argument( &description, info_description, &nPos ) &&
403*cdf0e10cSrcweir                      !read_argument( &product, info_product, &nPos ) &&
404*cdf0e10cSrcweir                      !read_argument( &company, info_company, &nPos ) &&
405*cdf0e10cSrcweir                      !read_argument( &copyright, info_copyright, &nPos ) &&
406*cdf0e10cSrcweir                      !read_argument( &trademark, info_trademark, &nPos ) &&
407*cdf0e10cSrcweir                      !read_argument( &keyfile, info_keyfile, &nPos ) &&
408*cdf0e10cSrcweir                      !read_argument( &delaySign, info_delaySign, &nPos ))
409*cdf0e10cSrcweir             {
410*cdf0e10cSrcweir                 if ( osl_getCommandArg( nPos, &cmd_arg.pData ) !=
411*cdf0e10cSrcweir                      osl_Process_E_None )
412*cdf0e10cSrcweir                 {
413*cdf0e10cSrcweir                     OSL_ASSERT( false );
414*cdf0e10cSrcweir                 }
415*cdf0e10cSrcweir                 ++nPos;
416*cdf0e10cSrcweir                 cmd_arg = cmd_arg.trim();
417*cdf0e10cSrcweir                 if (cmd_arg.getLength() > 0)
418*cdf0e10cSrcweir                 {
419*cdf0e10cSrcweir                     if (cmd_arg[ 0 ] == '-') // is option
420*cdf0e10cSrcweir                     {
421*cdf0e10cSrcweir                         OptionInfo const * option_info = 0;
422*cdf0e10cSrcweir                         if (cmd_arg.getLength() > 2 &&
423*cdf0e10cSrcweir                             cmd_arg[ 1 ] == '-')
424*cdf0e10cSrcweir                         {
425*cdf0e10cSrcweir                             // long option
426*cdf0e10cSrcweir                             option_info = get_option_info(
427*cdf0e10cSrcweir                                 cmd_arg.copy( 2 ), '\0' );
428*cdf0e10cSrcweir                         }
429*cdf0e10cSrcweir                         else if (cmd_arg.getLength() == 2 &&
430*cdf0e10cSrcweir                                  cmd_arg[ 1 ] != '-')
431*cdf0e10cSrcweir                         {
432*cdf0e10cSrcweir                             // short option
433*cdf0e10cSrcweir                             option_info = get_option_info(
434*cdf0e10cSrcweir                                 OUString(), cmd_arg[ 1 ] );
435*cdf0e10cSrcweir                         }
436*cdf0e10cSrcweir                         if (option_info == 0)
437*cdf0e10cSrcweir                         {
438*cdf0e10cSrcweir                             OUStringBuffer buf;
439*cdf0e10cSrcweir                             buf.appendAscii(
440*cdf0e10cSrcweir                                 RTL_CONSTASCII_STRINGPARAM("unknown option ") );
441*cdf0e10cSrcweir                             buf.append( cmd_arg );
442*cdf0e10cSrcweir                             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
443*cdf0e10cSrcweir                                                  "!  Use climaker --help "
444*cdf0e10cSrcweir                                                  "to print all options.") );
445*cdf0e10cSrcweir                             throw RuntimeException(
446*cdf0e10cSrcweir                                 buf.makeStringAndClear(),
447*cdf0e10cSrcweir                                 Reference< XInterface >() );
448*cdf0e10cSrcweir                         }
449*cdf0e10cSrcweir                         else
450*cdf0e10cSrcweir                         {
451*cdf0e10cSrcweir                             OSL_ENSURE( 0, "unhandled valid option?!" );
452*cdf0e10cSrcweir                             if (option_info->m_has_argument)
453*cdf0e10cSrcweir                                 ++nPos;
454*cdf0e10cSrcweir                         }
455*cdf0e10cSrcweir                     }
456*cdf0e10cSrcweir                     else
457*cdf0e10cSrcweir                     {
458*cdf0e10cSrcweir                         mandatory_registries.push_back(
459*cdf0e10cSrcweir                             path_make_absolute_file_url( cmd_arg ) );
460*cdf0e10cSrcweir                     }
461*cdf0e10cSrcweir                 }
462*cdf0e10cSrcweir             }
463*cdf0e10cSrcweir         }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir         // bootstrap uno
466*cdf0e10cSrcweir         xContext = ::cppu::bootstrap_InitialComponentContext(
467*cdf0e10cSrcweir             Reference< registry::XSimpleRegistry >() );
468*cdf0e10cSrcweir         Reference< container::XHierarchicalNameAccess > xTDmgr(
469*cdf0e10cSrcweir             xContext->getValueByName(
470*cdf0e10cSrcweir                 OUSTR("/singletons/com.sun.star.reflection."
471*cdf0e10cSrcweir                       "theTypeDescriptionManager") ),
472*cdf0e10cSrcweir             UNO_QUERY_THROW );
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir         // get rdb tdprovider factory
475*cdf0e10cSrcweir         Reference< lang::XSingleComponentFactory > xTDprov_factory(
476*cdf0e10cSrcweir             ::cppu::loadSharedLibComponentFactory(
477*cdf0e10cSrcweir                 OUSTR("bootstrap.uno" SAL_DLLEXTENSION), OUString(),
478*cdf0e10cSrcweir                 OUSTR("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider"),
479*cdf0e10cSrcweir                 Reference< lang::XMultiServiceFactory >(
480*cdf0e10cSrcweir                     xContext->getServiceManager(), UNO_QUERY ),
481*cdf0e10cSrcweir                 Reference< registry::XRegistryKey >() ), UNO_QUERY );
482*cdf0e10cSrcweir         if (! xTDprov_factory.is())
483*cdf0e10cSrcweir         {
484*cdf0e10cSrcweir             throw RuntimeException(
485*cdf0e10cSrcweir                 OUSTR("cannot get registry typedescription provider: "
486*cdf0e10cSrcweir                       "bootstrap.uno" SAL_DLLEXTENSION "!"),
487*cdf0e10cSrcweir                 Reference< XInterface >() );
488*cdf0e10cSrcweir         }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir         // create registry td provider for mandatory registry files
491*cdf0e10cSrcweir         Any arg( makeAny( open_registries( mandatory_registries, xContext ) ) );
492*cdf0e10cSrcweir         Reference< XInterface > xTD_provider(
493*cdf0e10cSrcweir             xTDprov_factory->createInstanceWithArgumentsAndContext(
494*cdf0e10cSrcweir                 Sequence< Any >( &arg, 1 ), xContext ) );
495*cdf0e10cSrcweir         // insert provider to tdmgr
496*cdf0e10cSrcweir         Reference< container::XSet > xSet( xTDmgr, UNO_QUERY_THROW );
497*cdf0e10cSrcweir         Any provider( makeAny( xTD_provider ) );
498*cdf0e10cSrcweir         xSet->insert( provider );
499*cdf0e10cSrcweir         OSL_ASSERT( xSet->has( provider ) );
500*cdf0e10cSrcweir         if (! extra_registries.empty())
501*cdf0e10cSrcweir         {
502*cdf0e10cSrcweir             arg = makeAny( open_registries( extra_registries, xContext ) );
503*cdf0e10cSrcweir             provider = makeAny(
504*cdf0e10cSrcweir                 xTDprov_factory->createInstanceWithArgumentsAndContext(
505*cdf0e10cSrcweir                     Sequence< Any >( &arg, 1 ), xContext ) );
506*cdf0e10cSrcweir             xSet->insert( provider );
507*cdf0e10cSrcweir             OSL_ASSERT( xSet->has( provider ) );
508*cdf0e10cSrcweir         }
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir         if (0 == output.getLength()) // no output file specified
511*cdf0e10cSrcweir         {
512*cdf0e10cSrcweir             // if only one rdb has been given, then take rdb name
513*cdf0e10cSrcweir             if (1 == mandatory_registries.size())
514*cdf0e10cSrcweir             {
515*cdf0e10cSrcweir                 output = mandatory_registries[ 0 ];
516*cdf0e10cSrcweir                 output = output.copy( output.lastIndexOf( '/' ) +1 );
517*cdf0e10cSrcweir                 sal_Int32 dot = output.lastIndexOf( '.' );
518*cdf0e10cSrcweir                 if (dot > 0)
519*cdf0e10cSrcweir                     output = output.copy( 0, dot );
520*cdf0e10cSrcweir             }
521*cdf0e10cSrcweir             else
522*cdf0e10cSrcweir             {
523*cdf0e10cSrcweir                 output = OUSTR("cli_unotypes");
524*cdf0e10cSrcweir             }
525*cdf0e10cSrcweir         }
526*cdf0e10cSrcweir         output = path_make_absolute_file_url( output );
527*cdf0e10cSrcweir         sal_Int32 slash = output.lastIndexOf( '/' );
528*cdf0e10cSrcweir         OUString sys_output_dir;
529*cdf0e10cSrcweir         if (FileBase::E_None != FileBase::getSystemPathFromFileURL(
530*cdf0e10cSrcweir                 output.copy( 0, slash ), sys_output_dir ))
531*cdf0e10cSrcweir         {
532*cdf0e10cSrcweir             throw RuntimeException(
533*cdf0e10cSrcweir                 OUSTR("cannot get system path from file url ") +
534*cdf0e10cSrcweir                 output.copy( 0, slash ),
535*cdf0e10cSrcweir                 Reference< XInterface >() );
536*cdf0e10cSrcweir         }
537*cdf0e10cSrcweir         OUString filename( output.copy( slash +1 ) );
538*cdf0e10cSrcweir         sal_Int32 dot = filename.lastIndexOf( '.' );
539*cdf0e10cSrcweir         OUString name( filename );
540*cdf0e10cSrcweir         if (dot < 0) // has no extension
541*cdf0e10cSrcweir             filename += OUSTR(".dll");
542*cdf0e10cSrcweir         else
543*cdf0e10cSrcweir             name = name.copy( 0, dot );
544*cdf0e10cSrcweir         ::System::String * output_dir = ustring_to_String( sys_output_dir );
545*cdf0e10cSrcweir         ::System::String * output_file = ustring_to_String( filename );
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir         //Get the key pair for making a strong name
548*cdf0e10cSrcweir         StrongNameKeyPair* kp = NULL;
549*cdf0e10cSrcweir         if (keyfile.getLength() > 0)
550*cdf0e10cSrcweir         {
551*cdf0e10cSrcweir             ::System::String * sKeyFile = ustring_to_String(keyfile);
552*cdf0e10cSrcweir             try {
553*cdf0e10cSrcweir                 System::IO::FileStream* fs = new System::IO::FileStream(
554*cdf0e10cSrcweir                     sKeyFile, System::IO::FileMode::Open);
555*cdf0e10cSrcweir                 kp = new StrongNameKeyPair(fs);
556*cdf0e10cSrcweir                 fs->Close();
557*cdf0e10cSrcweir             }
558*cdf0e10cSrcweir             catch (System::IO::FileNotFoundException * )
559*cdf0e10cSrcweir             {
560*cdf0e10cSrcweir                 throw Exception(OUSTR("Could not find the keyfile. Verify the --keyfile argument!"), 0);
561*cdf0e10cSrcweir             }
562*cdf0e10cSrcweir         }
563*cdf0e10cSrcweir         else
564*cdf0e10cSrcweir         {
565*cdf0e10cSrcweir             if (g_verbose)
566*cdf0e10cSrcweir             {
567*cdf0e10cSrcweir                 ::System::Console::Write(
568*cdf0e10cSrcweir                     S"> no key file specified. Cannot create strong name!\n");
569*cdf0e10cSrcweir             }
570*cdf0e10cSrcweir         }
571*cdf0e10cSrcweir         // setup assembly info: xxx todo set more? e.g. avoid strong versioning
572*cdf0e10cSrcweir         AssemblyName * assembly_name = new AssemblyName();
573*cdf0e10cSrcweir         assembly_name->set_CodeBase( output_dir );
574*cdf0e10cSrcweir         assembly_name->set_Name( name );
575*cdf0e10cSrcweir         if (kp != NULL)
576*cdf0e10cSrcweir             assembly_name->set_KeyPair(kp);
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir         if (version.getLength() != 0)
579*cdf0e10cSrcweir         {
580*cdf0e10cSrcweir             assembly_name->set_Version(
581*cdf0e10cSrcweir                 new ::System::Version( ustring_to_String( version ) ) );
582*cdf0e10cSrcweir         }
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir         // app domain
585*cdf0e10cSrcweir         ::System::AppDomain * current_appdomain =
586*cdf0e10cSrcweir               ::System::AppDomain::get_CurrentDomain();
587*cdf0e10cSrcweir         // target assembly
588*cdf0e10cSrcweir         Emit::AssemblyBuilder * assembly_builder =
589*cdf0e10cSrcweir             current_appdomain->DefineDynamicAssembly(
590*cdf0e10cSrcweir                 assembly_name, Emit::AssemblyBuilderAccess::Save, output_dir );
591*cdf0e10cSrcweir         if (product.getLength() != 0)
592*cdf0e10cSrcweir         {
593*cdf0e10cSrcweir             ::System::Type * params __gc [] = new ::System::Type * __gc [ 1 ];
594*cdf0e10cSrcweir             ::System::Object * args __gc [] = new ::System::Object * __gc [ 1 ];
595*cdf0e10cSrcweir             params[ 0 ] = __typeof (::System::String);
596*cdf0e10cSrcweir             args[ 0 ] = ustring_to_String( product );
597*cdf0e10cSrcweir             assembly_builder->SetCustomAttribute(
598*cdf0e10cSrcweir                 new Emit::CustomAttributeBuilder(
599*cdf0e10cSrcweir                     __typeof (AssemblyProductAttribute)->GetConstructor(
600*cdf0e10cSrcweir                         params ), args ) );
601*cdf0e10cSrcweir         }
602*cdf0e10cSrcweir         if (description.getLength() != 0)
603*cdf0e10cSrcweir         {
604*cdf0e10cSrcweir             ::System::Type * params __gc [] = new ::System::Type * __gc [ 1 ];
605*cdf0e10cSrcweir             ::System::Object * args __gc [] = new ::System::Object * __gc [ 1 ];
606*cdf0e10cSrcweir             params[ 0 ] = __typeof (::System::String);
607*cdf0e10cSrcweir             args[ 0 ] = ustring_to_String( description );
608*cdf0e10cSrcweir             assembly_builder->SetCustomAttribute(
609*cdf0e10cSrcweir                 new Emit::CustomAttributeBuilder(
610*cdf0e10cSrcweir                     __typeof (AssemblyDescriptionAttribute)->GetConstructor(
611*cdf0e10cSrcweir                         params ), args ) );
612*cdf0e10cSrcweir         }
613*cdf0e10cSrcweir         if (company.getLength() != 0)
614*cdf0e10cSrcweir         {
615*cdf0e10cSrcweir             ::System::Type * params __gc [] = new ::System::Type * __gc [ 1 ];
616*cdf0e10cSrcweir             ::System::Object * args __gc [] = new ::System::Object * __gc [ 1 ];
617*cdf0e10cSrcweir             params[ 0 ] = __typeof (::System::String);
618*cdf0e10cSrcweir             args[ 0 ] = ustring_to_String( company );
619*cdf0e10cSrcweir             assembly_builder->SetCustomAttribute(
620*cdf0e10cSrcweir                 new Emit::CustomAttributeBuilder(
621*cdf0e10cSrcweir                     __typeof (AssemblyCompanyAttribute)->GetConstructor(
622*cdf0e10cSrcweir                         params ), args ) );
623*cdf0e10cSrcweir         }
624*cdf0e10cSrcweir         if (copyright.getLength() != 0)
625*cdf0e10cSrcweir         {
626*cdf0e10cSrcweir             ::System::Type * params __gc [] = new ::System::Type * __gc [ 1 ];
627*cdf0e10cSrcweir             ::System::Object * args __gc [] = new ::System::Object * __gc [ 1 ];
628*cdf0e10cSrcweir             params[ 0 ] = __typeof (::System::String);
629*cdf0e10cSrcweir             args[ 0 ] = ustring_to_String( copyright );
630*cdf0e10cSrcweir             assembly_builder->SetCustomAttribute(
631*cdf0e10cSrcweir                 new Emit::CustomAttributeBuilder(
632*cdf0e10cSrcweir                     __typeof (AssemblyCopyrightAttribute)->GetConstructor(
633*cdf0e10cSrcweir                         params ), args ) );
634*cdf0e10cSrcweir         }
635*cdf0e10cSrcweir         if (trademark.getLength() != 0)
636*cdf0e10cSrcweir         {
637*cdf0e10cSrcweir             ::System::Type * params __gc [] = new ::System::Type * __gc [ 1 ];
638*cdf0e10cSrcweir             ::System::Object * args __gc [] = new ::System::Object * __gc [ 1 ];
639*cdf0e10cSrcweir             params[ 0 ] = __typeof (::System::String);
640*cdf0e10cSrcweir             args[ 0 ] = ustring_to_String( trademark );
641*cdf0e10cSrcweir             assembly_builder->SetCustomAttribute(
642*cdf0e10cSrcweir                 new Emit::CustomAttributeBuilder(
643*cdf0e10cSrcweir                     __typeof (AssemblyTrademarkAttribute)->GetConstructor(
644*cdf0e10cSrcweir                         params ), args ) );
645*cdf0e10cSrcweir         }
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir         // load extra assemblies
648*cdf0e10cSrcweir         Assembly * assemblies __gc [] =
649*cdf0e10cSrcweir             new Assembly * __gc [ extra_assemblies.size() ];
650*cdf0e10cSrcweir         for ( size_t pos = 0; pos < extra_assemblies.size(); ++pos )
651*cdf0e10cSrcweir         {
652*cdf0e10cSrcweir             assemblies[ pos ] = Assembly::LoadFrom(
653*cdf0e10cSrcweir                 ustring_to_String( extra_assemblies[ pos ] ) );
654*cdf0e10cSrcweir         }
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir         // type emitter
657*cdf0e10cSrcweir         TypeEmitter * type_emitter = new TypeEmitter(
658*cdf0e10cSrcweir             assembly_builder->DefineDynamicModule( output_file ), assemblies );
659*cdf0e10cSrcweir         // add handler resolving assembly's types
660*cdf0e10cSrcweir         ::System::ResolveEventHandler * type_resolver =
661*cdf0e10cSrcweir               new ::System::ResolveEventHandler(
662*cdf0e10cSrcweir                   type_emitter, &TypeEmitter::type_resolve );
663*cdf0e10cSrcweir         current_appdomain->add_TypeResolve( type_resolver );
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir         // and emit types to it
666*cdf0e10cSrcweir         if (explicit_types.empty())
667*cdf0e10cSrcweir         {
668*cdf0e10cSrcweir             Reference< reflection::XTypeDescriptionEnumeration > xTD_enum(
669*cdf0e10cSrcweir                 Reference< reflection::XTypeDescriptionEnumerationAccess >(
670*cdf0e10cSrcweir                     xTD_provider, UNO_QUERY_THROW )
671*cdf0e10cSrcweir                   ->createTypeDescriptionEnumeration(
672*cdf0e10cSrcweir                       OUString() /* all IDL modules */,
673*cdf0e10cSrcweir                       Sequence< TypeClass >() /* all classes of types */,
674*cdf0e10cSrcweir                       reflection::TypeDescriptionSearchDepth_INFINITE ) );
675*cdf0e10cSrcweir             while (xTD_enum->hasMoreElements())
676*cdf0e10cSrcweir             {
677*cdf0e10cSrcweir                 type_emitter->get_type( xTD_enum->nextTypeDescription() );
678*cdf0e10cSrcweir             }
679*cdf0e10cSrcweir         }
680*cdf0e10cSrcweir         else
681*cdf0e10cSrcweir         {
682*cdf0e10cSrcweir             Reference< container::XHierarchicalNameAccess > xHNA(
683*cdf0e10cSrcweir                 xTD_provider, UNO_QUERY_THROW );
684*cdf0e10cSrcweir             for ( size_t nPos = explicit_types.size(); nPos--; )
685*cdf0e10cSrcweir             {
686*cdf0e10cSrcweir                 type_emitter->get_type(
687*cdf0e10cSrcweir                     Reference< reflection::XTypeDescription >(
688*cdf0e10cSrcweir                         xHNA->getByHierarchicalName( explicit_types[ nPos ] ),
689*cdf0e10cSrcweir                         UNO_QUERY_THROW ) );
690*cdf0e10cSrcweir             }
691*cdf0e10cSrcweir         }
692*cdf0e10cSrcweir         type_emitter->Dispose();
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir         if (g_verbose)
695*cdf0e10cSrcweir         {
696*cdf0e10cSrcweir             ::System::Console::Write(
697*cdf0e10cSrcweir                 S"> saving assembly {0}{1}{2}...",
698*cdf0e10cSrcweir                 output_dir,
699*cdf0e10cSrcweir                 new ::System::String(
700*cdf0e10cSrcweir                     ::System::IO::Path::DirectorySeparatorChar, 1 ),
701*cdf0e10cSrcweir                 output_file );
702*cdf0e10cSrcweir         }
703*cdf0e10cSrcweir         assembly_builder->Save( output_file );
704*cdf0e10cSrcweir         if (g_verbose)
705*cdf0e10cSrcweir         {
706*cdf0e10cSrcweir             ::System::Console::WriteLine( S"ok." );
707*cdf0e10cSrcweir         }
708*cdf0e10cSrcweir         current_appdomain->remove_TypeResolve( type_resolver );
709*cdf0e10cSrcweir 	}
710*cdf0e10cSrcweir 	catch (Exception & exc)
711*cdf0e10cSrcweir 	{
712*cdf0e10cSrcweir         OString msg(
713*cdf0e10cSrcweir             OUStringToOString( exc.Message, osl_getThreadTextEncoding() ) );
714*cdf0e10cSrcweir         fprintf(
715*cdf0e10cSrcweir             stderr, "\n> error: %s\n> dying abnormally...\n", msg.getStr() );
716*cdf0e10cSrcweir         ret = 1;
717*cdf0e10cSrcweir 	}
718*cdf0e10cSrcweir 	catch (::System::Exception * exc)
719*cdf0e10cSrcweir 	{
720*cdf0e10cSrcweir         OString msg( OUStringToOString(
721*cdf0e10cSrcweir                          String_to_ustring( exc->ToString() ),
722*cdf0e10cSrcweir                          osl_getThreadTextEncoding() ) );
723*cdf0e10cSrcweir         fprintf(
724*cdf0e10cSrcweir             stderr,
725*cdf0e10cSrcweir             "\n> error: .NET exception occured: %s\n> dying abnormally...",
726*cdf0e10cSrcweir             msg.getStr() );
727*cdf0e10cSrcweir         ret = 1;
728*cdf0e10cSrcweir 	}
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir     try
731*cdf0e10cSrcweir     {
732*cdf0e10cSrcweir         Reference< lang::XComponent > xComp( xContext, UNO_QUERY );
733*cdf0e10cSrcweir         if (xComp.is())
734*cdf0e10cSrcweir             xComp->dispose();
735*cdf0e10cSrcweir     }
736*cdf0e10cSrcweir 	catch (Exception & exc)
737*cdf0e10cSrcweir 	{
738*cdf0e10cSrcweir         OString msg(
739*cdf0e10cSrcweir             OUStringToOString( exc.Message, osl_getThreadTextEncoding() ) );
740*cdf0e10cSrcweir         fprintf(
741*cdf0e10cSrcweir             stderr,
742*cdf0e10cSrcweir             "\n> error disposing component context: %s\n"
743*cdf0e10cSrcweir             "> dying abnormally...\n",
744*cdf0e10cSrcweir             msg.getStr() );
745*cdf0e10cSrcweir 		ret = 1;
746*cdf0e10cSrcweir 	}
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir 	return ret;
749*cdf0e10cSrcweir }
750