Browse Source

cmCTestUpdateHandler: Port to cmXMLWriter

Daniel Pfeifer 10 years ago
parent
commit
ed42c203ed

+ 6 - 6
Source/CTest/cmCTestCVS.cxx

@@ -13,7 +13,7 @@
 
 
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
-#include "cmXMLSafe.h"
+#include "cmXMLWriter.h"
 
 
 #include <cmsys/RegularExpression.hxx>
 #include <cmsys/RegularExpression.hxx>
 #include <cmsys/FStream.hxx>
 #include <cmsys/FStream.hxx>
@@ -266,13 +266,13 @@ void cmCTestCVS::LoadRevisions(std::string const& file,
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-void cmCTestCVS::WriteXMLDirectory(std::ostream& xml,
+void cmCTestCVS::WriteXMLDirectory(cmXMLWriter& xml,
                                    std::string const& path,
                                    std::string const& path,
                                    Directory const& dir)
                                    Directory const& dir)
 {
 {
   const char* slash = path.empty()? "":"/";
   const char* slash = path.empty()? "":"/";
-  xml << "\t<Directory>\n"
-      << "\t\t<Name>" << cmXMLSafe(path) << "</Name>\n";
+  xml.StartElement("Directory");
+  xml.Element("Name", path);
 
 
   // Lookup the branch checked out in the working tree.
   // Lookup the branch checked out in the working tree.
   std::string branchFlag = this->ComputeBranchFlag(path);
   std::string branchFlag = this->ComputeBranchFlag(path);
@@ -298,11 +298,11 @@ void cmCTestCVS::WriteXMLDirectory(std::ostream& xml,
     File f(fi->second, &revisions[0], &revisions[1]);
     File f(fi->second, &revisions[0], &revisions[1]);
     this->WriteXMLEntry(xml, path, fi->first, full, f);
     this->WriteXMLEntry(xml, path, fi->first, full, f);
     }
     }
-  xml << "\t</Directory>\n";
+  xml.EndElement(); // Directory
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-bool cmCTestCVS::WriteXMLUpdates(std::ostream& xml)
+bool cmCTestCVS::WriteXMLUpdates(cmXMLWriter& xml)
 {
 {
   cmCTestLog(this->CTest, HANDLER_OUTPUT,
   cmCTestLog(this->CTest, HANDLER_OUTPUT,
              "   Gathering version information (one . per updated file):\n"
              "   Gathering version information (one . per updated file):\n"

+ 2 - 2
Source/CTest/cmCTestCVS.h

@@ -29,7 +29,7 @@ public:
 private:
 private:
   // Implement cmCTestVC internal API.
   // Implement cmCTestVC internal API.
   virtual bool UpdateImpl();
   virtual bool UpdateImpl();
-  virtual bool WriteXMLUpdates(std::ostream& xml);
+  virtual bool WriteXMLUpdates(cmXMLWriter& xml);
 
 
   // Update status for files in each directory.
   // Update status for files in each directory.
   class Directory: public std::map<std::string, PathStatus> {};
   class Directory: public std::map<std::string, PathStatus> {};
@@ -38,7 +38,7 @@ private:
   std::string ComputeBranchFlag(std::string const& dir);
   std::string ComputeBranchFlag(std::string const& dir);
   void LoadRevisions(std::string const& file, const char* branchFlag,
   void LoadRevisions(std::string const& file, const char* branchFlag,
                      std::vector<Revision>& revisions);
                      std::vector<Revision>& revisions);
-  void WriteXMLDirectory(std::ostream& xml, std::string const& path,
+  void WriteXMLDirectory(cmXMLWriter& xml, std::string const& path,
                          Directory const& dir);
                          Directory const& dir);
 
 
   // Parsing helper classes.
   // Parsing helper classes.

+ 9 - 9
Source/CTest/cmCTestGlobalVC.cxx

@@ -13,7 +13,7 @@
 
 
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
-#include "cmXMLSafe.h"
+#include "cmXMLWriter.h"
 
 
 #include <cmsys/RegularExpression.hxx>
 #include <cmsys/RegularExpression.hxx>
 
 
@@ -91,36 +91,36 @@ void cmCTestGlobalVC::DoModification(PathStatus status,
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-void cmCTestGlobalVC::WriteXMLDirectory(std::ostream& xml,
+void cmCTestGlobalVC::WriteXMLDirectory(cmXMLWriter& xml,
                                         std::string const& path,
                                         std::string const& path,
                                         Directory const& dir)
                                         Directory const& dir)
 {
 {
   const char* slash = path.empty()? "":"/";
   const char* slash = path.empty()? "":"/";
-  xml << "\t<Directory>\n"
-      << "\t\t<Name>" << cmXMLSafe(path) << "</Name>\n";
+  xml.StartElement("Directory");
+  xml.Element("Name", path);
   for(Directory::const_iterator fi = dir.begin(); fi != dir.end(); ++fi)
   for(Directory::const_iterator fi = dir.begin(); fi != dir.end(); ++fi)
     {
     {
     std::string full = path + slash + fi->first;
     std::string full = path + slash + fi->first;
     this->WriteXMLEntry(xml, path, fi->first, full, fi->second);
     this->WriteXMLEntry(xml, path, fi->first, full, fi->second);
     }
     }
-  xml << "\t</Directory>\n";
+  xml.EndElement(); // Directory
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-void cmCTestGlobalVC::WriteXMLGlobal(std::ostream& xml)
+void cmCTestGlobalVC::WriteXMLGlobal(cmXMLWriter& xml)
 {
 {
   if(!this->NewRevision.empty())
   if(!this->NewRevision.empty())
     {
     {
-    xml << "\t<Revision>" << this->NewRevision << "</Revision>\n";
+    xml.Element("Revision", this->NewRevision);
     }
     }
   if(!this->OldRevision.empty() && this->OldRevision != this->NewRevision)
   if(!this->OldRevision.empty() && this->OldRevision != this->NewRevision)
     {
     {
-    xml << "\t<PriorRevision>" << this->OldRevision << "</PriorRevision>\n";
+    xml.Element("PriorRevision", this->OldRevision);
     }
     }
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-bool cmCTestGlobalVC::WriteXMLUpdates(std::ostream& xml)
+bool cmCTestGlobalVC::WriteXMLUpdates(cmXMLWriter& xml)
 {
 {
   cmCTestLog(this->CTest, HANDLER_OUTPUT,
   cmCTestLog(this->CTest, HANDLER_OUTPUT,
              "   Gathering version information (one . per revision):\n"
              "   Gathering version information (one . per revision):\n"

+ 3 - 3
Source/CTest/cmCTestGlobalVC.h

@@ -30,7 +30,7 @@ public:
 
 
 protected:
 protected:
   // Implement cmCTestVC internal API.
   // Implement cmCTestVC internal API.
-  virtual bool WriteXMLUpdates(std::ostream& xml);
+  virtual bool WriteXMLUpdates(cmXMLWriter& xml);
 
 
   /** Represent a vcs-reported action for one path in a revision.  */
   /** Represent a vcs-reported action for one path in a revision.  */
   struct Change
   struct Change
@@ -62,8 +62,8 @@ protected:
   virtual void LoadModifications() = 0;
   virtual void LoadModifications() = 0;
   virtual void LoadRevisions() = 0;
   virtual void LoadRevisions() = 0;
 
 
-  virtual void WriteXMLGlobal(std::ostream& xml);
-  void WriteXMLDirectory(std::ostream& xml, std::string const& path,
+  virtual void WriteXMLGlobal(cmXMLWriter& xml);
+  void WriteXMLDirectory(cmXMLWriter& xml, std::string const& path,
                          Directory const& dir);
                          Directory const& dir);
 };
 };
 
 

+ 3 - 3
Source/CTest/cmCTestSVN.cxx

@@ -14,7 +14,7 @@
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 #include "cmXMLParser.h"
 #include "cmXMLParser.h"
-#include "cmXMLSafe.h"
+#include "cmXMLWriter.h"
 
 
 #include <cmsys/RegularExpression.hxx>
 #include <cmsys/RegularExpression.hxx>
 
 
@@ -535,11 +535,11 @@ void cmCTestSVN::LoadModifications()
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-void cmCTestSVN::WriteXMLGlobal(std::ostream& xml)
+void cmCTestSVN::WriteXMLGlobal(cmXMLWriter& xml)
 {
 {
   this->cmCTestGlobalVC::WriteXMLGlobal(xml);
   this->cmCTestGlobalVC::WriteXMLGlobal(xml);
 
 
-  xml << "\t<SVNPath>" << this->RootInfo->Base << "</SVNPath>\n";
+  xml.Element("SVNPath", this->RootInfo->Base);
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------

+ 1 - 1
Source/CTest/cmCTestSVN.h

@@ -84,7 +84,7 @@ private:
   void DoRevisionSVN(Revision const& revision,
   void DoRevisionSVN(Revision const& revision,
                      std::vector<Change> const& changes);
                      std::vector<Change> const& changes);
 
 
-  void WriteXMLGlobal(std::ostream& xml);
+  void WriteXMLGlobal(cmXMLWriter& xml);
 
 
   // Parsing helper classes.
   // Parsing helper classes.
   class InfoParser;
   class InfoParser;

+ 32 - 31
Source/CTest/cmCTestUpdateHandler.cxx

@@ -20,7 +20,7 @@
 #include "cmVersion.h"
 #include "cmVersion.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratedFileStream.h"
 #include "cmXMLParser.h"
 #include "cmXMLParser.h"
-#include "cmXMLSafe.h"
+#include "cmXMLWriter.h"
 #include "cmCLocaleEnvironmentScope.h"
 #include "cmCLocaleEnvironmentScope.h"
 
 
 #include "cmCTestVC.h"
 #include "cmCTestVC.h"
@@ -224,24 +224,24 @@ int cmCTestUpdateHandler::ProcessHandler()
   bool updated = vc->Update();
   bool updated = vc->Update();
   std::string buildname = cmCTest::SafeBuildIdField(
   std::string buildname = cmCTest::SafeBuildIdField(
     this->CTest->GetCTestConfiguration("BuildName"));
     this->CTest->GetCTestConfiguration("BuildName"));
-  os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-    << "<Update mode=\"Client\" Generator=\"ctest-"
-    << cmVersion::GetCMakeVersion() << "\">\n"
-    << "\t<Site>" << this->CTest->GetCTestConfiguration("Site") << "</Site>\n"
-    << "\t<BuildName>" << buildname
-    << "</BuildName>\n"
-    << "\t<BuildStamp>" << this->CTest->GetCurrentTag() << "-"
-    << this->CTest->GetTestModelString() << "</BuildStamp>" << std::endl;
-  os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
-    << "\t<StartTime>" << start_time_time << "</StartTime>\n"
-    << "\t<UpdateCommand>"
-     << cmXMLSafe(vc->GetUpdateCommandLine()).Quotes(false)
-    << "</UpdateCommand>\n"
-    << "\t<UpdateType>" << cmXMLSafe(
-      cmCTestUpdateHandlerUpdateToString(this->UpdateType))
-    << "</UpdateType>\n";
-
-  vc->WriteXML(os);
+
+  cmXMLWriter xml(os);
+  xml.StartDocument();
+  xml.StartElement("Update");
+  xml.Attribute("mode", "Client");
+  xml.Attribute("Generator",
+    std::string("ctest-") + cmVersion::GetCMakeVersion());
+  xml.Element("Site", this->CTest->GetCTestConfiguration("Site"));
+  xml.Element("BuildName", buildname);
+  xml.Element("BuildStamp", this->CTest->GetCurrentTag() + "-" +
+    this->CTest->GetTestModelString());
+  xml.Element("StartDateTime", start_time);
+  xml.Element("StartTime", start_time_time);
+  xml.Element("UpdateCommand", vc->GetUpdateCommandLine());
+  xml.Element("UpdateType",
+    cmCTestUpdateHandlerUpdateToString(this->UpdateType));
+
+  vc->WriteXML(xml);
 
 
   int localModifications = 0;
   int localModifications = 0;
   int numUpdated = vc->GetPathCount(cmCTestVC::PathUpdated);
   int numUpdated = vc->GetPathCount(cmCTestVC::PathUpdated);
@@ -265,29 +265,30 @@ int cmCTestUpdateHandler::ProcessHandler()
 
 
   cmCTestOptionalLog(this->CTest, DEBUG, "End" << std::endl, this->Quiet);
   cmCTestOptionalLog(this->CTest, DEBUG, "End" << std::endl, this->Quiet);
   std::string end_time = this->CTest->CurrentTime();
   std::string end_time = this->CTest->CurrentTime();
-  os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
-     << "\t<EndTime>" << static_cast<unsigned int>(cmSystemTools::GetTime())
-     << "</EndTime>\n"
-    << "<ElapsedMinutes>" <<
-    static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
-    << "</ElapsedMinutes>\n"
-    << "\t<UpdateReturnStatus>";
+  xml.Element("EndDateTime", end_time);
+  xml.Element("EndTime", static_cast<unsigned int>(cmSystemTools::GetTime()));
+  xml.Element("ElapsedMinutes",
+    static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0);
+
+  xml.StartElement("UpdateReturnStatus");
   if(localModifications)
   if(localModifications)
     {
     {
-    os << "Update error: There are modified or conflicting files in the "
-      "repository";
+    xml.Content("Update error: "
+      "There are modified or conflicting files in the repository");
     cmCTestLog(this->CTest, ERROR_MESSAGE,
     cmCTestLog(this->CTest, ERROR_MESSAGE,
       "   There are modified or conflicting files in the repository"
       "   There are modified or conflicting files in the repository"
       << std::endl);
       << std::endl);
     }
     }
   if(!updated)
   if(!updated)
     {
     {
-    os << "Update command failed:\n" << vc->GetUpdateCommandLine();
+    xml.Content("Update command failed:\n");
+    xml.Content(vc->GetUpdateCommandLine());
     cmCTestLog(this->CTest, ERROR_MESSAGE, "   Update command failed: "
     cmCTestLog(this->CTest, ERROR_MESSAGE, "   Update command failed: "
                << vc->GetUpdateCommandLine() << "\n");
                << vc->GetUpdateCommandLine() << "\n");
     }
     }
-  os << "</UpdateReturnStatus>" << std::endl;
-  os << "</Update>" << std::endl;
+  xml.EndElement(); // UpdateReturnStatus
+  xml.EndElement(); // Update
+  xml.EndDocument();
   return numUpdated;
   return numUpdated;
 }
 }
 
 

+ 18 - 20
Source/CTest/cmCTestVC.cxx

@@ -13,7 +13,7 @@
 
 
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
-#include "cmXMLSafe.h"
+#include "cmXMLWriter.h"
 
 
 #include <cmsys/Process.h>
 #include <cmsys/Process.h>
 
 
@@ -202,7 +202,7 @@ bool cmCTestVC::UpdateImpl()
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-bool cmCTestVC::WriteXML(std::ostream& xml)
+bool cmCTestVC::WriteXML(cmXMLWriter& xml)
 {
 {
   this->Log << "--- Begin Revisions ---\n";
   this->Log << "--- Begin Revisions ---\n";
   bool result = this->WriteXMLUpdates(xml);
   bool result = this->WriteXMLUpdates(xml);
@@ -211,7 +211,7 @@ bool cmCTestVC::WriteXML(std::ostream& xml)
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-bool cmCTestVC::WriteXMLUpdates(std::ostream&)
+bool cmCTestVC::WriteXMLUpdates(cmXMLWriter&)
 {
 {
   cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
   cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
              "* CTest cannot extract updates for this VCS tool.\n");
              "* CTest cannot extract updates for this VCS tool.\n");
@@ -219,7 +219,7 @@ bool cmCTestVC::WriteXMLUpdates(std::ostream&)
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-void cmCTestVC::WriteXMLEntry(std::ostream& xml,
+void cmCTestVC::WriteXMLEntry(cmXMLWriter& xml,
                               std::string const& path,
                               std::string const& path,
                               std::string const& name,
                               std::string const& name,
                               std::string const& full,
                               std::string const& full,
@@ -228,21 +228,19 @@ void cmCTestVC::WriteXMLEntry(std::ostream& xml,
   static const char* desc[3] = { "Updated", "Modified", "Conflicting"};
   static const char* desc[3] = { "Updated", "Modified", "Conflicting"};
   Revision const& rev = f.Rev? *f.Rev : this->Unknown;
   Revision const& rev = f.Rev? *f.Rev : this->Unknown;
   std::string prior = f.PriorRev? f.PriorRev->Rev : std::string("Unknown");
   std::string prior = f.PriorRev? f.PriorRev->Rev : std::string("Unknown");
-  xml << "\t\t<" << desc[f.Status] << ">\n"
-      << "\t\t\t<File>" << cmXMLSafe(name) << "</File>\n"
-      << "\t\t\t<Directory>" << cmXMLSafe(path) << "</Directory>\n"
-      << "\t\t\t<FullName>" << cmXMLSafe(full) << "</FullName>\n"
-      << "\t\t\t<CheckinDate>" << cmXMLSafe(rev.Date) << "</CheckinDate>\n"
-      << "\t\t\t<Author>" << cmXMLSafe(rev.Author) << "</Author>\n"
-      << "\t\t\t<Email>" << cmXMLSafe(rev.EMail) << "</Email>\n"
-      << "\t\t\t<Committer>" << cmXMLSafe(rev.Committer) << "</Committer>\n"
-      << "\t\t\t<CommitterEmail>" << cmXMLSafe(rev.CommitterEMail)
-      << "</CommitterEmail>\n"
-      << "\t\t\t<CommitDate>" << cmXMLSafe(rev.CommitDate)
-      << "</CommitDate>\n"
-      << "\t\t\t<Log>" << cmXMLSafe(rev.Log) << "</Log>\n"
-      << "\t\t\t<Revision>" << cmXMLSafe(rev.Rev) << "</Revision>\n"
-      << "\t\t\t<PriorRevision>" << cmXMLSafe(prior) << "</PriorRevision>\n"
-      << "\t\t</" << desc[f.Status] << ">\n";
+  xml.StartElement(desc[f.Status]);
+  xml.Element("File", name);
+  xml.Element("Directory", path);
+  xml.Element("FullName", full);
+  xml.Element("CheckinDate", rev.Date);
+  xml.Element("Author", rev.Author);
+  xml.Element("Email", rev.EMail);
+  xml.Element("Committer", rev.Committer);
+  xml.Element("CommitterEmail", rev.CommitterEMail);
+  xml.Element("CommitDate", rev.CommitDate);
+  xml.Element("Log", rev.Log);
+  xml.Element("Revision", rev.Rev);
+  xml.Element("PriorRevision", prior);
+  xml.EndElement();
   ++this->PathCount[f.Status];
   ++this->PathCount[f.Status];
 }
 }

+ 4 - 3
Source/CTest/cmCTestVC.h

@@ -15,6 +15,7 @@
 #include "cmProcessTools.h"
 #include "cmProcessTools.h"
 
 
 class cmCTest;
 class cmCTest;
+class cmXMLWriter;
 
 
 /** \class cmCTestVC
 /** \class cmCTestVC
  * \brief Base class for version control system handlers
  * \brief Base class for version control system handlers
@@ -51,7 +52,7 @@ public:
     { return this->UpdateCommandLine; }
     { return this->UpdateCommandLine; }
 
 
   /** Write Update.xml entries for the updates found.  */
   /** Write Update.xml entries for the updates found.  */
-  bool WriteXML(std::ostream& xml);
+  bool WriteXML(cmXMLWriter& xml);
 
 
   /** Enumerate non-trivial working tree states during update.  */
   /** Enumerate non-trivial working tree states during update.  */
   enum PathStatus { PathUpdated, PathModified, PathConflicting };
   enum PathStatus { PathUpdated, PathModified, PathConflicting };
@@ -65,7 +66,7 @@ protected:
   virtual void NoteOldRevision();
   virtual void NoteOldRevision();
   virtual bool UpdateImpl();
   virtual bool UpdateImpl();
   virtual void NoteNewRevision();
   virtual void NoteNewRevision();
-  virtual bool WriteXMLUpdates(std::ostream& xml);
+  virtual bool WriteXMLUpdates(cmXMLWriter& xml);
 
 
 #if defined(__SUNPRO_CC) && __SUNPRO_CC <= 0x510
 #if defined(__SUNPRO_CC) && __SUNPRO_CC <= 0x510
 public: // Sun CC 5.1 needs help to allow cmCTestSVN::Revision to see this
 public: // Sun CC 5.1 needs help to allow cmCTestSVN::Revision to see this
@@ -110,7 +111,7 @@ protected:
                         OutputParser* out, OutputParser* err = 0);
                         OutputParser* out, OutputParser* err = 0);
 
 
   /** Write xml element for one file.  */
   /** Write xml element for one file.  */
-  void WriteXMLEntry(std::ostream& xml, std::string const& path,
+  void WriteXMLEntry(cmXMLWriter& xml, std::string const& path,
                      std::string const& name, std::string const& full,
                      std::string const& name, std::string const& full,
                      File const& f);
                      File const& f);