Search in sources :

Example 1 with ApkBuildStep

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);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeAndroidBinaryMobileInstallRunContext(com.google.idea.blaze.android.run.binary.mobileinstall.BlazeAndroidBinaryMobileInstallRunContext) BlazeAndroidRunConfigurationRunner(com.google.idea.blaze.android.run.runner.BlazeAndroidRunConfigurationRunner) BlazeAndroidRunContext(com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) ApkBuildStep(com.google.idea.blaze.android.run.runner.ApkBuildStep) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)

Example 2 with ApkBuildStep

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.
    }
}
Also used : ApkBuildStep(com.google.idea.blaze.android.run.runner.ApkBuildStep) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) Test(org.junit.Test)

Example 3 with ApkBuildStep

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");
}
Also used : ApkBuildStep(com.google.idea.blaze.android.run.runner.ApkBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) Test(org.junit.Test)

Example 4 with ApkBuildStep

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.
    }
}
Also used : ApkBuildStep(com.google.idea.blaze.android.run.runner.ApkBuildStep) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) Test(org.junit.Test)

Example 5 with ApkBuildStep

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");
}
Also used : ApkBuildStep(com.google.idea.blaze.android.run.runner.ApkBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) Test(org.junit.Test)

Aggregations

ApkBuildStep (com.google.idea.blaze.android.run.runner.ApkBuildStep)8 BlazeAndroidDeployInfo (com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo)7 Test (org.junit.Test)7 ApkProvisionException (com.android.tools.idea.run.ApkProvisionException)3 ParsedManifest (com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest)2 BlazeAndroidBinaryMobileInstallRunContext (com.google.idea.blaze.android.run.binary.mobileinstall.BlazeAndroidBinaryMobileInstallRunContext)1 BlazeAndroidRunConfigurationRunner (com.google.idea.blaze.android.run.runner.BlazeAndroidRunConfigurationRunner)1 BlazeAndroidRunContext (com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)1 ExecutionException (com.intellij.execution.ExecutionException)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1