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