-
Notifications
You must be signed in to change notification settings - Fork 365
/
IntelliSenseOnlyPlugIn.cs
202 lines (165 loc) · 8.81 KB
/
IntelliSenseOnlyPlugIn.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//===============================================================================================================
// System : Sandcastle Help File Builder Plug-Ins
// File : IntelliSenseOnlyPlugIn.cs
// Author : Eric Woodruff (Eric@EWoodruff.us)
// Updated : 02/25/2022
// Note : Copyright 2014-2022, Eric Woodruff, All rights reserved
//
// This file contains a plug-in that can be used to build an IntelliSense XML comments file without a related
// help file.
//
// This code is published under the Microsoft Public License (Ms-PL). A copy of the license should be
// distributed with the code and can be found at the project website: https://GitHub.com/EWSoftware/SHFB. This
// notice, the author's name, and all copyright notices must remain intact in all applications, documentation,
// and source files.
//
// Date Who Comments
// ==============================================================================================================
// 11/17/2014 EFW Created the code
//===============================================================================================================
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using SandcastleBuilder.Utils;
using SandcastleBuilder.Utils.BuildComponent;
using SandcastleBuilder.Utils.BuildEngine;
namespace SandcastleBuilder.PlugIns
{
/// <summary>
/// This plug-in class can be used to build an IntelliSense XML comments file without a related help file
/// </summary>
[HelpFileBuilderPlugInExport("IntelliSense Only", Version = AssemblyInfo.ProductVersion,
Copyright = AssemblyInfo.Copyright, Description = "This plug-in can be used to build IntelliSense XML " +
"comments files without a related help file. This results in a faster build for support projects that " +
"do not need a separate help file but do need IntelliSense XML comments files.")]
public sealed class IntelliSenseOnlyPlugIn : IPlugIn
{
#region Private data members
//=====================================================================
private List<ExecutionPoint> executionPoints;
private BuildProcess builder;
#endregion
#region IPlugIn implementation
//=====================================================================
/// <summary>
/// This read-only property returns a collection of execution points that define when the plug-in should
/// be invoked during the build process.
/// </summary>
public IEnumerable<ExecutionPoint> ExecutionPoints
{
get
{
if(executionPoints == null)
executionPoints = new List<ExecutionPoint>
{
// This one has a lower priority since we want to update the manifest and reference
// build configuration file last.
new ExecutionPoint(BuildStep.MergeCustomConfigs, ExecutionBehaviors.After, 100),
new ExecutionPoint(BuildStep.CombiningIntermediateTocFiles, ExecutionBehaviors.InsteadOf),
new ExecutionPoint(BuildStep.ExtractingHtmlInfo, ExecutionBehaviors.InsteadOf),
new ExecutionPoint(BuildStep.CopyStandardHelpContent, ExecutionBehaviors.InsteadOf),
new ExecutionPoint(BuildStep.GenerateHelpProject, ExecutionBehaviors.InsteadOf),
new ExecutionPoint(BuildStep.CompilingHelpFile, ExecutionBehaviors.InsteadOf),
new ExecutionPoint(BuildStep.GenerateFullTextIndex, ExecutionBehaviors.InsteadOf),
new ExecutionPoint(BuildStep.CopyingWebsiteFiles, ExecutionBehaviors.InsteadOf)
};
return executionPoints;
}
}
/// <summary>
/// This method is used to initialize the plug-in at the start of the build process
/// </summary>
/// <param name="buildProcess">A reference to the current build process</param>
/// <param name="configuration">The configuration data that the plug-in should use to initialize itself</param>
public void Initialize(BuildProcess buildProcess, XElement configuration)
{
builder = buildProcess;
var metadata = (HelpFileBuilderPlugInExportAttribute)this.GetType().GetCustomAttributes(
typeof(HelpFileBuilderPlugInExportAttribute), false).First();
builder.ReportProgress("{0} Version {1}\r\n{2}\r\n This build will only generate IntelliSense " +
"comments files.", metadata.Id, metadata.Version, metadata.Copyright);
}
/// <summary>
/// This method is used to execute the plug-in during the build process
/// </summary>
/// <param name="context">The current execution context</param>
public void Execute(ExecutionContext context)
{
XPathNavigator deleteItem;
if(context == null)
throw new ArgumentNullException(nameof(context));
if(context.BuildStep == BuildStep.MergeCustomConfigs)
{
builder.ReportProgress("Removing non-member topics from the build manifest...");
XmlDocument config = new XmlDocument();
config.Load(builder.BuildAssemblerManifestFile);
XPathNavigator navConfig = config.CreateNavigator();
XPathNavigator item = navConfig.SelectSingleNode("topics/topic");
bool moreItems = true;
while(item != null && moreItems)
{
string id = item.GetAttribute("id", String.Empty);
string topicType = item.GetAttribute("type", String.Empty);
if(topicType != "API" || id.Length < 2 || id[1] != ':' || id[0] == 'G' || id[0] == 'N' ||
id[0] == 'R')
{
deleteItem = item.Clone();
moreItems = item.MoveToNext();
deleteItem.DeleteSelf();
}
else
moreItems = item.MoveToNext();
}
config.Save(builder.BuildAssemblerManifestFile);
builder.ReportProgress("Removing irrelevant build components from the configuration file...");
config = new XmlDocument();
config.Load(builder.BuildAssemblerConfigurationFile);
navConfig = config.CreateNavigator();
// Delete the MAML configuration component set if present
item = navConfig.SelectSingleNode("//component[@id='Switch Component']/case[@value='MAML']");
if(item != null)
item.DeleteSelf();
// The IntelliSense build component must be there
item = navConfig.SelectSingleNode("//component[@id='IntelliSense Component']");
if(item == null)
throw new BuilderException("ISO0001", "The IntelliSense Only plug-in requires that the " +
"IntelliSense Component be added to the project and configured.");
// Remove the Syntax Component
item = navConfig.SelectSingleNode("//component[@id='Syntax Component']");
if(item != null)
item.DeleteSelf();
// Remove the Code Block Component
item = navConfig.SelectSingleNode("//component[@id='Code Block Component']");
if(item != null)
item.DeleteSelf();
// Remove the Transform Component and everything after it
item = navConfig.SelectSingleNode("//component[@id='Transform Component']");
moreItems = true;
while(item != null && moreItems)
{
deleteItem = item.Clone();
moreItems = item.MoveToNext();
deleteItem.DeleteSelf();
}
config.Save(builder.BuildAssemblerConfigurationFile);
}
// Ignore all other the steps
}
#endregion
#region IDisposable implementation
//=====================================================================
/// <summary>
/// This implements the Dispose() interface to properly dispose of the plug-in object
/// </summary>
public void Dispose()
{
// Nothing to dispose of in this one
GC.SuppressFinalize(this);
}
#endregion
}
}