aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-xoo-plugin/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-26 10:22:12 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-26 10:22:12 +0200
commit8664470d82c4f682866ca271d4e7e2a89374212f (patch)
tree0f490693a69dee5211e8c7c0bf7453f56a25c766 /plugins/sonar-xoo-plugin/src
parent4234c8d5b402e751dfd0c17732cfc843ba807fe0 (diff)
downloadsonarqube-8664470d82c4f682866ca271d4e7e2a89374212f.tar.gz
sonarqube-8664470d82c4f682866ca271d4e7e2a89374212f.zip
Revert "SONAR-5644 Rework SCM API"
This reverts commit a4e76de07797ea2b9b809a0cc0b90286c90cd3cd.
Diffstat (limited to 'plugins/sonar-xoo-plugin/src')
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java (renamed from plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java)36
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/package-info.java23
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java2
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooScmProvider.java43
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/package-info.java23
-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/rule/OneIssuePerLineSensorTest.java104
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java75
9 files changed, 31 insertions, 281 deletions
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 148a6df0b7c..e1988ac37ab 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
@@ -25,14 +25,13 @@ import org.sonar.xoo.lang.MeasureSensor;
import org.sonar.xoo.lang.SymbolReferencesSensor;
import org.sonar.xoo.lang.SyntaxHighlightingSensor;
import org.sonar.xoo.lang.TestCaseSensor;
+import org.sonar.xoo.lang.XooScmProvider;
import org.sonar.xoo.lang.XooTokenizerSensor;
import org.sonar.xoo.rule.CreateIssueByInternalKeySensor;
import org.sonar.xoo.rule.OneIssueOnDirPerFileSensor;
import org.sonar.xoo.rule.OneIssuePerLineSensor;
import org.sonar.xoo.rule.XooQualityProfile;
import org.sonar.xoo.rule.XooRulesDefinition;
-import org.sonar.xoo.scm.XooBlameCommand;
-import org.sonar.xoo.scm.XooScmProvider;
import java.util.Arrays;
import java.util.List;
@@ -54,7 +53,6 @@ public class XooPlugin extends SonarPlugin {
// SCM
XooScmProvider.class,
- XooBlameCommand.class,
// sensors
MeasureSensor.class,
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java
index 7d492cc315b..895d47dfbbe 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java
@@ -17,16 +17,18 @@
* 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.scm;
+package org.sonar.xoo.lang;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.fs.FileSystem;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.scm.BlameCommand;
import org.sonar.api.batch.scm.BlameLine;
+import org.sonar.api.batch.scm.ScmProvider;
+import org.sonar.api.config.Settings;
import org.sonar.api.utils.DateUtils;
import java.io.File;
@@ -35,19 +37,37 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-public class XooBlameCommand implements BlameCommand {
+public class XooScmProvider implements ScmProvider {
+
+ private static final Logger LOG = LoggerFactory.getLogger(XooScmProvider.class);
private static final String SCM_EXTENSION = ".scm";
+ private final Settings settings;
+
+ public XooScmProvider(Settings settings) {
+ this.settings = settings;
+ }
+
+ @Override
+ public String key() {
+ return "xoo";
+ }
+
+ @Override
+ public boolean supports(File baseDir) {
+ return false;
+ }
+
@Override
- public void blame(FileSystem fs, Iterable<InputFile> files, BlameResult result) {
+ public void blame(Iterable<InputFile> files, BlameResult handler) {
for (InputFile inputFile : files) {
- processFile(inputFile, result);
+ processFile(inputFile, handler);
}
}
@VisibleForTesting
- protected void processFile(InputFile inputFile, BlameResult result) {
+ protected void processFile(InputFile inputFile, BlameResult handler) {
File ioFile = inputFile.file();
File scmDataFile = new java.io.File(ioFile.getParentFile(), ioFile.getName() + SCM_EXTENSION);
if (!scmDataFile.exists()) {
@@ -74,7 +94,7 @@ public class XooBlameCommand implements BlameCommand {
blame.add(new BlameLine(date, revision, author));
}
}
- result.add(inputFile, blame);
+ handler.add(inputFile, blame);
} catch (IOException e) {
throw new IllegalStateException(e);
}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/package-info.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/package-info.java
deleted file mode 100644
index 9963cc34bd9..00000000000
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.xoo.lang;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
index 31db08c01f2..7a11c639e38 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
@@ -32,7 +32,7 @@ public class OneIssuePerLineSensor implements Sensor {
public static final String RULE_KEY = "OneIssuePerLine";
private static final String EFFORT_TO_FIX_PROPERTY = "sonar.oneIssuePerLine.effortToFix";
- public static final String FORCE_SEVERITY_PROPERTY = "sonar.oneIssuePerLine.forceSeverity";
+ private static final String FORCE_SEVERITY_PROPERTY = "sonar.oneIssuePerLine.forceSeverity";
@Override
public void describe(SensorDescriptor descriptor) {
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooScmProvider.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooScmProvider.java
deleted file mode 100644
index 5807d820043..00000000000
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooScmProvider.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.scm;
-
-import org.sonar.api.batch.scm.BlameCommand;
-import org.sonar.api.batch.scm.ScmProvider;
-
-public class XooScmProvider extends ScmProvider {
-
- private final XooBlameCommand blame;
-
- public XooScmProvider(XooBlameCommand blame) {
- this.blame = blame;
- }
-
- @Override
- public String key() {
- return "xoo";
- }
-
- @Override
- public BlameCommand blameCommand() {
- return blame;
- }
-
-}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/package-info.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/package-info.java
deleted file mode 100644
index f5c68e3c563..00000000000
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.xoo.scm;
-
-import javax.annotation.ParametersAreNonnullByDefault;
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 e8100740345..96ea0ea923c 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(14);
+ assertThat(new XooPlugin().getExtensions()).hasSize(13);
}
}
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
deleted file mode 100644
index 31d109e3653..00000000000
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.sonar.api.batch.fs.internal.DefaultFileSystem;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.sensor.SensorContext;
-import org.sonar.api.batch.sensor.SensorStorage;
-import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-import org.sonar.api.batch.sensor.issue.Issue;
-import org.sonar.api.batch.sensor.issue.Issue.Severity;
-import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
-import org.sonar.api.config.Settings;
-import org.sonar.xoo.Xoo;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class OneIssuePerLineSensorTest {
-
- private OneIssuePerLineSensor sensor = new OneIssuePerLineSensor();
-
- @Test
- public void testDescriptor() {
- DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
- sensor.describe(descriptor);
- assertThat(descriptor.ruleRepositories()).containsOnly(XooRulesDefinition.XOO_REPOSITORY);
- }
-
- @Test
- public void testRule() {
- DefaultFileSystem fs = new DefaultFileSystem();
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/Foo.xoo").setLanguage(Xoo.KEY).setLines(10);
- fs.add(inputFile);
-
- SensorContext context = mock(SensorContext.class);
- final SensorStorage sensorStorage = mock(SensorStorage.class);
- when(context.settings()).thenReturn(new Settings());
- when(context.fileSystem()).thenReturn(fs);
- when(context.newIssue()).thenAnswer(new Answer<Issue>() {
- @Override
- public Issue answer(InvocationOnMock invocation) throws Throwable {
- return new DefaultIssue(sensorStorage);
- }
- });
- sensor.execute(context);
-
- ArgumentCaptor<DefaultIssue> argCaptor = ArgumentCaptor.forClass(DefaultIssue.class);
- verify(sensorStorage, times(10)).store(argCaptor.capture());
- assertThat(argCaptor.getAllValues()).hasSize(10); // One issue per line
- assertThat(argCaptor.getValue().overridenSeverity()).isNull();
- }
-
- @Test
- public void testForceSeverity() {
- DefaultFileSystem fs = new DefaultFileSystem();
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/Foo.xoo").setLanguage(Xoo.KEY).setLines(10);
- fs.add(inputFile);
-
- SensorContext context = mock(SensorContext.class);
- final SensorStorage sensorStorage = mock(SensorStorage.class);
- Settings settings = new Settings();
- settings.setProperty(OneIssuePerLineSensor.FORCE_SEVERITY_PROPERTY, "MINOR");
- when(context.settings()).thenReturn(settings);
- when(context.fileSystem()).thenReturn(fs);
- when(context.newIssue()).thenAnswer(new Answer<Issue>() {
- @Override
- public Issue answer(InvocationOnMock invocation) throws Throwable {
- return new DefaultIssue(sensorStorage);
- }
- });
- sensor.execute(context);
-
- ArgumentCaptor<DefaultIssue> argCaptor = ArgumentCaptor.forClass(DefaultIssue.class);
- verify(sensorStorage, times(10)).store(argCaptor.capture());
- assertThat(argCaptor.getAllValues()).hasSize(10); // One issue per line
- assertThat(argCaptor.getValue().overridenSeverity()).isEqualTo(Severity.MINOR);
- }
-
-}
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
deleted file mode 100644
index bba495dd400..00000000000
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.scm;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultFileSystem;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.scm.BlameCommand.BlameResult;
-import org.sonar.api.batch.scm.BlameLine;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.xoo.Xoo;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class XooBlameCommandTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- private DefaultFileSystem fs;
- private File baseDir;
-
- @Before
- public void prepare() throws IOException {
- baseDir = temp.newFolder();
- fs = new DefaultFileSystem();
- }
-
- @Test
- public void testBlame() throws IOException {
- File source = new File(baseDir, "src/foo.xoo");
- FileUtils.write(source, "sample content");
- File scm = new File(baseDir, "src/foo.xoo.scm");
- FileUtils.write(scm, "123,julien,2014-12-12\n234,julien,2014-12-24");
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage(Xoo.KEY);
- fs.add(inputFile);
-
- BlameResult result = mock(BlameResult.class);
- new XooBlameCommand().blame(fs, Arrays.<InputFile>asList(inputFile), result);
- verify(result).add(inputFile, Arrays.asList(new BlameLine(DateUtils.parseDate("2014-12-12"), "123", "julien"),
- new BlameLine(DateUtils.parseDate("2014-12-24"), "234", "julien")));
- }
-
-}