Skip to content
This repository has been archived by the owner on Jul 8, 2019. It is now read-only.

Commit

Permalink
SonarQube 6.* support, and fixing various minor Linux issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablissimo committed Oct 30, 2016
1 parent cc8c4be commit 1c2ac3a
Show file tree
Hide file tree
Showing 28 changed files with 1,101 additions and 1,139 deletions.
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
language: java
jdk:
- oraclejdk8

addons:
artifacts:
s3_region: "us-west-2"
paths:
- $(ls ./target/*.jar | tr "\n" ":")
target_paths: builds/$TRAVIS_BRANCH/$TRAVIS_BUILD_NUMBER

after_success:
- mvn clean cobertura:cobertura coveralls:report
- mvn cobertura:cobertura coveralls:report
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SonarQube plugin for TypeScript files
##Demos

A live deployed demo hitting a few large open-source TypeScript projects can be found here:
https://sonar.pablissimo.com
[https://sonar.pablissimo.com](https://sonar.pablissimo.com).

Suggestions for more projects (or ones with easy-to-gather code coverage info) appreciated!

Expand All @@ -26,44 +26,38 @@ Suggestions for more projects (or ones with easy-to-gather code coverage info) a

##Overview

This is a **not even alpha-level yet** SonarQube plugin for analysing projects with TypeScript content that supports:
This is plugin for SonarQube 5.6+ for analysing projects with TypeScript content that supports:
* TsLint for code quality information
* Importing LCOV files for unit test coverage information
* NCLOC metric generation

It's unfinished in the following respects:
* Plug-in code quality needs improved
* Incomplete unit test coverage of the plugin
* Exceptionally little error handling
* No support for code duplication metrics

It's presented only for the interested, and the brave.

###Breaking change in 0.2###
To more easily support changes to the rules TsLint understands, the plugin no longer generates a TsLint configuration file for you but instead you must now specify your own using the sonar.ts.tslintconfigpath configuration property (either in the web interface, or in your sonar-project.properties file).

##Requirements
* Java 1.7+
* SonarQube 4.4+ (may or may not work with others)
* Java 1.8+
* SonarQube 5.4 LTS+
* TsLint 2.4.0+

The plugin has so far *only been tested on Windows* and it'll be no surprise if it fails on Linux just now.

##Building
* Download the source
* Build with maven, *mvn clean && mvn install*

##Installation
* Install Node.js
* Install TsLint (2.4.0+) with *npm install -g tslint*
* Find the path to TsLint and copy it - will be similar to *C:\Users\\[Username]\AppData\Roaming\npm\node_modules\tslint\bin\tslint* on Windows
* Copy .jar file from target/ after build to SonarQube extensions folder
* Install TsLint (2.4.0+) with `npm install -g tslint`, or ensure it is installed locally against your project
* If you're installing globally, find the path to TsLint and copy it - will be similar to ```C:\Users\\[Username]\AppData\Roaming\npm\node_modules\tslint\bin\tslint``` on Windows
* Copy .jar file (from ```target/``` after build, or downloaded from [Releases page](https://github.com/Pablissimo/SonarTsPlugin/releases)) to SonarQube extensions folder
* Restart SonarQube server
* Browse to SonarQube web interface, login as Admin, hit up Settings
* Find the TypeScript tab, paste in the TsLint path
* Hit the Rules tab, then the TsLint rule set, then apply it to your project - alter rule activation as required
* Make sure you have a ```tslint.json``` file next to ```sonar-project.properties```, or specify its path using the ```sonar.ts.tslintconfigpath``` setting
* If LCOV data available, add *sonar.ts.lcov.reportpath=lcov.dat* to your sonar-project.properties file (replace lcov.dat with your lcov output, will be sought relative to the sonar-project.properties file)
* Run sonar-runner
* Run ```sonar-runner``` or ```sonar-scanner```
* TsLint rule breaches should be shown in the web view

##Configuration
Expand All @@ -87,7 +81,7 @@ The plugin has so far *only been tested on Windows* and it'll be no surprise if
</thead>
<tbody>
<tr><td>sonar.ts.tslintpath</td><td><b>Recommended</b></td><td>Path to the installed copy of TsLint to use - see note below</td></tr>
<tr><td>sonar.ts.tslintconfigpath</td><td><b>Mandatory</b></td><td>Path to the tslint.json file that configures the rules to be used in linting</td></tr>
<tr><td>sonar.ts.tslintconfigpath</td><td><b>Recommended</b></td><td>Path to the tslint.json file that configures the rules to be used in linting - see note below</td></tr>
<tr><td>sonar.ts.excludetypedefinitionfiles</td><td><b>Optional</b></td><td>Excludes .d.ts files from analysis, defaults to true</td></tr>
<tr><td>sonar.ts.forceZeroCoverage</td><td><b>Optional</b></td><td>Forces code coverage percentage to zero when no report is supplied, defaults to false</td></tr>
<tr><td>sonar.ts.ignoreNotFound</td><td><b>Optional</b></td><td>Don't set code coverage percentage to zero when file is not found in report, defaults to false</td></tr>
Expand All @@ -104,6 +98,8 @@ By default, SonarTsPlugin will look for a version of TsLint installed locally wi

If analysis is failing, run ```sonar-runner``` with the ```-X -e``` options for more diagnostic information, including a note of where the plugin is searching for ```tslint```. Bear in mind that if running on a build server, the account running the build will need access to the path to ```tslint```.

By default, SonarTsPlugin will look for a TsLint configuration file called tslint.json next to the sonar-project.properties file. You can override this using the ```sonar.ts.tslintconfigpath``` configuration setting if this isn't the case for your project.

## TsLint Custom Rules

To present custom TsLint rules in SonarQube analysis, you can provide a configuration that maps the TsLint rules from your `sonar.ts.tslintrulesdir`
Expand Down
48 changes: 38 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.pablissimo.sonar</groupId>
<artifactId>sonar-typescript-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>0.9-SNAPSHOT</version>
<version>0.94-SNAPSHOT</version>

<name>TypeScript</name>
<description>Analyse TypeScript projects</description>
Expand All @@ -29,7 +29,7 @@
<connection>scm:git:[email protected]:Pablissimo/SonarTsPlugin.git</connection>
<developerConnection>scm:git:[email protected]:Pablissimo/SonarTsPlugin.git</developerConnection>
<url>https://github.com/Pablissimo/SonarTsPlugin</url>
<tag>0.9</tag>
<tag>1.0</tag>
</scm>
<issueManagement>
<system>Github</system>
Expand All @@ -42,14 +42,15 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<sonar.buildVersion>4.4</sonar.buildVersion>
<jdk.min.version>1.7</jdk.min.version>

<sonar.buildVersion>5.6</sonar.buildVersion>
<jdk.min.version>1.8</jdk.min.version>
<sslr.version>1.21</sslr.version>
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.buildVersion}</version>
<scope>provided</scope>
Expand All @@ -60,14 +61,35 @@
<artifactId>gson</artifactId>
<version>2.3</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-testing-harness</artifactId>
<version>${sonar.buildVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sslr</groupId>
<artifactId>sslr-testing-harness</artifactId>
<version>${sslr.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -97,9 +119,9 @@
<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.3</version>
<version>1.16</version>
<extensions>true</extensions>
<configuration>
<pluginKey>typescript</pluginKey>
Expand All @@ -113,6 +135,12 @@
<configuration>
<source>${jdk.min.version}</source>
<target>${jdk.min.version}</target>

<showDeprecation>true</showDeprecation>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand All @@ -136,7 +164,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<version>2.7</version>
<configuration>
<formats>
<format>xml</format>
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/pablissimo/sonar/CombinedCoverageSensor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.pablissimo.sonar;

import java.util.Map;
import java.util.Set;

import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;

public class CombinedCoverageSensor implements Sensor {

protected LOCSensor getLOCSensor() {
return new LOCSensorImpl();
}

protected TsCoverageSensor getCoverageSensor() {
return new TsCoverageSensorImpl();
}

@Override
public void describe(SensorDescriptor descriptor) {
descriptor.name("Combined LCOV and LOC sensor");
descriptor.onlyOnLanguage(TypeScriptLanguage.LANGUAGE_KEY);
}

@Override
public void execute(SensorContext context) {
// First - LOC everything up, as we'll need LOC for uncovered lines metrics
Map<InputFile, Set<Integer>> nonCommentLinesByFile = getLOCSensor().execute(context);

// Now the LCOV pass can properly handle files that don't appear in
// configuration and set lines-to-cover values as required
getCoverageSensor().execute(context, nonCommentLinesByFile);
}

}
7 changes: 4 additions & 3 deletions src/main/java/com/pablissimo/sonar/LCOVParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import java.util.List;
import java.util.Map;

import org.sonar.api.measures.CoverageMeasuresBuilder;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.coverage.NewCoverage;

public interface LCOVParser {
Map<String, CoverageMeasuresBuilder> parseFile(File file);
Map<String, CoverageMeasuresBuilder> parse(List<String> lines);
Map<InputFile, NewCoverage> parseFile(File file);
Map<InputFile, NewCoverage> parse(List<String> lines);
}
Loading

0 comments on commit 1c2ac3a

Please sign in to comment.