-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
109f31f
commit 21a4918
Showing
35 changed files
with
522 additions
and
627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using DotDocs.Build.Build; | ||
using System.Collections.Immutable; | ||
using System.Reflection; | ||
|
||
namespace DotDocs.Build | ||
{ | ||
/// <summary> | ||
/// A class providing tools to interact and mutate a real repository and its project files on disk. | ||
/// </summary> | ||
public class Solution | ||
{ | ||
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); | ||
|
||
/// <summary> | ||
/// The results of the entire build. | ||
/// </summary> | ||
// internal BuildInstance? build; | ||
|
||
/// <summary> | ||
/// The directory of the solution. | ||
/// </summary> | ||
public string Dir { get; private set; } | ||
|
||
/// <summary> | ||
/// All project groups in the solution. | ||
/// </summary> | ||
public ImmutableArray<ProjectDocument> DependencyGraph { get; private set; } | ||
|
||
/// <summary> | ||
/// The select root project of a group to be documented. | ||
/// </summary> | ||
// public ProjectDocument? SelectedRootProject { get; private set; } | ||
|
||
/// <summary> | ||
/// Creates a new solution. | ||
/// </summary> | ||
/// <param name="path">Location of the solution file.</param> | ||
private Solution(string path) | ||
{ | ||
Logger.Debug("Params: [{pathLbl}: {pathValue}]", nameof(path), path); | ||
Dir = path; | ||
} | ||
|
||
public static Solution From(string path) | ||
{ | ||
if (!Directory.Exists(path)) // Ensure path exists | ||
throw new DirectoryNotFoundException(path); | ||
|
||
var solution = new Solution(path); | ||
solution.MakeProjectGraph(); | ||
|
||
return solution; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a dependency graph for each project group. | ||
/// </summary> | ||
/// <returns></returns> | ||
private void MakeProjectGraph() | ||
{ | ||
Logger.Trace("Making the project dependency graph."); | ||
|
||
// Locate all solution and project files | ||
var projectFiles = Directory.GetFiles(Dir, "*.csproj", SearchOption.AllDirectories); | ||
DependencyGraph = FindRootProjects(projectFiles.ToList()) | ||
.ToImmutableArray(); | ||
} | ||
|
||
/// <summary> | ||
/// Ensures each project file has documentation generation enabled in the .csproj file. | ||
/// </summary> | ||
/// <returns></returns> | ||
public static void EnableDocumentationGeneration(ProjectDocument project) | ||
{ | ||
Logger.Trace("Beginning recursive loop to enable documentation generation on all projects."); | ||
|
||
ArgumentNullException.ThrowIfNull(project); | ||
|
||
project.EnableAllDocumentationGeneration(); | ||
} | ||
|
||
/// <summary> | ||
/// Builds active project via the property <see cref="SelectedRootProject"/>. | ||
/// </summary> | ||
/// <returns></returns> | ||
public static BuildInstance Build(ProjectDocument project) | ||
{ | ||
ArgumentNullException.ThrowIfNull(project); | ||
return new BuildInstance(project) | ||
.Build(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns all .csproj files that are the root project of a possibly larger project structure. | ||
/// </summary> | ||
/// <returns></returns> | ||
static IEnumerable<ProjectDocument> FindRootProjects(List<string> projectFiles) | ||
{ | ||
var projects = new List<ProjectDocument>(); | ||
|
||
while (projectFiles.Count != 0) | ||
{ | ||
var proj = projectFiles.First(); | ||
|
||
if (!File.Exists(projectFiles.First())) | ||
{ | ||
var ex = new FileNotFoundException($"The following project file path does not exist: {proj}"); | ||
Logger.Fatal(ex); | ||
throw ex; | ||
} | ||
|
||
projects.Add(ProjectDocument.From(proj, projectFiles, projects)); | ||
} | ||
return projects.Where(proj => proj.Parent == null).ToArray(); | ||
} | ||
} | ||
} |
Oops, something went wrong.