aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-10-02 17:27:20 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-10-02 17:28:06 +0200
commitfe4bf17e5c93ca6b683161d9ddaf390b0c9320dc (patch)
tree021fa553c5ca2ac910b7c51e283130b74e55e11a
parent322eae37aad3f6553f84e3499421f6709ee7c440 (diff)
downloadsonarqube-fe4bf17e5c93ca6b683161d9ddaf390b0c9320dc.tar.gz
sonarqube-fe4bf17e5c93ca6b683161d9ddaf390b0c9320dc.zip
SONAR-2657 Fix circular dependency in IoC container
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/FileHashSensor.java2
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/FileHashSensorTest.java10
-rw-r--r--sonar-application/pom.xml2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ChangedFileFilter.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileHashCache.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileHashCacheTest.java12
7 files changed, 24 insertions, 23 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 93c943a3490..09f8215f053 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
@@ -69,7 +69,7 @@ public final class FileHashSensor implements Sensor {
private void analyse(StringBuilder fileHashMap, Project project, FileType fileType) {
List<File> files = moduleFileSystem.files(FileQuery.on(fileType).onLanguage(project.getLanguageKey()));
for (File file : files) {
- String hash = fileHashCache.getCurrentHash(file);
+ String hash = fileHashCache.getCurrentHash(file, moduleFileSystem.sourceCharset());
fileHashMap.append(pathResolver.relativePath(moduleFileSystem.baseDir(), file)).append("=").append(hash).append("\n");
}
}
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 a7bbfa49697..f57dae2e809 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
@@ -19,6 +19,7 @@
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.base.Charsets;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
@@ -66,6 +67,7 @@ public class FileHashSensorTest {
@Before
public void prepare() {
fileSystem = mock(ModuleFileSystem.class);
+ when(fileSystem.sourceCharset()).thenReturn(Charsets.UTF_8);
componentDataCache = mock(ComponentDataCache.class);
fileHashCache = mock(FileHashCache.class);
sensor = new FileHashSensor(fileHashCache, fileSystem, new PathResolver(), componentDataCache);
@@ -84,11 +86,11 @@ public class FileHashSensorTest {
public void computeHashes() throws Exception {
File baseDir = temp.newFolder();
File file1 = new File(baseDir, "src/com/foo/Bar.java");
- FileUtils.write(file1, "Bar");
- when(fileHashCache.getCurrentHash(file1)).thenReturn("barhash");
+ FileUtils.write(file1, "Bar", Charsets.UTF_8);
+ when(fileHashCache.getCurrentHash(file1, Charsets.UTF_8)).thenReturn("barhash");
File file2 = new File(baseDir, "src/com/foo/Foo.java");
- FileUtils.write(file2, "Foo");
- when(fileHashCache.getCurrentHash(file2)).thenReturn("foohash");
+ FileUtils.write(file2, "Foo", Charsets.UTF_8);
+ when(fileHashCache.getCurrentHash(file2, Charsets.UTF_8)).thenReturn("foohash");
when(fileSystem.baseDir()).thenReturn(baseDir);
when(fileSystem.files(any(FileQuery.class))).thenReturn(Arrays.asList(file1, file2)).thenReturn(Collections.<File> emptyList());
sensor.analyse(project, mock(SensorContext.class));
diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml
index 7dc02556456..a55c24d7c99 100644
--- a/sonar-application/pom.xml
+++ b/sonar-application/pom.xml
@@ -276,7 +276,7 @@
<rules>
<requireFilesSize>
<minsize>55000000</minsize>
- <maxsize>60000000</maxsize>
+ <maxsize>60400000</maxsize>
<files>
<file>${project.build.directory}/sonar-${project.version}.zip</file>
</files>
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);
}
}