cmCTestUpdateHandler.cxx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestUpdateHandler.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmGlobalGenerator.h"
  19. #include "cmVersion.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include "cmXMLParser.h"
  22. //#include <cmsys/RegularExpression.hxx>
  23. #include <cmsys/Process.h>
  24. // used for sleep
  25. #ifdef _WIN32
  26. #include "windows.h"
  27. #endif
  28. #include <stdlib.h>
  29. #include <math.h>
  30. #include <float.h>
  31. //----------------------------------------------------------------------
  32. //**********************************************************************
  33. class cmCTestUpdateHandlerSVNXMLParser : public cmXMLParser
  34. {
  35. public:
  36. struct t_CommitLog
  37. {
  38. int m_Revision;
  39. std::string m_Author;
  40. std::string m_Date;
  41. std::string m_Message;
  42. };
  43. cmCTestUpdateHandlerSVNXMLParser(cmCTestUpdateHandler* up)
  44. : cmXMLParser(), m_UpdateHandler(up), m_MinRevision(-1), m_MaxRevision(-1)
  45. {
  46. }
  47. int Parse(const char* str)
  48. {
  49. m_MinRevision = -1;
  50. m_MaxRevision = -1;
  51. int res = this->cmXMLParser::Parse(str);
  52. if ( m_MinRevision == -1 || m_MaxRevision == -1 )
  53. {
  54. return 0;
  55. }
  56. return res;
  57. }
  58. typedef std::vector<t_CommitLog> t_VectorOfCommits;
  59. t_VectorOfCommits* GetCommits() { return &m_Commits; }
  60. int GetMinRevision() { return m_MinRevision; }
  61. int GetMaxRevision() { return m_MaxRevision; }
  62. protected:
  63. void StartElement(const char* name, const char** atts)
  64. {
  65. if ( strcmp(name, "logentry") == 0 )
  66. {
  67. m_CommitLog = t_CommitLog();
  68. const char* rev = this->FindAttribute(atts, "revision");
  69. if ( rev)
  70. {
  71. m_CommitLog.m_Revision = atoi(rev);
  72. if ( m_MinRevision < 0 || m_MinRevision > m_CommitLog.m_Revision )
  73. {
  74. m_MinRevision = m_CommitLog.m_Revision;
  75. }
  76. if ( m_MaxRevision < 0 || m_MaxRevision < m_CommitLog.m_Revision )
  77. {
  78. m_MaxRevision = m_CommitLog.m_Revision;
  79. }
  80. }
  81. }
  82. m_CharacterData.erase(m_CharacterData.begin(), m_CharacterData.end());
  83. }
  84. void EndElement(const char* name)
  85. {
  86. if ( strcmp(name, "logentry") == 0 )
  87. {
  88. cmCTestLog(m_UpdateHandler->GetCTestInstance(), HANDLER_VERBOSE_OUTPUT, "\tRevision: " << m_CommitLog.m_Revision<< std::endl
  89. << "\tAuthor: " << m_CommitLog.m_Author.c_str() << std::endl
  90. << "\tDate: " << m_CommitLog.m_Date.c_str() << std::endl
  91. << "\tMessage: " << m_CommitLog.m_Message.c_str() << std::endl);
  92. m_Commits.push_back(m_CommitLog);
  93. }
  94. else if ( strcmp(name, "author") == 0 )
  95. {
  96. m_CommitLog.m_Author.assign(&(*(m_CharacterData.begin())), m_CharacterData.size());
  97. }
  98. else if ( strcmp(name, "date") == 0 )
  99. {
  100. m_CommitLog.m_Date.assign(&(*(m_CharacterData.begin())), m_CharacterData.size());
  101. }
  102. else if ( strcmp(name, "msg") == 0 )
  103. {
  104. m_CommitLog.m_Message.assign(&(*(m_CharacterData.begin())), m_CharacterData.size());
  105. }
  106. m_CharacterData.erase(m_CharacterData.begin(), m_CharacterData.end());
  107. }
  108. void CharacterDataHandler(const char* data, int length)
  109. {
  110. m_CharacterData.insert(m_CharacterData.end(), data, data+length);
  111. }
  112. const char* FindAttribute( const char** atts, const char* attribute )
  113. {
  114. if ( !atts || !attribute )
  115. {
  116. return 0;
  117. }
  118. const char **atr = atts;
  119. while ( *atr && **atr && **(atr+1) )
  120. {
  121. if ( strcmp(*atr, attribute) == 0 )
  122. {
  123. return *(atr+1);
  124. }
  125. atr+=2;
  126. }
  127. return 0;
  128. }
  129. private:
  130. std::vector<char> m_CharacterData;
  131. cmCTestUpdateHandler* m_UpdateHandler;
  132. t_CommitLog m_CommitLog;
  133. t_VectorOfCommits m_Commits;
  134. int m_MinRevision;
  135. int m_MaxRevision;
  136. };
  137. //**********************************************************************
  138. //----------------------------------------------------------------------
  139. //----------------------------------------------------------------------
  140. cmCTestUpdateHandler::cmCTestUpdateHandler()
  141. {
  142. m_CTest = 0;
  143. }
  144. //----------------------------------------------------------------------
  145. int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
  146. {
  147. if ( type && *type )
  148. {
  149. std::string stype = cmSystemTools::LowerCase(type);
  150. if ( stype.find("cvs") != std::string::npos )
  151. {
  152. return cmCTestUpdateHandler::e_CVS;
  153. }
  154. if ( stype.find("svn") != std::string::npos )
  155. {
  156. return cmCTestUpdateHandler::e_SVN;
  157. }
  158. }
  159. else
  160. {
  161. std::string stype = cmSystemTools::LowerCase(cmd);
  162. if ( stype.find("cvs") != std::string::npos )
  163. {
  164. return cmCTestUpdateHandler::e_CVS;
  165. }
  166. if ( stype.find("svn") != std::string::npos )
  167. {
  168. return cmCTestUpdateHandler::e_SVN;
  169. }
  170. }
  171. return cmCTestUpdateHandler::e_CVS;
  172. }
  173. //----------------------------------------------------------------------
  174. //clearly it would be nice if this were broken up into a few smaller
  175. //functions and commented...
  176. int cmCTestUpdateHandler::ProcessHandler()
  177. {
  178. int count = 0;
  179. int updateType = e_CVS;
  180. std::string::size_type cc, kk;
  181. bool updateProducedError = false;
  182. // Get source dir
  183. const char* sourceDirectory = this->GetOption("SourceDirectory");
  184. if ( !sourceDirectory )
  185. {
  186. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl);
  187. return -1;
  188. }
  189. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Updating the repository: " << sourceDirectory << std::endl);
  190. // Get update command
  191. std::string updateCommand = m_CTest->GetCTestConfiguration("UpdateCommand");
  192. if ( updateCommand.empty() )
  193. {
  194. updateCommand = m_CTest->GetCTestConfiguration("CVSCommand");
  195. if ( updateCommand.empty() )
  196. {
  197. updateCommand = m_CTest->GetCTestConfiguration("SVNCommand");
  198. if ( updateCommand.empty() )
  199. {
  200. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot find CVSCommand, SVNCommand, or UpdateCommand key in the DartConfiguration.tcl" << std::endl);
  201. return -1;
  202. }
  203. else
  204. {
  205. updateType = e_SVN;
  206. }
  207. }
  208. else
  209. {
  210. updateType = e_CVS;
  211. }
  212. }
  213. else
  214. {
  215. updateType = this->DetermineType(updateCommand.c_str(), m_CTest->GetCTestConfiguration("UpdateType").c_str());
  216. }
  217. // And update options
  218. std::string updateOptions = m_CTest->GetCTestConfiguration("UpdateOptions");
  219. if ( updateOptions.empty() )
  220. {
  221. switch (updateType)
  222. {
  223. case cmCTestUpdateHandler::e_CVS:
  224. updateOptions = m_CTest->GetCTestConfiguration("CVSUpdateOptions");
  225. break;
  226. case cmCTestUpdateHandler::e_SVN:
  227. updateOptions = m_CTest->GetCTestConfiguration("SVNUpdateOptions");
  228. break;
  229. }
  230. }
  231. // Get update time
  232. std::string extra_update_opts;
  233. if ( m_CTest->GetTestModel() == cmCTest::NIGHTLY )
  234. {
  235. struct tm* t = m_CTest->GetNightlyTime(m_CTest->GetCTestConfiguration("NightlyStartTime"),
  236. m_CTest->GetTomorrowTag());
  237. char current_time[1024];
  238. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d",
  239. t->tm_year + 1900,
  240. t->tm_mon + 1,
  241. t->tm_mday,
  242. t->tm_hour,
  243. t->tm_min,
  244. t->tm_sec);
  245. std::string today_update_date = current_time;
  246. // TODO: SVN
  247. switch ( updateType )
  248. {
  249. case cmCTestUpdateHandler::e_CVS:
  250. extra_update_opts += "-D \"" + today_update_date +" UTC\"";
  251. break;
  252. case cmCTestUpdateHandler::e_SVN:
  253. extra_update_opts += "-r \"{" + today_update_date +" +0000}\"";
  254. break;
  255. }
  256. }
  257. updateCommand = "\"" + updateCommand + "\"";
  258. // First, check what the current state of repository is
  259. std::string command = "";
  260. switch( updateType )
  261. {
  262. case cmCTestUpdateHandler::e_CVS:
  263. // TODO: CVS - for now just leave empty
  264. break;
  265. case cmCTestUpdateHandler::e_SVN:
  266. command = updateCommand + " info";
  267. break;
  268. }
  269. cmGeneratedFileStream ofs;
  270. if ( !m_CTest->GetShowOnly() )
  271. {
  272. m_CTest->OpenOutputFile("Temporary", "LastUpdate.log", ofs);
  273. }
  274. // CVS variables
  275. // SVN variables
  276. int svn_current_revision = 0;
  277. int svn_latest_revision = 0;
  278. int svn_use_status = 0;
  279. std::string goutput;
  280. int retVal = 0;
  281. bool res = true;
  282. //
  283. // Get initial repository information if that is possible. With subversion, this will check the current revision.
  284. //
  285. if ( !command.empty() )
  286. {
  287. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Get repository information: " << command.c_str() << std::endl);
  288. if ( !m_CTest->GetShowOnly() )
  289. {
  290. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  291. &retVal, sourceDirectory,
  292. m_HandlerVerbose, 0 /*m_TimeOut*/);
  293. if ( ofs )
  294. {
  295. ofs << "--- Update information ---" << std::endl;
  296. ofs << goutput << std::endl;
  297. }
  298. switch ( updateType )
  299. {
  300. case cmCTestUpdateHandler::e_CVS:
  301. // TODO: CVS - for now just leave empty
  302. break;
  303. case cmCTestUpdateHandler::e_SVN:
  304. {
  305. cmsys::RegularExpression current_revision_regex("Revision: ([0-9]+)");
  306. if ( current_revision_regex.find(goutput.c_str()) )
  307. {
  308. std::string currentRevisionString = current_revision_regex.match(1);
  309. svn_current_revision = atoi(currentRevisionString.c_str());
  310. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Old revision of repository is: " << svn_current_revision << std::endl);
  311. }
  312. }
  313. break;
  314. }
  315. }
  316. else
  317. {
  318. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Update with command: " << command << std::endl);
  319. }
  320. }
  321. //
  322. // Now update repository and remember what files were updated
  323. //
  324. cmGeneratedFileStream os;
  325. if ( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), "Update.xml", os, true) )
  326. {
  327. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot open log file" << std::endl);
  328. }
  329. std::string start_time = m_CTest->CurrentTime();
  330. double elapsed_time_start = cmSystemTools::GetTime();
  331. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Update repository: " << command.c_str() << std::endl);
  332. if ( !m_CTest->GetShowOnly() )
  333. {
  334. command = "";
  335. switch( updateType )
  336. {
  337. case cmCTestUpdateHandler::e_CVS:
  338. command = updateCommand + " -z3 update " + updateOptions +
  339. " " + extra_update_opts;
  340. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  341. &retVal, sourceDirectory,
  342. m_HandlerVerbose, 0 /*m_TimeOut*/);
  343. break;
  344. case cmCTestUpdateHandler::e_SVN:
  345. {
  346. std::string partialOutput;
  347. command = updateCommand + " update " + updateOptions +
  348. " " + extra_update_opts;
  349. bool res1 = cmSystemTools::RunSingleCommand(command.c_str(), &partialOutput,
  350. &retVal, sourceDirectory,
  351. m_HandlerVerbose, 0 /*m_TimeOut*/);
  352. command = updateCommand + " status";
  353. res = cmSystemTools::RunSingleCommand(command.c_str(), &partialOutput,
  354. &retVal, sourceDirectory,
  355. m_HandlerVerbose, 0 /*m_TimeOut*/);
  356. goutput += partialOutput;
  357. res = res && res1;
  358. }
  359. }
  360. if ( ofs )
  361. {
  362. ofs << "--- Update repository ---" << std::endl;
  363. ofs << goutput << std::endl;;
  364. }
  365. }
  366. if ( !res || retVal )
  367. {
  368. updateProducedError = true;
  369. }
  370. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  371. << "<Update mode=\"Client\" Generator=\"ctest-"
  372. << cmVersion::GetCMakeVersion() << "\">\n"
  373. << "\t<Site>" << m_CTest->GetCTestConfiguration("Site") << "</Site>\n"
  374. << "\t<BuildName>" << m_CTest->GetCTestConfiguration("BuildName")
  375. << "</BuildName>\n"
  376. << "\t<BuildStamp>" << m_CTest->GetCurrentTag() << "-"
  377. << m_CTest->GetTestModelString() << "</BuildStamp>" << std::endl;
  378. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  379. << "\t<UpdateCommand>" << m_CTest->MakeXMLSafe(command)
  380. << "</UpdateCommand>\n";
  381. // Even though it failed, we may have some useful information. Try to continue...
  382. std::vector<cmStdString> lines;
  383. cmSystemTools::Split(goutput.c_str(), lines);
  384. // CVS style regular expressions
  385. cmsys::RegularExpression cvs_date_author_regex("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  386. cmsys::RegularExpression cvs_revision_regex("^revision +([^ ]*) *$");
  387. cmsys::RegularExpression cvs_end_of_file_regex("^=============================================================================$");
  388. cmsys::RegularExpression cvs_end_of_comment_regex("^----------------------------$");
  389. // Subversion style regular expressions
  390. cmsys::RegularExpression svn_status_line_regex("^ *([0-9]+) *([0-9]+) *([^ ]+) *([^ ][^\t\r\n]*)[ \t\r\n]*$");
  391. cmsys::RegularExpression svn_latest_revision_regex("(Updated to|At) revision ([0-9]+)\\.");
  392. cmsys::RegularExpression file_update_line("([A-Z]) *(.*)");
  393. std::string current_path = "<no-path>";
  394. bool first_file = true;
  395. cmCTestUpdateHandler::AuthorsToUpdatesMap authors_files_map;
  396. int num_updated = 0;
  397. int num_modified = 0;
  398. int num_conflicting = 0;
  399. // In subversion, get the latest revision
  400. if ( updateType == cmCTestUpdateHandler::e_SVN )
  401. {
  402. for ( cc= 0 ; cc < lines.size(); cc ++ )
  403. {
  404. const char* line = lines[cc].c_str();
  405. if ( svn_latest_revision_regex.find(line) )
  406. {
  407. svn_latest_revision = atoi(svn_latest_revision_regex.match(2).c_str());
  408. }
  409. }
  410. }
  411. if ( updateType == cmCTestUpdateHandler::e_SVN )
  412. {
  413. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Current revision of repository is: " << svn_latest_revision << std::endl);
  414. }
  415. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Gathering version information (each . represents one updated file):" << std::endl);
  416. int file_count = 0;
  417. for ( cc= 0 ; cc < lines.size(); cc ++ )
  418. {
  419. const char* line = lines[cc].c_str();
  420. if ( file_update_line.find(line) )
  421. {
  422. if ( file_count == 0 )
  423. {
  424. cmCTestLog(m_CTest, HANDLER_OUTPUT, " " << std::flush);
  425. }
  426. cmCTestLog(m_CTest, HANDLER_OUTPUT, "." << std::flush);
  427. std::string upChar = file_update_line.match(1);
  428. std::string upFile = file_update_line.match(2);
  429. char mod = upChar[0];
  430. bool modifiedOrConflict = false;
  431. if ( mod != 'M' && mod != 'C' && mod != 'G' )
  432. {
  433. count ++;
  434. modifiedOrConflict = true;
  435. }
  436. const char* file = upFile.c_str();
  437. cmCTestLog(m_CTest, DEBUG, "Line" << cc << ": " << mod << " - " << file << std::endl);
  438. std::string output;
  439. if ( modifiedOrConflict )
  440. {
  441. std::string logcommand;
  442. switch ( updateType )
  443. {
  444. case cmCTestUpdateHandler::e_CVS:
  445. logcommand = updateCommand + " -z3 log -N \"" + file + "\"";
  446. break;
  447. case cmCTestUpdateHandler::e_SVN:
  448. if ( svn_latest_revision > 0 && svn_latest_revision > svn_current_revision )
  449. {
  450. cmOStringStream logCommandStream;
  451. logCommandStream << updateCommand << " log -r " << svn_current_revision << ":" << svn_latest_revision
  452. << " --xml \"" << file << "\"";
  453. logcommand = logCommandStream.str();
  454. }
  455. else
  456. {
  457. logcommand = updateCommand + " status --verbose \"" + file + "\"";
  458. svn_use_status = 1;
  459. }
  460. break;
  461. }
  462. cmCTestLog(m_CTest, DEBUG, "Do log: " << logcommand << std::endl);
  463. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Get file update information: " << logcommand.c_str() << std::endl);
  464. res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output,
  465. &retVal, sourceDirectory,
  466. m_HandlerVerbose, 0 /*m_TimeOut*/);
  467. if ( ofs )
  468. {
  469. ofs << output << std::endl;
  470. }
  471. }
  472. if ( res && retVal == 0)
  473. {
  474. cmCTestLog(m_CTest, DEBUG, output << std::endl);
  475. std::string::size_type sline = 0;
  476. std::string srevision1 = "Unknown";
  477. std::string sdate1 = "Unknown";
  478. std::string sauthor1 = "Unknown";
  479. std::string semail1 = "Unknown";
  480. std::string comment1 = "";
  481. std::string srevision2 = "Unknown";
  482. std::string sdate2 = "Unknown";
  483. std::string sauthor2 = "Unknown";
  484. std::string comment2 = "";
  485. std::string semail2 = "Unknown";
  486. if ( updateType == cmCTestUpdateHandler::e_CVS )
  487. {
  488. bool have_first = false;
  489. bool have_second = false;
  490. std::vector<cmStdString> ulines;
  491. cmSystemTools::Split(output.c_str(), ulines);
  492. for ( kk = 0; kk < ulines.size(); kk ++ )
  493. {
  494. const char* clp = ulines[kk].c_str();
  495. if ( !have_second && !sline && cvs_revision_regex.find(clp) )
  496. {
  497. if ( !have_first )
  498. {
  499. srevision1 = cvs_revision_regex.match(1);
  500. }
  501. else
  502. {
  503. srevision2 = cvs_revision_regex.match(1);
  504. }
  505. }
  506. else if ( !have_second && !sline && cvs_date_author_regex.find(clp) )
  507. {
  508. sline = kk + 1;
  509. if ( !have_first )
  510. {
  511. sdate1 = cvs_date_author_regex.match(1);
  512. sauthor1 = cvs_date_author_regex.match(2);
  513. }
  514. else
  515. {
  516. sdate2 = cvs_date_author_regex.match(1);
  517. sauthor2 = cvs_date_author_regex.match(2);
  518. }
  519. }
  520. else if ( sline && cvs_end_of_comment_regex.find(clp) || cvs_end_of_file_regex.find(clp))
  521. {
  522. if ( !have_first )
  523. {
  524. have_first = true;
  525. }
  526. else if ( !have_second )
  527. {
  528. have_second = true;
  529. }
  530. sline = 0;
  531. }
  532. else if ( sline )
  533. {
  534. if ( !have_first )
  535. {
  536. comment1 += clp;
  537. comment1 += "\n";
  538. }
  539. else
  540. {
  541. comment2 += clp;
  542. comment2 += "\n";
  543. }
  544. }
  545. }
  546. }
  547. else if ( updateType == cmCTestUpdateHandler::e_SVN )
  548. {
  549. if ( svn_use_status )
  550. {
  551. cmOStringStream str;
  552. str << svn_current_revision;
  553. srevision1 = str.str();
  554. if (!svn_status_line_regex.find(output))
  555. {
  556. cmCTestLog(m_CTest, ERROR_MESSAGE, "Bad output from SVN status command: " << output << std::endl);
  557. }
  558. else if ( svn_status_line_regex.match(4) != file )
  559. {
  560. cmCTestLog(m_CTest, ERROR_MESSAGE, "Bad output from SVN status command. The file name returned: \"" << svn_status_line_regex.match(4) << "\" was different than the file specified: \"" << file << "\"" << std::endl);
  561. }
  562. else
  563. {
  564. srevision1 = svn_status_line_regex.match(2);
  565. int latest_revision = atoi(svn_status_line_regex.match(2).c_str());
  566. if ( svn_current_revision < latest_revision )
  567. {
  568. srevision2 = str.str();
  569. }
  570. sauthor1 = svn_status_line_regex.match(3);
  571. }
  572. }
  573. else
  574. {
  575. cmCTestUpdateHandlerSVNXMLParser parser(this);
  576. if ( parser.Parse(output.c_str()) )
  577. {
  578. int minrev = parser.GetMinRevision();
  579. int maxrev = parser.GetMaxRevision();
  580. cmCTestUpdateHandlerSVNXMLParser::t_VectorOfCommits::iterator it;
  581. for ( it = parser.GetCommits()->begin();
  582. it != parser.GetCommits()->end();
  583. ++ it )
  584. {
  585. if ( it->m_Revision == maxrev )
  586. {
  587. cmOStringStream mRevStream;
  588. mRevStream << maxrev;
  589. srevision1 = mRevStream.str();
  590. sauthor1 = it->m_Author;
  591. comment1 = it->m_Message;
  592. sdate1 = it->m_Date;
  593. }
  594. else if ( it->m_Revision == minrev )
  595. {
  596. cmOStringStream mRevStream;
  597. mRevStream << minrev;
  598. srevision2 = mRevStream.str();
  599. sauthor2 = it->m_Author;
  600. comment2 = it->m_Message;
  601. sdate2 = it->m_Date;
  602. }
  603. }
  604. }
  605. }
  606. }
  607. if ( mod == 'M' )
  608. {
  609. comment1 = "Locally modified file\n";
  610. sauthor1 = "Local User";
  611. }
  612. if ( mod == 'C' )
  613. {
  614. comment1 = "Conflict while updating\n";
  615. sauthor1 = "Local User";
  616. }
  617. std::string path = cmSystemTools::GetFilenamePath(file);
  618. std::string fname = cmSystemTools::GetFilenameName(file);
  619. if ( path != current_path )
  620. {
  621. if ( !first_file )
  622. {
  623. os << "\t</Directory>" << std::endl;
  624. }
  625. else
  626. {
  627. first_file = false;
  628. }
  629. os << "\t<Directory>\n"
  630. << "\t\t<Name>" << path << "</Name>" << std::endl;
  631. }
  632. if ( mod == 'C' )
  633. {
  634. num_conflicting ++;
  635. os << "\t<Conflicting>" << std::endl;
  636. }
  637. else if ( mod == 'G' )
  638. {
  639. num_conflicting ++;
  640. os << "\t<Conflicting>" << std::endl;
  641. }
  642. else if ( mod == 'M' )
  643. {
  644. num_modified ++;
  645. os << "\t<Modified>" << std::endl;
  646. }
  647. else
  648. {
  649. num_updated ++;
  650. os << "\t<Updated>" << std::endl;
  651. }
  652. if ( srevision2 == "Unknown" )
  653. {
  654. srevision2 = srevision1;
  655. }
  656. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "File: " << path.c_str() << " / " << fname.c_str() << " was updated by "
  657. << sauthor1.c_str() << " to revision: " << srevision1.c_str()
  658. << " from revision: " << srevision2.c_str() << std::endl);
  659. os << "\t\t<File Directory=\"" << cmCTest::MakeXMLSafe(path) << "\">" << cmCTest::MakeXMLSafe(fname)
  660. << "</File>\n"
  661. << "\t\t<Directory>" << cmCTest::MakeXMLSafe(path) << "</Directory>\n"
  662. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(file) << "</FullName>\n"
  663. << "\t\t<CheckinDate>" << cmCTest::MakeXMLSafe(sdate1) << "</CheckinDate>\n"
  664. << "\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  665. << "\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  666. << "\t\t<Log>" << cmCTest::MakeXMLSafe(comment1) << "</Log>\n"
  667. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  668. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  669. << std::endl;
  670. if ( srevision2 != srevision1 )
  671. {
  672. os
  673. << "\t\t<Revisions>\n"
  674. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  675. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  676. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  677. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate1) << "</Date>\n"
  678. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment1) << "</Comment>\n"
  679. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  680. << "\t\t</Revisions>\n"
  681. << "\t\t<Revisions>\n"
  682. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  683. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  684. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor2) << "</Author>\n"
  685. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate2) << "</Date>\n"
  686. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment2) << "</Comment>\n"
  687. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail2) << "</Email>\n"
  688. << "\t\t</Revisions>" << std::endl;
  689. }
  690. if ( mod == 'C' )
  691. {
  692. os << "\t</Conflicting>" << std::endl;
  693. }
  694. else if ( mod == 'G' )
  695. {
  696. os << "\t</Conflicting>" << std::endl;
  697. }
  698. else if ( mod == 'M' )
  699. {
  700. os << "\t</Modified>" << std::endl;
  701. }
  702. else
  703. {
  704. os << "\t</Updated>" << std::endl;
  705. }
  706. cmCTestUpdateHandler::UpdateFiles *u = &authors_files_map[sauthor1];
  707. cmCTestUpdateHandler::StringPair p;
  708. p.first = path;
  709. p.second = fname;
  710. u->push_back(p);
  711. current_path = path;
  712. }
  713. file_count ++;
  714. }
  715. }
  716. if ( file_count )
  717. {
  718. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl);
  719. }
  720. if ( num_updated )
  721. {
  722. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_updated << " updated files" << std::endl);
  723. }
  724. if ( num_modified )
  725. {
  726. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_modified << " locally modified files"
  727. << std::endl);
  728. }
  729. if ( num_conflicting )
  730. {
  731. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_conflicting << " conflicting files"
  732. << std::endl);
  733. }
  734. if ( num_modified == 0 && num_conflicting == 0 && num_updated == 0 )
  735. {
  736. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Project is up-to-date" << std::endl);
  737. }
  738. if ( !first_file )
  739. {
  740. os << "\t</Directory>" << std::endl;
  741. }
  742. cmCTestUpdateHandler::AuthorsToUpdatesMap::iterator it;
  743. for ( it = authors_files_map.begin();
  744. it != authors_files_map.end();
  745. it ++ )
  746. {
  747. os << "\t<Author>\n"
  748. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  749. cmCTestUpdateHandler::UpdateFiles *u = &(it->second);
  750. for ( cc = 0; cc < u->size(); cc ++ )
  751. {
  752. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  753. << (*u)[cc].second << "</File>" << std::endl;
  754. }
  755. os << "\t</Author>" << std::endl;
  756. }
  757. cmCTestLog(m_CTest, DEBUG, "End" << std::endl);
  758. std::string end_time = m_CTest->CurrentTime();
  759. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  760. << "<ElapsedMinutes>" <<
  761. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  762. << "</ElapsedMinutes>\n"
  763. << "\t<UpdateReturnStatus>";
  764. if ( num_modified > 0 || num_conflicting > 0 )
  765. {
  766. os << "Update error: There are modified or conflicting files in the repository";
  767. cmCTestLog(m_CTest, ERROR_MESSAGE, " There are modified or conflicting files in the repository" << std::endl);
  768. }
  769. if ( updateProducedError )
  770. {
  771. os << "Update error: ";
  772. os << m_CTest->MakeXMLSafe(goutput);
  773. cmCTestLog(m_CTest, ERROR_MESSAGE, " Update with command: " << command << " failed" << std::endl);
  774. }
  775. os << "</UpdateReturnStatus>" << std::endl;
  776. os << "</Update>" << std::endl;
  777. if ( ofs )
  778. {
  779. ofs.close();
  780. }
  781. if (! res || retVal )
  782. {
  783. cmCTestLog(m_CTest, ERROR_MESSAGE, "Error(s) when updating the project" << std::endl);
  784. cmCTestLog(m_CTest, ERROR_MESSAGE, "Output: " << goutput << std::endl);
  785. return -1;
  786. }
  787. return count;
  788. }