aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-plugin
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-24 16:02:35 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-24 16:02:35 +0000
commit51c728457cb0ea1763625d3600bddc2c3d7f049b (patch)
treeb5b29779f065bb57d4755a541db08879cb61bfc2 /plugins/sonar-core-plugin
parenta5ba257ffd83b0418f12c0dc1ba9542873f0d6e8 (diff)
downloadsonarqube-51c728457cb0ea1763625d3600bddc2c3d7f049b.tar.gz
sonarqube-51c728457cb0ea1763625d3600bddc2c3d7f049b.zip
SONAR-1711 add a lock on SensorContext/DecoratorContext in order to avoid creation of resources in methods saveViolation() and saveMeasure().
Diffstat (limited to 'plugins/sonar-core-plugin')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/JavaSourceImporter.java10
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/JavaSourceImporterTest.java9
2 files changed, 15 insertions, 4 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/JavaSourceImporter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/JavaSourceImporter.java
index b54a223fced..1b8f32a8892 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/JavaSourceImporter.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/JavaSourceImporter.java
@@ -21,6 +21,7 @@ package org.sonar.plugins.core.sensors;
import org.sonar.api.batch.AbstractSourceImporter;
import org.sonar.api.batch.Phase;
+import org.sonar.api.batch.ResourceCreationLock;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Resource;
@@ -30,9 +31,11 @@ import java.util.List;
@Phase(name = Phase.Name.PRE)
public class JavaSourceImporter extends AbstractSourceImporter {
+ private ResourceCreationLock lock;
- public JavaSourceImporter() {
+ public JavaSourceImporter(ResourceCreationLock lock) {
super(Java.INSTANCE);
+ this.lock = lock;
}
@Override
@@ -41,6 +44,11 @@ public class JavaSourceImporter extends AbstractSourceImporter {
}
@Override
+ protected void onFinished() {
+ lock.lock();
+ }
+
+ @Override
public String toString() {
return getClass().getSimpleName();
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/JavaSourceImporterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/JavaSourceImporterTest.java
index 34927cfb1c7..0b47543b33a 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/JavaSourceImporterTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/JavaSourceImporterTest.java
@@ -23,7 +23,10 @@ import org.apache.commons.io.FileUtils;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
import org.junit.Test;
+import org.sonar.api.batch.ResourceCreationLock;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Resource;
@@ -37,7 +40,7 @@ public class JavaSourceImporterTest {
@Test
public void shouldCreateResource() throws IOException {
- JavaSourceImporter importer = new JavaSourceImporter();
+ JavaSourceImporter importer = new JavaSourceImporter(mock(ResourceCreationLock.class));
Resource clazz = importer.createResource(new File(newDir("source1"), "/MyClass.java"), Arrays.asList(newDir("source1")), false);
assertThat(clazz, is(JavaFile.class));
assertThat(clazz.getKey(), is(JavaPackage.DEFAULT_PACKAGE_NAME + ".MyClass"));
@@ -46,7 +49,7 @@ public class JavaSourceImporterTest {
@Test
public void shouldCreateTestResource() throws IOException {
- JavaSourceImporter importer = new JavaSourceImporter();
+ JavaSourceImporter importer = new JavaSourceImporter(mock(ResourceCreationLock.class));
Resource resource = importer.createResource(new File(newDir("tests"), "/MyClassTest.java"), Arrays.asList(newDir("tests")), true);
assertThat(resource, is(JavaFile.class));
assertThat(ResourceUtils.isUnitTestClass(resource), is(true));
@@ -55,7 +58,7 @@ public class JavaSourceImporterTest {
@Test
public void doNotSaveInnerClasses() throws IOException {
// example : https://svn.apache.org/repos/asf/geronimo/server/trunk/plugins/corba/geronimo-corba/src/test/java/org/apache/geronimo/corba/compiler/other/Generic$Interface.java
- JavaSourceImporter importer = new JavaSourceImporter();
+ JavaSourceImporter importer = new JavaSourceImporter(mock(ResourceCreationLock.class));
Resource resource = importer.createResource(new File(newDir("tests"), "/Generic$Interface.java"), Arrays.asList(newDir("tests")), true);
assertThat(resource, nullValue());
}