* added type-support to BPackageResolvable

* split BPackageResolvable, BPackageResolvableExpression
  and BPackageVersion into separate files


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40316 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2011-01-29 17:59:58 +00:00
parent fbf800f60c
commit 3aeae97f65
9 changed files with 807 additions and 417 deletions
+74 -112
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2011, Oliver Tappe <[email protected]>
* Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__PACKAGE_INFO_H_
@@ -9,6 +9,10 @@
#include <ObjectList.h>
#include <String.h>
#include <package/PackageResolvable.h>
#include <package/PackageResolvableExpression.h>
#include <package/PackageVersion.h>
class BEntry;
@@ -18,16 +22,28 @@ namespace BPackageKit {
enum BPackageInfoIndex {
B_PACKAGE_INFO_NAME = 0,
B_PACKAGE_INFO_SUMMARY, // single line, 70 chars max
B_PACKAGE_INFO_DESCRIPTION, // multiple lines possible
B_PACKAGE_INFO_VENDOR, // e.g. "Haiku Project"
B_PACKAGE_INFO_PACKAGER, // e-mail address preferred
B_PACKAGE_INFO_SUMMARY, // single line
B_PACKAGE_INFO_DESCRIPTION, // multiple lines possible
B_PACKAGE_INFO_VENDOR, // e.g. "Haiku Project"
B_PACKAGE_INFO_PACKAGER, // e-mail address preferred
B_PACKAGE_INFO_ARCHITECTURE,
B_PACKAGE_INFO_VERSION, // <major>[.<minor>[.<micro>]]
B_PACKAGE_INFO_COPYRIGHTS, // list
B_PACKAGE_INFO_LICENSES, // list
B_PACKAGE_INFO_PROVIDES, // list
B_PACKAGE_INFO_REQUIRES, // list
B_PACKAGE_INFO_VERSION, // <major>[.<minor>[.<micro>]]
B_PACKAGE_INFO_COPYRIGHTS, // list
B_PACKAGE_INFO_LICENSES, // list
B_PACKAGE_INFO_PROVIDES, // list of resolvables this package provides,
// each optionally giving a version
B_PACKAGE_INFO_REQUIRES, // list of resolvables required by this package,
// each optionally specifying a version relation
// (e.g. libssl.so >= 0.9.8)
B_PACKAGE_INFO_SUPPLEMENTS, // list of resolvables that are supplemented
// by this package, i.e. this package marks
// itself as an extension to other packages
B_PACKAGE_INFO_CONFLICTS, // list of resolvables that inhibit installation
// of this package
B_PACKAGE_INFO_REPLACES, // list of resolvables that this package
// will replace (upon update)
B_PACKAGE_INFO_FRESHENS, // list of resolvables that this package
// contains a patch for
//
B_PACKAGE_INFO_ENUM_COUNT,
};
@@ -42,81 +58,6 @@ enum BPackageArchitecture {
};
class BPackageVersion {
public:
BPackageVersion();
BPackageVersion(const BString& major,
const BString& minor, const BString& micro,
uint8 release);
status_t InitCheck() const;
void GetVersionString(BString& string) const;
void SetTo(const BString& major,
const BString& minor, const BString& micro,
uint8 release);
void Clear();
int Compare(const BPackageVersion& other) const;
// does a natural compare over major, minor
// and micro, finally comparing release
private:
BString fMajor;
BString fMinor;
BString fMicro;
uint8 fRelease;
};
class BPackageProvision {
public:
BPackageProvision();
BPackageProvision(const BString& name,
const BPackageVersion& version
= BPackageVersion());
status_t InitCheck() const;
void GetProvisionString(BString& string) const;
void SetTo(const BString& name,
const BPackageVersion& version
= BPackageVersion());
void Clear();
private:
BString fName;
BPackageVersion fVersion;
};
class BPackageRequirement {
public:
BPackageRequirement();
BPackageRequirement(const BString& name,
const BString& _operator = "",
const BPackageVersion& version
= BPackageVersion());
status_t InitCheck() const;
void GetRequirementString(BString& string) const;
void SetTo(const BString& name,
const BString& _operator = "",
const BPackageVersion& version
= BPackageVersion());
void Clear();
private:
BString fName;
BString fOperator;
BPackageVersion fVersion;
};
/*
* Keeps a list of package info elements (e.g. name, version, vendor, ...) which
* will be converted to package attributes when creating a package. Usually,
@@ -154,11 +95,19 @@ public:
const BPackageVersion& Version() const;
const BObjectList<BString>& Copyrights() const;
const BObjectList<BString>& Licenses() const;
const BObjectList<BString>& CopyrightList() const;
const BObjectList<BString>& LicenseList() const;
const BObjectList<BPackageRequirement>& Requirements() const;
const BObjectList<BPackageProvision>& Provisions() const;
const BObjectList<BPackageResolvable>& ProvidesList() const;
const BObjectList<BPackageResolvableExpression>&
RequiresList() const;
const BObjectList<BPackageResolvableExpression>&
SupplementsList() const;
const BObjectList<BPackageResolvableExpression>&
ConflictsList() const;
const BObjectList<BPackageResolvableExpression>&
FreshensList() const;
const BObjectList<BString>& ReplacesList() const;
void SetName(const BString& name);
void SetSummary(const BString& summary);
@@ -171,37 +120,42 @@ public:
void SetVersion(const BPackageVersion& version);
void ClearCopyrights();
void ClearCopyrightList();
status_t AddCopyright(const BString& copyright);
void ClearLicenses();
void ClearLicenseList();
status_t AddLicense(const BString& license);
void ClearProvisions();
status_t AddProvision(
const BPackageProvision& provision);
void ClearProvidesList();
status_t AddProvides(const BPackageResolvable& provides);
void ClearRequirements();
status_t AddRequirement(
const BPackageRequirement& requirement);
void ClearRequiresList();
status_t AddRequires(
const BPackageResolvableExpression& expr);
void ClearSupplementsList();
status_t AddSupplements(
const BPackageResolvableExpression& expr);
void ClearConflictsList();
status_t AddConflicts(
const BPackageResolvableExpression& expr);
void ClearFreshensList();
status_t AddFreshens(
const BPackageResolvableExpression& expr);
void ClearReplacesList();
status_t AddReplaces(const BString& replaces);
void Clear();
public:
static status_t GetElementName(
BPackageInfoIndex index,
const char** name);
static status_t GetArchitectureName(
BPackageArchitecture arch,
const char** name);
static const char* kElementNames[];
static const char* kArchitectureNames[];
private:
class Parser;
friend class Parser;
static const char* kElementNames[];
static const char* kArchitectureNames[];
private:
BString fName;
@@ -214,11 +168,19 @@ private:
BPackageVersion fVersion;
BObjectList<BString> fCopyrights;
BObjectList<BString> fLicenses;
BObjectList<BString> fCopyrightList;
BObjectList<BString> fLicenseList;
BObjectList<BPackageProvision> fProvisions;
BObjectList<BPackageRequirement> fRequirements;
BObjectList<BPackageResolvable> fProvidesList;
BObjectList<BPackageResolvableExpression> fRequiresList;
BObjectList<BPackageResolvableExpression> fSupplementsList;
BObjectList<BPackageResolvableExpression> fConflictsList;
BObjectList<BPackageResolvableExpression> fFreshensList;
BObjectList<BString> fReplacesList;
};
+86
View File
@@ -0,0 +1,86 @@
/*
* Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__PACKAGE_RESOLVALBE_H_
#define _PACKAGE__PACKAGE_RESOLVALBE_H_
#include <String.h>
#include <package/PackageVersion.h>
namespace BPackageKit {
enum BPackageResolvableType {
B_PACKAGE_RESOLVABLE_TYPE_DEFAULT = 0,
B_PACKAGE_RESOLVABLE_TYPE_LIBRARY,
B_PACKAGE_RESOLVABLE_TYPE_COMMAND,
B_PACKAGE_RESOLVABLE_TYPE_APPLICATION,
B_PACKAGE_RESOLVABLE_TYPE_ADD_ON,
//
B_PACKAGE_RESOLVABLE_TYPE_ENUM_COUNT,
};
/*
* Defines a resolvable (something other packages can depend upon).
* Each resolvable is defined as a name (with an optional type prefix)
* and an optional version.
*
* resolvable ::= <name>['='<version>]
* name ::= [<type>':']<word>
* type ::= 'lib' | 'cmd' | 'app' | 'add_on'
*
* The type doesn't have any specific meaning to the dependency resolver,
* it just facilitates doing specific queries on the repository (like "is
* there any package providing the 'svn' command that the user just typed?").
* At a later stage, more types may be added in order to declare additional
* entities, e.g. translators.
*
* String examples:
* haiku=r1
* lib:libssl=0.9.8i
* subversion=1.5
* cmd:svn
*/
class BPackageResolvable {
public:
BPackageResolvable();
BPackageResolvable(const BString& name,
BPackageResolvableType type
= B_PACKAGE_RESOLVABLE_TYPE_DEFAULT,
const BPackageVersion& version
= BPackageVersion());
status_t InitCheck() const;
const BString& Name() const;
BPackageResolvableType Type() const;
const BPackageVersion& Version() const;
void GetAsString(BString& string) const;
void SetTo(const BString& name,
BPackageResolvableType type
= B_PACKAGE_RESOLVABLE_TYPE_DEFAULT,
const BPackageVersion& version
= BPackageVersion());
void Clear();
public:
static const char* kTypeNames[];
private:
BString fName;
BPackageResolvableType fType;
BPackageVersion fVersion;
};
} // namespace BPackageKit
#endif // _PACKAGE__PACKAGE_RESOLVALBE_H_
@@ -0,0 +1,65 @@
/*
* Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__PACKAGE_RESOLVABLE_EXPRESSION_H_
#define _PACKAGE__PACKAGE_RESOLVABLE_EXPRESSION_H_
#include <String.h>
#include <package/PackageVersion.h>
namespace BPackageKit {
/*
* Expresses a constraint on a specific resolvable, either just a name
* or a name plus a relational operator and a version.
* Instances of these will be matched against all the BPackageResolvable(s)
* of individual packages in order to solve a package management request.
*
* resolvable-expression ::= <name>[<op><version>]
* op ::= '<' | '<=' | '==' | '>=' | '>'
*
* String examples:
* haiku==r1
* lib:libssl==0.9.8
* subversion>=1.5
* cmd:svn
*/
class BPackageResolvableExpression {
public:
BPackageResolvableExpression();
BPackageResolvableExpression(
const BString& name,
const BString& _operator = "",
const BPackageVersion& version
= BPackageVersion());
status_t InitCheck() const;
const BString& Name() const;
const BString& Operator() const;
const BPackageVersion& Version() const;
void GetAsString(BString& string) const;
void SetTo(const BString& name,
const BString& _operator = "",
const BPackageVersion& version
= BPackageVersion());
void Clear();
private:
BString fName;
BString fOperator;
BPackageVersion fVersion;
};
} // namespace BPackageKit
#endif // _PACKAGE__PACKAGE_RESOLVABLE_EXPRESSION_H_
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__PACKAGE_VERSION_H_
#define _PACKAGE__PACKAGE_VERSION_H_
#include <String.h>
namespace BPackageKit {
class BPackageVersion {
public:
BPackageVersion();
BPackageVersion(const BString& major,
const BString& minor, const BString& micro,
uint8 release);
status_t InitCheck() const;
void GetAsString(BString& string) const;
void SetTo(const BString& major,
const BString& minor, const BString& micro,
uint8 release);
void Clear();
int Compare(const BPackageVersion& other) const;
// does a natural compare over major, minor
// and micro, finally comparing release
private:
BString fMajor;
BString fMinor;
BString fMicro;
uint8 fRelease;
};
} // namespace BPackageKit
#endif // _PACKAGE__PACKAGE_VERSION_H_