Skip to content

Commit

Permalink
chore: dead code elimination
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih authored and p-kostov committed Jun 28, 2024
1 parent c5362df commit 9765e96
Show file tree
Hide file tree
Showing 34 changed files with 52 additions and 502 deletions.
9 changes: 0 additions & 9 deletions src/Docfx.App/Helpers/Constants.cs

This file was deleted.

4 changes: 1 addition & 3 deletions src/Docfx.App/RunBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

namespace Docfx;

#pragma warning disable CS0618 // Type or member is obsolete

/// <summary>
/// Helper class to build document.
/// </summary>
Expand All @@ -20,7 +18,7 @@ public static string Exec(BuildJsonConfig config, BuildOptions options, string c
{
if (config.Template == null || config.Template.Count == 0)
{
config.Template = new ListWithStringFallback { Constants.DefaultTemplateName };
config.Template = new ListWithStringFallback { "default" };
}

var baseDirectory = Path.GetFullPath(string.IsNullOrEmpty(configDirectory) ? Directory.GetCurrentDirectory() : configDirectory);
Expand Down
36 changes: 17 additions & 19 deletions src/Docfx.Build/DocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,25 @@ List<IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuildParamet
{
var result = new List<IDocumentProcessor>();

using (var resource = parameter?.TemplateManager?.CreateTemplateResource())
var resource = parameter?.TemplateManager?.CreateTemplateResource();
if (resource == null || resource.IsEmpty)
{
if (resource == null || resource.IsEmpty)
{
return result;
}
return result;
}

foreach (var pair in resource.GetResources(@"^schemas/.*\.schema\.json"))
{
var fileName = Path.GetFileName(pair.Path);
foreach (var pair in resource.GetResources(@"^schemas/.*\.schema\.json"))
{
var fileName = Path.GetFileName(pair.Path);

using (new LoggerFileScope(fileName))
{
var schema = DocumentSchema.Load(pair.Content, fileName.Remove(fileName.Length - ".schema.json".Length));
var sdp = new SchemaDrivenDocumentProcessor(
schema,
new CompositionContainer(CompositionContainer.DefaultContainer),
markdownService);
Logger.LogVerbose($"\t{sdp.Name} with build steps ({string.Join(", ", from bs in sdp.BuildSteps orderby bs.BuildOrder select bs.Name)})");
result.Add(sdp);
}
using (new LoggerFileScope(fileName))
{
var schema = DocumentSchema.Load(pair.Content, fileName.Remove(fileName.Length - ".schema.json".Length));
var sdp = new SchemaDrivenDocumentProcessor(
schema,
new CompositionContainer(CompositionContainer.DefaultContainer),
markdownService);
Logger.LogVerbose($"\t{sdp.Name} with build steps ({string.Join(", ", from bs in sdp.BuildSteps orderby bs.BuildOrder select bs.Name)})");
result.Add(sdp);
}
}

Expand All @@ -227,7 +225,7 @@ List<IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuildParamet

private static MarkdigMarkdownService CreateMarkdigMarkdownService(DocumentBuildParameters parameters)
{
using var resource = parameters.TemplateManager?.CreateTemplateResource();
var resource = parameters.TemplateManager?.CreateTemplateResource();

return new MarkdigMarkdownService(
new MarkdownServiceParameters
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build/HostServiceCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Docfx.Build.Engine;

internal class HostServiceCreator : IHostServiceCreator
class HostServiceCreator
{
private readonly DocumentBuildContext _context;

Expand Down
32 changes: 0 additions & 32 deletions src/Docfx.Build/IHostServiceCreator.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/Docfx.Build/LinkPhaseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ private InternalManifestItem HandleSaveResult(
SaveResult result)
{
Context.SetFilePath(model.Key, ((RelativePath)model.File).GetPathFromWorkingFolder());
DocumentException.RunAll(
() => CheckFileLink(model, hostService, result),
() => HandleUids(result),
() => RegisterXRefSpec(result));

CheckFileLink(model, hostService, result);
HandleUids(result);
RegisterXRefSpec(result);

return GetManifestItem(model, result);
}
Expand Down
27 changes: 0 additions & 27 deletions src/Docfx.Build/OSPlatformSensitiveDictionary.cs

This file was deleted.

9 changes: 3 additions & 6 deletions src/Docfx.Build/PostProcessors/ValidateBookmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ public sealed class ValidateBookmark : HtmlDocumentHandler
/// <summary>
/// bookmarks mapping from output file -> bookmarks
/// </summary>
private readonly OSPlatformSensitiveDictionary<HashSet<string>> _registeredBookmarks =
new();
private readonly Dictionary<string, HashSet<string>> _registeredBookmarks = new(FilePathComparer.OSPlatformSensitiveStringComparer);
/// <summary>
/// file mapping from output file -> src file
/// </summary>
private readonly OSPlatformSensitiveDictionary<string> _fileMapping =
new();
private readonly OSPlatformSensitiveDictionary<List<LinkItem>> _linksWithBookmark =
new();
private readonly Dictionary<string, string> _fileMapping = new(FilePathComparer.OSPlatformSensitiveStringComparer);
private readonly Dictionary<string, List<LinkItem>> _linksWithBookmark = new(FilePathComparer.OSPlatformSensitiveStringComparer);

#region IHtmlDocumentHandler members

Expand Down
82 changes: 0 additions & 82 deletions src/Docfx.Build/ResourceFileReaders/ArchiveResourceReader.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ public override Stream GetResourceStream(string name)
return null;
}

protected override void Dispose(bool disposing)
{
foreach (var reader in _readers)
reader.Dispose();

base.Dispose(disposing);
}

public IEnumerator<ResourceFileReader> GetEnumerator() => ((IEnumerable<ResourceFileReader>)_readers).GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => _readers.GetEnumerator();
Expand Down
17 changes: 0 additions & 17 deletions src/Docfx.Build/ResourceFileReaders/IResourceFileReader.cs

This file was deleted.

20 changes: 1 addition & 19 deletions src/Docfx.Build/ResourceFileReaders/ResourceFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Docfx.Build.Engine;

public abstract class ResourceFileReader : IResourceFileReader, IDisposable
public abstract class ResourceFileReader
{
public abstract string Name { get; }

Expand Down Expand Up @@ -55,24 +55,6 @@ bool filter(string s)

public abstract Stream GetResourceStream(string name);

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
}

/// <summary>
/// Override Object.Finalize by defining a destructor
/// </summary>
~ResourceFileReader()
{
Dispose(false);
}

protected static string GetString(Stream stream)
{
if (stream == null) return null;
Expand Down
9 changes: 4 additions & 5 deletions src/Docfx.Build/SingleDocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ public Manifest Build(DocumentBuildParameters parameters, IMarkdownService markd

// Start building document...
List<HostService> hostServices = null;
IHostServiceCreator hostServiceCreator = null;
try
{
using var templateProcessor = parameters.TemplateManager?.GetTemplateProcessor(context, parameters.MaxParallelism)
?? new TemplateProcessor(new EmptyResourceReader(), context, 16);
var templateProcessor = parameters.TemplateManager?.GetTemplateProcessor(context, parameters.MaxParallelism)
?? new TemplateProcessor(new EmptyResourceReader(), context, 16);

hostServiceCreator = new HostServiceCreator(context);
var hostServiceCreator = new HostServiceCreator(context);
hostServices = GetInnerContexts(parameters, Processors, templateProcessor, hostServiceCreator, markdownService);

templateProcessor.CopyTemplateResources(context.ApplyTemplateSettings);
Expand Down Expand Up @@ -100,7 +99,7 @@ private List<HostService> GetInnerContexts(
DocumentBuildParameters parameters,
IEnumerable<IDocumentProcessor> processors,
TemplateProcessor templateProcessor,
IHostServiceCreator creator,
HostServiceCreator creator,
IMarkdownService markdownService)
{
var files = (from file in parameters.Files.EnumerateFiles().AsParallel().WithDegreeOfParallelism(parameters.MaxParallelism)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Docfx.Build.Engine;

public class PreprocessorLoader
{
private readonly IResourceFileReader _reader;
private readonly ResourceFileReader _reader;
private readonly int _maxParallelism;
private readonly DocumentBuildContext _context;

public PreprocessorLoader(IResourceFileReader reader, DocumentBuildContext context, int maxParallelism)
public PreprocessorLoader(ResourceFileReader reader, DocumentBuildContext context, int maxParallelism)
{
_reader = reader;
_maxParallelism = maxParallelism;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class TemplateJintPreprocessor : ITemplatePreprocessor

private Func<object, object> _getOptionsFunc;

public TemplateJintPreprocessor(IResourceFileReader resourceCollection, ResourceInfo scriptResource, DocumentBuildContext context, string name = null)
public TemplateJintPreprocessor(ResourceFileReader resourceCollection, ResourceInfo scriptResource, DocumentBuildContext context, string name = null)
{
if (!string.IsNullOrWhiteSpace(scriptResource.Content))
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public object TransformModel(object model)
return model;
}

private Jint.Engine SetupEngine(IResourceFileReader resourceCollection, ResourceInfo scriptResource, DocumentBuildContext context)
private Jint.Engine SetupEngine(ResourceFileReader resourceCollection, ResourceInfo scriptResource, DocumentBuildContext context)
{
var rootPath = (RelativePath)scriptResource.Path;
var engineCache = new Dictionary<string, Jint.Engine>();
Expand Down
Loading

0 comments on commit 9765e96

Please sign in to comment.