import java.util.List;
public class BatchComponents {
+ private BatchComponents() {
+ // only static stuff
+ }
+
public static Collection all() {
List components = Lists.newArrayList(
// Maven
private <T> List<T> getFilteredExtensions(Class<T> type, @Nullable Project project, @Nullable ExtensionMatcher matcher) {
List<T> result = Lists.newArrayList();
for (Object extension : getExtensions(type)) {
- if (type == Sensor.class && extension instanceof Analyzer) {
+ if (Sensor.class.equals(type) && extension instanceof Analyzer) {
extension = new SensorWrapper((Analyzer) extension, context, analyzerOptimizer);
}
if (shouldKeep(type, extension, project, matcher)) {
result.add((T) extension);
}
}
- if (type == Sensor.class) {
+ if (Sensor.class.equals(type)) {
// Retrieve Analyzer and wrap then in SensorWrapper
for (Object extension : getExtensions(Analyzer.class)) {
extension = new SensorWrapper((Analyzer) extension, context, analyzerOptimizer);
private boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) {
boolean keep = (ClassUtils.isAssignable(extension.getClass(), type)
- || (type == Sensor.class && ClassUtils.isAssignable(extension.getClass(), Analyzer.class)))
+ || (Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Analyzer.class)))
&& (matcher == null || matcher.accept(extension));
if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) {
keep = ((CheckProject) extension).shouldExecuteOnProject(project);
private static boolean doesReachThresholds(Comparable measureValue, Comparable criteriaValue, ResolvedCondition condition) {
int comparison = measureValue.compareTo(criteriaValue);
return !(isNotEquals(comparison, condition)
- || isGreater(comparison, condition)
- || isSmaller(comparison, condition)
- || isEquals(comparison, condition));
+ || isGreater(comparison, condition)
+ || isSmaller(comparison, condition)
+ || isEquals(comparison, condition));
}
private static boolean isNotEquals(int comparison, ResolvedCondition condition) {
private static boolean isADouble(Metric metric) {
return metric.getType() == Metric.ValueType.FLOAT ||
- metric.getType() == Metric.ValueType.PERCENT ||
- metric.getType() == Metric.ValueType.RATING;
+ metric.getType() == Metric.ValueType.PERCENT ||
+ metric.getType() == Metric.ValueType.RATING;
}
private static boolean isAInteger(Metric metric) {
return metric.getType() == Metric.ValueType.INT ||
- metric.getType() == Metric.ValueType.MILLISEC;
+ metric.getType() == Metric.ValueType.MILLISEC;
}
private static boolean isAString(Metric metric) {
return metric.getType() == Metric.ValueType.STRING ||
- metric.getType() == Metric.ValueType.LEVEL;
+ metric.getType() == Metric.ValueType.LEVEL;
}
private static boolean isABoolean(Metric metric) {
Double value;
if (period == null) {
value = measure.getValue();
- } else if (period == 1) {
- value = measure.getVariation1();
- } else if (period == 2) {
- value = measure.getVariation2();
- } else if (period == 3) {
- value = measure.getVariation3();
- } else if (period == 4) {
- value = measure.getVariation4();
- } else if (period == 5) {
- value = measure.getVariation5();
} else {
- throw new IllegalStateException("Following index period is not allowed : " + Double.toString(period));
+ switch (period.intValue()) {
+ case 1:
+ value = measure.getVariation1();
+ break;
+ case 2:
+ value = measure.getVariation2();
+ break;
+ case 3:
+ value = measure.getVariation3();
+ break;
+ case 4:
+ value = measure.getVariation4();
+ break;
+ case 5:
+ value = measure.getVariation5();
+ break;
+ default:
+ throw new IllegalStateException("Following index period is not allowed : " + Double.toString(period));
+ }
}
return value;
}
import org.sonar.api.database.DatabaseSession;
+/**
+ * @deprecated replaced by mybatis
+ */
@Deprecated
public interface DatabaseSessionFactory {
@Override
public void handle(Request request, Response response) {
- ActivityQuery query = createLogQuery(logService.newActivityQuery(), request);
+ ActivityQuery query = logService.newActivityQuery();
SearchOptions searchOptions = SearchOptions.create(request);
QueryOptions queryOptions = mapping.newQueryOptions(searchOptions);
json.endObject().close();
}
- public static ActivityQuery createLogQuery(ActivityQuery query, Request request) {
- // query.setTypes(request.param(SearchOptions.PARAM_TEXT_QUERY));
- return query;
- }
-
private void writeLogs(Result<Activity> result, JsonWriter json, SearchOptions options) {
json.name("logs").beginArray();
for (Activity log : result.getHits()) {
@Override
public int compare(@Nullable Duplication d1,
- @Nullable Duplication d2) {
+ @Nullable Duplication d2) {
if (d1 == null || d2 == null) {
return -1;
}
}
}
- private class BlockComparator implements Comparator<Block>, Serializable {
+ private static class BlockComparator implements Comparator<Block> {
@Override
public int compare(@Nullable Block b1,
- @Nullable Block b2) {
+ @Nullable Block b2) {
if (b1 == null || b2 == null) {
return -1;
}
}
}
-
public static class Duplication {
private final ComponentDto file;
private final Integer from, size;
private String language;
private String parent;
+ /**
+ * @deprecated in 4.4
+ */
@Deprecated
public int id() {
return id;
}
+ /**
+ * @deprecated in 4.4
+ */
@Deprecated
QProfile setId(int id) {
this.id = id;
@Override
public boolean equals(@Nullable Object o) {
- if (this == o)
+ if (this == o) {
return true;
+ }
if (o == null || getClass() != o.getClass()) {
return false;
}
-
QProfileName that = (QProfileName) o;
-
if (!lang.equals(that.lang)) {
return false;
}
RulesDefinition.Param paramDef = ruleDef.param(paramDto.getName());
if (paramDef == null) {
// TODO cascade on the activeRule upon RuleDeletion
- // activeRuleDao.removeRuleParam(paramDto, sqlSession);
dbClient.ruleDao().removeRuleParam(session, rule, paramDto);
} else {
// TODO validate that existing active rules still match constraints
private void updateExistingRule(RuleDto ruleDto, NewRule newRule, DbSession dbSession){
if (ruleDto.getStatus().equals(RuleStatus.REMOVED)) {
if (newRule.isPreventReactivation()) {
- throw new ReactivationException(String.format("A removed rule with the key '%s' already exits", ruleDto.getKey().rule()), ruleDto.getKey());
+ throw new ReactivationException(String.format("A removed rule with the key '%s' already exists", ruleDto.getKey().rule()), ruleDto.getKey());
} else {
ruleDto.setStatus(RuleStatus.READY);
dbClient.ruleDao().update(dbSession, ruleDto);
}
} else {
- throw new IllegalArgumentException(String.format("A rule with the key '%s' already exits", ruleDto.getKey().rule()));
+ throw new IllegalArgumentException(String.format("A rule with the key '%s' already exists", ruleDto.getKey().rule()));
}
}
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
}
private void setFields(QueryOptions options, SearchRequestBuilder esSearch) {
- /* integrate Option's Fields */
+ /* integrate Option's Fields */
Set<String> fields = new HashSet<String>();
if (!options.getFieldsToReturn().isEmpty()) {
for (String fieldToReturn : options.getFieldsToReturn()) {
}
private void setFacets(QueryOptions options, SearchRequestBuilder esSearch) {
- /* Integrate Facets */
+ /* Integrate Facets */
if (options.isFacet()) {
this.setFacets(esSearch);
}
}
private void setSorting(RuleQuery query, SearchRequestBuilder esSearch) {
- /* integrate Query Sort */
+ /* integrate Query Sort */
if (query.getSortField() != null) {
FieldSortBuilder sort = SortBuilders.fieldSort(query.getSortField().sortField());
if (query.isAscendingSort()) {
}
protected void setPagination(QueryOptions options, SearchRequestBuilder esSearch) {
- /* integrate Option's Pagination */
esSearch.setFrom(options.getOffset());
esSearch.setSize(options.getLimit());
}
- private QueryBuilder phraseQuery(IndexField field, String query, float boost) {
- return QueryBuilders.matchPhraseQuery(field.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, query)
- .boost(boost)
- .operator(MatchQueryBuilder.Operator.AND);
- }
-
private QueryBuilder termQuery(IndexField field, String query, float boost) {
return QueryBuilders.multiMatchQuery(query,
field.field(), field.field() + "." + IndexField.SEARCH_PARTIAL_SUFFIX)
BoolQueryBuilder qb = QueryBuilders.boolQuery();
String queryString = query.getQueryText();
- //Human readable type of querying
+ // Human readable type of querying
qb.should(QueryBuilders.queryString(query.getQueryText())
.field(RuleNormalizer.RuleField.NAME.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 20f)
.field(RuleNormalizer.RuleField.HTML_DESCRIPTION.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 3f)
FilterBuilders.orFilter(
FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), query.getDebtCharacteristics()),
FilterBuilders.termsFilter(RuleNormalizer.RuleField.CHARACTERISTIC.field(), query.getDebtCharacteristics()))
- ),
+ ),
// Match only when NOT NONE overriden
FilterBuilders.andFilter(
FilterBuilders.orFilter(
FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), query.getDebtCharacteristics()),
FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field(), query.getDebtCharacteristics())))
- )
- );
+ )
+ );
}
- //Debt char exist filter
+ // Debt char exist filter
if (query.getHasDebtCharacteristic() != null && query.getHasDebtCharacteristic()) {
fb.must(FilterBuilders.existsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()));
}
-
if (query.getAvailableSince() != null) {
fb.must(FilterBuilders.rangeFilter(RuleNormalizer.RuleField.CREATED_AT.field())
.gte(query.getAvailableSince()));
.size(10)
.minDocCount(1));
- /* the Tag facet */
+ /* the Tag facet */
query.addAggregation(AggregationBuilders
.terms("tags")
.field(RuleNormalizer.RuleField._TAGS.field())
.size(10)
.minDocCount(1));
- /* the Repo facet */
+ /* the Repo facet */
query.addAggregation(AggregationBuilders
.terms("repositories")
.field(RuleNormalizer.RuleField.REPOSITORY.field())
}
-
public Result<Rule> search(RuleQuery query, QueryOptions options) {
StopWatch profile = profiling.start("es", Profiling.Level.FULL);
return new Result<Rule>(this, esResult);
}
-
@Override
protected Rule toDoc(@Nullable Map<String, Object> fields) {
Preconditions.checkArgument(fields != null, "Cannot construct Rule with null response!!!");
return new RuleDoc(fields);
}
-
public Set<String> terms(String fields) {
Set<String> tags = new HashSet<String>();
String key = "_ref";
public Rule getById(int id) {
SearchResponse response = getClient().prepareSearch(this.getIndexName())
.setTypes(this.getIndexType())
- .setQuery(QueryBuilders.termQuery(RuleNormalizer.RuleField.ID.field(),id))
+ .setQuery(QueryBuilders.termQuery(RuleNormalizer.RuleField.ID.field(), id))
.setSize(1)
.get();
SearchHit hit = response.getHits().getAt(0);
- if(hit == null){
+ if (hit == null) {
return null;
} else {
return toDoc(hit.getSource());
return node.client();
}
- private ESNode getNode() {
- return this.node;
- }
-
/* Component Methods */
@Override
@Override
public void stop() {
-
+ // nothing to do
}
// Scrolling within the index
/* Cluster And ES Stats/Client methods */
- private void initializeManagementIndex() {
- LOG.debug("Setup of Management Index for ES");
-
- // String index = indexDefinition.getManagementIndex();
- //
- // IndicesExistsResponse indexExistsResponse = getClient().admin().indices()
- // .prepareExists(index).execute().actionGet();
- //
- // if (!indexExistsResponse.isExists()) {
- // getClient().admin().indices().prepareCreate(index)
- // .setSettings(ImmutableSettings.builder()
- // .put("mapper.dynamic", true)
- // .put("number_of_replicas", 1)
- // .put("number_of_shards", 1)
- // .build())
- // .get();
- // }
- }
-
protected void initializeIndex() {
-
- initializeManagementIndex();
-
String index = this.getIndexName();
IndicesExistsResponse indexExistsResponse = getClient().admin().indices()
private final String indexName;
private final String indexType;
- private final String MANAGEMENT_INDEX = "sonarindex";
- private final String MANAGEMENT_TYPE = "index";
+ private static final String MANAGEMENT_INDEX = "sonarindex";
+ private static final String MANAGEMENT_TYPE = "index";
private IndexDefinition(String indexName, String indexType) {
this.indexName = indexName;
*/
package org.sonar.server.search;
-/**
- * @since 4.4
- */
public final class IndexProperties {
+ private IndexProperties() {
+ // only static stuff
+ }
+
public static enum ES_TYPE {
MEMORY, TRANSPORT, DATA
}
}
protected void afterExecute(Runnable r, Throwable t) {
-// LOG.info("Current active thread number: " + this.getActiveCount() +
-// " queue size:" + this.getQueue().size() +
-// " scheduled task number:" + this.getTaskCount());
super.afterExecute(r, t);
if (t != null) {
throw new IllegalStateException(t);
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
if (projectKey == null) {
ResourceDto project = resourceDao().getRootProjectByComponentKey(componentKey);
if (project == null) {
- return false;
+ return false;
}
projectKey = project.getKey();
}
}
@Test
- public void fail_to_create_custom_rule_when_rule_key_already_exits() throws Exception {
+ public void fail_to_create_custom_rule_when_rule_key_already_exists() throws Exception {
// insert template rule
RuleDto templateRule = createTemplateRule();
creator.create(newRule);
fail();
} catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("A rule with the key 'CUSTOM_RULE' already exits");
+ assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("A rule with the key 'CUSTOM_RULE' already exists");
}
}
}
@Test
- public void fail_to_create_manual_rule_when_rule_key_already_exits() throws Exception {
+ public void fail_to_create_manual_rule_when_rule_key_already_exists() throws Exception {
NewRule newRule = NewRule.createForManualRule("MANUAL_RULE")
.setName("My manual")
.setHtmlDescription("Some description");
creator.create(newRule);
fail();
} catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("A rule with the key 'MANUAL_RULE' already exits");
+ assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("A rule with the key 'MANUAL_RULE' already exists");
}
}
import org.sonar.wsclient.qprofile.internal.DefaultQProfileClient;
import org.sonar.wsclient.qualitygate.QualityGateClient;
import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
-import org.sonar.wsclient.rule.RuleClient;
-import org.sonar.wsclient.rule.internal.DefaultRuleClient;
import org.sonar.wsclient.system.SystemClient;
import org.sonar.wsclient.system.internal.DefaultSystemClient;
import org.sonar.wsclient.user.UserClient;
return new DefaultProjectClient(requestFactory);
}
- /**
- * New client to interact with web services related to rules
- */
- public RuleClient ruleClient() {
- return new DefaultRuleClient(requestFactory);
- }
-
/**
* New client to interact with web services related to quality gates
*/
String componentKey();
/**
- * Deprecated since 4.4. Use {@link #componentKey()} instead
+ * @deprecated since 4.4. Use {@link #componentKey()} instead
*/
@Deprecated
Long componentId();
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.rule;
-
-/**
- * Allows management of rules
- * @since 4.2
- */
-public interface RuleClient {
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.rule.internal;
-
-import org.sonar.wsclient.internal.HttpRequestFactory;
-import org.sonar.wsclient.rule.RuleClient;
-
-/**
- * Do not instantiate this class, but use {@link org.sonar.wsclient.SonarClient#ruleClient()}.
- */
-public class DefaultRuleClient implements RuleClient {
-
- private static final String ROOT_URL = "/api/rules";
-
- private final HttpRequestFactory requestFactory;
-
- public DefaultRuleClient(HttpRequestFactory requestFactory) {
- this.requestFactory = requestFactory;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-@ParametersAreNonnullByDefault package org.sonar.wsclient.rule.internal;
-
-import javax.annotation.ParametersAreNonnullByDefault;
import org.sonar.wsclient.project.internal.DefaultProjectClient;
import org.sonar.wsclient.qprofile.internal.DefaultQProfileClient;
import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
-import org.sonar.wsclient.rule.internal.DefaultRuleClient;
import org.sonar.wsclient.system.internal.DefaultSystemClient;
import org.sonar.wsclient.user.internal.DefaultUserClient;
assertThat(client.userClient()).isNotNull().isInstanceOf(DefaultUserClient.class);
assertThat(client.permissionClient()).isNotNull().isInstanceOf(DefaultPermissionClient.class);
assertThat(client.projectClient()).isNotNull().isInstanceOf(DefaultProjectClient.class);
- assertThat(client.ruleClient()).isNotNull().isInstanceOf(DefaultRuleClient.class);
assertThat(client.qualityGateClient()).isNotNull().isInstanceOf(DefaultQualityGateClient.class);
assertThat(client.qProfileClient()).isNotNull().isInstanceOf(DefaultQProfileClient.class);
assertThat(client.systemClient()).isNotNull().isInstanceOf(DefaultSystemClient.class);
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.rule.internal;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.sonar.wsclient.MockHttpServerInterceptor;
-import org.sonar.wsclient.internal.HttpRequestFactory;
-
-public class DefaultRuleClientTest {
-
- @Rule
- public MockHttpServerInterceptor httpServer = new MockHttpServerInterceptor();
-
- private DefaultRuleClient client;
-
- @Before
- public void initClient() {
- HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
- this.client = new DefaultRuleClient(requestFactory);
- }
-
-}