From e0326c65ce7174157dc47c00f26b5e50e93b1883 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 16 Jun 2016 14:28:17 +0200 Subject: [PATCH] Fix Quality flaws --- .../java/org/sonar/search/SearchServer.java | 2 +- .../sonar/server/source/SourceService.java | 11 +++------- .../sonar/server/test/index/TestIndexer.java | 22 ++++++------------- .../java/org/sonar/db/issue/IssueDao.java | 7 ------ 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java index f21987fb994..ee6afaf3487 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java +++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java @@ -50,7 +50,7 @@ public class SearchServer implements Monitored { } // copied from https://github.com/elastic/elasticsearch/blob/v2.3.3/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java - private void initBootstrap() { + private static void initBootstrap() { // init lucene random seed. it will use /dev/urandom where available: StringHelper.randomId(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/SourceService.java b/server/sonar-server/src/main/java/org/sonar/server/source/SourceService.java index 57689404bc4..42d48210560 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/SourceService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/SourceService.java @@ -47,7 +47,7 @@ public class SourceService { * @param toInclusive starts from 1, must be greater than or equal param {@code from} */ public Optional> getLines(DbSession dbSession, String fileUuid, int from, int toInclusive) { - return getLines(dbSession, fileUuid, from, toInclusive, Functions.identity()); + return getLines(dbSession, fileUuid, from, toInclusive, Functions.identity()); } /** @@ -70,7 +70,7 @@ public class SourceService { return Optional.absent(); } DbFileSources.Data data = dto.getSourceData(); - return Optional.of((Iterable) FluentIterable.from(data.getLinesList()) + return Optional.of(FluentIterable.from(data.getLinesList()) .filter(new IsGreaterOrEqualThanLine(from)) .limit(toInclusive - from + 1) .transform(function)); @@ -81,12 +81,7 @@ public class SourceService { } private Function lineToHtml() { - return new Function() { - @Override - public String apply(@Nonnull DbFileSources.Line line) { - return htmlDecorator.getDecoratedSourceAsHtml(line.getSource(), line.getHighlighting(), line.getSymbols()); - } - }; + return line -> htmlDecorator.getDecoratedSourceAsHtml(line.getSource(), line.getHighlighting(), line.getSymbols()); } private enum LineToRaw implements Function { diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java index ad112c2f1b9..2b20ffdac67 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java @@ -19,10 +19,14 @@ */ package org.sonar.server.test.index; +import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID; +import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT; +import static org.sonar.server.test.index.TestIndexDefinition.INDEX; +import static org.sonar.server.test.index.TestIndexDefinition.TYPE; + import java.util.Iterator; import javax.annotation.Nullable; import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.index.query.QueryBuilders; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -31,11 +35,6 @@ import org.sonar.server.es.BulkIndexer; import org.sonar.server.es.EsClient; import org.sonar.server.source.index.FileSourcesUpdaterHelper; -import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID; -import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT; -import static org.sonar.server.test.index.TestIndexDefinition.INDEX; -import static org.sonar.server.test.index.TestIndexDefinition.TYPE; - /** * Add to Elasticsearch index {@link TestIndexDefinition} the rows of * db table FILE_SOURCES of type TEST that are not indexed yet @@ -51,12 +50,7 @@ public class TestIndexer extends BaseIndexer { public void index(final String projectUuid) { deleteByProject(projectUuid); - super.index(new IndexerTask() { - @Override - public long index(long lastUpdatedAt) { - return doIndex(lastUpdatedAt, projectUuid); - } - }); + super.index(lastUpdatedAt -> doIndex(lastUpdatedAt, projectUuid)); } public long index(Iterator dbRows) { @@ -90,9 +84,7 @@ public class TestIndexer extends BaseIndexer { bulk.start(); while (dbRows.hasNext()) { FileSourcesUpdaterHelper.Row row = dbRows.next(); - for (UpdateRequest updateRequest : row.getUpdateRequests()) { - bulk.add(updateRequest); - } + row.getUpdateRequests().forEach(bulk::add); maxUpdatedAt = Math.max(maxUpdatedAt, row.getUpdatedAt()); } bulk.stop(); diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java index d5a0eef5d9a..0a4526f36db 100644 --- a/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java +++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java @@ -31,7 +31,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.sonar.db.Dao; import org.sonar.db.DbSession; -import org.sonar.db.MyBatis; import org.sonar.db.RowNotFoundException; import static com.google.common.collect.FluentIterable.from; @@ -39,12 +38,6 @@ import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class IssueDao implements Dao { - private final MyBatis mybatis; - - public IssueDao(MyBatis mybatis) { - this.mybatis = mybatis; - } - public Optional selectByKey(DbSession session, String key) { return Optional.fromNullable(mapper(session).selectByKey(key)); } -- 2.39.5