Search in sources :

Example 1 with RepositoryPackages

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

the class UnresolvedDependenciesReporter method getRemotePackages.

@NotNull
private static Collection<RemotePackage> getRemotePackages(@NotNull ProgressIndicator indicator) {
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    RepositoryPackages packages = sdkHandler.getSdkManager(indicator).getPackages();
    return packages.getRemotePackages().values();
}
Also used : RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with RepositoryPackages

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

the class PatchInstallerUtilTest method getLatestPatcher.

@Test
public void getLatestPatcher() throws Exception {
    LocalPackage target = new FakeLocalPackage("patcher;v3");
    List<LocalPackage> local = ImmutableList.of(new FakeLocalPackage("patcher;v1"), target, new FakeLocalPackage("patcher;v2"));
    RepositoryPackages packages = new RepositoryPackages(local, ImmutableList.of());
    FakeRepoManager mgr = new FakeRepoManager(new File("/sdk"), packages);
    LocalPackage patcher = PatchInstallerUtil.getLatestPatcher(mgr);
    assertEquals(target, 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 3 with RepositoryPackages

use of com.android.repository.impl.meta.RepositoryPackages 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 4 with RepositoryPackages

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

the class RepositoryUrlManagerTest method testResolvedCoordinateRemoteSdk.

public void testResolvedCoordinateRemoteSdk() throws Exception {
    RemotePackage pkg = new FakePackage.FakeRemotePackage("extras;m2repository;com;google;android;gms;play-services;4.5.0");
    RepositoryPackages pkgs = new RepositoryPackages(ImmutableList.of(), ImmutableList.of(pkg));
    RepoManager mgr = new FakeRepoManager(pkgs);
    mySdkHandler = new AndroidSdkHandler(new File("/emptysdk"), ANDROID_HOME, myFileOp, mgr);
    GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString("com.google.android.gms:play-services:4.+");
    assertNotNull(coordinate);
    assertEquals("4.5.0", resolveDynamicCoordinateVersion(coordinate));
}
Also used : RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) RepoManager(com.android.repository.api.RepoManager) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) RemotePackage(com.android.repository.api.RemotePackage) File(java.io.File)

Example 5 with RepositoryPackages

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

the class SystemImageListModel method refreshImages.

public void refreshImages(final boolean forceRefresh) {
    synchronized (myLock) {
        myCompletedCalls = 0;
    }
    myIndicator.onRefreshStart("Refreshing...");
    final List<SystemImageDescription> items = Lists.newArrayList();
    RepoManager.RepoLoadedCallback localComplete = new RepoManager.RepoLoadedCallback() {

        @Override
        public void doRun(@NotNull RepositoryPackages packages) {
            // getLocalImages() doesn't use SdkPackages, so it's ok that we're not using what's passed in.
            items.addAll(getLocalImages());
            // Update list in the UI immediately with the locally available system images
            setItems(items);
            // Assume the remote has not completed yet
            completedDownload("");
        }
    };
    RepoManager.RepoLoadedCallback remoteComplete = new RepoManager.RepoLoadedCallback() {

        @Override
        public void doRun(@NotNull RepositoryPackages packages) {
            List<SystemImageDescription> remotes = getRemoteImages(packages);
            if (remotes != null) {
                items.addAll(remotes);
                setItems(items);
            }
            completedDownload("");
        }
    };
    Runnable error = new Runnable() {

        @Override
        public void run() {
            ApplicationManager.getApplication().invokeLater(new Runnable() {

                @Override
                public void run() {
                    completedDownload("Error loading remote images");
                }
            });
        }
    };
    StudioProgressRunner runner = new StudioProgressRunner(false, false, "Loading Images", true, myProject);
    mySdkHandler.getSdkManager(LOGGER).load(forceRefresh ? 0 : RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, ImmutableList.of(localComplete), ImmutableList.of(remoteComplete), ImmutableList.of(error), runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) RepoManager(com.android.repository.api.RepoManager) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) NotNull(org.jetbrains.annotations.NotNull) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

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