use of com.android.tools.klint.detector.api.Context in project kotlin by JetBrains.
the class LintDriver method checkProGuard.
private void checkProGuard(Project project, Project main) {
List<Detector> detectors = mScopeDetectors.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) {
if (detector.appliesTo(context, file)) {
detector.beforeCheckFile(context);
detector.run(context);
detector.afterCheckFile(context);
}
}
}
}
}
use of com.android.tools.klint.detector.api.Context in project kotlin by JetBrains.
the class OtherFileVisitor method scan.
/** Analyze other files in the given project */
void scan(@NonNull LintDriver driver, @NonNull Project project, @Nullable Project main) {
// Collect all project files
File projectFolder = project.getDir();
EnumSet<Scope> scopes = EnumSet.noneOf(Scope.class);
for (Detector detector : mDetectors) {
OtherFileScanner fileScanner = (OtherFileScanner) detector;
EnumSet<Scope> applicable = fileScanner.getApplicableFiles();
if (applicable.contains(Scope.OTHER)) {
scopes = Scope.ALL;
break;
}
scopes.addAll(applicable);
}
List<File> subset = project.getSubset();
if (scopes.contains(Scope.RESOURCE_FILE)) {
if (subset != null && !subset.isEmpty()) {
List<File> files = new ArrayList<File>(subset.size());
for (File file : subset) {
if (SdkUtils.endsWith(file.getPath(), DOT_XML) && !file.getName().equals(ANDROID_MANIFEST_XML)) {
files.add(file);
}
}
if (!files.isEmpty()) {
mFiles.put(Scope.RESOURCE_FILE, files);
}
} else {
List<File> files = Lists.newArrayListWithExpectedSize(100);
for (File res : project.getResourceFolders()) {
collectFiles(files, res);
}
File assets = new File(projectFolder, FD_ASSETS);
if (assets.exists()) {
collectFiles(files, assets);
}
if (!files.isEmpty()) {
mFiles.put(Scope.RESOURCE_FILE, files);
}
}
}
if (scopes.contains(Scope.JAVA_FILE)) {
if (subset != null && !subset.isEmpty()) {
List<File> files = new ArrayList<File>(subset.size());
for (File file : subset) {
if (file.getPath().endsWith(".kt")) {
files.add(file);
}
}
if (!files.isEmpty()) {
mFiles.put(Scope.JAVA_FILE, files);
}
} else {
List<File> files = Lists.newArrayListWithExpectedSize(100);
for (File srcFolder : project.getJavaSourceFolders()) {
collectFiles(files, srcFolder);
}
if (!files.isEmpty()) {
mFiles.put(Scope.JAVA_FILE, files);
}
}
}
if (scopes.contains(Scope.CLASS_FILE)) {
if (subset != null && !subset.isEmpty()) {
List<File> files = new ArrayList<File>(subset.size());
for (File file : subset) {
if (file.getPath().endsWith(DOT_CLASS)) {
files.add(file);
}
}
if (!files.isEmpty()) {
mFiles.put(Scope.CLASS_FILE, files);
}
} else {
List<File> files = Lists.newArrayListWithExpectedSize(100);
for (File classFolder : project.getJavaClassFolders()) {
collectFiles(files, classFolder);
}
if (!files.isEmpty()) {
mFiles.put(Scope.CLASS_FILE, files);
}
}
}
if (scopes.contains(Scope.MANIFEST)) {
if (subset != null && !subset.isEmpty()) {
List<File> files = new ArrayList<File>(subset.size());
for (File file : subset) {
if (file.getName().equals(ANDROID_MANIFEST_XML)) {
files.add(file);
}
}
if (!files.isEmpty()) {
mFiles.put(Scope.MANIFEST, files);
}
} else {
List<File> manifestFiles = project.getManifestFiles();
if (manifestFiles != null) {
mFiles.put(Scope.MANIFEST, manifestFiles);
}
}
}
for (Map.Entry<Scope, List<File>> entry : mFiles.entrySet()) {
Scope scope = entry.getKey();
List<File> files = entry.getValue();
List<Detector> applicable = new ArrayList<Detector>(mDetectors.size());
for (Detector detector : mDetectors) {
OtherFileScanner fileScanner = (OtherFileScanner) detector;
EnumSet<Scope> appliesTo = fileScanner.getApplicableFiles();
if (appliesTo.contains(Scope.OTHER) || appliesTo.contains(scope)) {
applicable.add(detector);
}
}
if (!applicable.isEmpty()) {
for (File file : files) {
Context context = new Context(driver, project, main, file);
for (Detector detector : applicable) {
detector.beforeCheckFile(context);
detector.run(context);
detector.afterCheckFile(context);
}
if (driver.isCanceled()) {
return;
}
}
}
}
}
use of com.android.tools.klint.detector.api.Context in project kotlin by JetBrains.
the class LintDriver method checkBuildScripts.
private void checkBuildScripts(Project project, Project main) {
List<Detector> detectors = mScopeDetectors.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) {
if (detector.appliesTo(context, file)) {
detector.beforeCheckFile(context);
detector.visitBuildScript(context, Maps.<String, Object>newHashMap());
detector.afterCheckFile(context);
}
}
}
}
}
use of com.android.tools.klint.detector.api.Context in project kotlin by JetBrains.
the class LintDriver method analyze.
/** Runs the driver to analyze the requested files */
private void analyze() {
mCanceled = false;
mScope = mRequest.getScope();
assert mScope == null || !mScope.contains(Scope.ALL_RESOURCE_FILES) || mScope.contains(Scope.RESOURCE_FILE);
Collection<Project> projects;
try {
projects = mRequest.getProjects();
if (projects == null) {
projects = computeProjects(mRequest.getFiles());
}
} catch (CircularDependencyException e) {
mCurrentProject = e.getProject();
if (mCurrentProject != null) {
Location location = e.getLocation();
File file = location != null ? location.getFile() : mCurrentProject.getDir();
Context context = new Context(this, mCurrentProject, null, file);
context.report(IssueRegistry.LINT_ERROR, e.getLocation(), e.getMessage());
mCurrentProject = null;
}
return;
}
if (projects.isEmpty()) {
mClient.log(null, "No projects found for %1$s", mRequest.getFiles().toString());
return;
}
if (mCanceled) {
return;
}
registerCustomDetectors(projects);
if (mScope == null) {
mScope = Scope.infer(projects);
}
fireEvent(EventType.STARTING, null);
for (Project project : projects) {
mPhase = 1;
Project main = mRequest.getMainProject(project);
// The set of available detectors varies between projects
computeDetectors(project);
if (mApplicableDetectors.isEmpty()) {
// No detectors enabled in this project: skip it
continue;
}
checkProject(project, main);
if (mCanceled) {
break;
}
runExtraPhases(project, main);
}
fireEvent(mCanceled ? EventType.CANCELED : EventType.COMPLETED, null);
}
use of com.android.tools.klint.detector.api.Context in project kotlin by JetBrains.
the class DefaultConfiguration method formatError.
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();
}
}, mClient);
mClient.report(new Context(driver, mProject, mProject, mConfigFile), IssueRegistry.LINT_ERROR, mProject.getConfiguration(driver).getSeverity(IssueRegistry.LINT_ERROR), Location.create(mConfigFile), message, TextFormat.RAW);
}
Aggregations