NETProjectGen.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. OBJECT(NETProjectBase)
  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. OBJECT(NETCSProject)
  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. OBJECT(NETSolution)
  82. public:
  83. NETSolution(Context* context, NETProjectGen* projectGen);
  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. private:
  93. void GenerateSolution(const String& slnPath);
  94. String name_;
  95. String outputPath_;
  96. String solutionGUID_;
  97. Vector<String> packages_;
  98. };
  99. class NETProjectGen : public Object
  100. {
  101. OBJECT(NETProjectGen)
  102. public:
  103. NETProjectGen(Context* context);
  104. virtual ~NETProjectGen();
  105. const String& GetScriptPlatform() { return scriptPlatform_; }
  106. NETSolution* GetSolution() { return solution_; }
  107. const Vector<SharedPtr<NETCSProject>>& GetCSProjects() { return projects_; }
  108. Project* GetAtomicProject() const { return atomicProject_; }
  109. NETCSProject* GetCSProjectByName(const String& name);
  110. bool GetCSProjectDependencies(NETCSProject * source, PODVector<NETCSProject*>& depends) const;
  111. void SetScriptPlatform(const String& platform) { scriptPlatform_ = platform; }
  112. bool Generate();
  113. /// Returns true if the generated solution requires NuGet
  114. bool GetRequiresNuGet();
  115. String GenerateUUID();
  116. bool LoadProject(const JSONValue& root);
  117. bool LoadProject(const String& projectPath);
  118. bool LoadProject(Project* project);
  119. private:
  120. String scriptPlatform_;
  121. SharedPtr<Project> atomicProject_;
  122. SharedPtr<NETSolution> solution_;
  123. Vector<SharedPtr<NETCSProject>> projects_;
  124. };
  125. }