"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
);
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);
}
/** 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) */
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;
}
.append("uuid", uuid)
.append("key", kee)
.append("basePluginKey", basePluginKey)
- .append("jarMd5", hash)
+ .append("fileHash", fileHash)
.append("createdAt", createdAt)
.append("updatedAt", updatedAt)
.toString();
return this;
}
+ @CheckForNull
public String getPluginKey() {
return pluginKey;
}
- public RuleDefinitionDto setPluginKey(String pluginKey) {
+ public RuleDefinitionDto setPluginKey(@Nullable String pluginKey) {
this.pluginKey = pluginKey;
return this;
}
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;
}
uuid,
kee,
base_plugin_key as basePluginKey,
- hash,
+ file_hash as fileHash,
created_at as createdAt,
updated_at as updatedAt
</sql>
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}
)
<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>
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);
}
.setUuid("c")
.setKee("javascript")
.setBasePluginKey("java")
- .setHash("cccccccccccccccccccccccccccccccc")
+ .setFileHash("cccccccccccccccccccccccccccccccc")
.setCreatedAt(1L)
.setUpdatedAt(2L));
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);
}
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);
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);
- }
-
}
return new PluginDto()
.setUuid(uuid)
.setKee(uuid)
- .setHash(randomAlphanumeric(32))
+ .setFileHash(randomAlphanumeric(32))
.setCreatedAt(nextLong())
.setUpdatedAt(nextLong());
}
<plugins uuid="a"
kee="java"
base_plugin_key="[null]"
- hash="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ file_hash="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
created_at="1500000000000"
updated_at="1600000000000"
/>
<plugins uuid="b"
kee="javacustom"
base_plugin_key="java"
- hash="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
+ file_hash="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
created_at="1500000000000"
updated_at="1600000000000"
/>
.setIsNullable(true)
.build())
.addColumn(newVarcharColumnDefBuilder()
- .setColumnName("hash")
+ .setColumnName("file_hash")
.setLimit(200)
.setIsNullable(false)
.build())
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);
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)
@CheckForNull
DebtRemediationFunction getRemediationFunction();
+ @CheckForNull
String getPluginKey();
}
return type;
}
+ @CheckForNull
@Override
public String getPluginKey() {
return pluginKey;
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;
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;
return createdAt;
}
+ @CheckForNull
public String getPluginKey() {
return pluginKey;
}
.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)
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());
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;
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;
.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);
}
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;
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;
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;
@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);
@Test
public void should_change_date_if_scm_is_available_and_first_analysis() {
+ analysisMetadataHolder.setBaseAnalysis(null);
currentAnalysisIs(3000L);
newIssue();
@Test
public void should_use_primary_location_when_backdating() {
+ analysisMetadataHolder.setBaseAnalysis(null);
currentAnalysisIs(3000L);
newIssue();
@Test
public void should_use_flows_location_when_backdating() {
+ analysisMetadataHolder.setBaseAnalysis(null);
currentAnalysisIs(3000L);
newIssue();
}
private void previousAnalysisWas(long analysisDate) {
- when(analysisMetadataHolder.getBaseAnalysis())
- .thenReturn(baseAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseAnalysis);
when(baseAnalysis.getCreatedAt())
.thenReturn(analysisDate);
}
}
private void currentAnalysisIs(long analysisDate) {
- when(analysisMetadataHolder.getAnalysisDate()).thenReturn(analysisDate);
+ analysisMetadataHolder.setAnalysisDate(analysisDate);
}
private void newIssue() {
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);
.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);
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"));
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);
db.pluginDbTester().insertPlugin(
p -> p.setKee("A"),
- p -> p.setHash("abcdA"),
+ p -> p.setFileHash("abcdA"),
p -> p.setUpdatedAt(111111L));
underTest.handle(request, response);
@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("{" +
<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>
<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>
<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>