cmCTest: Port GenerateNotesFile to cmXMLWriter

This commit is contained in:
Daniel Pfeifer 2015-05-24 00:08:35 +02:00 committed by Brad King
parent 9c0bb7d807
commit a53bd63e0c
2 changed files with 27 additions and 25 deletions

View File

@ -1719,54 +1719,56 @@ void cmCTest::EndXML(cmXMLWriter& xml)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int cmCTest::GenerateCTestNotesOutput(std::ostream& os, int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml,
const cmCTest::VectorOfStrings& files) const cmCTest::VectorOfStrings& files)
{ {
std::string buildname = cmCTest::SafeBuildIdField( std::string buildname = cmCTest::SafeBuildIdField(
this->GetCTestConfiguration("BuildName")); this->GetCTestConfiguration("BuildName"));
cmCTest::VectorOfStrings::const_iterator it; cmCTest::VectorOfStrings::const_iterator it;
os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" xml.StartDocument();
<< "<?xml-stylesheet type=\"text/xsl\" " xml.ProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" "
"href=\"Dart/Source/Server/XSL/Build.xsl " "href=\"Dart/Source/Server/XSL/Build.xsl "
"<file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n" "<file:///Dart/Source/Server/XSL/Build.xsl> \"");
<< "<Site BuildName=\"" << buildname xml.StartElement("Site");
<< "\" BuildStamp=\"" xml.Attribute("BuildName", buildname);
<< this->CurrentTag << "-" << this->GetTestModelString() << "\" Name=\"" xml.Attribute("BuildStamp", this->CurrentTag+"-"+this->GetTestModelString());
<< this->GetCTestConfiguration("Site") << "\" Generator=\"ctest" xml.Attribute("Name", this->GetCTestConfiguration("Site"));
<< cmVersion::GetCMakeVersion() xml.Attribute("Generator",std::string("ctest")+cmVersion::GetCMakeVersion());
<< "\">\n"; this->AddSiteProperties(xml);
this->AddSiteProperties(os); xml.StartElement("Notes");
os << "<Notes>" << std::endl;
for ( it = files.begin(); it != files.end(); it ++ ) for ( it = files.begin(); it != files.end(); it ++ )
{ {
cmCTestLog(this, OUTPUT, "\tAdd file: " << *it << std::endl); cmCTestLog(this, OUTPUT, "\tAdd file: " << *it << std::endl);
std::string note_time = this->CurrentTime(); std::string note_time = this->CurrentTime();
os << "<Note Name=\"" << cmXMLSafe(*it) << "\">\n" xml.StartElement("Note");
<< "<Time>" << cmSystemTools::GetTime() << "</Time>\n" xml.Attribute("Name", *it);
<< "<DateTime>" << note_time << "</DateTime>\n" xml.Element("Time", cmSystemTools::GetTime());
<< "<Text>" << std::endl; xml.Element("DateTime", note_time);
xml.StartElement("Text");
cmsys::ifstream ifs(it->c_str()); cmsys::ifstream ifs(it->c_str());
if ( ifs ) if ( ifs )
{ {
std::string line; std::string line;
while ( cmSystemTools::GetLineFromStream(ifs, line) ) while ( cmSystemTools::GetLineFromStream(ifs, line) )
{ {
os << cmXMLSafe(line) << std::endl; xml.Content(line);
xml.Content("\n");
} }
ifs.close(); ifs.close();
} }
else else
{ {
os << "Problem reading file: " << *it << std::endl; xml.Content("Problem reading file: " + *it + "\n");
cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: " << *it cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: " << *it
<< " while creating notes" << std::endl); << " while creating notes" << std::endl);
} }
os << "</Text>\n" xml.EndElement(); // Text
<< "</Note>" << std::endl; xml.EndElement(); // Note
} }
os << "</Notes>\n" xml.EndElement(); // Notes
<< "</Site>" << std::endl; xml.EndElement(); // Site
xml.EndDocument();
return 1; return 1;
} }
@ -1779,8 +1781,8 @@ int cmCTest::GenerateNotesFile(const VectorOfStrings &files)
cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file" << std::endl); cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file" << std::endl);
return 1; return 1;
} }
cmXMLWriter xml(ofs);
this->GenerateCTestNotesOutput(ofs, files); this->GenerateCTestNotesOutput(xml, files);
return 0; return 0;
} }

View File

@ -557,7 +557,7 @@ private:
bool UpdateCTestConfiguration(); bool UpdateCTestConfiguration();
//! Create note from files. //! Create note from files.
int GenerateCTestNotesOutput(std::ostream& os, int GenerateCTestNotesOutput(cmXMLWriter& xml,
const VectorOfStrings& files); const VectorOfStrings& files);
//! Check if the argument is the one specified //! Check if the argument is the one specified