@Override public ICodeBaseEntry next() throws InterruptedException { final String fileName = fileNameIterator.next(); // Make the filename relative to the directory String resourceName = getResourceName(fileName); // Update last modified time File file = new File(fileName); long modTime = file.lastModified(); addLastModifiedTime(modTime); return new DirectoryCodeBaseEntry(DirectoryCodeBase.this, resourceName); } }
@Override public ICodeBaseEntry lookupResource(String resourceName) { // Translate resource name, in case a resource name // has been overridden and the resource is being accessed // using the overridden name. resourceName = translateResourceName(resourceName); File file = getFullPathOfResource(resourceName); if (!file.exists()) { return null; } return new DirectoryCodeBaseEntry(this, resourceName); }
@Override public InputStream openResource() throws IOException { return codeBase.openFile(realResourceName); }
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 int getNumBytes() { File fullPath = codeBase.getFullPathOfResource(realResourceName); // this is not needed but causes slowdown on a slow file system IO // file.length() returns zero if not found, and matches the contract of // this method // if (!fullPath.exists()) { // return -1; // } return (int) fullPath.length(); }
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); } }
InputStream openFile(String resourceName) throws FileNotFoundException, IOException { File path = getFullPathOfResource(resourceName); return new BufferedInputStream(new FileInputStream(path)); }
@Override public ICodeBaseEntry lookupResource(String resourceName) { // Translate resource name, in case a resource name // has been overridden and the resource is being accessed // using the overridden name. resourceName = translateResourceName(resourceName); File file = getFullPathOfResource(resourceName); if (!file.exists()) { return null; } return new DirectoryCodeBaseEntry(this, resourceName); }
@Override public ICodeBaseEntry next() throws InterruptedException { final String fileName = fileNameIterator.next(); // Make the filename relative to the directory String resourceName = getResourceName(fileName); // Update last modified time File file = new File(fileName); long modTime = file.lastModified(); addLastModifiedTime(modTime); return new DirectoryCodeBaseEntry(DirectoryCodeBase.this, resourceName); } }
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()); }
@Override public int getNumBytes() { File fullPath = codeBase.getFullPathOfResource(realResourceName); // this is not needed but causes slowdown on a slow file system IO // file.length() returns zero if not found, and matches the contract of // this method // if (!fullPath.exists()) { // return -1; // } return (int) fullPath.length(); }
@Override public InputStream openResource() throws IOException { return codeBase.openFile(realResourceName); }
InputStream openFile(String resourceName) throws FileNotFoundException, IOException { File path = getFullPathOfResource(resourceName); return new BufferedInputStream(new FileInputStream(path)); }