Search in sources :

Example 16 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator 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 17 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator 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 18 with StudioLoggerProgressIndicator

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

the class SmwOldApiDirectInstall method startSdkInstallUsingNonSwtOldApi.

private void startSdkInstallUsingNonSwtOldApi() {
    // Get the SDK instance.
    final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    if (sdkHandler.getLocation() == null) {
        myErrorLabel.setText("Error: can't get SDK instance.");
        myErrorLabel.setIcon(AllIcons.General.BalloonError);
        return;
    }
    File androidSdkPath = IdeSdks.getInstance().getAndroidSdkPath();
    if (androidSdkPath != null && androidSdkPath.exists() && !androidSdkPath.canWrite()) {
        myErrorLabel.setText(String.format("SDK folder is read-only: '%1$s'", androidSdkPath.getPath()));
        myErrorLabel.setIcon(AllIcons.General.BalloonError);
        return;
    }
    myLabelSdkPath.setText(sdkHandler.getLocation().getPath());
    final CustomLogger logger = new CustomLogger();
    final com.android.repository.api.ProgressIndicator repoProgress = new StudioLoggerProgressIndicator(getClass());
    RepoManager.RepoLoadedCallback onComplete = packages -> UIUtil.invokeLaterIfNeeded(() -> {
        List<String> requestedChanges = myState.get(INSTALL_REQUESTS_KEY);
        if (requestedChanges == null) {
            assert false : "Shouldn't be in installer with no requests";
            myInstallFinished = true;
            invokeUpdate(null);
            return;
        }
        Map<String, RemotePackage> remotes = packages.getRemotePackages();
        List<RemotePackage> requestedPackages = Lists.newArrayList();
        boolean notFound = false;
        for (String path : requestedChanges) {
            RemotePackage remotePackage = remotes.get(path);
            if (remotePackage != null) {
                requestedPackages.add(remotePackage);
            } else {
                notFound = true;
            }
        }
        if (requestedPackages.isEmpty()) {
            myInstallFinished = true;
            invokeUpdate(null);
        } else {
            requestedPackages = InstallerUtil.computeRequiredPackages(requestedPackages, packages, repoProgress);
            if (requestedPackages == null) {
                notFound = true;
            } else {
                InstallTask task = new InstallTask(sdkHandler, requestedPackages, logger);
                BackgroundableProcessIndicator indicator = new BackgroundableProcessIndicator(task);
                logger.setIndicator(indicator);
                ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator);
            }
        }
        if (notFound) {
            myErrorLabel.setText("Problem: Some required packages could not be installed. Check internet connection.");
            myErrorLabel.setIcon(AllIcons.General.BalloonError);
        }
    });
    StudioProgressRunner runner = new StudioProgressRunner(false, false, "Updating SDK", false, null);
    sdkHandler.getSdkManager(repoProgress).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), null, runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : ILogger(com.android.utils.ILogger) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) StudioSdkInstallerUtil(com.android.tools.idea.sdk.install.StudioSdkInstallerUtil) NEWLY_INSTALLED_API_KEY(com.android.tools.idea.wizard.WizardConstants.NEWLY_INSTALLED_API_KEY) FileOp(com.android.repository.io.FileOp) INSTALL_REQUESTS_KEY(com.android.tools.idea.wizard.WizardConstants.INSTALL_REQUESTS_KEY) JBLabel(com.intellij.ui.components.JBLabel) RemotePackage(com.android.repository.api.RemotePackage) IPkgDesc(com.android.sdklib.repository.legacy.descriptors.IPkgDesc) Lists(com.google.common.collect.Lists) Task(com.intellij.openapi.progress.Task) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Map(java.util.Map) InstallerFactory(com.android.repository.api.InstallerFactory) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) ProgressManager(com.intellij.openapi.progress.ProgressManager) Installer(com.android.repository.api.Installer) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) AndroidVersion(com.android.sdklib.AndroidVersion) PkgType(com.android.sdklib.repository.legacy.descriptors.PkgType) LoggerProgressIndicatorWrapper(com.android.sdklib.repository.LoggerProgressIndicatorWrapper) InstallerUtil(com.android.repository.util.InstallerUtil) Disposable(com.intellij.openapi.Disposable) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) com.android.tools.idea.sdk(com.android.tools.idea.sdk) DynamicWizardStepWithDescription(com.android.tools.idea.wizard.dynamic.DynamicWizardStepWithDescription) InstallSelectedPackagesStep(com.android.tools.idea.sdk.wizard.InstallSelectedPackagesStep) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) FileOpUtils(com.android.repository.io.FileOpUtils) RepoManager(com.android.repository.api.RepoManager) NotNull(org.jetbrains.annotations.NotNull) PerformInBackgroundOption(com.intellij.openapi.progress.PerformInBackgroundOption) javax.swing(javax.swing) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepoManager(com.android.repository.api.RepoManager) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) RemotePackage(com.android.repository.api.RemotePackage)

Example 19 with StudioLoggerProgressIndicator

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

the class AvdWizardUtils method emulatorSupportsWebp.

@VisibleForTesting
static boolean emulatorSupportsWebp(@NotNull AndroidSdkHandler sdkHandler) {
    ProgressIndicator log = new StudioLoggerProgressIndicator(AvdWizardUtils.class);
    LocalPackage sdkPackage = sdkHandler.getLocalPackage(FD_EMULATOR, log);
    if (sdkPackage == null) {
        sdkPackage = sdkHandler.getLocalPackage(FD_TOOLS, log);
    }
    if (sdkPackage != null) {
        Revision version = sdkPackage.getVersion();
        // >= 25.2.3?
        if (version.getMajor() > 25 || version.getMajor() == 25 && (version.getMinor() > 2 || version.getMinor() == 2 && version.getMicro() >= 3)) {
            return true;
        }
    }
    return false;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LocalPackage(com.android.repository.api.LocalPackage) Revision(com.android.repository.Revision) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 20 with StudioLoggerProgressIndicator

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

the class SkinChooser method getSkins.

private List<File> getSkins() {
    List<Device> devices = DeviceManagerConnection.getDefaultDeviceManagerConnection().getDevices();
    Set<File> result = Sets.newTreeSet();
    for (Device device : devices) {
        File skinFile = AvdWizardUtils.resolveSkinPath(device.getDefaultHardware().getSkinFile(), null, FileOpUtils.create());
        if (skinFile != null && skinFile.exists()) {
            result.add(skinFile);
        }
    }
    StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(SkinChooser.class);
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    for (IAndroidTarget target : sdkHandler.getAndroidTargetManager(progress).getTargets(progress)) {
        Arrays.stream(target.getSkins()).map(this::resolve).forEach(result::add);
    }
    for (ISystemImage img : sdkHandler.getSystemImageManager(progress).getImages()) {
        Arrays.stream(img.getSkins()).map(this::resolve).forEach(result::add);
    }
    List<File> resultList = Lists.newArrayList();
    resultList.add(NO_SKIN);
    resultList.addAll(result);
    return resultList;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Device(com.android.sdklib.devices.Device) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) IAndroidTarget(com.android.sdklib.IAndroidTarget) ISystemImage(com.android.sdklib.ISystemImage) File(java.io.File)

Aggregations

StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)40 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)22 File (java.io.File)11 Nullable (org.jetbrains.annotations.Nullable)9 RepoManager (com.android.repository.api.RepoManager)8 StudioDownloader (com.android.tools.idea.sdk.StudioDownloader)8 ProgressIndicator (com.android.repository.api.ProgressIndicator)7 Revision (com.android.repository.Revision)6 LocalPackage (com.android.repository.api.LocalPackage)6 RemotePackage (com.android.repository.api.RemotePackage)6 BuildToolInfo (com.android.sdklib.BuildToolInfo)6 NotNull (org.jetbrains.annotations.NotNull)6 IAndroidTarget (com.android.sdklib.IAndroidTarget)4 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)4 VisibleForTesting (com.android.annotations.VisibleForTesting)3 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)3 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)3 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)3 StudioProgressRunner (com.android.tools.idea.sdk.progress.StudioProgressRunner)3 ImmutableList (com.google.common.collect.ImmutableList)3