Search in sources :

Example 1 with RemoteApkDownloader

use of com.google.idea.blaze.android.run.RemoteApkDownloader in project intellij by bazelbuild.

the class FullApkBuildStepIntegrationTest method build_withRemoteApkButDisabledRemoteApkFetching.

@Test
public void build_withRemoteApkButDisabledRemoteApkFetching() throws Exception {
    // Setup remote APK downloader for ensuring the download method is called
    RemoteApkDownloader mockDownloader = mock(RemoteApkDownloader.class);
    when(mockDownloader.canDownload(any())).thenReturn(true);
    registerExtension(RemoteApkDownloader.EP_NAME, mockDownloader);
    // Disable remote APK fetching
    MockExperimentService mockExperimentService = new MockExperimentService();
    mockExperimentService.setExperiment(FullApkBuildStep.FETCH_REMOTE_APKS, false);
    ServiceHelper.registerApplicationComponent(ExperimentService.class, mockExperimentService, getTestRootDisposable());
    // Return fake deploy info proto and mocked deploy info data object.
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    File apkFile = new File("/path/to/apk");
    when(mockDeployInfo.getApksToDeploy()).thenReturn(ImmutableList.of(apkFile));
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(eq(getProject()), eq(new File(getExecRoot())), eq(fakeProto))).thenReturn(mockDeployInfo);
    // Perform
    FullApkBuildStep buildStep = new FullApkBuildStep(getProject(), buildTarget, blazeFlags, helper);
    buildStep.build(context, new DeviceSession(null, null, null));
    // Verify
    assertThat(buildStep.getDeployInfo()).isNotNull();
    assertThat(buildStep.getDeployInfo().getApksToDeploy()).containsExactly(apkFile);
    assertThat(externalTaskInterceptor.command).contains(buildTarget.toString());
    assertThat(externalTaskInterceptor.command).contains("--output_groups=+android_deploy_info");
    assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
    verify(mockDownloader, times(0)).download(any(), any());
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) FullApkBuildStep(com.google.idea.blaze.android.run.runner.FullApkBuildStep) AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) RemoteApkDownloader(com.google.idea.blaze.android.run.RemoteApkDownloader) File(java.io.File) Test(org.junit.Test)

Example 2 with RemoteApkDownloader

use of com.google.idea.blaze.android.run.RemoteApkDownloader in project intellij by bazelbuild.

the class FullApkBuildStep method downloadApkIfRemote.

private static File downloadApkIfRemote(File apk, BlazeContext context) {
    for (RemoteApkDownloader downloader : RemoteApkDownloader.EP_NAME.getExtensionList()) {
        if (downloader.canDownload(apk)) {
            try {
                context.output(new StatusOutput("Downloading " + apk.getPath()));
                File tempFile = Files.createTempFile("localcopy", apk.getName()).toFile();
                tempFile.deleteOnExit();
                downloader.download(apk, tempFile);
                return tempFile;
            } catch (IOException ex) {
                // fallback to using original, don't want to block the whole app deployment process.
                log.warn("Couldn't create local copy of file " + apk.getPath(), ex);
            }
        }
    }
    return apk;
}
Also used : StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) RemoteApkDownloader(com.google.idea.blaze.android.run.RemoteApkDownloader) IOException(java.io.IOException) File(java.io.File)

Example 3 with RemoteApkDownloader

use of com.google.idea.blaze.android.run.RemoteApkDownloader in project intellij by bazelbuild.

the class FullApkBuildStepIntegrationTest method build_withRemoteApk.

@Test
public void build_withRemoteApk() throws Exception {
    // Setup remote APK downloader for ensuring the download method is called
    RemoteApkDownloader mockDownloader = mock(RemoteApkDownloader.class);
    when(mockDownloader.canDownload(any())).thenReturn(true);
    registerExtension(RemoteApkDownloader.EP_NAME, mockDownloader);
    // Return fake deploy info proto and mocked deploy info data object.
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    File apkFile = new File("/path/to/apk");
    when(mockDeployInfo.getApksToDeploy()).thenReturn(ImmutableList.of(apkFile));
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(eq(getProject()), eq(new File(getExecRoot())), eq(fakeProto))).thenReturn(mockDeployInfo);
    // Perform
    FullApkBuildStep buildStep = new FullApkBuildStep(getProject(), buildTarget, blazeFlags, helper);
    buildStep.build(context, new DeviceSession(null, null, null));
    // Verify
    assertThat(buildStep.getDeployInfo()).isNotNull();
    assertThat(buildStep.getDeployInfo().getApksToDeploy()).doesNotContain(apkFile);
    assertThat(getOnlyElement(buildStep.getDeployInfo().getApksToDeploy()).getPath()).contains("localcopy");
    assertThat(externalTaskInterceptor.command).contains(buildTarget.toString());
    assertThat(externalTaskInterceptor.command).contains("--output_groups=+android_deploy_info");
    assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
    verify(mockDownloader, times(1)).download(any(), any());
}
Also used : FullApkBuildStep(com.google.idea.blaze.android.run.runner.FullApkBuildStep) AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) RemoteApkDownloader(com.google.idea.blaze.android.run.RemoteApkDownloader) File(java.io.File) Test(org.junit.Test)

Aggregations

RemoteApkDownloader (com.google.idea.blaze.android.run.RemoteApkDownloader)3 File (java.io.File)3 AndroidDeployInfo (com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo)2 BlazeAndroidDeployInfo (com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo)2 BlazeApkDeployInfoProtoHelper (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper)2 DeviceSession (com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession)2 FullApkBuildStep (com.google.idea.blaze.android.run.runner.FullApkBuildStep)2 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)2 Test (org.junit.Test)2 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)1 MockExperimentService (com.google.idea.common.experiments.MockExperimentService)1 IOException (java.io.IOException)1