Skip to content

Commit

Permalink
Add TagParameters config and pass it down to host service (dotnet#2563)
Browse files Browse the repository at this point in the history
* Add TagParameters config and pass it down to host service

* update
  • Loading branch information
vicancy authored Mar 30, 2018
1 parent 0b468f4 commit 7944d10
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
namespace Microsoft.DocAsCode.Build.Engine
{
using System;
using System.Collections.Generic;
using System.Collections.Immutable;

using Microsoft.DocAsCode.Build.Engine.Incrementals;
using Microsoft.DocAsCode.Common;
using Microsoft.DocAsCode.Plugins;

public sealed class DocumentBuildParameters : MarshalByRefObject
using Newtonsoft.Json.Linq;

public sealed class DocumentBuildParameters : MarshalByRefObject, IBuildParameters
{
[IncrementalIgnore]
public FileCollection Files { get; set; }

[IncrementalIgnore]
public string OutputBaseDir { get; set; }

[IncrementalIgnore]
public IReadOnlyDictionary<string, JArray> TagParameters { get; set; }

public ImmutableArray<string> ExternalReferencePackages { get; set; } = ImmutableArray<string>.Empty;

public ImmutableArray<string> XRefMaps { get; set; } = ImmutableArray<string>.Empty;
Expand Down
10 changes: 8 additions & 2 deletions src/Microsoft.DocAsCode.Build.Engine/HostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal sealed class HostService : IHostService, IDisposable

#region Properties

public IBuildParameters BuildParameters { get; }

public TemplateProcessor Template { get; set; }

public ImmutableList<FileModel> Models { get; private set; }
Expand Down Expand Up @@ -63,16 +65,20 @@ internal sealed class HostService : IHostService, IDisposable
#region Constructors

public HostService(string baseDir, IEnumerable<FileModel> models)
: this(baseDir, models, null, null, 0) { }
: this(baseDir, models, null, null, 0, null) { }

public HostService(string baseDir, IEnumerable<FileModel> models, string versionName, string versionDir, int lruSize)
: this(baseDir, models, versionName, versionDir, lruSize, null) { }
: this(baseDir, models, versionName, versionDir, lruSize, null, null) { }

public HostService(string baseDir, IEnumerable<FileModel> models, string versionName, string versionDir, int lruSize, GroupInfo groupInfo)
: this(baseDir, models, versionName, versionDir, lruSize, groupInfo, null) { }

public HostService(string baseDir, IEnumerable<FileModel> models, string versionName, string versionDir, int lruSize, GroupInfo groupInfo, IBuildParameters buildParameters)
{
VersionName = versionName;
VersionOutputFolder = versionDir;
GroupInfo = groupInfo;
BuildParameters = buildParameters;

// Disable LRU, when Content.get, it is possible that the value is Serialized before the modification on the content does not complete yet
//if (lruSize > 0)
Expand Down
14 changes: 13 additions & 1 deletion src/Microsoft.DocAsCode.Build.Engine/HostServiceCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.DocAsCode.Build.Engine

using Microsoft.DocAsCode.Common;
using Microsoft.DocAsCode.Plugins;
using Newtonsoft.Json.Linq;

internal class HostServiceCreator : IHostServiceCreator
{
Expand Down Expand Up @@ -46,7 +47,8 @@ public virtual HostService CreateHostService(
parameters.VersionName,
parameters.VersionDir,
parameters.LruSize,
parameters.GroupInfo)
parameters.GroupInfo,
new BuildParameters(parameters.TagParameters))
{
MarkdownService = markdownService,
Processor = processor,
Expand Down Expand Up @@ -123,5 +125,15 @@ private static ImmutableDictionary<string, object> ApplyFileMetadata(
}
return result.ToImmutableDictionary();
}

private sealed class BuildParameters : IBuildParameters
{
public IReadOnlyDictionary<string, JArray> TagParameters { get; }

public BuildParameters(IReadOnlyDictionary<string, JArray> tagParameters)
{
TagParameters = tagParameters;
}
}
}
}
14 changes: 14 additions & 0 deletions src/Microsoft.DocAsCode.Plugins/IBuildParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.DocAsCode.Plugins
{
using System.Collections.Generic;

using Newtonsoft.Json.Linq;

public interface IBuildParameters
{
IReadOnlyDictionary<string, JArray> TagParameters { get; }
}
}
2 changes: 2 additions & 0 deletions src/Microsoft.DocAsCode.Plugins/IHostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Microsoft.DocAsCode.Plugins

public interface IHostService
{
IBuildParameters BuildParameters { get; }

ImmutableList<TreeItemRestructure> TableOfContentRestructions { get; set; }

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/docfx/Models/BuildJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.DocAsCode
using Microsoft.DocAsCode.Plugins;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

[Serializable]
public class BuildJsonConfig
Expand Down Expand Up @@ -64,6 +65,9 @@ public class BuildJsonConfig
[JsonProperty("fileMetadata")]
public Dictionary<string, FileMetadataPairs> FileMetadata { get; set; }

[JsonProperty("tagParameters")]
public Dictionary<string, JArray> TagParameters { get; set; }

[JsonProperty("fileMetadataFiles")]
public ListWithStringFallback FileMetadataFilePaths { get; set; } = new ListWithStringFallback();

Expand Down
1 change: 1 addition & 0 deletions src/docfx/SubCommands/DocumentBuilderWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private static IEnumerable<DocumentBuildParameters> ConfigToParameter(BuildJsonC
FALName = config.FALName,
DisableGitFeatures = config.DisableGitFeatures,
SchemaLicense = config.SchemaLicense,
TagParameters = config.TagParameters
};
if (config.GlobalMetadata != null)
{
Expand Down

0 comments on commit 7944d10

Please sign in to comment.