for (File jarFile : jarFiles) { try { JarFileIssueRegistry registry = JarFileIssueRegistry.get(client, jarFile); if (registry.hasLegacyDetectors()) { runCompatChecks = true; myCustomIssues = Sets.newHashSet(); myCustomIssues.addAll(registry.getIssues()); registries.add(registry); } catch (Throwable e) {
@NonNull public static JarFileIssueRegistry get(@NonNull LintClient client, @NonNull File jarFile) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { if (cache == null) { cache = new HashMap<>(); } else { SoftReference<JarFileIssueRegistry> reference = cache.get(jarFile); if (reference != null) { JarFileIssueRegistry registry = reference.get(); if (registry != null) { return registry; } } } // Ensure that the scope-to-detector map doesn't return stale results IssueRegistry.reset(); JarFileIssueRegistry registry = new JarFileIssueRegistry(client, jarFile); cache.put(jarFile, new SoftReference<>(registry)); return registry; }
/** * 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; }
loadAndCloseURLClassLoader(client, file, (URLClassLoader)loader);