aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-08-28 15:47:30 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-09-07 08:33:31 +0200
commitdb9ce02d06f81e31e108c2e0a4679b3c97c2013b (patch)
tree8c414cb06acbe9e3127c3bba00e2946b9fa3479f
parent0d4d37faf7a8c7e1c252c24c286d830802cfbb7b (diff)
downloadsonarqube-db9ce02d06f81e31e108c2e0a4679b3c97c2013b.tar.gz
sonarqube-db9ce02d06f81e31e108c2e0a4679b3c97c2013b.zip
SONAR-9664 Apply feedback
-rw-r--r--server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDto.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java3
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java3
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/plugin/PluginMapper.xml13
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginDaoTest.java21
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginTesting.java2
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/plugin/PluginDaoTest/shared.xml4
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePlugins.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/Rule.java1
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/RuleImpl.java1
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualityprofile/ActiveRule.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/startup/GeneratePluginIndex.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPlugins.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java18
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java16
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java2
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/insert_new_plugins-result.xml4
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins-result.xml4
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins.xml4
25 files changed, 68 insertions, 73 deletions
diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
index 2b1dc43cb0a..55bc327fb2a 100644
--- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
+++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
@@ -685,7 +685,7 @@ CREATE TABLE "PLUGINS" (
"UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
"KEE" VARCHAR(200) NOT NULL,
"BASE_PLUGIN_KEY" VARCHAR(200),
- "HASH" VARCHAR(200) NOT NULL,
+ "FILE_HASH" VARCHAR(200) NOT NULL,
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDao.java
index 68705f81a33..d7196d7670d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDao.java
@@ -42,10 +42,6 @@ public class PluginDao implements Dao {
mapper(dbSession).update(dto);
}
- public void delete(DbSession dbSession, PluginDto dto) {
- mapper(dbSession).delete(dto.getUuid());
- }
-
private static PluginMapper mapper(DbSession dbSession) {
return dbSession.getMapper(PluginMapper.class);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDto.java
index 13c512ff328..baeba50bc68 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDto.java
@@ -30,7 +30,7 @@ public class PluginDto {
/** Base plugin key, can be null */
private String basePluginKey;
/** JAR file MD5 checksum, can't be null */
- private String hash;
+ private String fileHash;
/** Time plugin was first installed */
private long createdAt;
/** Time of last plugin update (=md5 change) */
@@ -64,12 +64,12 @@ public class PluginDto {
return this;
}
- public String getHash() {
- return hash;
+ public String getFileHash() {
+ return fileHash;
}
- public PluginDto setHash(String s) {
- this.hash = s;
+ public PluginDto setFileHash(String s) {
+ this.fileHash = s;
return this;
}
@@ -97,7 +97,7 @@ public class PluginDto {
.append("uuid", uuid)
.append("key", kee)
.append("basePluginKey", basePluginKey)
- .append("jarMd5", hash)
+ .append("fileHash", fileHash)
.append("createdAt", createdAt)
.append("updatedAt", updatedAt)
.toString();
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java
index 13c687305c1..47f2b72bb9f 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java
@@ -295,11 +295,12 @@ public class RuleDefinitionDto {
return this;
}
+ @CheckForNull
public String getPluginKey() {
return pluginKey;
}
- public RuleDefinitionDto setPluginKey(String pluginKey) {
+ public RuleDefinitionDto setPluginKey(@Nullable String pluginKey) {
this.pluginKey = pluginKey;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java
index e5861debe31..c1c6a11cd99 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java
@@ -89,11 +89,12 @@ public class RuleDto {
return this;
}
+ @CheckForNull
public String getPluginKey() {
return definition.getPluginKey();
}
- public RuleDto setPluginKey(String s) {
+ public RuleDto setPluginKey(@Nullable String s) {
definition.setPluginKey(s);
return this;
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/plugin/PluginMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/plugin/PluginMapper.xml
index a6fdb0c199a..0ff5f6cf543 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/plugin/PluginMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/plugin/PluginMapper.xml
@@ -8,7 +8,7 @@
uuid,
kee,
base_plugin_key as basePluginKey,
- hash,
+ file_hash as fileHash,
created_at as createdAt,
updated_at as updatedAt
</sql>
@@ -30,14 +30,14 @@
uuid,
kee,
base_plugin_key,
- hash,
+ file_hash,
created_at,
updated_at
) values (
#{uuid,jdbcType=VARCHAR},
#{kee,jdbcType=VARCHAR},
#{basePluginKey,jdbcType=VARCHAR},
- #{hash,jdbcType=VARCHAR},
+ #{fileHash,jdbcType=VARCHAR},
#{createdAt,jdbcType=TIMESTAMP},
#{updatedAt,jdbcType=TIMESTAMP}
)
@@ -46,15 +46,10 @@
<update id="update" parameterType="org.sonar.db.plugin.PluginDto">
update plugins set
base_plugin_key=#{basePluginKey,jdbcType=VARCHAR},
- hash=#{hash,jdbcType=VARCHAR},
+ file_hash=#{fileHash,jdbcType=VARCHAR},
updated_at=#{updatedAt,jdbcType=BIGINT}
where
uuid=#{uuid,jdbcType=VARCHAR}
</update>
- <delete id="delete" parameterType="String">
- delete from plugins
- where
- uuid = #{uuid,jdbcType=VARCHAR}
- </delete>
</mapper>
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginDaoTest.java
index fda7a9581d1..bb646d180f4 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginDaoTest.java
@@ -48,7 +48,7 @@ public class PluginDaoTest {
assertThat(plugin.get().getUuid()).isEqualTo("a");
assertThat(plugin.get().getKee()).isEqualTo("java");
assertThat(plugin.get().getBasePluginKey()).isNull();
- assertThat(plugin.get().getHash()).isEqualTo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ assertThat(plugin.get().getFileHash()).isEqualTo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
assertThat(plugin.get().getCreatedAt()).isEqualTo(1500000000000L);
assertThat(plugin.get().getUpdatedAt()).isEqualTo(1600000000000L);
}
@@ -68,7 +68,7 @@ public class PluginDaoTest {
.setUuid("c")
.setKee("javascript")
.setBasePluginKey("java")
- .setHash("cccccccccccccccccccccccccccccccc")
+ .setFileHash("cccccccccccccccccccccccccccccccc")
.setCreatedAt(1L)
.setUpdatedAt(2L));
@@ -77,7 +77,7 @@ public class PluginDaoTest {
assertThat(plugin.get().getUuid()).isEqualTo("c");
assertThat(plugin.get().getKee()).isEqualTo("javascript");
assertThat(plugin.get().getBasePluginKey()).isEqualTo("java");
- assertThat(plugin.get().getHash()).isEqualTo("cccccccccccccccccccccccccccccccc");
+ assertThat(plugin.get().getFileHash()).isEqualTo("cccccccccccccccccccccccccccccccc");
assertThat(plugin.get().getCreatedAt()).isEqualTo(1L);
assertThat(plugin.get().getUpdatedAt()).isEqualTo(2L);
}
@@ -89,7 +89,7 @@ public class PluginDaoTest {
PluginDto plugin = underTest.selectByKey(db.getSession(), "java").get();
plugin.setBasePluginKey("foo");
- plugin.setHash("abc");
+ plugin.setFileHash("abc");
plugin.setUpdatedAt(3L);
underTest.update(db.getSession(), plugin);
@@ -98,19 +98,8 @@ public class PluginDaoTest {
assertThat(plugin.getUuid()).isEqualTo("a");
assertThat(plugin.getKee()).isEqualTo("java");
assertThat(plugin.getBasePluginKey()).isEqualTo("foo");
- assertThat(plugin.getHash()).isEqualTo("abc");
+ assertThat(plugin.getFileHash()).isEqualTo("abc");
assertThat(plugin.getCreatedAt()).isEqualTo(1500000000000L);
assertThat(plugin.getUpdatedAt()).isEqualTo(3L);
}
-
- @Test
- public void delete() {
- db.prepareDbUnit(getClass(), "shared.xml");
-
- underTest.delete(db.getSession(), new PluginDto()
- .setUuid("a"));
-
- assertThat(underTest.selectAll(db.getSession())).hasSize(1);
- }
-
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginTesting.java b/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginTesting.java
index a8be4522258..d75e017ed4b 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginTesting.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginTesting.java
@@ -38,7 +38,7 @@ public class PluginTesting {
return new PluginDto()
.setUuid(uuid)
.setKee(uuid)
- .setHash(randomAlphanumeric(32))
+ .setFileHash(randomAlphanumeric(32))
.setCreatedAt(nextLong())
.setUpdatedAt(nextLong());
}
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/plugin/PluginDaoTest/shared.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/plugin/PluginDaoTest/shared.xml
index 016bddf0d08..a667eb84ae4 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/plugin/PluginDaoTest/shared.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/plugin/PluginDaoTest/shared.xml
@@ -3,7 +3,7 @@
<plugins uuid="a"
kee="java"
base_plugin_key="[null]"
- hash="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ file_hash="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
created_at="1500000000000"
updated_at="1600000000000"
/>
@@ -11,7 +11,7 @@
<plugins uuid="b"
kee="javacustom"
base_plugin_key="java"
- hash="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
+ file_hash="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
created_at="1500000000000"
updated_at="1600000000000"
/>
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePlugins.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePlugins.java
index 9b28fa45fd7..4c36d3ddf71 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePlugins.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePlugins.java
@@ -56,7 +56,7 @@ public class CreateTablePlugins extends DdlChange {
.setIsNullable(true)
.build())
.addColumn(newVarcharColumnDefBuilder()
- .setColumnName("hash")
+ .setColumnName("file_hash")
.setLimit(200)
.setIsNullable(false)
.build())
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest.java
index 91f3f4b92f6..f4b14a5f944 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTablePluginsTest.java
@@ -49,7 +49,7 @@ public class CreateTablePluginsTest {
db.assertPrimaryKey(TABLE, "pk_plugins", "uuid");
db.assertColumnDefinition(TABLE, "kee", Types.VARCHAR, 200, false);
db.assertColumnDefinition(TABLE, "base_plugin_key", Types.VARCHAR, 200, true);
- db.assertColumnDefinition(TABLE, "hash", Types.VARCHAR, 200, false);
+ db.assertColumnDefinition(TABLE, "file_hash", Types.VARCHAR, 200, false);
db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false);
db.assertColumnDefinition(TABLE, "updated_at", Types.BIGINT, null, false);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java
index 873cd23b3af..1ed3b618c8a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculator.java
@@ -91,6 +91,10 @@ public class IssueCreationDateCalculator extends IssueVisitor {
private boolean ruleImplementationChanged(ActiveRule activeRule, long lastAnalysisDate) {
String pluginKey = activeRule.getPluginKey();
+ if (pluginKey == null) {
+ return false;
+ }
+
ScannerPlugin scannerPlugin = Optional.ofNullable(analysisMetadataHolder.getScannerPluginsByKey().get(pluginKey))
.orElseThrow(illegalStateException("The rule %s is declared to come from plugin %s, but this plugin was not used by scanner.", activeRule.getRuleKey(), pluginKey));
return pluginIsNew(scannerPlugin, lastAnalysisDate)
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/Rule.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/Rule.java
index 3c6cb7b4207..e8f131848f2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/Rule.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/Rule.java
@@ -46,5 +46,6 @@ public interface Rule {
@CheckForNull
DebtRemediationFunction getRemediationFunction();
+ @CheckForNull
String getPluginKey();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/RuleImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/RuleImpl.java
index 56aab9d104d..3104138ba31 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/RuleImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/RuleImpl.java
@@ -91,6 +91,7 @@ public class RuleImpl implements Rule {
return type;
}
+ @CheckForNull
@Override
public String getPluginKey() {
return pluginKey;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualityprofile/ActiveRule.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualityprofile/ActiveRule.java
index 68465731a9c..b04d54afdcb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualityprofile/ActiveRule.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualityprofile/ActiveRule.java
@@ -21,6 +21,8 @@ package org.sonar.server.computation.task.projectanalysis.qualityprofile;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.sonar.api.rule.RuleKey;
@@ -32,7 +34,7 @@ public class ActiveRule {
private final long createdAt;
private final String pluginKey;
- public ActiveRule(RuleKey ruleKey, String severity, Map<String, String> params, long createdAt, String pluginKey) {
+ public ActiveRule(RuleKey ruleKey, String severity, Map<String, String> params, long createdAt, @Nullable String pluginKey) {
this.ruleKey = ruleKey;
this.severity = severity;
this.pluginKey = pluginKey;
@@ -56,6 +58,7 @@ public class ActiveRule {
return createdAt;
}
+ @CheckForNull
public String getPluginKey() {
return pluginKey;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java
index 0d5595ecd67..04050fd6534 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java
@@ -72,7 +72,7 @@ public class InstalledAction implements PluginsWsAction {
.setSince("5.2")
.setChangelog(
new Change("6.6", "The 'filename' field is added"),
- new Change("6.6", "The 'hash' field is added"),
+ new Change("6.6", "The 'fileHash' field is added"),
new Change("6.6", "The 'sonarLintSupported' field is added"),
new Change("6.6", "The 'updatedAt' field is added"))
.setHandler(this)
diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java
index 44716a3ab7d..44c362d6c45 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java
@@ -95,7 +95,7 @@ public class PluginWSCommons {
if (pluginDto != null) {
json.prop(PROPERTY_FILENAME, pluginInfo.getNonNullJarFile().getName());
json.prop(PROPERTY_SONARLINT_SUPPORTED, pluginInfo.isSonarLintSupported());
- json.prop(PROPERTY_HASH, pluginDto.getHash());
+ json.prop(PROPERTY_HASH, pluginDto.getFileHash());
json.prop(PROPERTY_UPDATED_AT, pluginDto.getUpdatedAt());
}
json.prop(PROPERTY_DESCRIPTION, pluginInfo.getDescription());
diff --git a/server/sonar-server/src/main/java/org/sonar/server/startup/GeneratePluginIndex.java b/server/sonar-server/src/main/java/org/sonar/server/startup/GeneratePluginIndex.java
index 15527cc90c4..30eaad50656 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/startup/GeneratePluginIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/startup/GeneratePluginIndex.java
@@ -27,7 +27,7 @@ import java.io.Writer;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.CharUtils;
-import org.picocontainer.Startable;
+import org.sonar.api.Startable;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPlugins.java b/server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPlugins.java
index 58eb25bde36..248bf994af3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPlugins.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPlugins.java
@@ -22,7 +22,7 @@ package org.sonar.server.startup;
import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;
-import org.picocontainer.Startable;
+import org.sonar.api.Startable;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -83,15 +83,15 @@ public class RegisterPlugins implements Startable {
.setUuid(uuidFactory.create())
.setKee(pluginInfo.getKey())
.setBasePluginKey(pluginInfo.getBasePlugin())
- .setHash(newJarMd5)
+ .setFileHash(newJarMd5)
.setCreatedAt(now)
.setUpdatedAt(now);
dbClient.pluginDao().insert(dbSession, pluginDto);
- } else if (!previousDto.getHash().equals(newJarMd5)) {
+ } else if (!previousDto.getFileHash().equals(newJarMd5)) {
LOG.debug("Update plugin {}", pluginInfo.getKey());
previousDto
.setBasePluginKey(pluginInfo.getBasePlugin())
- .setHash(newJarMd5)
+ .setFileHash(newJarMd5)
.setUpdatedAt(now);
dbClient.pluginDao().update(dbSession, previousDto);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java
index f0e84c58a06..8f3cf22439e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCreationDateCalculatorTest.java
@@ -24,6 +24,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.core.issue.DefaultIssue;
@@ -33,7 +34,7 @@ import org.sonar.db.protobuf.DbIssues.Flow;
import org.sonar.db.protobuf.DbIssues.Location;
import org.sonar.db.protobuf.DbIssues.Locations.Builder;
import org.sonar.server.computation.task.projectanalysis.analysis.Analysis;
-import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
+import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.task.projectanalysis.analysis.ScannerPlugin;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule;
@@ -53,8 +54,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class IssueCreationDateCalculatorTest {
+ @Rule
+ public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
- private AnalysisMetadataHolder analysisMetadataHolder;
private ScmInfoRepository scmInfoRepository;
private IssueFieldsSetter issueUpdater;
private ActiveRulesHolder activeRulesHolder;
@@ -69,9 +71,9 @@ public class IssueCreationDateCalculatorTest {
@Before
public void before() {
- analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
scannerPlugins = new HashMap<>();
- when(analysisMetadataHolder.getScannerPluginsByKey()).thenReturn(scannerPlugins);
+ analysisMetadataHolder.setScannerPluginsByKey(scannerPlugins);
+ analysisMetadataHolder.setAnalysisDate(new Date());
scmInfoRepository = mock(ScmInfoRepository.class);
issueUpdater = mock(IssueFieldsSetter.class);
activeRulesHolder = mock(ActiveRulesHolder.class);
@@ -181,6 +183,7 @@ public class IssueCreationDateCalculatorTest {
@Test
public void should_change_date_if_scm_is_available_and_first_analysis() {
+ analysisMetadataHolder.setBaseAnalysis(null);
currentAnalysisIs(3000L);
newIssue();
@@ -226,6 +229,7 @@ public class IssueCreationDateCalculatorTest {
@Test
public void should_use_primary_location_when_backdating() {
+ analysisMetadataHolder.setBaseAnalysis(null);
currentAnalysisIs(3000L);
newIssue();
@@ -240,6 +244,7 @@ public class IssueCreationDateCalculatorTest {
@Test
public void should_use_flows_location_when_backdating() {
+ analysisMetadataHolder.setBaseAnalysis(null);
currentAnalysisIs(3000L);
newIssue();
@@ -271,8 +276,7 @@ public class IssueCreationDateCalculatorTest {
}
private void previousAnalysisWas(long analysisDate) {
- when(analysisMetadataHolder.getBaseAnalysis())
- .thenReturn(baseAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseAnalysis);
when(baseAnalysis.getCreatedAt())
.thenReturn(analysisDate);
}
@@ -286,7 +290,7 @@ public class IssueCreationDateCalculatorTest {
}
private void currentAnalysisIs(long analysisDate) {
- when(analysisMetadataHolder.getAnalysisDate()).thenReturn(analysisDate);
+ analysisMetadataHolder.setAnalysisDate(analysisDate);
}
private void newIssue() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java
index f7e0f39296a..9e113765a43 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java
@@ -104,7 +104,7 @@ public class InstalledActionTest {
of(new PluginInfo("").setName("").setJarFile(new File(""))));
db.pluginDbTester().insertPlugin(
p -> p.setKee(""),
- p -> p.setHash("abcdA"),
+ p -> p.setFileHash("abcdA"),
p -> p.setUpdatedAt(111111L));
underTest.handle(request, response);
@@ -130,7 +130,7 @@ public class InstalledActionTest {
.setJarFile(new File(getClass().getResource(jarFilename).toURI()))));
db.pluginDbTester().insertPlugin(
p -> p.setKee("plugKey"),
- p -> p.setHash("abcdplugKey"),
+ p -> p.setFileHash("abcdplugKey"),
p -> p.setUpdatedAt(111111L));
underTest.handle(request, response);
@@ -184,7 +184,7 @@ public class InstalledActionTest {
db.pluginDbTester().insertPlugin(
p -> p.setKee("plugKey"),
- p -> p.setHash("abcdplugKey"),
+ p -> p.setFileHash("abcdplugKey"),
p -> p.setUpdatedAt(111111L));
when(request.paramAsStrings(Param.FIELDS)).thenReturn(singletonList("category"));
@@ -223,19 +223,19 @@ public class InstalledActionTest {
db.pluginDbTester().insertPlugin(
p -> p.setKee("A"),
- p -> p.setHash("abcdA"),
+ p -> p.setFileHash("abcdA"),
p -> p.setUpdatedAt(111111L));
db.pluginDbTester().insertPlugin(
p -> p.setKee("B"),
- p -> p.setHash("abcdB"),
+ p -> p.setFileHash("abcdB"),
p -> p.setUpdatedAt(222222L));
db.pluginDbTester().insertPlugin(
p -> p.setKee("C"),
- p -> p.setHash("abcdC"),
+ p -> p.setFileHash("abcdC"),
p -> p.setUpdatedAt(333333L));
db.pluginDbTester().insertPlugin(
p -> p.setKee("D"),
- p -> p.setHash("abcdD"),
+ p -> p.setFileHash("abcdD"),
p -> p.setUpdatedAt(444444L));
underTest.handle(request, response);
@@ -261,7 +261,7 @@ public class InstalledActionTest {
db.pluginDbTester().insertPlugin(
p -> p.setKee("A"),
- p -> p.setHash("abcdA"),
+ p -> p.setFileHash("abcdA"),
p -> p.setUpdatedAt(111111L));
underTest.handle(request, response);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java
index e98d2b3f8d7..f3ddea9942b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java
@@ -65,7 +65,7 @@ public class PluginWSCommonsTest {
@Test
public void verify_properties_written_by_writePluginMetadata_with_dto() {
- underTest.writePluginInfo(jsonWriter, gitPluginInfo(), null, new PluginDto().setHash("abcdef123456").setUpdatedAt(123456L));
+ underTest.writePluginInfo(jsonWriter, gitPluginInfo(), null, new PluginDto().setFileHash("abcdef123456").setUpdatedAt(123456L));
jsonWriter.close();
assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo("{" +
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/insert_new_plugins-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/insert_new_plugins-result.xml
index 37b152ccac3..61b7da84dd9 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/insert_new_plugins-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/insert_new_plugins-result.xml
@@ -1,6 +1,6 @@
<dataset>
- <plugins uuid="a" kee="java" base_plugin_key="[null]" hash="bd451e47a1aa76e73da0359cef63dd63" created_at="12345" updated_at="12345"/>
- <plugins uuid="b" kee="javacustom" base_plugin_key="java" hash="de9b2de3ddc0680904939686c0dba5be" created_at="12345" updated_at="12345"/>
+ <plugins uuid="a" kee="java" base_plugin_key="[null]" file_hash="bd451e47a1aa76e73da0359cef63dd63" created_at="12345" updated_at="12345"/>
+ <plugins uuid="b" kee="javacustom" base_plugin_key="java" file_hash="de9b2de3ddc0680904939686c0dba5be" created_at="12345" updated_at="12345"/>
</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins-result.xml
index 037fb9aec93..13e66930f3e 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins-result.xml
@@ -1,6 +1,6 @@
<dataset>
- <plugins uuid="a" kee="java" base_plugin_key="[null]" hash="bd451e47a1aa76e73da0359cef63dd63" created_at="1" updated_at="1"/>
- <plugins uuid="b" kee="javacustom" base_plugin_key="java2" hash="d22091cff5155e892cfe2f9dab51f811" created_at="1" updated_at="12345"/>
+ <plugins uuid="a" kee="java" base_plugin_key="[null]" file_hash="bd451e47a1aa76e73da0359cef63dd63" created_at="1" updated_at="1"/>
+ <plugins uuid="b" kee="javacustom" base_plugin_key="java2" file_hash="d22091cff5155e892cfe2f9dab51f811" created_at="1" updated_at="12345"/>
</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins.xml b/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins.xml
index b217fb7fa6d..09657bd51a0 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/startup/RegisterPluginsTest/update_only_changed_plugins.xml
@@ -1,6 +1,6 @@
<dataset>
- <plugins uuid="a" kee="java" base_plugin_key="[null]" hash="bd451e47a1aa76e73da0359cef63dd63" created_at="1" updated_at="1"/>
- <plugins uuid="b" kee="javacustom" base_plugin_key="java" hash="de9b2de3ddc0680904939686c0dba5be" created_at="1" updated_at="1"/>
+ <plugins uuid="a" kee="java" base_plugin_key="[null]" file_hash="bd451e47a1aa76e73da0359cef63dd63" created_at="1" updated_at="1"/>
+ <plugins uuid="b" kee="javacustom" base_plugin_key="java" file_hash="de9b2de3ddc0680904939686c0dba5be" created_at="1" updated_at="1"/>
</dataset>