aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-xoo-plugin/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-10-16 15:58:26 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-16 16:52:40 +0200
commit229555a2030f9ea672654adf5087611ff2e60654 (patch)
treefcc28cc0c36f4a5670a22d651bc733822221fe07 /plugins/sonar-xoo-plugin/src
parent84c7aabe6ea304acaa96f14911b712bab02b51b8 (diff)
downloadsonarqube-229555a2030f9ea672654adf5087611ff2e60654.tar.gz
sonarqube-229555a2030f9ea672654adf5087611ff2e60654.zip
SONAR-5644 Apply some feedback on SCM API
Diffstat (limited to 'plugins/sonar-xoo-plugin/src')
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java24
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java18
2 files changed, 23 insertions, 19 deletions
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/scm/XooBlameCommand.java
index 0534d92d8cb..b78deb2812c 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/scm/XooBlameCommand.java
@@ -23,9 +23,6 @@ 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.BatchComponent;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.scm.BlameCommand;
import org.sonar.api.batch.scm.BlameLine;
@@ -34,27 +31,25 @@ import org.sonar.api.utils.DateUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-public class XooBlameCommand implements BlameCommand, BatchComponent {
+public class XooBlameCommand extends BlameCommand {
private static final String SCM_EXTENSION = ".scm";
@Override
- public void blame(FileSystem fs, Iterable<InputFile> files, BlameResult result) {
- for (InputFile inputFile : files) {
+ public void blame(BlameInput input, BlameOutput result) {
+ for (InputFile inputFile : input.filesToBlame()) {
processFile(inputFile, result);
}
}
@VisibleForTesting
- protected void processFile(InputFile inputFile, BlameResult result) {
+ protected void processFile(InputFile inputFile, BlameOutput result) {
File ioFile = inputFile.file();
File scmDataFile = new java.io.File(ioFile.getParentFile(), ioFile.getName() + SCM_EXTENSION);
if (!scmDataFile.exists()) {
- throw new IllegalStateException("Missing file " + scmDataFile);
+ return;
}
try {
@@ -71,13 +66,16 @@ public class XooBlameCommand implements BlameCommand, BatchComponent {
}
String revision = StringUtils.trimToNull(fields[0]);
String author = StringUtils.trimToNull(fields[1]);
+ BlameLine blameLine = new BlameLine().revision(revision).author(author);
String dateStr = StringUtils.trimToNull(fields[2]);
// Will throw an exception, when date is not in format "yyyy-MM-dd"
- Date date = dateStr != null ? DateUtils.parseDate(dateStr) : null;
- blame.add(new BlameLine(date, revision, author));
+ if (dateStr != null) {
+ blameLine.date(DateUtils.parseDate(dateStr));
+ }
+ blame.add(blameLine);
}
}
- result.add(inputFile, blame);
+ result.blameResult(inputFile, blame);
} catch (IOException e) {
throw new IllegalStateException(e);
}
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 bba495dd400..793752bcf0c 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
@@ -28,7 +28,8 @@ 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.BlameCommand.BlameInput;
+import org.sonar.api.batch.scm.BlameCommand.BlameOutput;
import org.sonar.api.batch.scm.BlameLine;
import org.sonar.api.utils.DateUtils;
import org.sonar.xoo.Xoo;
@@ -39,6 +40,7 @@ import java.util.Arrays;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class XooBlameCommandTest {
@@ -50,11 +52,14 @@ public class XooBlameCommandTest {
private DefaultFileSystem fs;
private File baseDir;
+ private BlameInput input;
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
fs = new DefaultFileSystem();
+ input = mock(BlameInput.class);
+ when(input.fileSystem()).thenReturn(fs);
}
@Test
@@ -66,10 +71,11 @@ public class XooBlameCommandTest {
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")));
+ BlameOutput result = mock(BlameOutput.class);
+ when(input.filesToBlame()).thenReturn(Arrays.<InputFile>asList(inputFile));
+ new XooBlameCommand().blame(input, result);
+ verify(result).blameResult(inputFile, Arrays.asList(
+ new BlameLine().revision("123").author("julien").date(DateUtils.parseDate("2014-12-12")),
+ new BlameLine().revision("234").author("julien").date(DateUtils.parseDate("2014-12-24"))));
}
-
}