Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b352a27
Support for SonarQube 7.9 LTS and 8.2.x+
Laurensvanrun Apr 3, 2020
1d43188
Documentation corrected
Laurensvanrun Apr 3, 2020
43c16de
Updated Delphi.g grammar:
Laurensvanrun Apr 9, 2020
7c5c1a8
Delphi.g fixed, ambigious assembler tokens removed
Laurensvanrun Apr 9, 2020
12b4e8d
Delphi grammar: Fix for &<reserved keyword>
Laurensvanrun Apr 14, 2020
e17e6ea
-Support disabled deadcode metrics
Laurensvanrun Apr 16, 2020
774bf3e
Grammar fixed for generics and type declarations
Laurensvanrun Apr 16, 2020
47e6f2f
Enabled disabled tests
Laurensvanrun Apr 16, 2020
b24069b
New pom.xml
Laurensvanrun Apr 16, 2020
e3eb3d5
Grammar improved:
Laurensvanrun Apr 16, 2020
f783159
Support interface method resolution
Laurensvanrun Apr 17, 2020
33d5f6f
Support for external directive
Laurensvanrun Apr 17, 2020
a8ee37c
Grammar improvements:
Laurensvanrun Apr 17, 2020
a6c4ba6
Extended readme
Laurensvanrun Apr 20, 2020
a4cf290
Improved lexer and parser for ^ in strings and pointers
Laurensvanrun Apr 20, 2020
8c3402c
Version 1.0.3
Laurensvanrun Apr 20, 2020
7005557
Changed version to 1.0.6
joachimmarder Feb 10, 2021
5ce3727
Grammar-fixes:
joachimmarder Feb 10, 2021
9650636
Added support for syntax:
joachimmarder Feb 10, 2021
35bfa4a
TypeAnalyzer.canAnalyze() now handles record helper like classes and …
joachimmarder Feb 10, 2021
0c8ed2a
TypePropertyAnalyzer.doAnalyze(): Extend exception with information o…
joachimmarder Feb 10, 2021
398a8a5
Fixed errors due to invalid javadoc
joachimmarder Feb 10, 2021
f88c1d3
Fixed errors due to invalid javadoc
joachimmarder Feb 10, 2021
db4e3a3
Fixed errors due to invalid javadoc
joachimmarder Feb 10, 2021
f9f14b2
Field names now also accept "f" at the beginning (fix).
joachimmarder Feb 10, 2021
4bc3098
Activated unit test parseInterfaceMethodResolutionClause() which mena…
joachimmarder Feb 10, 2021
7bc572e
Latest generated grammer for V1.0.6
joachimmarder Feb 10, 2021
888e7ac
Update README.md
joachimmarder Feb 10, 2021
ed786b2
Create maven.yml
joachimmarder Feb 10, 2021
172fafd
Delete .travis.yml
joachimmarder Feb 10, 2021
c011448
Increased priority of CatchingGeneralExceptionRule and RaisingGeneral…
joachimmarder Feb 10, 2021
65b2325
Slightlty decreased priority of ConstructorWithoutInheritedStatementR…
joachimmarder Feb 10, 2021
e28d57b
Update README.md
joachimmarder Feb 10, 2021
cafa100
Update pom.xml
joachimmarder Feb 10, 2021
a64ea86
Update README.md
joachimmarder Feb 10, 2021
e2aadec
Update README.md
joachimmarder Feb 10, 2021
9261999
Update README.md
joachimmarder Feb 10, 2021
ebfb73c
Update pom.xml
joachimmarder Feb 11, 2021
7856aa3
Do not apply FieldNameRule for public or pubnlished members, the "F" …
joachimmarder Feb 12, 2021
61f7d9e
Update maven.yml
joachimmarder Feb 13, 2021
8b5da45
Provide build artifact
joachimmarder Feb 15, 2021
6ab6333
Issue #6: Provide download of latest build
joachimmarder Feb 15, 2021
d435833
Trying to fix wildcard syntax. Issue #6
joachimmarder Feb 15, 2021
fbe8e6b
Reverted previous chnage: Wildcards do not work. Issue #6
joachimmarder Feb 15, 2021
b7e1107
Merge pull request #1 from JAM-Software/master
Laurensvanrun Mar 10, 2021
6ce9086
Updated README.md
Laurensvanrun Apr 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
push:
branches: [ master ]
paths-ignore:
- 'README.md'
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: upload JAR file
uses: actions/upload-artifact@v1
with:
name: sonar-delphi-plugin.jar
path: target/sonar-delphi-plugin-1.0.7.jar
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

168 changes: 125 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,35 @@
[![Build Status](https://travis-ci.org/ekot1/SonarDelphi.svg?branch=master)](https://travis-ci.org/ekot1/SonarDelphi)
![Java CI with Maven](https://github.com/JAM-Software/SonarDelphi/workflows/Java%20CI%20with%20Maven/badge.svg)

# SonarQube Delphi

SonarQube Delphi
================
Is a SonarQube (http://www.sonarqube.org/) plugin and provides
* 49 Rules for Delphi
* TestCoverage using AQtime (license needed)
* TestCoverage using [DelphiCodeCoverage](https://github.com/DelphiCodeCoverage/DelphiCodeCoverage) or AQtime (license needed)
* Optional .html output for TestCoverage
* Unittests results using DUnitX

This is Plugin-Version 3.4 SonarQube 5.6.1(LTS) is needed.
It is is mainly an updated version of https://github.com/fabriciocolombo/sonar-delphi all credit goes to them.
I have hosted it here since the orignal developer isn't active anymore.
This is Plugin-Version 1.0 SonarQube 7.9(LTS) or higher is needed (tested with SonarQube 7.9.3 and 8.2.0)
It is is mainly an updated version of https://github.com/fabriciocolombo/sonar-delphi, all credit goes to them.

This plugin was originally a [Sabre Airline Solutions](http://www.sabreairlinesolutions.com/home/) donation.

License
---------------------------------------------------------------------------------------
The entire PLugin follows the GPL: https://github.com/SandroLuck/SonarDelphi/blob/master/src/LUCK_LICENSE.txt

Steps to Analyze a Delphi Project
------------------------------------------------

1. Install SonarQube Server (see [Setup and Upgrade](http://docs.sonarqube.org/display/SONAR/Setup+and+Upgrade) for more details). Check supported versions of the [latest release](https://github.com/fabriciocolombo/sonar-delphi/releases/latest) of the plugin.
2. Install one of the supported [Runners](#supported-runners) (see below) and be sure you can call it from the directory where you have your source code
3. Install [Delphi Plugin](https://github.com/SandroLuck/SonarDelphi/releases) (see [Installing a Plugin](http://docs.sonarqube.org/display/SONAR/Installing+a+Plugin) for more details).
NOTE: This only applies to SonarQube 5.6.1(LTS) and heigher. For older versions see [Delphi Plugin](https://github.com/fabriciocolombo/sonar-delphi/releases)
4. Check the sample project corresponding to your Runner to know which config file you need to create. You can find the samples in [sonar-delphi/samples](https://github.com/fabriciocolombo/sonar-delphi/tree/master/samples).
5. Run your Analyzer command from the project root dir
6. Follow the link provided at the end of the analysis to browse your project's quality in SonarQube UI (see: [Browsing SonarQube](http://docs.sonarqube.org/display/SONAR/Browsing+SonarQube))
## License

Supported Runners
----------------------------
To run an analysis of your Java project, you can use the following Runners:
The entire PLugin follows the GPL: https://github.com/mendrix/SonarDelphi/blob/master/src/LUCK_LICENSE.txt

* [SonarQube Scanner](http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner): recommended for all projects
* See https://github.com/fabriciocolombo/sonar-delphi for diffrent approacheds which have not been tested yet with 0.3.4
## Reporting Issues

Reporting Issues
----------------------------
SonarQube Delphi Plugin uses GitHub's integrated issue tracking system to record bugs and feature
requests. If you want to raise an issue, please follow the recommendations below:

* Before you log a bug, please [search the issue tracker](https://github.com/SandroLuck/SonarDelphi/issues)
* Before you log a bug, please [search the issue tracker](https://github.com/mendrix/SonarDelphi/issues)
to see if someone has already reported the problem.
* If the issue doesn't already exist, [create a new issue](https://github.com/SandroLuck/SonarDelphi/issues/new)
* If the issue doesn't already exist, [create a new issue](https://github.com/mendrix/SonarDelphi/issues)
* Please provide as much information as possible with the issue report, we like to know
the version of SonarQube Delphi Plugin that you are using, as well as the SonarQube version.
* If possible try to create a test-case or project that replicates the issue.

Implemented Features
------------------------------------------
## Implemented Features

* Counting lines of code, statements, number of files
* Counting number of classes, number of packages, methods, accessors
Expand All @@ -67,31 +48,132 @@ Implemented Features
* Unused files recognition
* Unused functions
* Unused procedures
(Optional with AQtime)
* Coverage using AQtime
(Optional with AQtime and DelphiCodeCoverage)
* Coverage using AQtime or DelphiCodeCoverage
* Sufficient Coverage on new Code
(Optional with DUnit)
* Test results

Code Assumptions
----------------------------------
# Steps to Analyze a Delphi Project

1. Install SonarQube Server (see [Setup and Upgrade](http://docs.sonarqube.org/display/SONAR/Setup+and+Upgrade) for more details). Check supported versions of the [latest release](https://github.com/mendrix/SonarDelphi/releases) of the plugin.
2. Install one of the supported [Runners](#supported-runners) (see below) and be sure you can call it from the directory where you have your source code
3. Install [Delphi Plugin](https://github.com/mendrix/SonarDelphi/releases) (see [Installing a Plugin](http://docs.sonarqube.org/display/SONAR/Installing+a+Plugin) for more details).
4. Check the sample project corresponding to your Runner to know which config file you need to create. You can find the samples in [sonar-delphi/samples](https://github.com/mendrix/SonarDelphi/tree/master/samples).
5. Run your Analyzer command from the project root dir
6. Follow the link provided at the end of the analysis to browse your project's quality in SonarQube UI (see: [Browsing SonarQube](http://docs.sonarqube.org/display/SONAR/Browsing+SonarQube))

## Supported Runners

To run an analysis of your Java project, you can use the following Runners:

* [SonarQube Scanner](http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner): recommended for all projects

## Code Assumptions

* Grammar is NOT case insensitive, but Delphi code is. Plugin deals with it by DelphiSourceSanitizer class, which feeds ANTLR parser lowercase characters (the "LA" method)
* Number of classes includes: classes, records
* Directory is count as a package. Number of packages equals number of directories.
* Preprocessor definitions between {$if xxx} and {$ifend} are removed (DefineResolver class).
* Sources imported to SonarQube are parsed through IncludeResolver class. It means, that the source will be lowercased and unknown preprocessor definitions will be cut out.

CodeCoverage
-------------------------------
I am very sorry but I can't release the CodeCoverage solution I used so if you want CodeCoverage please refer to [latest release](https://github.com/fabriciocolombo/sonar-delphi/releases/latest)
## CodeCoverage and unit testing

CodeCoverage can be done through the [DelphiCodeCoverage tool](https://github.com/DelphiCodeCoverage/DelphiCodeCoverage). Use

CodeCoverage.exe -xml -xmllines

to create a XML output that can be importeded through this plugin. Therefore you have to edit your sonar project properties:

sonar.delphi.codecoverage.tool=dcc
sonar.delphi.codecoverage.report=Test/CoverageResults/CodeCoverage_Summary.xml

### Unittests with DUnit

To import the testresults from DUnit, you have to use the [DUnit extension] (https://github.com/mendrix/dunit-extension) and use the supplied runner (it is not necessary to change your test classes to TTestCaseExtension).

ExitCode := TTestRunnerUtils.RunRegisteredTests;

This will run your tests with GUI if no parameters are given. With the parameter `-xml` the tool will create a XML output that is compatible with JUnit for SonarQube. With `-output` your can specify the output directory

MyTester.exe -xml -output <outputdirectory>

To import these test results, add the following line to your sonar project properties:

sonar.junit.reportsPath=TestResults

You also have to specify where the plugin can find your testfiles. It is important that the sourcefiles from your tests are EXCLUDED in your sources directory.

sonar.exclusions=MyTestFiles/*
sonar.tests=MyTestFiles

### Unittests with DUnitX

It is also possible to import results from [DUnitX](http://docwiki.embarcadero.com/RADStudio/Rio/en/DUnitX_Overview). Therefore you have to add the file

DUnitX.Loggers.XML.SonarQube.pas

to your DUnitX project. Then change the .dpr of your application and add functionality for a sources directory (this is used to find the correct .pas file corresponding to the Delphi unit of the unittest):

TOptionsRegistry.RegisterOption<String>('sources', 's', 'Specify a file with on each line a directory where the PAS-files of the unittests can be found.', procedure (AString: String) begin
LSourcesDir := AString;
end);
sqLogger := TDUnitXXMLSonarQubeFileLogger.Create(LSourcesDir, TDUnitX.Options.XMLOutputFile);
runner.AddLogger(sqLogger);

To import the resulting XML file, add the following line to your sonar project properties:

sonar.testExecutionReportPaths=Test/TEST-dunitx-sqresults.xml

### Unittests with code coverage example

To have both codecoverage and unittests results for SonarQube, you have to combine above options. For example:

CodeCoverage.exe -e MyTester.exe -m MyTester.map -a ^^-xml^^ ^^-output TestResults^^ -ife -spf sourcedirs.txt -uf unitstotest.txt -od CoverageResults\ -html -xml -xmllines

# How to build the plugin

## Prerequisites

To build a plugin, you need Java 8 and Maven 3.1 (or greater).
- [JDK](https://jdk.java.net/)
- [Maven](https://maven.apache.org/)

## Compile and test

mvn compile
mvn test

### Package as plugin

mvn package

Now you can copy the plugin from the ```/target/``` directory to the SonarQube plugin directory.

### Importing into Eclipse

Importing into Eclipse
-------------------------------
First run the eclipse maven goal:

mvn eclipse:eclipse

The project can then be imported into Eclipse using File -> Import and then selecting General -> Existing Projects into Workspace.

Importing into Intellij
-------------------------------
### Importing into Intellij

Simply open the pom.xml in Intellij should solve most dependecies by itself.

# How to develop and debug the plugin

SonarQube has great documentation about [developing a plugin](https://docs.sonarqube.org/latest/extend/developing-plugin/). To debug this plugin with the SonarQube scanner you to just set the following environment variable (on Windows):

SET SONAR_SCANNER_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000"

Now you attach your Eclipse (or other) debugger to port 8000 to start debugging.

## Changing the grammar with ANLTRWorks

The plugin uses an ANTLR3 grammar to parse the Delphi language. The grammar definition can be found in **/src/main/antlr3/org/sonar/plugins/delphi/antlr/delphi.g**. An easy way to check and modify this grammar is using [ANTLRWorks](https://www.antlr3.org/works/). Here you can test your grammar on new files and implement new language definitions.

After successfully changing and testing the Delphi.g grammar you have to generate the new parser code (menu Generate, option Generate Code). Now copy the files **DelphiLexer.java** and **DelphiParser.java** from **/src/main/antlr3/org/sonar/plugins/delphi/antlr/output/** to **/src/main/java/org/sonar/plugins/delphi/antlr/** and (re)build the plugin.

Note: it is important to make sure your new grammar changes are also tested. If you only have to make sure that they can be parsed without errors, you can add your new language features to one of the existing grammar files in **/src/main/java/org/sonar/plugins/delphi/antlr** (the newest is **GrammarTest2020.pas**).
28 changes: 20 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


<artifactId>sonar-delphi-plugin</artifactId>
<version>0.3.4</version>
<version>1.0.7</version>
<groupId>org.delphi.plugin</groupId>
<name>Sonar Delphi Plugin</name>
<description>Enables analysis of Delphi projects.</description>
Expand All @@ -30,6 +30,14 @@
<role>developer</role>
</roles>
</developer>
<developer>
<id>mendrix</id>
<email>L.vanRun@mendrix.nl</email>
<name>Laurens van Run</name>
<roles>
<role>developer</role>
</roles>
</developer>
<developer>
<id>pk</id>
<email>przemyslaw.kociolek@sabre.com</email>
Expand Down Expand Up @@ -61,17 +69,17 @@

<issueManagement>
<system>GitHub</system>
<url>https://github.com/fabriciocolombo/sonar-delphi/issues</url>
<url>https://github.com/JAM-Software/sonar-delphi/issues</url>
</issueManagement>
<ciManagement>
<system>Travis</system>
<url>https://travis-ci.org/fabriciocolombo/sonar-delphi</url>
<system>GitHub</system>
<url>https://github.com/JAM-Software/SonarDelphi/actions</url>
</ciManagement>

<properties>
<!--Version Fields-->
<sonarQubeMinVersion>6.7</sonarQubeMinVersion>
<sonar.version>6.7</sonar.version>
<sonarQubeMinVersion>7.9</sonarQubeMinVersion>
<sonar.version>7.9</sonar.version>
<sonarcobertura.version>1.4</sonarcobertura.version>
<antlr-runtime.version>3.4</antlr-runtime.version>
<slf4j.version>1.7.5</slf4j.version>
Expand Down Expand Up @@ -165,7 +173,6 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand All @@ -188,6 +195,11 @@
<version>24.0-jre</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
</dependencies>


Expand Down Expand Up @@ -248,4 +260,4 @@
</plugins>
</build>

</project>
</project>
2 changes: 1 addition & 1 deletion sonar-delphi-plugin.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.sonarsource.sonarqube:sonar-plugin-api:6.7" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.sonarsource.sonarqube:sonar-plugin-api:7.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.codehaus.woodstox:woodstox-core-lgpl:4.4.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.xml.stream:stax-api:1.0-2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.codehaus.woodstox:stax2-api:3.1.4" level="project" />
Expand Down
Loading