Search in sources :

Example 1 with Installer

use of com.android.repository.api.Installer in project android by JetBrains.

the class PatchInstallerFactoryTest method createInstallerWithoutPatch.

@Test
public void createInstallerWithoutPatch() {
    myFileOp.setIsWindows(true);
    FakeRemotePackage remote = new FakeRemotePackage("foo");
    remote.setRevision(new Revision(2));
    FakeLocalPackage local = new FakeLocalPackage("foo");
    local.setRevision(new Revision(1));
    myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_4));
    myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote));
    Installer installer = myInstallerFactory.createInstaller(remote, myRepoManager, new FakeDownloader(myFileOp), myFileOp);
    assertTrue(installer instanceof FullInstaller);
}
Also used : FakeRemotePackage(com.android.repository.testframework.FakePackage.FakeRemotePackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) Revision(com.android.repository.Revision) Installer(com.android.repository.api.Installer) FakeDownloader(com.android.repository.testframework.FakeDownloader) Test(org.junit.Test)

Example 2 with Installer

use of com.android.repository.api.Installer in project android by JetBrains.

the class PatchInstallerFactoryTest method createInstallerWithPatch.

@Test
public void createInstallerWithPatch() {
    FakeRemotePackage remote = new FakeRemotePackage("foo");
    remote.setRevision(new Revision(2));
    remote.setPatchInfo("foo", new Revision(1));
    FakeLocalPackage local = new FakeLocalPackage("foo");
    local.setRevision(new Revision(1));
    myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_4));
    myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote));
    Installer installer = myInstallerFactory.createInstaller(remote, myRepoManager, new FakeDownloader(myFileOp), myFileOp);
    assertTrue(installer instanceof PatchInstaller);
}
Also used : FakeRemotePackage(com.android.repository.testframework.FakePackage.FakeRemotePackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) Revision(com.android.repository.Revision) Installer(com.android.repository.api.Installer) FakeDownloader(com.android.repository.testframework.FakeDownloader) Test(org.junit.Test)

Example 3 with Installer

use of com.android.repository.api.Installer 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 4 with Installer

use of com.android.repository.api.Installer in project android by JetBrains.

the class HaxmInstallListener method statusChanged.

@Override
public void statusChanged(@NonNull PackageOperation op, @NonNull ProgressIndicator progress) throws PackageOperation.StatusChangeListenerException {
    if ((op instanceof Uninstaller && op.getInstallStatus() == PackageOperation.InstallStatus.RUNNING) || (op instanceof Installer && op.getInstallStatus() == PackageOperation.InstallStatus.COMPLETE)) {
        // There are two possible workflows:
        // 1) Installation workflow: Install SDK package -> invoke wizard to run installer
        // 2) Uninstallation workflow: Invoke wizard to run installer with uninstallation params -> Uninstall SDK package
        // In both cases we need to leave the state of the SDK package consistent with the installer invocation success
        // status.
        // So if calling the installer during uninstallation fails, we simply throw an exception here and do not proceed
        // with SDK package removal, as the SDK package operation is in PREPARING state
        // If calling the installer during installation fails, then it is the responsibility of the wizard to cleanup the SDK
        // package as well
        final AtomicBoolean result = new AtomicBoolean(false);
        ApplicationManager.getApplication().invokeAndWait(() -> {
            HaxmWizard wizard = new HaxmWizard(op instanceof Uninstaller);
            wizard.init();
            result.set(wizard.showAndGet());
        }, ModalityState.any());
        if (!result.get()) {
            throw new PackageOperation.StatusChangeListenerException("HAXM setup failed!");
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Installer(com.android.repository.api.Installer) Uninstaller(com.android.repository.api.Uninstaller) HaxmWizard(com.android.tools.idea.sdk.wizard.HaxmWizard)

Example 5 with Installer

use of com.android.repository.api.Installer in project android by JetBrains.

the class PatchInstallerFactoryTest method createFallbackInstaller.

@Test
public void createFallbackInstaller() {
    FakeRemotePackage remote = new FakeRemotePackage("foo");
    remote.setRevision(new Revision(2));
    FakeLocalPackage local = new FakeLocalPackage("foo");
    local.setRevision(new Revision(1));
    myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local, PATCHER_4));
    myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote));
    Installer installer = myInstallerFactory.createInstaller(remote, myRepoManager, new FakeDownloader(myFileOp), myFileOp);
    assertNotNull(installer);
    assertFalse(installer instanceof PatchOperation);
}
Also used : FakeRemotePackage(com.android.repository.testframework.FakePackage.FakeRemotePackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) Revision(com.android.repository.Revision) Installer(com.android.repository.api.Installer) FakeDownloader(com.android.repository.testframework.FakeDownloader) Test(org.junit.Test)

Aggregations

Installer (com.android.repository.api.Installer)5 Revision (com.android.repository.Revision)3 FakeDownloader (com.android.repository.testframework.FakeDownloader)3 FakeLocalPackage (com.android.repository.testframework.FakePackage.FakeLocalPackage)3 FakeRemotePackage (com.android.repository.testframework.FakePackage.FakeRemotePackage)3 Test (org.junit.Test)3 InstallerFactory (com.android.repository.api.InstallerFactory)1 RemotePackage (com.android.repository.api.RemotePackage)1 RepoManager (com.android.repository.api.RepoManager)1 Uninstaller (com.android.repository.api.Uninstaller)1 FileOp (com.android.repository.io.FileOp)1 FileOpUtils (com.android.repository.io.FileOpUtils)1 InstallerUtil (com.android.repository.util.InstallerUtil)1 AndroidVersion (com.android.sdklib.AndroidVersion)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 LoggerProgressIndicatorWrapper (com.android.sdklib.repository.LoggerProgressIndicatorWrapper)1 IPkgDesc (com.android.sdklib.repository.legacy.descriptors.IPkgDesc)1 PkgType (com.android.sdklib.repository.legacy.descriptors.PkgType)1 com.android.tools.idea.sdk (com.android.tools.idea.sdk)1 StudioSdkInstallerUtil (com.android.tools.idea.sdk.install.StudioSdkInstallerUtil)1