Search in sources :

Example 11 with RepositoryPackages

use of com.android.repository.impl.meta.RepositoryPackages in project android by JetBrains.

the class PatchInstallerUtilTest method getDependantPatcher.

@Test
public void getDependantPatcher() throws Exception {
    LocalPackage target = new FakeLocalPackage("patcher;v2");
    List<LocalPackage> local = ImmutableList.of(new FakeLocalPackage("patcher;v1"), target, new FakeLocalPackage("patcher;v3"));
    FakeRemotePackage update = new FakeRemotePackage("p");
    List<RemotePackage> remote = ImmutableList.of(update, new FakeRemotePackage("patcher;v4"));
    update.setDependencies(ImmutableList.of(new FakeDependency(target.getPath())));
    RepositoryPackages packages = new RepositoryPackages(local, remote);
    FakeRepoManager mgr = new FakeRepoManager(new File("/sdk"), packages);
    LocalPackage patcher = PatchInstallerUtil.getDependantPatcher(update, mgr);
    assertEquals(target, patcher);
}
Also used : FakeRemotePackage(com.android.repository.testframework.FakePackage.FakeRemotePackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) LocalPackage(com.android.repository.api.LocalPackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) FakeDependency(com.android.repository.testframework.FakeDependency) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) RemotePackage(com.android.repository.api.RemotePackage) FakeRemotePackage(com.android.repository.testframework.FakePackage.FakeRemotePackage) File(java.io.File) Test(org.junit.Test)

Example 12 with RepositoryPackages

use of com.android.repository.impl.meta.RepositoryPackages in project android by JetBrains.

the class PatchInstallerUtilTest method dependantPatcherNotInstalled.

@Test
public void dependantPatcherNotInstalled() throws Exception {
    FakeLocalPackage target = new FakeLocalPackage("patcher;v2");
    List<LocalPackage> local = ImmutableList.of(new FakeLocalPackage("patcher;v1"), new FakeLocalPackage("patcher;v3"));
    FakeRemotePackage update = new FakeRemotePackage("p");
    List<RemotePackage> remote = ImmutableList.of(update, new FakeRemotePackage("patcher;v4"));
    update.setDependencies(ImmutableList.of(new FakeDependency(target.getPath())));
    RepositoryPackages packages = new RepositoryPackages(local, remote);
    FakeRepoManager mgr = new FakeRepoManager(new File("/sdk"), packages);
    LocalPackage patcher = PatchInstallerUtil.getDependantPatcher(update, mgr);
    assertNull(patcher);
}
Also used : FakeRemotePackage(com.android.repository.testframework.FakePackage.FakeRemotePackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) LocalPackage(com.android.repository.api.LocalPackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) FakeDependency(com.android.repository.testframework.FakeDependency) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) RemotePackage(com.android.repository.api.RemotePackage) FakeRemotePackage(com.android.repository.testframework.FakePackage.FakeRemotePackage) File(java.io.File) Test(org.junit.Test)

Example 13 with RepositoryPackages

use of com.android.repository.impl.meta.RepositoryPackages in project android by JetBrains.

the class PatchInstallerUtilTest method noLatestPatcher.

@Test
public void noLatestPatcher() throws Exception {
    List<LocalPackage> local = ImmutableList.of(new FakeLocalPackage("foo"));
    RepositoryPackages packages = new RepositoryPackages(local, ImmutableList.of());
    FakeRepoManager mgr = new FakeRepoManager(new File("/sdk"), packages);
    LocalPackage patcher = PatchInstallerUtil.getLatestPatcher(mgr);
    assertNull(patcher);
}
Also used : FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) LocalPackage(com.android.repository.api.LocalPackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) File(java.io.File) Test(org.junit.Test)

Example 14 with RepositoryPackages

use of com.android.repository.impl.meta.RepositoryPackages in project android by JetBrains.

the class InstallTaskTest method setUp.

@Before
public void setUp() {
    Mockito.when(myExisting1.getPath()).thenReturn("p1");
    Mockito.when(myAvailable1.getPath()).thenReturn("p2");
    Mockito.when(myAvailable2.getPath()).thenReturn("p3");
    RepositoryPackages repoPackages = new RepositoryPackages(ImmutableList.of(myExisting1), ImmutableList.of(myAvailable1, myAvailable2));
    AndroidSdkHandler repoHandler = new AndroidSdkHandler(SDK_ROOT, null, myFileOp, new FakeRepoManager(SDK_ROOT, repoPackages));
    RepoManager repoManager = repoHandler.getSdkManager(myProgressIndicator);
    myInstallTask = new InstallTask(factory, repoHandler, new FakeSettingsController(false), myProgressIndicator);
    myInstallTask.setInstallRequests(ImmutableList.of(new UpdatablePackage(myAvailable1), new UpdatablePackage(myAvailable2)));
    myInstallTask.setUninstallRequests(ImmutableList.of(myExisting1));
    Mockito.when(myInstaller.prepare(myProgressIndicator)).thenReturn(true);
    Mockito.when(myInstaller2.prepare(myProgressIndicator)).thenReturn(true);
    Mockito.when(myUninstaller.prepare(myProgressIndicator)).thenReturn(true);
    Mockito.when(myInstaller.complete(myProgressIndicator)).thenReturn(true);
    Mockito.when(myInstaller2.complete(myProgressIndicator)).thenReturn(true);
    Mockito.when(myUninstaller.complete(myProgressIndicator)).thenReturn(true);
    myOperations = new HashMap<>();
    myOperations.put(myExisting1, myUninstaller);
    myOperations.put(myAvailable1, myInstaller);
    myOperations.put(myAvailable2, myInstaller2);
    Mockito.when(factory.createInstaller(eq(myAvailable1), eq(repoManager), any(), eq(myFileOp))).thenReturn(myInstaller);
    Mockito.when(factory.createInstaller(eq(myAvailable2), eq(repoManager), any(), eq(myFileOp))).thenReturn(myInstaller2);
    Mockito.when(factory.createUninstaller(myExisting1, repoManager, myFileOp)).thenReturn(myUninstaller);
}
Also used : RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) FakeSettingsController(com.android.repository.testframework.FakeSettingsController) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Before(org.junit.Before)

Example 15 with RepositoryPackages

use of com.android.repository.impl.meta.RepositoryPackages in project android by JetBrains.

the class SdkUpdaterConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    myPanel.saveSources();
    HtmlBuilder message = new HtmlBuilder();
    message.openHtmlBody();
    final List<LocalPackage> toDelete = Lists.newArrayList();
    final Map<RemotePackage, UpdatablePackage> requestedPackages = Maps.newHashMap();
    for (PackageNodeModel model : myPanel.getStates()) {
        if (model.getState() == PackageNodeModel.SelectedState.NOT_INSTALLED) {
            if (model.getPkg().hasLocal()) {
                toDelete.add(model.getPkg().getLocal());
            }
        } else if (model.getState() == PackageNodeModel.SelectedState.INSTALLED && (model.getPkg().isUpdate() || !model.getPkg().hasLocal())) {
            UpdatablePackage pkg = model.getPkg();
            requestedPackages.put(pkg.getRemote(), pkg);
        }
    }
    boolean found = false;
    if (!toDelete.isEmpty()) {
        found = true;
        message.add("The following components will be deleted: \n");
        message.beginList();
        for (LocalPackage item : toDelete) {
            message.listItem().add(item.getDisplayName()).add(", Revision: ").add(item.getVersion().toString());
        }
        message.endList();
    }
    if (!requestedPackages.isEmpty()) {
        found = true;
        message.add("The following components will be installed: \n");
        message.beginList();
        Multimap<RemotePackage, RemotePackage> dependencies = HashMultimap.create();
        ProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
        RepositoryPackages packages = getRepoManager().getPackages();
        for (RemotePackage item : requestedPackages.keySet()) {
            List<RemotePackage> packageDependencies = InstallerUtil.computeRequiredPackages(ImmutableList.of(item), packages, progress);
            if (packageDependencies == null) {
                Messages.showErrorDialog((Project) null, "Unable to resolve dependencies for " + item.getDisplayName(), "Dependency Error");
                throw new ConfigurationException("Unable to resolve dependencies.");
            }
            for (RemotePackage dependency : packageDependencies) {
                dependencies.put(dependency, item);
            }
            message.listItem().add(String.format("%1$s %2$s %3$s", item.getDisplayName(), item.getTypeDetails() instanceof DetailsTypes.ApiDetailsType ? "revision" : "version", item.getVersion()));
        }
        for (RemotePackage dependency : dependencies.keySet()) {
            if (requestedPackages.containsKey(dependency)) {
                continue;
            }
            Set<RemotePackage> requests = Sets.newHashSet(dependencies.get(dependency));
            requests.remove(dependency);
            if (!requests.isEmpty()) {
                message.listItem().add(dependency.getDisplayName()).add(" (Required by ");
                Iterator<RemotePackage> requestIterator = requests.iterator();
                message.add(requestIterator.next().getDisplayName());
                while (requestIterator.hasNext()) {
                    message.add(", ").add(requestIterator.next().getDisplayName());
                }
                message.add(")");
            }
        }
        message.endList();
    }
    message.closeHtmlBody();
    if (found) {
        if (confirmChange(message)) {
            if (!requestedPackages.isEmpty() || !toDelete.isEmpty()) {
                ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPackages(myPanel.getComponent(), requestedPackages.values(), toDelete, true);
                if (dialog != null) {
                    dialog.show();
                    for (RemotePackage remotePackage : requestedPackages.keySet()) {
                        PackageOperation installer = getRepoManager().getInProgressInstallOperation(remotePackage);
                        if (installer != null) {
                            PackageOperation.StatusChangeListener listener = (installer1, progress) -> myPanel.getComponent().repaint();
                            myListeners.add(listener);
                            installer.registerStateChangeListener(listener);
                        }
                    }
                }
            }
            myPanel.refresh();
        } else {
            throw new ConfigurationException("Installation was canceled.");
        }
    } else {
        // We didn't have any changes, so just reload (maybe the channel changed).
        myChannelChangedCallback.run();
    }
}
Also used : Settings(com.intellij.openapi.options.ex.Settings) AllIcons(com.intellij.icons.AllIcons) DataContext(com.intellij.openapi.actionSystem.DataContext) com.android.repository.api(com.android.repository.api) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) Nls(org.jetbrains.annotations.Nls) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Map(java.util.Map) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Objects(com.google.common.base.Objects) com.google.common.collect(com.google.common.collect) DataManager(com.intellij.ide.DataManager) AncestorEvent(javax.swing.event.AncestorEvent) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) Iterator(java.util.Iterator) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioHelpManagerImpl(com.android.tools.idea.help.StudioHelpManagerImpl) HtmlBuilder(com.android.utils.HtmlBuilder) Set(java.util.Set) Configurable(com.intellij.openapi.options.Configurable) InstallerUtil(com.android.repository.util.InstallerUtil) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) AncestorListenerAdapter(com.intellij.ui.AncestorListenerAdapter) SdkQuickfixUtils(com.android.tools.idea.sdk.wizard.SdkQuickfixUtils) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) HtmlBuilder(com.android.utils.HtmlBuilder) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) ConfigurationException(com.intellij.openapi.options.ConfigurationException) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Aggregations

RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)15 FakeRepoManager (com.android.repository.testframework.FakeRepoManager)9 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)7 File (java.io.File)6 LocalPackage (com.android.repository.api.LocalPackage)5 FakeLocalPackage (com.android.repository.testframework.FakePackage.FakeLocalPackage)5 NotNull (org.jetbrains.annotations.NotNull)5 RemotePackage (com.android.repository.api.RemotePackage)4 RepoManager (com.android.repository.api.RepoManager)4 Test (org.junit.Test)4 StudioDownloader (com.android.tools.idea.sdk.StudioDownloader)3 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)3 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)2 BasicInstallerFactory (com.android.repository.impl.installer.BasicInstallerFactory)2 FakeDependency (com.android.repository.testframework.FakeDependency)2 FakeRemotePackage (com.android.repository.testframework.FakePackage.FakeRemotePackage)2 MockFileOp (com.android.repository.testframework.MockFileOp)2 HtmlBuilder (com.android.utils.HtmlBuilder)2 Before (org.junit.Before)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1