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: prodmap.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 "prodmap.hxx"
32 #include <tools/geninfo.hxx>
33 #include <tools/fsys.hxx>
34 #include "minormk.hxx"
38 #define PRODUCT_KEY "TARGETDESCRIPTION/PRODUCTS"
39 #define DEPENDS_ON_KEY "TARGETDESCRIPTION/DEPENDSON"
40 #define BASED_ON_KEY "TARGETDESCRIPTION/BASEDON"
43 // class ProductMapper
46 /*****************************************************************************/
47 ProductMapper::ProductMapper()
48 /*****************************************************************************/
49 : pVersionList( NULL
),
54 /*****************************************************************************/
55 ProductMapper::ProductMapper( GenericInformationList
*pVerList
)
56 /*****************************************************************************/
57 : pVersionList( pVerList
),
61 CreateProductList( pVerList
);
64 /*****************************************************************************/
65 ProductMapper::~ProductMapper()
66 /*****************************************************************************/
71 /*****************************************************************************/
72 void ProductMapper::CreateProductList( GenericInformationList
*pVerList
)
73 /*****************************************************************************/
76 creates a list of the following format:
78 ProductName Workspace // 6.0 Final SRC641
80 DependsOn // DependsOn
98 pVersionList
= pVerList
;
100 if ( pVersionList
) {
101 ByteString
sProductKey( PRODUCT_KEY
);
102 ByteString
sDependsOnKey( DEPENDS_ON_KEY
);
103 ByteString
sBasedOnKey( BASED_ON_KEY
);
105 for ( ULONG i
= 0; i
< pVersionList
->Count(); i
++ ) {
106 GenericInformation
*pVersion
= pVersionList
->GetObject( i
);
108 GenericInformation
*pProducts
= pVersion
->GetSubInfo( sProductKey
, TRUE
);
110 ByteString sProducts
= pProducts
->GetValue();
112 ByteString sDependsOn
;
113 GenericInformation
*pDependsOn
= pVersion
->GetSubInfo( sDependsOnKey
, TRUE
);
115 sDependsOn
= pDependsOn
->GetValue();
118 GenericInformation
*pBasedOn
= pVersion
->GetSubInfo( sBasedOnKey
, TRUE
);
120 sBasedOn
= pBasedOn
->GetValue();
122 for ( USHORT x
= 0; x
< sProducts
.GetTokenCount( ';' ); x
++ ) {
123 ByteString
sProduct( sProducts
.GetToken( x
, ';' ));
124 if( sProduct
.Len()) {
126 pProductList
= new GenericInformationList();
128 pProductList
->InsertInfo( sProduct
, *pVersion
, TRUE
, TRUE
);
130 for ( USHORT y
= 0; y
< sDependsOn
.GetTokenCount( ';' ); y
++ ) {
131 ByteString sDependsOnKey_l
= sProduct
;
132 sDependsOnKey_l
+= "/DependsOn/";
133 sDependsOnKey_l
+= sDependsOn
.GetToken( y
, ';' );
135 pProductList
->InsertInfo( sDependsOnKey_l
, "", TRUE
, TRUE
);
137 for ( USHORT z
= 0; z
< sBasedOn
.GetTokenCount( ';' ); z
++ ) {
138 ByteString sBasedOnKey_l
= sProduct
;
139 sBasedOnKey_l
+= "/BasedOn/";
140 sBasedOnKey_l
+= sBasedOn
.GetToken( z
, ';' );
142 pProductList
->InsertInfo( sBasedOnKey_l
, "", TRUE
, TRUE
);
151 /*****************************************************************************/
152 USHORT
ProductMapper::GetProductInformation(
153 const ByteString
&rProduct
, GenericInformation
*& pProductInfo
)
154 /*****************************************************************************/
159 return PRODUCT_MAPPER_NO_VERSION_INFORMATION
;
162 return PRODUCT_MAPPER_NO_PRODUCT
;
164 ByteString
sProductKey( rProduct
);
165 pProductInfo
= pProductList
->GetInfo( sProductKey
, TRUE
);
168 return PRODUCT_MAPPER_NO_PRODUCT
;
170 return PRODUCT_MAPPER_OK
;
173 /*****************************************************************************/
174 USHORT
ProductMapper::PrintDependentTargets(
175 const ByteString
&rProduct
, USHORT nLevel
)
176 /*****************************************************************************/
178 GenericInformation
*pProductInfo
;
180 USHORT nReturn
= GetProductInformation( rProduct
, pProductInfo
);
182 if ( nReturn
== PRODUCT_MAPPER_OK
) {
183 for ( USHORT i
= 0; i
< nLevel
; i
++ )
184 fprintf( stdout
, " " );
185 fprintf( stdout
, "%s (%s)\n", pProductInfo
->GetBuffer(),
186 pProductInfo
->GetValue().GetBuffer());
187 aPrintedList
.PutString( new ByteString( *pProductInfo
));
189 for ( ULONG j
= 0; j
< pProductList
->Count(); j
++ ) {
190 GenericInformation
*pCandidate
= pProductList
->GetObject( j
);
191 ByteString
sKey( "DEPENDSON/" );
193 GenericInformation
*pDependsOn
= pCandidate
->GetSubInfo( sKey
, TRUE
);
195 PrintDependentTargets( *pCandidate
, nLevel
+ 1 );
198 ByteString
sKey( "BASEDON" );
199 GenericInformation
*pBasedOn
= pProductInfo
->GetSubInfo( sKey
);
201 GenericInformationList
*pBases
= pBasedOn
->GetSubList();
203 for ( ULONG k
= 0; k
< pBases
->Count(); k
++ ) {
204 aBaseList
.PutString( new ByteString( *pBases
->GetObject( k
)));
214 /*****************************************************************************/
215 USHORT
ProductMapper::PrintAndDeleteBaseList()
216 /*****************************************************************************/
218 if ( aBaseList
.Count()) {
219 fprintf( stdout
, "\nbased on\n" );
220 while ( aBaseList
.Count()) {
221 ByteString
sProduct( *aBaseList
.GetObject(( ULONG
) 0 ));
222 if ( aPrintedList
.IsString( aBaseList
.GetObject(( ULONG
) 0 )) == NOT_THERE
) {
223 aPrintedList
.PutString( aBaseList
.GetObject(( ULONG
) 0 ));
224 PrintDependentTargets( sProduct
);
227 delete aBaseList
.GetObject(( ULONG
) 0 );
229 aBaseList
.Remove(( ULONG
) 0 );
231 while ( aPrintedList
.Count())
232 delete aPrintedList
.Remove(( ULONG
) 0 );
234 fprintf( stdout
, "\n" );
236 return PRODUCT_MAPPER_OK
;
239 /*****************************************************************************/
240 USHORT
ProductMapper::PrintDependencies( const ByteString
&rProduct
)
241 /*****************************************************************************/
243 USHORT nResult
= PrintDependentTargets( rProduct
);
244 PrintAndDeleteBaseList();
248 /*****************************************************************************/
249 USHORT
ProductMapper::PrintProductList()
250 /*****************************************************************************/
253 return PRODUCT_MAPPER_NO_VERSION_INFORMATION
;
255 if ( !pProductList
|| !pProductList
->Count())
256 return PRODUCT_MAPPER_NO_PRODUCT
;
258 if ( pProductList
->Count()) {
259 for ( ULONG i
= 0; i
< pProductList
->Count(); i
++ )
260 fprintf( stdout
, "%s (%s)\n",
261 pProductList
->GetObject( i
)->GetBuffer(),
262 pProductList
->GetObject( i
)->GetValue().GetBuffer());
263 fprintf( stdout
, "\n" );
266 return PRODUCT_MAPPER_OK
;
269 /*****************************************************************************/
270 SByteStringList
*ProductMapper::GetMinorList(
271 const ByteString
&rVersion
, const ByteString
&rEnvironment
)
272 /*****************************************************************************/
274 SByteStringList
*pList
= NULL
;
276 if ( pVersionList
) {
277 String
sRoot( GetVersionRoot( pVersionList
, rVersion
));
279 DirEntry
aEntry( sRoot
);
280 aEntry
+= DirEntry( String( rEnvironment
, RTL_TEXTENCODING_ASCII_US
));
281 String
sWildcard( String::CreateFromAscii( "inc.*" ));
282 aEntry
+= DirEntry( sWildcard
);
284 Dir
aDir( aEntry
, FSYS_KIND_DIR
);
285 for ( USHORT i
= 0; i
< aDir
.Count(); i
++ ) {
286 ByteString
sInc( aDir
[ i
].GetName(), RTL_TEXTENCODING_ASCII_US
);
287 if ( sInc
.GetTokenCount( '.' ) > 1 ) {
289 pList
= new SByteStringList();
290 pList
->PutString( new ByteString( sInc
.GetToken( 1, '.' )));
298 /*****************************************************************************/
299 String
ProductMapper::GetVersionRoot(
300 GenericInformationList
*pList
, const ByteString
&rVersion
)
301 /*****************************************************************************/
303 ByteString
sKey( rVersion
);
304 GenericInformation
*pVersion
= pList
->GetInfo( sKey
);
307 sKey
= "drives/o:/unixvolume";
308 GenericInformation
*pUnixVolume
= pVersion
->GetSubInfo( sKey
, TRUE
);
311 sPath
= pUnixVolume
->GetValue();
314 ByteString
sPath( "o:\\" );
316 sKey
= "settings/path";
317 GenericInformation
*pPath
= pVersion
->GetSubInfo( sKey
, TRUE
);
319 sPath
+= pPath
->GetValue().GetToken( 0, '\\' );
323 sPath
.SearchAndReplaceAll( "\\", "/" );
324 while( sPath
.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND
) {};
326 sPath
.SearchAndReplaceAll( "/", "\\" );
327 while( sPath
.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND
) {};
330 return String( sPath
, RTL_TEXTENCODING_ASCII_US
);
335 /*****************************************************************************/
336 BaseProductList
*ProductMapper::GetBases(
337 GenericInformation
*pProductInfo
, USHORT nLevel
,
338 BaseProductList
*pBases
)
339 /*****************************************************************************/
342 pBases
= new BaseProductList();
344 if ( pProductInfo
) {
345 ByteString
sCandidate( *pProductInfo
);
347 sCandidate
+= pProductInfo
->GetValue();
350 ByteString
sKey( "BASEDON" );
351 GenericInformation
*pBasedOn
= pProductInfo
->GetSubInfo( sKey
);
353 GenericInformationList
*pBasesInfo
= pBasedOn
->GetSubList();
355 for ( ULONG k
= 0; k
< pBasesInfo
->Count(); k
++ ) {
356 GenericInformation
*pBaseProduct
;
357 if ( GetProductInformation( *pBasesInfo
->GetObject( k
), pBaseProduct
) == PRODUCT_MAPPER_OK
)
358 GetBases( pBaseProduct
, ++ nLevel
, pBases
);
363 ByteString
sUpperCandidate( sCandidate
);
364 sUpperCandidate
.ToUpperAscii();
365 for ( USHORT i
= 0; i
< pBases
->Count() && !bFound
; i
++ ) {
366 ByteString
sTest( *pBases
->GetObject( i
));
367 if ( sTest
.ToUpperAscii() == sUpperCandidate
)
371 pBases
->Insert( new ByteString( sCandidate
), ( ULONG
) 0 );
376 /*****************************************************************************/
377 USHORT
ProductMapper::PrintMinorList(
378 const ByteString rProduct
, const ByteString rEnvironment
)
379 /*****************************************************************************/
382 return PRODUCT_MAPPER_NO_VERSION_INFORMATION
;
384 if ( !pProductList
|| !pProductList
->Count())
385 return PRODUCT_MAPPER_NO_PRODUCT
;
387 GenericInformation
*pProductInfo
;
388 GetProductInformation( rProduct
, pProductInfo
);
390 return PRODUCT_MAPPER_NO_PRODUCT
;
392 BaseProductList
*pBases
= GetBases( pProductInfo
);
393 if ( pBases
->Count()) {
394 if ( pBases
->Count() > 1 )
395 fprintf( stdout
, "Product \"%s\" based on ", pBases
->GetObject(( ULONG
) 0 )->GetBuffer());
397 fprintf( stdout
, "Product \"%s\" based on no other products", pBases
->GetObject(( ULONG
) 0 )->GetBuffer());
399 for ( ULONG i
= 1; i
< pBases
->Count(); i
++ ) {
400 fprintf( stdout
, "\"%s\"", pBases
->GetObject( i
)->GetBuffer());
401 if ( i
< pBases
->Count() - 1 )
402 fprintf( stdout
, ", " );
404 fprintf( stdout
, "\n\n" );
406 USHORT nResult
= PRODUCT_MAPPER_OK
;
408 if ( rEnvironment
.Len())
409 nResult
= PrintSingleMinorList( pProductInfo
, pBases
, rEnvironment
);
411 ByteString
sEnvKey( pProductInfo
->GetValue());
412 sEnvKey
+= "/Environments";
414 GenericInformation
*pEnvironmentInfo
= pVersionList
->GetInfo( sEnvKey
, TRUE
);
415 if ( pEnvironmentInfo
) {
416 GenericInformationList
*pEnvironmentList
= pEnvironmentInfo
->GetSubList();
417 if ( pEnvironmentList
) {
418 for ( ULONG i
= 0; i
< pEnvironmentList
->Count(); i
++ ) {
419 USHORT nTmp
= PrintSingleMinorList( pProductInfo
, pBases
, *pEnvironmentList
->GetObject( i
));
420 if ( nTmp
!= PRODUCT_MAPPER_OK
)
427 for ( ULONG m
= 0; m
< pBases
->Count(); m
++ )
428 delete pBases
->GetObject( m
);
434 /*****************************************************************************/
435 USHORT
ProductMapper::PrintSingleMinorList(
436 GenericInformation
*pProductInfo
, BaseProductList
*pBases
,
437 const ByteString rEnvironment
)
438 /*****************************************************************************/
440 DirEntry
aRoot( GetVersionRoot( pVersionList
, pProductInfo
->GetValue()));
441 aRoot
+= DirEntry( String( rEnvironment
, RTL_TEXTENCODING_ASCII_US
));
442 if ( !aRoot
.Exists())
443 return PRODUCT_MAPPER_OK
;
445 SByteStringList
*pMinors
= GetMinorList( pProductInfo
->GetValue(), rEnvironment
);
447 pMinors
= new SByteStringList();
448 pMinors
->Insert( new ByteString( "" ), LIST_APPEND
);
450 SByteStringList aOutputList
;
451 BOOL bUnknownMinor
= FALSE
;
452 for ( ULONG i
= 0; i
< pMinors
->Count(); i
++ ) {
454 ByteString sProductVersion
;
456 for ( ULONG j
= 0; j
< pBases
->Count(); j
++ ) {
457 ByteString
sCurProduct( *pBases
->GetObject( j
));
458 ByteString
sVersion( sCurProduct
.GetToken( sCurProduct
.GetTokenCount( '(' ) - 1, '(' ).GetToken( 0, ')' ));
460 sProductVersion
= sVersion
;
462 MinorMk
*pMinorMk
= new MinorMk(
463 pVersionList
, sProductVersion
, sVersion
, rEnvironment
, *pMinors
->GetObject( i
));
465 ByteString
sMinor( pMinorMk
->GetLastMinor().GetBuffer());
466 if ( !sMinor
.Len()) {
468 bUnknownMinor
= TRUE
;
471 sOutput
+= pMinorMk
->GetBuildNr();
474 if ( i
== pMinors
->Count() - 1 )
483 sOutput
+= pMinorMk
->GetBuildNr();
486 aOutputList
.PutString( new ByteString( sOutput
));
488 ByteString sOldMinor
;
490 if ( aOutputList
.Count())
491 fprintf( stdout
, "Available builds on %s:\n", rEnvironment
.GetBuffer());
493 for ( ULONG o
= 0; o
< aOutputList
.Count(); o
++ ) {
494 ByteString
sOutput( *aOutputList
.GetObject( o
));
495 sOutput
= sOutput
.Copy( sOutput
.GetToken( 0, ' ' ).Len() + 1 );
497 ByteString
sCurMinor( sOutput
.GetToken( 1, '.' ).GetToken( 0, '(' ));
498 if ( sOldMinor
.Len() && sCurMinor
< sOldMinor
) {
499 fprintf( stdout
, " ----------\n" );
501 sOldMinor
= sCurMinor
;
503 fprintf( stdout
, "%s\n", sOutput
.GetBuffer());
504 delete aOutputList
.GetObject( o
);
507 fprintf( stdout
, "Symbol ! indcates that at least one minor could not be found\n\n" );
508 else if ( aOutputList
.Count())
509 fprintf( stdout
, "\n" );
511 for ( ULONG l
= 0; l
< pMinors
->Count(); l
++ )
512 delete pMinors
->GetObject( l
);
515 return PRODUCT_MAPPER_OK
;