Search in sources :

Example 6 with PsAndroidModule

use of com.android.tools.idea.gradle.structure.model.android.PsAndroidModule 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)

Example 7 with PsAndroidModule

use of com.android.tools.idea.gradle.structure.model.android.PsAndroidModule in project android by JetBrains.

the class AddLibraryDependencyDialog method doValidate.

@Override
@Nullable
protected ValidationInfo doValidate() {
    List<Exception> searchErrors = myLibraryDependenciesForm.getSearchErrors();
    if (!searchErrors.isEmpty()) {
        StringBuilder buffer = new StringBuilder();
        searchErrors.forEach(e -> buffer.append(getErrorMessage(e)).append("\n"));
        return new ValidationInfo(buffer.toString(), myLibraryDependenciesForm.getPreferredFocusedComponent());
    }
    String selectedLibrary = myLibraryDependenciesForm.getSelectedLibrary();
    if (isEmpty(selectedLibrary)) {
        return new ValidationInfo("Please specify the library to add as dependency", myLibraryDependenciesForm.getPreferredFocusedComponent());
    }
    PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(selectedLibrary);
    PsModule module = getModule();
    if (spec != null && module instanceof PsAndroidModule) {
        PsAndroidModule androidModule = (PsAndroidModule) module;
        Ref<Boolean> found = new Ref<>(false);
        androidModule.forEachDeclaredDependency(dependency -> {
            if (dependency instanceof PsLibraryAndroidDependency) {
                PsLibraryAndroidDependency libraryDependency = (PsLibraryAndroidDependency) dependency;
                PsArtifactDependencySpec resolvedSpec = libraryDependency.getResolvedSpec();
                if (Objects.equals(spec.group, resolvedSpec.group) && Objects.equals(spec.name, resolvedSpec.name)) {
                    found.set(true);
                }
            }
        });
        if (found.get()) {
            String msg = String.format("Library '%1$s' is already a dependency", spec.name);
            return new ValidationInfo(msg, myLibraryDependenciesForm.getPreferredFocusedComponent());
        }
    }
    return getScopesPanel().validateInput();
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Ref(com.intellij.openapi.util.Ref) PsModule(com.android.tools.idea.gradle.structure.model.PsModule) PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency) UnknownHostException(java.net.UnknownHostException) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with PsAndroidModule

use of com.android.tools.idea.gradle.structure.model.android.PsAndroidModule in project android by JetBrains.

the class ModuleDependencyNode method setUp.

private void setUp(@NotNull PsModuleAndroidDependency moduleDependency) {
    myName = moduleDependency.toText(PLAIN_TEXT);
    PsAndroidModule dependentModule = moduleDependency.getParent();
    PsProject project = dependentModule.getParent();
    PsModule referred = project.findModuleByGradlePath(moduleDependency.getGradlePath());
    if (referred instanceof PsAndroidModule) {
        PsAndroidModule androidModule = (PsAndroidModule) referred;
        androidModule.forEachDependency(dependency -> {
            if (!dependency.isDeclared()) {
                return;
            }
            String moduleVariant = moduleDependency.getConfigurationName();
            if (!dependency.isIn(ARTIFACT_MAIN, moduleVariant)) {
                return;
            }
            AbstractPsModelNode<?> child = AbstractDependencyNode.createNode(this, dependency);
            if (child != null) {
                myChildren.add(child);
            }
        });
    }
}
Also used : PsProject(com.android.tools.idea.gradle.structure.model.PsProject) PsModule(com.android.tools.idea.gradle.structure.model.PsModule) PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule)

Aggregations

PsAndroidModule (com.android.tools.idea.gradle.structure.model.android.PsAndroidModule)8 PsModule (com.android.tools.idea.gradle.structure.model.PsModule)5 PsJavaModule (com.android.tools.idea.gradle.structure.model.java.PsJavaModule)4 NotNull (org.jetbrains.annotations.NotNull)3 PsContext (com.android.tools.idea.gradle.structure.configurables.PsContext)2 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)2 PsProject (com.android.tools.idea.gradle.structure.model.PsProject)2 Ref (com.intellij.openapi.util.Ref)2 Nullable (org.jetbrains.annotations.Nullable)2 PsAllModulesFakeModule (com.android.tools.idea.gradle.structure.configurables.android.dependencies.PsAllModulesFakeModule)1 AndroidModuleDependenciesConfigurable (com.android.tools.idea.gradle.structure.configurables.android.dependencies.module.AndroidModuleDependenciesConfigurable)1 ProjectDependenciesConfigurable (com.android.tools.idea.gradle.structure.configurables.android.dependencies.project.ProjectDependenciesConfigurable)1 TargetAndroidModuleNode (com.android.tools.idea.gradle.structure.configurables.android.dependencies.project.treeview.TargetAndroidModuleNode)1 JavaModuleDependenciesConfigurable (com.android.tools.idea.gradle.structure.configurables.java.dependencies.JavaModuleDependenciesConfigurable)1 AvailableLibraryUpdate (com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdate)1 AvailableLibraryUpdates (com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdates)1 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 AndroidDependencyScopesPanel (com.android.tools.idea.gradle.structure.dependencies.android.AndroidDependencyScopesPanel)1