public InputStream openSource(SourceLineAnnotation source) throws IOException { SourceFile sourceFile = findSourceFile(source); return sourceFile.getInputStream(); }
public SourceFinder getSourceFinder() { if (sourceFinder == null) { sourceFinder = new SourceFinder(this); } return sourceFinder; }
String platformName = getPlatformName(packageName, fileName); String canonicalName = getCanonicalName(packageName, fileName);
public static String getCanonicalName(SourceLineAnnotation source) { return getCanonicalName(source.getPackageName(), getOrGuessSourceFile(source)); }
public SourceFile findSourceFile(SourceLineAnnotation source) throws IOException { return findSourceFile(source.getPackageName(), getOrGuessSourceFile(source)); }
public static String getPlatformName(SourceLineAnnotation source) { return getPlatformName(source.getPackageName(), getOrGuessSourceFile(source)); }
origCollection = new SortedBugCollection(); origCollection.readXML(args[0]); SourceFinder sourceFinder = new SourceFinder(origCollection.getProject()); continue; if (!sourceFinder.hasSourceFile(s)) { continue; SourceFile sourceFile = sourceFinder.findSourceFile(s); long when = sourceFile.getLastModified(); if (when > 0) {
private void copySourceForAnnotation(BugAnnotation ann) { SourceLineAnnotation sourceAnnotation; if (ann instanceof BugAnnotationWithSourceLines) { sourceAnnotation = ((BugAnnotationWithSourceLines) ann).getSourceLines(); } else if (ann instanceof SourceLineAnnotation) { sourceAnnotation = (SourceLineAnnotation) ann; } else { return; } if (sourceAnnotation == null) { return; } if (sourceAnnotation.isUnknown()) { return; } String fullName = SourceFinder.getPlatformName(sourceAnnotation); SourceFile sourceFile; try { sourceFile = sourceFinder.findSourceFile(sourceAnnotation); } catch (IOException e) { if (couldNotFind.add(fullName)) { System.out.println("Did not find " + fullName); } return; } if (copied.add(fullName)) { copySourceFile(fullName, sourceFile); } }
/** * A zip or jar archive containing source files. */ static class ZipSourceRepository implements SourceRepository { ZipFile zipFile; public ZipSourceRepository(@WillCloseWhenClosed ZipFile zipFile) { this.zipFile = zipFile; } @Override public boolean contains(String fileName) { return zipFile.getEntry(fileName) != null; } @Override public boolean isPlatformDependent() { return false; } @Override public SourceFileDataSource getDataSource(String fileName) { return new ZipSourceFileDataSource(zipFile, fileName); } @Override public void close() throws IOException { zipFile.close(); } }
/** * @param url * @return * @throws IOException * @throws MalformedURLException */ private InputStream open(final String url) throws IOException, MalformedURLException { InputStream in = null; URLConnection connection = new URL(url).openConnection(); if (getProject().isGuiAvaliable()) { int size = connection.getContentLength(); in = getProject().getGuiCallback().getProgressMonitorInputStream(connection.getInputStream(), size, "Loading source via url"); } else { in = connection.getInputStream(); } return in; }
public boolean findSource(SourceLineAnnotation srcLine) { if (srcLine == null) { return false; } String cName = srcLine.getClassName(); if (sourceFound.contains(cName)) { return true; } if (sourceNotFound.contains(cName)) { return false; } boolean result = sourceFinder.hasSourceFile(srcLine); return result; }
public boolean findSource0(SourceLineAnnotation srcLine) { if (srcLine == null) { return false; } String cName = srcLine.getClassName(); if (sourceFound.contains(cName)) { return true; } if (sourceNotFound.contains(cName)) { return false; } try { InputStream in = sourceFinder.openSource(srcLine); in.close(); sourceFound.add(cName); return true; } catch (IOException e1) { sourceNotFound.add(cName); return false; } }
/** * Set the list of source directories. */ void setSourceBaseList(Iterable<String> sourceBaseList) { for (String repos : sourceBaseList) { if (repos.endsWith(".zip") || repos.endsWith(".jar") || repos.endsWith(".z0p.gz")) { // Zip or jar archive try { if (repos.startsWith("http:") || repos.startsWith("https:") || repos.startsWith("file:")) { String url = SystemProperties.rewriteURLAccordingToProperties(repos); repositoryList.add(makeInMemorySourceRepository(url)); } else { repositoryList.add(new ZipSourceRepository(new ZipFile(repos))); } } catch (IOException e) { // Ignored - we won't use this archive AnalysisContext.logError("Unable to load " + repos, e); } } else { File dir = new File(repos); if (dir.canRead() && dir.isDirectory()) { repositoryList.add(new DirectorySourceRepository(repos)); } else { AnalysisContext.logError("Unable to load " + repos); } } } }
public SourceFile findSourceFile(SourceLineAnnotation source) throws IOException { return findSourceFile(source.getPackageName(), getOrGuessSourceFile(source)); }
private void copySourceForAnnotation(BugAnnotation ann) { SourceLineAnnotation sourceAnnotation; if (ann instanceof BugAnnotationWithSourceLines) { sourceAnnotation = ((BugAnnotationWithSourceLines) ann).getSourceLines(); } else if (ann instanceof SourceLineAnnotation) { sourceAnnotation = (SourceLineAnnotation) ann; } else { return; } if (sourceAnnotation == null) { return; } if (sourceAnnotation.isUnknown()) { return; } String fullName = SourceFinder.getPlatformName(sourceAnnotation); SourceFile sourceFile; try { sourceFile = sourceFinder.findSourceFile(sourceAnnotation); } catch (IOException e) { if (couldNotFind.add(fullName)) { System.out.println("Did not find " + fullName); } return; } if (copied.add(fullName)) { copySourceFile(fullName, sourceFile); } }
public static String getCanonicalName(SourceLineAnnotation source) { return getCanonicalName(source.getPackageName(), getOrGuessSourceFile(source)); }
public static String getPlatformName(SourceLineAnnotation source) { return getPlatformName(source.getPackageName(), getOrGuessSourceFile(source)); }
/** * A zip or jar archive containing source files. */ static class ZipSourceRepository implements SourceRepository { ZipFile zipFile; public ZipSourceRepository(ZipFile zipFile) { this.zipFile = zipFile; } @Override public boolean contains(String fileName) { return zipFile.getEntry(fileName) != null; } @Override public boolean isPlatformDependent() { return false; } @Override public SourceFileDataSource getDataSource(String fileName) { return new ZipSourceFileDataSource(zipFile, fileName); } }
SourceRepository makeInMemorySourceRepository(final String url) { final BlockingSourceRepository r = new BlockingSourceRepository(); Util.runInDameonThread(() -> { InputStream in = null; try { URLConnection connection = new URL(url).openConnection(); in = connection.getInputStream(); if (getProject().isGuiAvaliable()) { in = getProject().getGuiCallback().getProgressMonitorInputStream(in, connection.getContentLength(), "Downloading project source code..."); } if (url.endsWith(".z0p.gz")) { in = new GZIPInputStream(in); } r.setBase(new InMemorySourceRepository(new ZipInputStream(in))); } catch (IOException e) { if (getProject().isGuiAvaliable()) { getProject().getGuiCallback().setErrorMessage("Unable to load " + url + "; " + e.getMessage()); } AnalysisContext.logError("Unable to load " + url, e); Util.closeSilently(in); } }, "Source loading thread"); return r; }
public boolean findSource(SourceLineAnnotation srcLine) { if (srcLine == null) { return false; } String cName = srcLine.getClassName(); if (sourceFound.contains(cName)) { return true; } if (sourceNotFound.contains(cName)) { return false; } boolean result = sourceFinder.hasSourceFile(srcLine); return result; }