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: dependy.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 ************************************************************************/
32 #include "dependy.hxx"
34 #include "../support/syshelp.hxx"
35 #include "../support/list.hxx"
36 #include "../xcd/xmltree.hxx"
37 #include "../xcd/parse.hxx"
41 Simstr
ShortName(const Simstr
& i_rService
);
45 Service::Service( const char * i_sName
)
52 Service::AddImplementation( const char * i_sLibrary
)
54 ServiceInfo
* ret
= new ServiceInfo(i_sLibrary
);
55 aImplementations
.push_back(ret
);
59 ServiceInfo::ServiceInfo( const char * i_sLibrary
)
60 : sImplementingLibrary(i_sLibrary
)
66 ServiceInfo::AddDependency( const char * i_sNeededService
)
68 aNeededServices
.push_back(i_sNeededService
);
71 DependencyFinder::DependencyFinder()
75 DependencyFinder::~DependencyFinder()
80 DependencyFinder::GatherData( const char * i_sSearchDirectory
)
83 GatherFileNames( aFiles
, i_sSearchDirectory
);
85 for ( unsigned i
= 0; i
< aFiles
.size(); ++i
)
87 ReadFile( aFiles
[i
].str() );
92 DependencyFinder::FindNeededServices( StringVector
& o_rLibraries
,
93 StringVector
& o_rServices
,
94 const Simstr
& i_rService
)
96 Map_Services::const_iterator itService
= aServices
.find(i_rService
);
97 if ( itService
== aServices
.end() )
99 std::cerr
<< "Error: Service \""
106 aResult_Libraries
.erase( aResult_Libraries
.begin(), aResult_Libraries
.end() );
107 aResult_Services
.erase( aResult_Services
.begin(), aResult_Services
.end() );
109 // const ServiceInfo & rSInfo = (*itService).second->FirstImplementation();
110 Add2Result( *(*itService
).second
);
112 for ( std::set
< Simstr
>::const_iterator il
= aResult_Libraries
.begin();
113 il
!= aResult_Libraries
.end();
116 o_rLibraries
.push_back(*il
);
119 for ( std::set
< Simstr
>::const_iterator is
= aResult_Services
.begin();
120 is
!= aResult_Services
.end();
123 o_rServices
.push_back(*is
);
128 DependencyFinder::ReadFile( const char * i_sFilename
)
130 ModuleDescription aModule
;
131 X2CParser
aParser(aModule
);
133 if ( !aParser
.Parse(i_sFilename
) )
135 std::cerr
<< "Error: File \""
137 << "\" could not be parsed."
143 Simstr sModule
= aModule
.ModuleName();
145 List
< const MultipleTextElement
* > aImplServices
;
146 List
< const MultipleTextElement
* > aNeededServices
;
148 aModule
.Get_SupportedServices(aImplServices
);
149 aModule
.Get_ServiceDependencies(aNeededServices
);
151 unsigned nImplServicesSize
= aImplServices
.size();
152 unsigned nNeededServicesSize
= aNeededServices
.size();
154 for ( unsigned i
= 0; i
< nImplServicesSize
; ++i
)
156 const MultipleTextElement
& rImpl
= *aImplServices
[i
];
158 unsigned nImplDataSize
= rImpl
.Size();
159 for ( unsigned di
= 0; di
< nImplDataSize
; ++di
)
161 Simstr sService
= ShortName(rImpl
.Data(di
));
162 Service
* pService
= aServices
[sService
];
165 pService
= new Service(rImpl
.Data(di
));
166 aServices
[sService
] = pService
;
168 ServiceInfo
& rSInfo
= pService
->AddImplementation(sModule
);
170 for ( unsigned n
= 0; n
< nNeededServicesSize
; ++n
)
172 unsigned nNeededDataSize
= aNeededServices
[n
]->Size();
173 for ( unsigned dn
= 0; dn
< nNeededDataSize
; ++dn
)
175 if (! aNeededServices
[n
]->Data(dn
).is_no_text())
176 rSInfo
.AddDependency( ShortName(aNeededServices
[n
]->Data(dn
)) );
184 DependencyFinder::Add2Result( const Service
& i_rService
)
186 const ServiceInfo
& rSInfo
= i_rService
.FirstImplementation();
187 aResult_Libraries
.insert(rSInfo
.Library());
189 const ServiceInfo::List_NeededServices
& rNeededs
190 = rSInfo
.NeededServices();
191 for ( StringVector::const_iterator it
= rNeededs
.begin();
192 it
!= rNeededs
.end();
195 std::pair
< std::set
< Simstr
>::iterator
, bool > aInsertResult
196 = aResult_Services
.insert(*it
);
197 if (aInsertResult
.second
)
198 { // Needed service not yet known
199 Map_Services::const_iterator itFound
= aServices
.find(*it
);
200 if ( itFound
== aServices
.end() )
202 std::cerr
<< "Needed service \""
209 Add2Result( *(*itFound
).second
);
211 } // endif (! aInsertResult.second)
218 ShortName(const Simstr
& i_rService
)
220 const char * pStart
= i_rService
.str();
221 const char * pEnd
= strchr(pStart
,' ');
223 return Simstr(pStart
, 0, int(pEnd
-pStart
));