Search in sources :

Example 1 with AvailableLibraryUpdates

use of com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdates 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 2 with AvailableLibraryUpdates

use of com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdates in project android by JetBrains.

the class PsLibraryUpdateCheckerDaemon method search.

private void search(@NotNull Collection<ArtifactRepository> repositories, @NotNull Collection<LibraryUpdateId> ids) {
    myRunning.set(true);
    getAvailableUpdates().clear();
    int resultCount = repositories.size() * ids.size();
    List<Future<SearchResult>> jobs = Lists.newArrayListWithExpectedSize(resultCount);
    Set<SearchRequest> requests = Sets.newHashSet();
    ids.forEach(id -> {
        SearchRequest request = new SearchRequest(id.getName(), id.getGroupId(), 1, 0);
        requests.add(request);
    });
    Set<SearchResult> results = Sets.newHashSet();
    List<Exception> errors = Lists.newArrayList();
    Application application = ApplicationManager.getApplication();
    application.executeOnPooledThread(() -> {
        for (ArtifactRepository repository : repositories) {
            for (SearchRequest request : requests) {
                jobs.add(application.executeOnPooledThread(() -> repository.search(request)));
            }
        }
        for (Future<SearchResult> job : jobs) {
            try {
                SearchResult result = Futures.getChecked(job, Exception.class);
                List<FoundArtifact> artifacts = result.getArtifacts();
                if (artifacts.size() == 1) {
                    FoundArtifact artifact = artifacts.get(0);
                    if (!artifact.getVersions().isEmpty()) {
                        results.add(result);
                    }
                }
            } catch (Exception e) {
                errors.add(e);
            }
        }
        AvailableLibraryUpdates updates = getAvailableUpdates();
        for (SearchResult result : results) {
            List<FoundArtifact> artifacts = result.getArtifacts();
            updates.add(artifacts.get(0));
        }
        updates.lastSearchTimeMillis = System.currentTimeMillis();
        myResultsUpdaterQueue.queue(new UpdatesAvailable());
    });
}
Also used : SearchRequest(com.android.tools.idea.gradle.structure.model.repositories.search.SearchRequest) SearchResult(com.android.tools.idea.gradle.structure.model.repositories.search.SearchResult) ArtifactRepository(com.android.tools.idea.gradle.structure.model.repositories.search.ArtifactRepository) FoundArtifact(com.android.tools.idea.gradle.structure.model.repositories.search.FoundArtifact) Future(java.util.concurrent.Future) AvailableLibraryUpdates(com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdates) Application(com.intellij.openapi.application.Application)

Aggregations

AvailableLibraryUpdates (com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdates)2 PsContext (com.android.tools.idea.gradle.structure.configurables.PsContext)1 AvailableLibraryUpdate (com.android.tools.idea.gradle.structure.daemon.AvailableLibraryUpdateStorage.AvailableLibraryUpdate)1 PsModulePath (com.android.tools.idea.gradle.structure.model.PsModulePath)1 ArtifactRepository (com.android.tools.idea.gradle.structure.model.repositories.search.ArtifactRepository)1 FoundArtifact (com.android.tools.idea.gradle.structure.model.repositories.search.FoundArtifact)1 SearchRequest (com.android.tools.idea.gradle.structure.model.repositories.search.SearchRequest)1 SearchResult (com.android.tools.idea.gradle.structure.model.repositories.search.SearchResult)1 PsLibraryDependencyNavigationPath (com.android.tools.idea.gradle.structure.navigation.PsLibraryDependencyNavigationPath)1 PsLibraryDependencyVersionQuickFixPath (com.android.tools.idea.gradle.structure.quickfix.PsLibraryDependencyVersionQuickFixPath)1 Application (com.intellij.openapi.application.Application)1 Future (java.util.concurrent.Future)1