Search in sources :

Example 6 with StudioDownloader

use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.

the class InstallCMakeHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    // We need to statically fetch the SDK handler each time because the location might change.
    // TODO: remove the need for doing this each time.
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    StudioLoggerProgressIndicator progressIndicator = new StudioLoggerProgressIndicator(getClass());
    RepoManager sdkManager = sdkHandler.getSdkManager(progressIndicator);
    StudioProgressRunner progressRunner = new StudioProgressRunner(false, /* backgroundable */
    false, /* cancellable */
    "Loading Remote SDK", true, /* in UI thread */
    project);
    RepoManager.RepoLoadedCallback onComplete = packages -> {
        Collection<RemotePackage> cmakePackages = packages.getRemotePackagesForPrefix(FD_CMAKE);
        if (!cmakePackages.isEmpty()) {
            RemotePackage cmakePackage;
            if (cmakePackages.size() == 1) {
                cmakePackage = getFirstItem(cmakePackages);
            } else {
                cmakePackage = sdkHandler.getLatestRemotePackageForPrefix(FD_CMAKE, false, progressIndicator);
            }
            if (cmakePackage != null) {
                ModelWizardDialog dialog = createDialogForPaths(project, ImmutableList.of(cmakePackage.getPath()));
                if (dialog != null && dialog.showAndGet()) {
                    GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
                }
                return;
            }
            notifyCMakePackageNotFound(project);
        }
    };
    Runnable onError = () -> notifyCMakePackageNotFound(project);
    sdkManager.load(DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), ImmutableList.of(onError), progressRunner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) ContainerUtil.getFirstItem(com.intellij.util.containers.ContainerUtil.getFirstItem) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Collection(java.util.Collection) DEFAULT_EXPIRATION_PERIOD_MS(com.android.repository.api.RepoManager.DEFAULT_EXPIRATION_PERIOD_MS) RemotePackage(com.android.repository.api.RemotePackage) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) FD_CMAKE(com.android.SdkConstants.FD_CMAKE) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) RepoManager(com.android.repository.api.RepoManager) NotNull(org.jetbrains.annotations.NotNull) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) SdkQuickfixUtils.createDialogForPaths(com.android.tools.idea.sdk.wizard.SdkQuickfixUtils.createDialogForPaths) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepoManager(com.android.repository.api.RepoManager) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Collection(java.util.Collection) RemotePackage(com.android.repository.api.RemotePackage) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

Example 7 with StudioDownloader

use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.

the class InstallNdkHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    File path = getNdkPath(project);
    if (path != null) {
        // Try to install SDK in local.properties.
        SelectNdkDialog dialog = new SelectNdkDialog(path.getPath(), false, true);
        dialog.setModal(true);
        if (dialog.showAndGet() && setNdkPath(project, dialog.getAndroidNdkPath())) {
            // Saving NDK path is successful.
            GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
        }
        return;
    }
    // There is no path. Try installing from SDK.
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    StudioLoggerProgressIndicator progressIndicator = new StudioLoggerProgressIndicator(getClass());
    RepoManager sdkManager = sdkHandler.getSdkManager(progressIndicator);
    StudioProgressRunner progressRunner = new StudioProgressRunner(false, /* backgroundable */
    false, /* cancellable */
    "Loading Remote SDK", true, /* in UI thread */
    project);
    RepoManager.RepoLoadedCallback onComplete = packages -> {
        Map<String, RemotePackage> remotePackages = packages.getRemotePackages();
        RemotePackage ndkPackage = remotePackages.get(FD_NDK);
        if (ndkPackage != null) {
            ModelWizardDialog dialog = createDialogForPaths(project, ImmutableList.of(ndkPackage.getPath()));
            if (dialog != null && dialog.showAndGet()) {
                GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
            }
            return;
        }
        notifyNdkPackageNotFound(project);
    };
    Runnable onError = () -> notifyNdkPackageNotFound(project);
    sdkManager.load(DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), ImmutableList.of(onError), progressRunner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) IOException(java.io.IOException) DEFAULT_EXPIRATION_PERIOD_MS(com.android.repository.api.RepoManager.DEFAULT_EXPIRATION_PERIOD_MS) RemotePackage(com.android.repository.api.RemotePackage) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) File(java.io.File) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) Nullable(org.jetbrains.annotations.Nullable) SelectNdkDialog(com.android.tools.idea.sdk.SelectNdkDialog) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Map(java.util.Map) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) RepoManager(com.android.repository.api.RepoManager) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) FD_NDK(com.android.SdkConstants.FD_NDK) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) SdkQuickfixUtils.createDialogForPaths(com.android.tools.idea.sdk.wizard.SdkQuickfixUtils.createDialogForPaths) SelectNdkDialog(com.android.tools.idea.sdk.SelectNdkDialog) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepoManager(com.android.repository.api.RepoManager) File(java.io.File) Map(java.util.Map) RemotePackage(com.android.repository.api.RemotePackage) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 8 with StudioDownloader

use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.

the class SdkQuickfixUtils method createDialog.

@VisibleForTesting
@Nullable
static ModelWizardDialog createDialog(@Nullable Project project, @Nullable Component parent, @Nullable Collection<String> requestedPaths, @Nullable Collection<UpdatablePackage> requestedPackages, @Nullable Collection<LocalPackage> requestedUninstalls, @Nullable AndroidSdkHandler sdkHandler, boolean backgroundable) {
    if (sdkHandler == null) {
        return null;
    }
    RepoManager mgr = sdkHandler.getSdkManager(REPO_LOGGER);
    if (mgr.getLocalPath() == null) {
        String title = "SDK Problem";
        String msg = "<html>" + "Your Android SDK is missing or out of date." + "<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>";
        Messages.showErrorDialog(msg, title);
        return null;
    }
    List<String> unknownPaths = new ArrayList<>();
    List<UpdatablePackage> resolvedPackages;
    mgr.loadSynchronously(0, new StudioLoggerProgressIndicator(SdkQuickfixUtils.class), new StudioDownloader(), StudioSettingsController.getInstance());
    RepositoryPackages packages = mgr.getPackages();
    if (requestedPackages == null) {
        requestedPackages = new ArrayList<>();
    }
    requestedPackages.addAll(lookupPaths(requestedPaths, packages, unknownPaths));
    try {
        resolvedPackages = resolve(requestedPackages, packages);
    } catch (PackageResolutionException e) {
        Messages.showErrorDialog(e.getMessage(), "Error Resolving Packages");
        return null;
    }
    Set<LocalPackage> resolvedUninstalls = new HashSet<>();
    if (requestedUninstalls != null) {
        resolvedUninstalls.addAll(requestedUninstalls);
        // We don't want to uninstall something required by a package we're installing
        resolvedPackages.forEach(updatable -> resolvedUninstalls.remove(updatable.getLocal()));
    }
    List<UpdatablePackage> unavailableDownloads = Lists.newArrayList();
    verifyAvailability(resolvedPackages, unavailableDownloads);
    // If there were requests we didn't understand or can't download, show an error.
    if (!unknownPaths.isEmpty() || !unavailableDownloads.isEmpty()) {
        String title = "Packages Unavailable";
        HtmlBuilder builder = new HtmlBuilder();
        builder.openHtmlBody().add(String.format("%1$s packages are not available for download!", resolvedPackages.isEmpty() ? "All" : "Some")).newline().newline().add("The following packages are not available:").beginList();
        for (UpdatablePackage p : unavailableDownloads) {
            builder.listItem().add(p.getRepresentative().getDisplayName());
        }
        for (String p : unknownPaths) {
            builder.listItem().add("Package id " + p);
        }
        builder.endList().closeHtmlBody();
        Messages.showErrorDialog(builder.getHtml(), title);
    }
    // If everything was removed, don't continue.
    if (resolvedPackages.isEmpty() && resolvedUninstalls.isEmpty()) {
        return null;
    }
    List<RemotePackage> installRequests = resolvedPackages.stream().map(UpdatablePackage::getRemote).collect(Collectors.toList());
    ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
    wizardBuilder.addStep(new LicenseAgreementStep(new LicenseAgreementModel(mgr.getLocalPath()), installRequests));
    InstallSelectedPackagesStep installStep = new InstallSelectedPackagesStep(resolvedPackages, resolvedUninstalls, sdkHandler, backgroundable);
    wizardBuilder.addStep(installStep);
    ModelWizard wizard = wizardBuilder.build();
    String title = "SDK Quickfix Installation";
    return new StudioWizardDialogBuilder(wizard, title, parent).setProject(project).setModalityType(DialogWrapper.IdeModalityType.IDE).setCancellationPolicy(ModelWizardDialog.CancellationPolicy.CAN_CANCEL_UNTIL_CAN_FINISH).build();
}
Also used : HtmlBuilder(com.android.utils.HtmlBuilder) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard) HtmlBuilder(com.android.utils.HtmlBuilder) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) VisibleForTesting(com.android.annotations.VisibleForTesting) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with StudioDownloader

use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.

the class SystemImageListModel method refreshImages.

public void refreshImages(final boolean forceRefresh) {
    synchronized (myLock) {
        myCompletedCalls = 0;
    }
    myIndicator.onRefreshStart("Refreshing...");
    final List<SystemImageDescription> items = Lists.newArrayList();
    RepoManager.RepoLoadedCallback localComplete = new RepoManager.RepoLoadedCallback() {

        @Override
        public void doRun(@NotNull RepositoryPackages packages) {
            // getLocalImages() doesn't use SdkPackages, so it's ok that we're not using what's passed in.
            items.addAll(getLocalImages());
            // Update list in the UI immediately with the locally available system images
            setItems(items);
            // Assume the remote has not completed yet
            completedDownload("");
        }
    };
    RepoManager.RepoLoadedCallback remoteComplete = new RepoManager.RepoLoadedCallback() {

        @Override
        public void doRun(@NotNull RepositoryPackages packages) {
            List<SystemImageDescription> remotes = getRemoteImages(packages);
            if (remotes != null) {
                items.addAll(remotes);
                setItems(items);
            }
            completedDownload("");
        }
    };
    Runnable error = new Runnable() {

        @Override
        public void run() {
            ApplicationManager.getApplication().invokeLater(new Runnable() {

                @Override
                public void run() {
                    completedDownload("Error loading remote images");
                }
            });
        }
    };
    StudioProgressRunner runner = new StudioProgressRunner(false, false, "Loading Images", true, myProject);
    mySdkHandler.getSdkManager(LOGGER).load(forceRefresh ? 0 : RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, ImmutableList.of(localComplete), ImmutableList.of(remoteComplete), ImmutableList.of(error), runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) RepoManager(com.android.repository.api.RepoManager) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) NotNull(org.jetbrains.annotations.NotNull) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

Example 10 with StudioDownloader

use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.

the class LicenseAgreementStep method createChangesList.

private List<Change> createChangesList() {
    ProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
    RepoManager sdkManager = mySdkHandler.getSdkManager(progress);
    sdkManager.loadSynchronously(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, progress, new StudioDownloader(), StudioSettingsController.getInstance());
    Map<String, RemotePackage> remotePackages = sdkManager.getPackages().getRemotePackages();
    List<Change> toReturn = Lists.newArrayList();
    List<String> requestedPackages = myState.get(INSTALL_REQUESTS_KEY);
    if (requestedPackages != null) {
        for (String path : requestedPackages) {
            RemotePackage p = remotePackages.get(path);
            License license = p.getLicense();
            if (license == null) {
                license = AndroidSdkLicenseTemporaryData.getLicense(p.getTypeDetails() instanceof DetailsTypes.ApiDetailsType && ((DetailsTypes.ApiDetailsType) p.getTypeDetails()).getAndroidVersion().isPreview());
            }
            myLicenses.add(license);
            if (!license.checkAccepted(mySdkRoot, mySdkHandler.getFileOp())) {
                toReturn.add(new Change(ChangeType.INSTALL, p, license));
            }
        }
    }
    return toReturn;
}
Also used : DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)

Aggregations

StudioDownloader (com.android.tools.idea.sdk.StudioDownloader)14 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)9 RepoManager (com.android.repository.api.RepoManager)7 NotNull (org.jetbrains.annotations.NotNull)6 RemotePackage (com.android.repository.api.RemotePackage)5 StudioProgressRunner (com.android.tools.idea.sdk.progress.StudioProgressRunner)5 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)4 AndroidSdks (com.android.tools.idea.sdk.AndroidSdks)4 StudioSettingsController (com.android.tools.idea.sdk.StudioSettingsController)4 ImmutableList (com.google.common.collect.ImmutableList)4 Nullable (org.jetbrains.annotations.Nullable)4 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)3 ProgressIndicator (com.android.repository.api.ProgressIndicator)2 DEFAULT_EXPIRATION_PERIOD_MS (com.android.repository.api.RepoManager.DEFAULT_EXPIRATION_PERIOD_MS)2 RepoPackage (com.android.repository.api.RepoPackage)2 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)2 IdDisplay (com.android.sdklib.repository.IdDisplay)2 AndroidTargetManager (com.android.sdklib.repository.targets.AndroidTargetManager)2 SystemImage (com.android.sdklib.repository.targets.SystemImage)2 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)2