Skip to content

Commit

Permalink
First attempt at the manual merge for #1 / #4. This should be fairly …
Browse files Browse the repository at this point in the history
…close.
  • Loading branch information
bsclifton committed Sep 20, 2015
1 parent a853e16 commit 3620194
Show file tree
Hide file tree
Showing 20 changed files with 474 additions and 667 deletions.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Required metadata
sonar.projectKey=ruby-sonar-plugin-gd
sonar.projectName=Ruby Sonar Plugin
sonar.projectVersion=1.0.1
sonar.projectVersion=1.1.0

# Comma-separated paths to directories with sources (required)
sonar.sources=src/main/java
Expand Down
18 changes: 1 addition & 17 deletions src/main/java/com/godaddy/sonar/ruby/RubyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.godaddy.sonar.ruby.core.profiles.SonarWayProfile;
import com.godaddy.sonar.ruby.metricfu.CaneRulesRepository;
import com.godaddy.sonar.ruby.metricfu.MetricfuComplexitySensor;
import com.godaddy.sonar.ruby.metricfu.MetricfuComplexityYamlParserImpl;
import com.godaddy.sonar.ruby.metricfu.MetricfuDuplicationSensor;
import com.godaddy.sonar.ruby.metricfu.MetricfuIssueSensor;
import com.godaddy.sonar.ruby.metricfu.MetricfuYamlParser;
Expand All @@ -33,7 +32,6 @@ public final class RubyPlugin extends SonarPlugin
{
public static final String SIMPLECOVRCOV_REPORT_PATH_PROPERTY = "sonar.simplecovrcov.reportPath";
public static final String METRICFU_REPORT_PATH_PROPERTY = "sonar.metricfu.reportPath";
public static final String METRICFU_COMPLEXITY_METRIC_PROPERTY = "sonar.metricfu.complexityMetric";

public static final String KEY_REPOSITORY_CANE = "cane";
public static final String NAME_REPOSITORY_CANE = "Cane";
Expand All @@ -50,7 +48,7 @@ public List<Object> getExtensions()
extensions.add(Ruby.class);
extensions.add(SimpleCovRcovSensor.class);
extensions.add(SimpleCovRcovJsonParserImpl.class);
extensions.add(MetricfuComplexityYamlParserImpl.class);
extensions.add(MetricfuYamlParser.class);
extensions.add(RubySourceCodeColorizer.class);
extensions.add(RubySensor.class);
extensions.add(MetricfuComplexitySensor.class);
Expand Down Expand Up @@ -83,20 +81,6 @@ public List<Object> getExtensions()
.build();
extensions.add(simplecovrcovReportPath);

List<String> options = Arrays.asList("Saikuro", "Cane");

PropertyDefinition ComplexityMetric = PropertyDefinition.builder(METRICFU_COMPLEXITY_METRIC_PROPERTY)
.category(CoreProperties.CATEGORY_CODE_COVERAGE)
.subCategory("Ruby Coverage")
.name("MetricFu Complexity Metric")
.description("Type of complexity, Saikuro or Cane")
.defaultValue("Saikuro")
.onQualifiers(Qualifiers.PROJECT)
.type(PropertyType.SINGLE_SELECT_LIST)
.options(options)
.build();
extensions.add(ComplexityMetric);

return extensions;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.godaddy.sonar.ruby.metricfu;

public class CaneCommentViolation extends CaneViolation {
private int line;
private String className;

public CaneCommentViolation(String file, int line, String className) {
Expand All @@ -17,14 +16,6 @@ public String getKey() {
return "CommentViolation";
}

public int getLine() {
return line;
}

public void setLine(int line) {
this.line = line;
}

public String getClassName() {
return className;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.godaddy.sonar.ruby.metricfu;

public class CaneLineStyleViolation extends CaneViolation {
private int line;
private String description;
private String key = "UnknownViolation";

Expand All @@ -18,14 +17,6 @@ public String getKey() {
return key;
}

public int getLine() {
return line;
}

public void setLine(int line) {
this.line = line;
}

public String getDescription() {
return description;
}
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/com/godaddy/sonar/ruby/metricfu/CaneViolation.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.godaddy.sonar.ruby.metricfu;

public abstract class CaneViolation {
private String file;

public abstract class CaneViolation extends MetricBase {
public CaneViolation(String file) {
this.file = file;
}
Expand All @@ -11,14 +9,6 @@ public CaneViolation() {
}

public abstract String getKey();

public String getFile() {
return file;
}

public void setFile(String file) {
this.file = file;
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import java.util.ArrayList;

public class FlayReason {
public class FlayReason extends MetricBase {

public class Match {
private String file;
private Integer start;
private Integer lines;

Expand All @@ -23,12 +22,6 @@ public Match(String file) {
this(file, 1, 1);
}

public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public Integer getStartLine() {
return start;
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/godaddy/sonar/ruby/metricfu/MetricBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.godaddy.sonar.ruby.metricfu;

public class MetricBase {
protected int line;
protected String file;

public MetricBase() {
}

public int getComplexity() {
return complexity;
}

public void setComplexity(int complexity) {
this.complexity = complexity;
}

public int getLine() {
return line;
}

public void setLine(int line) {
this.line = line;
}

public String getFile() {
return file;
}

public void setFile(String file) {
this.file = file;
}

@Override
public String toString() {
return "file: " + file + " line: " + line;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,29 @@

public class MetricfuComplexitySensor implements Sensor
{
private static final Logger LOG = LoggerFactory
.getLogger(MetricfuComplexitySensor.class);
private static final Logger LOG = LoggerFactory.getLogger(MetricfuComplexitySensor.class);

private MetricfuComplexityYamlParser metricfuComplexityYamlParser;
private Settings settings;
private FileSystem fs;
private MetricfuYamlParser metricfuYamlParser;
private Settings settings;
private FileSystem fs;

private static final Number[] FILES_DISTRIB_BOTTOM_LIMITS = { 0, 5, 10, 20, 30, 60, 90 };
private static final Number[] FUNCTIONS_DISTRIB_BOTTOM_LIMITS = { 1, 2, 4, 6, 8, 10, 12, 20, 30 };
private static final Number[] FILES_DISTRIB_BOTTOM_LIMITS = { 0, 5, 10, 20, 30, 60, 90 };
private static final Number[] FUNCTIONS_DISTRIB_BOTTOM_LIMITS = { 1, 2, 4, 6, 8, 10, 12, 20, 30 };

private String reportPath = "tmp/metric_fu/report.yml";
private PathResolver pathResolver;
private String reportPath = "tmp/metric_fu/report.yml";
private PathResolver pathResolver;

public MetricfuComplexitySensor(Settings settings, FileSystem fs,
PathResolver pathResolver,
MetricfuComplexityYamlParser metricfuComplexityYamlParser) {
MetricfuYamlParser metricfuYamlParser) {

this.settings = settings;
this.fs = fs;
this.metricfuComplexityYamlParser = metricfuComplexityYamlParser;
this.metricfuYamlParser = metricfuYamlParser;
this.pathResolver = pathResolver;

//TODO: this needs to be respected by all sensors
//because of the merge, the logic has moved to MetricfuYamlParser
String reportpath_prop = settings.getString(RubyPlugin.METRICFU_REPORT_PATH_PROPERTY);
if (null != reportpath_prop) {
this.reportPath = reportpath_prop;
Expand Down Expand Up @@ -77,13 +80,11 @@ public void analyse(Project project, SensorContext context)
}
}

private void analyzeFile(InputFile inputFile, SensorContext sensorContext, File resultsFile)
throws IOException
private void analyzeFile(File file, List<File> sourceDirs, SensorContext sensorContext) throws IOException
{
LOG.info("functions are set");
String complexityType = settings.getString(RubyPlugin.METRICFU_COMPLEXITY_METRIC_PROPERTY);
List<RubyFunction> functions = metricfuComplexityYamlParser.parseFunctions(inputFile.file().getName(), resultsFile,
complexityType);
List<SaikuroComplexity> functions = metricfuYamlParser.parseSaikuro(resource.getName());

// if function list is empty, then return, do not compute any complexity
// on that file
Expand All @@ -95,23 +96,20 @@ private void analyzeFile(InputFile inputFile, SensorContext sensorContext, File
// COMPLEXITY
LOG.info("COMPLEXITY are set" + functions.toString());
int fileComplexity = 0;
for (RubyFunction function : functions)
for (SaikuroComplexity function : functions)
{
fileComplexity += function.getComplexity();
LOG.info("File complexity " + fileComplexity);
}

RangeDistributionBuilder fileDistribution = new RangeDistributionBuilder(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION,
FILES_DISTRIB_BOTTOM_LIMITS);
RangeDistributionBuilder fileDistribution = new RangeDistributionBuilder(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION, FILES_DISTRIB_BOTTOM_LIMITS);
fileDistribution.add(Double.valueOf(fileComplexity));
sensorContext.saveMeasure(inputFile, fileDistribution.build().setPersistenceMode(PersistenceMode.MEMORY));

sensorContext.saveMeasure(inputFile, CoreMetrics.FUNCTION_COMPLEXITY,
Double.valueOf(fileComplexity) / functions.size());
sensorContext.saveMeasure(inputFile, CoreMetrics.FUNCTION_COMPLEXITY, Double.valueOf(fileComplexity) / functions.size());

RangeDistributionBuilder functionDistribution = new RangeDistributionBuilder(
CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, FUNCTIONS_DISTRIB_BOTTOM_LIMITS);
for (RubyFunction function : functions)
RangeDistributionBuilder functionDistribution = new RangeDistributionBuilder(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, FUNCTIONS_DISTRIB_BOTTOM_LIMITS);
for (SaikuroComplexity function : functions)
{
functionDistribution.add(Double.valueOf(function.getComplexity()));
}
Expand Down

This file was deleted.

Loading

0 comments on commit 3620194

Please sign in to comment.