Search in sources :

Example 1 with StudioProgressIndicatorAdapter

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

the class StudioDownloader method downloadFully.

@Override
public void downloadFully(@NotNull URL url, @NotNull File target, @Nullable String checksum, @NotNull ProgressIndicator indicator) throws IOException {
    if (target.exists() && checksum != null) {
        if (checksum.equals(Downloader.hash(new BufferedInputStream(new FileInputStream(target)), target.length(), indicator))) {
            return;
        }
    }
    // We don't use the settings here explicitly, since HttpRequests picks up the network settings from studio directly.
    indicator.logInfo("Downloading " + url);
    indicator.setText("Downloading...");
    indicator.setSecondaryText(url.toString());
    com.intellij.openapi.progress.ProgressIndicator studioProgress = myStudioProgressIndicator;
    if (studioProgress == null) {
        studioProgress = ProgressManager.getInstance().getProgressIndicator();
    }
    HttpRequests.request(url.toExternalForm()).saveToFile(target, new StudioProgressIndicatorAdapter(indicator, studioProgress));
}
Also used : StudioProgressIndicatorAdapter(com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter)

Example 2 with StudioProgressIndicatorAdapter

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

the class InstallTaskTest method runCallbacks.

@Test
public void runCallbacks() throws Exception {
    Runnable prepareComplete = Mockito.mock(Runnable.class);
    myInstallTask.setPrepareCompleteCallback(prepareComplete);
    Function<List<RepoPackage>, Void> complete = (Function<List<RepoPackage>, Void>) Mockito.mock(Function.class);
    myInstallTask.setCompleteCallback(complete);
    myInstallTask.run(new StudioProgressIndicatorAdapter(myProgressIndicator, new EmptyProgressIndicator()));
    InOrder callbackCalls = Mockito.inOrder(myInstaller, prepareComplete, complete);
    callbackCalls.verify(myInstaller).prepare(myProgressIndicator);
    callbackCalls.verify(prepareComplete).run();
    callbackCalls.verify(myInstaller).complete(myProgressIndicator);
    callbackCalls.verify(complete).apply(new ArrayList<>());
}
Also used : Function(java.util.function.Function) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) InOrder(org.mockito.InOrder) StudioProgressIndicatorAdapter(com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Example 3 with StudioProgressIndicatorAdapter

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

the class SdkComponentSourceTest method testIgnored.

public void testIgnored() throws Exception {
    final AtomicReference<String> id = new AtomicReference<String>();
    ProgressIndicator progress = new StudioProgressIndicatorAdapter(new FakeProgressIndicator(), null);
    for (UpdatableExternalComponent c : myTestComponentSource.getAvailableVersions(progress, null)) {
        if ("package newerRemote".equals(c.getName())) {
            id.set(SdkComponentSource.getPackageRevisionId((RepoPackage) c.getKey()));
        }
    }
    assertNotNull(id.get());
    ExternalComponentManager.getInstance().registerComponentSource(myTestComponentSource);
    UpdateSettings settings = new UpdateSettings() {

        @Override
        public List<String> getEnabledExternalUpdateSources() {
            return ImmutableList.of(myTestComponentSource.getName());
        }

        @Override
        public List<String> getIgnoredBuildNumbers() {
            return ImmutableList.of(id.get());
        }
    };
    Collection<ExternalUpdate> updates = UpdateChecker.updateExternal(true, settings, progress);
    assertEquals(1, updates.size());
    ExternalUpdate update = updates.iterator().next();
    Iterator<UpdatableExternalComponent> iter = update.getComponents().iterator();
    UpdatableExternalComponent component = iter.next();
    assertEquals("package newerPreview", component.getName());
    assertEquals(new Revision(1, 0, 0, 2), ((RepoPackage) component.getKey()).getVersion());
    assertFalse(iter.hasNext());
}
Also used : StudioProgressIndicatorAdapter(com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) UpdateSettings(com.intellij.openapi.updateSettings.impl.UpdateSettings) ExternalUpdate(com.intellij.openapi.updateSettings.impl.ExternalUpdate) Revision(com.android.repository.Revision) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) UpdatableExternalComponent(com.intellij.ide.externalComponents.UpdatableExternalComponent)

Example 4 with StudioProgressIndicatorAdapter

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

the class SdkComponentSourceTest method testAvailableStableVersions.

public void testAvailableStableVersions() throws Exception {
    ProgressIndicator progress = new StudioProgressIndicatorAdapter(new FakeProgressIndicator(), null);
    Set<UpdatableExternalComponent> components = Sets.newTreeSet(COMPONENT_COMPARATOR);
    components.addAll(myTestComponentSource.getAvailableVersions(progress, null));
    Iterator<UpdatableExternalComponent> componentIter = components.iterator();
    validateStablePackages(componentIter);
    assertFalse(componentIter.hasNext());
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) UpdatableExternalComponent(com.intellij.ide.externalComponents.UpdatableExternalComponent) StudioProgressIndicatorAdapter(com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter)

Example 5 with StudioProgressIndicatorAdapter

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

the class SdkComponentSourceTest method testBetaUpdates.

public void testBetaUpdates() throws Exception {
    myChannelId = 1;
    ExternalComponentManager.getInstance().registerComponentSource(myTestComponentSource);
    ProgressIndicator progress = new StudioProgressIndicatorAdapter(new FakeProgressIndicator(), null);
    UpdateSettings settings = new UpdateSettings() {

        @Override
        public List<String> getEnabledExternalUpdateSources() {
            return ImmutableList.of(myTestComponentSource.getName());
        }
    };
    Collection<ExternalUpdate> updates = UpdateChecker.updateExternal(true, settings, progress);
    assertEquals(1, updates.size());
    ExternalUpdate update = updates.iterator().next();
    Iterator<UpdatableExternalComponent> iter = update.getComponents().iterator();
    UpdatableExternalComponent component = iter.next();
    assertEquals("package newerPreview", component.getName());
    assertEquals(new Revision(1, 0, 0, 2), ((RepoPackage) component.getKey()).getVersion());
    component = iter.next();
    assertEquals("package newerRemote", component.getName());
    assertEquals(new Revision(1, 1, 0), ((RepoPackage) component.getKey()).getVersion());
    component = iter.next();
    assertEquals("package zNewerInBeta", component.getName());
    assertEquals(new Revision(2, 0, 0), ((RepoPackage) component.getKey()).getVersion());
    assertFalse(iter.hasNext());
}
Also used : ExternalUpdate(com.intellij.openapi.updateSettings.impl.ExternalUpdate) Revision(com.android.repository.Revision) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) UpdatableExternalComponent(com.intellij.ide.externalComponents.UpdatableExternalComponent) StudioProgressIndicatorAdapter(com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter) UpdateSettings(com.intellij.openapi.updateSettings.impl.UpdateSettings)

Aggregations

StudioProgressIndicatorAdapter (com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter)10 UpdatableExternalComponent (com.intellij.ide.externalComponents.UpdatableExternalComponent)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Revision (com.android.repository.Revision)4 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)4 Test (org.junit.Test)4 ExternalUpdate (com.intellij.openapi.updateSettings.impl.ExternalUpdate)3 UpdateSettings (com.intellij.openapi.updateSettings.impl.UpdateSettings)3 InOrder (org.mockito.InOrder)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Function (java.util.function.Function)1