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);
}
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);
}
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);
}
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);
}
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();
}
}
Aggregations