use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonarqube by SonarSource.
the class JGitBlameCommandTest method testBlameOnNestedModule.
@Test
public void testBlameOnNestedModule() throws IOException {
File projectDir = temp.newFolder();
javaUnzip("dummy-git-nested.zip", projectDir);
JGitBlameCommand jGitBlameCommand = newJGitBlameCommand();
File baseDir = new File(projectDir, "dummy-git-nested/dummy-project");
DefaultFileSystem fs = new DefaultFileSystem(baseDir);
when(input.fileSystem()).thenReturn(fs);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile);
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
jGitBlameCommand.blame(input, blameResult);
Date revisionDate = DateUtils.parseDateTime("2012-07-17T16:12:48+0200");
String revision = "6b3aab35a3ea32c1636fee56f996e677653c48ea";
String author = "david@gageot.net";
verify(blameResult).blameResult(inputFile, Arrays.asList(new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author)));
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonarqube by SonarSource.
the class JGitBlameCommandTest method properFailureIfNotAGitProject.
@Test
public void properFailureIfNotAGitProject() throws IOException {
File projectDir = temp.newFolder();
javaUnzip("dummy-git.zip", projectDir);
JGitBlameCommand jGitBlameCommand = newJGitBlameCommand();
File baseDir = new File(projectDir, "dummy-git");
// Delete .git
FileUtils.forceDelete(new File(baseDir, ".git"));
DefaultFileSystem fs = new DefaultFileSystem(baseDir);
when(input.fileSystem()).thenReturn(fs);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).build();
fs.add(inputFile);
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
assertThatThrownBy(() -> jGitBlameCommand.blame(input, blameResult)).isInstanceOf(MessageException.class).hasMessageContaining("Not inside a Git work tree: ");
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonarqube by SonarSource.
the class JGitBlameCommandTest method dontFailOnSymlink.
@Test
public void dontFailOnSymlink() throws IOException {
assumeTrue(!System2.INSTANCE.isOsWindows());
File projectDir = temp.newFolder();
javaUnzip("dummy-git.zip", projectDir);
JGitBlameCommand jGitBlameCommand = newJGitBlameCommand();
File baseDir = new File(projectDir, "dummy-git");
DefaultFileSystem fs = new DefaultFileSystem(baseDir);
when(input.fileSystem()).thenReturn(fs);
String relativePath = DUMMY_JAVA;
String relativePath2 = "src/main/java/org/dummy/Dummy2.java";
DefaultInputFile inputFile = new TestInputFileBuilder("foo", relativePath).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile);
DefaultInputFile inputFile2 = new TestInputFileBuilder("foo", relativePath2).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile2);
// Create symlink
Files.createSymbolicLink(inputFile2.file().toPath(), inputFile.file().toPath());
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile, inputFile2));
jGitBlameCommand.blame(input, blameResult);
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonarqube by SonarSource.
the class XooBlameCommandTest method prepare.
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
fs = new DefaultFileSystem(baseDir.toPath());
input = mock(BlameInput.class);
when(input.fileSystem()).thenReturn(fs);
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class XmlAnalyzerTest method should_interrupt_analysis_when_InterruptedException_is_thrown.
@Test
public void should_interrupt_analysis_when_InterruptedException_is_thrown() {
DefaultFileSystem fs = new DefaultFileSystem(new File(""));
File pomFile = new File(VALID_POM);
fs.add(new TestInputFileBuilder("", pomFile.getAbsolutePath()).build());
XmlCheckThrowingException check = new XmlCheckThrowingException(new RuntimeException("Analysis cancelled"));
SonarComponents sonarComponents = createSonarComponentsMock(fs, check);
thrown.expectMessage("Analysis cancelled");
thrown.expect(RuntimeException.class);
XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents, check);
analyzer.scan(Lists.newArrayList(pomFile));
}
Aggregations