Metric models
Required role | Rule Management |
Access | CodeChecker Server → Rules Configuration → Metric Models |
Metric models are script instructions used to create metrics and analyze an application's source code. A metric model defines the actions to carry out to retrieve a value when analyzing code. A metric model uses properties. When the metric using a metric model is instantiated for a quality rule, values for each of the properties are defined to conform to the specific rule’s context.
You want to create a quality rule to make sure the word 'TODO' is not found in the source code or the comments. The metric used in the quality rule needs to find the occurrences of this word.
To create the required metric, you will need to use the SEARCH_WORD metric model and define the correct properties when you instantiate the metric.
ARCAD CodeChecker comes with a set of standard, ready-to-use, non-editable metric models. However, ARCAD CodeChecker also allows you to create metric models using the Groovy scripting language.
For more information about the Groovy programming language, refer to the Groovy documentation.
For more information about metrics, refer to Metrics.
For more information about quality rules, refer to Quality rules.
The Metric Models view is accessed from the Configuration node in the Navigator.
The standard metric models supplied by ARCAD CodeChecker are highlighted to be easily identified.
Enter any combination of the above search criteria, then click the Search button to display the results. To display the complete list, click the Search button without entering any search criteria.
Follow the subsequent steps to create a new metric model.
Step 1 To access the Create Metric Model wizard, either click the Create icon in the toolbar of the Metric Models search view, or right-click anywhere in the search list of the view and select Create Metric Model.
Step 2 Define the metric model's Code, Name and Description. These values are required to create new metric models. The Code cannot be changed once the metric model is created, but the Name and Description can be edited later.
Click Finish.
Result The new metric model is created and its editor opens automatically. It is displayed in the search list in the Metric Models search view.
It is required to edit new metric models before using them.
To open a metric model’s editor, locate it in the Metric Models search view, then either:
- double-click on the item in the view,
- right-click on the item in the view and select Edit, or
- select the item in the view and click the Edit icon in the toolbar.
You can edit the values located in the Metric Model tab and the Script tab in the metric model's editor. The Metrics tab displays the list of metrics that were created using the metric model. Double click on a metric to access its editor.
Any changes made to a metric model are carried over to the metrics already created using this model, as long as these metrics are not used in active quality rules. A metric used in an active quality rule can no longer be edited, and any changes made to the metric model used to create it will not be carried over.
Save the changes (, Ctrl+S
or File > Save).
- Code
- This field displays the model's unique ID defined when creating the metric model. Once a model is created, it is not possible to edit this code.
- Name
- The metric model's name should reflect the actions carried out to retrieve a value during the code analysis to be easily identified.
- Description
- Use this description to give as many details as possible about the actions carried out by the metric model and the type of value retrieved. This description is displayed in the metric creation wizard.
Check the languages to which the metric model applies.
The languages supported by ARCAD CodeChecker are:
- CL
- COBOL
- RPG (RPG III)
- RPGLE (RPG IV)
The languages checked will be the only ones available for metrics created using the metric model.
If you leave the RPGLE box unchecked for a metric model, you will not be able to apply this language to metrics created using this metric model.
Define the metric model's script. Use the dedicated script editor in the Script tab.
To insert a class in the script using the CAST Classes helper, place the cursor on a line in the script editor. Right-click and select CAST classes > NAME OF THE CLASS in the contextual menu.
To test the script, right-click anywhere in the script editor and select Test script. A dialog opens to select a source file for testing. Select the file and click Open. The test starts and a dialog opens to display the result of the test.
You cannot edit the script of the standard ARCAD CodeChecker metric models.
For more information about the Groovy programming language, refer to the Groovy documentation.
Manage the properties included in the metric model's script in the Properties section of the editor. The values of these properties are defined in the quality rule(s) that will employ the metrics that use this model.
Follow the subsequent steps to create a new property.
Step 1 To open the New Metric Model Property wizard, click Create.
Step 2 Define a Property ID for the new property. This ID is used to identify the property in the metric model's script.
Step 3 Select the Type of the value from the drop-down list. This value is entered when the metric created from the metric model is instantiated. possible types are:
- Boolean,
- Date,
- Float,
- Integer,
- Select: to define a list of possible choices,
- String.
Step 4 Enter a detailed Description of the property. Use this description to give as many details as possible about the value that should be entered when creating a metric, depending on the quality rule's context.
Click OK.
Result The new property is created and is displayed in the Properties section in the metric model's editor.
To edit a property, either double-click on it, or select it and click Edit. Click OK to save any changes made or Cancel to keep the property unchanged.
To delete a property, select it and click Delete. Click Yes to confirm or No to keep the property.
Deleted metric models cannot be accessed or recovered.
It is not possible to delete a metric model currently used by a metric. You must first delete all of the metrics that use it before deleting the metric model.
Standard metric models cannot be deleted.
To delete a metric model, either right-click on it in the Metric Models search view and select Delete, or select it and click the Delete icon in the toolbar. Click OK to confirm or click Cancel to keep the metric model.