Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring in Greg Allen's extensions and update to merge against current master #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<groupId>com.godaddy.sonar</groupId>
<artifactId>sonar-ruby-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>1.0.0</version>
<version>1.1.0</version>

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

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.buildVersion>3.5.1</sonar.buildVersion>
<sonar.buildVersion>3.7</sonar.buildVersion>
<jdk.min.version>1.6</jdk.min.version>
</properties>

Expand Down
53 changes: 35 additions & 18 deletions src/main/java/com/godaddy/sonar/ruby/RubyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import com.godaddy.sonar.ruby.core.RubySourceCodeColorizer;
import com.godaddy.sonar.ruby.core.RubySourceImporter;
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;
import com.godaddy.sonar.ruby.metricfu.ReekRulesRepository;
import com.godaddy.sonar.ruby.metricfu.RoodiRulesRepository;
import com.godaddy.sonar.ruby.simplecovrcov.SimpleCovRcovJsonParserImpl;
import com.godaddy.sonar.ruby.simplecovrcov.SimpleCovRcovSensor;

Expand All @@ -22,22 +27,34 @@
@Properties({})
public final class RubyPlugin extends SonarPlugin
{
public static final String KEY_REPOSITORY_CANE = "cane";
public static final String NAME_REPOSITORY_CANE = "Cane";

public List<Class<? extends Extension>> getExtensions()
{
List<Class<? extends Extension>> extensions = new ArrayList<Class<? extends Extension>>();
extensions.add(Ruby.class);
extensions.add(SimpleCovRcovSensor.class);
extensions.add(SimpleCovRcovJsonParserImpl.class);
extensions.add(MetricfuComplexityYamlParserImpl.class);
extensions.add(RubySourceImporter.class);
extensions.add(RubySourceCodeColorizer.class);
extensions.add(RubySensor.class);
extensions.add(MetricfuComplexitySensor.class);

// Profiles
extensions.add(SonarWayProfile.class);

return extensions;
}
public static final String KEY_REPOSITORY_REEK = "reek";
public static final String NAME_REPOSITORY_REEK = "Reek";

public static final String KEY_REPOSITORY_ROODI = "roodi";
public static final String NAME_REPOSITORY_ROODI = "Roodi";

public List<Class<? extends Extension>> getExtensions() {
List<Class<? extends Extension>> extensions = new ArrayList<Class<? extends Extension>>();
extensions.add(Ruby.class);
extensions.add(SimpleCovRcovSensor.class);
extensions.add(SimpleCovRcovJsonParserImpl.class);
extensions.add(MetricfuYamlParser.class);
extensions.add(RubySourceImporter.class);
extensions.add(RubySourceCodeColorizer.class);
extensions.add(RubySensor.class);
extensions.add(MetricfuComplexitySensor.class);
extensions.add(MetricfuDuplicationSensor.class);
extensions.add(MetricfuIssueSensor.class);
extensions.add(CaneRulesRepository.class);
extensions.add(ReekRulesRepository.class);
extensions.add(RoodiRulesRepository.class);

// Profiles
extensions.add(SonarWayProfile.class);

return extensions;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/godaddy/sonar/ruby/core/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public Ruby()

public String[] getFileSuffixes()
{
return new String[]{"rb"};
return new String[]{".rb"};
}
}
35 changes: 13 additions & 22 deletions src/main/java/com/godaddy/sonar/ruby/core/RubyFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

public class RubyFile extends Resource<RubyPackage>
{
private String filename;
private static final long serialVersionUID = 678217195520058883L;
private String filename;
private String longName;
private String packageKey;
private RubyPackage parent = null;
Expand All @@ -29,33 +30,23 @@ public RubyFile(File file, List<File> sourceDirs)
throw new IllegalArgumentException("File cannot be null");
}

String dirName = null;
this.filename = StringUtils.substringBeforeLast(file.getName(), ".");

this.packageKey = RubyPackage.DEFAULT_PACKAGE_NAME;
this.filename = StringUtils.substringBeforeLast(file.getName(), ".");
this.longName = this.filename;
String key = this.packageKey + File.separator + this.filename;

if (sourceDirs != null)
{
PathResolver resolver = new PathResolver();
RelativePath relativePath = resolver.relativePath(sourceDirs, file);
if (relativePath != null)
{
dirName = relativePath.dir().toString();

this.filename = StringUtils.substringBeforeLast(relativePath.path(), ".");

if (dirName.indexOf(File.separator) >= 0)
{
this.packageKey = StringUtils.strip(dirName, File.separator);
this.packageKey = StringUtils.replace(this.packageKey, File.separator, ".");
this.packageKey = StringUtils.substringAfterLast(this.packageKey, ".");
}
if (relativePath != null && relativePath.path().indexOf(File.separator) >= 0)
{
this.packageKey = StringUtils.substringBeforeLast(relativePath.path(), File.separator);
this.packageKey = StringUtils.strip(this.packageKey, File.separator);
key = this.packageKey + File.separator + this.filename;
this.longName = key;
}
}

String key = new StringBuilder().append(this.packageKey).append(".").append(this.filename).toString();
this.longName = key;

}
setKey(key);
}

Expand Down Expand Up @@ -101,7 +92,7 @@ public String getQualifier()
public boolean matchFilePattern(String antPattern)
{
String patternWithoutFileSuffix = StringUtils.substringBeforeLast(antPattern, ".");
WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, ".");
WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, File.separator);
String key = getKey();
return matcher.match(key);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/godaddy/sonar/ruby/core/RubyPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@SuppressWarnings("rawtypes")
public class RubyPackage extends Resource
{
public static final String DEFAULT_PACKAGE_NAME = "[default]";
private static final long serialVersionUID = -8901912464767594618L;
public static final String DEFAULT_PACKAGE_NAME = "[default]";

public RubyPackage(String key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void doAnalyse(Project project, SensorContext context) throws IOExcept

List<File> sourceDirs = moduleFileSystem.sourceDirs();
LOG.info("Got {} source dirs", sourceDirs.size());
List<File> sourceFiles = moduleFileSystem.files(FileQuery.onSource());
List<File> sourceFiles = moduleFileSystem.files(FileQuery.onSource().onLanguage(Ruby.KEY));
LOG.info("Got {} source files", sourceFiles.size());
parseDirs(context, sourceFiles, sourceDirs, false, sourceCharset);
for (File directory : sourceDirs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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) {
super(file);
this.line = line;
this.className = className;
}

public CaneCommentViolation() {
}

public String getKey() {
return "CommentViolation";
}

public int getLine() {
return line;
}

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

public String getClassName() {
return className;
}

public void setClassName(String className) {
this.className = className;
}

@Override
public String toString() {
return "file: " + getFile() + " line: " + line + " class: " + className;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.godaddy.sonar.ruby.metricfu;

public class CaneComplexityViolation extends CaneViolation {
private String method;
private int complexity;

public CaneComplexityViolation(String file, String method, int complexity) {
super(file);
this.method = method;
this.complexity = complexity;
}

public CaneComplexityViolation() {
}

public String getKey() {
return "ComplexityViolation";
}

public String getMethod() {
return method;
}

public void setMethod(String method) {
this.method = method;
}

public int getComplexity() {
return complexity;
}

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

@Override
public String toString() {
return "file: " + getFile() + " line: " + complexity + " method: " + method;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.godaddy.sonar.ruby.metricfu;

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

public CaneLineStyleViolation(String file, int line, String description) {
super(file);
setLine(line);
setDescription(description);
}

public CaneLineStyleViolation() {
}

public String getKey() {
return key;
}

public int getLine() {
return line;
}

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

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;

if (description.contains("tabs")) {
key = "LineStyleTabsViolation";
} else if (description.contains("whitespace")) {
key = "LineStyleWhitespaceViolation";
} else if (description.contains("characters")) {
key = "LineStyleLengthViolation";
}
}

@Override
public String toString() {
return "file: " + getFile() + " line: " + line + " description: " + description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.godaddy.sonar.ruby.metricfu;

import org.apache.commons.io.IOUtils;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.rules.XMLRuleParser;

import com.godaddy.sonar.ruby.RubyPlugin;
import com.godaddy.sonar.ruby.core.Ruby;

import java.io.InputStream;
import java.util.List;

public class CaneRulesRepository extends RuleRepository {
public CaneRulesRepository() {
super(RubyPlugin.KEY_REPOSITORY_CANE, Ruby.KEY);
setName(RubyPlugin.NAME_REPOSITORY_CANE);
}


@Override
public List<Rule> createRules() {
XMLRuleParser parser = new XMLRuleParser();
InputStream input = CaneRulesRepository.class.getResourceAsStream("/com/godaddy/sonar/ruby/metricfu/CaneRulesRepository.xml");
try {
return parser.parse(input);
} finally {
IOUtils.closeQuietly(input);
}
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/godaddy/sonar/ruby/metricfu/CaneViolation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.godaddy.sonar.ruby.metricfu;

public abstract class CaneViolation {
private String file;

public CaneViolation(String file) {
this.file = file;
}

public CaneViolation() {
}

public abstract String getKey();

public String getFile() {
return file;
}

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

@Override
public String toString() {
return "file: " + file;
}
}
Loading