Search in sources :

Example 1 with PsContext

use of com.android.tools.idea.gradle.structure.configurables.PsContext in project android by JetBrains.

the class QuickFixes method setLibraryDependencyVersion.

private static void setLibraryDependencyVersion(@NonNls PsContext context, @NotNull String moduleName, @NotNull String dependency, @NotNull String version) {
    PsModule module = context.getProject().findModuleByName(moduleName);
    if (module instanceof PsAndroidModule) {
        PsAndroidModule androidModule = (PsAndroidModule) module;
        androidModule.forEachDeclaredDependency(declaredDependency -> {
            if (declaredDependency instanceof PsLibraryDependency) {
                setLibraryDependencyVersion((PsLibraryDependency) declaredDependency, dependency, version);
            }
        });
    } else if (module instanceof PsJavaModule) {
        PsJavaModule javaModule = (PsJavaModule) module;
        javaModule.forEachDeclaredDependency(declaredDependency -> {
            if (declaredDependency instanceof PsLibraryDependency) {
                setLibraryDependencyVersion((PsLibraryDependency) declaredDependency, dependency, version);
            }
        });
    }
}
Also used : PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule) List(java.util.List) PsJavaModule(com.android.tools.idea.gradle.structure.model.java.PsJavaModule) PsContext(com.android.tools.idea.gradle.structure.configurables.PsContext) NonNls(org.jetbrains.annotations.NonNls) PsLibraryDependency(com.android.tools.idea.gradle.structure.model.PsLibraryDependency) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) PsModule(com.android.tools.idea.gradle.structure.model.PsModule) NotNull(org.jetbrains.annotations.NotNull) Splitter(com.google.common.base.Splitter) PsJavaModule(com.android.tools.idea.gradle.structure.model.java.PsJavaModule) PsModule(com.android.tools.idea.gradle.structure.model.PsModule) PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule) PsLibraryDependency(com.android.tools.idea.gradle.structure.model.PsLibraryDependency)

Example 2 with PsContext

use of com.android.tools.idea.gradle.structure.configurables.PsContext in project android by JetBrains.

the class PsAnalyzerDaemon method checkForUpdates.

private boolean checkForUpdates(@NotNull PsLibraryDependency dependency) {
    PsContext context = getContext();
    AvailableLibraryUpdates results = context.getLibraryUpdateCheckerDaemon().getAvailableUpdates();
    PsArtifactDependencySpec spec = dependency.getDeclaredSpec();
    if (spec != null) {
        AvailableLibraryUpdate update = results.findUpdateFor(spec);
        if (update != null) {
            String text = String.format("Newer version available: <b>%1$s</b> (%2$s)", update.version, update.repository);
            PsLibraryDependencyNavigationPath mainPath = new PsLibraryDependencyNavigationPath(context, dependency);
            PsIssue issue = new PsIssue(text, mainPath, LIBRARY_UPDATES_AVAILABLE, UPDATE);
            issue.setExtraPath(new PsModulePath(dependency.getParent()));
            PsLibraryDependencyVersionQuickFixPath quickFix = new PsLibraryDependencyVersionQuickFixPath(dependency, update.version);
            quickFix.setHrefText("[Update]");
            issue.setQuickFixPath(quickFix);
            myIssues.add(issue);
            return true;
        }
    }
    return false;
}
Also used : AvailableLibraryUpdate(com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdate) PsLibraryDependencyVersionQuickFixPath(com.android.tools.idea.gradle.structure.quickfix.PsLibraryDependencyVersionQuickFixPath) PsContext(com.android.tools.idea.gradle.structure.configurables.PsContext) PsModulePath(com.android.tools.idea.gradle.structure.model.PsModulePath) AvailableLibraryUpdates(com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdates) PsLibraryDependencyNavigationPath(com.android.tools.idea.gradle.structure.navigation.PsLibraryDependencyNavigationPath)

Example 3 with PsContext

use of com.android.tools.idea.gradle.structure.configurables.PsContext in project android by JetBrains.

the class PsAnalyzerDaemon method addApplicableUpdatesAsIssues.

private void addApplicableUpdatesAsIssues() {
    PsContext context = getContext();
    context.getProject().forEachModule(module -> {
        Ref<Boolean> updatesFound = new Ref<>(false);
        if (module instanceof PsAndroidModule) {
            PsAndroidModule androidModule = (PsAndroidModule) module;
            androidModule.forEachDeclaredDependency(dependency -> {
                if (dependency instanceof PsLibraryDependency) {
                    boolean found = checkForUpdates((PsLibraryDependency) dependency);
                    if (found) {
                        updatesFound.set(true);
                    }
                }
            });
        } else if (module instanceof PsJavaModule) {
            PsJavaModule javaModule = (PsJavaModule) module;
            javaModule.forEachDeclaredDependency(dependency -> {
                if (dependency instanceof PsLibraryDependency) {
                    boolean found = checkForUpdates((PsLibraryDependency) dependency);
                    if (found) {
                        updatesFound.set(true);
                    }
                }
            });
        }
        if (updatesFound.get()) {
            myResultsUpdaterQueue.queue(new IssuesComputed(module));
        }
    });
}
Also used : PsLibraryDependencyNavigationPath(com.android.tools.idea.gradle.structure.navigation.PsLibraryDependencyNavigationPath) PsAndroidModuleAnalyzer(com.android.tools.idea.gradle.structure.daemon.analysis.PsAndroidModuleAnalyzer) EventDispatcher(com.intellij.util.EventDispatcher) LIBRARY_UPDATES_AVAILABLE(com.android.tools.idea.gradle.structure.model.PsIssueType.LIBRARY_UPDATES_AVAILABLE) PsModulePath(com.android.tools.idea.gradle.structure.model.PsModulePath) com.android.tools.idea.gradle.structure.model(com.android.tools.idea.gradle.structure.model) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReadAction(com.intellij.openapi.application.ReadAction) AvailableLibraryUpdates(com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdates) UPDATE(com.android.tools.idea.gradle.structure.model.PsIssue.Severity.UPDATE) PsJavaModule(com.android.tools.idea.gradle.structure.model.java.PsJavaModule) PsLibraryDependencyVersionQuickFixPath(com.android.tools.idea.gradle.structure.quickfix.PsLibraryDependencyVersionQuickFixPath) Map(java.util.Map) RunResult(com.intellij.openapi.application.RunResult) Logger(com.intellij.openapi.diagnostic.Logger) PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule) AvailableLibraryUpdate(com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdate) PsModelAnalyzer(com.android.tools.idea.gradle.structure.daemon.analysis.PsModelAnalyzer) ActionCallback(com.intellij.openapi.util.ActionCallback) Maps(com.google.common.collect.Maps) ANY_COMPONENT(com.intellij.util.ui.update.MergingUpdateQueue.ANY_COMPONENT) Disposable(com.intellij.openapi.Disposable) MergingUpdateQueue(com.intellij.util.ui.update.MergingUpdateQueue) EventListener(java.util.EventListener) Update(com.intellij.util.ui.update.Update) Result(com.intellij.openapi.application.Result) PsContext(com.android.tools.idea.gradle.structure.configurables.PsContext) PsJavaModuleAnalyzer(com.android.tools.idea.gradle.structure.daemon.analysis.PsJavaModuleAnalyzer) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PsJavaModule(com.android.tools.idea.gradle.structure.model.java.PsJavaModule) Ref(com.intellij.openapi.util.Ref) PsContext(com.android.tools.idea.gradle.structure.configurables.PsContext) PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

PsContext (com.android.tools.idea.gradle.structure.configurables.PsContext)3 AvailableLibraryUpdate (com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdate)2 AvailableLibraryUpdates (com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdates)2 PsModulePath (com.android.tools.idea.gradle.structure.model.PsModulePath)2 PsAndroidModule (com.android.tools.idea.gradle.structure.model.android.PsAndroidModule)2 PsJavaModule (com.android.tools.idea.gradle.structure.model.java.PsJavaModule)2 PsLibraryDependencyNavigationPath (com.android.tools.idea.gradle.structure.navigation.PsLibraryDependencyNavigationPath)2 PsLibraryDependencyVersionQuickFixPath (com.android.tools.idea.gradle.structure.quickfix.PsLibraryDependencyVersionQuickFixPath)2 NotNull (org.jetbrains.annotations.NotNull)2 PsAndroidModuleAnalyzer (com.android.tools.idea.gradle.structure.daemon.analysis.PsAndroidModuleAnalyzer)1 PsJavaModuleAnalyzer (com.android.tools.idea.gradle.structure.daemon.analysis.PsJavaModuleAnalyzer)1 PsModelAnalyzer (com.android.tools.idea.gradle.structure.daemon.analysis.PsModelAnalyzer)1 com.android.tools.idea.gradle.structure.model (com.android.tools.idea.gradle.structure.model)1 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)1 UPDATE (com.android.tools.idea.gradle.structure.model.PsIssue.Severity.UPDATE)1 LIBRARY_UPDATES_AVAILABLE (com.android.tools.idea.gradle.structure.model.PsIssueType.LIBRARY_UPDATES_AVAILABLE)1 PsLibraryDependency (com.android.tools.idea.gradle.structure.model.PsLibraryDependency)1 PsModule (com.android.tools.idea.gradle.structure.model.PsModule)1 Splitter (com.google.common.base.Splitter)1 Maps (com.google.common.collect.Maps)1