1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XmlBuildList.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <EXTERN.h> /* from the Perl distribution */
34 #include <tools/prewin.h>
36 #include <tools/postwin.h>
40 #undef Copy /* from Perl handy.h */
42 #include <soldep/XmlBuildList.hxx>
43 #include "XmlBuildListDef.hxx"
46 # define EXTERN_C extern "C"
48 # define EXTERN_C extern
51 static PerlInterpreter
*my_perl
; /*** The Perl interpreter ***/
52 static const char * DEP_MD_SIMPLE_STR
= "md-simple";
54 EXTERN_C
void boot_DynaLoader (pTHX_ CV
* cv
);
55 static void xs_init (pTHX
);
56 static void dl_init (pTHX
);
58 static void xs_init(pTHX
)
60 char *file
= __FILE__
;
63 /* DynaLoader is a special case */
64 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader
, file
);
68 static void dl_init(pTHX
)
70 char *file
= __FILE__
;
73 /* Dynamicboot strapping code*/
77 /* end Dynamic bootstrapping code */
79 *file
=0; // how does this works???
84 FullByteStringList::FullByteStringList()
85 : FullByteStingListImpl(),
90 FullByteStringList::~FullByteStringList()
92 ByteString
* pStr
= First();
100 ULONG
FullByteStringList::GetPos (ByteString
& rStr
)
102 ULONG nCurPos
= GetCurPos();
104 ByteString
* pStr
= First();
116 return LIST_ENTRY_NOTFOUND
;
119 FullByteStringListWrapper
& FullByteStringListWrapper::operator=( const FullByteStringListWrapper
& rFullByteStringListWrapper
)
122 if (pStringList
->GetRef() == 0)
125 pStringList
->DecRef();
127 pStringList
= rFullByteStringListWrapper
.GetStringList();
129 pStringList
->IncRef();
133 FullByteStringListWrapper::~FullByteStringListWrapper ()
137 if (pStringList
->GetRef() == 0)
140 pStringList
->DecRef();
145 // Function initializes Perl
146 // ATTENTION: No check built in - YET TO DO
148 void XmlBuildList::initPerl(const char* ModulePath
) {
151 my_perl
= perl_alloc();
153 throw XmlBuildListException("Cannot initialize perl");
154 perl_construct(my_perl
);
155 char* embedding
[] = {"", "-e", "0"};
156 int exitstatus
= perl_parse(my_perl
, xs_init
, 3, embedding
, (char **)NULL
);
159 exitstatus
= perl_run(my_perl
);
162 // Create a variable (s. perlguts)
163 SV
* sv
= get_sv("main::module_path", TRUE
);
164 sv_setpv(sv
, ModulePath
);
165 eval_pv("use lib $main::module_path; use XMLBuildListParser;", FALSE
);
166 checkOperationSuccess();
167 eval_pv("$main::build_lst_obj = XMLBuildListParser->new();", FALSE
);
168 checkOperationSuccess();
169 eval_pv("@array = ();", FALSE
);
170 checkOperationSuccess();
171 PerlInitialized
= TRUE
;
174 // Function proves if the $@ perl variable is set, if yes -
175 // last operation was unsuccessfull -> throws exception
176 void XmlBuildList::checkOperationSuccess() {
177 char* op_result
= SvPV_nolen(get_sv("main::@", FALSE
));
178 if (strcmp(op_result
, ""))
179 throw XmlBuildListException(op_result
);
183 // Function generates a regular array with NULL as last element
184 // from the Perl-object @array
186 FullByteStringList
* XmlBuildList::extractArray() {
187 FullByteStringList
* pStringList
= new FullByteStringList();
188 AV
* theArrayObj
= get_av("main::array", FALSE
);
189 I32 arrayLength
= av_len(theArrayObj
); // $#array value
190 if (arrayLength
== -1)
195 // populate vector with strings (char*)
196 for (int i
= 0; i
<= arrayLength
; i
++) {
197 string_ptr
= av_fetch(theArrayObj
, i
, NULL
);
198 //pStoredString = savepv(SvPV_nolen(*string_ptr));
199 pStoredString
= SvPV_nolen(*string_ptr
);
200 ByteString
* pStr
= new ByteString(pStoredString
);
201 pStringList
->Insert(pStr
, LIST_APPEND
);
207 char* XmlBuildList::getError() {
208 eval_pv("$main::string1 = $main::build_lst_obj->getError();", FALSE
);
209 checkOperationSuccess();
210 return SvPV_nolen(get_sv("main::string1", FALSE
));
213 /*****************************************************************************/
214 XmlBuildList::XmlBuildList(const ByteString
& rModulePath
)
215 /*****************************************************************************/
216 : PerlInitialized (FALSE
)
218 initPerl(rModulePath
.GetBuffer());
219 string_obj1
= get_sv("main::string1", TRUE
);
220 string_obj2
= get_sv("main::string2", TRUE
);
221 string_obj3
= get_sv("main::string3", TRUE
);
222 if (!(string_obj1
&& string_obj2
&& string_obj3
))
223 throw XmlBuildListException("Cannot initialize Perl string objects");
227 // Function uninitializes Perl
229 /*****************************************************************************/
230 XmlBuildList::~XmlBuildList()
231 /*****************************************************************************/
233 if (!PerlInitialized
)
235 perl_destruct(my_perl
);
237 PerlInitialized
= FALSE
;
240 /*****************************************************************************/
241 void XmlBuildList::loadXMLFile(const ByteString
& rBuildList
)
242 /*****************************************************************************/
244 sv_setpv(string_obj1
, rBuildList
.GetBuffer());
245 eval_pv("$main::string2 = $main::build_lst_obj->loadXMLFile($main::string1);", FALSE
);
246 checkOperationSuccess();
247 if(!SvTRUE(string_obj2
)) {
248 const char* Message
= getError();
249 throw XmlBuildListException(Message
);
253 /*****************************************************************************/
254 FullByteStringListWrapper
XmlBuildList::getProducts()
255 /*****************************************************************************/
257 eval_pv("@array = $main::build_lst_obj->getProducts();", FALSE
);
258 checkOperationSuccess();
259 FullByteStringList
* pList
= extractArray();
260 return FullByteStringListWrapper(pList
);
263 /*****************************************************************************/
264 FullByteStringListWrapper
XmlBuildList::getJobDirectories(const ByteString
& rJobType
, const ByteString
& rJobPlatform
)
265 /*****************************************************************************/
267 sv_setpv(string_obj1
, rJobType
.GetBuffer());
268 sv_setpv(string_obj2
, rJobPlatform
.GetBuffer());
269 eval_pv("@array = $main::build_lst_obj->getJobDirectories($main::string1, $main::string2);", FALSE
);
270 checkOperationSuccess();
271 FullByteStringList
* pList
= extractArray();
272 return FullByteStringListWrapper(pList
);
275 /*****************************************************************************/
276 FullByteStringListWrapper
XmlBuildList::getModuleDependencies(const ByteString
& rProduct
, const ByteString
& rDependencyType
)
277 /*****************************************************************************/
279 FullByteStringList
* pProducts
= new FullByteStringList();
280 FullByteStringListWrapper
aProducts (pProducts
);
282 aProducts
.Insert (new ByteString(rProduct
), LIST_APPEND
);
283 return getModuleDependencies(aProducts
, rDependencyType
);
286 /*****************************************************************************/
287 FullByteStringListWrapper
XmlBuildList::getModuleDependencies(FullByteStringListWrapper
& rProducts
, const ByteString
& rDependencyType
)
288 /*****************************************************************************/
290 eval_pv("@products = ();", FALSE
);
291 checkOperationSuccess();
292 AV
* theArrayObj
= get_av("main::products", FALSE
);
293 FullByteStringList
* pProducts
= rProducts
.GetStringList();
294 ByteString
* pStr
= pProducts
->First();
297 sv_setpv(string_obj2
, pStr
->GetBuffer());
298 av_push(theArrayObj
, string_obj2
);
299 pStr
= pProducts
->Next();
302 sv_setpv(string_obj1
, rDependencyType
.GetBuffer());
303 eval_pv("@array = $main::build_lst_obj->getModuleDependencies(\\@products, $main::string1);", FALSE
);
304 checkOperationSuccess();
305 FullByteStringList
* pList
= extractArray();
306 return FullByteStringListWrapper(pList
);
309 /*****************************************************************************/
310 FullByteStringListWrapper
XmlBuildList::getJobBuildReqs(const ByteString
& rJobDir
, const ByteString
& rBuildReqPlatform
)
311 /*****************************************************************************/
313 sv_setpv(string_obj1
, rJobDir
.GetBuffer());
314 sv_setpv(string_obj2
, rBuildReqPlatform
.GetBuffer());
315 eval_pv("@array = $main::build_lst_obj->getJobBuildReqs($main::string1, $main::string2);", FALSE
);
316 checkOperationSuccess();
317 FullByteStringList
* pList
= extractArray();
318 return FullByteStringListWrapper(pList
);
321 /*****************************************************************************/
322 ByteString
XmlBuildList::getModuleDepType(const ByteString
& rDepModuleName
)
323 /*****************************************************************************/
325 sv_setpv(string_obj1
, rDepModuleName
.GetBuffer());
326 eval_pv("$main::string1 = $main::build_lst_obj->getModuleDepType($main::string1);", FALSE
);
327 checkOperationSuccess();
328 char* pString
= SvPV_nolen(get_sv("main::string1", FALSE
));
329 ByteString
sDependencyType(pString
);
330 return sDependencyType
;
333 /*****************************************************************************/
334 sal_Bool
XmlBuildList::hasModuleDepType(FullByteStringListWrapper
& rProducts
, const ByteString
& rDependencyType
)
335 /*****************************************************************************/
337 FullByteStringListWrapper aDepencendModules
= getModuleDependencies(rProducts
, rDependencyType
);
338 if (aDepencendModules
.Count()>0)
345 /*****************************************************************************/
346 FullByteStringListWrapper
XmlBuildList::getModuleDepTypes(FullByteStringListWrapper
& rProducts
)
347 /*****************************************************************************/
349 FullByteStringList
* pList
= new FullByteStringList();
351 ByteString aDepType
= ByteString( DEP_MD_SIMPLE_STR
);
352 bool bHasType
= hasModuleDepType(rProducts
, aDepType
);
354 pList
->Insert(new ByteString (aDepType
));
356 aDepType
= ByteString(DEP_MD_ALWAYS_STR
);
357 bHasType
= hasModuleDepType(rProducts
, aDepType
);
359 pList
->Insert(new ByteString (aDepType
));
361 aDepType
= ByteString(DEP_MD_FORCE_STR
);
362 bHasType
= hasModuleDepType(rProducts
, aDepType
);
364 pList
->Insert(new ByteString (aDepType
));
366 return FullByteStringListWrapper (pList
);
369 /*****************************************************************************/
370 FullByteStringListWrapper
XmlBuildList::getModuleProducts(const ByteString
& rDepModuleName
)
371 /*****************************************************************************/
373 sv_setpv(string_obj1
, rDepModuleName
.GetBuffer());
374 eval_pv("@array = $main::build_lst_obj->getModuleProducts($main::string1);", FALSE
);
375 checkOperationSuccess();
376 FullByteStringList
* pList
= extractArray();
377 return FullByteStringListWrapper(pList
);
380 /*****************************************************************************/
381 ByteString
XmlBuildList::getModuleName()
382 /*****************************************************************************/
384 eval_pv("$main::string1 = $main::build_lst_obj->getModuleName();", FALSE
);
385 checkOperationSuccess();
386 char* pString
= SvPV_nolen(get_sv("main::string1", FALSE
));
387 ByteString
sModuleName(pString
);
391 /*****************************************************************************/
392 FullByteStringListWrapper
XmlBuildList::getDirDependencies(const ByteString
& rJobDir
, const ByteString
& rJobType
, const ByteString
& rJobPlatform
)
393 /*****************************************************************************/
395 sv_setpv(string_obj1
, rJobDir
.GetBuffer());
396 sv_setpv(string_obj2
, rJobType
.GetBuffer());
397 sv_setpv(string_obj3
, rJobPlatform
.GetBuffer());
398 eval_pv("@array = $main::build_lst_obj->getDirDependencies($main::string1, $main::string2, $main::string3);", FALSE
);
399 checkOperationSuccess();
400 FullByteStringList
* pList
= extractArray();
401 return FullByteStringListWrapper(pList
);
404 /*****************************************************************************/
405 FullByteStringListWrapper
XmlBuildList::getJobTypes(const ByteString
& rJobDir
)
406 /*****************************************************************************/
408 sv_setpv(string_obj1
, rJobDir
.GetBuffer());
409 eval_pv("@array = $main::build_lst_obj->getJobTypes($main::string1);", FALSE
);
410 checkOperationSuccess();
411 FullByteStringList
* pList
= extractArray();
412 return FullByteStringListWrapper(pList
);
415 /*****************************************************************************/
416 FullByteStringListWrapper
XmlBuildList::getJobPlatforms(const ByteString
& rJobDir
)
417 /*****************************************************************************/
419 sv_setpv(string_obj1
, rJobDir
.GetBuffer());
420 eval_pv("@array = $main::build_lst_obj->getJobPlatforms($main::string1);", FALSE
);
421 checkOperationSuccess();
422 FullByteStringList
* pList
= extractArray();
423 return FullByteStringListWrapper(pList
);
426 /*****************************************************************************/
427 FullByteStringListWrapper
XmlBuildList::getJobBuildReqPlatforms(const ByteString
& rJobDir
, const ByteString
& rBuildReqName
)
428 /*****************************************************************************/
430 sv_setpv(string_obj1
, rJobDir
.GetBuffer());
431 sv_setpv(string_obj2
, rBuildReqName
.GetBuffer());
432 eval_pv("@array = $main::build_lst_obj->getJobBuildReqPlatforms($main::string1, $main::string2);", FALSE
);
433 checkOperationSuccess();
434 FullByteStringList
* pList
= extractArray();
435 return FullByteStringListWrapper(pList
);