aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-10 14:59:36 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-10 15:34:18 +0100
commit9fb2ca6c4d1257c6387f108ffbca0cf09e802704 (patch)
treecdc3b112641993007f6d53767bf82bc280c3c7c3 /plugins
parentdb911e46da06f2339afa889acb3c8f1e7bbe5ae9 (diff)
downloadsonarqube-9fb2ca6c4d1257c6387f108ffbca0cf09e802704.tar.gz
sonarqube-9fb2ca6c4d1257c6387f108ffbca0cf09e802704.zip
SONAR-6068 Improve performance of FileSystem query operation
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java11
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java73
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java15
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java2
13 files changed, 104 insertions, 15 deletions
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
index 660d7c142ce..28a78f5cc50 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
@@ -20,7 +20,9 @@
package org.sonar.plugins.cpd;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
@@ -28,24 +30,29 @@ import org.sonar.api.resources.Java;
import org.sonar.batch.duplication.BlockCache;
import org.sonar.plugins.cpd.index.IndexFactory;
+import java.io.IOException;
+
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
public class CpdSensorTest {
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
JavaCpdEngine sonarEngine;
DefaultCpdEngine sonarBridgeEngine;
CpdSensor sensor;
Settings settings;
@Before
- public void setUp() {
+ public void setUp() throws IOException {
IndexFactory indexFactory = mock(IndexFactory.class);
sonarEngine = new JavaCpdEngine(indexFactory, null, null);
sonarBridgeEngine = new DefaultCpdEngine(indexFactory, new CpdMappings(), null, null, mock(BlockCache.class));
settings = new Settings(new PropertyDefinitions(CpdPlugin.class));
- DefaultFileSystem fs = new DefaultFileSystem();
+ DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder());
sensor = new CpdSensor(sonarEngine, sonarBridgeEngine, settings, fs);
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
index 6623cbb3866..96c090c5dc9 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
@@ -31,6 +31,7 @@ import org.sonar.xoo.rule.ChecksSensor;
import org.sonar.xoo.rule.CreateIssueByInternalKeySensor;
import org.sonar.xoo.rule.OneIssueOnDirPerFileSensor;
import org.sonar.xoo.rule.OneIssuePerLineSensor;
+import org.sonar.xoo.rule.RandomAccessSensor;
import org.sonar.xoo.rule.XooFakeExporter;
import org.sonar.xoo.rule.XooFakeImporter;
import org.sonar.xoo.rule.XooFakeImporterWithMessages;
@@ -74,6 +75,7 @@ public class XooPlugin extends SonarPlugin {
CoveragePerTestSensor.class,
DependencySensor.class,
ChecksSensor.class,
+ RandomAccessSensor.class,
OneIssuePerLineSensor.class,
OneIssueOnDirPerFileSensor.class,
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java
new file mode 100644
index 00000000000..6d51bd8661a
--- /dev/null
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java
@@ -0,0 +1,73 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.xoo.rule;
+
+import org.apache.commons.io.FileUtils;
+import org.sonar.api.batch.fs.FilePredicates;
+import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputFile.Type;
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.xoo.Xoo;
+
+import java.io.File;
+import java.io.IOException;
+
+public class RandomAccessSensor implements Sensor {
+
+ private static final String SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS = "sonar.xoo.randomAccessIssue.paths";
+ public static final String RULE_KEY = "RandomAccessIssue";
+
+ @Override
+ public void describe(SensorDescriptor descriptor) {
+ descriptor
+ .name("One Issue Per File with Random Access")
+ .onlyOnLanguages(Xoo.KEY)
+ .createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY)
+ .requireProperty(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS);
+ }
+
+ @Override
+ public void execute(SensorContext context) {
+ File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS));
+ FileSystem fs = context.fileSystem();
+ FilePredicates p = fs.predicates();
+ try {
+ for (String path : FileUtils.readLines(f)) {
+ createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private void createIssues(InputFile file, SensorContext context) {
+ RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
+ context.newIssue()
+ .ruleKey(ruleKey)
+ .onFile(file)
+ .atLine(1)
+ .message("This issue is generated on each file")
+ .save();
+ }
+}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
index 3895e6b638f..c7493349640 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
@@ -27,6 +27,6 @@ public class XooPluginTest {
@Test
public void provide_extensions() {
- assertThat(new XooPlugin().getExtensions()).hasSize(19);
+ assertThat(new XooPlugin().getExtensions()).hasSize(20);
}
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java
index e22b81eb5f8..7cf94a15d02 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java
@@ -57,7 +57,7 @@ public class CoveragePerTestSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new CoveragePerTestSensor();
- fileSystem = new DefaultFileSystem();
+ fileSystem = new DefaultFileSystem(baseDir);
when(context.fileSystem()).thenReturn(fileSystem);
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java
index 11ed815ac3c..46f6e56c69d 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java
@@ -56,7 +56,7 @@ public class DependencySensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new DependencySensor();
- fileSystem = new DefaultFileSystem();
+ fileSystem = new DefaultFileSystem(baseDir);
when(context.fileSystem()).thenReturn(fileSystem);
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java
index bea85df2714..ade948848f7 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java
@@ -65,7 +65,7 @@ public class MeasureSensorTest {
baseDir = temp.newFolder();
metricFinder = mock(MetricFinder.class);
sensor = new MeasureSensor(metricFinder);
- fileSystem = new DefaultFileSystem();
+ fileSystem = new DefaultFileSystem(baseDir);
when(context.fileSystem()).thenReturn(fileSystem);
storage = mock(SensorStorage.class);
when(context.newMeasure()).then(new Answer<DefaultMeasure>() {
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
index d5f6a30723e..945253e72b0 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
@@ -52,7 +52,7 @@ public class SymbolReferencesSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new SymbolReferencesSensor();
- fileSystem = new DefaultFileSystem();
+ fileSystem = new DefaultFileSystem(baseDir);
when(context.fileSystem()).thenReturn(fileSystem);
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
index cad3b968113..75c5a1c6685 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
@@ -52,7 +52,7 @@ public class SyntaxHighlightingSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new SyntaxHighlightingSensor();
- fileSystem = new DefaultFileSystem();
+ fileSystem = new DefaultFileSystem(baseDir);
when(context.fileSystem()).thenReturn(fileSystem);
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java
index 49b669707e0..41109c800c4 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java
@@ -56,7 +56,7 @@ public class TestCaseSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new TestCaseSensor();
- fileSystem = new DefaultFileSystem();
+ fileSystem = new DefaultFileSystem(baseDir);
when(context.fileSystem()).thenReturn(fileSystem);
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java
index 448d45cfcc5..752f4144aba 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java
@@ -57,7 +57,7 @@ public class XooTokenizerSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new XooTokenizerSensor();
- fileSystem = new DefaultFileSystem();
+ fileSystem = new DefaultFileSystem(baseDir);
when(context.fileSystem()).thenReturn(fileSystem);
settings = new Settings();
when(context.settings()).thenReturn(settings);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
index 7a80fc56d57..f283ffb0cd1 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
@@ -19,7 +19,9 @@
*/
package org.sonar.xoo.rule;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -34,6 +36,8 @@ import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
import org.sonar.api.config.Settings;
import org.sonar.xoo.Xoo;
+import java.io.IOException;
+
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -42,6 +46,9 @@ import static org.mockito.Mockito.when;
public class OneIssuePerLineSensorTest {
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
private OneIssuePerLineSensor sensor = new OneIssuePerLineSensor();
@Test
@@ -52,8 +59,8 @@ public class OneIssuePerLineSensorTest {
}
@Test
- public void testRule() {
- DefaultFileSystem fs = new DefaultFileSystem();
+ public void testRule() throws IOException {
+ DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder());
DefaultInputFile inputFile = new DefaultInputFile("foo", "src/Foo.xoo").setLanguage(Xoo.KEY).setLines(10);
fs.add(inputFile);
@@ -76,8 +83,8 @@ public class OneIssuePerLineSensorTest {
}
@Test
- public void testForceSeverity() {
- DefaultFileSystem fs = new DefaultFileSystem();
+ public void testForceSeverity() throws IOException {
+ DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder());
DefaultInputFile inputFile = new DefaultInputFile("foo", "src/Foo.xoo").setLanguage(Xoo.KEY).setLines(10);
fs.add(inputFile);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java
index 793752bcf0c..d0156cc083d 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java
@@ -57,7 +57,7 @@ public class XooBlameCommandTest {
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
- fs = new DefaultFileSystem();
+ fs = new DefaultFileSystem(baseDir);
input = mock(BlameInput.class);
when(input.fileSystem()).thenReturn(fs);
}