diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 6f43a1e0c..50639b0ae 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -13,7 +13,7 @@ #include "cmGeneratedFileStream.h" #include "cmSystemTools.h" -#include "cmXMLSafe.h" +#include "cmXMLWriter.h" #include "cmake.h" #include @@ -407,35 +407,32 @@ void cmCTestLaunch::WriteXML() // Use cmGeneratedFileStream to atomically create the report file. cmGeneratedFileStream fxml(logXML.c_str()); - fxml << "\tIsError()? "Error" : "Warning") << "\">\n"; - this->WriteXMLAction(fxml); - this->WriteXMLCommand(fxml); - this->WriteXMLResult(fxml); - this->WriteXMLLabels(fxml); - fxml << "\t\n"; + cmXMLWriter xml(fxml, 2); + xml.StartElement("Failure"); + xml.Attribute("type", this->IsError() ? "Error" : "Warning"); + this->WriteXMLAction(xml); + this->WriteXMLCommand(xml); + this->WriteXMLResult(xml); + this->WriteXMLLabels(xml); + xml.EndElement(); // Failure } //---------------------------------------------------------------------------- -void cmCTestLaunch::WriteXMLAction(std::ostream& fxml) +void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml) { - fxml << "\t\t\n"; - fxml << "\t\t\n"; + xml.Comment("Meta-information about the build action"); + xml.StartElement("Action"); // TargetName if(!this->OptionTargetName.empty()) { - fxml << "\t\t\t" - << cmXMLSafe(this->OptionTargetName) - << "\n"; + xml.Element("TargetName", this->OptionTargetName); } // Language if(!this->OptionLanguage.empty()) { - fxml << "\t\t\t" - << cmXMLSafe(this->OptionLanguage) - << "\n"; + xml.Element("Language", this->OptionLanguage); } // SourceFile @@ -454,17 +451,13 @@ void cmCTestLaunch::WriteXMLAction(std::ostream& fxml) source.c_str()); } - fxml << "\t\t\t" - << cmXMLSafe(source) - << "\n"; + xml.Element("SourceFile", source); } // OutputFile if(!this->OptionOutput.empty()) { - fxml << "\t\t\t" - << cmXMLSafe(this->OptionOutput) - << "\n"; + xml.Element("OutputFile", this->OptionOutput); } // OutputType @@ -494,103 +487,94 @@ void cmCTestLaunch::WriteXMLAction(std::ostream& fxml) } if(outputType) { - fxml << "\t\t\t" - << cmXMLSafe(outputType) - << "\n"; + xml.Element("OutputType", outputType); } - fxml << "\t\t\n"; + xml.EndElement(); // Action } //---------------------------------------------------------------------------- -void cmCTestLaunch::WriteXMLCommand(std::ostream& fxml) +void cmCTestLaunch::WriteXMLCommand(cmXMLWriter& xml) { - fxml << "\n"; - fxml << "\t\t\n"; - fxml << "\t\t\n"; + xml.Comment("Details of command"); + xml.StartElement("Command"); if(!this->CWD.empty()) { - fxml << "\t\t\t" - << cmXMLSafe(this->CWD) - << "\n"; + xml.Element("WorkingDirectory", this->CWD); } for(std::vector::const_iterator ai = this->RealArgs.begin(); ai != this->RealArgs.end(); ++ai) { - fxml << "\t\t\t" - << cmXMLSafe(ai->c_str()) - << "\n"; + xml.Element("Argument", *ai); } - fxml << "\t\t\n"; + xml.EndElement(); // Command } //---------------------------------------------------------------------------- -void cmCTestLaunch::WriteXMLResult(std::ostream& fxml) +void cmCTestLaunch::WriteXMLResult(cmXMLWriter& xml) { - fxml << "\n"; - fxml << "\t\t\n"; - fxml << "\t\t\n"; + xml.Comment("Result of command"); + xml.StartElement("Result"); // StdOut - fxml << "\t\t\t"; - this->DumpFileToXML(fxml, this->LogOut); - fxml << "\n"; + xml.StartElement("StdOut"); + this->DumpFileToXML(xml, this->LogOut); + xml.EndElement(); // StdOut // StdErr - fxml << "\t\t\t"; - this->DumpFileToXML(fxml, this->LogErr); - fxml << "\n"; + xml.StartElement("StdErr"); + this->DumpFileToXML(xml, this->LogErr); + xml.EndElement(); // StdErr // ExitCondition - fxml << "\t\t\t"; + xml.StartElement("ExitCondition"); cmsysProcess* cp = this->Process; switch (cmsysProcess_GetState(cp)) { case cmsysProcess_State_Starting: - fxml << "No process has been executed"; break; + xml.Content("No process has been executed"); break; case cmsysProcess_State_Executing: - fxml << "The process is still executing"; break; + xml.Content("The process is still executing"); break; case cmsysProcess_State_Disowned: - fxml << "Disowned"; break; + xml.Content("Disowned"); break; case cmsysProcess_State_Killed: - fxml << "Killed by parent"; break; + xml.Content("Killed by parent"); break; case cmsysProcess_State_Expired: - fxml << "Killed when timeout expired"; break; + xml.Content("Killed when timeout expired"); break; case cmsysProcess_State_Exited: - fxml << this->ExitCode; break; + xml.Content(this->ExitCode); break; case cmsysProcess_State_Exception: - fxml << "Terminated abnormally: " - << cmXMLSafe(cmsysProcess_GetExceptionString(cp)); break; + xml.Content("Terminated abnormally: "); + xml.Content(cmsysProcess_GetExceptionString(cp)); break; case cmsysProcess_State_Error: - fxml << "Error administrating child process: " - << cmXMLSafe(cmsysProcess_GetErrorString(cp)); break; + xml.Content("Error administrating child process: "); + xml.Content(cmsysProcess_GetErrorString(cp)); break; }; - fxml << "\n"; + xml.EndElement(); // ExitCondition - fxml << "\t\t\n"; + xml.EndElement(); // Result } //---------------------------------------------------------------------------- -void cmCTestLaunch::WriteXMLLabels(std::ostream& fxml) +void cmCTestLaunch::WriteXMLLabels(cmXMLWriter& xml) { this->LoadLabels(); if(!this->Labels.empty()) { - fxml << "\n"; - fxml << "\t\t\n"; - fxml << "\t\t\n"; + xml.Comment("Interested parties"); + xml.StartElement("Labels"); for(std::set::const_iterator li = this->Labels.begin(); li != this->Labels.end(); ++li) { - fxml << "\t\t\t\n"; + xml.Element("Label", *li); } - fxml << "\t\t\n"; + xml.EndElement(); // Labels } } //---------------------------------------------------------------------------- -void cmCTestLaunch::DumpFileToXML(std::ostream& fxml, +void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml, std::string const& fname) { cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary); @@ -605,7 +589,8 @@ void cmCTestLaunch::DumpFileToXML(std::ostream& fxml, continue; } - fxml << sep << cmXMLSafe(line).Quotes(false); + xml.Content(sep); + xml.Content(line); sep = "\n"; } } diff --git a/Source/CTest/cmCTestLaunch.h b/Source/CTest/cmCTestLaunch.h index bc90d28cf..b13e4847b 100644 --- a/Source/CTest/cmCTestLaunch.h +++ b/Source/CTest/cmCTestLaunch.h @@ -15,6 +15,8 @@ #include "cmStandardIncludes.h" #include +class cmXMLWriter; + /** \class cmCTestLaunch * \brief Launcher for make rules to report results for ctest * @@ -92,11 +94,11 @@ private: // Methods to generate the xml fragment. void WriteXML(); - void WriteXMLAction(std::ostream& fxml); - void WriteXMLCommand(std::ostream& fxml); - void WriteXMLResult(std::ostream& fxml); - void WriteXMLLabels(std::ostream& fxml); - void DumpFileToXML(std::ostream& fxml, std::string const& fname); + void WriteXMLAction(cmXMLWriter& xml); + void WriteXMLCommand(cmXMLWriter& xml); + void WriteXMLResult(cmXMLWriter& xml); + void WriteXMLLabels(cmXMLWriter& xml); + void DumpFileToXML(cmXMLWriter& xml, std::string const& fname); // Configuration void LoadConfig();