Search in sources :

Example 11 with StudioDownloader

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

the class PatchInstallingRestarter method processPatch.

/**
   * Either restart and install the given patch or delete it (if it's already installed).
   */
private void processPatch(File androidSdkPath, StudioLoggerProgressIndicator progress, File patchDir) {
    RepoPackage pendingPackage = null;
    File installDir = null;
    try {
        RepoManager mgr = mySdkHandler.getSdkManager(progress);
        Repository repo = InstallerUtil.readPendingPackageXml(patchDir, mgr, myFileOp, progress);
        if (repo != null) {
            File patch = new File(patchDir, PatchInstallerUtil.PATCH_JAR_FN);
            pendingPackage = repo.getLocalPackage();
            boolean remote = false;
            if (pendingPackage != null) {
                // If the pending package was local, use the corresponding installed local package.
                installDir = mgr.getPackages().getLocalPackages().get(pendingPackage.getPath()).getLocation();
            } else {
                // Otherwise it's remote.
                pendingPackage = repo.getRemotePackage().get(0);
                installDir = ((RemotePackage) pendingPackage).getInstallDir(mgr, progress);
                remote = true;
            }
            File existingPackageXml = new File(installDir, LocalRepoLoaderImpl.PACKAGE_XML_FN);
            File oldPackageXml = new File(patchDir, OLD_PACKAGE_XML_FN);
            if (patch.exists() && existingPackageXml.renameTo(oldPackageXml)) {
            // This will exit the app.
            //          Main.installPatch("sdk", PatchInstallerUtil.PATCH_JAR_FN, FileUtil.getTempDirectory(), patch, installDir.getAbsolutePath());
            } else {
                // The patch is already installed, or was cancelled.
                String relativePath = FileOpUtils.makeRelative(androidSdkPath, installDir, myFileOp);
                // Use the old mechanism to get the version, since it's actually part of the package itself. Thus we can tell if the patch
                // has already been applied.
                Revision rev = AndroidCommonUtils.parsePackageRevision(androidSdkPath.getPath(), relativePath);
                if (rev != null && rev.equals(pendingPackage.getVersion())) {
                    // We need to make sure the listeners are fired, so create an installer that does nothing and invoke it.
                    InstallerFactory dummyFactory = new DummyInstallerFactory();
                    dummyFactory.setListenerFactory(new StudioSdkInstallListenerFactory(mySdkHandler));
                    if (remote) {
                        Installer installer = dummyFactory.createInstaller((RemotePackage) pendingPackage, mgr, new StudioDownloader(), myFileOp);
                        installer.complete(progress);
                    } else {
                        Uninstaller uninstaller = dummyFactory.createUninstaller((LocalPackage) pendingPackage, mgr, myFileOp);
                        uninstaller.complete(progress);
                    }
                } else {
                    // something went wrong. Move the old package.xml back into place.
                    progress.logWarning("Failed to find version information in " + new File(androidSdkPath, SdkConstants.FN_SOURCE_PROP));
                    oldPackageXml.renameTo(existingPackageXml);
                }
            }
        }
    } catch (Exception e) {
        StringBuilder message = new StringBuilder("A problem occurred while installing ");
        message.append(pendingPackage != null ? pendingPackage.getDisplayName() : "an SDK package");
        if (installDir != null) {
            message.append(" in ").append(installDir);
        }
        message.append(". Please try again.");
        Messages.showErrorDialog(message.toString(), "Error Launching SDK Component Installer");
        progress.logWarning("Failed to install SDK package", e);
    }
    // If we get here we either got an error or the patch was already installed. Delete the patch dir.
    try {
        myFileOp.deleteFileOrFolder(patchDir);
    } catch (Exception e) {
        progress.logWarning("Problem during patch cleanup", e);
    }
}
Also used : AbstractInstaller(com.android.repository.impl.installer.AbstractInstaller) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) AbstractInstallerFactory(com.android.repository.impl.installer.AbstractInstallerFactory) Revision(com.android.repository.Revision) AbstractUninstaller(com.android.repository.impl.installer.AbstractUninstaller) File(java.io.File) StudioSdkInstallListenerFactory(com.android.tools.idea.sdk.install.StudioSdkInstallListenerFactory)

Example 12 with StudioDownloader

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

the class ComponentInstaller method installPackages.

public void installPackages(@NotNull List<RemotePackage> packages, ProgressIndicator progress) throws WizardException {
    RepoManager sdkManager = mySdkHandler.getSdkManager(progress);
    for (RemotePackage request : packages) {
        // Intentionally don't register any listeners on the installer, so we don't recurse on haxm
        // TODO: This is a hack. Any future rewrite of this shouldn't require this behavior.
        InstallerFactory factory = new BasicInstallerFactory();
        Installer installer = factory.createInstaller(request, sdkManager, new StudioDownloader(), mySdkHandler.getFileOp());
        if (installer.prepare(progress)) {
            installer.complete(progress);
        }
    }
    sdkManager.loadSynchronously(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, progress, null, null);
}
Also used : BasicInstallerFactory(com.android.repository.impl.installer.BasicInstallerFactory) BasicInstallerFactory(com.android.repository.impl.installer.BasicInstallerFactory) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

Example 13 with StudioDownloader

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

the class FormFactorApiComboBox method loadRemoteTargets.

private void loadRemoteTargets(final int minSdkLevel, final Runnable completedCallback, final Runnable foundItemsCallback, final Runnable noItemsCallback) {
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    final Runnable runCallbacks = () -> {
        if (completedCallback != null) {
            completedCallback.run();
        }
        if (getItemCount() > 0) {
            if (foundItemsCallback != null) {
                foundItemsCallback.run();
            }
        } else {
            if (noItemsCallback != null) {
                noItemsCallback.run();
            }
        }
    };
    RepoManager.RepoLoadedCallback onComplete = packages -> {
        addPackages(packages.getNewPkgs(), minSdkLevel);
        addOfflineLevels();
        loadSavedApi();
        runCallbacks.run();
    };
    // We need to pick up addons that don't have a target created due to the base platform not being installed.
    RepoManager.RepoLoadedCallback onLocalComplete = packages -> addPackages(packages.getLocalPackages().values(), minSdkLevel);
    Runnable onError = () -> ApplicationManager.getApplication().invokeLater(() -> {
        addOfflineLevels();
        runCallbacks.run();
    }, ModalityState.any());
    StudioProgressRunner runner = new StudioProgressRunner(false, false, "Refreshing Targets", true, null);
    sdkHandler.getSdkManager(REPO_LOG).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, ImmutableList.of(onLocalComplete), ImmutableList.of(onComplete), ImmutableList.of(onError), runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : Iterables(com.google.common.collect.Iterables) ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) ActionListener(java.awt.event.ActionListener) ModalityState(com.intellij.openapi.application.ModalityState) WizardConstants(com.android.tools.idea.wizard.WizardConstants) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) INSTALL_REQUESTS_KEY(com.android.tools.idea.wizard.WizardConstants.INSTALL_REQUESTS_KEY) RemotePackage(com.android.repository.api.RemotePackage) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) ConfigureAndroidProjectPath(com.android.tools.idea.npw.deprecated.ConfigureAndroidProjectPath) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidTargetManager(com.android.sdklib.repository.targets.AndroidTargetManager) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) RepoPackage(com.android.repository.api.RepoPackage) Collection(java.util.Collection) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata) Set(java.util.Set) AndroidSdkUtils(org.jetbrains.android.sdk.AndroidSdkUtils) TemplateUtils(com.android.tools.idea.templates.TemplateUtils) com.android.sdklib(com.android.sdklib) IdDisplay(com.android.sdklib.repository.IdDisplay) ScopedDataBinder(com.android.tools.idea.wizard.dynamic.ScopedDataBinder) Sets(com.google.common.collect.Sets) Sdk(com.intellij.openapi.projectRoots.Sdk) ProgressIndicator(com.android.repository.api.ProgressIndicator) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) Nullable(org.jetbrains.annotations.Nullable) ApiComboBoxItem(com.android.tools.idea.ui.ApiComboBoxItem) List(java.util.List) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) ATTR_MIN_API(com.android.tools.idea.templates.TemplateMetadata.ATTR_MIN_API) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Key(com.android.tools.idea.wizard.dynamic.ScopedStateStore.Key) RepoManager(com.android.repository.api.RepoManager) SystemImage(com.android.sdklib.repository.targets.SystemImage) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) javax.swing(javax.swing) RepoManager(com.android.repository.api.RepoManager) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

Example 14 with StudioDownloader

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

the class SourcesTableModel method reset.

/**
   * Reset the sources to the state they were before the user made any changes.
   */
public void reset() {
    if (!isSourcesModified()) {
        // We don't have any changes, but if we haven't initialized at all, do it now.
        if (myInitialItems == null) {
            refreshUi();
        }
        return;
    }
    // Force refresh so the file is reloaded.
    myConfigurable.getRepoManager().getSources(new StudioDownloader(), myLogger, true);
    myInitialItems = null;
    refreshUi();
}
Also used : StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

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