cmake/Source/CTest/cmCTestUploadHandler.cxx

74 lines
2.2 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2011-06-19 15:41:06 +03:00
#include "cmCTestUploadHandler.h"
2020-02-01 23:06:01 +01:00
#include <ostream>
#include <string>
2019-11-11 23:01:05 +01:00
#include "cmCTest.h"
2011-06-19 15:41:06 +03:00
#include "cmGeneratedFileStream.h"
#include "cmVersion.h"
2015-08-17 11:37:30 +02:00
#include "cmXMLWriter.h"
2011-06-19 15:41:06 +03:00
cmCTestUploadHandler::cmCTestUploadHandler()
{
this->Initialize();
}
void cmCTestUploadHandler::Initialize()
{
this->Superclass::Initialize();
this->Files.clear();
}
2019-11-11 23:01:05 +01:00
void cmCTestUploadHandler::SetFiles(std::set<std::string> const& files)
2011-06-19 15:41:06 +03:00
{
this->Files = files;
}
int cmCTestUploadHandler::ProcessHandler()
{
cmGeneratedFileStream ofs;
2016-07-09 11:21:54 +02:00
if (!this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(), "Upload.xml",
ofs)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot open Upload.xml file" << std::endl);
2011-06-19 15:41:06 +03:00
return -1;
2016-07-09 11:21:54 +02:00
}
std::string buildname =
cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName"));
2015-08-17 11:37:30 +02:00
cmXMLWriter xml(ofs);
xml.StartDocument();
2016-07-09 11:21:54 +02:00
xml.ProcessingInstruction("xml-stylesheet",
"type=\"text/xsl\" "
"href=\"Dart/Source/Server/XSL/Build.xsl "
"<file:///Dart/Source/Server/XSL/Build.xsl> \"");
2015-08-17 11:37:30 +02:00
xml.StartElement("Site");
xml.Attribute("BuildName", buildname);
2018-08-09 18:06:22 +02:00
xml.Attribute("BuildStamp",
this->CTest->GetCurrentTag() + "-" +
2016-07-09 11:21:54 +02:00
this->CTest->GetTestModelString());
2015-08-17 11:37:30 +02:00
xml.Attribute("Name", this->CTest->GetCTestConfiguration("Site"));
xml.Attribute("Generator",
2019-11-11 23:01:05 +01:00
std::string("ctest-") + cmVersion::GetCMakeVersion());
2015-08-17 11:37:30 +02:00
this->CTest->AddSiteProperties(xml);
xml.StartElement("Upload");
2011-06-19 15:41:06 +03:00
2018-01-26 17:06:56 +01:00
for (std::string const& file : this->Files) {
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, OUTPUT,
2018-01-26 17:06:56 +01:00
"\tUpload file: " << file << std::endl, this->Quiet);
2015-08-17 11:37:30 +02:00
xml.StartElement("File");
2018-01-26 17:06:56 +01:00
xml.Attribute("filename", file);
2015-08-17 11:37:30 +02:00
xml.StartElement("Content");
xml.Attribute("encoding", "base64");
2018-01-26 17:06:56 +01:00
xml.Content(this->CTest->Base64EncodeFile(file));
2015-08-17 11:37:30 +02:00
xml.EndElement(); // Content
xml.EndElement(); // File
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
xml.EndElement(); // Upload
xml.EndElement(); // Site
xml.EndDocument();
2011-06-19 15:41:06 +03:00
return 0;
}