Search in sources :

Example 1 with MobileInstallBuildStep

use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep in project intellij by bazelbuild.

the class MobileInstallBuildStepIntegrationTest method nullExecRoot.

@Test
public void nullExecRoot() throws Exception {
    // Return null execroot
    when(mockBuildResultHelper.getBuildOutput()).thenReturn(new ParsedBepOutput(null, null, null, null, 0, BuildResult.SUCCESS, 0));
    // Mobile-install build step requires only one device be active.  DeviceFutures class is final,
    // so we have to make one with a stub AndroidDevice.
    DeviceFutures deviceFutures = new DeviceFutures(ImmutableList.of(new FakeDevice()));
    // Return fake deploy info proto and mocked deploy info data object.
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(getProject(), new File(getExecRoot()), fakeProto)).thenReturn(mockDeployInfo);
    // Perform
    MobileInstallBuildStep buildStep = new MobileInstallBuildStep(getProject(), buildTarget, blazeFlags, execFlags, helper);
    buildStep.build(context, new DeviceSession(null, deviceFutures, null));
    // Verify
    assertThat(context.hasErrors()).isTrue();
    assertThat(messageCollector.getMessages()).contains("Could not locate execroot!");
}
Also used : 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) MobileInstallBuildStep(com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) DeviceFutures(com.android.tools.idea.run.DeviceFutures) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) File(java.io.File) Test(org.junit.Test)

Example 2 with MobileInstallBuildStep

use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep in project intellij by bazelbuild.

the class MobileInstallBuildStepIntegrationTest method deployInfoBuiltCorrectly_withInactiveAdbTunnelSetup.

@Test
public void deployInfoBuiltCorrectly_withInactiveAdbTunnelSetup() throws Exception {
    // Mobile-install build step requires only one device be active.  DeviceFutures class is final,
    // so we have to make one with a stub AndroidDevice.
    DeviceFutures deviceFutures = new DeviceFutures(ImmutableList.of(new FakeDevice()));
    // Return fake deploy info proto and mocked deploy info data object.
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(getProject(), new File(getExecRoot()), fakeProto)).thenReturn(mockDeployInfo);
    // Setup mock AdbTunnelConfigurator for testing device port flags.
    AdbTunnelConfigurator tunnelConfigurator = mock(AdbTunnelConfigurator.class);
    when(tunnelConfigurator.isActive()).thenReturn(false);
    when(tunnelConfigurator.getAdbServerPort()).thenReturn(12345);
    registerExtension(AdbTunnelConfiguratorProvider.EP_NAME, providerCxt -> tunnelConfigurator);
    // Perform
    MobileInstallBuildStep buildStep = new MobileInstallBuildStep(getProject(), buildTarget, blazeFlags, execFlags, helper);
    buildStep.build(context, new DeviceSession(null, deviceFutures, null));
    // Verify
    assertThat(buildStep.getDeployInfo()).isNotNull();
    assertThat(buildStep.getDeployInfo()).isEqualTo(mockDeployInfo);
    assertThat(externalTaskInterceptor.context).isEqualTo(context);
    assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
    assertThat(externalTaskInterceptor.command).containsAllIn(execFlags);
    assertThat(externalTaskInterceptor.command).contains("--nolaunch_app");
    assertThat(externalTaskInterceptor.command).contains("--device");
    // workaround for inconsistent stateful AndroidDebugBridge class.
    assertThat(externalTaskInterceptor.command).containsAnyOf("serial-number", "serial-number:tcp:0");
    assertThat(externalTaskInterceptor.command).contains(buildTarget.toString());
}
Also used : 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) MobileInstallBuildStep(com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) DeviceFutures(com.android.tools.idea.run.DeviceFutures) AdbTunnelConfigurator(com.google.idea.blaze.android.run.binary.mobileinstall.AdbTunnelConfigurator) File(java.io.File) Test(org.junit.Test)

Example 3 with MobileInstallBuildStep

use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep in project intellij by bazelbuild.

the class MobileInstallBuildStepIntegrationTest method deployInfoBuiltCorrectly.

@Test
public void deployInfoBuiltCorrectly() throws Exception {
    // Mobile-install build step requires only one device be active.  DeviceFutures class is final,
    // so we have to make one with a stub AndroidDevice.
    DeviceFutures deviceFutures = new DeviceFutures(ImmutableList.of(new FakeDevice()));
    // Return fake deploy info proto and mocked deploy info data object.
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(getProject(), new File(getExecRoot()), fakeProto)).thenReturn(mockDeployInfo);
    // Perform
    MobileInstallBuildStep buildStep = new MobileInstallBuildStep(getProject(), buildTarget, blazeFlags, execFlags, helper);
    buildStep.build(context, new DeviceSession(null, deviceFutures, null));
    // Verify
    assertThat(buildStep.getDeployInfo()).isNotNull();
    assertThat(buildStep.getDeployInfo()).isEqualTo(mockDeployInfo);
    assertThat(externalTaskInterceptor.context).isEqualTo(context);
    assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
    assertThat(externalTaskInterceptor.command).containsAllIn(execFlags);
    assertThat(externalTaskInterceptor.command).contains("--nolaunch_app");
    assertThat(externalTaskInterceptor.command).containsAnyOf("serial-number", "serial-number:tcp:0");
    assertThat(externalTaskInterceptor.command).contains(buildTarget.toString());
}
Also used : 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) MobileInstallBuildStep(com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) DeviceFutures(com.android.tools.idea.run.DeviceFutures) File(java.io.File) Test(org.junit.Test)

Example 4 with MobileInstallBuildStep

use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep in project intellij by bazelbuild.

the class MobileInstallBuildStepIntegrationTest method deployInfoBuiltCorrectly_withNullAdbTunnelSetup.

@Test
public void deployInfoBuiltCorrectly_withNullAdbTunnelSetup() throws Exception {
    // Mobile-install build step requires only one device be active.  DeviceFutures class is final,
    // so we have to make one with a stub AndroidDevice.
    DeviceFutures deviceFutures = new DeviceFutures(ImmutableList.of(new FakeDevice()));
    // Return fake deploy info proto and mocked deploy info data object.
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(getProject(), new File(getExecRoot()), fakeProto)).thenReturn(mockDeployInfo);
    // Setup mock AdbTunnelConfigurator for testing device port flags.
    AdbTunnelConfigurator tunnelConfigurator = mock(AdbTunnelConfigurator.class);
    when(tunnelConfigurator.isActive()).thenReturn(true);
    when(tunnelConfigurator.getAdbServerPort()).thenReturn(12345);
    registerExtension(AdbTunnelConfiguratorProvider.EP_NAME, providerCxt -> null);
    // Perform
    MobileInstallBuildStep buildStep = new MobileInstallBuildStep(getProject(), buildTarget, blazeFlags, execFlags, helper);
    buildStep.build(context, new DeviceSession(null, deviceFutures, null));
    // Verify
    assertThat(buildStep.getDeployInfo()).isNotNull();
    assertThat(buildStep.getDeployInfo()).isEqualTo(mockDeployInfo);
    assertThat(externalTaskInterceptor.context).isEqualTo(context);
    assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
    assertThat(externalTaskInterceptor.command).containsAllIn(execFlags);
    assertThat(externalTaskInterceptor.command).contains("--nolaunch_app");
    assertThat(externalTaskInterceptor.command).contains("--device");
    // workaround for inconsistent stateful AndroidDebugBridge class.
    assertThat(externalTaskInterceptor.command).containsAnyOf("serial-number", "serial-number:tcp:0");
    assertThat(externalTaskInterceptor.command).contains(buildTarget.toString());
}
Also used : 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) MobileInstallBuildStep(com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) DeviceFutures(com.android.tools.idea.run.DeviceFutures) AdbTunnelConfigurator(com.google.idea.blaze.android.run.binary.mobileinstall.AdbTunnelConfigurator) File(java.io.File) Test(org.junit.Test)

Example 5 with MobileInstallBuildStep

use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep in project intellij by bazelbuild.

the class MobileInstallBuildStepIntegrationTest method moreThanOneDevice.

@Test
public void moreThanOneDevice() throws Exception {
    // Make blaze command invocation always pass.
    registerApplicationService(ExternalTaskProvider.class, builder -> scopes -> 0);
    // Mobile-install build step requires only one device be active.  DeviceFutures class is final,
    // so we have to make one with a stub AndroidDevice.
    DeviceFutures deviceFutures = new DeviceFutures(ImmutableList.of(new FakeDevice(), new FakeDevice()));
    // Return fake deploy info proto and mocked deploy info data object.
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(getProject(), new File(getExecRoot()), fakeProto)).thenReturn(mockDeployInfo);
    // Perform
    MobileInstallBuildStep buildStep = new MobileInstallBuildStep(getProject(), buildTarget, ImmutableList.of(), ImmutableList.of(), helper);
    buildStep.build(context, new DeviceSession(null, deviceFutures, null));
    // Verify
    assertThat(context.hasErrors()).isTrue();
    assertThat(messageCollector.getMessages()).contains("Only one device can be used with mobile-install.");
}
Also used : 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) MobileInstallBuildStep(com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) DeviceFutures(com.android.tools.idea.run.DeviceFutures) File(java.io.File) Test(org.junit.Test)

Aggregations

DeviceFutures (com.android.tools.idea.run.DeviceFutures)8 AndroidDeployInfo (com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo)8 MobileInstallBuildStep (com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep)8 BlazeAndroidDeployInfo (com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo)8 BlazeApkDeployInfoProtoHelper (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper)8 DeviceSession (com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession)8 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)8 Test (org.junit.Test)8 File (java.io.File)7 AdbTunnelConfigurator (com.google.idea.blaze.android.run.binary.mobileinstall.AdbTunnelConfigurator)3 GetDeployInfoException (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper.GetDeployInfoException)1 ParsedBepOutput (com.google.idea.blaze.base.command.buildresult.ParsedBepOutput)1