NETProjectGen.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <Atomic/Core/Object.h>
  24. #include <Atomic/Resource/XMLFile.h>
  25. #include <Atomic/Resource/JSONFile.h>
  26. using namespace Atomic;
  27. namespace ToolCore
  28. {
  29. class NETProjectGen;
  30. class NETProjectBase : public Object
  31. {
  32. ATOMIC_OBJECT(NETProjectBase, Object)
  33. public:
  34. NETProjectBase(Context* context, NETProjectGen* projectGen);
  35. virtual ~NETProjectBase();
  36. void ReplacePathStrings(String& path);
  37. void CopyXMLElementRecursive(XMLElement source, XMLElement dest);
  38. protected:
  39. SharedPtr<XMLFile> xmlFile_;
  40. WeakPtr<NETProjectGen> projectGen_;
  41. };
  42. class NETCSProject : public NETProjectBase
  43. {
  44. ATOMIC_OBJECT(NETCSProject, NETProjectBase)
  45. public:
  46. NETCSProject(Context* context, NETProjectGen* projectGen);
  47. virtual ~NETCSProject();
  48. bool Load(const JSONValue& root);
  49. const String& GetName() { return name_; }
  50. const String& GetProjectGUID() { return projectGuid_; }
  51. const Vector<String>& GetReferences() const { return references_; }
  52. const Vector<String>& GetPackages() const { return packages_; }
  53. bool Generate();
  54. private:
  55. bool CreateProjectFolder(const String& path);
  56. void CreateCompileItemGroup(XMLElement &projectRoot);
  57. void CreateReferencesItemGroup(XMLElement &projectRoot);
  58. void CreateProjectReferencesItemGroup(XMLElement & projectRoot);
  59. void CreatePackagesItemGroup(XMLElement &projectRoot);
  60. void CreateMainPropertyGroup(XMLElement &projectRoot);
  61. void CreateDebugPropertyGroup(XMLElement &projectRoot);
  62. void CreateReleasePropertyGroup(XMLElement &projectRoot);
  63. void CreateAssemblyInfo();
  64. void GetAssemblySearchPaths(String& paths);
  65. String name_;
  66. String projectGuid_;
  67. String outputType_;
  68. String rootNamespace_;
  69. String assemblyName_;
  70. String assemblyOutputPath_;
  71. String assemblySearchPaths_;
  72. // project paths
  73. String projectPath_;
  74. XMLElement xmlRoot_;
  75. Vector<String> references_;
  76. Vector<String> packages_;
  77. Vector<String> sourceFolders_;
  78. };
  79. class NETSolution : public NETProjectBase
  80. {
  81. ATOMIC_OBJECT(NETSolution, NETProjectBase)
  82. public:
  83. NETSolution(Context* context, NETProjectGen* projectGen, bool rewrite = false);
  84. virtual ~NETSolution();
  85. bool Load(const JSONValue& root);
  86. bool Generate();
  87. const String& GetOutputPath() { return outputPath_; }
  88. String GetOutputFilename() { return outputPath_ + name_ + ".sln"; }
  89. Vector<String>& GetPackages() { return packages_; }
  90. // Registers a NuGet package, returns true if the package hasn't been previously registered
  91. bool RegisterPackage(const String& package);
  92. /// If true, the sln file will rewritten if it exists, default is false
  93. void SetRewriteSolution(bool rewrite) { rewriteSolution_ = rewrite; }
  94. private:
  95. void GenerateSolution(const String& slnPath);
  96. String name_;
  97. String outputPath_;
  98. String solutionGUID_;
  99. Vector<String> packages_;
  100. bool rewriteSolution_;
  101. };
  102. class NETProjectGen : public Object
  103. {
  104. ATOMIC_OBJECT(NETProjectGen, Object)
  105. public:
  106. NETProjectGen(Context* context);
  107. virtual ~NETProjectGen();
  108. const String& GetScriptPlatform() { return scriptPlatform_; }
  109. NETSolution* GetSolution() { return solution_; }
  110. const Vector<SharedPtr<NETCSProject>>& GetCSProjects() { return projects_; }
  111. Project* GetAtomicProject() const { return atomicProject_; }
  112. NETCSProject* GetCSProjectByName(const String& name);
  113. bool GetCSProjectDependencies(NETCSProject * source, PODVector<NETCSProject*>& depends) const;
  114. void SetScriptPlatform(const String& platform) { scriptPlatform_ = platform; }
  115. bool Generate();
  116. /// Returns true if the generated solution requires NuGet
  117. bool GetRequiresNuGet();
  118. String GenerateUUID();
  119. /// If true, the sln file will rewritten if it exists, default is false
  120. void SetRewriteSolution(bool rewrite);
  121. bool LoadProject(const JSONValue& root);
  122. bool LoadProject(const String& projectPath);
  123. bool LoadProject(Project* project);
  124. private:
  125. // if true, the solution (sln) file will be recreated if it exists
  126. bool rewriteSolution_;
  127. String scriptPlatform_;
  128. SharedPtr<Project> atomicProject_;
  129. SharedPtr<NETSolution> solution_;
  130. Vector<SharedPtr<NETCSProject>> projects_;
  131. };
  132. }