@Override public void log(Throwable exception, String format, Object... args) { mDelegate.log(exception, format, args); }
private static boolean createCache(LintClient client, File xmlFile, File binaryData) { long begin = 0; if (WRITE_STATS) { begin = System.currentTimeMillis(); } // Read in data List<String> lines; try { lines = Files.readLines(xmlFile, Charsets.UTF_8); } catch (IOException e) { client.log(e, "Can't read typo database file"); return false; } if (WRITE_STATS) { long end = System.currentTimeMillis(); System.out.println("Reading data structures took " + (end - begin) + " ms)"); } try { writeDatabase(binaryData, lines); return true; } catch (IOException ioe) { client.log(ioe, "Can't write typo cache file"); } return false; }
protected void readManifest(File manifest) { if (manifest.exists()) { try { String xml = Files.toString(manifest, Charsets.UTF_8); Document document = XmlUtils.parseDocumentSilently(xml, true); if (document != null) { readManifest(document); } } catch (IOException e) { client.log(e, "Could not read manifest %1$s", manifest); } } }
protected void readManifest(File manifest) { if (manifest.exists()) { try { String xml = Files.toString(manifest, Charsets.UTF_8); Document document = XmlUtils.parseDocumentSilently(xml, true); if (document != null) { readManifest(document); } } catch (IOException e) { mClient.log(e, "Could not read manifest %1$s", manifest); } } }
private List<File> getAospJavaClassPath() { List<File> classDirs = new ArrayList<>(1); for (File dir : getIntermediateDirs()) { File classes = new File(dir, "classes"); if (classes.exists()) { classDirs.add(classes); } else { classes = new File(dir, "classes.jar"); if (classes.exists()) { classDirs.add(classes); } } } if (classDirs.isEmpty()) { client.log(null, "No bytecode found: Has the project been built? (%1$s)", getName()); } return classDirs; }
private List<File> getAospJavaSourcePath() { List<File> sources = new ArrayList<>(2); // Normal sources File src = new File(dir, "src"); if (src.exists()) { sources.add(src); } // Generates sources for (File dir : getIntermediateDirs()) { File classes = new File(dir, "src"); if (classes.exists()) { sources.add(classes); } } if (sources.isEmpty()) { client.log(null, "Warning: Could not find sources or generated sources for project %1$s", getName()); } return sources; }
@Override public PsiJavaFile parseJavaToPsi(@NonNull JavaContext context) { if (sourceUnits != null && ecjResult != null) { EcjSourceFile sourceUnit = sourceUnits.get(context.file); if (sourceUnit != null) { try { return ecjResult.findFile(sourceUnit); } catch (Throwable t) { client.log(t, "Failed converting ECJ parse tree to PSI for file %1$s", context.file.getPath()); return null; } } } return null; }
private static boolean createCache(LintClient client, File xmlFile, File binaryData, boolean isSupport) { long begin = 0; if (WRITE_STATS) { begin = System.currentTimeMillis(); } Api info = Api.parseApi(xmlFile); if (WRITE_STATS) { long end = System.currentTimeMillis(); System.out.println("Reading XML data structures took " + (end - begin) + " ms)"); } if (info != null) { try { writeDatabase(binaryData, info, isSupport); return true; } catch (IOException ioe) { client.log(ioe, "Can't write API cache file"); } } return false; }
private static boolean createCache(LintClient client, File xmlFile, File binaryData) { long begin = 0; if (WRITE_STATS) { begin = System.currentTimeMillis(); } Api info = Api.parseApi(xmlFile); if (WRITE_STATS) { long end = System.currentTimeMillis(); System.out.println("Reading XML data structures took " + (end - begin) + " ms)"); } if (info != null) { try { writeDatabase(binaryData, info); return true; } catch (IOException ioe) { client.log(ioe, "Can't write API cache file"); } } return false; }
private static boolean createCache(LintClient client, File xmlFile, File binaryData) { long begin = 0; if (WRITE_STATS) { begin = System.currentTimeMillis(); } Api info = Api.parseApi(xmlFile); if (WRITE_STATS) { long end = System.currentTimeMillis(); System.out.println("Reading XML data structures took " + (end - begin) + " ms)"); } if (info != null) { try { writeDatabase(binaryData, info); return true; } catch (IOException ioe) { client.log(ioe, "Can't write API cache file"); } } return false; }
@Nullable private static AnnotationsDatabase getDatabase( @NonNull LintClient client, @NonNull File file) { try { return file.isFile() ? new AnnotationsDatabase(file) : null; } catch (IOException ioe) { client.log(ioe, "Could not read %1$s", file.getPath()); return null; } }
/** * Adds in any custom lint rules and returns the result as a new issue registry, * or the same one if no custom rules were found * * @param registry the main registry to add rules to * @return a new registry containing the passed in rules plus any custom rules, * or the original registry if no custom rules were found */ public IssueRegistry addCustomLintRules(@NonNull IssueRegistry registry) { List<File> jarFiles = findGlobalRuleJars(); if (!jarFiles.isEmpty()) { List<IssueRegistry> registries = Lists.newArrayListWithExpectedSize(jarFiles.size()); registries.add(registry); for (File jarFile : jarFiles) { try { registries.add(JarFileIssueRegistry.get(this, jarFile)); } catch (Throwable e) { log(e, "Could not load custom rule jar file %1$s", jarFile); } } if (registries.size() > 1) { // the first item is the passed in registry itself return new CompositeIssueRegistry(registries); } } return registry; }
/** * Add all .java files found in the given folder, and add it to the source maps as well * as the result list */ private void gatherJavaFiles(@NonNull List<EcjSourceFile> sources, @NonNull File dir) { File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (file.isFile() && file.getName().endsWith(DOT_JAVA)) { try { CharSequence contents = LintUtils.getEncodedString(client, file, false); EcjSourceFile unit = EcjSourceFile.create(contents, file); sources.add(unit); sourceUnits.put(file, unit); } catch (IOException e) { client.log(Severity.ERROR, e, "Couldn't read %1$s", file); } } else if (file.isDirectory()) { gatherJavaFiles(sources, file); } } } }
@Override public void log(@Nullable Throwable exception, @Nullable String format, @Nullable Object... args) { mDelegate.log(exception, format, args); }
/** Adds in all the super classes found for the given class entries into the given map */ private static void addSuperClasses( @NonNull LintClient client, @NonNull SuperclassVisitor visitor, @NonNull List<ClassEntry> entries) { for (ClassEntry entry : entries) { try { ClassReader reader = new ClassReader(entry.bytes); int flags = ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES; reader.accept(visitor, flags); } catch (Throwable t) { client.log(null, "Error processing %1$s: broken class file?", entry.path()); } } }
private void checkIndividualJavaFiles( @NonNull Project project, @Nullable Project main, @NonNull List<Detector> checks, @NonNull List<File> files) { JavaParser javaParser = client.getJavaParser(project); if (javaParser == null) { client.log(null, "No java parser provided to lint: not running Java checks"); return; } List<JavaContext> contexts = Lists.newArrayListWithExpectedSize(files.size()); for (File file : files) { if (file.isFile() && file.getPath().endsWith(DOT_JAVA)) { contexts.add(new JavaContext(this, project, main, file, javaParser)); } } if (contexts.isEmpty()) { return; } visitJavaFiles(checks, javaParser, contexts); }
/** * Send an exception or error message (with warning severity) to the log * * @param exception the exception, possibly null * @param format the error message using {@link String#format} syntax, possibly null * (though in that case the exception should not be null) * @param args any arguments for the format string */ public void log( @Nullable Throwable exception, @Nullable String format, @Nullable Object... args) { log(Severity.WARNING, exception, format, args); }
@Override public void log(@NonNull Severity severity, @Nullable Throwable exception, @Nullable String format, @Nullable Object... args) { mDelegate.log(exception, format, args); }
/** * Send an exception to the log. Convenience wrapper around {@link LintClient#log}. * * @param exception the exception, possibly null * @param format the error message using {@link String#format} syntax, possibly null * @param args any arguments for the format string */ public void log( @Nullable Throwable exception, @Nullable String format, @Nullable Object... args) { driver.getClient().log(exception, format, args); }
@Override public void report(Context context, Issue issue, Location location, String message, Object data) { Configuration configuration = context.configuration; if (!configuration.isEnabled(issue)) { if (issue != IssueRegistry.PARSER_ERROR) { mDelegate.log(null, "Incorrect detector reported disabled issue %1$s", issue.toString()); } return; } if (configuration.isIgnored(context, issue, location, message, data)) { return; } Severity severity = configuration.getSeverity(issue); if (severity == Severity.IGNORE) { return; } mDelegate.report(context, issue, location, message, data); }