diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-10-02 17:27:20 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-10-02 17:28:06 +0200 |
commit | fe4bf17e5c93ca6b683161d9ddaf390b0c9320dc (patch) | |
tree | 021fa553c5ca2ac910b7c51e283130b74e55e11a /sonar-batch | |
parent | 322eae37aad3f6553f84e3499421f6709ee7c440 (diff) | |
download | sonarqube-fe4bf17e5c93ca6b683161d9ddaf390b0c9320dc.tar.gz sonarqube-fe4bf17e5c93ca6b683161d9ddaf390b0c9320dc.zip |
SONAR-2657 Fix circular dependency in IoC container
Diffstat (limited to 'sonar-batch')
4 files changed, 16 insertions, 17 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ChangedFileFilter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ChangedFileFilter.java index af0968d4137..509fb2ef08b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ChangedFileFilter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ChangedFileFilter.java @@ -41,7 +41,7 @@ class ChangedFileFilter implements FileSystemFilter { if (previousHash == null) { return true; } - String currentHash = fileHashCache.getCurrentHash(file); + String currentHash = fileHashCache.getCurrentHash(file, context.fileSystem().sourceCharset()); return !currentHash.equals(previousHash); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileHashCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileHashCache.java index 34452fa2305..69309908449 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileHashCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileHashCache.java @@ -26,7 +26,6 @@ import org.picocontainer.Startable; import org.sonar.api.BatchComponent; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.database.model.Snapshot; -import org.sonar.api.scan.filesystem.ModuleFileSystem; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.SonarException; import org.sonar.batch.components.PastSnapshot; @@ -40,6 +39,7 @@ import javax.annotation.CheckForNull; import java.io.File; import java.io.IOException; import java.io.StringReader; +import java.nio.charset.Charset; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -56,13 +56,11 @@ public class FileHashCache implements BatchComponent, Startable { private PastSnapshotFinder pastSnapshotFinder; private Snapshot snapshot; private ProjectDefinition module; - private ModuleFileSystem fs; - public FileHashCache(ModuleFileSystem fs, ProjectDefinition module, PathResolver pathResolver, HashBuilder hashBuilder, + public FileHashCache(ProjectDefinition module, PathResolver pathResolver, HashBuilder hashBuilder, Snapshot snapshot, SnapshotDataDao snapshotDataDao, PastSnapshotFinder pastSnapshotFinder) { - this.fs = fs; this.module = module; this.pathResolver = pathResolver; this.hashBuilder = hashBuilder; @@ -96,10 +94,10 @@ public class FileHashCache implements BatchComponent, Startable { } } - public String getCurrentHash(File file) { + public String getCurrentHash(File file, Charset sourceCharset) { String relativePath = pathResolver.relativePath(module.getBaseDir(), file); if (!currentHashCache.containsKey(relativePath)) { - currentHashCache.put(relativePath, hashBuilder.computeHashNormalizeLineEnds(file, fs.sourceCharset())); + currentHashCache.put(relativePath, hashBuilder.computeHashNormalizeLineEnds(file, sourceCharset)); } return currentHashCache.get(relativePath); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java index 30ca6a3fa6f..49d30a44713 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java @@ -19,6 +19,7 @@ */ package org.sonar.batch.scan.filesystem; +import com.google.common.base.Charsets; import org.apache.commons.io.filefilter.FileFilterUtils; import org.junit.Rule; import org.junit.Test; @@ -271,13 +272,13 @@ public class DefaultModuleFileSystemTest { FileHashCache fileHashCache = mock(FileHashCache.class); when(fileHashCache.getPreviousHash(foo)).thenReturn("oldfoohash"); - when(fileHashCache.getCurrentHash(foo)).thenReturn("foohash"); + when(fileHashCache.getCurrentHash(foo, Charsets.UTF_8)).thenReturn("foohash"); when(fileHashCache.getPreviousHash(hello)).thenReturn("oldhellohash"); - when(fileHashCache.getCurrentHash(hello)).thenReturn("oldhellohash"); + when(fileHashCache.getCurrentHash(hello, Charsets.UTF_8)).thenReturn("oldhellohash"); when(fileHashCache.getPreviousHash(fooTest)).thenReturn("oldfooTesthash"); - when(fileHashCache.getCurrentHash(fooTest)).thenReturn("fooTesthash"); + when(fileHashCache.getCurrentHash(fooTest, Charsets.UTF_8)).thenReturn("fooTesthash"); when(fileHashCache.getPreviousHash(helloTest)).thenReturn("oldhelloTesthash"); - when(fileHashCache.getCurrentHash(helloTest)).thenReturn("oldhelloTesthash"); + when(fileHashCache.getCurrentHash(helloTest, Charsets.UTF_8)).thenReturn("oldhelloTesthash"); DefaultModuleFileSystem fileSystem = new DefaultModuleFileSystem(fileHashCache) .setBaseDir(basedir) diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileHashCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileHashCacheTest.java index 1342044a151..1c70890ffec 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileHashCacheTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileHashCacheTest.java @@ -71,7 +71,7 @@ public class FileHashCacheTest { baseDir = temp.newFolder(); snapshotDataDao = mock(SnapshotDataDao.class); moduleFileSystem = mock(ModuleFileSystem.class); - cache = new FileHashCache(moduleFileSystem, ProjectDefinition.create().setBaseDir(baseDir), new PathResolver(), new HashBuilder(), snapshot, + cache = new FileHashCache(ProjectDefinition.create().setBaseDir(baseDir), new PathResolver(), new HashBuilder(), snapshot, snapshotDataDao, pastSnapshotFinder); } @@ -106,7 +106,7 @@ public class FileHashCacheTest { .thenReturn(Arrays.asList(snapshotDataDto)); File file = new File(baseDir, "src/main/java/foo/Bar.java"); - FileUtils.write(file, "foo"); + FileUtils.write(file, "foo", Charsets.UTF_8); cache.start(); assertThat(cache.getPreviousHash(file)).isEqualTo("abcd1234"); } @@ -116,12 +116,12 @@ public class FileHashCacheTest { when(moduleFileSystem.sourceCharset()).thenReturn(Charsets.UTF_8); File file = new File(baseDir, "src/main/java/foo/Bar.java"); - FileUtils.write(file, "foo"); + FileUtils.write(file, "foo", Charsets.UTF_8); String hash = "9a8742076ef9ffa5591f633704c2286b"; - assertThat(cache.getCurrentHash(file)).isEqualTo(hash); + assertThat(cache.getCurrentHash(file, Charsets.UTF_8)).isEqualTo(hash); // Modify file - FileUtils.write(file, "bar"); - assertThat(cache.getCurrentHash(file)).isEqualTo(hash); + FileUtils.write(file, "bar", Charsets.UTF_8); + assertThat(cache.getCurrentHash(file, Charsets.UTF_8)).isEqualTo(hash); } } |