7
7
using System . Threading ;
8
8
using System . Threading . Tasks ;
9
9
using BuildXL . Utilities . Core ;
10
- using BuildXL . Utilities . Instrumentation . Common ;
11
10
12
11
namespace BuildXL . Plugin
13
12
{
14
13
/// <nodoc />
15
14
public class PluginFactory : IPluginFactory
16
15
{
17
16
/// <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 ( ) ;
25
18
26
19
private const string StartPluginProcessArgumentsForamt = "--ipcmoniker {0} --logdir {1} --logVerbose {2}" ;
27
20
28
- private IPlugin PluginCreation_RunInProcess ( PluginCreationArgument argument )
21
+ private readonly Func < PluginCreationArgument , IPlugin > m_pluginRunInProcessCreationFunc = argument =>
29
22
{
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
-
33
23
var processStartInfo = new ProcessStartInfo ( argument . PluginPath )
34
24
{
35
25
Arguments = string . Format ( StartPluginProcessArgumentsForamt , argument . ConnectionOption . IpcMoniker , argument . ConnectionOption . LogDir , argument . ConnectionOption . LogVerbose ) ,
36
26
UseShellExecute = false ,
37
27
RedirectStandardOutput = false ,
38
- RedirectStandardError = true ,
39
28
} ;
40
29
41
30
string id = argument . PluginId ;
42
31
43
32
var process = new Process ( ) ;
44
33
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 ( ) ;
48
35
49
36
var client = argument . CreatePluginClientFunc . Invoke ( argument . ConnectionOption ) ;
50
37
var plugin = new Plugin ( id , argument . PluginPath , process , client ) ;
51
38
return plugin ;
52
- }
39
+ } ;
53
40
54
- private IPlugin PluginCreation_RunInThread ( PluginCreationArgument argument )
41
+ private readonly Func < PluginCreationArgument , IPlugin > m_pluginRunInThreadCreationFunc = argument =>
55
42
{
56
43
Contract . RequiresNotNull ( argument , "argument can't be null" ) ;
57
44
Contract . RequiresNotNull ( argument . RunInPluginThreadAction , "runInpluginThead can't be null" ) ;
@@ -65,14 +52,14 @@ private IPlugin PluginCreation_RunInThread(PluginCreationArgument argument)
65
52
var client = argument . CreatePluginClientFunc . Invoke ( argument . ConnectionOption ) ;
66
53
var plugin = new Plugin ( argument . PluginId , argument . PluginPath , pluginTask , cancellationTokenSource , client ) ;
67
54
return plugin ;
68
- }
55
+ } ;
69
56
70
57
/// <nodoc />
71
58
public IPlugin CreatePlugin ( PluginCreationArgument pluginCreationArgument )
72
59
{
73
60
return pluginCreationArgument . RunInSeparateProcess ?
74
- PluginCreation_RunInProcess ( pluginCreationArgument ) :
75
- PluginCreation_RunInThread ( pluginCreationArgument ) ;
61
+ m_pluginRunInProcessCreationFunc . Invoke ( pluginCreationArgument ) :
62
+ m_pluginRunInThreadCreationFunc . Invoke ( pluginCreationArgument ) ;
76
63
}
77
64
78
65
/// <nodoc />
@@ -91,8 +78,6 @@ public async Task<Possible<IPlugin>> CreatePluginAsync(PluginCreationArgument pl
91
78
}
92
79
else
93
80
{
94
- string stderr = await plugin . PluginProcess . StandardError . ReadToEndAsync ( ) ;
95
- Tracing . Logger . Log . PluginManagerLogMessage ( m_loggingContext , $ "Plugin process stderr:\n { stderr } ") ;
96
81
plugin . PluginProcess . Kill ( ) ;
97
82
return pluginCreationResult . Failure ;
98
83
}
@@ -108,5 +93,18 @@ public string CreatePluginId()
108
93
{
109
94
return Guid . NewGuid ( ) . ToString ( ) ;
110
95
}
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
+ }
111
109
}
112
110
}
0 commit comments