Skip to content

Commit 799ce05

Browse files
authored
Merge pull request #27 from mishadoff/dev/eastwood-options-added
Added ability to pass eastwood options
2 parents a07bb9c + 3628f6b commit 799ce05

File tree

7 files changed

+43
-26
lines changed

7 files changed

+43
-26
lines changed

src/main/java/org/sonar/plugins/clojure/sensors/AbstractSensor.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,30 @@ private InputFile getFile(Issue issue, FileSystem fileSystem) {
8383
}
8484

8585
protected void saveIssue(Issue issue, SensorContext context) {
86-
InputFile file = getFile(issue, context.fileSystem());
86+
try {
87+
InputFile file = getFile(issue, context.fileSystem());
8788

88-
if (file == null) {
89-
LOG.warn("Not able to find a file with path '{}'", issue.getFilePath());
90-
return;
91-
}
89+
if (file == null) {
90+
LOG.warn("Not able to find a file with path '{}'", issue.getFilePath());
91+
return;
92+
}
9293

93-
RuleKey ruleKey = RuleKey.of(ClojureLintRulesDefinition.REPOSITORY_KEY, issue.getExternalRuleId().trim());
94+
RuleKey ruleKey = RuleKey.of(ClojureLintRulesDefinition.REPOSITORY_KEY, issue.getExternalRuleId().trim());
9495

95-
NewIssue newIssue = context.newIssue().forRule(ruleKey);
96+
NewIssue newIssue = context.newIssue().forRule(ruleKey);
9697

97-
NewIssueLocation primaryLocation = newIssue
98-
.newLocation()
99-
.on(file)
100-
.message(issue.getDescription().trim());
98+
NewIssueLocation primaryLocation = newIssue
99+
.newLocation()
100+
.on(file)
101+
.message(issue.getDescription().trim());
101102

102-
primaryLocation.at(file.selectLine(issue.getLine()));
103+
primaryLocation.at(file.selectLine(issue.getLine()));
103104

104-
newIssue.at(primaryLocation);
105-
newIssue.save();
105+
newIssue.at(primaryLocation);
106+
newIssue.save();
107+
} catch (Exception e) {
108+
LOG.error("Can not save the issue due to: " + e.getMessage());
109+
}
106110
}
107111

108112
/**

src/main/java/org/sonar/plugins/clojure/sensors/CommandRunner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public CommandStreamConsumer run(String command, String... arguments) {
1414
CommandStreamConsumer stdErr = new CommandStreamConsumer();
1515
Command cmd = Command.create(command);
1616
for (String arg: arguments) {
17-
cmd.addArgument(arg);
17+
if (arg != null) {
18+
cmd.addArgument(arg);
19+
}
1820
}
1921
CommandExecutor.create().execute(cmd, stdOut, stdErr, TIMEOUT);
2022
return stdOut;

src/main/java/org/sonar/plugins/clojure/sensors/eastwood/EastwoodSensor.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public EastwoodSensor(CommandRunner commandRunner) {
3232
}
3333

3434

35-
36-
3735
@Override
3836
public void describe(SensorDescriptor descriptor) {
3937
descriptor.name("SonarClojure")
@@ -43,11 +41,11 @@ public void describe(SensorDescriptor descriptor) {
4341

4442
@Override
4543
public void execute(SensorContext context) {
46-
4744
if (!checkIfPluginIsDisabled(context, ClojureProperties.EASTWOOD_DISABLED)) {
4845
LOG.info("Clojure project detected");
4946
LOG.info("Running Eastwood");
50-
CommandStreamConsumer stdOut = this.commandRunner.run(LEIN_COMMAND, EASTWOOD_COMMAND);
47+
String options = context.config().get(ClojureProperties.EASTWOOD_OPTIONS).orElse(null);
48+
CommandStreamConsumer stdOut = this.commandRunner.run(LEIN_COMMAND, EASTWOOD_COMMAND, options);
5149
if (isLeinInstalled(stdOut.getData()) && isPluginInstalled(stdOut.getData(), EASTWOOD_COMMAND)){
5250
String info = EastwoodIssueParser.parseRuntimeInfo(stdOut);
5351
if (info != null) {
@@ -57,15 +55,13 @@ public void execute(SensorContext context) {
5755
}
5856

5957
List<Issue> issues = EastwoodIssueParser.parse(stdOut);
60-
LOG.info("Saving issues");
58+
LOG.info("Saving issues " + issues.size());
6159
for (Issue issue : issues) {
6260
saveIssue(issue, context);
6361
}
6462
}
6563
} else {
6664
LOG.info ("Eastwood plugin is disabled");
6765
}
68-
6966
}
70-
7167
}

src/main/java/org/sonar/plugins/clojure/settings/ClojureProperties.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class ClojureProperties {
1212
public static final String FILE_SUFFIXES_DEFAULT_VALUE = "clj,cljs,cljc";
1313
public static final String ANCIENT_CLJ_DISABLED = "sonar.clojure.ancient-clj.disabled";
1414
public static final String EASTWOOD_DISABLED = "sonar.clojure.eastwood.disabled";
15+
public static final String EASTWOOD_OPTIONS = "sonar.clojure.eastwood.options";
1516
public static final String LEIN_NVD_DISABLED = "sonar.clojure.lein-nvd.disabled";
1617
public static final String LEIN_NVD_JSON_OUTPUT_LOCATION = "sonar.clojure.lein-nvd.json-output-location";
1718
public static final String MAIN_CATEGORY = "ClojureLanguage";
@@ -24,6 +25,7 @@ private ClojureProperties() {}
2425
public static List<PropertyDefinition> getProperties() {
2526
return asList(getFileSuffixProperty(),
2627
getEastwoodDisabledProperty(),
28+
getEastwoodOptionsProperty(),
2729
getAncientCljDisabledProperty(),
2830
getCloverageDisabledProperty(),
2931
getCloverageJsonOutputLocation(),
@@ -51,6 +53,16 @@ public static PropertyDefinition getEastwoodDisabledProperty() {
5153
.build();
5254
}
5355

56+
public static PropertyDefinition getEastwoodOptionsProperty() {
57+
return PropertyDefinition.builder(EASTWOOD_OPTIONS)
58+
.category(MAIN_CATEGORY)
59+
.subCategory("Sensors")
60+
.defaultValue(null)
61+
.name("Eastwood sensor options")
62+
.description("Provide string of options for eastwood plugin (e.g {:continue-on-exception true})")
63+
.build();
64+
}
65+
5466
public static PropertyDefinition getAncientCljDisabledProperty() {
5567
return PropertyDefinition.builder(ANCIENT_CLJ_DISABLED)
5668
.category(MAIN_CATEGORY)

src/test/java/org/sonar/plugins/clojure/sensors/eastwood/EastwoodSensorTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.sonar.plugins.clojure.sensors.eastwood;
22

33
import org.junit.Before;
4+
import org.junit.Ignore;
45
import org.junit.Test;
56
import org.mockito.Mock;
67
import org.mockito.Mockito;
@@ -73,7 +74,9 @@ public void testExecuteSensor() throws IOException {
7374
CommandStreamConsumer stdOut = new CommandStreamConsumer();
7475
stdOut.consumeLine("file.clj:1:0:issue-1:description-1");
7576
stdOut.consumeLine("file.clj:2:0:issue-2:description-2");
76-
Mockito.when(commandRunner.run("lein", "eastwood")).thenReturn(stdOut);
77+
String ignoredOptions = null;
78+
Mockito.when(commandRunner.run("lein", "eastwood", ignoredOptions))
79+
.thenReturn(stdOut);
7780

7881
EastwoodSensor eastwoodSensor = new EastwoodSensor(commandRunner);
7982
eastwoodSensor.execute(context);

src/test/java/org/sonar/plugins/clojure/settings/ClojurePropertiesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void testGetFileSuffixProperty() {
2323
@Test
2424
public void testGetProperties() {
2525
List<PropertyDefinition> propertyDefinitions = ClojureProperties.getProperties();
26-
assertThat(propertyDefinitions.size(), is(8));
26+
assertThat(propertyDefinitions.size(), is(9));
2727
assertThat(propertyDefinitions.get(0).key(), is("sonar.clojure.file.suffixes"));
2828

2929
}

start-sonarqube.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -eu
33
./mvnw clean package
44
docker build . --tag sonarqube_local_image
5-
docker rm -f sonarqube_local_test
6-
docker run --name sonarqube_local_test -p 9000:9000 sonarqube_local_image
5+
docker rm -f sonarqube_local_image
6+
docker run --name sonarqube_local_image -p 9000:9000 sonarqube_local_image
77

88

0 commit comments

Comments
 (0)