private void checkJava(Project project, List<File> sourceFolders, List<Detector> checks) { Context context = new Context(mClient, project, project.getDir(), mScope); fireEvent(EventType.SCANNING_FILE, context); for (Detector detector : checks) { ((Detector.JavaScanner) detector).checkJavaSources(context, sourceFolders); if (mCanceled) { return; } } }
private void checkClasses(Project project, List<File> binFolders, List<Detector> checks) { Context context = new Context(mClient, project, project.getDir(), mScope); fireEvent(EventType.SCANNING_FILE, context); for (Detector detector : checks) { ((Detector.ClassScanner) detector).checkJavaClasses(context); if (mCanceled) { return; } } }
private void checkPropertyFile(Project project, Project main, List<Detector> detectors, String relativePath) { File file = new File(project.getDir(), relativePath); if (file.exists()) { Context context = new Context(this, project, main, file); fireEvent(EventType.SCANNING_FILE, context); for (Detector detector : detectors) { detector.beforeCheckFile(context); detector.run(context); detector.afterCheckFile(context); } } }
XmlVisitor visitor = getVisitor(type, xmlDetectors); if (visitor != null) { Context context = new Context(mClient, project, file, mScope); fireEvent(EventType.SCANNING_FILE, context); visitor.visitFile(context, file);
private void checkResourceFolder(Project project, File dir, ResourceFolderType type, List<ResourceXmlDetector> checks) { // Process the resource folder File[] xmlFiles = dir.listFiles(); if (xmlFiles != null && xmlFiles.length > 0) { XmlVisitor visitor = getVisitor(type, checks); if (visitor != null) { // if not, there are no applicable rules in this folder for (File file : xmlFiles) { if (LintUtils.isXmlFile(file)) { Context context = new Context(mClient, project, file, mScope); fireEvent(EventType.SCANNING_FILE, context); visitor.visitFile(context, file); if (mCanceled) { return; } } } } } }
private void formatError(String message, Object... args) { if (args != null && args.length > 0) { message = String.format(message, args); } message = "Failed to parse `lint.xml` configuration file: " + message; LintDriver driver = new LintDriver(new IssueRegistry() { @Override @NonNull public List<Issue> getIssues() { return Collections.emptyList(); } }, client); client.report(new Context(driver, project, project, configFile), IssueRegistry.LINT_ERROR, project.getConfiguration(driver).getSeverity(IssueRegistry.LINT_ERROR), Location.create(configFile), message, TextFormat.RAW); }
private void checkProGuard(Project project, Project main) { List<Detector> detectors = scopeDetectors.get(Scope.PROGUARD_FILE); if (detectors != null) { List<File> files = project.getProguardFiles(); for (File file : files) { Context context = new Context(this, project, main, file); fireEvent(EventType.SCANNING_FILE, context); for (Detector detector : detectors) { detector.beforeCheckFile(context); detector.run(context); detector.afterCheckFile(context); } } } }
private void checkBuildScripts(Project project, Project main) { List<Detector> detectors = scopeDetectors.get(Scope.GRADLE_FILE); if (detectors != null) { List<File> files = project.getSubset(); if (files == null) { files = project.getGradleBuildScripts(); } for (File file : files) { Context context = new Context(this, project, main, file); fireEvent(EventType.SCANNING_FILE, context); for (Detector detector : detectors) { detector.beforeCheckFile(context); detector.visitBuildScript(context, Maps.newHashMap()); detector.afterCheckFile(context); } } } }
Context context = new Context(driver, project, main, file); for (Detector detector : applicable) { detector.beforeCheckFile(context);
Context context = new Context(mClient, project, manifestFile, mScope); context.location = new Location(manifestFile, null, null); IDomParser parser = mClient.getParser(); File file = new File(project.getDir(), PROGUARD_CFG); if (file.exists()) { Context context = new Context(mClient, project, file, mScope); fireEvent(EventType.SCANNING_FILE, context); context.location = new Location(file, null, null);
phase++; fireEvent(EventType.NEW_PHASE, new Context(this, project, null, project.getDir()));
private void checkProject(Project project) { File projectDir = project.getDir(); Context projectContext = new Context(mClient, project, projectDir, mScope); fireEvent(EventType.SCANNING_PROJECT, projectContext); for (Detector check : mApplicableDetectors) { check.beforeCheckProject(projectContext); if (mCanceled) { return; } } runFileDetectors(project, projectDir); for (Detector check : mApplicableDetectors) { check.afterCheckProject(projectContext); if (mCanceled) { return; } } if (mCanceled) { mClient.report( projectContext, // Must provide an issue since API guarantees that the issue parameter // is valid Issue.create("Lint", "", "", Category.PERFORMANCE, 0, Severity.INFORMATIONAL, //$NON-NLS-1$ null, EnumSet.noneOf(Scope.class)), null /*range*/, "Lint canceled by user", null); } }
protected void reportNonExistingIssueId(@Nullable Project project, @NonNull String id) { String message = String.format("Unknown issue id \"%1$s\"", id); if (driver != null && project != null) { Location location = Location.create(project.getDir()); if (!isSuppressed(IssueRegistry.LINT_ERROR)) { report(new Context(driver, project, project, project.getDir()), IssueRegistry.LINT_ERROR, project.getConfiguration(driver).getSeverity(IssueRegistry.LINT_ERROR), location, message, TextFormat.RAW); } } else { log(Severity.ERROR, null, "Lint: %1$s", message); } }
private void checkProject(@NonNull Project project, @NonNull Project main) { File projectDir = project.getDir(); Context projectContext = new Context(this, project, null, projectDir); fireEvent(EventType.SCANNING_PROJECT, projectContext); List<Project> libraries = project.getAllLibraries(); for (Project library : libraries) { Context libraryContext = new Context(this, library, project, projectDir); fireEvent(EventType.SCANNING_LIBRARY_PROJECT, libraryContext); currentProject = library;
LintUtils.describeCounts(foundErrorCount, foundWarningCount, false), getDisplayPath(project, baselineFile)); client.report(new Context(driver, project, project, baselineFile), IssueRegistry.BASELINE, client.getConfiguration(project, driver).getSeverity(IssueRegistry.BASELINE), + "baseline file (%2$s) but not found in the project; perhaps they have " + "been fixed?", fixedCount, getDisplayPath(project, baselineFile)); client.report(new Context(driver, project, project, baselineFile), IssueRegistry.BASELINE, client.getConfiguration(project, driver).getSeverity(IssueRegistry.BASELINE),
+ "Does the project need to be built first?", project.getName()); Location location = Location.create(project.getDir()); client.report(new Context(this, project, main, project.getDir()), IssueRegistry.LINT_ERROR, project.getConfiguration(this).getSeverity(IssueRegistry.LINT_ERROR),
Location location = e.getLocation(); File file = location != null ? location.getFile() : currentProject.getDir(); Context context = new Context(this, currentProject, null, file); context.report(IssueRegistry.LINT_ERROR, e.getLocation(), e.getMessage()); currentProject = null;
@NonNull @Override protected Project createProject(@NonNull File dir, @NonNull File referenceDir) { Project project = super.createProject(dir, referenceDir); if (project.isGradleProject()) { @SuppressWarnings("SpellCheckingInspection") String message = String.format("\"`%1$s`\" is a Gradle project. To correctly " + "analyze Gradle projects, you should run \"`gradlew :lint`\" instead.", project.getName()); Location location = Location.create(project.getDir()); Context context = new Context(driver, project, project, project.getDir()); if (context.isEnabled(IssueRegistry.LINT_ERROR) && !getConfiguration(project, null).isIgnored(context, IssueRegistry.LINT_ERROR, location, message)) { report(context, IssueRegistry.LINT_ERROR, project.getConfiguration(null).getSeverity( IssueRegistry.LINT_ERROR), location, message, TextFormat.RAW); } } return project; }