use of org.sonar.plugins.java.api.JavaFileScannerContext in project sonar-java by SonarSource.
the class CommonsCollectionsTest method initAndScan.
private void initAndScan() {
File prjDir = new File("target/test-projects/commons-collections-3.2.1");
File srcDir = new File(prjDir, "src");
context = SensorContextTester.create(srcDir);
DefaultFileSystem fs = context.fileSystem();
Collection<File> files = FileUtils.listFiles(srcDir, new String[] { "java" }, true);
for (File file : files) {
fs.add(new TestInputFileBuilder("", file.getPath()).build());
}
Measurer measurer = new Measurer(fs, context, mock(NoSonarFilter.class));
JavaResourceLocator javaResourceLocator = new JavaResourceLocator() {
public Map<String, String> sourceFileCache = Maps.newHashMap();
@Override
public InputFile findResourceByClassName(String className) {
return null;
}
@Override
public String findSourceFileKeyByClassName(String className) {
String name = className.replace('.', '/');
return sourceFileCache.get(name);
}
@Override
public Collection<File> classFilesToAnalyze() {
return Collections.emptyList();
}
@Override
public Collection<File> classpath() {
return null;
}
@Override
public void scanFile(JavaFileScannerContext context) {
JavaFilesCache javaFilesCache = new JavaFilesCache();
javaFilesCache.scanFile(context);
for (String key : javaFilesCache.resourcesCache.keySet()) {
sourceFileCache.put(key, context.getFileKey());
}
}
};
squid = new JavaSquid(new JavaVersionImpl(), null, measurer, javaResourceLocator, null, new JavaCheck[0]);
squid.scan(files, Collections.<File>emptyList());
}
use of org.sonar.plugins.java.api.JavaFileScannerContext in project sonar-java by SonarSource.
the class DebugCheckTestUtils method verifyIssuesWithMaxSteps.
static void verifyIssuesWithMaxSteps(String sourcefile, SECheck check, int maxSteps) {
BehaviorCache behaviorCache = new BehaviorCache(new SquidClassLoader(new ArrayList<>()));
SymbolicExecutionVisitor sev = new SymbolicExecutionVisitor(Collections.singletonList(check), behaviorCache) {
@Override
protected ExplodedGraphWalker getWalker() {
return new ExplodedGraphWalker(Collections.singletonList(check), behaviorCache, (SemanticModel) context.getSemanticModel()) {
@Override
protected int maxSteps() {
return maxSteps;
}
};
}
@Override
public void scanFile(JavaFileScannerContext context) {
super.scanFile(context);
// the check has been executed, but we still need to call the scan manually to report the issues
check.scanFile(context);
}
};
JavaCheckVerifier.verify(sourcefile, sev);
}
Aggregations