use of org.sonar.api.batch.fs.FilePredicates in project sonar-java by SonarSource.
the class PmdXmlReportReader method onXmlEvent.
private void onXmlEvent(XMLEvent event) {
if (event.isStartElement()) {
StartElement element = event.asStartElement();
String elementName = element.getName().getLocalPart();
if ("file".equals(elementName)) {
String filePath = getAttributeValue(element, "name");
FilePredicates predicates = context.fileSystem().predicates();
inputFile = context.fileSystem().inputFile(predicates.hasPath(filePath));
if (inputFile == null) {
LOG.warn("No input file found for {}. No PMD issue will be imported on this file.", filePath);
}
} else if ("violation".equals(elementName) && inputFile != null) {
onViolationStartElement(element);
}
} else if (event.isCharacters()) {
issueMessage.append(event.asCharacters().getData());
} else if (event.isEndElement() && "violation".equals(event.asEndElement().getName().getLocalPart()) && inputFile != null && issue != null) {
issueLocation.message(issueMessage.toString());
issue.at(issueLocation).save();
}
}
use of org.sonar.api.batch.fs.FilePredicates in project sonar-java by SonarSource.
the class SpotBugsXmlReportReader method findInputFile.
private static InputFile findInputFile(SensorContext context, List<String> sourceDirs, String relativeLinuxPath) {
FilePredicates predicates = context.fileSystem().predicates();
InputFile inputFile = null;
for (String sourceDir : sourceDirs) {
File sourceFile = new File(sourceDir, relativeLinuxPath);
inputFile = context.fileSystem().inputFile(predicates.hasPath(sourceFile.toString()));
if (inputFile != null) {
break;
}
}
return inputFile;
}
use of org.sonar.api.batch.fs.FilePredicates in project sonar-java by SonarSource.
the class CheckstyleXmlReportReader method onFileElement.
private void onFileElement(StartElement element) {
String filePath = getAttributeValue(element, NAME);
if (filePath.isEmpty()) {
inputFile = null;
return;
}
FilePredicates predicates = context.fileSystem().predicates();
inputFile = context.fileSystem().inputFile(predicates.hasPath(filePath));
if (inputFile == null) {
LOG.warn("No input file found for '{}'. No checkstyle issues will be imported on this file.", filePath);
}
}
use of org.sonar.api.batch.fs.FilePredicates in project sonar-checkstyle by checkstyle.
the class CheckstyleAuditListenerTest method before.
@Before
public void before() {
fileSystem = mock(FileSystem.class);
context = mock(SensorContext.class);
inputFile = mock(InputFile.class);
ruleFinder = mock(ActiveRules.class);
final FilePredicates predicates = mock(FilePredicates.class);
final FilePredicate filePredicate = mock(FilePredicate.class);
when(fileSystem.inputFile(any(FilePredicate.class))).thenReturn(inputFile);
when(fileSystem.predicates()).thenReturn(predicates);
when(predicates.hasAbsolutePath(anyString())).thenReturn(filePredicate);
}
use of org.sonar.api.batch.fs.FilePredicates in project sonar-checkstyle by checkstyle.
the class CheckstyleConfiguration method getSourceFiles.
public List<InputFile> getSourceFiles() {
final FilePredicates predicates = fileSystem.predicates();
final Iterable<InputFile> files = fileSystem.inputFiles(predicates.and(predicates.hasLanguage(CheckstyleConstants.JAVA_KEY), predicates.hasType(InputFile.Type.MAIN)));
final List<InputFile> fileList = new ArrayList<>();
for (InputFile file : files) {
fileList.add(file);
}
return fileList;
}
Aggregations