aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-svn-plugin
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-10-08 09:17:18 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-08 09:17:35 +0200
commitf5609262df4ebe0d85273c0d64cd3e6cd606ab48 (patch)
treeded8f0e738e3afaef9e2d123948cae35f2f94d38 /plugins/sonar-svn-plugin
parenta59365165984175c4d2db031005b031e00827545 (diff)
downloadsonarqube-f5609262df4ebe0d85273c0d64cd3e6cd606ab48.tar.gz
sonarqube-f5609262df4ebe0d85273c0d64cd3e6cd606ab48.zip
Improve coverage
Diffstat (limited to 'plugins/sonar-svn-plugin')
-rw-r--r--plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnBlameCommand.java44
-rw-r--r--plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnConfiguration.java8
-rw-r--r--plugins/sonar-svn-plugin/src/test/java/org/sonar/plugins/scm/svn/SvnBlameCommandTest.java27
3 files changed, 55 insertions, 24 deletions
diff --git a/plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnBlameCommand.java b/plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnBlameCommand.java
index 5b3746f5dcc..f6b462839b9 100644
--- a/plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnBlameCommand.java
+++ b/plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnBlameCommand.java
@@ -84,31 +84,35 @@ public class SvnBlameCommand implements BlameCommand, BatchComponent {
private Future<Void> submitTask(final FileSystem fs, final BlameResult result, ExecutorService executorService, final InputFile inputFile) {
return executorService.submit(new Callable<Void>() {
public Void call() {
- String filename = inputFile.relativePath();
- Command cl = createCommandLine(fs.baseDir(), filename);
- SvnBlameConsumer consumer = new SvnBlameConsumer(filename);
- StringStreamConsumer stderr = new StringStreamConsumer();
- int exitCode;
- try {
- exitCode = execute(cl, consumer, stderr);
- } catch (CommandException e) {
- // Unwrap CommandException
- throw e.getCause() instanceof RuntimeException ? (RuntimeException) e.getCause() : new IllegalStateException(e.getCause());
- }
- if (exitCode != 0) {
- throw new IllegalStateException("The svn blame command [" + cl.toString() + "] failed: " + stderr.getOutput());
- }
- List<BlameLine> lines = consumer.getLines();
- if (lines.size() == inputFile.lines() - 1) {
- // SONARPLUGINS-3097 SVN do not report blame on last empty line
- lines.add(lines.get(lines.size() - 1));
- }
- result.add(inputFile, lines);
+ blame(fs, inputFile, result);
return null;
}
});
}
+ private void blame(final FileSystem fs, final InputFile inputFile, final BlameResult result) {
+ String filename = inputFile.relativePath();
+ Command cl = createCommandLine(fs.baseDir(), filename);
+ SvnBlameConsumer consumer = new SvnBlameConsumer(filename);
+ StringStreamConsumer stderr = new StringStreamConsumer();
+ int exitCode;
+ try {
+ exitCode = execute(cl, consumer, stderr);
+ } catch (CommandException e) {
+ // Unwrap CommandException
+ throw e.getCause() instanceof RuntimeException ? (RuntimeException) e.getCause() : new IllegalStateException(e.getCause());
+ }
+ if (exitCode != 0) {
+ throw new IllegalStateException("The svn blame command [" + cl.toString() + "] failed: " + stderr.getOutput());
+ }
+ List<BlameLine> lines = consumer.getLines();
+ if (lines.size() == inputFile.lines() - 1) {
+ // SONARPLUGINS-3097 SVN do not report blame on last empty line
+ lines.add(lines.get(lines.size() - 1));
+ }
+ result.add(inputFile, lines);
+ }
+
private int execute(Command cl, StreamConsumer consumer, StreamConsumer stderr) {
LOG.debug("Executing: " + cl);
return commandExecutor.execute(cl, consumer, stderr, -1);
diff --git a/plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnConfiguration.java b/plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnConfiguration.java
index 6ecb618dce4..16942c8a0f8 100644
--- a/plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnConfiguration.java
+++ b/plugins/sonar-svn-plugin/src/main/java/org/sonar/plugins/scm/svn/SvnConfiguration.java
@@ -36,10 +36,10 @@ import java.util.List;
public class SvnConfiguration implements BatchComponent {
private static final String CATEGORY_SVN = "SVN";
- private static final String USER_PROP_KEY = "sonar.svn.username";
- private static final String PASSWORD_PROP_KEY = "sonar.svn.password.secured";
- private static final String CONFIG_DIR_PROP_KEY = "sonar.svn.config_dir";
- private static final String TRUST_SERVER_PROP_KEY = "sonar.svn.trust_server_cert";
+ public static final String USER_PROP_KEY = "sonar.svn.username";
+ public static final String PASSWORD_PROP_KEY = "sonar.svn.password.secured";
+ public static final String CONFIG_DIR_PROP_KEY = "sonar.svn.config_dir";
+ public static final String TRUST_SERVER_PROP_KEY = "sonar.svn.trust_server_cert";
private final Settings settings;
public SvnConfiguration(Settings settings) {
diff --git a/plugins/sonar-svn-plugin/src/test/java/org/sonar/plugins/scm/svn/SvnBlameCommandTest.java b/plugins/sonar-svn-plugin/src/test/java/org/sonar/plugins/scm/svn/SvnBlameCommandTest.java
index c9306a7e11f..a3b5a79fc19 100644
--- a/plugins/sonar-svn-plugin/src/test/java/org/sonar/plugins/scm/svn/SvnBlameCommandTest.java
+++ b/plugins/sonar-svn-plugin/src/test/java/org/sonar/plugins/scm/svn/SvnBlameCommandTest.java
@@ -32,6 +32,8 @@ 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.config.PropertyDefinitions;
+import org.sonar.api.config.Settings;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.command.Command;
import org.sonar.api.utils.command.CommandExecutor;
@@ -42,6 +44,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
+import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.mock;
@@ -183,4 +186,28 @@ public class SvnBlameCommandTest {
new SvnBlameCommand(commandExecutor, mock(SvnConfiguration.class)).blame(fs, Arrays.<InputFile>asList(inputFile), result);
}
+ @Test
+ public void testAllParams() {
+ CommandExecutor commandExecutor = mock(CommandExecutor.class);
+ Settings settings = new Settings(new PropertyDefinitions(SvnConfiguration.getProperties()));
+ SvnBlameCommand svnBlameCommand = new SvnBlameCommand(commandExecutor, new SvnConfiguration(settings));
+
+ Command commandLine = svnBlameCommand.createCommandLine(baseDir, "src/main/java/Foo.java");
+ assertThat(commandLine.toCommandLine()).isEqualTo("svn blame --xml src/main/java/Foo.java --non-interactive");
+ assertThat(commandLine.toString()).isEqualTo("svn blame --xml src/main/java/Foo.java --non-interactive");
+
+ settings.setProperty(SvnConfiguration.USER_PROP_KEY, "myUser");
+ settings.setProperty(SvnConfiguration.PASSWORD_PROP_KEY, "myPass");
+ commandLine = svnBlameCommand.createCommandLine(baseDir, "src/main/java/Foo.java");
+ assertThat(commandLine.toCommandLine()).isEqualTo("svn blame --xml src/main/java/Foo.java --non-interactive --username myUser --password myPass");
+ assertThat(commandLine.toString()).isEqualTo("svn blame --xml src/main/java/Foo.java --non-interactive --username ******** --password ********");
+
+ settings.setProperty(SvnConfiguration.CONFIG_DIR_PROP_KEY, "/home/julien/.svn");
+ settings.setProperty(SvnConfiguration.TRUST_SERVER_PROP_KEY, "true");
+ commandLine = svnBlameCommand.createCommandLine(baseDir, "src/main/java/Foo.java");
+ assertThat(commandLine.toCommandLine())
+ .isEqualTo("svn blame --xml src/main/java/Foo.java --non-interactive --config-dir /home/julien/.svn --username myUser --password myPass --trust-server-cert");
+ assertThat(commandLine.toString()).isEqualTo(
+ "svn blame --xml src/main/java/Foo.java --non-interactive --config-dir /home/julien/.svn --username ******** --password ******** --trust-server-cert");
+ }
}