1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include "prodmap.hxx"
29 #include <tools/geninfo.hxx>
30 #include <tools/fsys.hxx>
31 #include "minormk.hxx"
35 #define PRODUCT_KEY "TARGETDESCRIPTION/PRODUCTS"
36 #define DEPENDS_ON_KEY "TARGETDESCRIPTION/DEPENDSON"
37 #define BASED_ON_KEY "TARGETDESCRIPTION/BASEDON"
40 // class ProductMapper
43 /*****************************************************************************/
44 ProductMapper::ProductMapper()
45 /*****************************************************************************/
46 : pVersionList( NULL
),
51 /*****************************************************************************/
52 ProductMapper::ProductMapper( GenericInformationList
*pVerList
)
53 /*****************************************************************************/
54 : pVersionList( pVerList
),
58 CreateProductList( pVerList
);
61 /*****************************************************************************/
62 ProductMapper::~ProductMapper()
63 /*****************************************************************************/
68 /*****************************************************************************/
69 void ProductMapper::CreateProductList( GenericInformationList
*pVerList
)
70 /*****************************************************************************/
73 creates a list of the following format:
75 ProductName Workspace // 6.0 Final SRC641
77 DependsOn // DependsOn
95 pVersionList
= pVerList
;
98 ByteString
sProductKey( PRODUCT_KEY
);
99 ByteString
sDependsOnKey( DEPENDS_ON_KEY
);
100 ByteString
sBasedOnKey( BASED_ON_KEY
);
102 for ( ULONG i
= 0; i
< pVersionList
->Count(); i
++ ) {
103 GenericInformation
*pVersion
= pVersionList
->GetObject( i
);
105 GenericInformation
*pProducts
= pVersion
->GetSubInfo( sProductKey
, TRUE
);
107 ByteString sProducts
= pProducts
->GetValue();
109 ByteString sDependsOn
;
110 GenericInformation
*pDependsOn
= pVersion
->GetSubInfo( sDependsOnKey
, TRUE
);
112 sDependsOn
= pDependsOn
->GetValue();
115 GenericInformation
*pBasedOn
= pVersion
->GetSubInfo( sBasedOnKey
, TRUE
);
117 sBasedOn
= pBasedOn
->GetValue();
119 for ( USHORT x
= 0; x
< sProducts
.GetTokenCount( ';' ); x
++ ) {
120 ByteString
sProduct( sProducts
.GetToken( x
, ';' ));
121 if( sProduct
.Len()) {
123 pProductList
= new GenericInformationList();
125 pProductList
->InsertInfo( sProduct
, *pVersion
, TRUE
, TRUE
);
127 for ( USHORT y
= 0; y
< sDependsOn
.GetTokenCount( ';' ); y
++ ) {
128 ByteString sDependsOnKey_l
= sProduct
;
129 sDependsOnKey_l
+= "/DependsOn/";
130 sDependsOnKey_l
+= sDependsOn
.GetToken( y
, ';' );
132 pProductList
->InsertInfo( sDependsOnKey_l
, "", TRUE
, TRUE
);
134 for ( USHORT z
= 0; z
< sBasedOn
.GetTokenCount( ';' ); z
++ ) {
135 ByteString sBasedOnKey_l
= sProduct
;
136 sBasedOnKey_l
+= "/BasedOn/";
137 sBasedOnKey_l
+= sBasedOn
.GetToken( z
, ';' );
139 pProductList
->InsertInfo( sBasedOnKey_l
, "", TRUE
, TRUE
);
148 /*****************************************************************************/
149 USHORT
ProductMapper::GetProductInformation(
150 const ByteString
&rProduct
, GenericInformation
*& pProductInfo
)
151 /*****************************************************************************/
156 return PRODUCT_MAPPER_NO_VERSION_INFORMATION
;
159 return PRODUCT_MAPPER_NO_PRODUCT
;
161 ByteString
sProductKey( rProduct
);
162 pProductInfo
= pProductList
->GetInfo( sProductKey
, TRUE
);
165 return PRODUCT_MAPPER_NO_PRODUCT
;
167 return PRODUCT_MAPPER_OK
;
170 /*****************************************************************************/
171 USHORT
ProductMapper::PrintDependentTargets(
172 const ByteString
&rProduct
, USHORT nLevel
)
173 /*****************************************************************************/
175 GenericInformation
*pProductInfo
;
177 USHORT nReturn
= GetProductInformation( rProduct
, pProductInfo
);
179 if ( nReturn
== PRODUCT_MAPPER_OK
) {
180 for ( USHORT i
= 0; i
< nLevel
; i
++ )
181 fprintf( stdout
, " " );
182 fprintf( stdout
, "%s (%s)\n", pProductInfo
->GetBuffer(),
183 pProductInfo
->GetValue().GetBuffer());
184 aPrintedList
.PutString( new ByteString( *pProductInfo
));
186 for ( ULONG j
= 0; j
< pProductList
->Count(); j
++ ) {
187 GenericInformation
*pCandidate
= pProductList
->GetObject( j
);
188 ByteString
sKey( "DEPENDSON/" );
190 GenericInformation
*pDependsOn
= pCandidate
->GetSubInfo( sKey
, TRUE
);
192 PrintDependentTargets( *pCandidate
, nLevel
+ 1 );
195 ByteString
sKey( "BASEDON" );
196 GenericInformation
*pBasedOn
= pProductInfo
->GetSubInfo( sKey
);
198 GenericInformationList
*pBases
= pBasedOn
->GetSubList();
200 for ( ULONG k
= 0; k
< pBases
->Count(); k
++ ) {
201 aBaseList
.PutString( new ByteString( *pBases
->GetObject( k
)));
211 /*****************************************************************************/
212 USHORT
ProductMapper::PrintAndDeleteBaseList()
213 /*****************************************************************************/
215 if ( aBaseList
.Count()) {
216 fprintf( stdout
, "\nbased on\n" );
217 while ( aBaseList
.Count()) {
218 ByteString
sProduct( *aBaseList
.GetObject(( ULONG
) 0 ));
219 if ( aPrintedList
.IsString( aBaseList
.GetObject(( ULONG
) 0 )) == NOT_THERE
) {
220 aPrintedList
.PutString( aBaseList
.GetObject(( ULONG
) 0 ));
221 PrintDependentTargets( sProduct
);
224 delete aBaseList
.GetObject(( ULONG
) 0 );
226 aBaseList
.Remove(( ULONG
) 0 );
228 while ( aPrintedList
.Count())
229 delete aPrintedList
.Remove(( ULONG
) 0 );
231 fprintf( stdout
, "\n" );
233 return PRODUCT_MAPPER_OK
;
236 /*****************************************************************************/
237 USHORT
ProductMapper::PrintDependencies( const ByteString
&rProduct
)
238 /*****************************************************************************/
240 USHORT nResult
= PrintDependentTargets( rProduct
);
241 PrintAndDeleteBaseList();
245 /*****************************************************************************/
246 USHORT
ProductMapper::PrintProductList()
247 /*****************************************************************************/
250 return PRODUCT_MAPPER_NO_VERSION_INFORMATION
;
252 if ( !pProductList
|| !pProductList
->Count())
253 return PRODUCT_MAPPER_NO_PRODUCT
;
255 if ( pProductList
->Count()) {
256 for ( ULONG i
= 0; i
< pProductList
->Count(); i
++ )
257 fprintf( stdout
, "%s (%s)\n",
258 pProductList
->GetObject( i
)->GetBuffer(),
259 pProductList
->GetObject( i
)->GetValue().GetBuffer());
260 fprintf( stdout
, "\n" );
263 return PRODUCT_MAPPER_OK
;
266 /*****************************************************************************/
267 SByteStringList
*ProductMapper::GetMinorList(
268 const ByteString
&rVersion
, const ByteString
&rEnvironment
)
269 /*****************************************************************************/
271 SByteStringList
*pList
= NULL
;
273 if ( pVersionList
) {
274 String
sRoot( GetVersionRoot( pVersionList
, rVersion
));
276 DirEntry
aEntry( sRoot
);
277 aEntry
+= DirEntry( String( rEnvironment
, RTL_TEXTENCODING_ASCII_US
));
278 String
sWildcard( String::CreateFromAscii( "inc.*" ));
279 aEntry
+= DirEntry( sWildcard
);
281 Dir
aDir( aEntry
, FSYS_KIND_DIR
);
282 for ( USHORT i
= 0; i
< aDir
.Count(); i
++ ) {
283 ByteString
sInc( aDir
[ i
].GetName(), RTL_TEXTENCODING_ASCII_US
);
284 if ( sInc
.GetTokenCount( '.' ) > 1 ) {
286 pList
= new SByteStringList();
287 pList
->PutString( new ByteString( sInc
.GetToken( 1, '.' )));
295 /*****************************************************************************/
296 String
ProductMapper::GetVersionRoot(
297 GenericInformationList
*pList
, const ByteString
&rVersion
)
298 /*****************************************************************************/
300 ByteString
sKey( rVersion
);
301 GenericInformation
*pVersion
= pList
->GetInfo( sKey
);
304 sKey
= "drives/o:/unixvolume";
305 GenericInformation
*pUnixVolume
= pVersion
->GetSubInfo( sKey
, TRUE
);
308 sPath
= pUnixVolume
->GetValue();
311 ByteString
sPath( "o:\\" );
313 sKey
= "settings/path";
314 GenericInformation
*pPath
= pVersion
->GetSubInfo( sKey
, TRUE
);
316 sPath
+= pPath
->GetValue().GetToken( 0, '\\' );
320 sPath
.SearchAndReplaceAll( "\\", "/" );
321 while( sPath
.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND
) {};
323 sPath
.SearchAndReplaceAll( "/", "\\" );
324 while( sPath
.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND
) {};
327 return String( sPath
, RTL_TEXTENCODING_ASCII_US
);
332 /*****************************************************************************/
333 BaseProductList
*ProductMapper::GetBases(
334 GenericInformation
*pProductInfo
, USHORT nLevel
,
335 BaseProductList
*pBases
)
336 /*****************************************************************************/
339 pBases
= new BaseProductList();
341 if ( pProductInfo
) {
342 ByteString
sCandidate( *pProductInfo
);
344 sCandidate
+= pProductInfo
->GetValue();
347 ByteString
sKey( "BASEDON" );
348 GenericInformation
*pBasedOn
= pProductInfo
->GetSubInfo( sKey
);
350 GenericInformationList
*pBasesInfo
= pBasedOn
->GetSubList();
352 for ( ULONG k
= 0; k
< pBasesInfo
->Count(); k
++ ) {
353 GenericInformation
*pBaseProduct
;
354 if ( GetProductInformation( *pBasesInfo
->GetObject( k
), pBaseProduct
) == PRODUCT_MAPPER_OK
)
355 GetBases( pBaseProduct
, ++ nLevel
, pBases
);
360 ByteString
sUpperCandidate( sCandidate
);
361 sUpperCandidate
.ToUpperAscii();
362 for ( USHORT i
= 0; i
< pBases
->Count() && !bFound
; i
++ ) {
363 ByteString
sTest( *pBases
->GetObject( i
));
364 if ( sTest
.ToUpperAscii() == sUpperCandidate
)
368 pBases
->Insert( new ByteString( sCandidate
), ( ULONG
) 0 );
373 /*****************************************************************************/
374 USHORT
ProductMapper::PrintMinorList(
375 const ByteString rProduct
, const ByteString rEnvironment
)
376 /*****************************************************************************/
379 return PRODUCT_MAPPER_NO_VERSION_INFORMATION
;
381 if ( !pProductList
|| !pProductList
->Count())
382 return PRODUCT_MAPPER_NO_PRODUCT
;
384 GenericInformation
*pProductInfo
;
385 GetProductInformation( rProduct
, pProductInfo
);
387 return PRODUCT_MAPPER_NO_PRODUCT
;
389 BaseProductList
*pBases
= GetBases( pProductInfo
);
390 if ( pBases
->Count()) {
391 if ( pBases
->Count() > 1 )
392 fprintf( stdout
, "Product \"%s\" based on ", pBases
->GetObject(( ULONG
) 0 )->GetBuffer());
394 fprintf( stdout
, "Product \"%s\" based on no other products", pBases
->GetObject(( ULONG
) 0 )->GetBuffer());
396 for ( ULONG i
= 1; i
< pBases
->Count(); i
++ ) {
397 fprintf( stdout
, "\"%s\"", pBases
->GetObject( i
)->GetBuffer());
398 if ( i
< pBases
->Count() - 1 )
399 fprintf( stdout
, ", " );
401 fprintf( stdout
, "\n\n" );
403 USHORT nResult
= PRODUCT_MAPPER_OK
;
405 if ( rEnvironment
.Len())
406 nResult
= PrintSingleMinorList( pProductInfo
, pBases
, rEnvironment
);
408 ByteString
sEnvKey( pProductInfo
->GetValue());
409 sEnvKey
+= "/Environments";
411 GenericInformation
*pEnvironmentInfo
= pVersionList
->GetInfo( sEnvKey
, TRUE
);
412 if ( pEnvironmentInfo
) {
413 GenericInformationList
*pEnvironmentList
= pEnvironmentInfo
->GetSubList();
414 if ( pEnvironmentList
) {
415 for ( ULONG i
= 0; i
< pEnvironmentList
->Count(); i
++ ) {
416 USHORT nTmp
= PrintSingleMinorList( pProductInfo
, pBases
, *pEnvironmentList
->GetObject( i
));
417 if ( nTmp
!= PRODUCT_MAPPER_OK
)
424 for ( ULONG m
= 0; m
< pBases
->Count(); m
++ )
425 delete pBases
->GetObject( m
);
431 /*****************************************************************************/
432 USHORT
ProductMapper::PrintSingleMinorList(
433 GenericInformation
*pProductInfo
, BaseProductList
*pBases
,
434 const ByteString rEnvironment
)
435 /*****************************************************************************/
437 DirEntry
aRoot( GetVersionRoot( pVersionList
, pProductInfo
->GetValue()));
438 aRoot
+= DirEntry( String( rEnvironment
, RTL_TEXTENCODING_ASCII_US
));
439 if ( !aRoot
.Exists())
440 return PRODUCT_MAPPER_OK
;
442 SByteStringList
*pMinors
= GetMinorList( pProductInfo
->GetValue(), rEnvironment
);
444 pMinors
= new SByteStringList();
445 pMinors
->Insert( new ByteString( "" ), LIST_APPEND
);
447 SByteStringList aOutputList
;
448 BOOL bUnknownMinor
= FALSE
;
449 for ( ULONG i
= 0; i
< pMinors
->Count(); i
++ ) {
451 ByteString sProductVersion
;
453 for ( ULONG j
= 0; j
< pBases
->Count(); j
++ ) {
454 ByteString
sCurProduct( *pBases
->GetObject( j
));
455 ByteString
sVersion( sCurProduct
.GetToken( sCurProduct
.GetTokenCount( '(' ) - 1, '(' ).GetToken( 0, ')' ));
457 sProductVersion
= sVersion
;
459 MinorMk
*pMinorMk
= new MinorMk(
460 pVersionList
, sProductVersion
, sVersion
, rEnvironment
, *pMinors
->GetObject( i
));
462 ByteString
sMinor( pMinorMk
->GetLastMinor().GetBuffer());
463 if ( !sMinor
.Len()) {
465 bUnknownMinor
= TRUE
;
468 sOutput
+= pMinorMk
->GetBuildNr();
471 if ( i
== pMinors
->Count() - 1 )
480 sOutput
+= pMinorMk
->GetBuildNr();
483 aOutputList
.PutString( new ByteString( sOutput
));
485 ByteString sOldMinor
;
487 if ( aOutputList
.Count())
488 fprintf( stdout
, "Available builds on %s:\n", rEnvironment
.GetBuffer());
490 for ( ULONG o
= 0; o
< aOutputList
.Count(); o
++ ) {
491 ByteString
sOutput( *aOutputList
.GetObject( o
));
492 sOutput
= sOutput
.Copy( sOutput
.GetToken( 0, ' ' ).Len() + 1 );
494 ByteString
sCurMinor( sOutput
.GetToken( 1, '.' ).GetToken( 0, '(' ));
495 if ( sOldMinor
.Len() && sCurMinor
< sOldMinor
) {
496 fprintf( stdout
, " ----------\n" );
498 sOldMinor
= sCurMinor
;
500 fprintf( stdout
, "%s\n", sOutput
.GetBuffer());
501 delete aOutputList
.GetObject( o
);
504 fprintf( stdout
, "Symbol ! indcates that at least one minor could not be found\n\n" );
505 else if ( aOutputList
.Count())
506 fprintf( stdout
, "\n" );
508 for ( ULONG l
= 0; l
< pMinors
->Count(); l
++ )
509 delete pMinors
->GetObject( l
);
512 return PRODUCT_MAPPER_OK
;