2 * Copyright 2011, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
5 #ifndef _PACKAGE__PACKAGE_INFO_H_
6 #define _PACKAGE__PACKAGE_INFO_H_
9 #include <Archivable.h>
10 #include <ObjectList.h>
12 #include <StringList.h>
14 #include <package/GlobalWritableFileInfo.h>
15 #include <package/PackageArchitecture.h>
16 #include <package/PackageFlags.h>
17 #include <package/PackageInfoAttributes.h>
18 #include <package/PackageResolvable.h>
19 #include <package/PackageResolvableExpression.h>
20 #include <package/PackageVersion.h>
21 #include <package/User.h>
22 #include <package/UserSettingsFileInfo.h>
29 namespace BPackageKit
{
33 * Keeps a list of package info elements (e.g. name, version, vendor, ...) which
34 * will be converted to package attributes when creating a package. Usually,
35 * these elements have been parsed from a ".PackageInfo" file.
36 * Alternatively, they can be read from an existing package file.
38 class BPackageInfo
: public BArchivable
{
40 struct ParseErrorListener
{
41 virtual ~ParseErrorListener();
42 virtual void OnError(const BString
& msg
, int line
, int col
) = 0;
47 BPackageInfo(BMessage
* archive
,
48 status_t
* _error
= NULL
);
49 virtual ~BPackageInfo();
51 status_t
ReadFromConfigFile(
52 const BEntry
& packageInfoEntry
,
53 ParseErrorListener
* listener
= NULL
);
54 status_t
ReadFromConfigFile(
55 BFile
& packageInfoFile
,
56 ParseErrorListener
* listener
= NULL
);
57 status_t
ReadFromConfigString(
58 const BString
& packageInfoString
,
59 ParseErrorListener
* listener
= NULL
);
60 status_t
ReadFromPackageFile(const char* path
);
61 status_t
ReadFromPackageFile(int fd
);
63 status_t
InitCheck() const;
65 const BString
& Name() const;
66 const BString
& Summary() const;
67 const BString
& Description() const;
68 const BString
& Vendor() const;
69 const BString
& Packager() const;
70 const BString
& BasePackage() const;
71 const BString
& Checksum() const;
72 const BString
& InstallPath() const;
73 BString
FileName() const;
74 // the explicitly set file name, if any, or
75 // CanonicalFileName() otherwise
79 BPackageArchitecture
Architecture() const;
80 const char* ArchitectureName() const;
83 const BPackageVersion
& Version() const;
85 const BStringList
& CopyrightList() const;
86 const BStringList
& LicenseList() const;
87 const BStringList
& URLList() const;
88 const BStringList
& SourceURLList() const;
90 const BObjectList
<BGlobalWritableFileInfo
>&
91 GlobalWritableFileInfos() const;
92 const BObjectList
<BUserSettingsFileInfo
>&
93 UserSettingsFileInfos() const;
95 const BObjectList
<BUser
>& Users() const;
96 const BStringList
& Groups() const;
98 const BStringList
& PostInstallScripts() const;
100 const BObjectList
<BPackageResolvable
>& ProvidesList() const;
101 const BObjectList
<BPackageResolvableExpression
>&
102 RequiresList() const;
103 const BObjectList
<BPackageResolvableExpression
>&
104 SupplementsList() const;
105 const BObjectList
<BPackageResolvableExpression
>&
106 ConflictsList() const;
107 const BObjectList
<BPackageResolvableExpression
>&
108 FreshensList() const;
109 const BStringList
& ReplacesList() const;
111 BString
CanonicalFileName() const;
113 bool Matches(const BPackageResolvableExpression
&
116 void SetName(const BString
& name
);
117 void SetSummary(const BString
& summary
);
118 void SetDescription(const BString
& description
);
119 void SetVendor(const BString
& vendor
);
120 void SetPackager(const BString
& packager
);
121 void SetBasePackage(const BString
& basePackage
);
122 void SetChecksum(const BString
& checksum
);
123 void SetInstallPath(const BString
& installPath
);
124 void SetFileName(const BString
& fileName
);
126 void SetFlags(uint32 flags
);
128 void SetArchitecture(
129 BPackageArchitecture architecture
);
131 void SetVersion(const BPackageVersion
& version
);
133 void ClearCopyrightList();
134 status_t
AddCopyright(const BString
& copyright
);
136 void ClearLicenseList();
137 status_t
AddLicense(const BString
& license
);
140 status_t
AddURL(const BString
& url
);
142 void ClearSourceURLList();
143 status_t
AddSourceURL(const BString
& url
);
145 void ClearGlobalWritableFileInfos();
146 status_t
AddGlobalWritableFileInfo(
147 const BGlobalWritableFileInfo
& info
);
149 void ClearUserSettingsFileInfos();
150 status_t
AddUserSettingsFileInfo(
151 const BUserSettingsFileInfo
& info
);
154 status_t
AddUser(const BUser
& user
);
157 status_t
AddGroup(const BString
& group
);
159 void ClearPostInstallScripts();
160 status_t
AddPostInstallScript(const BString
& path
);
162 void ClearProvidesList();
163 status_t
AddProvides(const BPackageResolvable
& provides
);
165 void ClearRequiresList();
166 status_t
AddRequires(
167 const BPackageResolvableExpression
& expr
);
169 void ClearSupplementsList();
170 status_t
AddSupplements(
171 const BPackageResolvableExpression
& expr
);
173 void ClearConflictsList();
174 status_t
AddConflicts(
175 const BPackageResolvableExpression
& expr
);
177 void ClearFreshensList();
178 status_t
AddFreshens(
179 const BPackageResolvableExpression
& expr
);
181 void ClearReplacesList();
182 status_t
AddReplaces(const BString
& replaces
);
186 virtual status_t
Archive(BMessage
* archive
,
187 bool deep
= true) const;
188 static BArchivable
* Instantiate(BMessage
* archive
);
190 status_t
GetConfigString(BString
& _string
) const;
191 BString
ToString() const;
194 static status_t
GetArchitectureByName(const BString
& name
,
195 BPackageArchitecture
& _architecture
);
197 static status_t
ParseVersionString(const BString
& string
,
198 bool revisionIsOptional
,
199 BPackageVersion
& _version
,
200 ParseErrorListener
* listener
= NULL
);
201 static status_t
ParseResolvableExpressionString(
202 const BString
& string
,
203 BPackageResolvableExpression
& _expression
,
204 ParseErrorListener
* listener
= NULL
);
207 static const char* const kElementNames
[];
208 static const char* const kArchitectureNames
[];
209 static const char* const kWritableFileUpdateTypes
[];
214 struct StringBuilder
;
216 struct PackageFileLocation
;
218 typedef BObjectList
<BPackageResolvable
> ResolvableList
;
219 typedef BObjectList
<BPackageResolvableExpression
>
220 ResolvableExpressionList
;
222 typedef BObjectList
<BGlobalWritableFileInfo
>
223 GlobalWritableFileInfoList
;
224 typedef BObjectList
<BUserSettingsFileInfo
>
225 UserSettingsFileInfoList
;
227 typedef BObjectList
<BUser
> UserList
;
230 status_t
_ReadFromPackageFile(
231 const PackageFileLocation
& fileLocation
);
233 static status_t
_AddVersion(BMessage
* archive
,
235 const BPackageVersion
& version
);
236 static status_t
_AddResolvables(BMessage
* archive
,
238 const ResolvableList
& resolvables
);
239 static status_t
_AddResolvableExpressions(BMessage
* archive
,
241 const ResolvableExpressionList
&
243 static status_t
_AddGlobalWritableFileInfos(BMessage
* archive
,
245 const GlobalWritableFileInfoList
&
247 static status_t
_AddUserSettingsFileInfos(BMessage
* archive
,
249 const UserSettingsFileInfoList
&
251 static status_t
_AddUsers(BMessage
* archive
, const char* field
,
252 const UserList
& users
);
254 static status_t
_ExtractVersion(BMessage
* archive
,
255 const char* field
, int32 index
,
256 BPackageVersion
& _version
);
257 static status_t
_ExtractStringList(BMessage
* archive
,
258 const char* field
, BStringList
& _list
);
259 static status_t
_ExtractResolvables(BMessage
* archive
,
261 ResolvableList
& _resolvables
);
262 static status_t
_ExtractResolvableExpressions(BMessage
* archive
,
264 ResolvableExpressionList
& _expressions
);
265 static status_t
_ExtractGlobalWritableFileInfos(
266 BMessage
* archive
, const char* field
,
267 GlobalWritableFileInfoList
& _infos
);
268 static status_t
_ExtractUserSettingsFileInfos(
269 BMessage
* archive
, const char* field
,
270 UserSettingsFileInfoList
& _infos
);
271 static status_t
_ExtractUsers(BMessage
* archive
,
272 const char* field
, UserList
& _users
);
277 BString fDescription
;
280 BString fBasePackage
;
284 BPackageArchitecture fArchitecture
;
286 BPackageVersion fVersion
;
288 BStringList fCopyrightList
;
289 BStringList fLicenseList
;
290 BStringList fURLList
;
291 BStringList fSourceURLList
;
293 BObjectList
<BGlobalWritableFileInfo
> fGlobalWritableFileInfos
;
294 BObjectList
<BUserSettingsFileInfo
> fUserSettingsFileInfos
;
299 BStringList fPostInstallScripts
;
301 ResolvableList fProvidesList
;
303 ResolvableExpressionList fRequiresList
;
304 ResolvableExpressionList fSupplementsList
;
305 ResolvableExpressionList fConflictsList
;
306 ResolvableExpressionList fFreshensList
;
308 BStringList fReplacesList
;
311 BString fInstallPath
;
316 } // namespace BPackageKit
319 #endif // _PACKAGE__PACKAGE_INFO_H_