@Override public ICodeBaseLocator createFilesystemCodeBaseLocator(String pathName) { // Attempt to canonicalize the pathname. // It's not fatal if we can't. try { pathName = new File(pathName).getCanonicalPath(); } catch (IOException e) { // Ignore } return new FilesystemCodeBaseLocator(pathName); }
static IScannableCodeBase createFilesystemCodeBase(FilesystemCodeBaseLocator codeBaseLocator) throws IOException { String fileName = codeBaseLocator.getPathName(); File file = new File(fileName); if (!file.exists() || !file.canRead()) { return createEmptyCodeBase(codeBaseLocator, file); } else if (file.isDirectory()) { return new DirectoryCodeBase(codeBaseLocator, file); } else if (!file.isFile()) { return createEmptyCodeBase(codeBaseLocator, file); } else if (fileName.endsWith(".class")) { return new SingleFileCodeBase(codeBaseLocator, fileName); } else if (fileName.endsWith(File.separator + "jrt-fs.jar")) { return new JrtfsCodeBase(codeBaseLocator, fileName); } else { try { return ZipCodeBaseFactory.makeZipCodeBase(codeBaseLocator, file); } catch (IOException e) { return createEmptyCodeBase(codeBaseLocator, file); } } }
@Override public ICodeBaseLocator createRelativeCodeBaseLocator(String relativePath) { File path = new File(pathName); if (!path.isDirectory()) { path = path.getParentFile(); } File relativeFile = new File(path, relativePath); return new FilesystemCodeBaseLocator(relativeFile.getPath()); }
if (l.getPathName().endsWith(".java")) { if (DEBUG){ System.err.println("Ignoring .java file \"" + l.getPathName() + "\" specified in classpath or auxclasspath");
private FilesystemCodeBaseLocator buildLocator(File file) throws Exception { return new FilesystemCodeBaseLocator(file.getCanonicalPath()); }
static IScannableCodeBase createFilesystemCodeBase(FilesystemCodeBaseLocator codeBaseLocator) throws IOException { String fileName = codeBaseLocator.getPathName(); File file = new File(fileName); if (!file.exists()) { throw new FileNotFoundException("File " + file.getAbsolutePath() + " doesn't exist"); } else if (!file.canRead()) { throw new IOException("File " + file.getAbsolutePath() + " not readable"); } else if (file.isDirectory()) { return new DirectoryCodeBase(codeBaseLocator, file); } else if (!file.isFile()) { throw new IOException("File " + file.getAbsolutePath() + " is not a normal file"); } else if (fileName.endsWith(".class")) { return new SingleFileCodeBase(codeBaseLocator, fileName); } else { return ZipCodeBaseFactory.makeZipCodeBase(codeBaseLocator, file); } }
private LinkedList<WorkListItem> buildFindBugsFullJarCodebaseList() { String findbugsFullJar = ClassPathUtil.findCodeBaseInClassPath("findbugs-full.jar", SystemProperties.getProperty("java.class.path")); LinkedList<WorkListItem> workList = new LinkedList<>(); if (findbugsFullJar != null) { // // Found findbugs-full.jar: add it to the aux classpath. // (This is a bit weird, since we only want to resolve a subset // of its classes.) // ICodeBaseLocator loc = new FilesystemCodeBaseLocator(findbugsFullJar); workList.addLast(new WorkListItem(loc, false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH)); } return workList; }
if (l.getPathName().endsWith(".java")) { if (DEBUG){ System.err.println("Ignoring .java file \"" + l.getPathName() + "\" specified in classpath or auxclasspath");
@Override public ICodeBaseLocator createFilesystemCodeBaseLocator(String pathName) { // Attempt to canonicalize the pathname. // It's not fatal if we can't. try { pathName = new File(pathName).getCanonicalPath(); } catch (IOException e) { // Ignore } return new FilesystemCodeBaseLocator(pathName); }
public Iterable<ICodeBaseLocator> get(Iterable<String> auxilliaryCodeBasePaths) throws IOException { List<ICodeBaseLocator> auxilliaryCodeBaseLocators = new ArrayList<ICodeBaseLocator>(); for (String codeBasePath : auxilliaryCodeBasePaths) { auxilliaryCodeBaseLocators.add(new FilesystemCodeBaseLocator(codeBasePath)); } return unmodifiableList(auxilliaryCodeBaseLocators); }
@Override public ICodeBaseLocator createRelativeCodeBaseLocator(String relativePath) { File path = new File(pathName); if (!path.isDirectory()) { path = path.getParentFile(); } File relativeFile = new File(path, relativePath); return new FilesystemCodeBaseLocator(relativeFile.getPath()); }
private LinkedList<WorkListItem> buildFindBugsFullJarCodebaseList() { String findbugsFullJar = ClassPathUtil.findCodeBaseInClassPath("findbugs-full.jar", SystemProperties.getProperty("java.class.path")); LinkedList<WorkListItem> workList = new LinkedList<WorkListItem>(); if (findbugsFullJar != null) { // // Found findbugs-full.jar: add it to the aux classpath. // (This is a bit weird, since we only want to resolve a subset // of its classes.) // ICodeBaseLocator loc = new FilesystemCodeBaseLocator(findbugsFullJar); workList.addLast(new WorkListItem(loc, false, ICodeBase.Discovered.IN_SYSTEM_CLASSPATH)); } return workList; }
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()); }