Skip to content

Commit a6c4ba6

Browse files
committed
Extended readme
1 parent a8ee37c commit a6c4ba6

File tree

2 files changed

+72
-40
lines changed

2 files changed

+72
-40
lines changed

README.md

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Build Status](https://travis-ci.org/ekot1/SonarDelphi.svg?branch=master)](https://travis-ci.org/ekot1/SonarDelphi)
22

3-
SonarQube Delphi
4-
================
3+
# SonarQube Delphi
4+
55
Is a SonarQube (http://www.sonarqube.org/) plugin and provides
66
* 49 Rules for Delphi
77
* TestCoverage using DelphiCodeCoverage or AQtime (license needed)
@@ -14,30 +14,12 @@ I have hosted it here since the orignal developer isn't active anymore.
1414

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

17-
License
18-
---------------------------------------------------------------------------------------
19-
The entire PLugin follows the GPL: https://github.com/SandroLuck/SonarDelphi/blob/master/src/LUCK_LICENSE.txt
20-
21-
Steps to Analyze a Delphi Project
22-
------------------------------------------------
17+
## License
2318

24-
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.
25-
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
26-
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).
27-
NOTE: This only applies to SonarQube 7.9(LTS) and heigher. For older versions see [Delphi Plugin](https://github.com/fabriciocolombo/sonar-delphi/releases)
28-
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).
29-
5. Run your Analyzer command from the project root dir
30-
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))
31-
32-
Supported Runners
33-
----------------------------
34-
To run an analysis of your Java project, you can use the following Runners:
19+
The entire PLugin follows the GPL: https://github.com/SandroLuck/SonarDelphi/blob/master/src/LUCK_LICENSE.txt
3520

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

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

@@ -48,8 +30,7 @@ requests. If you want to raise an issue, please follow the recommendations below
4830
the version of SonarQube Delphi Plugin that you are using, as well as the SonarQube version.
4931
* If possible try to create a test-case or project that replicates the issue.
5032

51-
Implemented Features
52-
------------------------------------------
33+
## Implemented Features
5334

5435
* Counting lines of code, statements, number of files
5536
* Counting number of classes, number of packages, methods, accessors
@@ -74,17 +55,33 @@ Implemented Features
7455
(Optional with DUnit)
7556
* Test results
7657

77-
Code Assumptions
78-
----------------------------------
58+
# Steps to Analyze a Delphi Project
59+
60+
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.
61+
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
62+
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).
63+
NOTE: This only applies to SonarQube 7.9(LTS) and heigher. For older versions see [Delphi Plugin](https://github.com/fabriciocolombo/sonar-delphi/releases)
64+
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).
65+
5. Run your Analyzer command from the project root dir
66+
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))
67+
68+
## Supported Runners
69+
70+
To run an analysis of your Java project, you can use the following Runners:
71+
72+
* [SonarQube Scanner](http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner): recommended for all projects
73+
* See https://github.com/fabriciocolombo/sonar-delphi for diffrent approacheds which have not been tested yet with 0.3.4
74+
75+
## Code Assumptions
7976

8077
* 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)
8178
* Number of classes includes: classes, records
8279
* Directory is count as a package. Number of packages equals number of directories.
8380
* Preprocessor definitions between {$if xxx} and {$ifend} are removed (DefineResolver class).
8481
* 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.
8582

86-
CodeCoverage
87-
-------------------------------
83+
## CodeCoverage and unit testing
84+
8885
CodeCoverage can be done through the [DelphiCodeCoverage tool](https://sourceforge.net/p/delphicodecoverage/git/ci/master/tree/). Use
8986

9087
CodeCoverage.exe -xml -xmllines
@@ -94,8 +91,8 @@ to create a XML output that can be importeded through this plugin. Therefore you
9491
sonar.delphi.codecoverage.tool=dcc
9592
sonar.delphi.codecoverage.report=Test/CoverageResults/CodeCoverage_Summary.xml
9693

97-
Unittests with DUnit
98-
-------------------------------
94+
### Unittests with DUnit
95+
9996
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).
10097

10198
ExitCode := TTestRunnerUtils.RunRegisteredTests;
@@ -113,8 +110,8 @@ You also have to specify where the plugin can find your testfiles. It is importa
113110
sonar.exclusions=MyTestFiles/*
114111
sonar.tests=MyTestFiles
115112

116-
Unittests with DUnitX
117-
-------------------------------
113+
### Unittests with DUnitX
114+
118115
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
119116

120117
DUnitX.Loggers.XML.SonarQube.pas
@@ -131,20 +128,55 @@ To import the resulting XML file, add the following line to your sonar project p
131128

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

134-
Unittests with code coverage example
135-
-------------------------------
131+
### Unittests with code coverage example
132+
136133
To have both codecoverage and unittests results for SonarQube, you have to combine above options. For example:
137134

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

140-
Importing into Eclipse
141-
-------------------------------
137+
# How to build the plugin
138+
139+
## Prerequisites
140+
141+
To build a plugin, you need Java 8 and Maven 3.1 (or greater).
142+
- [JDK](https://jdk.java.net/)
143+
- [Maven](https://maven.apache.org/)
144+
145+
## Compile and test
146+
147+
mvn compile
148+
mvn test
149+
150+
### Package as plugin
151+
152+
mvn package
153+
154+
Now you can copy the plugin from the ```/target/``` directory to the SonarQube plugin directory.
155+
156+
### Importing into Eclipse
157+
142158
First run the eclipse maven goal:
143159

144160
mvn eclipse:eclipse
145161

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

148-
Importing into Intellij
149-
-------------------------------
164+
### Importing into Intellij
165+
150166
Simply open the pom.xml in Intellij should solve most dependecies by itself.
167+
168+
# How to develop and debug the plugin
169+
170+
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):
171+
172+
SET SONAR_SCANNER_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000"
173+
174+
Now you attach your Eclipse (or other) debugger to port 8000 to start debugging.
175+
176+
## Changing the grammar with ANLTRWorks
177+
178+
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.
179+
180+
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.
181+
182+
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**).

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
<artifactId>sonar-delphi-plugin</artifactId>
8-
<version>1.0.1</version>
8+
<version>1.0.2</version>
99
<groupId>org.delphi.plugin</groupId>
1010
<name>Sonar Delphi Plugin</name>
1111
<description>Enables analysis of Delphi projects.</description>

0 commit comments

Comments
 (0)