use of org.sonar.api.batch.fs.InputFile in project sonar-java by SonarSource.
the class UnitTestAnalyzer method analyzeLinesCoveredByTests.
private boolean analyzeLinesCoveredByTests(String sessionId, ExecutionDataStore executionDataStore) {
int i = sessionId.indexOf(' ');
if (i < 0) {
return false;
}
String testClassName = sessionId.substring(0, i);
String testName = sessionId.substring(i + 1);
InputFile testResource = javaResourceLocator.findResourceByClassName(testClassName);
if (testResource == null) {
// No such test class
return false;
}
boolean result = false;
CoverageBuilder coverageBuilder = jacocoReportReader.analyzeFiles(executionDataStore, classFilesOfStore(executionDataStore));
for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) {
InputFile resource = getResource(coverage);
if (resource != null) {
List<Integer> coveredLines = coveredLines(coverage);
if (!coveredLines.isEmpty() && addCoverage(resource, testResource, testName, coveredLines)) {
result = true;
}
}
}
return result;
}
use of org.sonar.api.batch.fs.InputFile in project sonar-java by SonarSource.
the class PostAnalysisIssueFilter method scanFile.
@Override
public void scanFile(JavaFileScannerContext context) {
InputFile component = fileSystem.inputFile(fileSystem.predicates().is(context.getFile()));
if (component == null) {
throw new AnalysisException("Component not found: " + context.getFileKey());
}
String componentKey = component.key();
for (JavaIssueFilter javaIssueFilter : getIssueFilters()) {
javaIssueFilter.setComponentKey(componentKey);
javaIssueFilter.scanFile(context);
}
}
use of org.sonar.api.batch.fs.InputFile in project sonar-java by SonarSource.
the class JavaSquidSensorTest method createContext.
private static SensorContextTester createContext(InputFile.Type onType) throws IOException {
SensorContextTester context = SensorContextTester.create(new File("src/test/java/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
String effectiveKey = "org/sonar/plugins/java/JavaSquidSensorTest.java";
File file = new File(fs.baseDir(), effectiveKey);
DefaultInputFile inputFile = new TestInputFileBuilder("", effectiveKey).setLanguage("java").setModuleBaseDir(fs.baseDirPath()).setType(onType).initMetadata(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8)).setCharset(StandardCharsets.UTF_8).build();
fs.add(inputFile);
return context;
}
use of org.sonar.api.batch.fs.InputFile in project sonar-java by SonarSource.
the class DefaultJavaResourceLocator method findResourceByClassName.
@Override
public InputFile findResourceByClassName(String className) {
String name = className.replace('.', '/');
InputFile inputFile = resourcesByClass.get(name);
if (inputFile == null) {
LOG.debug("Class not found in resource cache : {}", className);
}
return inputFile;
}
use of org.sonar.api.batch.fs.InputFile in project sonar-java by SonarSource.
the class XmlFileSensor method execute.
@Override
public void execute(SensorContext context) {
if (hasXmlFiles()) {
Iterable<InputFile> xmlInputFiles = getXmlFiles();
// make xml files visible in SQ UI, when XML plugin is not installed
xmlInputFiles.forEach(context::markForPublishing);
sonarComponents.registerCheckClasses(CheckList.REPOSITORY_KEY, CheckList.getXmlChecks());
sonarComponents.setSensorContext(context);
new XmlAnalyzer(sonarComponents, sonarComponents.checkClasses()).scan(toFile(xmlInputFiles));
}
}
Aggregations