1 /* 2 * Copyright 2011, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _PACKAGE__PACKAGE_INFO_H_ 6 #define _PACKAGE__PACKAGE_INFO_H_ 7 8 9 #include <ObjectList.h> 10 #include <String.h> 11 #include <StringList.h> 12 13 #include <package/PackageArchitecture.h> 14 #include <package/PackageFlags.h> 15 #include <package/PackageInfoAttributes.h> 16 #include <package/PackageResolvable.h> 17 #include <package/PackageResolvableExpression.h> 18 #include <package/PackageVersion.h> 19 20 21 class BEntry; 22 class BFile; 23 24 25 namespace BPackageKit { 26 27 28 /* 29 * Keeps a list of package info elements (e.g. name, version, vendor, ...) which 30 * will be converted to package attributes when creating a package. Usually, 31 * these elements have been parsed from a ".PackageInfo"-file. 32 * Alternatively, the package reader populates a BPackageInfo object by 33 * collecting package attributes from an existing package. 34 */ 35 class BPackageInfo { 36 public: 37 struct ParseErrorListener { 38 virtual ~ParseErrorListener(); 39 virtual void OnError(const BString& msg, int line, int col) = 0; 40 }; 41 42 public: 43 BPackageInfo(); 44 ~BPackageInfo(); 45 46 status_t ReadFromConfigFile( 47 const BEntry& packageInfoEntry, 48 ParseErrorListener* listener = NULL); 49 status_t ReadFromConfigFile( 50 BFile& packageInfoFile, 51 ParseErrorListener* listener = NULL); 52 status_t ReadFromConfigString( 53 const BString& packageInfoString, 54 ParseErrorListener* listener = NULL); 55 56 status_t InitCheck() const; 57 58 const BString& Name() const; 59 const BString& Summary() const; 60 const BString& Description() const; 61 const BString& Vendor() const; 62 const BString& Packager() const; 63 const BString& Checksum() const; 64 const BString& InstallPath() const; 65 66 uint32 Flags() const; 67 68 BPackageArchitecture Architecture() const; 69 70 const BPackageVersion& Version() const; 71 72 const BStringList& CopyrightList() const; 73 const BStringList& LicenseList() const; 74 const BStringList& URLList() const; 75 const BStringList& SourceURLList() const; 76 77 const BObjectList<BPackageResolvable>& ProvidesList() const; 78 const BObjectList<BPackageResolvableExpression>& 79 RequiresList() const; 80 const BObjectList<BPackageResolvableExpression>& 81 SupplementsList() const; 82 const BObjectList<BPackageResolvableExpression>& 83 ConflictsList() const; 84 const BObjectList<BPackageResolvableExpression>& 85 FreshensList() const; 86 const BStringList& ReplacesList() const; 87 88 void SetName(const BString& name); 89 void SetSummary(const BString& summary); 90 void SetDescription(const BString& description); 91 void SetVendor(const BString& vendor); 92 void SetPackager(const BString& packager); 93 void SetChecksum(const BString& checksum); 94 void SetInstallPath(const BString& installPath); 95 96 void SetFlags(uint32 flags); 97 98 void SetArchitecture( 99 BPackageArchitecture architecture); 100 101 void SetVersion(const BPackageVersion& version); 102 103 void ClearCopyrightList(); 104 status_t AddCopyright(const BString& copyright); 105 106 void ClearLicenseList(); 107 status_t AddLicense(const BString& license); 108 109 void ClearURLList(); 110 status_t AddURL(const BString& url); 111 112 void ClearSourceURLList(); 113 status_t AddSourceURL(const BString& url); 114 115 void ClearProvidesList(); 116 status_t AddProvides(const BPackageResolvable& provides); 117 118 void ClearRequiresList(); 119 status_t AddRequires( 120 const BPackageResolvableExpression& expr); 121 122 void ClearSupplementsList(); 123 status_t AddSupplements( 124 const BPackageResolvableExpression& expr); 125 126 void ClearConflictsList(); 127 status_t AddConflicts( 128 const BPackageResolvableExpression& expr); 129 130 void ClearFreshensList(); 131 status_t AddFreshens( 132 const BPackageResolvableExpression& expr); 133 134 void ClearReplacesList(); 135 status_t AddReplaces(const BString& replaces); 136 137 void Clear(); 138 139 public: 140 static status_t GetArchitectureByName(const BString& name, 141 BPackageArchitecture& _architecture); 142 143 static const char* kElementNames[]; 144 static const char* kArchitectureNames[]; 145 146 private: 147 class Parser; 148 friend class Parser; 149 150 private: 151 BString fName; 152 BString fSummary; 153 BString fDescription; 154 BString fVendor; 155 BString fPackager; 156 157 uint32 fFlags; 158 159 BPackageArchitecture fArchitecture; 160 161 BPackageVersion fVersion; 162 163 BStringList fCopyrightList; 164 BStringList fLicenseList; 165 BStringList fURLList; 166 BStringList fSourceURLList; 167 168 BObjectList<BPackageResolvable> fProvidesList; 169 170 BObjectList<BPackageResolvableExpression> fRequiresList; 171 BObjectList<BPackageResolvableExpression> fSupplementsList; 172 173 BObjectList<BPackageResolvableExpression> fConflictsList; 174 175 BObjectList<BPackageResolvableExpression> fFreshensList; 176 177 BStringList fReplacesList; 178 179 BString fChecksum; 180 BString fInstallPath; 181 }; 182 183 184 } // namespace BPackageKit 185 186 187 #endif // _PACKAGE__PACKAGE_INFO_H_ 188