How to integrate with ICodeProcessor

The following page should explain how to integrate an ICodeProcessor and its main components, as an example, you can visit the following code processor: DummyCodeProcessor

How to integrate

First, you need to download and install the Mobilize.Common.Contracts nuget

This class is used in the license fingerprint

Next, you need to implement the ICodeProcessor interface defined in the Mobilize.Common.Contracts.CodeProcessor namespace:

public interface ICodeProcessor : IDisposable
{
    string Name { get; }

    bool RequiresLicense { get; }

    IEnumerable<string> SupportedExtensions { get; }

    IProgressDescriptor ProgressDescriptor { get; }

    ILogger Logger { get; set; }

    void Cancel();
    
    CodeProcessorExecutionResult Execute(ExecutionParameters executionParameters, ICodeModelWriter codeModelWriter);

    CodeDescriptor GetCodeDescriptor(string inputFolder);

    bool ValidateParameters(ExecutionParameters executionParameters, ref string errorMessage);
}

Properties

Name

The tool name defined by the team.

RequiresLicense

Most code processors will need a license, there are some cases like scanners that don't need a license.

SupportedExtensions

The list of supported extensions by the code processor, as an example in a c# code processor should be { ".sln" }, or an oracle code processor should have {".ora", ".sql", ... }

ProgressDescriptor

An instance of the progress descriptor defined the Mobilize.Common.Utils nuget, for more information visit ProgressDescriptor, it is recommended to initialize the progress descriptor during the construction of the code processor, as an example:

    public MyCodeProcessor()
    {
        this.parsingProgressDescriptor = new SingleProgressDescriptor("Parsing");
        this.processingProgressDescriptor = new SingleProgressDescriptor("Processing");
        this.writeResultsProgressDescriptor = new SingleProgressDescriptor("WriteResults");
        SubProgressDescriptor[] subProgressDescriptors = new SubProgressDescriptor[]
        {
            new SubProgressDescriptor(3.33f, this.parsingProgressDescriptor),
            new SubProgressDescriptor(3.33f, this.processingProgressDescriptor),
            new SubProgressDescriptor(3.33f, this.writeResultsProgressDescriptor),
        };
        
        this.compoundProgressDescriptor = new CompoundProgressDescriptor("MyCodeProcessor", subProgressDescriptors);
    }

You can change the progress descriptor to InProgress or another state following the example:

this.parsingProgressDescriptor.UpdateState(ProgressStatus.InProgress);

Logger

An instance of the Logger defined in the Mobilize.Common.Utils nuget, for more information visit Logger

The Logger instance is provided by the controller, so it's not needed to create a new instance of it

Functions

Cancel

This is currently not supported by the infrastructure

ValidateParameters

Method used to validate if the received execution parameters are valid to the code processor, the return value should be either true if everything is correct or false otherwise if the execution parameters are not valid, it should be specified in the errorMessage ref parameter since that message will be shown to the user, the paths are validated beforehand so it's not needed to validate it again, its only needed to validate the additional parameters received in the ExecutionParameters.

Execute

Method used to execute the code processor, this method will be called after ValidateParameters method, any assessment information should be registered through the ICodeModelWriter instance, for more information about the return value visit CodeProcessorExecutionResult.

GetCodeDescriptor

Method used to get CodeDescriptor using the inputFolder parameter.

Return values

CodeProcessorExecutionResult

This class is defined in the Mobilize.Common.Contracts nuget as the following:

public class CodeProcessorExecutionResult
{
    public CodeProcessorExecutionResult(ExecutionStatus executionStatus, Dictionary<string, string> customResultDetails = null);

    public ExecutionStatus ExecutionStatus { get; }
    public Dictionary<string, string> CustomResultDetails { get; }
}

ExecutionStatus

A class composed of the following properties:

public class ExecutionStatus
{
    public ExecutionStatus(FinalResult finalResult, Exception exceptionReport = null);

    public FinalResult FinalResult { get; }
    public Exception exceptionReport { get; }
}

FinalResult

An enum used to describe the code processor final state, it should be one of the following values:

public enum FinalResult
{
    Success = 0,
    Crashed = 1,
    Cancelled = 2,
    Disconnected = 3
}

ExceptionReport

Added if the code processor execution failed due to an exception.

CustomResultDetails

A key-value pair dictionary that the code processor should add values in case there is something extra to show to the user since it will be used later in the interface.

CodeDescriptor

This class is defined in the Mobilize.Common.Contracts nuget as the following:

public class CodeDescriptor
{

    public CodeDescriptor(string unitsType, bool hasSomethingToProcess, IEnumerable<ExtensionCategory> extensionCategories = null, IEnumerable<ProjectDescriptor> projectDescriptors = null);

    public long Units { get; }

    public string UnitsType { get; }

    public long AllFileBytes { get; }

    public bool HasSomethingToProcess { get; }

    public IEnumerable<ExtensionCategory> ExtensionsCategory { get; }

    public IEnumerable<ProjectDescriptor> ProjectDescriptors { get; }
}

Units

The number of units measured in the given ProjectDescriptors

UnitsType

To specify what are the units, for example, Lines of code, files

AllFileBytes

The sum of all bytes from the projects files

HasSomethingToProcess

Value to say whether the code processor can do something with the current input

ExtensionsCategory

A class used to group certain file extensions with a category, for example: ".sql" ".ora" as a "SQL" category

ProjectDescriptors

A list of projects that describes each project with its files

Last updated