Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class JsonLocationInfo

public JsonLocationInfo(string swaggerPath, string jsonLocation)
{
FilePath = PathUtility.NormalizePath(swaggerPath);
FilePath = Path.GetFullPath(swaggerPath).Replace('\\', '/');
JsonLocation = jsonLocation;
}

Expand Down
12 changes: 0 additions & 12 deletions src/Docfx.Build/Conceptual/ConceptualDocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace Docfx.Build.ConceptualDocuments;
[Export(typeof(IDocumentProcessor))]
class ConceptualDocumentProcessor : DisposableDocumentProcessor
{
#region Fields

private readonly string[] SystemKeys = {
"conceptual",
"type",
Expand All @@ -27,18 +25,10 @@ class ConceptualDocumentProcessor : DisposableDocumentProcessor
"wordCount"
};

#endregion

#region Constructors

public ConceptualDocumentProcessor()
{
}

#endregion

#region IDocumentProcessor Members

[ImportMany(nameof(ConceptualDocumentProcessor))]
public override IEnumerable<IDocumentBuildStep> BuildSteps { get; set; }

Expand Down Expand Up @@ -121,6 +111,4 @@ public override SaveResult Save(FileModel model)

return result;
}

#endregion
}
194 changes: 91 additions & 103 deletions src/Docfx.Build/DocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Reflection;
using Docfx.Build.SchemaDriven;
using Docfx.Common;
using Docfx.DataContracts.Common;
using Docfx.MarkdigEngine;
using Docfx.Plugins;
using Newtonsoft.Json;
Expand Down Expand Up @@ -49,9 +48,6 @@ public void Build(IList<DocumentBuildParameters> parameters, string outputDirect
throw new ArgumentException("Parameters are empty.", nameof(parameters));
}

var logCodesLogListener = new LogCodesLogListener();
Logger.RegisterListener(logCodesLogListener);

var markdownService = CreateMarkdigMarkdownService(parameters[0]);

#if NET7_0_OR_GREATER
Expand All @@ -67,129 +63,121 @@ public void Build(IList<DocumentBuildParameters> parameters, string outputDirect
// Load schema driven processor from template
LoadSchemaDrivenDocumentProcessors(parameters[0]);

try
var manifests = new List<Manifest>();
if (parameters.All(p => p.Files.Count == 0))
{
var manifests = new List<Manifest>();
if (parameters.All(p => p.Files.Count == 0))
{
Logger.LogSuggestion(
"No file found, nothing will be generated. Please make sure docfx.json is correctly configured.",
code: SuggestionCodes.Build.EmptyInputFiles);
}
Logger.LogSuggestion(
"No file found, nothing will be generated. Please make sure docfx.json is correctly configured.",
code: SuggestionCodes.Build.EmptyInputFiles);
}

var noContentFound = true;
var emptyContentGroups = new List<string>();
foreach (var parameter in parameters)
var noContentFound = true;
var emptyContentGroups = new List<string>();
foreach (var parameter in parameters)
{
if (parameter.CustomLinkResolver != null)
{
if (parameter.CustomLinkResolver != null)
if (_container.TryGetExport(parameter.CustomLinkResolver, out ICustomHrefGenerator chg))
{
if (_container.TryGetExport(parameter.CustomLinkResolver, out ICustomHrefGenerator chg))
{
parameter.ApplyTemplateSettings.HrefGenerator = chg;
}
else
{
Logger.LogWarning($"Custom href generator({parameter.CustomLinkResolver}) is not found.");
}
parameter.ApplyTemplateSettings.HrefGenerator = chg;
}
else
{
Logger.LogWarning($"Custom href generator({parameter.CustomLinkResolver}) is not found.");
}
FileAbstractLayerBuilder falBuilder = FileAbstractLayerBuilder.Default
.ReadFromRealFileSystem(EnvironmentContext.BaseDirectory)
.WriteToRealFileSystem(parameter.OutputBaseDir);
}
FileAbstractLayerBuilder falBuilder = FileAbstractLayerBuilder.Default
.ReadFromRealFileSystem(EnvironmentContext.BaseDirectory)
.WriteToRealFileSystem(parameter.OutputBaseDir);

EnvironmentContext.FileAbstractLayerImpl = falBuilder.Create();
EnvironmentContext.FileAbstractLayerImpl = falBuilder.Create();

if (parameter.Files.Count == 0)
if (parameter.Files.Count == 0)
{
manifests.Add(new Manifest() { SourceBasePath = StringExtension.ToNormalizedPath(EnvironmentContext.BaseDirectory) });
}
else
{
if (!parameter.Files.EnumerateFiles().Any(s => s.Type == DocumentType.Article))
{
manifests.Add(new Manifest() { SourceBasePath = StringExtension.ToNormalizedPath(EnvironmentContext.BaseDirectory) });
if (!string.IsNullOrEmpty(parameter.GroupInfo?.Name))
{
emptyContentGroups.Add(parameter.GroupInfo.Name);
}
}
else
{
if (!parameter.Files.EnumerateFiles().Any(s => s.Type == DocumentType.Article))
{
if (!string.IsNullOrEmpty(parameter.GroupInfo?.Name))
{
emptyContentGroups.Add(parameter.GroupInfo.Name);
}
}
else
{
noContentFound = false;
}

parameter.Metadata = _postProcessorsManager.PrepareMetadata(parameter.Metadata);
if (!string.IsNullOrEmpty(parameter.VersionName))
{
Logger.LogInfo($"Start building for version: {parameter.VersionName}");
}
noContentFound = false;
}

using var builder = new SingleDocumentBuilder
{
MetadataValidators = MetadataValidators.ToList(),
Processors = Processors,
};
manifests.Add(builder.Build(parameter, markdownService));
parameter.Metadata = _postProcessorsManager.PrepareMetadata(parameter.Metadata);
if (!string.IsNullOrEmpty(parameter.VersionName))
{
Logger.LogInfo($"Start building for version: {parameter.VersionName}");
}

using var builder = new SingleDocumentBuilder
{
MetadataValidators = MetadataValidators.ToList(),
Processors = Processors,
};
manifests.Add(builder.Build(parameter, markdownService));
}
if (noContentFound)
{
Logger.LogSuggestion(
"No content file found. Please make sure the content section of docfx.json is correctly configured.",
code: SuggestionCodes.Build.EmptyInputContents);
}
else if (emptyContentGroups.Count > 0)
{
Logger.LogSuggestion(
$"No content file found in group: {string.Join(",", emptyContentGroups)}. Please make sure the content section of docfx.json is correctly configured.",
code: SuggestionCodes.Build.EmptyInputContents);
}
}
if (noContentFound)
{
Logger.LogSuggestion(
"No content file found. Please make sure the content section of docfx.json is correctly configured.",
code: SuggestionCodes.Build.EmptyInputContents);
}
else if (emptyContentGroups.Count > 0)
{
Logger.LogSuggestion(
$"No content file found in group: {string.Join(",", emptyContentGroups)}. Please make sure the content section of docfx.json is correctly configured.",
code: SuggestionCodes.Build.EmptyInputContents);
}

var generatedManifest = ManifestUtility.MergeManifest(manifests);
generatedManifest.Sitemap = parameters.FirstOrDefault()?.SitemapOptions;
ManifestUtility.RemoveDuplicateOutputFiles(generatedManifest.Files);
ManifestUtility.ApplyLogCodes(generatedManifest.Files, logCodesLogListener.Codes);
var generatedManifest = ManifestUtility.MergeManifest(manifests);
generatedManifest.Sitemap = parameters.FirstOrDefault()?.SitemapOptions;
ManifestUtility.RemoveDuplicateOutputFiles(generatedManifest.Files);

EnvironmentContext.FileAbstractLayerImpl =
FileAbstractLayerBuilder.Default
.ReadFromManifest(generatedManifest, parameters[0].OutputBaseDir)
.WriteToManifest(generatedManifest, parameters[0].OutputBaseDir)
.Create();
EnvironmentContext.FileAbstractLayerImpl =
FileAbstractLayerBuilder.Default
.ReadFromManifest(generatedManifest, parameters[0].OutputBaseDir)
.WriteToManifest(generatedManifest, parameters[0].OutputBaseDir)
.Create();

_postProcessorsManager.Process(generatedManifest, outputDirectory);
_postProcessorsManager.Process(generatedManifest, outputDirectory);

if (parameters[0].KeepFileLink)
{
var count = (from f in generatedManifest.Files
from o in f.Output
select o.Value into v
where v.LinkToPath != null
select v).Count();
if (count > 0)
{
Logger.LogInfo($"Skip dereferencing {count} files.");
}
}
else
if (parameters[0].KeepFileLink)
{
var count = (from f in generatedManifest.Files
from o in f.Output
select o.Value into v
where v.LinkToPath != null
select v).Count();
if (count > 0)
{
generatedManifest.Dereference(parameters[0].OutputBaseDir, parameters[0].MaxParallelism);
Logger.LogInfo($"Skip dereferencing {count} files.");
}

// Save to manifest.json
EnvironmentContext.FileAbstractLayerImpl =
FileAbstractLayerBuilder.Default
.ReadFromRealFileSystem(parameters[0].OutputBaseDir)
.WriteToRealFileSystem(parameters[0].OutputBaseDir)
.Create();

generatedManifest.Files.Sort((a, b) => (a.SourceRelativePath ?? "").CompareTo(b.SourceRelativePath ?? ""));
JsonUtility.Serialize("manifest.json", generatedManifest, Formatting.Indented);

EnvironmentContext.FileAbstractLayerImpl = null;
}
finally
else
{
Logger.UnregisterListener(logCodesLogListener);
generatedManifest.Dereference(parameters[0].OutputBaseDir, parameters[0].MaxParallelism);
}

// Save to manifest.json
EnvironmentContext.FileAbstractLayerImpl =
FileAbstractLayerBuilder.Default
.ReadFromRealFileSystem(parameters[0].OutputBaseDir)
.WriteToRealFileSystem(parameters[0].OutputBaseDir)
.Create();

generatedManifest.Files.Sort((a, b) => (a.SourceRelativePath ?? "").CompareTo(b.SourceRelativePath ?? ""));
JsonUtility.Serialize("manifest.json", generatedManifest, Formatting.Indented);

EnvironmentContext.FileAbstractLayerImpl = null;

List<IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuildParameters parameter)
{
var result = new List<IDocumentProcessor>();
Expand Down
14 changes: 0 additions & 14 deletions src/Docfx.Build/ManifestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,4 @@ public static Manifest MergeManifest(List<Manifest> manifests)
Groups = manifestGroupInfos.Count > 0 ? manifestGroupInfos : null,
};
}

public static void ApplyLogCodes(List<ManifestItem> manifestItems, ConcurrentDictionary<string, ImmutableHashSet<string>> codes)
{
ArgumentNullException.ThrowIfNull(manifestItems);
ArgumentNullException.ThrowIfNull(codes);

foreach (var item in manifestItems)
{
if (codes.TryGetValue(item.SourceRelativePath, out var value))
{
item.LogCodes = value;
}
}
}
}
35 changes: 0 additions & 35 deletions src/Docfx.Common/Loggers/LogCodesLogListener.cs

This file was deleted.

37 changes: 0 additions & 37 deletions src/Docfx.Common/Path/PathUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,6 @@ public static bool IsPathCaseInsensitive()
return true;
}

/// <summary>
/// http://stackoverflow.com/questions/422090/in-c-sharp-check-that-filename-is-possibly-valid-not-that-it-exists
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static bool IsValidFilePath(string path)
{
FileInfo fi = null;
try
{
fi = new FileInfo(path);
}
catch (ArgumentException) { }
catch (PathTooLongException) { }
catch (NotSupportedException) { }
return fi != null;
}

/// <summary>
/// Creates a relative path from one file or folder to another.
/// </summary>
Expand Down Expand Up @@ -161,23 +143,4 @@ public static string FormatPath(this string path, UriKind kind, string basePath

return null;
}

public static string NormalizePath(string path)
{
if (string.IsNullOrEmpty(path))
{
return path;
}
return Path.GetFullPath(path).Replace('\\', '/');
}

public static bool IsDirectory(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentException($"{nameof(path)} should not be null or empty string");
}

return Directory.Exists(path);
}
}
3 changes: 1 addition & 2 deletions src/Docfx.Common/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public static string ForwardSlashCombine(this string baseAddress, string relativ

public static string BackSlashToForwardSlash(this string input)
{
if (string.IsNullOrEmpty(input)) return null;
return input.Replace('\\', '/');
return input?.Replace('\\', '/');
}

public static string ToDelimitedString(this IEnumerable<string> input, string delimiter = ",")
Expand Down
Loading