Skip to content

Commit

Permalink
Merge pull request #27 from mishadoff/dev/eastwood-options-added
Browse files Browse the repository at this point in the history
Added ability to pass eastwood options
  • Loading branch information
fsantiag authored May 2, 2019
2 parents a07bb9c + 3628f6b commit 799ce05
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 26 deletions.
32 changes: 18 additions & 14 deletions src/main/java/org/sonar/plugins/clojure/sensors/AbstractSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,30 @@ private InputFile getFile(Issue issue, FileSystem fileSystem) {
}

protected void saveIssue(Issue issue, SensorContext context) {
InputFile file = getFile(issue, context.fileSystem());
try {
InputFile file = getFile(issue, context.fileSystem());

if (file == null) {
LOG.warn("Not able to find a file with path '{}'", issue.getFilePath());
return;
}
if (file == null) {
LOG.warn("Not able to find a file with path '{}'", issue.getFilePath());
return;
}

RuleKey ruleKey = RuleKey.of(ClojureLintRulesDefinition.REPOSITORY_KEY, issue.getExternalRuleId().trim());
RuleKey ruleKey = RuleKey.of(ClojureLintRulesDefinition.REPOSITORY_KEY, issue.getExternalRuleId().trim());

NewIssue newIssue = context.newIssue().forRule(ruleKey);
NewIssue newIssue = context.newIssue().forRule(ruleKey);

NewIssueLocation primaryLocation = newIssue
.newLocation()
.on(file)
.message(issue.getDescription().trim());
NewIssueLocation primaryLocation = newIssue
.newLocation()
.on(file)
.message(issue.getDescription().trim());

primaryLocation.at(file.selectLine(issue.getLine()));
primaryLocation.at(file.selectLine(issue.getLine()));

newIssue.at(primaryLocation);
newIssue.save();
newIssue.at(primaryLocation);
newIssue.save();
} catch (Exception e) {
LOG.error("Can not save the issue due to: " + e.getMessage());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public CommandStreamConsumer run(String command, String... arguments) {
CommandStreamConsumer stdErr = new CommandStreamConsumer();
Command cmd = Command.create(command);
for (String arg: arguments) {
cmd.addArgument(arg);
if (arg != null) {
cmd.addArgument(arg);
}
}
CommandExecutor.create().execute(cmd, stdOut, stdErr, TIMEOUT);
return stdOut;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public EastwoodSensor(CommandRunner commandRunner) {
}




@Override
public void describe(SensorDescriptor descriptor) {
descriptor.name("SonarClojure")
Expand All @@ -43,11 +41,11 @@ public void describe(SensorDescriptor descriptor) {

@Override
public void execute(SensorContext context) {

if (!checkIfPluginIsDisabled(context, ClojureProperties.EASTWOOD_DISABLED)) {
LOG.info("Clojure project detected");
LOG.info("Running Eastwood");
CommandStreamConsumer stdOut = this.commandRunner.run(LEIN_COMMAND, EASTWOOD_COMMAND);
String options = context.config().get(ClojureProperties.EASTWOOD_OPTIONS).orElse(null);
CommandStreamConsumer stdOut = this.commandRunner.run(LEIN_COMMAND, EASTWOOD_COMMAND, options);
if (isLeinInstalled(stdOut.getData()) && isPluginInstalled(stdOut.getData(), EASTWOOD_COMMAND)){
String info = EastwoodIssueParser.parseRuntimeInfo(stdOut);
if (info != null) {
Expand All @@ -57,15 +55,13 @@ public void execute(SensorContext context) {
}

List<Issue> issues = EastwoodIssueParser.parse(stdOut);
LOG.info("Saving issues");
LOG.info("Saving issues " + issues.size());
for (Issue issue : issues) {
saveIssue(issue, context);
}
}
} else {
LOG.info ("Eastwood plugin is disabled");
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ClojureProperties {
public static final String FILE_SUFFIXES_DEFAULT_VALUE = "clj,cljs,cljc";
public static final String ANCIENT_CLJ_DISABLED = "sonar.clojure.ancient-clj.disabled";
public static final String EASTWOOD_DISABLED = "sonar.clojure.eastwood.disabled";
public static final String EASTWOOD_OPTIONS = "sonar.clojure.eastwood.options";
public static final String LEIN_NVD_DISABLED = "sonar.clojure.lein-nvd.disabled";
public static final String LEIN_NVD_JSON_OUTPUT_LOCATION = "sonar.clojure.lein-nvd.json-output-location";
public static final String MAIN_CATEGORY = "ClojureLanguage";
Expand All @@ -24,6 +25,7 @@ private ClojureProperties() {}
public static List<PropertyDefinition> getProperties() {
return asList(getFileSuffixProperty(),
getEastwoodDisabledProperty(),
getEastwoodOptionsProperty(),
getAncientCljDisabledProperty(),
getCloverageDisabledProperty(),
getCloverageJsonOutputLocation(),
Expand Down Expand Up @@ -51,6 +53,16 @@ public static PropertyDefinition getEastwoodDisabledProperty() {
.build();
}

public static PropertyDefinition getEastwoodOptionsProperty() {
return PropertyDefinition.builder(EASTWOOD_OPTIONS)
.category(MAIN_CATEGORY)
.subCategory("Sensors")
.defaultValue(null)
.name("Eastwood sensor options")
.description("Provide string of options for eastwood plugin (e.g {:continue-on-exception true})")
.build();
}

public static PropertyDefinition getAncientCljDisabledProperty() {
return PropertyDefinition.builder(ANCIENT_CLJ_DISABLED)
.category(MAIN_CATEGORY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sonar.plugins.clojure.sensors.eastwood;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
Expand Down Expand Up @@ -73,7 +74,9 @@ public void testExecuteSensor() throws IOException {
CommandStreamConsumer stdOut = new CommandStreamConsumer();
stdOut.consumeLine("file.clj:1:0:issue-1:description-1");
stdOut.consumeLine("file.clj:2:0:issue-2:description-2");
Mockito.when(commandRunner.run("lein", "eastwood")).thenReturn(stdOut);
String ignoredOptions = null;
Mockito.when(commandRunner.run("lein", "eastwood", ignoredOptions))
.thenReturn(stdOut);

EastwoodSensor eastwoodSensor = new EastwoodSensor(commandRunner);
eastwoodSensor.execute(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void testGetFileSuffixProperty() {
@Test
public void testGetProperties() {
List<PropertyDefinition> propertyDefinitions = ClojureProperties.getProperties();
assertThat(propertyDefinitions.size(), is(8));
assertThat(propertyDefinitions.size(), is(9));
assertThat(propertyDefinitions.get(0).key(), is("sonar.clojure.file.suffixes"));

}
Expand Down
4 changes: 2 additions & 2 deletions start-sonarqube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu
./mvnw clean package
docker build . --tag sonarqube_local_image
docker rm -f sonarqube_local_test
docker run --name sonarqube_local_test -p 9000:9000 sonarqube_local_image
docker rm -f sonarqube_local_image
docker run --name sonarqube_local_image -p 9000:9000 sonarqube_local_image


0 comments on commit 799ce05

Please sign in to comment.