1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Product.cc
13 #include "zypp/base/LogTools.h"
15 #include "zypp/Product.h"
18 #include "zypp/sat/LookupAttr.h"
19 #include "zypp/sat/WhatProvides.h"
20 #include "zypp/sat/WhatObsoletes.h"
21 #include "zypp/PoolItem.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 IMPL_PTR_TYPE(Product);
33 void fillList( std::list<Url> & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r )
35 sat::LookupAttr query( attr_r, solv_r );
36 for_( it, query.begin(), query.end() )
38 try // ignore malformed urls
40 ret_r.push_back( Url( it.asString() ) );
42 catch( const url::UrlException & )
47 void fillList( std::list<std::string> & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r )
49 sat::LookupAttr query( attr_r, solv_r );
50 for_( it, query.begin(), query.end() )
52 ret_r.push_back( it.asString() );
57 ///////////////////////////////////////////////////////////////////
59 // METHOD NAME : Product::Product
62 Product::Product( const sat::Solvable & solvable_r )
63 : ResObject( solvable_r )
66 ///////////////////////////////////////////////////////////////////
68 // METHOD NAME : Product::~Product
74 ///////////////////////////////////////////////////////////////////
76 sat::Solvable Product::referencePackage() const
78 Capability identCap( lookupStrAttribute( sat::SolvAttr::productReferences ) );
81 // No 'references': fallback to provider of 'product(name) = version'
82 // Without this solver testcase won't work, as it does not remember
84 identCap = Capability( str::form( "product(%s) = %s", name().c_str(), edition().c_str() ) );
88 return sat::Solvable::noSolvable;
92 // if there is productReferences defined, we expect
93 // a matching package within the same repo.
94 sat::WhatProvides providers( identCap );
95 for_( it, providers.begin(), providers.end() )
97 if ( it->repository() == repository() )
101 WAR << *this << ": no reference package found: " << identCap << endl;
102 return sat::Solvable::noSolvable;
105 Product::ReplacedProducts Product::replacedProducts() const
107 std::vector<constPtr> ret;
108 // By now we simply collect what is obsoleted by the Product,
109 // or by the products buddy (release-package).
111 // Check our own dependencies. We should not have any,
112 // but just to be shure.
113 sat::WhatObsoletes obsoleting( satSolvable() );
114 for_( it, obsoleting.begin(), obsoleting.end() )
116 if ( it->isKind( ResKind::product ) )
117 ret.push_back( make<Product>( *it ) );
120 // If we have a buddy, we check what product buddies the
122 obsoleting = sat::WhatObsoletes( poolItem().buddy() );
123 for_( it, obsoleting.poolItemBegin(), obsoleting.poolItemEnd() )
125 if ( (*it).buddy().isKind( ResKind::product ) )
126 ret.push_back( make<Product>( (*it).buddy() ) );
132 ///////////////////////////////////////////////////////////////////
134 std::string Product::shortName() const
135 { return lookupStrAttribute( sat::SolvAttr::productShortlabel ); }
137 std::string Product::flavor() const
138 { return lookupStrAttribute( sat::SolvAttr::productFlavor ); }
140 std::string Product::type() const
141 { return lookupStrAttribute( sat::SolvAttr::productType ); }
143 Url Product::releaseNotesUrl() const
146 fillList( ret, satSolvable(), sat::SolvAttr::productRelnotesurl );
152 std::list<Url> Product::updateUrls() const
155 fillList( ret, satSolvable(), sat::SolvAttr::productUpdateurls );
159 std::list<Url> Product::extraUrls() const
162 fillList( ret, satSolvable(), sat::SolvAttr::productExtraurls );
166 std::list<Url> Product::optionalUrls() const
169 fillList( ret, satSolvable(), sat::SolvAttr::productOptionalurls );
173 std::list<std::string> Product::flags() const
175 std::list<std::string> ret;
176 fillList( ret, satSolvable(), sat::SolvAttr::productFlags );
180 std::string Product::distributionName() const
181 { return lookupStrAttribute( sat::SolvAttr::productDistproduct ); }
183 Edition Product::distributionEdition() const
184 { return Edition( lookupStrAttribute( sat::SolvAttr::productDistversion ) ); }
187 /////////////////////////////////////////////////////////////////
189 ///////////////////////////////////////////////////////////////////