77using System . Threading ;
88using System . Threading . Tasks ;
99using BuildXL . Utilities . Core ;
10- using BuildXL . Utilities . Instrumentation . Common ;
1110
1211namespace BuildXL . Plugin
1312{
1413 /// <nodoc />
1514 public class PluginFactory : IPluginFactory
1615 {
1716 /// <nodoc />
18- private readonly LoggingContext m_loggingContext ;
19-
20- /// <nodoc />
21- public PluginFactory ( LoggingContext loggingContext )
22- {
23- m_loggingContext = loggingContext ;
24- }
17+ public static PluginFactory Instance = new PluginFactory ( ) ;
2518
2619 private const string StartPluginProcessArgumentsForamt = "--ipcmoniker {0} --logdir {1} --logVerbose {2}" ;
2720
28- private IPlugin PluginCreation_RunInProcess ( PluginCreationArgument argument )
21+ private readonly Func < PluginCreationArgument , IPlugin > m_pluginRunInProcessCreationFunc = argument =>
2922 {
30- Tracing . Logger . Log . PluginManagerLogMessage ( m_loggingContext , $ "PluginFactory starting plugin { argument . PluginPath } with args " +
31- $ "{ string . Format ( StartPluginProcessArgumentsForamt , argument . ConnectionOption . IpcMoniker , argument . ConnectionOption . LogDir , argument . ConnectionOption . LogVerbose ) } ") ;
32-
3323 var processStartInfo = new ProcessStartInfo ( argument . PluginPath )
3424 {
3525 Arguments = string . Format ( StartPluginProcessArgumentsForamt , argument . ConnectionOption . IpcMoniker , argument . ConnectionOption . LogDir , argument . ConnectionOption . LogVerbose ) ,
3626 UseShellExecute = false ,
3727 RedirectStandardOutput = false ,
38- RedirectStandardError = true ,
3928 } ;
4029
4130 string id = argument . PluginId ;
4231
4332 var process = new Process ( ) ;
4433 process . StartInfo = processStartInfo ;
45- bool success = process . Start ( ) ;
46-
47- Tracing . Logger . Log . PluginManagerLogMessage ( m_loggingContext , $ "PluginFactory start result for plugin { argument . PluginPath } : { success } ") ;
34+ process . Start ( ) ;
4835
4936 var client = argument . CreatePluginClientFunc . Invoke ( argument . ConnectionOption ) ;
5037 var plugin = new Plugin ( id , argument . PluginPath , process , client ) ;
5138 return plugin ;
52- }
39+ } ;
5340
54- private IPlugin PluginCreation_RunInThread ( PluginCreationArgument argument )
41+ private readonly Func < PluginCreationArgument , IPlugin > m_pluginRunInThreadCreationFunc = argument =>
5542 {
5643 Contract . RequiresNotNull ( argument , "argument can't be null" ) ;
5744 Contract . RequiresNotNull ( argument . RunInPluginThreadAction , "runInpluginThead can't be null" ) ;
@@ -65,14 +52,14 @@ private IPlugin PluginCreation_RunInThread(PluginCreationArgument argument)
6552 var client = argument . CreatePluginClientFunc . Invoke ( argument . ConnectionOption ) ;
6653 var plugin = new Plugin ( argument . PluginId , argument . PluginPath , pluginTask , cancellationTokenSource , client ) ;
6754 return plugin ;
68- }
55+ } ;
6956
7057 /// <nodoc />
7158 public IPlugin CreatePlugin ( PluginCreationArgument pluginCreationArgument )
7259 {
7360 return pluginCreationArgument . RunInSeparateProcess ?
74- PluginCreation_RunInProcess ( pluginCreationArgument ) :
75- PluginCreation_RunInThread ( pluginCreationArgument ) ;
61+ m_pluginRunInProcessCreationFunc . Invoke ( pluginCreationArgument ) :
62+ m_pluginRunInThreadCreationFunc . Invoke ( pluginCreationArgument ) ;
7663 }
7764
7865 /// <nodoc />
@@ -91,8 +78,6 @@ public async Task<Possible<IPlugin>> CreatePluginAsync(PluginCreationArgument pl
9178 }
9279 else
9380 {
94- string stderr = await plugin . PluginProcess . StandardError . ReadToEndAsync ( ) ;
95- Tracing . Logger . Log . PluginManagerLogMessage ( m_loggingContext , $ "Plugin process stderr:\n { stderr } ") ;
9681 plugin . PluginProcess . Kill ( ) ;
9782 return pluginCreationResult . Failure ;
9883 }
@@ -108,5 +93,18 @@ public string CreatePluginId()
10893 {
10994 return Guid . NewGuid ( ) . ToString ( ) ;
11095 }
96+
97+ /// <nodoc />
98+ public static void SetGrpcPluginClientBasedOnMessageType ( IPlugin plugin , PluginMessageType messageType )
99+ {
100+ //switch(messageType)
101+ //{
102+ // case PluginMessageType.ParseLogMessage:
103+ // plugin.SetLogParsePluginClient();
104+ // break;
105+ // default:
106+ // break;
107+ //}
108+ }
111109 }
112110}
0 commit comments