Adding More Languages to Squan Sources

Squan Sources can handle files written in languages that are not officially supported with a bit of extra configuration (new in 18.0). In this mode, only a basic analysis of the file is carried out so that an artefact is created in the project and findings can be attached to it. A subset of the base metrics from Squan Sources is optionally recorded for the artefact so that line counting, stability and text duplication metrics are available at file level for the new language.

The example below shows how you can add TypeScript files to your analysis:

  1. Copy <SQUORE_HOME>/configuration/tools/SQuORE/form.xml and its .properties files into your own configuration

  2. Edit form.xml to add a new language key and associated file extensions:

    <?xml version="1.0" encoding="UTF-8"?>
    <tags baseName="SQuORE" ...>
    	<tag type="multipleChoice" key="languages" ... defaultValue="...;typescript">
    		...
    		<value key="typescript" option=".ts,.TS" />
    	</tag>
    </tags>

    Files with extensions matching the typescript language will be added to your project as TYPESCRIPT_FILE artefacts

  3. Edit the defaultValue of the additional_param field to specify how Squan Sources should count source code lines and comment lines in the new language, based on another language officially supported by Squore. This step is optional, and is only needed if you want the to record basic line counting metrics for the artefacts.

    <?xml version="1.0" encoding="UTF-8"?>
    <tags baseName="SQuORE" ...>
    	...
    	<tag type="text" key="additional_param" defaultValue="typescript=javascript" />
    	...
    </tags>

    Lines in TypeScript files will be counted as they would for Javascript code.

  4. Add translations for the new language key to show in the web UI in Squan Sources's form_en.properties

    OPT.typescript.NAME=TypeScript
  5. Add translations for the new artefact type in one of the properties files imported by your Description Bundle:

    T.TYPESCRIPT_FILE.NAME=TypeScript File
  6. The new artefact type should also be declared as a type in your model. The easiest way to do this is to add it to the GENERIC_FILE alias in your analysis model, which is pre-configured to record the line counting metrics for new artefacts. You should also define a root indicator for you new artefact type. The following snippet shows a minimal configuration using a dummy indicator:

    <!-- <configuration>/MyModel/Analysis/Bundle.xml -->
    <?xml version="1.0" encoding="UTF-8"?>
    <Bundle>
    ...
    	<ArtefactType id="GENERIC_FILE" heirs="TYPESCRIPT_FILE" />
    
    	<RootIndicator artefactTypes="TYPESCRIPT_FILE" indicatorId="DUMMY" />
    	<Indicator indicatorId="DUMMY" scaleId="SCALE_INFO" targetArtefactTypes="TYPESCRIPT_FILE" displayTypes="IMAGE" />
    
    	<Measure measureId="DUMMY">
    		<Computation targetArtefactTypes="TYPESCRIPT_FILE" result="0" />
    	</Measure>
    ...
    </Bundle>
  7. Reload your configuration and analyse a project, checking the box for TypeScript in Squan Sources's options to get Typescrypt artefacts in your project.

    The new option for TypeScript files in Squan Sources

    Tip

    If you are launchin an analysis from the command line, use the language key defined in step 2 to analyse TypeScript files:

    -d "type=SQuORE,languages=typescript,additional_param=typescript=javascript"
  8. After the analysis finishes and you can see your artefacts in the tree, use the Dashboard Editor to build a dashboard for your new artefact type.

  9. Finally, create a handler for the source code viewer to display your new file type into your configuration folder, by copying <SQUORE_HOME>/configuration/sources/javascript_file.properties into your own configuration as <SQUORE_HOME>/configuration/sources/typescript_file.properties.