CPack/IFW: port to cmXMLWriter

This commit is contained in:
Daniel Pfeifer 2015-07-16 21:53:57 +02:00 committed by Brad King
parent 754485afff
commit 51465da1ec
6 changed files with 81 additions and 103 deletions

View File

@ -27,7 +27,7 @@
#include <cmSystemTools.h> #include <cmSystemTools.h>
#include <cmMakefile.h> #include <cmMakefile.h>
#include <cmGeneratedFileStream.h> #include <cmGeneratedFileStream.h>
#include <cmXMLSafe.h> #include <cmXMLWriter.h>
#include <cmVersionConfig.h> #include <cmVersionConfig.h>
#include <cmTimestamp.h> #include <cmTimestamp.h>
@ -611,18 +611,19 @@ cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage(
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCPackIFWGenerator::WriteGeneratedByToStrim(cmGeneratedFileStream &xout) void cmCPackIFWGenerator::WriteGeneratedByToStrim(cmXMLWriter &xout)
{ {
xout << "<!-- Generated by CPack " << CMake_VERSION << " IFW generator " std::stringstream comment;
comment << "Generated by CPack " << CMake_VERSION << " IFW generator "
<< "for QtIFW "; << "for QtIFW ";
if(IsVersionLess("2.0")) if(IsVersionLess("2.0"))
{ {
xout << "less 2.0"; comment << "less 2.0";
} }
else else
{ {
xout << FrameworkVersion; comment << FrameworkVersion;
} }
xout << " tools at " << cmTimestamp().CurrentTime("", true) << " -->" comment << " tools at " << cmTimestamp().CurrentTime("", true);
<< std::endl; xout.Comment(comment.str().c_str());
} }

View File

@ -13,12 +13,13 @@
#ifndef cmCPackIFWGenerator_h #ifndef cmCPackIFWGenerator_h
#define cmCPackIFWGenerator_h #define cmCPackIFWGenerator_h
#include <cmGeneratedFileStream.h>
#include <CPack/cmCPackGenerator.h> #include <CPack/cmCPackGenerator.h>
#include "cmCPackIFWPackage.h" #include "cmCPackIFWPackage.h"
#include "cmCPackIFWInstaller.h" #include "cmCPackIFWInstaller.h"
class cmXMLWriter;
/** \class cmCPackIFWGenerator /** \class cmCPackIFWGenerator
* \brief A generator for Qt Installer Framework tools * \brief A generator for Qt Installer Framework tools
* *
@ -121,7 +122,7 @@ protected: // Methods
cmCPackIFWPackage* GetGroupPackage(cmCPackComponentGroup *group) const; cmCPackIFWPackage* GetGroupPackage(cmCPackComponentGroup *group) const;
cmCPackIFWPackage* GetComponentPackage(cmCPackComponent *component) const; cmCPackIFWPackage* GetComponentPackage(cmCPackComponent *component) const;
void WriteGeneratedByToStrim(cmGeneratedFileStream& xout); void WriteGeneratedByToStrim(cmXMLWriter& xout);
protected: // Data protected: // Data

View File

@ -17,7 +17,7 @@
#include <CPack/cmCPackLog.h> #include <CPack/cmCPackLog.h>
#include <cmGeneratedFileStream.h> #include <cmGeneratedFileStream.h>
#include <cmXMLSafe.h> #include <cmXMLWriter.h>
#ifdef cmCPackLogger #ifdef cmCPackLogger
# undef cmCPackLogger # undef cmCPackLogger
@ -334,30 +334,27 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
} }
// Output stream // Output stream
cmGeneratedFileStream xout((Directory + "/config/config.xml").data()); cmGeneratedFileStream fout((Directory + "/config/config.xml").data());
cmXMLWriter xout(fout);
xout << "<?xml version=\"1.0\"?>" << std::endl; xout.StartDocument();
WriteGeneratedByToStrim(xout); WriteGeneratedByToStrim(xout);
xout << "<Installer>" << std::endl; xout.StartElement("Installer");
xout << " <Name>" << cmXMLSafe(Name).str() << "</Name>" << std::endl; xout.Element("Name", Name);
xout.Element("Version", Version);
xout << " <Version>" << Version << "</Version>" << std::endl; xout.Element("Title", Title);
xout << " <Title>" << cmXMLSafe(Title).str() << "</Title>"
<< std::endl;
if(!Publisher.empty()) if(!Publisher.empty())
{ {
xout << " <Publisher>" << cmXMLSafe(Publisher).str() xout.Element("Publisher", Publisher);
<< "</Publisher>" << std::endl;
} }
if(!ProductUrl.empty()) if(!ProductUrl.empty())
{ {
xout << " <ProductUrl>" << ProductUrl << "</ProductUrl>" << std::endl; xout.Element("ProductUrl", ProductUrl);
} }
// ApplicationIcon // ApplicationIcon
@ -369,8 +366,7 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
name = cmSystemTools::GetFilenameWithoutExtension(name); name = cmSystemTools::GetFilenameWithoutExtension(name);
cmsys::SystemTools::CopyFileIfDifferent( cmsys::SystemTools::CopyFileIfDifferent(
InstallerApplicationIcon.data(), path.data()); InstallerApplicationIcon.data(), path.data());
xout << " <InstallerApplicationIcon>" << name xout.Element("InstallerApplicationIcon", name);
<< "</InstallerApplicationIcon>" << std::endl;
} }
// WindowIcon // WindowIcon
@ -380,8 +376,7 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
std::string path = Directory + "/config/" + name; std::string path = Directory + "/config/" + name;
cmsys::SystemTools::CopyFileIfDifferent( cmsys::SystemTools::CopyFileIfDifferent(
InstallerWindowIcon.data(), path.data()); InstallerWindowIcon.data(), path.data());
xout << " <InstallerWindowIcon>" << name xout.Element("InstallerWindowIcon", name);
<< "</InstallerWindowIcon>" << std::endl;
} }
// Logo // Logo
@ -390,104 +385,91 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
std::string name = cmSystemTools::GetFilenameName(Logo); std::string name = cmSystemTools::GetFilenameName(Logo);
std::string path = Directory + "/config/" + name; std::string path = Directory + "/config/" + name;
cmsys::SystemTools::CopyFileIfDifferent(Logo.data(), path.data()); cmsys::SystemTools::CopyFileIfDifferent(Logo.data(), path.data());
xout << " <Logo>" << name << "</Logo>" << std::endl; xout.Element("Logo", name);
} }
// Start menu // Start menu
if(!IsVersionLess("2.0")) if(!IsVersionLess("2.0"))
{ {
xout << " <StartMenuDir>" << StartMenuDir xout.Element("StartMenuDir", StartMenuDir);
<< "</StartMenuDir>" << std::endl;
} }
// Target dir // Target dir
if(!TargetDir.empty()) if(!TargetDir.empty())
{ {
xout << " <TargetDir>" << TargetDir << "</TargetDir>" << std::endl; xout.Element("TargetDir", TargetDir);
} }
// Admin target dir // Admin target dir
if(!AdminTargetDir.empty()) if(!AdminTargetDir.empty())
{ {
xout << " <AdminTargetDir>" << AdminTargetDir xout.Element("AdminTargetDir", AdminTargetDir);
<< "</AdminTargetDir>" << std::endl;
} }
// Remote repositories // Remote repositories
if (!Repositories.empty()) if (!Repositories.empty())
{ {
xout << " <RemoteRepositories>" << std::endl; xout.StartElement("RemoteRepositories");
for(std::vector<RepositoryStruct>::iterator for(std::vector<RepositoryStruct>::iterator
rit = Repositories.begin(); rit != Repositories.end(); ++rit) rit = Repositories.begin(); rit != Repositories.end(); ++rit)
{ {
xout << " <Repository>" << std::endl; xout.StartElement("Repository");
// Url // Url
xout << " <Url>" << rit->Url xout.Element("Url", rit->Url);
<< "</Url>" << std::endl;
// Enabled // Enabled
if(!rit->Enabled.empty()) if(!rit->Enabled.empty())
{ {
xout << " <Enabled>" << rit->Enabled xout.Element("Enabled", rit->Enabled);
<< "</Enabled>" << std::endl;
} }
// Username // Username
if(!rit->Username.empty()) if(!rit->Username.empty())
{ {
xout << " <Username>" << rit->Username xout.Element("Username", rit->Username);
<< "</Username>" << std::endl;
} }
// Password // Password
if(!rit->Password.empty()) if(!rit->Password.empty())
{ {
xout << " <Password>" << rit->Password xout.Element("Password", rit->Password);
<< "</Password>" << std::endl;
} }
// DisplayName // DisplayName
if(!rit->DisplayName.empty()) if(!rit->DisplayName.empty())
{ {
xout << " <DisplayName>" << rit->DisplayName xout.Element("DisplayName", rit->DisplayName);
<< "</DisplayName>" << std::endl;
} }
xout << " </Repository>" << std::endl; xout.EndElement();
} }
xout << " </RemoteRepositories>" << std::endl; xout.EndElement();
} }
// Maintenance tool // Maintenance tool
if(!IsVersionLess("2.0") && !MaintenanceToolName.empty()) if(!IsVersionLess("2.0") && !MaintenanceToolName.empty())
{ {
xout << " <MaintenanceToolName>" << MaintenanceToolName xout.Element("MaintenanceToolName", MaintenanceToolName);
<< "</MaintenanceToolName>" << std::endl;
} }
// Maintenance tool ini file // Maintenance tool ini file
if(!IsVersionLess("2.0") && !MaintenanceToolIniFile.empty()) if(!IsVersionLess("2.0") && !MaintenanceToolIniFile.empty())
{ {
xout << " <MaintenanceToolIniFile>" << MaintenanceToolIniFile xout.Element("MaintenanceToolIniFile", MaintenanceToolIniFile);
<< "</MaintenanceToolIniFile>" << std::endl;
} }
// Different allows // Different allows
if(IsVersionLess("2.0")) if(IsVersionLess("2.0"))
{ {
// CPack IFW default policy // CPack IFW default policy
xout << " <!-- CPack IFW default policy for QtIFW less 2.0 -->" xout.Comment("CPack IFW default policy for QtIFW less 2.0");
<< std::endl; xout.Element("AllowNonAsciiCharacters", "true");
xout << " <AllowNonAsciiCharacters>true</AllowNonAsciiCharacters>" xout.Element("AllowSpaceInPath", "true");
<< std::endl;
xout << " <AllowSpaceInPath>true</AllowSpaceInPath>" << std::endl;
} }
else else
{ {
if(!AllowNonAsciiCharacters.empty()) if(!AllowNonAsciiCharacters.empty())
{ {
xout << " <AllowNonAsciiCharacters>" << AllowNonAsciiCharacters xout.Element("AllowNonAsciiCharacters", AllowNonAsciiCharacters);
<< "</AllowNonAsciiCharacters>" << std::endl;
} }
if(!AllowSpaceInPath.empty()) if(!AllowSpaceInPath.empty())
{ {
xout << " <AllowAllowSpaceInPath>" << AllowSpaceInPath xout.Element("AllowSpaceInPath", AllowSpaceInPath);
<< "</AllowSpaceInPath>" << std::endl;
} }
} }
@ -497,10 +479,11 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
std::string name = cmSystemTools::GetFilenameName(ControlScript); std::string name = cmSystemTools::GetFilenameName(ControlScript);
std::string path = Directory + "/config/" + name; std::string path = Directory + "/config/" + name;
cmsys::SystemTools::CopyFileIfDifferent(ControlScript.data(), path.data()); cmsys::SystemTools::CopyFileIfDifferent(ControlScript.data(), path.data());
xout << " <ControlScript>" << name << "</ControlScript>" << std::endl; xout.Element("ControlScript", name);
} }
xout << "</Installer>" << std::endl; xout.EndElement();
xout.EndDocument();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -535,7 +518,7 @@ void cmCPackIFWInstaller::GeneratePackageFiles()
} }
} }
void cmCPackIFWInstaller::WriteGeneratedByToStrim(cmGeneratedFileStream &xout) void cmCPackIFWInstaller::WriteGeneratedByToStrim(cmXMLWriter &xout)
{ {
if(Generator) Generator->WriteGeneratedByToStrim(xout); if(Generator) Generator->WriteGeneratedByToStrim(xout);
} }

View File

@ -13,11 +13,11 @@
#ifndef cmCPackIFWInstaller_h #ifndef cmCPackIFWInstaller_h
#define cmCPackIFWInstaller_h #define cmCPackIFWInstaller_h
#include <cmGeneratedFileStream.h>
#include <cmStandardIncludes.h> #include <cmStandardIncludes.h>
class cmCPackIFWPackage; class cmCPackIFWPackage;
class cmCPackIFWGenerator; class cmCPackIFWGenerator;
class cmXMLWriter;
/** \class cmCPackIFWInstaller /** \class cmCPackIFWInstaller
* \brief A binary installer to be created CPack IFW generator * \brief A binary installer to be created CPack IFW generator
@ -115,7 +115,7 @@ public: // Internal implementation
std::string Directory; std::string Directory;
protected: protected:
void WriteGeneratedByToStrim(cmGeneratedFileStream& xout); void WriteGeneratedByToStrim(cmXMLWriter& xout);
}; };
#endif // cmCPackIFWInstaller_h #endif // cmCPackIFWInstaller_h

View File

@ -18,6 +18,7 @@
#include <cmGeneratedFileStream.h> #include <cmGeneratedFileStream.h>
#include <cmTimestamp.h> #include <cmTimestamp.h>
#include <cmXMLWriter.h>
//----------------------------------------------------------------- Logger --- //----------------------------------------------------------------- Logger ---
#ifdef cmCPackLogger #ifdef cmCPackLogger
@ -447,35 +448,28 @@ void cmCPackIFWPackage::GeneratePackageFile()
} }
// Output stream // Output stream
cmGeneratedFileStream xout((Directory + "/meta/package.xml").data()); cmGeneratedFileStream fout((Directory + "/meta/package.xml").data());
cmXMLWriter xout(fout);
xout << "<?xml version=\"1.0\"?>" << std::endl; xout.StartDocument();
WriteGeneratedByToStrim(xout); WriteGeneratedByToStrim(xout);
xout << "<Package>" << std::endl; xout.StartElement("Package");
xout << " <DisplayName>" << DisplayName xout.Element("DisplayName", DisplayName);
<< "</DisplayName>" << std::endl; xout.Element("Description", Description);
xout.Element("Name", Name);
xout.Element("Version", Version);
xout << " <Description>" << Description if (!ReleaseDate.empty())
<< "</Description>" << std::endl;
xout << " <Name>" << Name << "</Name>" << std::endl;
xout << " <Version>" << Version
<< "</Version>" << std::endl;
xout << " <ReleaseDate>";
if(ReleaseDate.empty())
{ {
xout << cmTimestamp().CurrentTime("%Y-%m-%d", true); xout.Element("ReleaseDate", ReleaseDate);
} }
else else
{ {
xout << ReleaseDate; xout.Element("ReleaseDate", cmTimestamp().CurrentTime("%Y-%m-%d", true));
} }
xout << "</ReleaseDate>" << std::endl;
// Script (copy to meta dir) // Script (copy to meta dir)
if(!Script.empty()) if(!Script.empty())
@ -483,7 +477,7 @@ void cmCPackIFWPackage::GeneratePackageFile()
std::string name = cmSystemTools::GetFilenameName(Script); std::string name = cmSystemTools::GetFilenameName(Script);
std::string path = Directory + "/meta/" + name; std::string path = Directory + "/meta/" + name;
cmsys::SystemTools::CopyFileIfDifferent(Script.data(), path.data()); cmsys::SystemTools::CopyFileIfDifferent(Script.data(), path.data());
xout << " <Script>" << name << "</Script>" << std::endl; xout.Element("Script", name);
} }
// Dependencies // Dependencies
@ -501,16 +495,16 @@ void cmCPackIFWPackage::GeneratePackageFile()
// Write dependencies // Write dependencies
if (!compDepSet.empty()) if (!compDepSet.empty())
{ {
xout << " <Dependencies>"; std::stringstream dependencies;
std::set<DependenceStruct>::iterator it = compDepSet.begin(); std::set<DependenceStruct>::iterator it = compDepSet.begin();
xout << it->NameWithCompare(); dependencies << it->NameWithCompare();
++it; ++it;
while(it != compDepSet.end()) while(it != compDepSet.end())
{ {
xout << "," << it->NameWithCompare(); dependencies << "," << it->NameWithCompare();
++it; ++it;
} }
xout << "</Dependencies>" << std::endl; xout.Element("Dependencies", dependencies.str());
} }
// Licenses (copy to meta dir) // Licenses (copy to meta dir)
@ -524,43 +518,42 @@ void cmCPackIFWPackage::GeneratePackageFile()
} }
if(!licenses.empty()) if(!licenses.empty())
{ {
xout << " <Licenses>" << std::endl; xout.StartElement("Licenses");
for(size_t i = 0; i < licenses.size(); i += 2) for(size_t i = 0; i < licenses.size(); i += 2)
{ {
xout << " <License " xout.StartElement("License");
<< "name=\"" << licenses[i] << "\" " xout.Attribute("name", licenses[i]);
<< "file=\"" << licenses[i + 1] << "\" " xout.Attribute("file", licenses[i + 1]);
<< "/>" <<std::endl; xout.EndElement();
} }
xout << " </Licenses>" << std::endl; xout.EndElement();
} }
if (!ForcedInstallation.empty()) if (!ForcedInstallation.empty())
{ {
xout << " <ForcedInstallation>" << ForcedInstallation xout.Element("ForcedInstallation", ForcedInstallation);
<< "</ForcedInstallation>" << std::endl;
} }
if (!Virtual.empty()) if (!Virtual.empty())
{ {
xout << " <Virtual>" << Virtual << "</Virtual>" << std::endl; xout.Element("Virtual", Virtual);
} }
else if (!Default.empty()) else if (!Default.empty())
{ {
xout << " <Default>" << Default << "</Default>" << std::endl; xout.Element("Default", Default);
} }
// Priority // Priority
if(!SortingPriority.empty()) if(!SortingPriority.empty())
{ {
xout << " <SortingPriority>" << SortingPriority xout.Element("SortingPriority", SortingPriority);
<< "</SortingPriority>" << std::endl;
} }
xout << "</Package>" << std::endl; xout.EndElement();
xout.EndDocument();
} }
void cmCPackIFWPackage::WriteGeneratedByToStrim(cmGeneratedFileStream &xout) void cmCPackIFWPackage::WriteGeneratedByToStrim(cmXMLWriter &xout)
{ {
if(Generator) Generator->WriteGeneratedByToStrim(xout); if(Generator) Generator->WriteGeneratedByToStrim(xout);
} }

View File

@ -14,12 +14,12 @@
#define cmCPackIFWPackage_h #define cmCPackIFWPackage_h
#include <cmStandardIncludes.h> #include <cmStandardIncludes.h>
#include <cmGeneratedFileStream.h>
class cmCPackComponent; class cmCPackComponent;
class cmCPackComponentGroup; class cmCPackComponentGroup;
class cmCPackIFWInstaller; class cmCPackIFWInstaller;
class cmCPackIFWGenerator; class cmCPackIFWGenerator;
class cmXMLWriter;
/** \class cmCPackIFWPackage /** \class cmCPackIFWPackage
* \brief A single component to be installed by CPack IFW generator * \brief A single component to be installed by CPack IFW generator
@ -135,7 +135,7 @@ public: // Internal implementation
std::string Directory; std::string Directory;
protected: protected:
void WriteGeneratedByToStrim(cmGeneratedFileStream& xout); void WriteGeneratedByToStrim(cmXMLWriter& xout);
}; };
#endif // cmCPackIFWPackage_h #endif // cmCPackIFWPackage_h