Skip to content

Commit

Permalink
Try to fix ITs on Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Aug 26, 2015
1 parent 2c42bfd commit a5ef5fb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
4 changes: 4 additions & 0 deletions its/src/test/java/com/sonarsource/it/scm/MercurialTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public void testBlame() throws Exception {
MavenBuild sonar = MavenBuild.create(pom)
.setGoals("clean verify sonar:sonar")
.setProperty("sonar.junit.reportsPath", "");
// Hack for Travis that have Mercurial 2.0.2
if (System.getenv("TRAVIS") != null) {
sonar.setProperty("sonar.mercurial.considerWhitespaces", "true");
}
orchestrator.executeBuilds(sonar);

assertThat(getScmData("dummy-hg:dummy:src/main/java/org/dummy/Dummy.java"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,39 @@
*/
package org.sonar.plugins.scm.mercurial;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.command.Command;
import org.sonar.api.utils.command.CommandExecutor;
import org.sonar.api.utils.command.StreamConsumer;
import org.sonar.api.utils.command.StringStreamConsumer;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class MercurialBlameCommand extends BlameCommand {

private static final Logger LOG = LoggerFactory.getLogger(MercurialBlameCommand.class);
private final CommandExecutor commandExecutor;
private Settings settings;

public MercurialBlameCommand() {
this(CommandExecutor.create());
public MercurialBlameCommand(Settings settings) {
this(CommandExecutor.create(), settings);
}

MercurialBlameCommand(CommandExecutor commandExecutor) {
MercurialBlameCommand(CommandExecutor commandExecutor, Settings settings) {
this.commandExecutor = commandExecutor;
this.settings = settings;
}

@Override
Expand Down Expand Up @@ -109,8 +115,11 @@ private Command createCommandLine(File workingDirectory, String filename) {
Command cl = Command.create("hg");
cl.setDirectory(workingDirectory);
cl.addArgument("blame");
// Ignore whitespaces
cl.addArgument("-w");
// Hack to support Mercurial prior to 2.1
if (!settings.getBoolean("sonar.mercurial.considerWhitespaces")) {
// Ignore whitespaces
cl.addArgument("-w");
}
// Verbose to have user email adress
cl.addArgument("-v");
// list the author
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package org.sonar.plugins.scm.mercurial;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -33,15 +36,12 @@
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.config.Settings;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.command.Command;
import org.sonar.api.utils.command.CommandExecutor;
import org.sonar.api.utils.command.StreamConsumer;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -95,7 +95,7 @@ public Integer answer(InvocationOnMock invocation) throws Throwable {
});

when(input.filesToBlame()).thenReturn(Arrays.<InputFile>asList(inputFile));
new MercurialBlameCommand(commandExecutor).blame(input, result);
new MercurialBlameCommand(commandExecutor, new Settings()).blame(input, result);
verify(result).blameResult(inputFile,
Arrays.asList(new BlameLine().date(DateUtils.parseDateTime("2014-11-04T11:01:10+0100")).revision("d45dafac0d9a").author("[email protected]"),
new BlameLine().date(DateUtils.parseDateTime("2014-11-04T11:01:10+0100")).revision("d45dafac0d9a").author("[email protected]"),
Expand Down Expand Up @@ -129,7 +129,7 @@ public Integer answer(InvocationOnMock invocation) throws Throwable {
});

when(input.filesToBlame()).thenReturn(Arrays.<InputFile>asList(inputFile));
new MercurialBlameCommand(commandExecutor).blame(input, result);
new MercurialBlameCommand(commandExecutor, new Settings()).blame(input, result);
verify(result).blameResult(inputFile,
Arrays.asList(new BlameLine().date(DateUtils.parseDateTime("2014-11-04T11:01:10+0100")).revision("d45dafac0d9a").author("[email protected]"),
new BlameLine().date(DateUtils.parseDateTime("2014-11-04T11:01:10+0100")).revision("d45dafac0d9a").author("[email protected]"),
Expand Down Expand Up @@ -158,10 +158,11 @@ public Integer answer(InvocationOnMock invocation) throws Throwable {
});

when(input.filesToBlame()).thenReturn(Arrays.<InputFile>asList(inputFile));
new MercurialBlameCommand(commandExecutor).blame(input, result);
new MercurialBlameCommand(commandExecutor, new Settings()).blame(input, result);

// TODO assert log contains
// "The mercurial blame command [hg blame -w -v --user --date --changeset src/foo.xoo] failed: abandon : src/foo.xoo: no such file in rev 000000000000"
// "The mercurial blame command [hg blame -w -v --user --date --changeset src/foo.xoo] failed: abandon : src/foo.xoo: no such file in
// rev 000000000000"
}

}

0 comments on commit a5ef5fb

Please sign in to comment.