SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4"));
Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(46).doesNotContain(CpdTokenizerSensor.class);
+ assertThat(context.getExtensions()).hasSize(47).doesNotContain(CpdTokenizerSensor.class);
}
@Test
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER);
Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(49).contains(CpdTokenizerSensor.class);
+ assertThat(context.getExtensions()).hasSize(50).contains(CpdTokenizerSensor.class);
}
@Test
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.6"), SonarQubeSide.SCANNER);
Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(50).contains(CpdTokenizerSensor.class);
+ assertThat(context.getExtensions()).hasSize(51).contains(CpdTokenizerSensor.class);
}
}
assertThat(repo).isNotNull();
assertThat(repo.name()).isEqualTo("Xoo");
assertThat(repo.language()).isEqualTo("xoo");
- assertThat(repo.rules()).hasSize(18);
+ assertThat(repo.rules()).hasSize(19);
RulesDefinition.Rule rule = repo.rule(OneIssuePerLineSensor.RULE_KEY);
assertThat(rule.name()).isNotEmpty();
assertThat(countRowsWithValue(RuleScope.MAIN)).isEqualTo(2);
}
- @Test
- public void support_large_number_of_rows() throws SQLException {
- for (int i = 0; i < 2_000; i++) {
- insertRow(i, null);
- }
-
- assertThat(countRowsWithValue(null)).isEqualTo(2000);
- assertThat(countRowsWithValue(RuleScope.MAIN)).isZero();
-
- underTest.execute();
-
- assertThat(countRowsWithValue(RuleScope.MAIN)).isEqualTo(2_000);
- assertThat(countRowsWithValue(null)).isEqualTo(0);
- }
-
@Test
public void execute_is_reentreant() throws SQLException {
insertRow(1, null);
import org.picocontainer.Startable;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.RuleScope;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.debt.DebtRemediationFunction;
return ruleDto;
}
- private static Scope toDtoScope(RulesDefinition.Scope scope) {
+ private static Scope toDtoScope(RuleScope scope) {
switch (scope) {
case ALL:
return Scope.ALL;
.setDefRemediationGapMultiplier(templateRuleDto.getDefRemediationGapMultiplier())
.setDefRemediationBaseEffort(templateRuleDto.getDefRemediationBaseEffort())
.setGapDescription(templateRuleDto.getGapDescription())
+ .setScope(templateRuleDto.getScope())
.setSystemTags(templateRuleDto.getSystemTags())
.setCreatedAt(system2.now())
.setUpdatedAt(system2.now());
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
+import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction(ACTION)
.addPagingParams(100, MAX_LIMIT)
- .setHandler(this);
+ .setHandler(this)
+ .setChangelog(new Change("7.1", "The field 'scope' has been added to the response"))
+ .setChangelog(new Change("7.1", "The field 'scope' has been added to the 'f' parameter"));
action.createParam(FACETS)
.setDescription("Comma-separated list of the facets to be computed. No facet is computed by default.")
"<li>\"debtRemFn\" becomes \"remFn\"</li>" +
"<li>\"effortToFixDescription\" becomes \"gapDescription\"</li>" +
"<li>\"debtOverloaded\" becomes \"remFnOverloaded\"</li>" +
- "</ul>" +
- "In 7.1, the field 'scope' has been added.")
+ "</ul>")
.setPossibleValues(Ordering.natural().sortedCopy(OPTIONAL_FIELDS));
+
Iterator<String> it = OPTIONAL_FIELDS.iterator();
paramFields.setExampleValue(format("%s,%s", it.next(), it.next()));
doDefinition(action);
"<li>\"debtRemFnOffset\" becomes \"remFnBaseEffort\"</li>" +
"<li>\"defaultDebtRemFnOffset\" becomes \"defaultRemFnBaseEffort\"</li>" +
"<li>\"debtOverloaded\" becomes \"remFnOverloaded\"</li>" +
- "</ul>" +
- "In 7.1, a new field 'scope' has been added to the response.")
+ "</ul>")
.setResponseExample(getClass().getResource("search-example.json"))
.setSince("4.4")
.setHandler(this);
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.RuleScope;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.debt.DebtRemediationFunction;
.setSeverity(BLOCKER)
.setInternalKey("config1")
.setTags("tag1", "tag2", "tag3")
- .setScope(Scope.ALL)
+ .setScope(RuleScope.ALL)
.setType(RuleType.CODE_SMELL)
.setStatus(RuleStatus.BETA)
.setGapDescription("squid.S115.effortToFix");
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.rule;
+
+/**
+ * @since 7.1
+ *
+ */
+public enum RuleScope {
+ MAIN, TEST, ALL;
+
+ public static RuleScope defaultScope() {
+ return MAIN;
+ }
+}
import org.apache.commons.lang.StringUtils;
import org.sonar.api.ExtensionPoint;
import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.rule.RuleScope;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
private final Map<String, NewParam> paramsByKey = new HashMap<>();
private final DebtRemediationFunctions functions;
private boolean activatedByDefault;
- private Scope scope;
+ private RuleScope scope;
private NewRule(@Nullable String pluginKey, String repoKey, String key) {
this.pluginKey = pluginKey;
* @since 7.1
*/
@CheckForNull
- public Scope scope() {
+ public RuleScope scope() {
return this.scope;
}
/**
* @since 7.1
*/
- public NewRule setScope(Scope scope) {
+ public NewRule setScope(RuleScope scope) {
this.scope = scope;
return this;
}
private final Map<String, Param> params;
private final RuleStatus status;
private final boolean activatedByDefault;
- private final Scope scope;
+ private final RuleScope scope;
private Rule(Repository repository, NewRule newRule) {
this.pluginKey = newRule.pluginKey;
this.status = newRule.status;
this.debtRemediationFunction = newRule.debtRemediationFunction;
this.gapDescription = newRule.gapDescription;
- this.scope = newRule.scope == null ? Scope.MAIN : newRule.scope;
+ this.scope = newRule.scope == null ? RuleScope.MAIN : newRule.scope;
this.type = newRule.type == null ? RuleTagsToTypeConverter.convert(newRule.tags) : newRule.type;
this.tags = ImmutableSortedSet.copyOf(Sets.difference(newRule.tags, RuleTagsToTypeConverter.RESERVED_TAGS));
Map<String, Param> paramsBuilder = new HashMap<>();
public String name() {
return name;
}
-
+
/**
* @since 7.1
* @return
*/
- public Scope scope() {
+ public RuleScope scope() {
return scope;
}
}
}
- enum Scope {
- ALL, MAIN, TEST;
- }
-
@Immutable
class Param {
private final String key;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.rule.RuleScope;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.debt.DebtRemediationFunction;
-import org.sonar.api.server.rule.RulesDefinition.Scope;
import org.sonar.api.utils.log.LogTester;
import static org.assertj.core.api.Assertions.assertThat;
.setInternalKey("/something")
.setStatus(RuleStatus.BETA)
.setTags("one", "two")
- .setScope(Scope.ALL)
+ .setScope(RuleScope.ALL)
.addTags("two", "three", "four");
newRepo.createRule("ABC").setName("ABC").setMarkdownDescription("ABC");
assertThat(repo.rules()).hasSize(2);
RulesDefinition.Rule rule = repo.rule("NPE");
- assertThat(rule.scope()).isEqualTo(Scope.ALL);
+ assertThat(rule.scope()).isEqualTo(RuleScope.ALL);
assertThat(rule.key()).isEqualTo("NPE");
assertThat(rule.name()).isEqualTo("Detect NPE");
assertThat(rule.severity()).isEqualTo(Severity.BLOCKER);
RulesDefinition.Rule rule = context.repository("findbugs").rule("NPE");
assertThat(rule.name()).isEqualTo("NullPointer");
}
-
+
@Test
public void default_scope_should_be_main() {
RulesDefinition.NewRepository newFindbugs = context.createRepository("findbugs", "java");
newFindbugs.done();
RulesDefinition.Rule rule = context.repository("findbugs").rule("key");
- assertThat(rule.scope()).isEqualTo(Scope.MAIN);
+ assertThat(rule.scope()).isEqualTo(RuleScope.MAIN);
}
@Test