use of com.google.idea.blaze.android.run.runner.ApkBuildStep in project intellij by bazelbuild.
the class BlazeAndroidBinaryRunConfigurationHandler method createRunner.
@Override
public BlazeCommandRunConfigurationRunner createRunner(Executor executor, ExecutionEnvironment env) throws ExecutionException {
Project project = env.getProject();
BlazeCommandRunConfiguration configuration = BlazeAndroidRunConfigurationHandler.getCommandConfig(env);
BlazeAndroidRunConfigurationValidationUtil.validate(project);
Module module = ModuleFinder.getInstance(env.getProject()).findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
AndroidFacet facet = module != null ? AndroidFacet.getInstance(module) : null;
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
// Only suggest building with mobile-install if native debugging isn't enabled.
if (configState.getLaunchMethod() == AndroidBinaryLaunchMethod.NON_BLAZE && !configState.getCommonState().isNativeDebuggingEnabled()) {
maybeShowMobileInstallOptIn(project, configuration);
}
// We collect metrics from a few different locations. In order to tie them all
// together, we create a unique launch id.
String launchId = LaunchMetrics.newLaunchId();
// Create build step for matching launch method.
ImmutableList<String> blazeFlags = configState.getCommonState().getExpandedBuildFlags(project, projectViewSet, BlazeCommandName.RUN, BlazeInvocationContext.runConfigContext(ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), false));
ImmutableList<String> exeFlags = ImmutableList.copyOf(configState.getCommonState().getExeFlagsState().getFlagsForExternalProcesses());
ApkBuildStep buildStep = ApkBuildStepProvider.getInstance(Blaze.getBuildSystemName(project)).getBuildStep(project, AndroidBinaryLaunchMethodsUtils.useMobileInstall(configState.getLaunchMethod()), Label.create(configuration.getSingleTarget().toString()), blazeFlags, exeFlags, launchId);
// Create run context for matching launch method.
BlazeAndroidRunContext runContext = null;
switch(configState.getLaunchMethod()) {
case NON_BLAZE:
runContext = new BlazeAndroidBinaryNormalBuildRunContext(project, facet, configuration, env, configState, buildStep, launchId);
break;
case MOBILE_INSTALL_V2:
// Standardize on a single mobile-install launch method
configState.setLaunchMethod(AndroidBinaryLaunchMethod.MOBILE_INSTALL);
// fall through
case MOBILE_INSTALL:
runContext = new BlazeAndroidBinaryMobileInstallRunContext(project, facet, configuration, env, configState, buildStep, launchId);
break;
default:
throw new ExecutionException("No compatible launch methods.");
}
logBinaryLaunch(launchId, configState.getLaunchMethod().name(), env.getExecutor().getId(), configuration.getSingleTarget().toString(), configState.getCommonState().isNativeDebuggingEnabled());
return new BlazeAndroidRunConfigurationRunner(module, runContext, configuration);
}
use of com.google.idea.blaze.android.run.runner.ApkBuildStep in project intellij by bazelbuild.
the class BlazeAndroidTestApplicationIdProviderTest method getPackageName_noPackageNameInMergedManifest.
@Test
public void getPackageName_noPackageNameInMergedManifest() throws Exception {
BlazeAndroidDeployInfo deployInfo = new BlazeAndroidDeployInfo(stubManifest("test.package.name"), stubManifest(null), ImmutableList.of());
ApkBuildStep mockBuildStep = mock(ApkBuildStep.class);
when(mockBuildStep.getDeployInfo()).thenReturn(deployInfo);
BlazeAndroidTestApplicationIdProvider provider = new BlazeAndroidTestApplicationIdProvider(mockBuildStep);
try {
provider.getPackageName();
fail();
} catch (ApkProvisionException ex) {
// An exception should be thrown if the package name is not available because it's a
// serious error and should not fail silently. In this case we shouldn't fallback to
// the main package name, because the test package will be invalid as long as test
// manifest is missing package name.
}
}
use of com.google.idea.blaze.android.run.runner.ApkBuildStep in project intellij by bazelbuild.
the class BlazeAndroidTestApplicationIdProviderTest method getPackageName_noMergedManifest.
@Test
public void getPackageName_noMergedManifest() throws Exception {
BlazeAndroidDeployInfo deployInfo = new BlazeAndroidDeployInfo(stubManifest("test.package.name"), null, ImmutableList.of());
ApkBuildStep mockBuildStep = mock(ApkBuildStep.class);
when(mockBuildStep.getDeployInfo()).thenReturn(deployInfo);
BlazeAndroidTestApplicationIdProvider provider = new BlazeAndroidTestApplicationIdProvider(mockBuildStep);
assertThat(provider.getPackageName()).isEqualTo("test.package.name");
}
use of com.google.idea.blaze.android.run.runner.ApkBuildStep in project intellij by bazelbuild.
the class BlazeAndroidTestApplicationIdProviderTest method getTestPackageName_noPackageNameInMergedManifest.
@Test
public void getTestPackageName_noPackageNameInMergedManifest() throws Exception {
BlazeAndroidDeployInfo deployInfo = new BlazeAndroidDeployInfo(stubManifest(null), stubManifest("package.name"), ImmutableList.of());
ApkBuildStep mockBuildStep = mock(ApkBuildStep.class);
when(mockBuildStep.getDeployInfo()).thenReturn(deployInfo);
BlazeAndroidTestApplicationIdProvider provider = new BlazeAndroidTestApplicationIdProvider(mockBuildStep);
try {
provider.getTestPackageName();
fail();
} catch (ApkProvisionException ex) {
// An exception should be thrown if the package name is not available because it's a
// serious error and should not fail silently. In this case we shouldn't fallback to
// the main package name, because the test package will be invalid as long as test
// manifest is missing package name.
}
}
use of com.google.idea.blaze.android.run.runner.ApkBuildStep in project intellij by bazelbuild.
the class BlazeAndroidTestApplicationIdProviderTest method getTestPackageName.
@Test
public void getTestPackageName() throws Exception {
BlazeAndroidDeployInfo deployInfo = new BlazeAndroidDeployInfo(stubManifest("test.package.name"), stubManifest("package.name"), ImmutableList.of());
ApkBuildStep mockBuildStep = mock(ApkBuildStep.class);
when(mockBuildStep.getDeployInfo()).thenReturn(deployInfo);
BlazeAndroidTestApplicationIdProvider provider = new BlazeAndroidTestApplicationIdProvider(mockBuildStep);
assertThat(provider.getTestPackageName()).isEqualTo("test.package.name");
}
Aggregations