use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class FileExtensionPredicateTest method mockWithName.
private InputFile mockWithName(String filename) throws IOException {
InputFile inputFile = mock(InputFile.class);
when(inputFile.file()).thenReturn(new File("dummy parent", filename));
return inputFile;
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class SensorContextTesterTest method testAnalysisErrors.
@Test
public void testAnalysisErrors() {
assertThat(tester.allAnalysisErrors()).isEmpty();
NewAnalysisError newAnalysisError = tester.newAnalysisError();
InputFile file = new TestInputFileBuilder("foo", "src/Foo.java").build();
newAnalysisError.onFile(file).message("error").at(new DefaultTextPointer(5, 2)).save();
assertThat(tester.allAnalysisErrors()).hasSize(1);
AnalysisError analysisError = tester.allAnalysisErrors().iterator().next();
assertThat(analysisError.inputFile()).isEqualTo(file);
assertThat(analysisError.message()).isEqualTo("error");
assertThat(analysisError.location()).isEqualTo(new DefaultTextPointer(5, 2));
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class FilenamePredicateTest method should_not_match_file_by_different_filename.
@Test
public void should_not_match_file_by_different_filename() throws IOException {
String filename = "some name";
InputFile inputFile = mock(InputFile.class);
when(inputFile.file()).thenReturn(newDummyFile(filename + "x"));
assertThat(new FilenamePredicate(filename).apply(inputFile)).isFalse();
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class FilenamePredicateTest method should_match_file_by_filename.
@Test
public void should_match_file_by_filename() throws IOException {
String filename = "some name";
InputFile inputFile = mock(InputFile.class);
when(inputFile.file()).thenReturn(newDummyFile(filename));
assertThat(new FilenamePredicate(filename).apply(inputFile)).isTrue();
}
use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.
the class CpdExecutor method runCpdAnalysis.
@VisibleForTesting
void runCpdAnalysis(ExecutorService executorService, String componentKey, final Collection<Block> fileBlocks, long timeout) {
DefaultInputComponent component = (DefaultInputComponent) componentStore.getByKey(componentKey);
if (component == null) {
LOG.error("Resource not found in component store: {}. Skipping CPD computation for it", componentKey);
return;
}
InputFile inputFile = (InputFile) component;
LOG.debug("Detection of duplications for {}", inputFile.absolutePath());
progressReport.message(String.format("%d/%d - current file: %s", count, total, inputFile.absolutePath()));
List<CloneGroup> duplications;
Future<List<CloneGroup>> futureResult = executorService.submit(() -> SuffixTreeCloneDetectionAlgorithm.detect(index, fileBlocks));
try {
duplications = futureResult.get(timeout, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
LOG.warn("Timeout during detection of duplications for " + inputFile.absolutePath());
futureResult.cancel(true);
return;
} catch (Exception e) {
throw new IllegalStateException("Fail during detection of duplication for " + inputFile.absolutePath(), e);
}
List<CloneGroup> filtered;
if (!"java".equalsIgnoreCase(inputFile.language())) {
Predicate<CloneGroup> minimumTokensPredicate = DuplicationPredicates.numberOfUnitsNotLessThan(getMinimumTokens(inputFile.language()));
filtered = from(duplications).filter(minimumTokensPredicate).toList();
} else {
filtered = duplications;
}
saveDuplications(component, filtered);
}
Aggregations