Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit c41115c

Browse files
lyrchshakedlokits
authored andcommitted
6.7 dev (#9)
* Added l10n properties from 6.2 sonar * Fixed about page locales for sonar v6.2 * Adjusted deps and eliminated original locales file Once I've removed sonar-batch artifact I do not longer need `core.properties` to get locales work when use this plugin in SQ 6.2 * Testing branch against SonarQube v6.1 * Begin work to update plugin for SonarQube 6.7 - Updated dependencies to work with SonarQube 6.7 - Removed Colorizer because it relies upon libraries that have been removed. * Fix RubyFile and its tests for SonarQube 6.7 - Update Qualifiers to use current idenfiers - Remove use of deprecated Project class - Use TestInputFileBuilder to build files for testing - Remove commented code * Fix RubyPackage and its tests for SonarQube 6.7 - Update Qualifiers to use the updated identifier. * Update SimpleCovRcovSensor and its tests for SonarQube 6.7 - Remove unused code - Correctly implement 6.7 interface - Update tests to use new libraries - Update tests to test the updated interface implementation * Update tests to use new libraries for SonarQube 6.7 * Update RubySensor and tests for SonarQube 6.7 - Use new libaries and interfaces for 6.7 - Update test with new libraries - Needed to remove the test for execute() because EasyMock does not work with the return type by default - Information on how to fix the test here: - https://stackoverflow.com/q/2667172 - https://stackoverflow.com/q/7204829 * Update RubySensor and tests for SonarQube 6.7 - Use new libaries and interfaces for 6.7 - Update test with new libraries - Needed to change the test for execute() because the underlying library for saving metrics has changed. * Update RubocopSensorTest for SonarQube 6.7 - Update test with new libraries * Updated the compose version and added a semaphore delay to the sonarqube instance (#11) * Update README.md * Fixed version By semantic versioning 2.0, minor and patch digits should be reset after major update * Update README.md * Address review comments - Remove commented code - Add docstring - Remove development debug statement
1 parent 2ace27f commit c41115c

22 files changed

+140
-210
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jdk:
88

99
# install docker compose
1010
env:
11-
COMPOSE_VERSION: 1.11.2
11+
COMPOSE_VERSION: 1.19.0
1212
before_install:
1313
- curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
1414
- chmod +x docker-compose
@@ -22,6 +22,7 @@ before_script:
2222

2323
# run unit tests and integration tests
2424
script:
25+
- while [[ "$(docker-compose logs sonarqube | grep -c 'SonarQube is up')" -ne 1 ]]; do sleep 1; done
2526
- mvn test
2627
- ./run_test.sh
2728

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SonarQube Ruby Plugin [![Build Status](https://travis-ci.org/shakedlokits/ruby-s
22
=================
33

44
## Description
5-
This plugin enables publishing static and dynamic analysis reports of Ruby projects onto SonarQube 5.6.3+
5+
This plugin enables publishing static and dynamic analysis reports of Ruby projects onto SonarQube 6.7+
66

77
The plugin currently supports the following services:
88
* Lines of code, Number of classes, Comment precentage
@@ -11,7 +11,7 @@ The plugin currently supports the following services:
1111
* Code Coverage (line coverage)
1212
* Coding Style Violations
1313

14-
It relies on standardized external tools: [SimpleCov](https://github.com/colszowka/simplecov), [SimpleCov-RCov](https://github.com/fguillen/simplecov-rcov) and [Metric_Fu](https://github.com/metricfu/metric_fu/) in order to make the analysis and report the metrics which are then in turn published to SonarQube.
14+
It relies on standardized external tools: [SimpleCov](https://github.com/colszowka/simplecov), [SimpleCov-RCov](https://github.com/fguillen/simplecov-rcov), [Metric_Fu](https://github.com/metricfu/metric_fu/) and [Rubocop](https://github.com/bbatsov/rubocop) in order to make the analysis and report the metrics which are then in turn published to SonarQube.
1515

1616
## Install
1717
1. Run `mvn install` to produce the `target/sonar-ruby-plugin-VERSION.jar` plugin file
@@ -45,8 +45,7 @@ end
4545
**Important:** Do not change the output directory for the simplecov-rcov report, leave it as default, or code coverage will not be reported.
4646

4747
##### Code Complexity
48-
In order for the plugin to report on code complexity, [metric_fu](https://github.com/metricfu/metric_fu/) needs to be ran against the ruby project,
49-
which will generate a metric report. Please see the [gem's homepage](https://github.com/metricfu/metric_fu/) for installation and usage instructions.
48+
In order for the plugin to report on code complexity, [metric_fu](https://github.com/metricfu/metric_fu/) needs to be ran against the ruby project, which will generate a metric report. Please see the [gem's homepage](https://github.com/metricfu/metric_fu/) for installation and usage instructions.
5049

5150
**Important:** We recommend using metric_fu by running `metric_fu -r --no-flog --no-flay --no-roodi --no-open` which would analyze and report all of the metrics supported by the plugin. Such as Saikuro/Cane coverage, Cane issues, Hostpots, Code smells and more..
5251

@@ -87,7 +86,7 @@ Use the `sonar.ruby.coverage.testSuites` property to set the correct tests aggre
8786

8887
**Important:** We recommend run rubocop as such `rubocop -f json -o tmp/rubocop/report.json`.
8988

90-
##Future Plans
89+
## Future Plans
9190
* Code Duplication
9291
* Structural Analysis
9392
* Code Debt
@@ -101,7 +100,7 @@ We referenced the [Java Sonar Plugin](https://github.com/SonarSource/sonar-java)
101100

102101
## Tool Versions
103102
This plugin has been tested with the following dependency versions:
104-
* [SonarQube](http://www.sonarqube.org/downloads/) 5.6.3 LTS
103+
* [SonarQube](http://www.sonarqube.org/downloads/) 6.7
105104
* SonarQube Runner 2.7 (or newer)
106105
* metric_fu gem version 4.12.0 (latest at time of edit)
107106
* simplecov 0.12.0
@@ -111,6 +110,7 @@ This plugin has been tested with the following dependency versions:
111110
## Authors
112111
* [Brian Clifton](https://github.com/bsclifton)
113112
* [Shaked Lokits](https://github.com/shakedlokits) - *Maintainer*
113+
* [Jared Wilkerson](https://github.com/lyrch)
114114
* [Serge Gernyak](https://github.com/sergio1990)
115115
* [Will Greenway](https://api.github.com/users/wpgreenway)
116116
* [Greg Allen](https://api.github.com/users/ggallen)

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sonarqube:
2-
image: sonarqube:5.6.3
2+
image: sonarqube:6.7
33
volumes:
44
- ./target:/opt/sonarqube/extensions/plugins
55
ports:

pom.xml

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<groupId>com.godaddy.sonar</groupId>
77
<artifactId>sonar-ruby-plugin</artifactId>
88
<packaging>sonar-plugin</packaging>
9-
<version>1.4.2</version>
9+
<version>2.0.0</version>
1010

1111
<name>Sonar Ruby Plugin</name>
1212
<description>Plugin to report ruby code coverage into sonar</description>
1313

1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16-
<sonar.buildVersion>5.5</sonar.buildVersion>
16+
<sonar.buildVersion>6.7</sonar.buildVersion>
1717
<!--FIXME: update batch version to build version once available-->
1818
<sonar.sonarBatchVersion>5.4</sonar.sonarBatchVersion>
1919
<jdk.min.version>1.6</jdk.min.version>
@@ -33,31 +33,16 @@
3333
<version>${sonar.buildVersion}</version>
3434
<scope>provided</scope>
3535
</dependency>
36-
<dependency>
37-
<groupId>org.sonarsource.sonarqube</groupId>
38-
<artifactId>sonar-batch</artifactId>
39-
<version>${sonar.sonarBatchVersion}</version>
40-
<!--FIXME:HACK: using exclusion pattens to resolve this https://groups.google.com/forum/#!msg/sonarqube/R8jk9MK9bGI/gOn5uhk9GgAJ-->
41-
<exclusions>
42-
<exclusion>
43-
<groupId>com.google.guava</groupId>
44-
<artifactId>guava</artifactId>
45-
</exclusion>
46-
<exclusion>
47-
<groupId>commons-lang</groupId>
48-
<artifactId>commons-lang</artifactId>
49-
</exclusion>
50-
<exclusion>
51-
<groupId>commons-io</groupId>
52-
<artifactId>commons-io</artifactId>
53-
</exclusion>
54-
</exclusions>
55-
</dependency>
5636
<dependency>
5737
<groupId>org.jruby</groupId>
5838
<artifactId>jruby-complete</artifactId>
5939
<version>1.7.20</version>
6040
</dependency>
41+
<dependency>
42+
<groupId>com.google.code.gson</groupId>
43+
<artifactId>gson</artifactId>
44+
<version>2.8.0</version>
45+
</dependency>
6146
<dependency>
6247
<groupId>org.sonarsource.sslr-squid-bridge</groupId>
6348
<artifactId>sslr-squid-bridge</artifactId>

run_test.sh

100644100755
File mode changed.

src/main/java/com/godaddy/sonar/ruby/RubyPlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.godaddy.sonar.ruby;
22

33
import com.godaddy.sonar.ruby.core.Ruby;
4-
import com.godaddy.sonar.ruby.core.RubySourceCodeColorizer;
54
import com.godaddy.sonar.ruby.core.profiles.SonarWayProfile;
65
import com.godaddy.sonar.ruby.metricfu.*;
76

@@ -59,7 +58,6 @@ public List<Object> getExtensions() {
5958
extensions.add(MetricfuYamlParser.class);
6059
extensions.add(RubocopSensor.class);
6160
extensions.add(DefaultReportJsonParser.class);
62-
extensions.add(RubySourceCodeColorizer.class);
6361
extensions.add(RubySensor.class);
6462
extensions.add(MetricfuComplexitySensor.class);
6563
// extensions.add(MetricfuDuplicationSensor.class);

src/main/java/com/godaddy/sonar/ruby/RubySensor.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import com.godaddy.sonar.ruby.core.RubyRecognizer;
55
import com.godaddy.sonar.ruby.parsers.CommentCountParser;
66
import com.google.common.collect.Lists;
7+
import jnr.ffi.annotations.In;
78
import org.apache.commons.io.FileUtils;
89
import org.apache.commons.io.IOUtils;
9-
import org.sonar.api.batch.Sensor;
10-
import org.sonar.api.batch.SensorContext;
10+
import org.sonar.api.batch.sensor.Sensor;
11+
import org.sonar.api.batch.sensor.SensorContext;
1112
import org.sonar.api.batch.fs.FileSystem;
1213
import org.sonar.api.batch.fs.InputFile;
14+
import org.sonar.api.batch.sensor.SensorDescriptor;
1315
import org.sonar.api.config.Settings;
1416
import org.sonar.api.measures.CoreMetrics;
1517
import org.sonar.api.resources.Project;
@@ -27,30 +29,39 @@ public RubySensor(Settings settings, FileSystem fileSystem) {
2729
this.fileSystem = fileSystem;
2830
}
2931

30-
@Override
3132
public boolean shouldExecuteOnProject(Project project) {
3233
// This sensor is executed only when there are Ruby files
3334
return fileSystem.hasFiles(fileSystem.predicates().hasLanguage(Ruby.KEY));
3435
}
3536

36-
public void analyse(Project project, SensorContext context) {
37-
computeBaseMetrics(context, project);
37+
public void describe(SensorDescriptor descriptor){
38+
descriptor.onlyOnLanguage(Ruby.KEY).name("Ruby Sensor").onlyOnFileType(InputFile.Type.MAIN);
39+
}
40+
41+
public void execute(SensorContext context) {
42+
computeBaseMetrics(context);
3843
}
3944

40-
protected void computeBaseMetrics(SensorContext sensorContext, Project project) {
45+
/**
46+
* Analysis helper function used on a Ruby project compute and save the folloing metrics
47+
* into the SonarQube system: NCLOC, COMMENT_LINES, FILES, CLASSES
48+
*
49+
* @param sensorContext the project sensor context
50+
*/
51+
protected void computeBaseMetrics(SensorContext sensorContext) {
4152
Reader reader = null;
4253
List<InputFile> inputFiles = Lists.newArrayList(fileSystem.inputFiles(fileSystem.predicates().hasLanguage(Ruby.KEY)));
43-
4454
for (InputFile inputFile : inputFiles) {
4555
try {
4656
reader = new StringReader(FileUtils.readFileToString(inputFile.file(), fileSystem.encoding().name()));
4757
Source source = new Source(reader, new RubyRecognizer());
48-
sensorContext.saveMeasure(inputFile, CoreMetrics.NCLOC, (double) source.getMeasure(Metric.LINES_OF_CODE));
58+
59+
sensorContext.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.NCLOC).withValue(source.getMeasure((Metric.LINES_OF_CODE))).save();
4960

5061
int numCommentLines = CommentCountParser.countLinesOfComment(inputFile.file());
51-
sensorContext.saveMeasure(inputFile, CoreMetrics.COMMENT_LINES, (double) numCommentLines);
52-
sensorContext.saveMeasure(inputFile, CoreMetrics.FILES, 1.0);
53-
sensorContext.saveMeasure(inputFile, CoreMetrics.CLASSES, 1.0);
62+
sensorContext.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.COMMENT_LINES).withValue(numCommentLines).save();
63+
sensorContext.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.FILES).withValue(1).save();
64+
sensorContext.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.CLASSES).withValue(1).save();
5465
} catch (Exception e) {
5566
throw new IllegalStateException("Error computing base metrics for project.", e);
5667
} finally {

src/main/java/com/godaddy/sonar/ruby/core/RubyFile.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public String getScope() {
8888
}
8989

9090
public String getQualifier() {
91-
return Qualifiers.CLASS;
91+
return Qualifiers.FILE;
9292
}
9393

9494
public boolean matchFilePattern(String antPattern) {
@@ -113,11 +113,4 @@ public String toString() {
113113
+ ", getKey()=" + getKey() + ", getId()=" + getId() + ", getPath()=" + getPath() + ", getEffectiveKey()="
114114
+ getEffectiveKey() + ", isExcluded()=" + isExcluded() + "]\n";
115115
}
116-
117-
// @Override
118-
// public String toString()
119-
// {
120-
// return new ToStringBuilder(this).append("key", getKey()).append("package", packageKey).append("longName", longName).toString();
121-
// }
122-
123116
}

src/main/java/com/godaddy/sonar/ruby/core/RubyPackage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public String getScope() {
5656

5757
@Override
5858
public String getQualifier() {
59-
return Qualifiers.PACKAGE;
59+
return Qualifiers.PROJECT;
6060
}
6161
}

src/main/java/com/godaddy/sonar/ruby/core/RubySourceCodeColorizer.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)