Add class BPackageInfoContentHandler
A BPackageContentHandler subclass that initializes a BPackageInfo from the read package attributes. Pulled out of RepositoryWriterImpl's PackageContentHandler.
This commit is contained in:
parent
dbe2a683f0
commit
26265b7b4d
1
headers/build/os/package/PackageInfoContentHandler.h
Normal file
1
headers/build/os/package/PackageInfoContentHandler.h
Normal file
@ -0,0 +1 @@
|
||||
#include <../os/package/PackageInfoContentHandler.h>
|
51
headers/os/package/PackageInfoContentHandler.h
Normal file
51
headers/os/package/PackageInfoContentHandler.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__PACKAGE_INFO_CONTENT_HANDLER_H_
|
||||
#define _PACKAGE__PACKAGE_INFO_CONTENT_HANDLER_H_
|
||||
|
||||
|
||||
#include <package/hpkg/PackageContentHandler.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
class BPackageInfo;
|
||||
|
||||
|
||||
namespace BHPKG {
|
||||
class BErrorOutput;
|
||||
}
|
||||
|
||||
|
||||
class BPackageInfoContentHandler : public BHPKG::BPackageContentHandler {
|
||||
public:
|
||||
BPackageInfoContentHandler(
|
||||
BPackageInfo& packageInfo,
|
||||
BHPKG::BErrorOutput* errorOutput = NULL);
|
||||
virtual ~BPackageInfoContentHandler();
|
||||
|
||||
virtual status_t HandleEntry(BHPKG::BPackageEntry* entry);
|
||||
virtual status_t HandleEntryAttribute(
|
||||
BHPKG::BPackageEntry* entry,
|
||||
BHPKG::BPackageEntryAttribute* attribute);
|
||||
virtual status_t HandleEntryDone(BHPKG::BPackageEntry* entry);
|
||||
|
||||
virtual status_t HandlePackageAttribute(
|
||||
const BHPKG::BPackageInfoAttributeValue&
|
||||
value);
|
||||
|
||||
virtual void HandleErrorOccurred();
|
||||
|
||||
protected:
|
||||
BPackageInfo& fPackageInfo;
|
||||
BHPKG::BErrorOutput* fErrorOutput;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__PACKAGE_INFO_CONTENT_HANDLER_H_
|
@ -68,6 +68,7 @@ BuildPlatformSharedLibrary libpackage_build.so
|
||||
Job.cpp
|
||||
JobQueue.cpp
|
||||
PackageInfo.cpp
|
||||
PackageInfoContentHandler.cpp
|
||||
PackageInfoSet.cpp
|
||||
PackageResolvable.cpp
|
||||
PackageResolvableExpression.cpp
|
||||
|
@ -55,6 +55,7 @@ SharedLibrary libpackage.so
|
||||
Job.cpp
|
||||
JobQueue.cpp
|
||||
PackageInfo.cpp
|
||||
PackageInfoContentHandler.cpp
|
||||
PackageInfoSet.cpp
|
||||
PackageResolvable.cpp
|
||||
PackageResolvableExpression.cpp
|
||||
|
161
src/kits/package/PackageInfoContentHandler.cpp
Normal file
161
src/kits/package/PackageInfoContentHandler.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <package/PackageInfoContentHandler.h>
|
||||
|
||||
#include <package/PackageInfo.h>
|
||||
#include <package/hpkg/ErrorOutput.h>
|
||||
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
using namespace BHPKG;
|
||||
|
||||
|
||||
BPackageInfoContentHandler::BPackageInfoContentHandler(
|
||||
BPackageInfo& packageInfo, BErrorOutput* errorOutput)
|
||||
:
|
||||
fPackageInfo(packageInfo),
|
||||
fErrorOutput(errorOutput)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BPackageInfoContentHandler::~BPackageInfoContentHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPackageInfoContentHandler::HandleEntry(BPackageEntry* entry)
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPackageInfoContentHandler::HandleEntryAttribute(BPackageEntry* entry,
|
||||
BPackageEntryAttribute* attribute)
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPackageInfoContentHandler::HandleEntryDone(BPackageEntry* entry)
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPackageInfoContentHandler::HandlePackageAttribute(
|
||||
const BPackageInfoAttributeValue& value)
|
||||
{
|
||||
switch (value.attributeID) {
|
||||
case B_PACKAGE_INFO_NAME:
|
||||
fPackageInfo.SetName(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_SUMMARY:
|
||||
fPackageInfo.SetSummary(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_DESCRIPTION:
|
||||
fPackageInfo.SetDescription(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_VENDOR:
|
||||
fPackageInfo.SetVendor(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_PACKAGER:
|
||||
fPackageInfo.SetPackager(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_FLAGS:
|
||||
fPackageInfo.SetFlags(value.unsignedInt);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_ARCHITECTURE:
|
||||
fPackageInfo.SetArchitecture(
|
||||
(BPackageArchitecture)value.unsignedInt);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_VERSION:
|
||||
fPackageInfo.SetVersion(value.version);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_COPYRIGHTS:
|
||||
fPackageInfo.AddCopyright(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_LICENSES:
|
||||
fPackageInfo.AddLicense(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_PROVIDES:
|
||||
fPackageInfo.AddProvides(value.resolvable);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_REQUIRES:
|
||||
fPackageInfo.AddRequires(value.resolvableExpression);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_SUPPLEMENTS:
|
||||
fPackageInfo.AddSupplements(value.resolvableExpression);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_CONFLICTS:
|
||||
fPackageInfo.AddConflicts(value.resolvableExpression);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_FRESHENS:
|
||||
fPackageInfo.AddFreshens(value.resolvableExpression);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_REPLACES:
|
||||
fPackageInfo.AddReplaces(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_URLS:
|
||||
fPackageInfo.AddURL(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_SOURCE_URLS:
|
||||
fPackageInfo.AddSourceURL(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_CHECKSUM:
|
||||
fPackageInfo.SetChecksum(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_INSTALL_PATH:
|
||||
fPackageInfo.SetInstallPath(value.string);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (fErrorOutput != NULL) {
|
||||
fErrorOutput->PrintError(
|
||||
"Invalid package attribute section: unexpected package "
|
||||
"attribute id %d encountered\n", value.attributeID);
|
||||
}
|
||||
return B_BAD_DATA;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageInfoContentHandler::HandleErrorOccurred()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPackageKit
|
@ -24,6 +24,7 @@
|
||||
#include <package/BlockBufferCacheNoLock.h>
|
||||
#include <package/ChecksumAccessors.h>
|
||||
#include <package/HashableString.h>
|
||||
#include <package/PackageInfoContentHandler.h>
|
||||
#include <package/RepositoryInfo.h>
|
||||
|
||||
|
||||
@ -85,12 +86,11 @@ private:
|
||||
};
|
||||
|
||||
|
||||
struct PackageContentHandler : public BPackageContentHandler {
|
||||
struct PackageContentHandler : public BPackageInfoContentHandler {
|
||||
PackageContentHandler(BErrorOutput* errorOutput, BPackageInfo* packageInfo,
|
||||
int packageFileFD, BRepositoryInfo* repositoryInfo)
|
||||
:
|
||||
fErrorOutput(errorOutput),
|
||||
fPackageInfo(packageInfo),
|
||||
BPackageInfoContentHandler(*packageInfo, errorOutput),
|
||||
fPackageFileReader(packageFileFD),
|
||||
fRepositoryInfo(repositoryInfo)
|
||||
{
|
||||
@ -100,7 +100,7 @@ struct PackageContentHandler : public BPackageContentHandler {
|
||||
{
|
||||
// if license must be approved, read any license files from package such
|
||||
// that those can be stored in the repository later
|
||||
if ((fPackageInfo->Flags() & B_PACKAGE_FLAG_APPROVE_LICENSE) == 0
|
||||
if ((fPackageInfo.Flags() & B_PACKAGE_FLAG_APPROVE_LICENSE) == 0
|
||||
|| entry == NULL)
|
||||
return B_OK;
|
||||
|
||||
@ -160,108 +160,11 @@ struct PackageContentHandler : public BPackageContentHandler {
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual status_t HandlePackageAttribute(
|
||||
const BPackageInfoAttributeValue& value)
|
||||
{
|
||||
switch (value.attributeID) {
|
||||
case B_PACKAGE_INFO_NAME:
|
||||
fPackageInfo->SetName(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_SUMMARY:
|
||||
fPackageInfo->SetSummary(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_DESCRIPTION:
|
||||
fPackageInfo->SetDescription(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_VENDOR:
|
||||
fPackageInfo->SetVendor(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_PACKAGER:
|
||||
fPackageInfo->SetPackager(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_FLAGS:
|
||||
fPackageInfo->SetFlags(value.unsignedInt);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_ARCHITECTURE:
|
||||
fPackageInfo->SetArchitecture(
|
||||
(BPackageArchitecture)value.unsignedInt);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_VERSION:
|
||||
fPackageInfo->SetVersion(value.version);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_COPYRIGHTS:
|
||||
fPackageInfo->AddCopyright(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_LICENSES:
|
||||
fPackageInfo->AddLicense(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_PROVIDES:
|
||||
fPackageInfo->AddProvides(value.resolvable);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_REQUIRES:
|
||||
fPackageInfo->AddRequires(value.resolvableExpression);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_SUPPLEMENTS:
|
||||
fPackageInfo->AddSupplements(value.resolvableExpression);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_CONFLICTS:
|
||||
fPackageInfo->AddConflicts(value.resolvableExpression);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_FRESHENS:
|
||||
fPackageInfo->AddFreshens(value.resolvableExpression);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_REPLACES:
|
||||
fPackageInfo->AddReplaces(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_URLS:
|
||||
fPackageInfo->AddURL(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_SOURCE_URLS:
|
||||
fPackageInfo->AddSourceURL(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_CHECKSUM:
|
||||
fPackageInfo->SetChecksum(value.string);
|
||||
break;
|
||||
|
||||
case B_PACKAGE_INFO_INSTALL_PATH:
|
||||
fPackageInfo->SetInstallPath(value.string);
|
||||
break;
|
||||
|
||||
default:
|
||||
fErrorOutput->PrintError(
|
||||
"Invalid package attribute section: unexpected package "
|
||||
"attribute id %d encountered\n", value.attributeID);
|
||||
return B_BAD_DATA;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual void HandleErrorOccurred()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
BErrorOutput* fErrorOutput;
|
||||
BPackageInfo* fPackageInfo;
|
||||
BPackageReader* fPackageReader;
|
||||
BFDDataReader fPackageFileReader;
|
||||
BRepositoryInfo* fRepositoryInfo;
|
||||
|
Loading…
Reference in New Issue
Block a user