diff options
8 files changed, 63 insertions, 73 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java index 32b760bc463..07fdef297f6 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java @@ -52,17 +52,17 @@ public class TendencyAnalyser { for (Double p : values) { if (p != null) { nullValuesYList = false; - //SumY calculation + // SumY calculation sumY += p; // sumYPower2 calculation sumYPower2 += p * p; - //sumXY calculation + // sumXY calculation sumXY += p * (i + 1); - //SumX calculation + // SumX calculation sumX += (i + 1); - //sumXPower2 calculation + // sumXPower2 calculation sumXPower2 += (i + 1) * (i + 1); - //Point number calculation + // Point number calculation nbrPoints++; } i++; @@ -77,10 +77,10 @@ public class TendencyAnalyser { SlopeData result = new SlopeData(); - //yIntercept Calculation the value when X equals zero + // yIntercept Calculation the value when X equals zero result.setYIntercept(n1 / d); // Slope Calculation - if (n0 == 0d && d == 0d) { + if (Double.doubleToRawLongBits(n0) == 0L && Double.doubleToRawLongBits(d) == 0L) { result.setSlope(0.0); } else { Double slope = n0 / d; @@ -94,7 +94,7 @@ public class TendencyAnalyser { result.setSumXY(sumXY); result.setSumYPower2(sumYPower2); - if (sumXPower2 == 0 || sumYPower2 == 0) { + if (Double.doubleToRawLongBits(sumXPower2) == 0L || Double.doubleToRawLongBits(sumYPower2) == 0L) { result.setCorrelationRate(0.0); } else { result.setCorrelationRate(sumXY / Math.sqrt(sumXPower2 * sumYPower2)); @@ -103,7 +103,6 @@ public class TendencyAnalyser { return result; } - static class SlopeData { private double sumXPower2; private double sumYPower2; diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java index dc348a54516..a69e61c4487 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java @@ -19,6 +19,7 @@ */ package org.sonar.process.monitor; +import org.slf4j.LoggerFactory; import org.sonar.process.MessageException; import org.sonar.process.ProcessCommands; import org.sonar.process.ProcessUtils; @@ -90,9 +91,9 @@ class ProcessRef { // signal is sent, waiting for shutdown hooks to be executed (or not... it depends on OS) process.waitFor(); - } catch (InterruptedException ignored) { + } catch (InterruptedException e) { // can't wait for the termination of process. Let's assume it's down. - // TODO log warning + LoggerFactory.getLogger(getClass()).warn(String.format("Interrupted while stopping process %s", key), e); } } ProcessUtils.closeStreams(process); diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/BaseTangleIndexDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/design/BaseTangleIndexDecorator.java index 509cedcc7f1..069b5707236 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/design/BaseTangleIndexDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/design/BaseTangleIndexDecorator.java @@ -82,9 +82,8 @@ public class BaseTangleIndexDecorator implements Decorator { return context.getMeasure(tangleIndexMetric) == null; } - private double compute(double tangles, double totalWeight) { - if (totalWeight==0.0) { + if (Double.doubleToRawLongBits(totalWeight) == 0L) { return 0.0; } double result = 2 * tangles / totalWeight; diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java index 15092940d68..550ce46b6d3 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java @@ -44,7 +44,6 @@ import java.util.UUID; */ public final class IssueDto extends Dto<String> implements Serializable { - private Long id; private String kee; private Long componentId; @@ -87,12 +86,10 @@ public final class IssueDto extends Dto<String> implements Serializable { return getKee(); } - @Deprecated public Long getId() { return id; } - @Deprecated public IssueDto setId(@Nullable Long id) { this.id = id; return this; @@ -118,9 +115,8 @@ public final class IssueDto extends Dto<String> implements Serializable { } /** - * @deprecated please use setComponent(ComponentDto component) + * please use setComponent(ComponentDto component) */ - @Deprecated public IssueDto setComponentId(Long componentId) { this.componentId = componentId; return this; @@ -137,9 +133,8 @@ public final class IssueDto extends Dto<String> implements Serializable { } /** - * @deprecated please use setRootComponent + * please use setRootComponent */ - @Deprecated public IssueDto setRootComponentId(Long rootComponentId) { this.rootComponentId = rootComponentId; return this; @@ -159,9 +154,8 @@ public final class IssueDto extends Dto<String> implements Serializable { } /** - * @deprecated please use setRule(RuleDto rule) + * please use setRule(RuleDto rule) */ - @Deprecated public IssueDto setRuleId(Integer ruleId) { this.ruleId = ruleId; return this; diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java b/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java index 4df446c8dd4..9c42c50fb96 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java @@ -151,26 +151,6 @@ public class DbTemplate implements ServerComponent { return columnTypes; } - public int getRowCount(DataSource dataSource, String table) { - Connection connection = null; - Statement statement = null; - ResultSet resultSet = null; - try { - connection = dataSource.getConnection(); - statement = connection.createStatement(); - resultSet = statement.executeQuery("SELECT count(*) FROM " + table); - - return resultSet.next() ? resultSet.getInt(1) : 0; - } catch (SQLException e) { - LOG.error("Fail to get row count for table " + table, e); - throw new SonarException("Fail to get row count for table " + table, e); - } finally { - DbUtils.closeQuietly(resultSet); - DbUtils.closeQuietly(statement); - DbUtils.closeQuietly(connection); - } - } - public DbTemplate truncate(DataSource dataSource, String table) { Connection connection = null; Statement statement = null; diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/PreviewDatabaseFactoryTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/PreviewDatabaseFactoryTest.java index 0e4dbbe9b3d..0aaf8ad5061 100644 --- a/sonar-core/src/test/java/org/sonar/core/persistence/PreviewDatabaseFactoryTest.java +++ b/sonar-core/src/test/java/org/sonar/core/persistence/PreviewDatabaseFactoryTest.java @@ -32,7 +32,6 @@ import org.sonar.api.config.Settings; import org.sonar.core.profiling.Profiling; import javax.sql.DataSource; - import java.io.File; import java.io.IOException; import java.sql.Connection; @@ -68,9 +67,9 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase { byte[] db = createDb(null); dataSource = createDatabase(db); - assertThat(rowCount("projects")).isZero(); - assertThat(rowCount("events")).isZero(); - assertThat(rowCount("users")).isEqualTo(3); + assertThat(countRows("projects")).isZero(); + assertThat(countRows("events")).isZero(); + assertThat(countRows("users")).isEqualTo(3); // Verify that password column was not exported into dryRun DB assertThat(getUserPassword(dataSource, 1)).isNull(); } @@ -86,10 +85,10 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase { byte[] database = createDb(123L); dataSource = createDatabase(database); - assertThat(rowCount("projects")).isEqualTo(1); - assertThat(rowCount("snapshots")).isEqualTo(1); - assertThat(rowCount("project_measures")).isEqualTo(1); - assertThat(rowCount("events")).isEqualTo(2); + assertThat(countRows("projects")).isEqualTo(1); + assertThat(countRows("snapshots")).isEqualTo(1); + assertThat(countRows("project_measures")).isEqualTo(1); + assertThat(countRows("events")).isEqualTo(2); } @Test @@ -99,7 +98,7 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase { byte[] database = createDb(399L); dataSource = createDatabase(database); - assertThat(rowCount("issues")).isEqualTo(1); + assertThat(countRows("issues")).isEqualTo(1); } @Test @@ -109,11 +108,11 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase { // 300 : root module -> export issues of all modules byte[] database = createDb(300L); dataSource = createDatabase(database); - assertThat(rowCount("issues")).isEqualTo(1); - assertThat(rowCount("projects")).isEqualTo(4); - assertThat(rowCount("snapshots")).isEqualTo(4); - assertThat(rowCount("snapshot_data")).isEqualTo(2); - assertThat(rowCount("project_measures")).isEqualTo(4); + assertThat(countRows("issues")).isEqualTo(1); + assertThat(countRows("projects")).isEqualTo(4); + assertThat(countRows("snapshots")).isEqualTo(4); + assertThat(countRows("snapshot_data")).isEqualTo(2); + assertThat(countRows("project_measures")).isEqualTo(4); } @Test @@ -123,10 +122,10 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase { // 301 : sub module with 1 closed issue and 1 open issue byte[] database = createDb(301L); dataSource = createDatabase(database); - assertThat(rowCount("issues")).isEqualTo(1); - assertThat(rowCount("projects")).isEqualTo(2); - assertThat(rowCount("snapshots")).isEqualTo(2); - assertThat(rowCount("project_measures")).isEqualTo(4); + assertThat(countRows("issues")).isEqualTo(1); + assertThat(countRows("projects")).isEqualTo(2); + assertThat(countRows("snapshots")).isEqualTo(2); + assertThat(countRows("project_measures")).isEqualTo(4); } @Test @@ -136,7 +135,7 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase { // 302 : sub module without any issues byte[] database = createDb(302L); dataSource = createDatabase(database); - assertThat(rowCount("issues")).isEqualTo(0); + assertThat(countRows("issues")).isEqualTo(0); } @Test @@ -145,9 +144,9 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase { byte[] database = createDb(null); dataSource = createDatabase(database); - assertThat(rowCount("permission_templates")).isEqualTo(1); - assertThat(rowCount("perm_templates_users")).isEqualTo(1); - assertThat(rowCount("perm_templates_groups")).isEqualTo(1); + assertThat(countRows("permission_templates")).isEqualTo(1); + assertThat(countRows("perm_templates_users")).isEqualTo(1); + assertThat(countRows("perm_templates_groups")).isEqualTo(1); } private BasicDataSource createDatabase(byte[] db) throws IOException { @@ -156,8 +155,23 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase { return new DbTemplate(new Profiling(new Settings())).dataSource("org.h2.Driver", "sonar", "sonar", "jdbc:h2:" + file.getAbsolutePath().replaceAll(".h2.db", "")); } - private int rowCount(String table) { - return new DbTemplate(new Profiling(new Settings())).getRowCount(dataSource, table); + private int countRows(String table) { + Connection connection = null; + Statement statement = null; + ResultSet resultSet = null; + try { + connection = dataSource.getConnection(); + statement = connection.createStatement(); + resultSet = statement.executeQuery("SELECT count(*) FROM " + table); + + return resultSet.next() ? resultSet.getInt(1) : 0; + } catch (SQLException e) { + throw new IllegalStateException("Fail to get row count for table " + table, e); + } finally { + DbUtils.closeQuietly(resultSet); + DbUtils.closeQuietly(statement); + DbUtils.closeQuietly(connection); + } } public String getUserPassword(DataSource dataSource, int userId) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/WeightedMeanAggregationFormula.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/WeightedMeanAggregationFormula.java index 61f4d7ccbae..c6daf0289ac 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/WeightedMeanAggregationFormula.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/WeightedMeanAggregationFormula.java @@ -63,7 +63,7 @@ public class WeightedMeanAggregationFormula implements Formula { return null; } - double result = count==0.0 ? 0.0 : sum/count; + double result = Double.doubleToRawLongBits(count)==0L ? 0.0 : sum/count; return new Measure(context.getTargetMetric(), result); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypeTree.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypeTree.java index 7ee68787081..c6e4031f9e2 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypeTree.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypeTree.java @@ -21,11 +21,15 @@ package org.sonar.api.resources; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; -import com.google.common.collect.*; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableListMultimap; +import com.google.common.collect.ListMultimap; +import com.google.common.collect.Lists; import org.sonar.api.ServerExtension; import org.sonar.api.task.TaskExtension; -import javax.annotation.concurrent.Immutable; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -33,12 +37,11 @@ import java.util.List; /** * @since 2.14 */ -@Immutable public class ResourceTypeTree implements TaskExtension, ServerExtension { - private List<ResourceType> types; - private ListMultimap<String, String> relations; - private ResourceType root; + private final List<ResourceType> types; + private final ListMultimap<String, String> relations; + private final ResourceType root; private ResourceTypeTree(Builder builder) { this.types = ImmutableList.copyOf(builder.types); |