Skip to content

Commit

Permalink
Update configs to disable plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
fsantiag committed Feb 7, 2021
1 parent 9c6b81d commit 0606222
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 67 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ version, keep in mind that it might cause errors on SonarClojure analysis.
### Configuring Sensors

#### Disabling
Sensors can be disabled by setting `sonar.clojure.<sensorname>.disabled=true` in the sonar-project.properties or
by using the command line argument `-Dsonar.clojure.<sensorname>.disabled` when running sonar-scanner.
Sensors can be disabled by setting `sonar.clojure.<sensorname>.enabled=false` in the sonar-project.properties or
by using the command line argument `-Dsonar.clojure.<sensorname>.enabled` when running sonar-scanner.
Sensor names are `eastwood`, `kibit`, `clj-kondo`, `ancient`, `nvd` and `cloverage`.

#### Report file location
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.sonar.plugins.clojure</groupId>
<artifactId>sonar-clojure-plugin</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
<packaging>sonar-plugin</packaging>
<name>sonar-clojure</name>
<description>SonarClojure is a plugin for SonarQube to analyze Clojure source.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public AbstractSensor(LeiningenRunner leiningenRunner) {
this.leiningenRunner = leiningenRunner;
}

protected boolean isPluginDisabled(SensorContext context, String pluginName, String propertyName, boolean defaultValue) {
Boolean pluginDisabled = context.config().getBoolean(propertyName).orElse(defaultValue);
LOG.debug(String.format("Property: %s Value: %s", propertyName, pluginDisabled));
if (pluginDisabled) {
protected boolean isPluginEnabled(SensorContext context, String pluginName, String propertyName, boolean defaultValue) {
Boolean pluginEnabled = context.config().getBoolean(propertyName).orElse(defaultValue);
LOG.debug(String.format("Property: %s Value: %s", propertyName, pluginEnabled));
if (!pluginEnabled) {
LOG.info(pluginName + " disabled");
}
return pluginDisabled;
return pluginEnabled;
}

protected Optional<InputFile> getFile(String filePath, FileSystem fileSystem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Optional;

import static org.sonar.plugins.clojure.sensors.ancient.AncientOutputParser.parse;
import static org.sonar.plugins.clojure.settings.AncientProperties.DISABLED_PROPERTY;
import static org.sonar.plugins.clojure.settings.AncientProperties.DISABLED_PROPERTY_DEFAULT;
import static org.sonar.plugins.clojure.settings.AncientProperties.ENABLED_PROPERTY;
import static org.sonar.plugins.clojure.settings.AncientProperties.ENABLED_PROPERTY_DEFAULT;
import static org.sonar.plugins.clojure.settings.Properties.SENSORS_TIMEOUT_PROPERTY;
import static org.sonar.plugins.clojure.settings.Properties.SENSORS_TIMEOUT_PROPERTY_DEFAULT;

Expand All @@ -47,7 +47,7 @@ public void describe(SensorDescriptor descriptor) {

@Override
public void execute(SensorContext context) {
if (!isPluginDisabled(context, PLUGIN_NAME, DISABLED_PROPERTY, DISABLED_PROPERTY_DEFAULT)) {
if (isPluginEnabled(context, PLUGIN_NAME, ENABLED_PROPERTY, ENABLED_PROPERTY_DEFAULT)) {
LOG.info("Running Lein Ancient");

long timeOut = context.config().getLong(SENSORS_TIMEOUT_PROPERTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void describe(SensorDescriptor descriptor) {

@Override
public void execute(SensorContext context) {
if (!isPluginDisabled(context, PLUGIN_NAME, DISABLED_PROPERTY, DISABLED_PROPERTY_DEFAULT)) {
if (isPluginEnabled(context, PLUGIN_NAME, ENABLED_PROPERTY, ENABLED_PROPERTY_DEFAULT)) {
LOG.info("Running " + PLUGIN_NAME);

long timeOut = context.config().getLong(SENSORS_TIMEOUT_PROPERTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public void execute(SensorContext context) {

LOG.debug("Saving issues: " + issues.size());
issues.forEach(issue -> saveIssue(issue, context));
} else {
LOG.info("Eastwood disabled");
}
}
private boolean isSensorEnabled(SensorContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void describe(SensorDescriptor descriptor) {

@Override
public void execute(SensorContext context) {
if (!isPluginDisabled(context, PLUGIN_NAME, KibitProperties.DISABLED_PROPERTY, KibitProperties.DISABLED_PROPERTY_DEFAULT)) {
if (isPluginEnabled(context, PLUGIN_NAME, KibitProperties.ENABLED_PROPERTY, KibitProperties.ENABLED_PROPERTY_DEFAULT)) {
LOG.info("Running Kibit");
long timeOut = context.config().getLong(SENSORS_TIMEOUT_PROPERTY)
.orElse(Long.valueOf(SENSORS_TIMEOUT_PROPERTY_DEFAULT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private Severity getSeverity(String level) {

@Override
public void execute(SensorContext context) {
if (!isPluginDisabled(context, PLUGIN_NAME, DISABLED_PROPERTY, DISABLED_PROPERTY_DEFAULT)) {
if (isPluginEnabled(context, PLUGIN_NAME, ENABLED_PROPERTY, ENABLED_PROPERTY_DEFAULT)) {
LOG.info("Running clj-kondo");

String config = context.config().get(CONFIG).orElse(DEFAULT_CONFIG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void describe(SensorDescriptor descriptor) {
@Override
public void execute(SensorContext context) {

if (!isPluginDisabled(context, PLUGIN_NAME, DISABLED_PROPERTY, DISABLED_PROPERTY_DEFAULT)) {
if (isPluginEnabled(context, PLUGIN_NAME, ENABLED_PROPERTY, ENABLED_PROPERTY_DEFAULT)) {
LOG.info("Running Lein NVD");
String reportPath = context.config().get(NvdProperties.REPORT_LOCATION_PROPERTY).orElse(REPORT_LOCATION_DEFAULT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
import static org.sonar.plugins.clojure.settings.Properties.SUB_CATEGORY;

public class AncientProperties {
public static final String DISABLED_PROPERTY = "sonar.clojure.ancient.disabled";
public static final boolean DISABLED_PROPERTY_DEFAULT = false;
public static final String ENABLED_PROPERTY = "sonar.clojure.ancient.enabled";
public static final boolean ENABLED_PROPERTY_DEFAULT = true;

private AncientProperties() {
}

static PropertyDefinition getAncientDisabled() {
return PropertyDefinition.builder(DISABLED_PROPERTY)
return PropertyDefinition.builder(ENABLED_PROPERTY)
.category(MAIN_CATEGORY)
.subCategory(SUB_CATEGORY)
.defaultValue(valueOf(DISABLED_PROPERTY_DEFAULT))
.defaultValue(valueOf(ENABLED_PROPERTY_DEFAULT))
.name("Ancient Disabled")
.description("Indicates the ancient sensor should be disabled")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import static org.sonar.plugins.clojure.settings.Properties.SUB_CATEGORY;

public class CloverageProperties {
public static final String DISABLED_PROPERTY = "sonar.clojure.cloverage.disabled";
public static final boolean DISABLED_PROPERTY_DEFAULT = false;
public static final String ENABLED_PROPERTY = "sonar.clojure.cloverage.enabled";
public static final boolean ENABLED_PROPERTY_DEFAULT = true;
public static final String REPORT_LOCATION_PROPERTY = "sonar.clojure.cloverage.reportPath";
public static final String REPORT_LOCATION_DEFAULT = "target/coverage/codecov.json";

private CloverageProperties() {
}

static PropertyDefinition getDisabledProperty() {
return PropertyDefinition.builder(DISABLED_PROPERTY)
static PropertyDefinition getEnabledProperty() {
return PropertyDefinition.builder(ENABLED_PROPERTY)
.category(MAIN_CATEGORY)
.subCategory(SUB_CATEGORY)
.defaultValue("false")
.defaultValue(String.valueOf(ENABLED_PROPERTY_DEFAULT))
.name("Cloverage Disabled")
.description("Indicates if cloverage sensor should be disabled")
.build();
Expand All @@ -38,6 +38,6 @@ static PropertyDefinition getReportLocationProperty() {
}

static List<PropertyDefinition> getProperties() {
return asList(getDisabledProperty(), getReportLocationProperty());
return asList(getEnabledProperty(), getReportLocationProperty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
import static org.sonar.plugins.clojure.settings.Properties.SUB_CATEGORY;

public class KibitProperties {
public static final String DISABLED_PROPERTY = "sonar.clojure.kibit.disabled";
public static final boolean DISABLED_PROPERTY_DEFAULT = false;
public static final String ENABLED_PROPERTY = "sonar.clojure.kibit.enabled";
public static final boolean ENABLED_PROPERTY_DEFAULT = true;

private KibitProperties() {
}

static PropertyDefinition getDisabledProperty() {
return PropertyDefinition.builder(DISABLED_PROPERTY)
static PropertyDefinition getEnabledProperty() {
return PropertyDefinition.builder(ENABLED_PROPERTY)
.category(MAIN_CATEGORY)
.subCategory(SUB_CATEGORY)
.defaultValue(valueOf(DISABLED_PROPERTY_DEFAULT))
.defaultValue(valueOf(ENABLED_PROPERTY_DEFAULT))
.name("Kibit Disabled")
.description("Indicates if kibit sensor should be disabled")
.build();
}

static List<PropertyDefinition> getProperties() {
return singletonList(getDisabledProperty());
return singletonList(getEnabledProperty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
import static org.sonar.plugins.clojure.settings.Properties.SUB_CATEGORY;

public class KondoProperties {
public static final String DISABLED_PROPERTY = "sonar.clojure.kondo.disabled";
public static final String ENABLED_PROPERTY = "sonar.clojure.kondo.enabled";
public static final String OPTIONS = "sonar.clojure.kondo.options";
public static final String CONFIG = "sonar.clojure.kondo.config";
public static final boolean DISABLED_PROPERTY_DEFAULT = true;
public static final boolean ENABLED_PROPERTY_DEFAULT = false;
public static final String DEFAULT_OPTIONS = "--lint src";
public static final String DEFAULT_CONFIG = "{:output {:format :edn}}";

private KondoProperties() {
}

static PropertyDefinition getDisabledProperty() {
return PropertyDefinition.builder(DISABLED_PROPERTY)
static PropertyDefinition getEnabledProperty() {
return PropertyDefinition.builder(ENABLED_PROPERTY)
.category(MAIN_CATEGORY)
.subCategory(SUB_CATEGORY)
.defaultValue(valueOf(DISABLED_PROPERTY_DEFAULT))
.defaultValue(valueOf(ENABLED_PROPERTY_DEFAULT))
.name("clj-kondo disabled")
.description("Indicates if clj-kondo sensor should be disabled")
.build();
Expand All @@ -51,6 +51,6 @@ static PropertyDefinition getConfigProperty() {
}

static List<PropertyDefinition> getProperties() {
return asList(getDisabledProperty(), getOptionsProperty(), getConfigProperty());
return asList(getEnabledProperty(), getOptionsProperty(), getConfigProperty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
import static org.sonar.plugins.clojure.settings.Properties.SUB_CATEGORY;

public class NvdProperties {
public static final String DISABLED_PROPERTY = "sonar.clojure.nvd.disabled";
public static final boolean DISABLED_PROPERTY_DEFAULT = false;
public static final String ENABLED_PROPERTY = "sonar.clojure.nvd.enabled";
public static final boolean ENABLED_PROPERTY_DEFAULT = true;
public static final String REPORT_LOCATION_PROPERTY = "sonar.clojure.nvd.reportPath";
public static final String REPORT_LOCATION_DEFAULT = "target/nvd/dependency-check-report.json";

private NvdProperties() {
}

static PropertyDefinition getDisabledProperty() {
return PropertyDefinition.builder(DISABLED_PROPERTY)
static PropertyDefinition getEnabledProperty() {
return PropertyDefinition.builder(ENABLED_PROPERTY)
.category(MAIN_CATEGORY)
.subCategory(SUB_CATEGORY)
.defaultValue(valueOf(DISABLED_PROPERTY_DEFAULT))
.defaultValue(valueOf(ENABLED_PROPERTY_DEFAULT))
.name("Lein NVD Disabled")
.description("Indicates if lein-nvd sensor should be disabled")
.build();
Expand All @@ -39,6 +39,6 @@ static PropertyDefinition getReportLocationProperty() {
}

static List<PropertyDefinition> getProperties() {
return asList(getDisabledProperty(), getReportLocationProperty());
return asList(getEnabledProperty(), getReportLocationProperty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

import java.io.File;

import static junit.framework.TestCase.assertTrue;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;

@RunWith(MockitoJUnitRunner.class)
public class AbstractSensorTest {
Expand All @@ -34,11 +35,11 @@ public void setUp() {
@Test
public void shouldDisablePluginWhenPropertyIsSet() {
SensorContextTester context = SensorContextTester.create(new File("/"));
context.settings().appendProperty("property.foo", "true");
context.settings().appendProperty("property.enabled", "false");

boolean isDisabled = dummySensor.isPluginDisabled(context, "SOME_PLUGIN", "property.foo", false);
boolean isDisabled = dummySensor.isPluginEnabled(context, "SOME_PLUGIN", "property.enabled", true);

assertTrue(isDisabled);
assertThat(isDisabled, equalTo(false));
assertThat(logTester.logs(), hasItem("SOME_PLUGIN disabled"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.sonar.plugins.clojure.language.Clojure;
import org.sonar.plugins.clojure.sensors.LeiningenRunner;
import org.sonar.plugins.clojure.sensors.CommandStreamConsumer;
import org.sonar.plugins.clojure.settings.AncientProperties;

import java.io.File;
import java.io.IOException;
Expand All @@ -20,12 +21,12 @@
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.sonar.plugins.clojure.settings.KondoProperties.ENABLED_PROPERTY;

public class AncientSensorTest {
@Mock
Expand All @@ -44,7 +45,7 @@ public void shouldConfigureSensor() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
ancientSensor.describe(descriptor);
assertThat(descriptor.name(), is("Ancient"));
assertTrue(descriptor.languages().contains("clj"));
assertThat(descriptor.languages().contains("clj"), is(true));
assertThat(descriptor.languages().size(), is(1));
}

Expand Down Expand Up @@ -75,6 +76,8 @@ public void shouldExecuteAncient() throws IOException {
private SensorContextTester prepareContext() throws IOException {
SensorContextTester context = SensorContextTester.create(new File("/"));

context.settings().appendProperty(AncientProperties.ENABLED_PROPERTY, "true");

File baseDir = new File("src/test/resources/");
File file = new File(baseDir, "project.clj");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.sonar.plugins.clojure.language.Clojure;
import org.sonar.plugins.clojure.sensors.LeiningenRunner;
import org.sonar.plugins.clojure.sensors.CommandStreamConsumer;
import org.sonar.plugins.clojure.settings.CloverageProperties;

import java.io.File;
import java.io.IOException;
Expand All @@ -26,6 +27,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sonar.plugins.clojure.settings.CloverageProperties.REPORT_LOCATION_PROPERTY;
import static org.sonar.plugins.clojure.settings.KondoProperties.ENABLED_PROPERTY;

@RunWith(MockitoJUnitRunner.class)
public class CloverageSensorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

Expand All @@ -43,7 +42,7 @@ public void shouldConfigureSensor() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
kibitSensor.describe(descriptor);
assertThat(descriptor.name(), is("Kibit"));
assertTrue(descriptor.languages().contains("clj"));
assertThat(descriptor.languages().contains("clj"), is(true));
assertThat(descriptor.languages().size(), is(1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.sonar.plugins.clojure.settings.KondoProperties.*;

@RunWith(MockitoJUnitRunner.class)
Expand Down Expand Up @@ -73,7 +72,7 @@ private SensorContextTester prepareContext() throws IOException {

context.settings().appendProperty(OPTIONS, "--lint src");
context.settings().appendProperty(CONFIG, "{:output {:format :edn}}");
context.settings().appendProperty(DISABLED_PROPERTY, "false");
context.settings().appendProperty(ENABLED_PROPERTY, "true");

File baseDir = new File("src/test/resources/");
File file = new File(baseDir, "file.clj");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class AncientPropertiesTest {
@Test
public void shouldHaveAncientDisabledProperty() {
PropertyDefinition ancientDisabled = AncientProperties.getAncientDisabled();
assertThat(ancientDisabled.key(), is("sonar.clojure.ancient.disabled"));
assertThat(ancientDisabled.key(), is("sonar.clojure.ancient.enabled"));
assertThat(ancientDisabled.name(), is("Ancient Disabled"));
assertThat(ancientDisabled.category(), is("SonarClojure"));
assertThat(ancientDisabled.subCategory(), is("Sensors"));
assertThat(ancientDisabled.defaultValue(), is("false"));
assertThat(ancientDisabled.defaultValue(), is("true"));
assertThat(ancientDisabled.description(), is("Indicates the ancient sensor should be disabled"));
}

Expand Down
Loading

0 comments on commit 0606222

Please sign in to comment.