Search in sources :

Example 16 with Project

use of com.android.tools.klint.detector.api.Project in project kotlin by JetBrains.

the class LintDriver method registerCustomDetectors.

private void registerCustomDetectors(Collection<Project> projects) {
    // Look at the various projects, and if any of them provide a custom
    // lint jar, "add" them (this will replace the issue registry with
    // a CompositeIssueRegistry containing the original issue registry
    // plus JarFileIssueRegistry instances for each lint jar
    Set<File> jarFiles = Sets.newHashSet();
    for (Project project : projects) {
        jarFiles.addAll(mClient.findRuleJars(project));
        for (Project library : project.getAllLibraries()) {
            jarFiles.addAll(mClient.findRuleJars(library));
        }
    }
    jarFiles.addAll(mClient.findGlobalRuleJars());
    if (!jarFiles.isEmpty()) {
        List<IssueRegistry> registries = Lists.newArrayListWithExpectedSize(jarFiles.size());
        registries.add(mRegistry);
        for (File jarFile : jarFiles) {
            try {
                JarFileIssueRegistry registry = JarFileIssueRegistry.get(mClient, jarFile);
                if (registry.hasLegacyDetectors()) {
                    mRunCompatChecks = true;
                }
                if (myCustomIssues == null) {
                    myCustomIssues = Sets.newHashSet();
                }
                myCustomIssues.addAll(registry.getIssues());
                registries.add(registry);
            } catch (Throwable e) {
                mClient.log(e, "Could not load custom rule jar file %1$s", jarFile);
            }
        }
        if (registries.size() > 1) {
            // the first item is mRegistry itself
            mRegistry = new CompositeIssueRegistry(registries);
        }
    }
}
Also used : Project(com.android.tools.klint.detector.api.Project) File(java.io.File) PsiFile(com.intellij.psi.PsiFile)

Example 17 with Project

use of com.android.tools.klint.detector.api.Project in project kotlin by JetBrains.

the class LintDriver method checkProject.

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> allLibraries = project.getAllLibraries();
    Set<Project> allProjects = new HashSet<Project>(allLibraries.size() + 1);
    allProjects.add(project);
    allProjects.addAll(allLibraries);
    mCurrentProjects = allProjects.toArray(new Project[allProjects.size()]);
    mCurrentProject = project;
    for (Detector check : mApplicableDetectors) {
        check.beforeCheckProject(projectContext);
        if (mCanceled) {
            return;
        }
    }
    assert mCurrentProject == project;
    runFileDetectors(project, main);
    if (!Scope.checkSingleFile(mScope)) {
        List<Project> libraries = project.getAllLibraries();
        for (Project library : libraries) {
            Context libraryContext = new Context(this, library, project, projectDir);
            fireEvent(EventType.SCANNING_LIBRARY_PROJECT, libraryContext);
            mCurrentProject = library;
            for (Detector check : mApplicableDetectors) {
                check.beforeCheckLibraryProject(libraryContext);
                if (mCanceled) {
                    return;
                }
            }
            assert mCurrentProject == library;
            runFileDetectors(library, main);
            if (mCanceled) {
                return;
            }
            assert mCurrentProject == library;
            for (Detector check : mApplicableDetectors) {
                check.afterCheckLibraryProject(libraryContext);
                if (mCanceled) {
                    return;
                }
            }
        }
    }
    mCurrentProject = project;
    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
        IssueRegistry.CANCELLED, Severity.INFORMATIONAL, Location.create(project.getDir()), "Lint canceled by user", TextFormat.RAW);
    }
    mCurrentProjects = null;
}
Also used : ClassContext(com.android.tools.klint.detector.api.ClassContext) XmlContext(com.android.tools.klint.detector.api.XmlContext) JavaContext(com.android.tools.klint.detector.api.JavaContext) ResourceContext(com.android.tools.klint.detector.api.ResourceContext) Context(com.android.tools.klint.detector.api.Context) Project(com.android.tools.klint.detector.api.Project) ResourceXmlDetector(com.android.tools.klint.detector.api.ResourceXmlDetector) Detector(com.android.tools.klint.detector.api.Detector) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) HashSet(java.util.HashSet)

Aggregations

Project (com.android.tools.klint.detector.api.Project)17 File (java.io.File)8 PsiFile (com.intellij.psi.PsiFile)4 IOException (java.io.IOException)4 NonNull (com.android.annotations.NonNull)3 Module (com.intellij.openapi.module.Module)3 AbstractResourceRepository (com.android.ide.common.res2.AbstractResourceRepository)2 ResourceItem (com.android.ide.common.res2.ResourceItem)2 LintClient (com.android.tools.klint.client.api.LintClient)2 ClassContext (com.android.tools.klint.detector.api.ClassContext)2 Context (com.android.tools.klint.detector.api.Context)2 JavaContext (com.android.tools.klint.detector.api.JavaContext)2 Location (com.android.tools.klint.detector.api.Location)2 ResourceContext (com.android.tools.klint.detector.api.ResourceContext)2 XmlContext (com.android.tools.klint.detector.api.XmlContext)2 HashSet (java.util.HashSet)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 ResourceFile (com.android.ide.common.res2.ResourceFile)1 ResourceUrl (com.android.ide.common.resources.ResourceUrl)1