e61af5f1c56035da90cb422e940f114ab7f50e02
[reactos.git] / reactos / tools / rbuild / backend / versionreport / versionreport.cpp
1 /*
2 * Copyright (C) 2007 Marc Piulachs (marc.piulachs [at] codexchange [dot] net)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #ifdef _MSC_VER
19 #pragma warning ( disable : 4786 )
20 #endif//_MSC_VER
21
22 #include <iostream>
23 #include <fstream>
24 #include <string>
25 #include <vector>
26 #include <map>
27
28 #include <stdio.h>
29
30 #include "versionreport.h"
31 #include "../mingw/mingw.h"
32
33 using std::string;
34 using std::vector;
35 using std::map;
36 using std::ifstream;
37
38 #ifdef OUT
39 #undef OUT
40 #endif//OUT
41
42
43 static class VReportFactory : public Backend::Factory
44 {
45 public:
46
47 VReportFactory() : Factory("VReport", "Version Report") {}
48 Backend *operator() (Project &project,
49 Configuration& configuration)
50 {
51 return new VReportBackend(project, configuration);
52 }
53
54 } factory;
55
56
57 VReportBackend::VReportBackend(Project &project,
58 Configuration& configuration) : Backend(project, configuration)
59 {
60
61 }
62
63 void VReportBackend::Process()
64 {
65 string filename_depmap ( "versionreport.xml" );
66 printf ( "Creating version report: %s\n", filename_depmap.c_str() );
67
68 m_VReportFile = fopen ( filename_depmap.c_str(), "wb" );
69
70 if ( !m_VReportFile )
71 {
72 printf ( "Could not create file '%s'.\n", filename_depmap.c_str() );
73 return;
74 }
75
76 GenerateReport ( m_VReportFile );
77
78 fclose ( m_VReportFile );
79 printf ( "Done.\n" );
80 }
81
82 void
83 VReportBackend::CleanFiles ( void )
84 {
85 remove ( "versionreport.xml" );
86 }
87
88 void
89 VReportBackend::GenerateReport ( FILE* OUT )
90 {
91 fprintf ( m_VReportFile, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\r\n" );
92 fprintf ( m_VReportFile, "<?xml-stylesheet type=\"text/xsl\" href=\"vreport.xsl\"?>\r\n" );
93 fprintf ( m_VReportFile, "<components>\r\n" );
94
95 for( std::map<std::string, Module*>::const_iterator p = ProjectNode.modules.begin(); p != ProjectNode.modules.end(); ++ p )
96 {
97 Module& module = *p->second;
98 if ((module.type != Iso) &&
99 (module.type != LiveIso) &&
100 (module.type != IsoRegTest) &&
101 (module.type != LiveIsoRegTest))
102 {
103 Module& module = *p->second;
104
105 if (module.metadata)
106 {
107 if (module.metadata->version.length() > 0)
108 {
109 fprintf ( m_VReportFile, "\t<component>\r\n" );
110 fprintf ( m_VReportFile, "\t\t<name>%s</name>\r\n", module.name.c_str () );
111 fprintf ( m_VReportFile, "\t\t<base>%s</base>\r\n", module.output->relative_path.c_str () );
112 fprintf ( m_VReportFile, "\t\t<version>%s</version>\r\n", module.metadata->version.c_str () );
113 fprintf ( m_VReportFile, "\t\t<date>%s</date>\r\n", module.metadata->date.c_str () );
114 fprintf ( m_VReportFile, "\t\t<owner>%s</owner>\r\n", module.metadata->owner.c_str () );
115 fprintf ( m_VReportFile, "\t</component>\r\n" );
116 }
117 }
118 }
119 }
120
121 fprintf ( m_VReportFile, "</components>" );
122 }
123
124
125 VReportConfiguration::VReportConfiguration ( const std::string &name )
126 {
127 /* nothing to do here */
128 }