1 // =================================
 2 // Copyright (c) 2020 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 #include <cpp2cm/cpp2cm/System.hpp>
 7 #include <cpp2cm/cpp2cm/Project.hpp>
 8 #include <sngxml/dom/Document.hpp>
 9 #include <sngxml/dom/Element.hpp>
10 #include <sngxml/dom/Parser.hpp>
11 #include <sngxml/xpath/XPathEvaluate.hpp>
12 #include <soulng/util/Path.hpp>
13 #include <soulng/util/Unicode.hpp>
14 
15 namespace cpp2cm {
16 
17 using namespace soulng::util;
18 using namespace soulng::unicode;
19 
20 void ProcessSystemXml(const std::string& systemXmlFilePathbool verbose)
21 {
22     std::string systemRootDir = Path::GetDirectoryName(systemXmlFilePath);
23     std::unique_ptr<sngxml::dom::Document> systemXmlDoc = sngxml::dom::ReadDocument(systemXmlFilePath);
24     std::unique_ptr<sngxml::xpath::XPathObject> result = sngxml::xpath::Evaluate(U"/cpp2cm/projects/project"systemXmlDoc.get());
25     if (result)
26     {
27         if (result->Type() == sngxml::xpath::XPathObjectType::nodeSet)
28         {
29             sngxml::xpath::XPathNodeSet* nodeSet = static_cast<sngxml::xpath::XPathNodeSet*>(result.get());
30             int n = nodeSet->Length();
31             for (int i = 0; i < n; ++i)
32             {
33                 sngxml::dom::Node* node = (*nodeSet)[i];
34                 if (node->GetNodeType() == sngxml::dom::NodeType::elementNode)
35                 {
36                     sngxml::dom::Element* element = static_cast<sngxml::dom::Element*>(node);
37                     std::u32string fileAttr = element->GetAttribute(U"file");
38                     if (!fileAttr.empty())
39                     {
40                         std::string projectXmlFilePath = GetFullPath(Path::Combine(systemRootDirToUtf8(fileAttr)));
41                         Project project(systemXmlFilePathprojectXmlFilePathfalse);
42                         project.SetSystem();
43                         project.Process(verboseProcessType::stage);
44                     }
45                 }
46             }
47         }
48     }
49 }
50 
51 } // namespace cpp2cm