summaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/java
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-06-30 16:52:26 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-06-30 17:14:22 +0200
commitc95a564cd7ee1705f38062efe4f8750dffd6a8fa (patch)
treee94a9567229aac0ec664254c802365f9deac72c8 /sonar-server/src/main/java
parentd44ef046f3dd7d59397c681cb79ebe3173d915bb (diff)
downloadsonarqube-c95a564cd7ee1705f38062efe4f8750dffd6a8fa.tar.gz
sonarqube-c95a564cd7ee1705f38062efe4f8750dffd6a8fa.zip
Fix some quality flaws
Diffstat (limited to 'sonar-server/src/main/java')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/activity/ws/SearchAction.java7
-rw-r--r--sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java7
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfile.java6
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileName.java5
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java1
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java36
-rw-r--r--sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java28
-rw-r--r--sonar-server/src/main/java/org/sonar/server/search/IndexDefinition.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/search/IndexProperties.java7
-rw-r--r--sonar-server/src/main/java/org/sonar/server/search/IndexQueueWorker.java3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/user/UserSession.java8
12 files changed, 40 insertions, 76 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/activity/ws/SearchAction.java b/sonar-server/src/main/java/org/sonar/server/activity/ws/SearchAction.java
index 587de65ac8a..a6c40219281 100644
--- a/sonar-server/src/main/java/org/sonar/server/activity/ws/SearchAction.java
+++ b/sonar-server/src/main/java/org/sonar/server/activity/ws/SearchAction.java
@@ -72,7 +72,7 @@ public class SearchAction implements RequestHandler {
@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);
@@ -84,11 +84,6 @@ public class SearchAction implements RequestHandler {
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()) {
diff --git a/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java b/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java
index bec04c2fa8c..3e206296000 100644
--- a/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java
+++ b/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java
@@ -113,7 +113,7 @@ public class DuplicationsParser implements ServerComponent {
@Override
public int compare(@Nullable Duplication d1,
- @Nullable Duplication d2) {
+ @Nullable Duplication d2) {
if (d1 == null || d2 == null) {
return -1;
}
@@ -145,10 +145,10 @@ public class DuplicationsParser implements ServerComponent {
}
}
- 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;
}
@@ -161,7 +161,6 @@ public class DuplicationsParser implements ServerComponent {
}
}
-
public static class Duplication {
private final ComponentDto file;
private final Integer from, size;
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfile.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfile.java
index 40cfff102f7..ff068a999f0 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfile.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfile.java
@@ -35,11 +35,17 @@ public class QProfile {
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;
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileName.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileName.java
index ec97754abef..ae09c899cd5 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileName.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileName.java
@@ -39,14 +39,13 @@ public class QProfileName {
@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;
}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
index 8c0a2fc6181..f0b388b98cf 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
@@ -295,7 +295,6 @@ public class RegisterRules implements Startable {
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
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java
index 7cd89b2811e..30dd0f2c058 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java
@@ -196,13 +196,13 @@ public class RuleCreator implements ServerComponent {
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()));
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
index 87f197c8973..22b272b72cd 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
@@ -59,6 +59,7 @@ import org.sonar.server.search.Result;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -105,7 +106,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
}
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()) {
@@ -125,14 +126,14 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
}
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()) {
@@ -152,17 +153,10 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
}
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)
@@ -189,7 +183,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
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)
@@ -244,7 +238,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
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(
@@ -254,16 +248,15 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
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()));
@@ -322,7 +315,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
.size(10)
.minDocCount(1));
- /* the Tag facet */
+ /* the Tag facet */
query.addAggregation(AggregationBuilders
.terms("tags")
.field(RuleNormalizer.RuleField._TAGS.field())
@@ -330,7 +323,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
.size(10)
.minDocCount(1));
- /* the Repo facet */
+ /* the Repo facet */
query.addAggregation(AggregationBuilders
.terms("repositories")
.field(RuleNormalizer.RuleField.REPOSITORY.field())
@@ -340,7 +333,6 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
}
-
public Result<Rule> search(RuleQuery query, QueryOptions options) {
StopWatch profile = profiling.start("es", Profiling.Level.FULL);
@@ -369,14 +361,12 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
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";
@@ -406,11 +396,11 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
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());
diff --git a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
index 6460aca50f3..ddd10ef0e85 100644
--- a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
+++ b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
@@ -97,10 +97,6 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial
return node.client();
}
- private ESNode getNode() {
- return this.node;
- }
-
/* Component Methods */
@Override
@@ -112,7 +108,7 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial
@Override
public void stop() {
-
+ // nothing to do
}
// Scrolling within the index
@@ -157,29 +153,7 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial
/* 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()
diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexDefinition.java b/sonar-server/src/main/java/org/sonar/server/search/IndexDefinition.java
index 5185ae6b9ef..81d8929466e 100644
--- a/sonar-server/src/main/java/org/sonar/server/search/IndexDefinition.java
+++ b/sonar-server/src/main/java/org/sonar/server/search/IndexDefinition.java
@@ -26,8 +26,8 @@ public class IndexDefinition {
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;
diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexProperties.java b/sonar-server/src/main/java/org/sonar/server/search/IndexProperties.java
index 87a68428806..a2f67178aca 100644
--- a/sonar-server/src/main/java/org/sonar/server/search/IndexProperties.java
+++ b/sonar-server/src/main/java/org/sonar/server/search/IndexProperties.java
@@ -19,11 +19,12 @@
*/
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
}
diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexQueueWorker.java b/sonar-server/src/main/java/org/sonar/server/search/IndexQueueWorker.java
index d0c5ade780f..c2948b717d9 100644
--- a/sonar-server/src/main/java/org/sonar/server/search/IndexQueueWorker.java
+++ b/sonar-server/src/main/java/org/sonar/server/search/IndexQueueWorker.java
@@ -51,9 +51,6 @@ public class IndexQueueWorker extends ThreadPoolExecutor
}
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);
diff --git a/sonar-server/src/main/java/org/sonar/server/user/UserSession.java b/sonar-server/src/main/java/org/sonar/server/user/UserSession.java
index f8b9853fb50..1bfc6f48ff0 100644
--- a/sonar-server/src/main/java/org/sonar/server/user/UserSession.java
+++ b/sonar-server/src/main/java/org/sonar/server/user/UserSession.java
@@ -35,7 +35,11 @@ import org.sonar.server.platform.Platform;
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;
@@ -188,7 +192,7 @@ public class UserSession {
if (projectKey == null) {
ResourceDto project = resourceDao().getRootProjectByComponentKey(componentKey);
if (project == null) {
- return false;
+ return false;
}
projectKey = project.getKey();
}