IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.Tools.Runner.IkvmToolLauncher Class Referenceabstract
Inheritance diagram for IKVM.Tools.Runner.IkvmToolLauncher:
IKVM.Tools.Runner.Exporter.IkvmExporterLauncher IKVM.Tools.Runner.Importer.IkvmImporterLauncher

Public Member Functions

 IkvmToolLauncher (string toolName, string toolPath, IIkvmToolDiagnosticEventListener listener)
 Initializes a new instance.
 
string? GetToolExe ()
 Gets the path to executable for the given environment.
 

Protected Member Functions

ValueTask LogEventAsync (in IkvmToolDiagnosticEvent @event, CancellationToken cancellationToken)
 Logs an event if a listener is provided.
 
ValueTask LogEventAsync (IkvmToolDiagnosticEventLevel level, string message, string[] args, CancellationToken cancellationToken)
 Logs an anonymous event if a listener is provided.
 
ValueTask ParseAndLogEventAsync (string line, CancellationToken cancellationToken)
 Parses the line and logs it.
 
IkvmToolDiagnosticEvent ParseEvent (string line)
 Parse a line of JSON tool output into a diagnostic event.
 

Detailed Description

Definition at line 14 of file IkvmToolLauncher.cs.

Constructor & Destructor Documentation

◆ IkvmToolLauncher()

IKVM.Tools.Runner.IkvmToolLauncher.IkvmToolLauncher ( string toolName,
string toolPath,
IIkvmToolDiagnosticEventListener listener )

Initializes a new instance.

Parameters
toolName
toolPath
listener

Definition at line 27 of file IkvmToolLauncher.cs.

28 {
29 this.toolName = toolName ?? throw new ArgumentNullException(nameof(toolName));
30 this.toolPath = toolPath ?? throw new ArgumentNullException(nameof(toolPath));
31 this.listener = listener;
32
33 if (Directory.Exists(toolPath) == false)
34 throw new DirectoryNotFoundException($"Could not locate tool path {toolPath}.");
35 }

Member Function Documentation

◆ GetToolExe()

string? IKVM.Tools.Runner.IkvmToolLauncher.GetToolExe ( )

Gets the path to executable for the given environment.

Returns
Exceptions
ArgumentNullException
NotImplementedException

Definition at line 98 of file IkvmToolLauncher.cs.

99 {
100 foreach (var name in (Span<string>)[toolName + ".exe", toolName])
101 if (File.Exists(Path.Combine(toolPath, name)))
102 return Path.Combine(toolPath, name);
103
104 return null;
105 }

◆ LogEventAsync() [1/2]

ValueTask IKVM.Tools.Runner.IkvmToolLauncher.LogEventAsync ( IkvmToolDiagnosticEventLevel level,
string message,
string[] args,
CancellationToken cancellationToken )
protected

Logs an anonymous event if a listener is provided.

Parameters
level
message
args
Returns

Definition at line 54 of file IkvmToolLauncher.cs.

55 {
56 return LogEventAsync(new IkvmToolDiagnosticEvent(-1, level, message, args), cancellationToken);
57 }
ValueTask LogEventAsync(in IkvmToolDiagnosticEvent @event, CancellationToken cancellationToken)
Logs an event if a listener is provided.
readonly record struct IkvmToolDiagnosticEvent(int Id, IkvmToolDiagnosticEventLevel Level, string Message, object?[] Args, IkvmToolDiagnosticEventLocation Location=default)
Describes an event emitted from a tool.

◆ LogEventAsync() [2/2]

ValueTask IKVM.Tools.Runner.IkvmToolLauncher.LogEventAsync ( in IkvmToolDiagnosticEvent @ event,
CancellationToken cancellationToken )
protected

Logs an event if a listener is provided.

Parameters
event
Returns

Definition at line 42 of file IkvmToolLauncher.cs.

43 {
44 return listener.ReceiveAsync(@event, cancellationToken);
45 }
ValueTask ReceiveAsync(IkvmToolDiagnosticEvent @event, CancellationToken cancellationToken)
Receives a diagnostic event.

◆ ParseAndLogEventAsync()

ValueTask IKVM.Tools.Runner.IkvmToolLauncher.ParseAndLogEventAsync ( string line,
CancellationToken cancellationToken )
protected

Parses the line and logs it.

Parameters
line
cancellationToken
Returns

Definition at line 65 of file IkvmToolLauncher.cs.

66 {
67 return LogEventAsync(ParseEvent(line), cancellationToken);
68 }
IkvmToolDiagnosticEvent ParseEvent(string line)
Parse a line of JSON tool output into a diagnostic event.

◆ ParseEvent()

IkvmToolDiagnosticEvent IKVM.Tools.Runner.IkvmToolLauncher.ParseEvent ( string line)
protected

Parse a line of JSON tool output into a diagnostic event.

Parameters
line
Returns

Definition at line 75 of file IkvmToolLauncher.cs.

76 {
77 try
78 {
79 var buffer = Encoding.UTF8.GetBytes(line);
80 var reader = new Utf8JsonReader(buffer);
81 if (reader.Read() == false)
82 throw new JsonException();
83
84 return IkvmToolDiagnosticEvent.ReadJson(ref reader);
85 }
86 catch (JsonException)
87 {
88 return new IkvmToolDiagnosticEvent(0, IkvmToolDiagnosticEventLevel.Fatal, "Unable to parse tool output: {0}", [line]);
89 }
90 }
IkvmToolDiagnosticEventLevel
Describes the level of diagnostic event a tool could emit.

The documentation for this class was generated from the following file: