IClassPathBuilder builder = classFactory.createClassPathBuilder(bugReporter); for (String path : project.getFileArray()) { if (seen.add(path)) { builder.addCodeBase(classFactory.createFilesystemCodeBaseLocator(path), true); builder.addCodeBase(classFactory.createFilesystemCodeBaseLocator(path), false);
private IClassPath buildClassPath(IClassPathBuilder builder, IClassFactory factory) throws InterruptedException, IOException, CheckedAnalysisException { progress.startScanningArchives(project.getFileCount()); for (String path : project.getFileList()) { builder.addCodeBase(factory.createFilesystemCodeBaseLocator(path), true); } for (String path : project.getAuxClasspathEntryList()) { builder.addCodeBase(factory.createFilesystemCodeBaseLocator(path), false); } IClassPath classPath = factory.createClassPath(); builder.build(classPath, progress); progress.doneScanningArchives(); return classPath; }
private static void setUpStaticDependenciesWithinFindBugs(BugReporter bugReporter) throws Exception { bugReporter.setPriorityThreshold(Priorities.LOW_PRIORITY); ClassPathImpl classPath = new ClassPathImpl(); IAnalysisCache analysisCache = ClassFactory.instance().createAnalysisCache(classPath, bugReporter); new ClassContextClassAnalysisEngine().registerWith(analysisCache); new edu.umd.cs.findbugs.classfile.engine.asm.EngineRegistrar().registerAnalysisEngines(analysisCache); new edu.umd.cs.findbugs.classfile.engine.bcel.EngineRegistrar().registerAnalysisEngines(analysisCache); new edu.umd.cs.findbugs.classfile.engine.EngineRegistrar().registerAnalysisEngines(analysisCache); registerUserDefined(analysisCache); Global.setAnalysisCacheForCurrentThread(analysisCache); ICodeBaseLocator codeBaseLocator = new FilesystemCodeBaseLocator("."); ICodeBase codeBase = new DirectoryCodeBase(codeBaseLocator, new File(CODEBASE_DIRECTORY)); codeBase.setApplicationCodeBase(true); classPath.addCodeBase(codeBase); addAuxCodeBasesFromClassPath(classPath); IClassFactory classFactory = ClassFactory.instance(); IClassPathBuilder builder = classFactory.createClassPathBuilder(bugReporter); builder.addCodeBase(codeBaseLocator, true); builder.scanNestedArchives(true); IClassPathBuilderProgress progress = new NoOpFindBugsProgress(); builder.build(classPath, progress); List<ClassDescriptor> appClassList = builder.getAppClassList(); AnalysisCacheToAnalysisContextAdapter analysisContext = new AnalysisCacheToAnalysisContextAdapter(); AnalysisContext.setCurrentAnalysisContext(analysisContext); analysisContext.setAppClassList(appClassList); analysisContext.setFieldSummary(new FieldSummary()); }
/** * Add worklist items from given system classpath. * * @param workList * the worklist * @param path * a system classpath */ private void addWorkListItemsForClasspath(LinkedList<WorkListItem> workList, String path) { if (path == null) { return; } StringTokenizer st = new StringTokenizer(path, File.pathSeparator); while (st.hasMoreTokens()) { String entry = st.nextToken(); if (DEBUG) { System.out.println("System classpath entry: " + entry); } addToWorkList(workList, new WorkListItem(classFactory.createFilesystemCodeBaseLocator(entry), false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH)); } }
/** * Create the analysis cache object and register it for current execution thread. * <p> * This method is protected to allow clients override it and possibly reuse * some previous analysis data (for Eclipse interactive re-build) * * @throws IOException * if error occurs registering analysis engines in a plugin */ protected IAnalysisCache createAnalysisCache() throws IOException { IAnalysisCache analysisCache = ClassFactory.instance().createAnalysisCache(classPath, bugReporter); // Register the "built-in" analysis engines registerBuiltInAnalysisEngines(analysisCache); // Register analysis engines in plugins registerPluginAnalysisEngines(detectorFactoryCollection, analysisCache); // Install the DetectorFactoryCollection as a database analysisCache.eagerlyPutDatabase(DetectorFactoryCollection.class, detectorFactoryCollection); Global.setAnalysisCacheForCurrentThread(analysisCache); return analysisCache; } /**
IClassPathBuilder builder = factory.createClassPathBuilder(errorLogger);
/** * Create the classpath object. */ private void createClassPath() { classPath = classFactory.createClassPath(); }
System.out.println("Entry is an library!"); ICodeBaseLocator nestedArchiveLocator = classFactory.createNestedArchiveCodeBaseLocator(codeBase, entry.getResourceName()); addToWorkList(workList,
/** * Add worklist items from given extensions directory. * * @param workList * the worklist * @param extDir * an extensions directory */ private void addWorkListItemsForExtDir(LinkedList<WorkListItem> workList, String extDir) { File dir = new File(extDir); File[] fileList = dir.listFiles((FileFilter) pathname -> { String path = pathname.getPath(); boolean isArchive = Archive.isArchiveFileName(path); return isArchive; }); if (fileList == null) { return; } for (File archive : fileList) { addToWorkList(workList, new WorkListItem(classFactory.createFilesystemCodeBaseLocator(archive.getPath()), false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH)); } }
/** * Create the analysis cache object and register it for current execution thread. * <p> * This method is protected to allow clients override it and possibly reuse * some previous analysis data (for Eclipse interactive re-build) * * @throws IOException * if error occurs registering analysis engines in a plugin */ protected IAnalysisCache createAnalysisCache() throws IOException { IAnalysisCache analysisCache = ClassFactory.instance().createAnalysisCache(classPath, bugReporter); // Register the "built-in" analysis engines registerBuiltInAnalysisEngines(analysisCache); // Register analysis engines in plugins registerPluginAnalysisEngines(detectorFactoryCollection, analysisCache); // Install the DetectorFactoryCollection as a database analysisCache.eagerlyPutDatabase(DetectorFactoryCollection.class, detectorFactoryCollection); Global.setAnalysisCacheForCurrentThread(analysisCache); return analysisCache; } /**
try { IClassFactory factory = ClassFactory.instance(); IClassPathBuilder builder = factory.createClassPathBuilder(errorLogger);
/** * Create the classpath object. */ private void createClassPath() { classPath = classFactory.createClassPath(); }
System.out.println("Entry is an library!"); ICodeBaseLocator nestedArchiveLocator = classFactory.createNestedArchiveCodeBaseLocator(codeBase, entry.getResourceName()); addToWorkList(workList,
IClassPathBuilder builder = classFactory.createClassPathBuilder(bugReporter); for (String path : project.getFileArray()) { if (seen.add(path)) { builder.addCodeBase(classFactory.createFilesystemCodeBaseLocator(path), true); builder.addCodeBase(classFactory.createFilesystemCodeBaseLocator(path), false);
private IClassPath buildClassPath(IClassPathBuilder builder, IClassFactory factory) throws InterruptedException, IOException, CheckedAnalysisException { progress.startScanningArchives(project.getFileCount()); for (String path : project.getFileList()) { builder.addCodeBase(factory.createFilesystemCodeBaseLocator(path), true); } for (String path : project.getAuxClasspathEntryList()) { builder.addCodeBase(factory.createFilesystemCodeBaseLocator(path), false); } IClassPath classPath = factory.createClassPath(); builder.build(classPath, progress); progress.doneScanningArchives(); return classPath; }
ICodeBaseLocator codeBaseLocator = classFactory.createFilesystemCodeBaseLocator(loc.getPath()); workList.add(new WorkListItem(codeBaseLocator, false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH)); ICodeBaseLocator codeBaseLocator = classFactory.createFilesystemCodeBaseLocator(entry); workList.add(new WorkListItem(codeBaseLocator, false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH)); break;
/** * Add worklist items from given system classpath. * * @param workList * the worklist * @param path * a system classpath */ private void addWorkListItemsForClasspath(LinkedList<WorkListItem> workList, String path) { if (path == null) { return; } StringTokenizer st = new StringTokenizer(path, File.pathSeparator); while (st.hasMoreTokens()) { String entry = st.nextToken(); if (DEBUG) { System.out.println("System classpath entry: " + entry); } addToWorkList(workList, new WorkListItem(classFactory.createFilesystemCodeBaseLocator(entry), false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH)); } }
addToWorkList(workList, new WorkListItem(classFactory.createFilesystemCodeBaseLocator(archive.getPath()), false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH));
ICodeBaseLocator codeBaseLocator = classFactory.createFilesystemCodeBaseLocator(loc.getPath()); workList.add(new WorkListItem(codeBaseLocator, false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH)); ICodeBaseLocator codeBaseLocator = classFactory.createFilesystemCodeBaseLocator(entry); workList.add(new WorkListItem(codeBaseLocator, false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH)); break;