findAvailableXMLFiles();
}
- protected void findAvailableXMLFiles() {
+ private void findAvailableXMLFiles() {
if (contributingPluginKeyToClassLoader == null) {
contributingPluginKeyToClassLoader = Maps.newTreeMap();
// Add default model
*/
package org.sonar.server.es;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
return this;
}
- /**
- * WARNING - dangerous
- */
- @Deprecated
- public SearchOptions disableLimit() {
- this.limit = 999_999;
- return this;
- }
-
/**
* Lists selected facets.
*/
return fieldsToReturn;
}
- public boolean hasField(String key) {
- return fieldsToReturn.isEmpty() || fieldsToReturn.contains(key);
- }
-
public SearchOptions addFields(@Nullable Collection<String> c) {
if (c != null) {
for (String s : c) {
return this;
}
- public SearchOptions addFields(String... array) {
- return addFields(Arrays.asList(array));
- }
-
public SearchOptions writeJson(JsonWriter json, long totalHits) {
json.prop("total", totalHits);
json.prop(WebService.Param.PAGE, getPage());
json.prop(WebService.Param.PAGE_SIZE, getLimit());
return this;
}
-
- @Deprecated
- public SearchOptions writeDeprecatedJson(JsonWriter json, long totalHits) {
- int pages = 0;
- if (limit > 0) {
- pages = (int) (totalHits / limit);
- if (totalHits % limit > 0) {
- pages++;
- }
- }
- json.name("paging").beginObject()
- .prop("pageIndex", getPage())
- .prop("pageSize", getLimit())
- .prop("total", totalHits)
- .prop("fTotal", String.valueOf(totalHits))
- .prop("pages", pages)
- .endObject();
- return this;
- }
}
this.order = order;
}
- public QueryBuilder query() {
- return query;
- }
-
- public Map<String, QueryBuilder> filters() {
- return filters;
- }
-
public AggregationBuilder buildStickyFacet(String fieldName, String facetName, Object... selected) {
return buildStickyFacet(fieldName, facetName, FACET_DEFAULT_SIZE, selected);
}
}
private static <T> Collection<T> defaultCollection(@Nullable Collection<T> c) {
- return c == null ? Collections.<T>emptyList() : Collections.unmodifiableCollection(c);
+ return c == null ? Collections.emptyList() : Collections.unmodifiableCollection(c);
}
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.server.issue.workflow;
-
-import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.condition.Condition;
-
-public class OrCondition implements Condition {
- private final Condition[] conditions;
-
- public OrCondition(Condition... conditions) {
- this.conditions = conditions;
- }
-
- @Override
- public boolean matches(Issue issue) {
- for (Condition condition : conditions) {
- if (condition.matches(issue)) {
- return true;
- }
- }
- return false;
- }
-
-}
*/
package org.sonar.server.qualityprofile;
-import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import org.sonar.api.rule.RuleStatus;
import org.sonar.api.server.ServerSide;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.es.SearchOptions;
import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.rule.index.RuleIndex;
-import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.search.FacetValue;
@ServerSide
private final DbClient dbClient;
private final ActiveRuleIndex activeRuleIndex;
- private final RuleIndex ruleIndex;
- public QProfileLoader(DbClient dbClient, ActiveRuleIndex activeRuleIndex, RuleIndex ruleIndex) {
+ public QProfileLoader(DbClient dbClient, ActiveRuleIndex activeRuleIndex) {
this.dbClient = dbClient;
this.activeRuleIndex = activeRuleIndex;
- this.ruleIndex = ruleIndex;
}
public Map<String, Multimap<String, FacetValue>> getAllProfileStats() {
}
}
- public long countDeprecatedActiveRulesByProfile(String key) {
- return ruleIndex.search(
- new RuleQuery()
- .setQProfileKey(key)
- .setActivation(true)
- .setStatuses(Lists.newArrayList(RuleStatus.DEPRECATED)),
- new SearchOptions().setLimit(0)).getTotal();
- }
-
}
assertThat(options.getLimit()).isEqualTo(SearchOptions.MAX_LIMIT);
}
- @Test
- public void disable_limit() {
- SearchOptions options = new SearchOptions().disableLimit();
- assertThat(options.getLimit()).isEqualTo(999999);
- }
-
@Test
public void max_page_size() {
SearchOptions options = new SearchOptions().setPage(3, SearchOptions.MAX_LIMIT + 10);
assertThat(options.getLimit()).isEqualTo(SearchOptions.MAX_LIMIT);
}
- @Test
- public void hasField() {
- // parameter is missing -> all the fields are returned by default
- SearchOptions options = new SearchOptions();
- assertThat(options.hasField("repo")).isTrue();
-
- // parameter is set to empty -> all the fields are returned by default
- options = new SearchOptions().addFields("");
- assertThat(options.hasField("repo")).isTrue();
-
- // parameter is set -> return only the selected fields
- options = new SearchOptions().addFields("name", "repo");
- assertThat(options.hasField("name")).isTrue();
- assertThat(options.hasField("repo")).isTrue();
- assertThat(options.hasField("severity")).isFalse();
- }
-
@Test
public void writeJson() {
SearchOptions options = new SearchOptions().setPage(3, 10);
JsonAssert.assertJson(json.toString()).isSimilarTo("{\"total\": 42, \"p\": 3, \"ps\": 10}");
}
- @Test
- public void writeDeprecatedJson() {
- SearchOptions options = new SearchOptions().setPage(3, 10);
- StringWriter json = new StringWriter();
- JsonWriter jsonWriter = JsonWriter.of(json).beginObject();
- options.writeDeprecatedJson(jsonWriter, 42L);
- jsonWriter.endObject().close();
-
- JsonAssert.assertJson(json.toString()).isSimilarTo("{\"paging\": {\"pageIndex\": 3, \"pageSize\": 10, \"total\": 42, \"fTotal\": \"42\", \"pages\": 5}}");
- }
-
- @Test
- public void writeDeprecatedJson_exact_nb_of_pages() {
- SearchOptions options = new SearchOptions().setPage(3, 10);
- StringWriter json = new StringWriter();
- JsonWriter jsonWriter = JsonWriter.of(json).beginObject();
- options.writeDeprecatedJson(jsonWriter, 30L);
- jsonWriter.endObject().close();
-
- JsonAssert.assertJson(json.toString()).isSimilarTo("{\"paging\": {\"pageIndex\": 3, \"pageSize\": 10, \"total\": 30, \"fTotal\": \"30\", \"pages\": 3}}");
- }
-
@Test
public void fail_if_result_after_first_10_000() {
expectedException.expect(IllegalArgumentException.class);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.server.issue.workflow;
-
-import org.junit.Test;
-import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.condition.Condition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class OrConditionTest {
-
- private static final Condition TRUE_CONDITION = new BooleanCondition(true);
- private static final Condition FALSE_CONDITION = new BooleanCondition(false);
- Issue issue = mock(Issue.class);
-
- @Test
- public void match() {
- assertThat(new OrCondition(TRUE_CONDITION).matches(issue)).isTrue();
- assertThat(new OrCondition(FALSE_CONDITION).matches(issue)).isFalse();
- assertThat(new OrCondition(FALSE_CONDITION, TRUE_CONDITION).matches(issue)).isTrue();
- assertThat(new OrCondition(FALSE_CONDITION, FALSE_CONDITION).matches(issue)).isFalse();
- }
-
- private static class BooleanCondition implements Condition {
- private final boolean b;
-
- public BooleanCondition(boolean b) {
- this.b = b;
- }
-
- @Override
- public boolean matches(Issue issue) {
- return b;
- }
- }
-}
import org.sonar.api.profiles.ProfileExporter;
import org.sonar.api.profiles.ProfileImporter;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
assertThat(stats.get(XOO_P1_KEY).get("countActiveRules").size()).isEqualTo(1);
}
- @Test
- public void count_by_deprecated() {
- logInAsQProfileAdministrator();
-
- // create deprecated rule
- RuleDto deprecatedXooRule = RuleTesting.newDto(RuleKey.of("xoo", "deprecated1"))
- .setSeverity("MINOR").setLanguage("xoo").setStatus(RuleStatus.DEPRECATED);
- dbClient.ruleDao().insert(dbSession, deprecatedXooRule);
- dbSession.commit();
- ruleIndexer.index();
-
- // active some rules
- service.activate(XOO_P1_KEY, new RuleActivation(deprecatedXooRule.getKey()).setSeverity("BLOCKER"));
- service.activate(XOO_P1_KEY, new RuleActivation(RuleTesting.XOO_X1).setSeverity("BLOCKER"));
- dbSession.commit();
-
- assertThat(loader.countDeprecatedActiveRulesByProfile(XOO_P1_KEY)).isEqualTo(1);
- }
-
public static class XooExporter extends ProfileExporter {
public XooExporter() {
super("xootool", "Xoo Tool");
+++ /dev/null
-CREATE TABLE "FAKE" (
- "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
- "KEE" VARCHAR(200) NOT NULL,
- "CREATED_AT" TIMESTAMP,
- "UPDATED_AT" TIMESTAMP
-);
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.server.db.fake.FakeMapper">
-
- <sql id="selectColumns">
- f.id,
- f.kee as "key",
- f.created_at as "createdAt",
- f.updated_at as "updatedAt"
- </sql>
-
- <select id="selectByKey" parameterType="String" resultType="fake">
- select
- <include refid="selectColumns"/>
- from fake f WHERE f.kee=#{key}
- </select>
-
- <insert id="insert" parameterType="fake" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- insert into fake (kee, created_at, updated_at)
- values (#{key}, #{createdAt}, #{updatedAt})
- </insert>
-
- <select id="selectAfterDate" resultType="fake" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
- select
- <include refid="selectColumns"/>
- from fake f
- <where>
- <if test="date != null">
- f.updated_at IS NULL or f.updated_at >= #{date}
- </if>
- </where>
- </select>
-
-</mapper>