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