diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-10 01:19:57 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-10 01:19:57 +0200 |
commit | 7cdb8cbfb54bcb028300674f18ce08ea3ee35858 (patch) | |
tree | f3bffef9fac71d13c4e48553e7b4bc2c49625efc /plugins/sonar-core-plugin | |
parent | c2a0f4f06564c1d62f08d4e20489f70f0f4ad223 (diff) | |
download | sonarqube-7cdb8cbfb54bcb028300674f18ce08ea3ee35858.tar.gz sonarqube-7cdb8cbfb54bcb028300674f18ce08ea3ee35858.zip |
SONAR-3677 refactor API
Diffstat (limited to 'plugins/sonar-core-plugin')
2 files changed, 8 insertions, 6 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FileHashSensor.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FileHashSensor.java index 40212eb910f..ef03cf16bff 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FileHashSensor.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FileHashSensor.java @@ -20,7 +20,6 @@ package org.sonar.plugins.core.sensors; import com.google.common.collect.Maps; -import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.Sensor; import org.sonar.api.batch.SensorContext; import org.sonar.api.resources.Project; @@ -28,6 +27,7 @@ import org.sonar.api.scan.filesystem.InputFile; import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.index.ComponentDataCache; import org.sonar.batch.scan.filesystem.InputFileCache; +import org.sonar.core.DryRunIncompatible; import org.sonar.core.source.SnapshotDataTypes; import java.util.Map; @@ -36,8 +36,10 @@ import java.util.Map; * This sensor will retrieve hash of each file of the current module and store it in DB * in order to compare it during next analysis and see if the file was modified. * This is used by the incremental preview mode. + * * @since 4.0 */ +@DryRunIncompatible public final class FileHashSensor implements Sensor { private final InputFileCache fileCache; @@ -56,10 +58,9 @@ public final class FileHashSensor implements Sensor { public void analyse(Project project, SensorContext context) { Map<String, String> map = Maps.newHashMap(); for (InputFile inputFile : fileCache.byModule(project.key())) { - String baseRelativePath = inputFile.attribute(InputFile.ATTRIBUTE_BASE_RELATIVE_PATH); String hash = inputFile.attribute(InputFile.ATTRIBUTE_HASH); - if (StringUtils.isNotEmpty(baseRelativePath) && StringUtils.isNotEmpty(hash)) { - map.put(baseRelativePath, hash); + if (hash != null) { + map.put(inputFile.relativePath(), hash); } } if (!map.isEmpty()) { diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FileHashSensorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FileHashSensorTest.java index c763efd4919..6c5a6645d1b 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FileHashSensorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FileHashSensorTest.java @@ -28,6 +28,7 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.SensorContext; import org.sonar.api.resources.Project; import org.sonar.api.scan.filesystem.InputFile; +import org.sonar.api.scan.filesystem.internal.DefaultInputFile; import org.sonar.batch.index.ComponentDataCache; import org.sonar.batch.scan.filesystem.InputFileCache; import org.sonar.core.source.SnapshotDataTypes; @@ -53,8 +54,8 @@ public class FileHashSensorTest { @Test public void store_file_hashes() throws Exception { when(fileCache.byModule("struts")).thenReturn(Lists.<InputFile>newArrayList( - InputFile.create(temp.newFile(), "src/Foo.java", ImmutableMap.of(InputFile.ATTRIBUTE_HASH, "ABC")), - InputFile.create(temp.newFile(), "src/Bar.java", ImmutableMap.of(InputFile.ATTRIBUTE_HASH, "DEF")) + DefaultInputFile.create(temp.newFile(), "src/Foo.java", ImmutableMap.of(InputFile.ATTRIBUTE_HASH, "ABC")), + DefaultInputFile.create(temp.newFile(), "src/Bar.java", ImmutableMap.of(InputFile.ATTRIBUTE_HASH, "DEF")) )); SensorContext sensorContext = mock(SensorContext.class); |