debugger = debuggerService.getDebugger();
- return getConnectDebuggerTask(debugger, debugger.createState());
- }
- }
-
- @Nullable
- private ConnectDebuggerTask getConnectDebuggerTask(
- @NotNull AndroidDebugger debugger, @NotNull /* S */ AndroidDebuggerState debuggerState) {
- try {
- return runContext.getDebuggerTask(debugger, debuggerState);
- } catch (ExecutionException e) {
- LOG.warn("Cannot get debugger task", e);
- return null;
- }
- }
-
- @Override
- public String getLaunchTypeDisplayName() {
- return "Launch";
- }
-
- private boolean isNativeDebuggingEnabled(LaunchOptions launchOptions) {
- Object flag = launchOptions.getExtraOption(NATIVE_DEBUGGING_ENABLED);
- return flag instanceof Boolean && (Boolean) flag;
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/BlazeAndroidOpenProfilerWindowTask.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/BlazeAndroidOpenProfilerWindowTask.java
deleted file mode 100644
index 47a02f53f2c..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/BlazeAndroidOpenProfilerWindowTask.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.profilers.ProfilerProgramRunner;
-import com.android.tools.idea.run.tasks.LaunchContext;
-import com.android.tools.idea.run.tasks.LaunchResult;
-import com.android.tools.idea.run.tasks.LaunchTask;
-import com.android.tools.idea.run.tasks.LaunchTaskDurations;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.project.Project;
-
-/** Opens the profiler tool window. */
-public class BlazeAndroidOpenProfilerWindowTask implements LaunchTask {
- private static final String ID = "OPEN_PROFILER_TOOLWINDOW";
- private final Project project;
-
- public BlazeAndroidOpenProfilerWindowTask(Project project) {
- this.project = project;
- }
-
- @Override
- public String getDescription() {
- return "Open the Profiler Tool Window";
- }
-
- @Override
- public int getDuration() {
- return LaunchTaskDurations.LAUNCH_ACTIVITY;
- }
-
- @Override
- public String getId() {
- return ID;
- }
-
- @Override
- public LaunchResult run(LaunchContext launchContext) {
- ApplicationManager.getApplication()
- .invokeLater(() -> ProfilerProgramRunner.createProfilerToolWindow(project, null));
- return LaunchResult.success();
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/BlazeAndroidRunConfigurationRunner.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/BlazeAndroidRunConfigurationRunner.java
deleted file mode 100644
index 099f5694e73..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/BlazeAndroidRunConfigurationRunner.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.AndroidSessionInfo;
-import com.android.tools.idea.run.DeviceFutures;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.editor.DeployTarget;
-import com.android.tools.idea.run.editor.DeployTargetState;
-import com.android.tools.idea.run.util.LaunchUtils;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.idea.blaze.android.run.BlazeAndroidRunState;
-import com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator;
-import com.google.idea.blaze.base.command.BlazeInvocationContext.ContextType;
-import com.google.idea.blaze.base.experiments.ExperimentScope;
-import com.google.idea.blaze.base.issueparser.BlazeIssueParser;
-import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationRunner;
-import com.google.idea.blaze.base.scope.BlazeContext;
-import com.google.idea.blaze.base.scope.Scope;
-import com.google.idea.blaze.base.scope.ScopedTask;
-import com.google.idea.blaze.base.scope.output.IssueOutput;
-import com.google.idea.blaze.base.scope.scopes.IdeaLogScope;
-import com.google.idea.blaze.base.scope.scopes.ProblemsViewScope;
-import com.google.idea.blaze.base.scope.scopes.ToolWindowScope;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.settings.BlazeUserSettings;
-import com.google.idea.blaze.base.toolwindow.Task;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunProfileState;
-import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Key;
-import java.util.concurrent.CancellationException;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.android.util.AndroidBundle;
-
-/**
- * Supports the execution. Used by both android_binary and android_test.
- *
- * Builds the APK and installs it, launches and debug tasks, etc.
- *
- *
Any indirection between android_binary/android_test, mobile-install, InstantRun etc. should
- * come via the strategy class.
- */
-public final class BlazeAndroidRunConfigurationRunner
- implements BlazeCommandRunConfigurationRunner {
-
- private static final Logger LOG = Logger.getInstance(BlazeAndroidRunConfigurationRunner.class);
-
- private static final Key RUN_CONTEXT_KEY =
- Key.create("blaze.run.context");
- public static final Key DEVICE_SESSION_KEY =
- Key.create("blaze.device.session");
-
- private final Module module;
- private final BlazeAndroidRunContext runContext;
- private final BlazeCommandRunConfiguration runConfig;
-
- public BlazeAndroidRunConfigurationRunner(
- Module module, BlazeAndroidRunContext runContext, BlazeCommandRunConfiguration runConfig) {
- this.module = module;
- this.runContext = runContext;
- this.runConfig = runConfig;
- }
-
- @Override
- @Nullable
- public final RunProfileState getRunProfileState(final Executor executor, ExecutionEnvironment env)
- throws ExecutionException {
-
- final AndroidFacet facet = AndroidFacet.getInstance(module);
- assert facet != null : "Enforced by fatal validation check in createRunner.";
- final Project project = env.getProject();
-
- boolean isDebug = executor instanceof DefaultDebugExecutor;
- AndroidSessionInfo info =
- AndroidSessionInfo.findOldSession(project, null, runConfig, env.getExecutionTarget());
-
- BlazeAndroidDeviceSelector deviceSelector = runContext.getDeviceSelector();
- BlazeAndroidDeviceSelector.DeviceSession deviceSession =
- deviceSelector.getDevice(
- project, facet, executor, env, info, isDebug, runConfig.getUniqueID());
- if (deviceSession == null) {
- return null;
- }
-
- DeployTarget deployTarget = deviceSession.deployTarget;
- if (deployTarget != null && deployTarget.hasCustomRunProfileState(executor)) {
- return deployTarget.getRunProfileState(executor, env, DeployTargetState.DEFAULT_STATE);
- }
-
- DeviceFutures deviceFutures = deviceSession.deviceFutures;
- if (deviceFutures == null) {
- // The user deliberately canceled, or some error was encountered and exposed by the chooser.
- // Quietly exit.
- return null;
- }
-
- if (deviceFutures.get().isEmpty()) {
- throw new ExecutionException(AndroidBundle.message("deployment.target.not.found"));
- }
-
- if (isDebug) {
- String error = canDebug(deviceFutures, facet, module.getName());
- if (error != null) {
- throw new ExecutionException(error);
- }
- }
-
- LaunchOptions.Builder launchOptionsBuilder = getDefaultLaunchOptions().setDebug(isDebug);
- runContext.augmentLaunchOptions(launchOptionsBuilder);
-
- // Store the run context on the execution environment so before-run tasks can access it.
- env.putCopyableUserData(RUN_CONTEXT_KEY, runContext);
- env.putCopyableUserData(DEVICE_SESSION_KEY, deviceSession);
-
- return new BlazeAndroidRunState(env, launchOptionsBuilder, deviceSession, runContext);
- }
-
- @Nullable
- private static String canDebug(
- DeviceFutures deviceFutures, AndroidFacet facet, String moduleName) {
- // If we are debugging on a device, then the app needs to be debuggable
- for (ListenableFuture future : deviceFutures.get()) {
- if (!future.isDone()) {
- // this is an emulator, and we assume that all emulators are debuggable
- continue;
- }
- IDevice device = Futures.getUnchecked(future);
- if (!LaunchUtils.canDebugAppOnDevice(facet, device)) {
- return AndroidBundle.message(
- "android.cannot.debug.noDebugPermissions", moduleName, device.getName());
- }
- }
- return null;
- }
-
- private static LaunchOptions.Builder getDefaultLaunchOptions() {
- return LaunchOptionsCompat.getDefaultLaunchOptions();
- }
-
- @Override
- public boolean executeBeforeRunTask(ExecutionEnvironment env) {
- final Project project = env.getProject();
- BlazeUserSettings settings = BlazeUserSettings.getInstance();
- return Scope.root(
- context -> {
- context
- .push(new ProblemsViewScope(project, settings.getShowProblemsViewOnRun()))
- .push(new ExperimentScope())
- .push(
- new ToolWindowScope.Builder(
- project, new Task(project, "Build apk", Task.Type.BEFORE_LAUNCH))
- .setPopupBehavior(settings.getShowBlazeConsoleOnRun())
- .setIssueParsers(
- BlazeIssueParser.defaultIssueParsers(
- project,
- WorkspaceRoot.fromProject(project),
- ContextType.BeforeRunTask))
- .build())
- .push(new IdeaLogScope());
-
- BlazeAndroidRunContext runContext = env.getCopyableUserData(RUN_CONTEXT_KEY);
- if (runContext == null) {
- IssueOutput.error("Could not find run context. Please try again").submit(context);
- return false;
- }
- BlazeAndroidDeviceSelector.DeviceSession deviceSession =
- env.getCopyableUserData(DEVICE_SESSION_KEY);
-
- ApkBuildStep buildStep = runContext.getBuildStep();
- ScopedTask buildTask =
- new ScopedTask(context) {
- @Override
- protected Void execute(BlazeContext context) {
- buildStep.build(context, deviceSession);
- return null;
- }
- };
-
- try {
- ListenableFuture buildFuture =
- ProgressiveTaskWithProgressIndicator.builder(
- project,
- String.format("Executing %s apk build", Blaze.buildSystemName(project)))
- .submitTaskWithResult(buildTask);
- Futures.getChecked(buildFuture, ExecutionException.class);
- } catch (ExecutionException e) {
- context.setHasError();
- } catch (CancellationException e) {
- context.setCancelled();
- } catch (Exception e) {
- LOG.error(e);
- return false;
- }
- return context.shouldContinue();
- });
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/BlazeAndroidRunContext.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/BlazeAndroidRunContext.java
deleted file mode 100644
index a35a0cdaa46..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/BlazeAndroidRunContext.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsolePrinter;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.android.tools.idea.run.tasks.LaunchTask;
-import com.android.tools.idea.run.tasks.LaunchTasksProvider;
-import com.android.tools.idea.run.util.LaunchStatus;
-import com.google.common.collect.ImmutableList;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import javax.annotation.Nullable;
-import org.jetbrains.annotations.NotNull;
-
-/** Instantiated when the configuration wants to run. */
-public interface BlazeAndroidRunContext {
-
- BlazeAndroidDeviceSelector getDeviceSelector();
-
- void augmentLaunchOptions(LaunchOptions.Builder options);
-
- ConsoleProvider getConsoleProvider();
-
- ApkBuildStep getBuildStep();
-
- ApplicationIdProvider getApplicationIdProvider() throws ExecutionException;
-
- LaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException;
-
- /** Returns the tasks to deploy the application. */
- ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException;
-
- /** Returns the task to launch the application. */
- @Nullable
- LaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions,
- @Nullable Integer userId,
- @NotNull String contributorsAmStartOptions,
- LaunchStatus launchStatus)
- throws ExecutionException;
-
- /** Returns the task to connect the debugger. */
- @Nullable
- ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState)
- throws ExecutionException;
-
- @Nullable
- Integer getUserId(IDevice device, ConsolePrinter consolePrinter) throws ExecutionException;
-
- String getAmStartOptions();
-
- Executor getExecutor();
-
- ProfilerState getProfileState();
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/CheckApkDebuggableTask.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/CheckApkDebuggableTask.java
deleted file mode 100644
index e912e81538c..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/CheckApkDebuggableTask.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import static com.google.common.collect.ImmutableList.toImmutableList;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.run.ConsolePrinter;
-import com.android.tools.idea.run.tasks.LaunchContext;
-import com.android.tools.idea.run.tasks.LaunchResult;
-import com.android.tools.idea.run.tasks.LaunchTask;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableList;
-import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceFile;
-import com.google.devrel.gmscore.tools.apk.arsc.Chunk;
-import com.google.devrel.gmscore.tools.apk.arsc.XmlAttribute;
-import com.google.devrel.gmscore.tools.apk.arsc.XmlChunk;
-import com.google.devrel.gmscore.tools.apk.arsc.XmlStartElementChunk;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.zip.ZipFile;
-import org.jetbrains.annotations.NotNull;
-
-/** Checks APKs to see if they are debuggable and warn the user if they aren't. */
-public class CheckApkDebuggableTask implements LaunchTask {
- private static final String ID = "APK_DEBUGGABILITY_CHECKER";
- private final BlazeAndroidDeployInfo deployInfo;
-
- public CheckApkDebuggableTask(BlazeAndroidDeployInfo deployInfo) {
- this.deployInfo = deployInfo;
- }
-
- @Override
- public String getDescription() {
- return "Checking debug attribute in APKs";
- }
-
- @Override
- public int getDuration() {
- return 2; // See com.android.tools.idea.run.tasks.LaunchTaskDurations for related magic numbers.
- }
-
- @Override
- public String getId() {
- return ID;
- }
-
- @Override
- public LaunchResult run(@NotNull LaunchContext launchContext) {
- checkApkDebuggableTaskDelegate(
- deployInfo, launchContext.getDevice(), launchContext.getConsolePrinter());
- return LaunchResult.success(); // Don't block deployment.
- }
-
- /**
- * Checks if all APKs in the deploy info are debuggable and output an error message to console if
- * any of them aren't. This check doesn't apply if the target device is a running a debug build
- * android (e.g. userdebug build) and will simply return.
- */
- @VisibleForTesting
- public static void checkApkDebuggableTaskDelegate(
- BlazeAndroidDeployInfo deployInfo, IDevice device, ConsolePrinter consolePrinter) {
- if (isDebugDevice(device)) {
- return;
- }
- try {
- ImmutableList nonDebuggableApkNames =
- getNonDebuggableDeployApks(deployInfo).stream()
- .map(File::getName)
- .collect(toImmutableList());
- if (nonDebuggableApkNames.isEmpty()) {
- return;
- }
- // Use "and" as delimiter because there won't be more than 2 APKs, so "and" makes more sense.
- String message =
- "The \"android:debuggable\" attribute is not set to \"true\" in "
- + String.join(" and ", nonDebuggableApkNames)
- + ". Debugger may not attach properly or attach at all."
- + " Please ensure \"android:debuggable\" attribute is set to true or"
- + " overridden to true via manifest overrides.";
- consolePrinter.stderr(message);
- } catch (IOException e) {
- consolePrinter.stderr("Could not read deploy apks: " + e.getMessage());
- }
- }
-
- private static ImmutableList getNonDebuggableDeployApks(BlazeAndroidDeployInfo deployInfo)
- throws IOException {
- ImmutableList.Builder nonDebuggableApks = ImmutableList.builder();
- for (File apk : deployInfo.getApksToDeploy()) {
- if (!isApkDebuggable(apk)) {
- nonDebuggableApks.add(apk);
- }
- }
- return nonDebuggableApks.build();
- }
-
- /** Returns true if the device is a debug build device. */
- private static boolean isDebugDevice(IDevice device) {
- String roDebuggable = device.getProperty("ro.debuggable");
- return (roDebuggable != null && roDebuggable.equals("1"));
- }
-
- @VisibleForTesting
- public static boolean isApkDebuggable(File apk) throws IOException {
- try (ZipFile zipFile = new ZipFile(apk);
- InputStream stream = zipFile.getInputStream(zipFile.getEntry("AndroidManifest.xml"))) {
- BinaryResourceFile file = BinaryResourceFile.fromInputStream(stream);
- List chunks = file.getChunks();
-
- if (chunks.isEmpty()) {
- throw new IllegalArgumentException("Invalid APK, empty manifest");
- }
-
- if (!(chunks.get(0) instanceof XmlChunk)) {
- throw new IllegalArgumentException("APK manifest chunk[0] != XmlChunk");
- }
-
- XmlChunk xmlChunk = (XmlChunk) chunks.get(0);
- for (Chunk chunk : xmlChunk.getChunks().values()) {
- if (!(chunk instanceof XmlStartElementChunk)) {
- continue;
- }
-
- XmlStartElementChunk startChunk = (XmlStartElementChunk) chunk;
- if (startChunk.getName().equals("application")) {
- for (XmlAttribute attribute : startChunk.getAttributes()) {
- if (attribute.name().equals("debuggable")) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/LaunchOptionsCompat.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/LaunchOptionsCompat.java
deleted file mode 100644
index 5a606a8a2ea..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/runner/LaunchOptionsCompat.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.run.LaunchOptions;
-
-/** Compat class for LunchOptions.Builder. */
-public class LaunchOptionsCompat {
-
- private LaunchOptionsCompat() {}
-
- /** Create default launch options to maintain compatibility with #api211. */
- public static LaunchOptions.Builder getDefaultLaunchOptions() {
- return LaunchOptions.builder().setClearLogcatBeforeStart(false);
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestLaunchTask.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestLaunchTask.java
deleted file mode 100644
index 3e4fbaed099..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestLaunchTask.java
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.tools.idea.run.ConsolePrinter;
-import com.android.tools.idea.run.tasks.LaunchContext;
-import com.android.tools.idea.run.tasks.LaunchResult;
-import com.android.tools.idea.run.tasks.LaunchTask;
-import com.android.tools.idea.run.tasks.LaunchTaskDurations;
-import com.android.tools.idea.run.util.LaunchStatus;
-import com.android.tools.idea.run.util.ProcessHandlerLaunchStatus;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.idea.blaze.base.async.executor.BlazeExecutor;
-import com.google.idea.blaze.base.async.process.ExternalTask;
-import com.google.idea.blaze.base.async.process.LineProcessingOutputStream;
-import com.google.idea.blaze.base.command.BlazeCommand;
-import com.google.idea.blaze.base.command.BlazeCommandName;
-import com.google.idea.blaze.base.command.BlazeFlags;
-import com.google.idea.blaze.base.command.buildresult.BuildResultHelper;
-import com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException;
-import com.google.idea.blaze.base.command.buildresult.BuildResultHelperBep;
-import com.google.idea.blaze.base.filecache.FileCaches;
-import com.google.idea.blaze.base.ideinfo.AndroidInstrumentationInfo;
-import com.google.idea.blaze.base.ideinfo.TargetIdeInfo;
-import com.google.idea.blaze.base.ideinfo.TargetKey;
-import com.google.idea.blaze.base.model.BlazeProjectData;
-import com.google.idea.blaze.base.model.primitives.Label;
-import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
-import com.google.idea.blaze.base.projectview.ProjectViewManager;
-import com.google.idea.blaze.base.projectview.ProjectViewSet;
-import com.google.idea.blaze.base.run.testlogs.BlazeTestResultHolder;
-import com.google.idea.blaze.base.scope.Scope;
-import com.google.idea.blaze.base.scope.output.IssueOutput;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs;
-import com.google.idea.blaze.base.sync.aspects.BuildResult;
-import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
-import com.google.idea.blaze.base.util.SaveUtil;
-import com.google.idea.blaze.java.AndroidBlazeRules.RuleTypes;
-import com.intellij.execution.process.ProcessAdapter;
-import com.intellij.execution.process.ProcessEvent;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.ExecutionException;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.ide.PooledThreadExecutor;
-
-/**
- * An Android application launcher that invokes `blaze test` on an android_test target, and sets up
- * process handling and debugging for the test run.
- */
-public class BlazeAndroidTestLaunchTask implements LaunchTask {
- private static final String ID = "BLAZE_ANDROID_TEST";
-
- // Uses a local device/emulator attached to adb to run an android_test.
- public static final String TEST_LOCAL_DEVICE =
- BlazeFlags.TEST_ARG + "--device_broker_type=LOCAL_ADB_SERVER";
- // Uses a local device/emulator attached to adb to run an android_test.
- public static final String TEST_DEBUG = BlazeFlags.TEST_ARG + "--enable_debug";
- // Specifies the serial number for a local test device.
- private static final String TEST_DEVICE_SERIAL = "--device_serial_number=";
- private static final Logger LOG = Logger.getInstance(BlazeAndroidTestLaunchTask.class);
-
- private final Project project;
- private final Label target;
- private final List buildFlags;
- private final BlazeAndroidTestFilter testFilter;
- private final BlazeTestResultHolder testResultsHolder;
-
- private ListenableFuture blazeResult;
-
- private final BlazeAndroidTestRunContext runContext;
-
- private final boolean debug;
-
- public BlazeAndroidTestLaunchTask(
- Project project,
- Label target,
- List buildFlags,
- BlazeAndroidTestFilter testFilter,
- BlazeAndroidTestRunContext runContext,
- boolean debug,
- BlazeTestResultHolder testResultsHolder) {
- this.project = project;
- this.target = target;
- this.buildFlags = buildFlags;
- this.testFilter = testFilter;
- this.runContext = runContext;
- this.debug = debug;
- this.testResultsHolder = testResultsHolder;
- }
-
- @NotNull
- @Override
- public String getDescription() {
- return String.format("Running %s tests", Blaze.buildSystemName(project));
- }
-
- @Override
- public int getDuration() {
- return LaunchTaskDurations.LAUNCH_ACTIVITY;
- }
-
- @Override
- public LaunchResult run(@NotNull LaunchContext launchContext) {
- BlazeExecutor blazeExecutor = BlazeExecutor.getInstance();
-
- ProcessHandlerLaunchStatus processHandlerLaunchStatus =
- (ProcessHandlerLaunchStatus) launchContext.getLaunchStatus();
- final ProcessHandler processHandler = processHandlerLaunchStatus.getProcessHandler();
-
- blazeResult =
- blazeExecutor.submit(
- () ->
- Scope.root(
- context -> {
- SaveUtil.saveAllFiles();
-
- ProjectViewSet projectViewSet =
- ProjectViewManager.getInstance(project).getProjectViewSet();
- if (projectViewSet == null) {
- IssueOutput.error("Could not load project view. Please resync project.")
- .submit(context);
- return false;
- }
-
- BlazeProjectData projectData =
- BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
- TargetIdeInfo targetInfo =
- projectData.getTargetMap().get(TargetKey.forPlainTarget(target));
- if (targetInfo == null
- || targetInfo.getKind()
- != RuleTypes.ANDROID_INSTRUMENTATION_TEST.getKind()) {
- IssueOutput.error(
- "Unable to identify target \""
- + target
- + "\". If this is a newly added target, please sync the"
- + " project and try again.")
- .submit(context);
- return null;
- }
- AndroidInstrumentationInfo testInstrumentationInfo =
- targetInfo.getAndroidInstrumentationInfo();
- if (testInstrumentationInfo == null) {
- IssueOutput.error(
- "Required target data missing for \""
- + target
- + "\". Has the target definition changed recently? Please"
- + " sync the project and try again.")
- .submit(context);
- return null;
- }
-
- BlazeCommand.Builder commandBuilder =
- BlazeCommand.builder(
- Blaze.getBuildSystemProvider(project)
- .getBuildSystem()
- .getBuildInvoker(project, context),
- BlazeCommandName.TEST)
- .addTargets(target);
- // Build flags must match BlazeBeforeRunTask.
- commandBuilder.addBlazeFlags(buildFlags);
-
- // Run the test on the selected local device/emulator if no target device is
- // specified.
- Label targetDevice = testInstrumentationInfo.getTargetDevice();
- if (targetDevice == null) {
- commandBuilder
- .addBlazeFlags(TEST_LOCAL_DEVICE, BlazeFlags.TEST_OUTPUT_STREAMED)
- .addBlazeFlags(
- testDeviceSerialFlags(launchContext.getDevice().getSerialNumber()))
- .addBlazeFlags(testFilter.getBlazeFlags());
- }
-
- if (debug) {
- commandBuilder.addBlazeFlags(TEST_DEBUG, BlazeFlags.NO_CACHE_TEST_RESULTS);
- }
-
- ConsolePrinter printer = launchContext.getConsolePrinter();
- LineProcessingOutputStream.LineProcessor stdoutLineProcessor =
- line -> {
- printer.stdout(line);
- return true;
- };
- LineProcessingOutputStream.LineProcessor stderrLineProcessor =
- line -> {
- printer.stderr(line);
- return true;
- };
-
- printer.stdout(
- String.format("Starting %s test...\n", Blaze.buildSystemName(project)));
-
- int retVal;
- try (BuildResultHelper buildResultHelper = new BuildResultHelperBep()) {
- commandBuilder.addBlazeFlags(buildResultHelper.getBuildFlags());
- BlazeCommand command = commandBuilder.build();
- printer.stdout(command + "\n");
-
- retVal =
- ExternalTask.builder(WorkspaceRoot.fromProject(project))
- .addBlazeCommand(command)
- .context(context)
- .stdout(LineProcessingOutputStream.of(stdoutLineProcessor))
- .stderr(LineProcessingOutputStream.of(stderrLineProcessor))
- .build()
- .run();
-
- if (retVal != 0) {
- context.setHasError();
- } else {
- testResultsHolder.setTestResults(
- buildResultHelper.getTestResults(Optional.empty()));
- }
- ListenableFuture unusedFuture =
- FileCaches.refresh(
- project,
- context,
- BlazeBuildOutputs.noOutputs(BuildResult.fromExitCode(retVal)));
- } catch (GetArtifactsException e) {
- LOG.error(e.getMessage());
- }
- return !context.hasErrors();
- }));
-
- blazeResult.addListener(runContext::onLaunchTaskComplete, PooledThreadExecutor.INSTANCE);
-
- // The debug case is set up in ConnectBlazeTestDebuggerTask
- if (!debug) {
- waitAndSetUpForKillingBlazeOnStop(processHandler, launchContext.getLaunchStatus());
- }
- return LaunchResult.success();
- }
-
- @NotNull
- @Override
- public String getId() {
- return ID;
- }
-
- /**
- * Hooks up the Blaze process to be killed if the user hits the 'Stop' button, then waits for the
- * Blaze process to stop. In non-debug mode, we wait for test execution to finish before returning
- * from launch() (this matches the behavior of the stock ddmlib runner).
- */
- @SuppressWarnings("Interruption")
- private void waitAndSetUpForKillingBlazeOnStop(
- @NotNull final ProcessHandler processHandler, @NotNull final LaunchStatus launchStatus) {
- processHandler.addProcessListener(
- new ProcessAdapter() {
- @Override
- public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
- blazeResult.cancel(true /* mayInterruptIfRunning */);
- launchStatus.terminateLaunch("Test run stopped.\n", true);
- }
- });
-
- try {
- blazeResult.get();
- launchStatus.terminateLaunch("Tests ran to completion.\n", true);
- } catch (CancellationException e) {
- // The user has canceled the test.
- launchStatus.terminateLaunch("Test run stopped.\n", true);
- } catch (InterruptedException e) {
- // We've been interrupted - cancel the underlying Blaze process.
- blazeResult.cancel(true /* mayInterruptIfRunning */);
- launchStatus.terminateLaunch("Test run stopped.\n", true);
- } catch (ExecutionException e) {
- LOG.error(e);
- launchStatus.terminateLaunch(
- "Test run stopped due to internal exception. Please file a bug report.\n", true);
- }
- }
-
- @NotNull
- private static String testDeviceSerialFlags(@NotNull String serial) {
- return BlazeFlags.TEST_ARG + TEST_DEVICE_SERIAL + serial;
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestProgramRunner.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestProgramRunner.java
deleted file mode 100644
index 024033c74af..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestProgramRunner.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.tools.idea.execution.common.AndroidSessionInfo;
-import com.android.tools.idea.run.AndroidProgramRunner;
-import com.android.tools.idea.run.AndroidSessionInfoCompat;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.ExecutionResult;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.configurations.RunProfile;
-import com.intellij.execution.configurations.RunProfileState;
-import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.executors.DefaultRunExecutor;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.runners.RunContentBuilder;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.fileEditor.FileDocumentManager;
-
-/** Program runner for configurations from {@link BlazeAndroidTestRunConfigurationHandler}. */
-public class BlazeAndroidTestProgramRunner extends AndroidProgramRunner {
- @Override
- public boolean canRun(String executorId, RunProfile profile) {
- BlazeAndroidRunConfigurationHandler handler =
- BlazeAndroidRunConfigurationHandler.getHandlerFrom(profile);
- if (!(handler instanceof BlazeAndroidTestRunConfigurationHandler)) {
- return false;
- }
- if (!(profile instanceof BlazeCommandRunConfiguration)) {
- return false;
- }
- return DefaultRunExecutor.EXECUTOR_ID.equals(executorId)
- || DefaultDebugExecutor.EXECUTOR_ID.equals(executorId);
- }
-
- @Override
- protected boolean canRunWithMultipleDevices(String executorId) {
- return false;
- }
-
- @Override
- protected RunContentDescriptor doExecute(
- final RunProfileState state, final ExecutionEnvironment env) throws ExecutionException {
- FileDocumentManager.getInstance().saveAllDocuments();
- ExecutionResult result = state.execute(env.getExecutor(), this);
- RunContentDescriptor descriptor =
- new RunContentBuilder(result, env).showRunContent(env.getContentToReuse());
- if (descriptor != null) {
- ProcessHandler processHandler = descriptor.getProcessHandler();
- assert processHandler != null;
- RunProfile runProfile = env.getRunProfile();
- RunConfiguration runConfiguration =
- (runProfile instanceof RunConfiguration) ? (RunConfiguration) runProfile : null;
- AndroidSessionInfo sessionInfo =
- AndroidSessionInfoCompat.create(
- processHandler,
- descriptor,
- runConfiguration,
- env.getExecutor().getId(),
- env.getExecutor().getActionName(),
- env.getExecutionTarget());
- processHandler.putUserData(AndroidSessionInfo.KEY, sessionInfo);
- }
- return descriptor;
- }
-
- @Override
- public String getRunnerId() {
- return "AndroidTestProgramRunner";
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunConfigurationHandler.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunConfigurationHandler.java
deleted file mode 100644
index 050ddc03fee..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunConfigurationHandler.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import static com.android.tools.idea.run.deployment.DeviceAndSnapshotComboBoxAction.DEPLOYS_TO_LOCAL_DEVICE;
-
-import com.android.tools.idea.run.ValidationError;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.idea.blaze.android.run.ApkBuildStepProvider;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationCommonState;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationValidationUtil;
-import com.google.idea.blaze.android.run.LaunchMetrics;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunConfigurationRunner;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.google.idea.blaze.android.run.runner.FullApkBuildStep;
-import com.google.idea.blaze.android.run.test.BlazeAndroidTestLaunchMethodsProvider.AndroidTestLaunchMethod;
-import com.google.idea.blaze.base.command.BlazeCommandName;
-import com.google.idea.blaze.base.command.BlazeInvocationContext;
-import com.google.idea.blaze.base.model.primitives.Label;
-import com.google.idea.blaze.base.model.primitives.TargetExpression;
-import com.google.idea.blaze.base.projectview.ProjectViewManager;
-import com.google.idea.blaze.base.projectview.ProjectViewSet;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder;
-import com.google.idea.blaze.base.run.ExecutorType;
-import com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationRunner;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.sync.data.BlazeDataStorage;
-import com.google.idea.blaze.base.sync.projectstructure.ModuleFinder;
-import com.google.idea.blaze.java.AndroidBlazeRules;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.JavaExecutionUtil;
-import com.intellij.execution.configurations.RuntimeConfigurationException;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/**
- * {@link com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationHandler} for
- * android_test targets.
- */
-public class BlazeAndroidTestRunConfigurationHandler
- implements BlazeAndroidRunConfigurationHandler {
- private final Project project;
- private final BlazeAndroidTestRunConfigurationState configState;
-
- BlazeAndroidTestRunConfigurationHandler(BlazeCommandRunConfiguration configuration) {
- this.project = configuration.getProject();
- this.configState =
- new BlazeAndroidTestRunConfigurationState(
- Blaze.buildSystemName(configuration.getProject()));
- configuration.putUserData(DEPLOYS_TO_LOCAL_DEVICE, true);
- }
-
- @Override
- public BlazeAndroidTestRunConfigurationState getState() {
- return configState;
- }
-
- @Override
- public BlazeAndroidRunConfigurationCommonState getCommonState() {
- return configState.getCommonState();
- }
-
- @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();
-
- ImmutableList blazeFlags =
- configState
- .getCommonState()
- .getExpandedBuildFlags(
- project,
- projectViewSet,
- BlazeCommandName.TEST,
- BlazeInvocationContext.runConfigContext(
- ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), false));
- ImmutableList exeFlags =
- ImmutableList.copyOf(
- configState.getCommonState().getExeFlagsState().getFlagsForExternalProcesses());
-
- // 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();
- Label label = Label.create(configuration.getSingleTarget().toString());
-
- ApkBuildStep buildStep =
- getTestBuildStep(
- project, configState, configuration, blazeFlags, exeFlags, launchId, label);
-
- BlazeAndroidRunContext runContext =
- new BlazeAndroidTestRunContext(
- project, facet, configuration, env, configState, label, blazeFlags, buildStep);
-
- LaunchMetrics.logTestLaunch(
- launchId, configState.getLaunchMethod().name(), env.getExecutor().getId());
-
- return new BlazeAndroidRunConfigurationRunner(module, runContext, configuration);
- }
-
- private static ApkBuildStep getTestBuildStep(
- Project project,
- BlazeAndroidTestRunConfigurationState configState,
- BlazeCommandRunConfiguration configuration,
- ImmutableList blazeFlags,
- ImmutableList exeFlags,
- String launchId,
- Label label)
- throws ExecutionException {
- if (configuration.getTargetKind()
- == AndroidBlazeRules.RuleTypes.ANDROID_INSTRUMENTATION_TEST.getKind()) {
- boolean useMobileInstall =
- AndroidTestLaunchMethod.MOBILE_INSTALL.equals(configState.getLaunchMethod());
- return ApkBuildStepProvider.getInstance(Blaze.getBuildSystemName(project))
- .getAitBuildStep(
- project,
- useMobileInstall,
- /* nativeDebuggingEnabled= */ false,
- label,
- blazeFlags,
- exeFlags,
- launchId);
- } else {
- // TODO(b/248317444): This path is only invoked for the deprecated {@code android_test}
- // targets, and should eventually be removed.
- return new FullApkBuildStep(project, label, blazeFlags, /* nativeDebuggingEnabled= */ false);
- }
- }
-
- @Override
- public final void checkConfiguration() throws RuntimeConfigurationException {
- BlazeAndroidRunConfigurationValidationUtil.throwTopConfigurationError(validate());
- }
-
- /**
- * We collect errors rather than throwing to avoid missing fatal errors by exiting early for a
- * warning. We use a separate method for the collection so the compiler prevents us from
- * accidentally throwing.
- */
- private List validate() {
- List errors = Lists.newArrayList();
- errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateWorkspaceModule(project));
- errors.addAll(configState.validate(project));
- return errors;
- }
-
- @Override
- @Nullable
- public String suggestedName(BlazeCommandRunConfiguration configuration) {
- TargetExpression target = configuration.getSingleTarget();
- if (target == null) {
- return null;
- }
- BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
-
- boolean isClassTest =
- configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_CLASS;
- boolean isMethodTest =
- configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_METHOD;
- if ((isClassTest || isMethodTest) && configState.getClassName() != null) {
- // Get the class name without the package.
- String className = JavaExecutionUtil.getPresentableClassName(configState.getClassName());
- if (className != null) {
- String targetString = className;
- if (isMethodTest) {
- targetString += "#" + configState.getMethodName();
- }
-
- if (getState().getLaunchMethod().equals(AndroidTestLaunchMethod.NON_BLAZE)) {
- return targetString;
- } else {
- return nameBuilder.setTargetString(targetString).build();
- }
- }
- }
- return nameBuilder.build();
- }
-
- @Override
- @Nullable
- public BlazeCommandName getCommandName() {
- if (getState().getLaunchMethod().equals(AndroidTestLaunchMethod.BLAZE_TEST)) {
- return BlazeCommandName.TEST;
- } else if (getState().getLaunchMethod().equals(AndroidTestLaunchMethod.MOBILE_INSTALL)) {
- return BlazeCommandName.MOBILE_INSTALL;
- }
- return null;
- }
-
- @Override
- public String getHandlerName() {
- return "Android Test Handler";
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunContext.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunContext.java
deleted file mode 100644
index 9701159d71a..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunContext.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-import static com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryNormalBuildRunContextBase.getApkInfoToInstall;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApkProvider;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsolePrinter;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.android.tools.idea.run.tasks.LaunchTask;
-import com.android.tools.idea.run.tasks.LaunchTasksProvider;
-import com.android.tools.idea.run.util.LaunchStatus;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.idea.blaze.android.run.BlazeAndroidDeploymentService;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.deployinfo.BlazeApkProviderService;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.google.idea.blaze.android.run.test.BlazeAndroidTestLaunchMethodsProvider.AndroidTestLaunchMethod;
-import com.google.idea.blaze.base.model.primitives.Label;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.smrunner.BlazeTestUiSession;
-import com.google.idea.blaze.base.run.testlogs.BlazeTestResultHolder;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Run context for android_test. */
-public class BlazeAndroidTestRunContext implements BlazeAndroidRunContext {
- protected final Project project;
- protected final AndroidFacet facet;
- protected final BlazeCommandRunConfiguration runConfiguration;
- protected final ExecutionEnvironment env;
- protected final BlazeAndroidTestRunConfigurationState configState;
- protected final Label label;
- protected final ImmutableList blazeFlags;
- protected final List launchTaskCompleteListeners = Lists.newArrayList();
- protected final ConsoleProvider consoleProvider;
- protected final ApkBuildStep buildStep;
- protected final ApplicationIdProvider applicationIdProvider;
- protected final ApkProvider apkProvider;
- private final BlazeTestResultHolder testResultsHolder = new BlazeTestResultHolder();
-
- public BlazeAndroidTestRunContext(
- Project project,
- AndroidFacet facet,
- BlazeCommandRunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidTestRunConfigurationState configState,
- Label label,
- ImmutableList blazeFlags,
- ApkBuildStep buildStep) {
- this.project = project;
- this.facet = facet;
- this.runConfiguration = runConfiguration;
- this.env = env;
- this.label = label;
- this.configState = configState;
- this.buildStep = buildStep;
- this.blazeFlags = blazeFlags;
-
- switch (configState.getLaunchMethod()) {
- case MOBILE_INSTALL:
- case NON_BLAZE:
- consoleProvider = new AitIdeTestConsoleProvider(runConfiguration, configState);
- break;
- case BLAZE_TEST:
- BlazeTestUiSession session =
- BlazeTestUiSession.create(ImmutableList.of(), testResultsHolder);
- this.consoleProvider = new AitBlazeTestConsoleProvider(project, runConfiguration, session);
- break;
- default:
- throw new IllegalStateException(
- "Unsupported launch method " + configState.getLaunchMethod());
- }
-
- applicationIdProvider = new BlazeAndroidTestApplicationIdProvider(buildStep);
- apkProvider = BlazeApkProviderService.getInstance().getApkProvider(project, buildStep);
- }
-
- @Override
- public BlazeAndroidDeviceSelector getDeviceSelector() {
- return new BlazeAndroidDeviceSelector.NormalDeviceSelector();
- }
-
- @Override
- public void augmentLaunchOptions(LaunchOptions.Builder options) {
- options.setDeploy(!configState.getLaunchMethod().equals(AndroidTestLaunchMethod.BLAZE_TEST));
- }
-
- @Override
- public ConsoleProvider getConsoleProvider() {
- return consoleProvider;
- }
-
- @Override
- public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
- return applicationIdProvider;
- }
-
- @Nullable
- @Override
- public ApkBuildStep getBuildStep() {
- return buildStep;
- }
-
- @Override
- public ProfilerState getProfileState() {
- return null;
- }
-
- @Override
- public LaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder) {
- return new BlazeAndroidLaunchTasksProvider(
- project, this, applicationIdProvider, launchOptionsBuilder);
- }
-
- @Override
- public ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException {
- if (configState.getLaunchMethod() != AndroidTestLaunchMethod.NON_BLAZE) {
- return ImmutableList.of();
- }
-
- return ImmutableList.of(
- BlazeAndroidDeploymentService.getInstance(project)
- .getDeployTask(getApkInfoToInstall(device, launchOptions, apkProvider), launchOptions));
- }
-
- @Override
- @Nullable
- public LaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions,
- @Nullable Integer userId,
- String contributorsAmStartOptions,
- LaunchStatus launchStatus)
- throws ExecutionException {
- switch (configState.getLaunchMethod()) {
- case BLAZE_TEST:
- BlazeAndroidTestFilter testFilter =
- new BlazeAndroidTestFilter(
- configState.getTestingType(),
- configState.getClassName(),
- configState.getMethodName(),
- configState.getPackageName());
- return new BlazeAndroidTestLaunchTask(
- project,
- label,
- blazeFlags,
- testFilter,
- this,
- launchOptions.isDebug(),
- testResultsHolder);
- case NON_BLAZE:
- case MOBILE_INSTALL:
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
- return StockAndroidTestLaunchTask.getStockTestLaunchTask(
- configState, applicationIdProvider, launchOptions.isDebug(), deployInfo, launchStatus);
- }
- throw new AssertionError();
- }
-
- @Override
- @SuppressWarnings({"unchecked", "rawtypes"}) // Raw type from upstream.
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState)
- throws ExecutionException {
- switch (configState.getLaunchMethod()) {
- case BLAZE_TEST:
- return new ConnectBlazeTestDebuggerTask(this, androidDebugger, androidDebuggerState);
- case NON_BLAZE:
- case MOBILE_INSTALL:
- return getBaseDebuggerTask(
- androidDebugger, androidDebuggerState, env, facet, applicationIdProvider);
- }
- throw new AssertionError();
- }
-
- void onLaunchTaskComplete() {
- for (Runnable runnable : launchTaskCompleteListeners) {
- runnable.run();
- }
- }
-
- void addLaunchTaskCompleteListener(Runnable runnable) {
- launchTaskCompleteListeners.add(runnable);
- }
-
- @Override
- public Executor getExecutor() {
- return env.getExecutor();
- }
-
- @Nullable
- @Override
- public Integer getUserId(IDevice device, ConsolePrinter consolePrinter) {
- return null;
- }
-
- @Override
- public String getAmStartOptions() {
- return "";
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/ConnectBlazeTestDebuggerTask.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/ConnectBlazeTestDebuggerTask.java
deleted file mode 100644
index 06a644fb496..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/ConnectBlazeTestDebuggerTask.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.execution.common.debug.DebugSessionStarter;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.process.ProcessOutputTypes;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.runners.ExecutionUtil;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.wm.ToolWindowId;
-import com.intellij.xdebugger.impl.XDebugSessionImpl;
-import java.io.OutputStream;
-import java.util.function.Function;
-import kotlin.Unit;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.concurrency.Promise;
-
-/** Connects the blaze debugger during execution. */
-class ConnectBlazeTestDebuggerTask implements ConnectDebuggerTask {
- private static final Logger LOG = Logger.getInstance(ConnectBlazeTestDebuggerTask.class);
-
- private final BlazeAndroidTestRunContext runContext;
- private final AndroidDebugger myAndroidDebugger;
- private final S myAndroidDebuggerState;
-
- public ConnectBlazeTestDebuggerTask(
- BlazeAndroidTestRunContext runContext,
- AndroidDebugger androidDebugger,
- S androidDebuggerState) {
- this.runContext = runContext;
- myAndroidDebugger = androidDebugger;
- myAndroidDebuggerState = androidDebuggerState;
- }
-
- /**
- * Wires up listeners to automatically reconnect the debugger for each test method. When you
- * `blaze test` an android_test in debug mode, it kills the instrumentation process between each
- * test method, disconnecting the debugger. We listen for the start of a new method waiting for a
- * debugger, and reconnect. TODO: Support stopping Blaze from the UI. This is hard because we have
- * no way to distinguish process handler termination/debug session ending initiated by the user.
- *
- * @return Promise with debug session or error
- */
- @Override
- public @NotNull Promise perform(
- @NotNull IDevice device,
- @NotNull String applicationId,
- @NotNull ExecutionEnvironment environment,
- @NotNull ProcessHandler oldProcessHandler) {
- final ProcessHandler masterProcessHandler =
- new ProcessHandler() {
-
- @Override
- protected void destroyProcessImpl() {
- notifyProcessTerminated(0);
- }
-
- @Override
- protected void detachProcessImpl() {
- notifyProcessDetached();
- }
-
- @Override
- public boolean detachIsDefault() {
- return false;
- }
-
- @Override
- public @Nullable OutputStream getProcessInput() {
- return null;
- }
- };
- Promise debugSessionPromise =
- DebugSessionStarter.INSTANCE
- .attachReattachingDebuggerToStartedProcess(
- device,
- applicationId,
- masterProcessHandler,
- environment,
- myAndroidDebugger,
- myAndroidDebuggerState,
- /* destroyRunningProcess= */ x -> Unit.INSTANCE,
- null,
- Long.MAX_VALUE)
- .onSuccess(
- session -> {
- oldProcessHandler.detachProcess();
- session.showSessionTab();
- })
- .onError(
- it -> {
- if (it instanceof ExecutionException) {
- ExecutionUtil.handleExecutionError(
- environment.getProject(),
- ToolWindowId.DEBUG,
- it,
- "Error running " + environment.getRunProfile().getName(),
- it.getMessage(),
- Function.identity(),
- null);
- } else {
- Logger.getInstance(this.getClass()).error(it);
- }
- });
-
- runContext.addLaunchTaskCompleteListener(
- () -> {
- masterProcessHandler.notifyTextAvailable(
- "Test run completed.\n", ProcessOutputTypes.STDOUT);
- masterProcessHandler.detachProcess();
- });
- return debugSessionPromise;
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/StockAndroidTestLaunchTask.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/StockAndroidTestLaunchTask.java
deleted file mode 100644
index d557d37b010..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/run/test/StockAndroidTestLaunchTask.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
-import com.android.tools.idea.execution.common.processhandler.AndroidProcessHandler;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsolePrinter;
-import com.android.tools.idea.run.tasks.LaunchContext;
-import com.android.tools.idea.run.tasks.LaunchResult;
-import com.android.tools.idea.run.tasks.LaunchTask;
-import com.android.tools.idea.run.util.LaunchStatus;
-import com.android.tools.idea.testartifacts.instrumented.AndroidTestListener;
-import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.android.manifest.ManifestParser;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.util.Computable;
-import com.intellij.openapi.util.text.StringUtil;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.jetbrains.annotations.NotNull;
-
-class StockAndroidTestLaunchTask implements LaunchTask {
- private static final String ID = "STOCK_ANDROID_TEST";
-
- private static final Logger LOG = Logger.getInstance(StockAndroidTestLaunchTask.class);
-
- private final BlazeAndroidTestRunConfigurationState configState;
- private final String instrumentationTestRunner;
- private final String testApplicationId;
- private final boolean waitForDebugger;
-
- StockAndroidTestLaunchTask(
- BlazeAndroidTestRunConfigurationState configState,
- String runner,
- String testPackage,
- boolean waitForDebugger) {
- this.configState = configState;
- this.instrumentationTestRunner = runner;
- this.waitForDebugger = waitForDebugger;
- this.testApplicationId = testPackage;
- }
-
- @Nullable
- public static LaunchTask getStockTestLaunchTask(
- BlazeAndroidTestRunConfigurationState configState,
- ApplicationIdProvider applicationIdProvider,
- boolean waitForDebugger,
- BlazeAndroidDeployInfo deployInfo,
- LaunchStatus launchStatus) {
- String testPackage;
- try {
- testPackage = applicationIdProvider.getTestPackageName();
- if (testPackage == null) {
- launchStatus.terminateLaunch("Unable to determine test package name", true);
- return null;
- }
- } catch (ApkProvisionException e) {
- launchStatus.terminateLaunch("Unable to determine test package name", true);
- return null;
- }
-
- List availableRunners = getRunnersFromManifest(deployInfo);
- if (availableRunners.isEmpty()) {
- launchStatus.terminateLaunch(
- String.format(
- "No instrumentation test runner is defined in the manifest.\n"
- + "At least one instrumentation tag must be defined for the\n"
- + "\"%1$s\" package in the AndroidManifest.xml, e.g.:\n"
- + "\n"
- + "\n"
- + "\n"
- + " \n"
- + " \n"
- + "\n"
- + "",
- testPackage),
- true);
- // Note: Gradle users will never see the above message, so don't mention Gradle here.
- // Even if no runners are defined in build.gradle, Gradle will add a default to the manifest.
- return null;
- }
- String runner = configState.getInstrumentationRunnerClass();
- if (!StringUtil.isEmpty(runner)) {
- if (!availableRunners.contains(runner)) {
- launchStatus.terminateLaunch(
- String.format(
- "Instrumentation test runner \"%2$s\"\n"
- + "is not defined for the \"%1$s\" package in the manifest.\n"
- + "Clear the 'Specific instrumentation runner' field in your configuration\n"
- + "to default to \"%3$s\",\n"
- + "or add the runner to your AndroidManifest.xml:\n"
- + "\n"
- + "\n"
- + "\n"
- + " \n"
- + " \n"
- + "\n"
- + "",
- testPackage, runner, availableRunners.get(0)),
- true);
- return null;
- }
- } else {
- // Default to the first available runner.
- runner = availableRunners.get(0);
- }
-
- return new StockAndroidTestLaunchTask(configState, runner, testPackage, waitForDebugger);
- }
-
- private static ImmutableList getRunnersFromManifest(
- final BlazeAndroidDeployInfo deployInfo) {
- if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
- return ApplicationManager.getApplication()
- .runReadAction(
- (Computable>) () -> getRunnersFromManifest(deployInfo));
- }
-
- ManifestParser.ParsedManifest parsedManifest = deployInfo.getMergedManifest();
- if (parsedManifest != null) {
- return ImmutableList.copyOf(parsedManifest.instrumentationClassNames);
- }
- return ImmutableList.of();
- }
-
- @Override
- public String getDescription() {
- return "Launching instrumentation runner";
- }
-
- @Override
- public int getDuration() {
- return 2;
- }
-
- @Override
- public LaunchResult run(@NotNull LaunchContext launchContext) {
- ConsolePrinter printer = launchContext.getConsolePrinter();
- printer.stdout("Running tests\n");
-
- final RemoteAndroidTestRunner runner =
- new RemoteAndroidTestRunner(
- testApplicationId, instrumentationTestRunner, launchContext.getDevice());
- switch (configState.getTestingType()) {
- case BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_MODULE:
- break;
- case BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_PACKAGE:
- runner.setTestPackageName(configState.getPackageName());
- break;
- case BlazeAndroidTestRunConfigurationState.TEST_CLASS:
- runner.setClassName(configState.getClassName());
- break;
- case BlazeAndroidTestRunConfigurationState.TEST_METHOD:
- runner.setMethodName(configState.getClassName(), configState.getMethodName());
- break;
- default:
- LOG.error(String.format("Unrecognized testing type: %d", configState.getTestingType()));
- return LaunchResult.error("", getDescription());
- }
- runner.setDebug(waitForDebugger);
- runner.setRunOptions(configState.getExtraOptions());
-
- printer.stdout("$ adb shell " + runner.getAmInstrumentCommand());
-
- // run in a separate thread as this will block until the tests complete
- ApplicationManager.getApplication()
- .executeOnPooledThread(
- () -> {
- try {
- // This issues "am instrument" command and blocks execution.
- runner.run(new AndroidTestListener(printer));
-
- // Detach the device from the android process handler manually as soon as "am
- // instrument" command finishes. This is required because the android process
- // handler may overlook target process especially when the test
- // runs really fast (~10ms). Because the android process handler discovers new
- // processes by polling, this race condition happens easily. By detaching the device
- // manually, we can avoid the android process handler waiting for (already finished)
- // process to show up until it times out (10 secs).
- // Note: this is a copy of ag/9593981, but it is worth figuring out a better
- // strategy here if the behavior of AndroidTestListener is not guaranteed.
- ProcessHandler processHandler = launchContext.getProcessHandler();
- if (processHandler instanceof AndroidProcessHandler) {
- ((AndroidProcessHandler) processHandler).detachDevice(launchContext.getDevice());
- }
- } catch (Exception e) {
- LOG.info(e);
- printer.stderr("Error: Unexpected exception while running tests: " + e);
- }
- });
-
- return LaunchResult.success();
- }
-
- @NotNull
- @Override
- public String getId() {
- return ID;
- }
-}
diff --git a/aswb/sdkcompat/as222/com/google/idea/blaze/android/sync/model/idea/BlazeAndroidModel.java b/aswb/sdkcompat/as222/com/google/idea/blaze/android/sync/model/idea/BlazeAndroidModel.java
deleted file mode 100644
index 00a9e4a94c9..00000000000
--- a/aswb/sdkcompat/as222/com/google/idea/blaze/android/sync/model/idea/BlazeAndroidModel.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.sync.model.idea;
-
-import com.android.tools.idea.model.AndroidModel;
-import com.android.tools.idea.model.Namespacing;
-import com.android.tools.idea.projectsystem.NamedIdeaSourceProvider;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.intellij.openapi.project.Project;
-import java.io.File;
-
-/** Blaze model for an android project. #api42. */
-public class BlazeAndroidModel extends BlazeAndroidModelBase {
- private final NamedIdeaSourceProvider sourceProvider;
-
- public BlazeAndroidModel(
- Project project,
- File rootDirPath,
- NamedIdeaSourceProvider sourceProvider,
- ListenableFuture applicationId,
- int minSdkVersion,
- boolean desugarJava8Libs) {
- super(project, rootDirPath, applicationId, minSdkVersion, desugarJava8Libs);
- this.sourceProvider = sourceProvider;
- }
-
- public NamedIdeaSourceProvider getDefaultSourceProvider() {
- return sourceProvider;
- }
-
- @Override
- public Namespacing getNamespacing() {
- return Namespacing.DISABLED;
- }
-
- @Override
- protected String uninitializedApplicationId() {
- return AndroidModel.UNINITIALIZED_APPLICATION_ID;
- }
-}
diff --git a/aswb/sdkcompat/as222/org/jetbrains/android/facet/AndroidFacetPropertiesCompat.java b/aswb/sdkcompat/as222/org/jetbrains/android/facet/AndroidFacetPropertiesCompat.java
deleted file mode 100644
index fff25619e8a..00000000000
--- a/aswb/sdkcompat/as222/org/jetbrains/android/facet/AndroidFacetPropertiesCompat.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.facet;
-
-/** Compat class for AndroidFacetProperties. */
-public class AndroidFacetPropertiesCompat {
-
- private AndroidFacetPropertiesCompat() {}
-
- public static void enableSourcesAutogeneration(AndroidFacetProperties props, boolean enable) {}
-}
diff --git a/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidPlatformCompat.java b/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidPlatformCompat.java
deleted file mode 100644
index 77fdbc6bcf1..00000000000
--- a/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidPlatformCompat.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.android.sdklib.BuildToolInfo;
-import com.intellij.openapi.projectRoots.Sdk;
-
-/** Compat class for {@link AndroidPlatform} */
-public class AndroidPlatformCompat {
- AndroidPlatform androidPlatform;
-
- public AndroidPlatformCompat(AndroidPlatform androidPlatform) {
- this.androidPlatform = androidPlatform;
- }
-
- public BuildToolInfo getLatestBuildTool(boolean allowBuildTool) {
- return androidPlatform.getSdkData().getLatestBuildTool(allowBuildTool);
- }
-
- public int getApiLevel() {
- return androidPlatform.getApiLevel();
- }
-
- public static int getApiLevel(Sdk sdk) {
- int androidSdkApiLevel = 1;
- AndroidSdkAdditionalData additionalData = (AndroidSdkAdditionalData) sdk.getSdkAdditionalData();
- if (additionalData != null) {
- AndroidPlatform androidPlatform = additionalData.getAndroidPlatform();
- if (androidPlatform != null) {
- androidSdkApiLevel = androidPlatform.getApiLevel();
- }
- }
- return androidSdkApiLevel;
- }
-}
diff --git a/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidPlatformsCompat.java b/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidPlatformsCompat.java
deleted file mode 100644
index 3548e0aeb71..00000000000
--- a/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidPlatformsCompat.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.projectRoots.Sdk;
-
-/** Compat shim class for {@link AndroidPlatforms} */
-public class AndroidPlatformsCompat {
- private AndroidPlatformsCompat() {}
-
- public static AndroidPlatformCompat getInstance(Sdk sdk) {
- return new AndroidPlatformCompat(AndroidPlatform.getInstance(sdk));
- }
-
- public static AndroidPlatformCompat getInstance(Module module) {
- return new AndroidPlatformCompat(AndroidPlatform.getInstance(module));
- }
-}
diff --git a/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidSdkAdditionalDataCompat.java b/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidSdkAdditionalDataCompat.java
deleted file mode 100644
index d9033a9b7b8..00000000000
--- a/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidSdkAdditionalDataCompat.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.android.tools.idea.sdk.AndroidSdks;
-import com.intellij.openapi.projectRoots.Sdk;
-
-/** Compat shim class for {@link AndroidSdkAdditionalData} */
-public class AndroidSdkAdditionalDataCompat {
- private AndroidSdkAdditionalDataCompat() {}
-
- public static AndroidSdkAdditionalData from(Sdk sdk) {
- return AndroidSdks.getInstance().getAndroidSdkAdditionalData(sdk);
- }
-}
diff --git a/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidSdkDataCompat.java b/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidSdkDataCompat.java
deleted file mode 100644
index 990b4b409fe..00000000000
--- a/aswb/sdkcompat/as222/org/jetbrains/android/sdk/AndroidSdkDataCompat.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.android.sdklib.IAndroidTarget;
-import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import java.io.File;
-
-/** Compat class for {@link AndroidSdkData} */
-public class AndroidSdkDataCompat {
- AndroidSdkData androidSdkData;
-
- private AndroidSdkDataCompat(File sdkLocation, boolean forceReparse) {
- androidSdkData = AndroidSdkData.getSdkData(sdkLocation, forceReparse);
- }
-
- public static AndroidSdkDataCompat getSdkData(String sdkHomepath) {
- return new AndroidSdkDataCompat(new File(sdkHomepath), false);
- }
-
- @CanIgnoreReturnValue
- public static AndroidSdkDataCompat getSdkData(File sdkLocation, boolean forceReparse) {
- return new AndroidSdkDataCompat(sdkLocation, forceReparse);
- }
-
- public IAndroidTarget[] getTargets() {
- return androidSdkData.getTargets();
- }
-}
diff --git a/aswb/sdkcompat/as223/com/android/tools/idea/model/AndroidManifestIndexCompat.java b/aswb/sdkcompat/as223/com/android/tools/idea/model/AndroidManifestIndexCompat.java
deleted file mode 100644
index 82eb27bee0c..00000000000
--- a/aswb/sdkcompat/as223/com/android/tools/idea/model/AndroidManifestIndexCompat.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.model;
-
-/** Compat class for {@link com.android.tools.idea.model.AndroidManifestIndex}. */
-public class AndroidManifestIndexCompat {
-
- private AndroidManifestIndexCompat() {}
-
- /** {@code indexEnabled} was removed in Studio 2021.2. #api211 */
- public static boolean indexEnabled() {
- return true;
- }
-}
diff --git a/aswb/sdkcompat/as223/com/android/tools/idea/progress/StudioLoggerProgressIndicatorCompat.java b/aswb/sdkcompat/as223/com/android/tools/idea/progress/StudioLoggerProgressIndicatorCompat.java
deleted file mode 100644
index 7f9654b2ccf..00000000000
--- a/aswb/sdkcompat/as223/com/android/tools/idea/progress/StudioLoggerProgressIndicatorCompat.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.progress;
-
-/** Compat layer for StudioLoggerProgressIndicator which moved packages in 2021.2. #api211 */
-public class StudioLoggerProgressIndicatorCompat extends StudioLoggerProgressIndicator {
- public StudioLoggerProgressIndicatorCompat(Class> c) {
- super(c);
- }
-}
diff --git a/aswb/sdkcompat/as223/com/android/tools/idea/run/AndroidSessionInfoCompat.java b/aswb/sdkcompat/as223/com/android/tools/idea/run/AndroidSessionInfoCompat.java
deleted file mode 100644
index 783ad5d39e4..00000000000
--- a/aswb/sdkcompat/as223/com/android/tools/idea/run/AndroidSessionInfoCompat.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.run;
-
-import com.android.ddmlib.Client;
-import com.android.tools.idea.execution.common.AndroidSessionInfo;
-import com.intellij.debugger.engine.RemoteDebugProcessHandler;
-import com.intellij.execution.ExecutionTarget;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.ui.RunContentDescriptor;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** Compat class for AndroidSessionInfo */
-public class AndroidSessionInfoCompat {
-
- private AndroidSessionInfoCompat() {}
-
- public static AndroidSessionInfo create(
- @NotNull ProcessHandler processHandler,
- @NotNull RunContentDescriptor descriptor,
- @Nullable RunConfiguration runConfiguration,
- @NotNull String executorId,
- @NotNull String executorActionName,
- @NotNull ExecutionTarget executionTarget) {
- return AndroidSessionInfo.create(processHandler, runConfiguration, executorId, executionTarget);
- }
-
- @Nullable
- public static RunContentDescriptor getDescriptor(AndroidSessionInfo session) {
- return null;
- }
-
- public static void putAndroidDebugClient(RemoteDebugProcessHandler handler, Client client) {}
-}
diff --git a/aswb/sdkcompat/as223/com/android/tools/idea/run/editor/DeployTargetCompat.java b/aswb/sdkcompat/as223/com/android/tools/idea/run/editor/DeployTargetCompat.java
deleted file mode 100644
index faa6faec6fe..00000000000
--- a/aswb/sdkcompat/as223/com/android/tools/idea/run/editor/DeployTargetCompat.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.run.editor;
-
-import com.android.tools.idea.run.DeviceFutures;
-import com.intellij.openapi.project.Project;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** SDK Compat class for {@link DeployTarget#getDevices}. */
-public class DeployTargetCompat {
-
- private DeployTargetCompat() {}
-
- @Nullable
- public static DeviceFutures getDevices(
- DeployTarget target, AndroidFacet facet, @NotNull Project project) {
- return target.getDevices(project);
- }
-}
diff --git a/aswb/sdkcompat/as223/com/android/tools/idea/run/tasks/DeployTasksCompat.java b/aswb/sdkcompat/as223/com/android/tools/idea/run/tasks/DeployTasksCompat.java
deleted file mode 100644
index 500a6786340..00000000000
--- a/aswb/sdkcompat/as223/com/android/tools/idea/run/tasks/DeployTasksCompat.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.run.tasks;
-
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTaskWrapper;
-import com.google.idea.common.experiments.BoolExperiment;
-import com.intellij.openapi.project.Project;
-import java.util.Collection;
-
-/** Compat class for {@link DeployTask} */
-public class DeployTasksCompat {
- private static final BoolExperiment updateCodeViaJvmti =
- new BoolExperiment("android.apply.changes", false);
-
- private DeployTasksCompat() {}
-
- public static BlazeLaunchTask createDeployTask(
- Project project, Collection packages, LaunchOptions launchOptions) {
- // We don't have a device information, fallback to the most conservative
- // install option.
- return new BlazeLaunchTaskWrapper(
- new DeployTask(
- project,
- packages,
- launchOptions.getPmInstallOptions(/* device= */ null),
- launchOptions.getInstallOnAllUsers(),
- launchOptions.getAlwaysInstallWithPm()));
- }
-}
-
diff --git a/aswb/sdkcompat/as223/com/android/tools/rendering/HtmlLinkManagerCompat.java b/aswb/sdkcompat/as223/com/android/tools/rendering/HtmlLinkManagerCompat.java
deleted file mode 100644
index 594132f69af..00000000000
--- a/aswb/sdkcompat/as223/com/android/tools/rendering/HtmlLinkManagerCompat.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.rendering;
-
-import com.android.tools.idea.rendering.HtmlLinkManager;
-import java.io.File;
-import org.jetbrains.annotations.NotNull;
-
-/** Compat class for {@link HtmlLinkManager} */
-public final class HtmlLinkManagerCompat {
- public static String createFilePositionUrl(@NotNull File file, int line, int column) {
- return HtmlLinkManager.createFilePositionUrl(file, line, column);
- }
-
- private HtmlLinkManagerCompat() {}
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/cppimpl/debug/BlazeAutoAndroidDebugger.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/cppimpl/debug/BlazeAutoAndroidDebugger.java
deleted file mode 100644
index 167fd4433a9..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/cppimpl/debug/BlazeAutoAndroidDebugger.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.cppimpl.debug;
-
-import com.android.ddmlib.Client;
-import com.android.tools.ndk.run.editor.AutoAndroidDebuggerState;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.project.Project;
-import com.intellij.xdebugger.XDebugSession;
-
-/** Shim for #api212 compat. */
-public class BlazeAutoAndroidDebugger extends BlazeAutoAndroidDebuggerBase {
- @Override
- public XDebugSession attachToClient(
- Project project, Client client, AutoAndroidDebuggerState state) throws ExecutionException {
- if (isNativeProject(project)) {
- log.info("Project has native development enabled. Attaching native debugger.");
- return nativeDebugger.attachToClient(project, client, state);
- } else {
- return super.attachToClient(project, client, state);
- }
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebugger.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebugger.java
deleted file mode 100644
index e92afddc27c..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebugger.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.cppimpl.debug;
-
-/**
- * API compat of {@link BlazeNativeAndroidDebuggerBase} with the following additions:
- *
- *
- * - Creates a run-config setting using {@link BlazeAndroidNativeAttachConfiguration} instead of
- * {@link AndroidNativeAttachConfiguration} to override counterproductive validations.
- *
- *
- * #api4.0
- */
-public class BlazeNativeAndroidDebugger extends BlazeNativeAndroidDebuggerBase {}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebuggerBase.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebuggerBase.java
deleted file mode 100644
index 911d90b7711..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebuggerBase.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.cppimpl.debug;
-
-import com.android.tools.ndk.run.editor.NativeAndroidDebugger;
-import com.google.idea.blaze.base.model.BlazeProjectData;
-import com.google.idea.blaze.base.model.primitives.LanguageClass;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
-import com.intellij.openapi.project.Project;
-
-/**
- * Extension of {@link NativeAndroidDebugger} with the following key differences compared to {@link
- * NativeAndroidDebugger}.
- *
- *
- * - Overrides {@link #supportsProject} so native debugger is only enabled for native support is
- * enabled.
- *
- */
-public class BlazeNativeAndroidDebuggerBase extends NativeAndroidDebugger {
- /**
- * This ID needs to be lexicographically larger than "Java" so it come after the "Java" debugger
- * when sorted lexicographically in the "Attach Debugger to Android Process" dialog. See {@link
- * org.jetbrains.android.actions.AndroidProcessChooserDialog#populateDebuggerTypeCombo}.
- */
- public static final String ID = "Native" + Blaze.defaultBuildSystemName();
-
- @Override
- public String getId() {
- return ID;
- }
-
- @Override
- public String getDisplayName() {
- return "Native Only";
- }
-
- @Override
- public boolean supportsProject(Project project) {
- BlazeProjectData blazeProjectData =
- BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
- return blazeProjectData != null
- && blazeProjectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.C);
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/projectsystem/BlazeProjectSystem.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/projectsystem/BlazeProjectSystem.java
deleted file mode 100755
index b5b20a1b2a7..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/projectsystem/BlazeProjectSystem.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright 2017 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.projectsystem;
-
-import static com.android.tools.idea.projectsystem.SourceProvidersKt.emptySourceProvider;
-import static org.jetbrains.android.facet.SourceProviderUtil.createSourceProvidersForLegacyModule;
-
-import com.android.tools.apk.analyzer.AaptInvoker;
-import com.android.tools.idea.log.LogWrapper;
-import com.android.tools.idea.model.AndroidModel;
-import com.android.tools.idea.model.ClassJarProvider;
-import com.android.tools.idea.projectsystem.AndroidModuleSystem;
-import com.android.tools.idea.projectsystem.AndroidProjectSystem;
-import com.android.tools.idea.projectsystem.NamedIdeaSourceProvider;
-import com.android.tools.idea.projectsystem.ProjectSystemBuildManager;
-import com.android.tools.idea.projectsystem.ProjectSystemSyncManager;
-import com.android.tools.idea.projectsystem.ScopeType;
-import com.android.tools.idea.projectsystem.SourceProviderManager;
-import com.android.tools.idea.projectsystem.SourceProviders;
-import com.android.tools.idea.projectsystem.SourceProvidersFactory;
-import com.android.tools.idea.projectsystem.SourceProvidersImpl;
-import com.android.tools.idea.res.AndroidInnerClassFinder;
-import com.android.tools.idea.res.AndroidResourceClassPsiElementFinder;
-import com.android.tools.idea.sdk.AndroidSdks;
-import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.android.resources.BlazeLightResourceClassService;
-import com.google.idea.blaze.android.sync.model.idea.BlazeAndroidModel;
-import com.google.idea.blaze.android.sync.model.idea.BlazeClassJarProvider;
-import com.google.idea.blaze.base.build.BlazeBuildService;
-import com.google.idea.blaze.base.qsync.QuerySync;
-import com.intellij.facet.ProjectFacetManager;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiElementFinder;
-import com.intellij.psi.search.GlobalSearchScope;
-import java.io.File;
-import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Base class to implement common methods in {@link AndroidProjectSystem} for blaze with different
- * sdk
- */
-public class BlazeProjectSystem implements AndroidProjectSystem {
- protected final Project project;
- protected final ProjectSystemSyncManager syncManager;
- protected final List myFinders;
- private final BlazeProjectSystemBuildManager buildManager;
-
- public BlazeProjectSystem(Project project) {
- this.project = project;
- syncManager = new BlazeProjectSystemSyncManager(project);
- buildManager = new BlazeProjectSystemBuildManager(project);
-
- myFinders =
- Arrays.asList(
- AndroidInnerClassFinder.INSTANCE,
- new AndroidResourceClassPsiElementFinder(getLightResourceClassService()));
- }
-
- @Override
- public boolean allowsFileCreation() {
- return true;
- }
-
- @Nullable
- @Override
- public VirtualFile getDefaultApkFile() {
- return null;
- }
-
- @Override
- public Path getPathToAapt() {
- return AaptInvoker.getPathToAapt(
- AndroidSdks.getInstance().tryToChooseSdkHandler(),
- new LogWrapper(BlazeProjectSystem.class));
- }
-
- // @Override #api42
- public void buildProject() {
- BlazeBuildService.getInstance(project).buildProject();
- }
-
- // @Override #api42
- public ProjectSystemBuildManager getBuildManager() {
- return buildManager;
- }
-
- @Override
- public AndroidModuleSystem getModuleSystem(Module module) {
- return BlazeModuleSystem.getInstance(module);
- }
-
- @Override
- public ProjectSystemSyncManager getSyncManager() {
- return syncManager;
- }
-
- @Override
- public Collection getPsiElementFinders() {
- return myFinders;
- }
-
- @Override
- public BlazeLightResourceClassService getLightResourceClassService() {
- return BlazeLightResourceClassService.getInstance(project);
- }
-
- @Override
- public SourceProvidersFactory getSourceProvidersFactory() {
- return new SourceProvidersFactory() {
- @Override
- public SourceProviders createSourceProvidersFor(AndroidFacet facet) {
- BlazeAndroidModel model = ((BlazeAndroidModel) AndroidModel.get(facet));
- if (model != null) {
- return createForModel(model);
- } else {
- return createSourceProvidersForLegacyModule(facet);
- }
- }
-
- private SourceProviders createForModel(BlazeAndroidModel model) {
- NamedIdeaSourceProvider mainSourceProvider = model.getDefaultSourceProvider();
- if (QuerySync.isEnabled()) {
- return new SourceProvidersImpl(
- mainSourceProvider,
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(),
- ImmutableList.of(),
- ImmutableList.of(),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- emptySourceProvider(ScopeType.MAIN),
- emptySourceProvider(ScopeType.UNIT_TEST),
- emptySourceProvider(ScopeType.ANDROID_TEST),
- emptySourceProvider(ScopeType.TEST_FIXTURES));
- } else {
- return new SourceProvidersImpl(
- mainSourceProvider,
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- emptySourceProvider(ScopeType.MAIN),
- emptySourceProvider(ScopeType.UNIT_TEST),
- emptySourceProvider(ScopeType.ANDROID_TEST),
- emptySourceProvider(ScopeType.TEST_FIXTURES));
- }
- }
- };
- }
-
- // @Override #api212
- public ClassJarProvider getClassJarProvider() {
- return new BlazeClassJarProvider(project);
- }
-
- @Override
- public Collection getAndroidFacetsWithPackageName(
- Project project, String packageName) {
- return getAndroidFacetsWithPackageName(
- project, packageName, GlobalSearchScope.projectScope(project));
- }
-
- private Collection getAndroidFacetsWithPackageName(
- Project project, String packageName, GlobalSearchScope scope) {
- List facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
- return facets.stream()
- .filter(facet -> hasPackageName(facet, packageName))
- .filter(
- facet -> {
- VirtualFile file = SourceProviderManager.getInstance(facet).getMainManifestFile();
- if (file == null) {
- return false;
- } else {
- return scope.contains(file);
- }
- })
- .collect(Collectors.toList());
- }
-
- @Override
- public Collection getSubmodules() {
- return ImmutableList.of();
- }
-
- @Override
- public Collection getBootClasspath(@NotNull Module module) {
- // TODO: b/266586669
- return ImmutableList.of();
- }
-
- private static boolean hasPackageName(AndroidFacet facet, String packageName) {
- String nameFromFacet = PackageNameUtils.getPackageName(facet.getModule());
- if (nameFromFacet == null) {
- return false;
- }
- return nameFromFacet.equals(packageName);
- }
-
- @NotNull
- // @Override #api223
- public List desugarLibraryConfigFiles(@NotNull Project project) {
- return ImmutableList.of();
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/projectsystem/PackageNameUtils.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/projectsystem/PackageNameUtils.java
deleted file mode 100644
index 83a7fcd9b20..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/projectsystem/PackageNameUtils.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.projectsystem;
-
-import com.android.manifmerger.ManifestSystemProperty;
-import com.android.tools.idea.model.AndroidManifestIndex;
-import com.android.tools.idea.model.AndroidManifestIndexCompat;
-import com.android.tools.idea.model.AndroidManifestRawText;
-import com.android.tools.idea.model.MergedManifestModificationTracker;
-import com.android.tools.idea.projectsystem.ManifestOverrides;
-import com.android.tools.idea.projectsystem.SourceProviderManager;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.idea.common.experiments.BoolExperiment;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.DumbService;
-import com.intellij.openapi.project.IndexNotReadyException;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.util.CachedValueProvider;
-import com.intellij.psi.util.CachedValuesManager;
-import org.jetbrains.android.dom.manifest.AndroidManifestUtils;
-import org.jetbrains.android.dom.manifest.AndroidManifestXmlFile;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.Nullable;
-
-/** Utilities to obtain the package name for a given module. */
-public class PackageNameUtils {
- /**
- * Determines whether we use the {@link AndroidManifestIndex} to obtain the raw text package name
- * from a module's primary manifest. Note that we still won't use the index if {@link
- * AndroidManifestIndex#indexEnabled()} returns false.
- *
- * @see PackageNameUtils#getPackageName(Module)
- * @see PackageNameUtils#doGetPackageName(AndroidFacet, boolean)
- */
- private static final BoolExperiment USE_ANDROID_MANIFEST_INDEX =
- new BoolExperiment("use.android.manifest.index", true);
-
- @Nullable
- public static String getPackageName(Module module) {
- AndroidFacet facet = AndroidFacet.getInstance(module);
- assert facet != null;
- return CachedValuesManager.getManager(module.getProject())
- .getCachedValue(
- facet,
- () -> {
- boolean useIndex =
- AndroidManifestIndexCompat.indexEnabled()
- && USE_ANDROID_MANIFEST_INDEX.getValue();
- String packageName = doGetPackageName(facet, useIndex);
- return CachedValueProvider.Result.create(
- StringUtil.nullize(packageName, true),
- MergedManifestModificationTracker.getInstance(module));
- });
- }
-
- /**
- * Returns the package name from an Android module's merged manifest without actually computing
- * the whole merged manifest. This is either
- *
- *
- * - The {@link ManifestSystemProperty#PACKAGE} manifest override if one is specified by the
- * corresponding BUILD target, or
- *
- The result of applying placeholder substitution to the raw package name from the module's
- * primary manifest
- *
- *
- * In the second case, we try to obtain the raw package name using the {@link
- * AndroidManifestIndex} if {@code useIndex} is true. If {@code useIndex} is false or querying the
- * index fails for some reason (e.g. this method is called in a read action but not a *smart* read
- * action), then we resort to parsing the PSI of the module's primary manifest to get the raw
- * package name.
- *
- * @see AndroidModuleSystem#getManifestOverrides()
- * @see AndroidModuleSystem#getPackageName()
- */
- @Nullable
- @VisibleForTesting
- static String doGetPackageName(AndroidFacet facet, boolean useIndex) {
- ManifestOverrides manifestOverrides =
- BlazeModuleSystem.getInstance(facet.getModule()).getManifestOverrides();
- String packageOverride =
- ManifestValueProcessor.getPackageOverride(manifestOverrides.getDirectOverrides());
- if (packageOverride != null) {
- return packageOverride;
- }
- String rawPackageName = null;
- if (useIndex) {
- rawPackageName = getRawPackageNameFromIndex(facet);
- }
- if (rawPackageName == null) {
- rawPackageName = getRawPackageNameFromPsi(facet);
- }
- return rawPackageName == null ? null : manifestOverrides.resolvePlaceholders(rawPackageName);
- }
-
- @Nullable
- private static String getRawPackageNameFromIndex(AndroidFacet facet) {
- VirtualFile primaryManifest = SourceProviderManager.getInstance(facet).getMainManifestFile();
- if (primaryManifest == null) {
- return null;
- }
- Project project = facet.getModule().getProject();
- try {
- AndroidManifestRawText manifestRawText =
- DumbService.getInstance(project)
- .runReadActionInSmartMode(
- () -> AndroidManifestIndex.getDataForManifestFile(project, primaryManifest));
- return manifestRawText == null ? null : manifestRawText.getPackageName();
- } catch (IndexNotReadyException e) {
- // TODO(142681129): runReadActionInSmartMode doesn't work if we already have read access.
- // We need to refactor the callers of AndroidManifestUtils#getPackage to require a *smart*
- // read action, at which point we can remove this try-catch.
- return null;
- }
- }
-
- @Nullable
- private static String getRawPackageNameFromPsi(AndroidFacet facet) {
- AndroidManifestXmlFile primaryManifest = AndroidManifestUtils.getPrimaryManifestXml(facet);
- return primaryManifest == null ? null : primaryManifest.getPackageName();
- }
-
- private PackageNameUtils() {}
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/resources/BlazeRClass.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/resources/BlazeRClass.java
deleted file mode 100644
index 5a8cbf8e450..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/resources/BlazeRClass.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.resources;
-
-import static org.jetbrains.android.AndroidResolveScopeEnlarger.LIGHT_CLASS_KEY;
-import static org.jetbrains.android.AndroidResolveScopeEnlarger.MODULE_POINTER_KEY;
-
-import com.android.ide.common.rendering.api.ResourceNamespace;
-import com.android.tools.idea.res.LocalResourceRepository;
-import com.android.tools.idea.res.ResourceRepositoryRClass;
-import com.android.tools.idea.res.StudioResourceRepositoryManager;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.module.ModulePointerManager;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiManager;
-import org.jetbrains.android.augment.AndroidLightField;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Blaze implementation of an R class based on resource repositories. */
-public class BlazeRClass extends ResourceRepositoryRClass {
-
- private final AndroidFacet androidFacet;
-
- public BlazeRClass(PsiManager psiManager, AndroidFacet androidFacet, String packageName) {
- super(
- psiManager,
- new ResourcesSource() {
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public Transitivity getTransitivity() {
- return Transitivity.TRANSITIVE;
- }
-
- @Override
- public StudioResourceRepositoryManager getResourceRepositoryManager() {
- return StudioResourceRepositoryManager.getInstance(androidFacet);
- }
-
- @Override
- public LocalResourceRepository getResourceRepository() {
- return StudioResourceRepositoryManager.getAppResources(androidFacet);
- }
-
- @Override
- public ResourceNamespace getResourceNamespace() {
- return ResourceNamespace.RES_AUTO;
- }
-
- @Override
- public AndroidLightField.FieldModifier getFieldModifier() {
- return AndroidLightField.FieldModifier.NON_FINAL;
- }
- });
- this.androidFacet = androidFacet;
- setModuleInfo(getModule(), false);
- VirtualFile virtualFile = myFile.getViewProvider().getVirtualFile();
- virtualFile.putUserData(
- MODULE_POINTER_KEY, ModulePointerManager.getInstance(getProject()).create(getModule()));
- virtualFile.putUserData(LIGHT_CLASS_KEY, ResourceRepositoryRClass.class);
- }
-
- public Module getModule() {
- return androidFacet.getModule();
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/BlazeAndroidDeploymentService.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/BlazeAndroidDeploymentService.java
deleted file mode 100644
index 6cc3a63459e..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/BlazeAndroidDeploymentService.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run;
-
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.tasks.DeployTask;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.intellij.openapi.project.Project;
-import java.util.Collection;
-
-/** A service that provides {@link DeployTask}. */
-public interface BlazeAndroidDeploymentService {
- static BlazeAndroidDeploymentService getInstance(Project project) {
- return project.getService(BlazeAndroidDeploymentService.class);
- }
-
- /** Returns a {@link DeployTask} to deploy the given files and launch options. */
- BlazeLaunchTask getDeployTask(Collection packages, LaunchOptions launchOptions);
-
- /** A default implementation that uses {@link DeployTasksCompat#createDeployTask}. */
- class DefaultDeploymentService implements BlazeAndroidDeploymentService {
- private final Project project;
-
- public DefaultDeploymentService(Project project) {
- this.project = project;
- }
-
- @Override
- public BlazeLaunchTask getDeployTask(
- Collection packages, LaunchOptions launchOptions) {
- return DeployTasksCompat.createDeployTask(project, packages, launchOptions);
- }
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/BlazeCommandAndroidDebuggerInfoProvider.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/BlazeCommandAndroidDebuggerInfoProvider.java
deleted file mode 100644
index 03dd9f80da7..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/BlazeCommandAndroidDebuggerInfoProvider.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.execution.common.debug.impl.java.AndroidJavaDebugger;
-import com.android.tools.idea.run.editor.AndroidDebuggerInfoProvider;
-import com.google.idea.blaze.android.cppimpl.debug.BlazeNativeAndroidDebugger;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.test.BlazeAndroidTestRunConfigurationState;
-import com.google.idea.blaze.base.model.BlazeProjectData;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.openapi.project.Project;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import org.jetbrains.annotations.Nullable;
-
-/** Provider of blaze project compatible android debuggers. */
-public class BlazeCommandAndroidDebuggerInfoProvider implements AndroidDebuggerInfoProvider {
- @Override
- public boolean supportsProject(Project project) {
- BlazeProjectData blazeProjectData =
- BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
- return blazeProjectData != null;
- }
-
- @Override
- @SuppressWarnings("rawtypes") // List includes multiple AndroidDebuggerState types.
- public List getAndroidDebuggers(RunConfiguration configuration) {
- if (getCommonState(configuration) != null) {
- return Arrays.asList(new BlazeNativeAndroidDebugger(), new AndroidJavaDebugger());
- }
- return Collections.emptyList();
- }
-
- @Nullable
- @Override
- public AndroidDebugger getSelectedAndroidDebugger(
- RunConfiguration configuration) {
- // b/170159822 Always return java debugger because BlazeAutoAndroidDebugger doesn't work and
- // users likely want the java debugger not the native debugger.
- return new AndroidJavaDebugger();
- }
-
- @Nullable
- @Override
- public AndroidDebuggerState getSelectedAndroidDebuggerState(RunConfiguration configuration) {
- AndroidDebugger debugger = getSelectedAndroidDebugger(configuration);
- if (debugger == null) {
- return null;
- }
- return debugger.createState();
- }
-
- @Nullable
- private BlazeAndroidRunConfigurationCommonState getCommonState(RunConfiguration configuration) {
- if (!(configuration instanceof BlazeCommandRunConfiguration)) {
- return null;
- }
- BlazeCommandRunConfiguration blazeRunConfig = (BlazeCommandRunConfiguration) configuration;
- BlazeAndroidBinaryRunConfigurationState binaryState =
- blazeRunConfig.getHandlerStateIfType(BlazeAndroidBinaryRunConfigurationState.class);
- if (binaryState != null) {
- return binaryState.getCommonState();
- }
- BlazeAndroidTestRunConfigurationState testState =
- blazeRunConfig.getHandlerStateIfType(BlazeAndroidTestRunConfigurationState.class);
- if (testState != null) {
- return testState.getCommonState();
- }
- return null;
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryApplicationLaunchTaskProvider.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryApplicationLaunchTaskProvider.java
deleted file mode 100644
index 8a74f3d458f..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryApplicationLaunchTaskProvider.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.activity.StartActivityFlagsProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTaskWrapper;
-import com.android.tools.idea.run.tasks.AndroidDeepLinkLaunchTask;
-import com.android.tools.idea.run.tasks.DefaultActivityLaunchTask;
-import com.android.tools.idea.run.tasks.SpecificActivityLaunchTask;
-import com.google.idea.blaze.android.manifest.ManifestParser;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.diagnostic.Logger;
-
-/** Provides the launch task for android_binary */
-public class BlazeAndroidBinaryApplicationLaunchTaskProvider {
- private static final Logger LOG =
- Logger.getInstance(BlazeAndroidBinaryApplicationLaunchTaskProvider.class);
-
- public static BlazeLaunchTask getApplicationLaunchTask(
- ApplicationIdProvider applicationIdProvider,
- ManifestParser.ParsedManifest mergedManifestParsedManifest,
- BlazeAndroidBinaryRunConfigurationState configState,
- StartActivityFlagsProvider startActivityFlagsProvider)
- throws ExecutionException {
- try {
- String applicationId = applicationIdProvider.getPackageName();
-
- switch (configState.getMode()) {
- case BlazeAndroidBinaryRunConfigurationState.LAUNCH_DEFAULT_ACTIVITY:
- BlazeDefaultActivityLocator activityLocator =
- new BlazeDefaultActivityLocator(mergedManifestParsedManifest);
- return new BlazeLaunchTaskWrapper(
- new DefaultActivityLaunchTask(
- applicationId, activityLocator, startActivityFlagsProvider));
- case BlazeAndroidBinaryRunConfigurationState.LAUNCH_SPECIFIC_ACTIVITY:
- return new BlazeLaunchTaskWrapper(
- new SpecificActivityLaunchTask(
- applicationId, configState.getActivityClass(), startActivityFlagsProvider));
- case BlazeAndroidBinaryRunConfigurationState.LAUNCH_DEEP_LINK:
- return new BlazeLaunchTaskWrapper(
- new AndroidDeepLinkLaunchTask(configState.getDeepLink(), startActivityFlagsProvider));
- case BlazeAndroidBinaryRunConfigurationState.DO_NOTHING:
- default:
- return null;
- }
- } catch (ApkProvisionException e) {
- throw new ExecutionException("Unable to identify application id");
- }
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContext.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContext.java
deleted file mode 100644
index 6b2d10e2dac..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContext.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2019 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.activity.DefaultStartActivityFlagsProvider;
-import com.android.tools.idea.run.activity.StartActivityFlagsProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Compat for #api212 */
-public class BlazeAndroidBinaryNormalBuildRunContext
- extends BlazeAndroidBinaryNormalBuildRunContextBase {
- BlazeAndroidBinaryNormalBuildRunContext(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, runConfiguration, env, configState, buildStep, launchId);
- }
-
- @Override
- public BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions, @Nullable Integer userId, String contributorsAmStartOptions)
- throws ExecutionException {
- String extraFlags = UserIdHelper.getFlagsFromUserId(userId);
- if (!contributorsAmStartOptions.isEmpty()) {
- extraFlags += (extraFlags.isEmpty() ? "" : " ") + contributorsAmStartOptions;
- }
-
- final StartActivityFlagsProvider startActivityFlagsProvider =
- new DefaultStartActivityFlagsProvider(project, launchOptions.isDebug(), extraFlags);
-
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
-
- return BlazeAndroidBinaryApplicationLaunchTaskProvider.getApplicationLaunchTask(
- applicationIdProvider,
- deployInfo.getMergedManifest(),
- configState,
- startActivityFlagsProvider);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-
- @Override
- public Executor getExecutor() {
- return env.getExecutor();
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextBase.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextBase.java
deleted file mode 100644
index bc3517e8fe8..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextBase.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider.NATIVE_DEBUGGING_ENABLED;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.gradle.util.DynamicAppUtils;
-import com.android.tools.idea.run.ApkFileUnit;
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.ApkProvider;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.idea.blaze.android.run.deployinfo.BlazeApkProviderService;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.NotNull;
-
-/** Run context for android_binary. */
-public abstract class BlazeAndroidBinaryNormalBuildRunContextBase
- implements BlazeAndroidRunContext {
- protected final Project project;
- protected final AndroidFacet facet;
- protected final RunConfiguration runConfiguration;
- protected final ExecutionEnvironment env;
- protected final BlazeAndroidBinaryRunConfigurationState configState;
- protected final ConsoleProvider consoleProvider;
- protected final ApkBuildStep buildStep;
- protected final ApkProvider apkProvider;
- protected final ApplicationIdProvider applicationIdProvider;
- private final String launchId;
-
- BlazeAndroidBinaryNormalBuildRunContextBase(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- this.project = project;
- this.facet = facet;
- this.runConfiguration = runConfiguration;
- this.env = env;
- this.configState = configState;
- this.consoleProvider = new BlazeAndroidBinaryConsoleProvider(project);
- this.buildStep = buildStep;
- this.apkProvider = BlazeApkProviderService.getInstance().getApkProvider(project, buildStep);
- this.applicationIdProvider = new BlazeAndroidBinaryApplicationIdProvider(buildStep);
- this.launchId = launchId;
- }
-
- @Override
- public BlazeAndroidDeviceSelector getDeviceSelector() {
- return new BlazeAndroidDeviceSelector.NormalDeviceSelector();
- }
-
- @Override
- public void augmentLaunchOptions(LaunchOptions.Builder options) {
- options.setDeploy(true).setOpenLogcatAutomatically(configState.showLogcatAutomatically());
- options.addExtraOptions(
- ImmutableMap.of(
- "android.profilers.state", // Not used after #api211
- configState.getProfilerState(),
- NATIVE_DEBUGGING_ENABLED,
- configState.getCommonState().isNativeDebuggingEnabled()));
- }
-
- @Override
- public ConsoleProvider getConsoleProvider() {
- return consoleProvider;
- }
-
- @Override
- public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
- return applicationIdProvider;
- }
-
- @Override
- public ApkBuildStep getBuildStep() {
- return buildStep;
- }
-
- @Nullable
- @Override
- public Integer getUserId(IDevice device) throws ExecutionException {
- return UserIdHelper.getUserIdFromConfigurationState(project, device, configState);
- }
-
- @Override
- public BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException {
- return new BlazeAndroidLaunchTasksProvider(
- project, this, applicationIdProvider, launchOptionsBuilder);
- }
-
- @Override
- public String getAmStartOptions() {
- return configState.getAmStartOptions();
- }
-
- @Override
- public ProfilerState getProfileState() {
- return configState.getProfilerState();
- }
-
- @Nullable
- @Override
- public ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException {
- BlazeLaunchTask deployTask =
- DeployTasksCompat.createDeployTask(
- project, getApkInfoToInstall(device, launchOptions, apkProvider), launchOptions);
- return ImmutableList.of(new DeploymentTimingReporterTask(launchId, deployTask));
- }
-
- /** Returns a list of APKs excluding any APKs for features that are disabled. */
- public static List getApkInfoToInstall(
- IDevice device, LaunchOptions launchOptions, ApkProvider apkProvider)
- throws ExecutionException {
- Collection apks;
- try {
- apks = apkProvider.getApks(device);
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
- List disabledFeatures = launchOptions.getDisabledDynamicFeatures();
- return apks.stream()
- .map(apk -> getApkInfoToInstall(apk, disabledFeatures))
- .collect(Collectors.toList());
- }
-
- @NotNull
- private static ApkInfo getApkInfoToInstall(ApkInfo apkInfo, List disabledFeatures) {
- if (apkInfo.getFiles().size() > 1) {
- List filteredApks =
- apkInfo.getFiles().stream()
- .filter(feature -> DynamicAppUtils.isFeatureEnabled(disabledFeatures, feature))
- .collect(Collectors.toList());
- return new ApkInfo(filteredApks, apkInfo.getApplicationId());
- } else {
- return apkInfo;
- }
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextCompat.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextCompat.java
deleted file mode 100644
index d54c472c84b..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextCompat.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Compat class for {@link BlazeAndroidBinaryNormalBuildRunContext}. */
-public class BlazeAndroidBinaryNormalBuildRunContextCompat
- extends BlazeAndroidBinaryNormalBuildRunContext {
-
- BlazeAndroidBinaryNormalBuildRunContextCompat(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, runConfiguration, env, configState, buildStep, launchId);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryProgramRunner.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryProgramRunner.java
deleted file mode 100644
index 50f42d4b2dd..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryProgramRunner.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.intellij.openapi.application.ModalityState.NON_MODAL;
-
-import com.android.tools.idea.profilers.ProfileRunExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutor;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.ExecutionResult;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunProfile;
-import com.intellij.execution.configurations.RunProfileState;
-import com.intellij.execution.configurations.RunnerSettings;
-import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.executors.DefaultRunExecutor;
-import com.intellij.execution.runners.AsyncProgramRunner;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.runners.RunContentBuilder;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.application.ActionsKt;
-import com.intellij.openapi.fileEditor.FileDocumentManager;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.progress.Task;
-import org.jetbrains.concurrency.AsyncPromise;
-import org.jetbrains.concurrency.Promise;
-
-/** Program runner for configurations from {@link BlazeAndroidBinaryRunConfigurationHandler}. */
-public class BlazeAndroidBinaryProgramRunner extends AsyncProgramRunner {
- @Override
- public boolean canRun(String executorId, RunProfile profile) {
- BlazeAndroidRunConfigurationHandler handler =
- BlazeAndroidRunConfigurationHandler.getHandlerFrom(profile);
- if (!(handler instanceof BlazeAndroidBinaryRunConfigurationHandler)) {
- return false;
- }
- return (DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)
- || DefaultRunExecutor.EXECUTOR_ID.equals(executorId)
- || ProfileRunExecutor.EXECUTOR_ID.equals(executorId));
- }
-
- @Override
- protected Promise execute(
- ExecutionEnvironment environment, RunProfileState state) {
- FileDocumentManager.getInstance().saveAllDocuments();
-
- AsyncPromise promise = new AsyncPromise<>();
-
- ProgressManager.getInstance()
- .run(
- new Task.Backgroundable(environment.getProject(), "Launching ${runProfile.name}") {
- @Override
- public void run(ProgressIndicator indicator) {
- try {
- RunContentDescriptor descriptor;
- if (state instanceof AndroidConfigurationExecutor) {
- AndroidConfigurationExecutor configurationExecutor =
- (AndroidConfigurationExecutor) state;
- Executor executor = environment.getExecutor();
- if (executor.getId().equals(DefaultDebugExecutor.EXECUTOR_ID)) {
- descriptor = configurationExecutor.debug(indicator);
- } else if (executor.getId().equals(DefaultRunExecutor.EXECUTOR_ID)
- || executor.getId().equals(ProfileRunExecutor.EXECUTOR_ID)) {
- descriptor = configurationExecutor.run(indicator);
- } else {
- throw new ExecutionException("Unsupported executor");
- }
- } else {
- descriptor = doExecute(state, environment);
- }
- promise.setResult(descriptor);
- } catch (ExecutionException e) {
- boolean unused = promise.setError(e);
- }
- }
-
- @Override
- public void onCancel() {
- super.onCancel();
- promise.setResult(null);
- }
- });
-
- return promise;
- }
-
- private RunContentDescriptor doExecute(
- final RunProfileState state, final ExecutionEnvironment env) throws ExecutionException {
- ExecutionResult result = state.execute(env.getExecutor(), this);
- return ActionsKt.invokeAndWaitIfNeeded(
- NON_MODAL,
- () -> new RunContentBuilder(result, env).showRunContent(env.getContentToReuse()));
- }
-
- @Override
- public String getRunnerId() {
- return "AndroidBinaryProgramRunner";
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/DeploymentTimingReporterTask.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/DeploymentTimingReporterTask.java
deleted file mode 100644
index 81696ad5b1e..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/DeploymentTimingReporterTask.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2021 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import com.android.tools.idea.run.blaze.BlazeLaunchContext;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.google.common.base.Stopwatch;
-import com.google.idea.blaze.android.run.LaunchMetrics;
-import com.intellij.execution.ExecutionException;
-
-/** A wrapper launch task that wraps the given deployment task and logs the deployment latency. */
-public class DeploymentTimingReporterTask implements BlazeLaunchTask {
- private final BlazeLaunchTask deployTask;
- private final String launchId;
-
- public DeploymentTimingReporterTask(String launchId, BlazeLaunchTask deployTask) {
- this.launchId = launchId;
- this.deployTask = deployTask;
- }
-
- @Override
- public void run(BlazeLaunchContext launchContext) throws ExecutionException {
- Stopwatch s = Stopwatch.createStarted();
- try {
- deployTask.run(launchContext);
- LaunchMetrics.logDeploymentTime(launchId, s.elapsed(), true);
- } catch (ExecutionException e) {
- LaunchMetrics.logDeploymentTime(launchId, s.elapsed(), false);
- throw e;
- }
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContext.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContext.java
deleted file mode 100644
index c49082cfdaa..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContext.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary.mobileinstall;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.activity.DefaultStartActivityFlagsProvider;
-import com.android.tools.idea.run.activity.StartActivityFlagsProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryApplicationLaunchTaskProvider;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.binary.UserIdHelper;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Run Context for mobile install launches, #api4.0 compat. */
-public class BlazeAndroidBinaryMobileInstallRunContext
- extends BlazeAndroidBinaryMobileInstallRunContextBase {
- public BlazeAndroidBinaryMobileInstallRunContext(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, runConfiguration, env, configState, buildStep, launchId);
- }
-
- @SuppressWarnings("unchecked") // upstream API
- @Override
- public BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions, @Nullable Integer userId, String contributorsAmStartOptions)
- throws ExecutionException {
-
- String extraFlags = UserIdHelper.getFlagsFromUserId(userId);
- if (!contributorsAmStartOptions.isEmpty()) {
- extraFlags += (extraFlags.isEmpty() ? "" : " ") + contributorsAmStartOptions;
- }
-
- final StartActivityFlagsProvider startActivityFlagsProvider =
- new DefaultStartActivityFlagsProvider(project, launchOptions.isDebug(), extraFlags);
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
-
- return BlazeAndroidBinaryApplicationLaunchTaskProvider.getApplicationLaunchTask(
- applicationIdProvider,
- deployInfo.getMergedManifest(),
- configState,
- startActivityFlagsProvider);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-
- @Override
- public Executor getExecutor() {
- return env.getExecutor();
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextBase.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextBase.java
deleted file mode 100644
index 7562174bd25..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextBase.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary.mobileinstall;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.run.ApkFileUnit;
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryApplicationIdProvider;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryConsoleProvider;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.binary.DeploymentTimingReporterTask;
-import com.google.idea.blaze.android.run.binary.UserIdHelper;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.google.idea.blaze.base.sync.data.BlazeDataStorage;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import java.util.Collections;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Run context for android_binary. */
-abstract class BlazeAndroidBinaryMobileInstallRunContextBase implements BlazeAndroidRunContext {
- protected final Project project;
- protected final AndroidFacet facet;
- protected final RunConfiguration runConfiguration;
- protected final ExecutionEnvironment env;
- protected final BlazeAndroidBinaryRunConfigurationState configState;
- protected final ConsoleProvider consoleProvider;
- protected final ApplicationIdProvider applicationIdProvider;
- protected final ApkBuildStep buildStep;
- private final String launchId;
-
- public BlazeAndroidBinaryMobileInstallRunContextBase(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- this.project = project;
- this.facet = facet;
- this.runConfiguration = runConfiguration;
- this.env = env;
- this.configState = configState;
- this.consoleProvider = new BlazeAndroidBinaryConsoleProvider(project);
- this.buildStep = buildStep;
- this.applicationIdProvider = new BlazeAndroidBinaryApplicationIdProvider(buildStep);
- this.launchId = launchId;
- }
-
- @Override
- public BlazeAndroidDeviceSelector getDeviceSelector() {
- return new BlazeAndroidDeviceSelector.NormalDeviceSelector();
- }
-
- @Override
- public void augmentLaunchOptions(LaunchOptions.Builder options) {
- options
- .setDeploy(buildStep.needsIdeDeploy())
- .setOpenLogcatAutomatically(configState.showLogcatAutomatically());
- // This is needed for compatibility with #api211
- options.addExtraOptions(
- ImmutableMap.of("android.profilers.state", configState.getProfilerState()));
- }
-
- @Override
- public ConsoleProvider getConsoleProvider() {
- return consoleProvider;
- }
-
- @Override
- public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
- return applicationIdProvider;
- }
-
- @Override
- public ApkBuildStep getBuildStep() {
- return buildStep;
- }
-
- @Override
- public ProfilerState getProfileState() {
- return configState.getProfilerState();
- }
-
- @Override
- public ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException {
- if (!buildStep.needsIdeDeploy()) {
- return ImmutableList.of();
- }
-
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
-
- String packageName = deployInfo.getMergedManifest().packageName;
- if (packageName == null) {
- throw new ExecutionException("Could not determine package name from deploy info");
- }
-
- ApkInfo info =
- new ApkInfo(
- deployInfo.getApksToDeploy().stream()
- .map(file -> new ApkFileUnit(BlazeDataStorage.WORKSPACE_MODULE_NAME, file))
- .collect(Collectors.toList()),
- packageName);
-
- BlazeLaunchTask deployTask =
- DeployTasksCompat.createDeployTask(project, Collections.singletonList(info), launchOptions);
- return ImmutableList.of(new DeploymentTimingReporterTask(launchId, deployTask));
- }
-
- @Nullable
- @Override
- public Integer getUserId(IDevice device) throws ExecutionException {
- return UserIdHelper.getUserIdFromConfigurationState(project, device, configState);
- }
-
- @Override
- public BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException {
- return new BlazeAndroidLaunchTasksProvider(
- project, this, applicationIdProvider, launchOptionsBuilder);
- }
-
- @Override
- public String getAmStartOptions() {
- return configState.getAmStartOptions();
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextCompat.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextCompat.java
deleted file mode 100644
index 29411ebad5a..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextCompat.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary.mobileinstall;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Compatct class for {@link BlazeAndroidBinaryMobileInstallRunContext}. */
-public class BlazeAndroidBinaryMobileInstallRunContextCompat
- extends BlazeAndroidBinaryMobileInstallRunContext {
-
- public BlazeAndroidBinaryMobileInstallRunContextCompat(
- Project project,
- AndroidFacet facet,
- BlazeCommandRunConfiguration configuration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, configuration, env, configState, buildStep, launchId);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidDebuggerService.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidDebuggerService.java
deleted file mode 100644
index c8658223baa..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidDebuggerService.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.execution.common.debug.impl.java.AndroidJavaDebugger;
-import com.android.tools.ndk.run.editor.AutoAndroidDebuggerState;
-import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.android.cppimpl.debug.BlazeAutoAndroidDebugger;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
-import com.intellij.ide.plugins.PluginManagerCore;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-
-/** Provides android debuggers and debugger states for blaze projects. */
-public interface BlazeAndroidDebuggerService {
-
- static BlazeAndroidDebuggerService getInstance(Project project) {
- return project.getService(BlazeAndroidDebuggerService.class);
- }
-
- /** Returns the standard debugger for non-native (Java) debugging. */
- AndroidDebugger getDebugger();
-
- /** Returns the standard debugger for native (C++) debugging. */
- AndroidDebugger getNativeDebugger();
-
- /**
- * Performs additional necessary setup for native debugging, incorporating info from {@link
- * BlazeAndroidDeployInfo}.
- */
- void configureNativeDebugger(
- AndroidDebuggerState state, @Nullable BlazeAndroidDeployInfo deployInfo);
-
- /** Default debugger service. */
- class DefaultDebuggerService implements BlazeAndroidDebuggerService {
- private final Project project;
-
- public DefaultDebuggerService(Project project) {
- this.project = project;
- }
-
- @Override
- public AndroidDebugger getDebugger() {
- return new AndroidJavaDebugger();
- }
-
- @Override
- public AndroidDebugger getNativeDebugger() {
- return new BlazeAutoAndroidDebugger();
- }
-
- @Override
- public void configureNativeDebugger(
- AndroidDebuggerState rawState, @Nullable BlazeAndroidDeployInfo deployInfo) {
- if (!isNdkPluginLoaded() && !(rawState instanceof AutoAndroidDebuggerState)) {
- return;
- }
- AutoAndroidDebuggerState state = (AutoAndroidDebuggerState) rawState;
-
- // Source code is always relative to the workspace root in a blaze project.
- String workingDirPath = WorkspaceRoot.fromProject(project).directory().getPath();
- state.setWorkingDir(workingDirPath);
-
- // Remote built binaries may use /proc/self/cwd to represent the working directory,
- // so we manually map /proc/self/cwd to the workspace root. We used to use
- // `plugin.symbol-file.dwarf.comp-dir-symlink-paths = "/proc/self/cwd"`
- // to automatically resolve this, but it's no longer supported in newer versions of
- // LLDB.
- String sourceMapToWorkspaceRootCommand =
- "settings append target.source-map /proc/self/cwd/ " + workingDirPath;
-
- ImmutableList startupCommands =
- ImmutableList.builder()
- .addAll(state.getUserStartupCommands())
- .add(sourceMapToWorkspaceRootCommand)
- .build();
- state.setUserStartupCommands(startupCommands);
-
- // NDK plugin will pass symbol directories to LLDB as `settings append
- // target.exec-search-paths`.
- if (deployInfo != null) {
- state.setSymbolDirs(
- deployInfo.getSymbolFiles().stream()
- .map(symbol -> symbol.getParentFile().getAbsolutePath())
- .collect(ImmutableList.toImmutableList()));
- }
- }
- }
-
- static boolean isNdkPluginLoaded() {
- return PluginManagerCore.getLoadedPlugins().stream()
- .anyMatch(
- d -> d.isEnabled() && d.getPluginId().getIdString().equals("com.android.tools.ndk"));
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidLaunchTasksProvider.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidLaunchTasksProvider.java
deleted file mode 100644
index 4f8d0d3976c..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidLaunchTasksProvider.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import static com.android.tools.idea.profilers.AndroidProfilerLaunchTaskContributor.isProfilerLaunch;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.deployer.ApkVerifierTracker;
-import com.android.tools.idea.editors.literals.LiveEditService;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.profilers.AndroidProfilerLaunchTaskContributor;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTaskWrapper;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.deployment.liveedit.LiveEditApp;
-import com.android.tools.idea.run.tasks.ClearLogcatTask;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.android.tools.idea.run.tasks.DismissKeyguardTask;
-import com.android.tools.idea.run.tasks.ShowLogcatTask;
-import com.android.tools.idea.run.tasks.StartLiveUpdateMonitoringTask;
-import com.android.tools.ndk.run.editor.AutoAndroidDebuggerState;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.idea.blaze.android.run.binary.UserIdHelper;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.common.experiments.BoolExperiment;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Set;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** Normal launch tasks provider. #api4.1 */
-public class BlazeAndroidLaunchTasksProvider implements BlazeLaunchTasksProvider {
- public static final String NATIVE_DEBUGGING_ENABLED = "NATIVE_DEBUGGING_ENABLED";
- private static final Logger LOG = Logger.getInstance(BlazeAndroidLaunchTasksProvider.class);
- private static final BoolExperiment isLiveEditEnabled =
- new BoolExperiment("aswb.live.edit.enabled", false);
-
- private final Project project;
- private final BlazeAndroidRunContext runContext;
- private final ApplicationIdProvider applicationIdProvider;
- private final LaunchOptions.Builder launchOptionsBuilder;
-
- public BlazeAndroidLaunchTasksProvider(
- Project project,
- BlazeAndroidRunContext runContext,
- ApplicationIdProvider applicationIdProvider,
- LaunchOptions.Builder launchOptionsBuilder) {
- this.project = project;
- this.runContext = runContext;
- this.applicationIdProvider = applicationIdProvider;
- this.launchOptionsBuilder = launchOptionsBuilder;
- }
-
- @NotNull
- @Override
- public List getTasks(@NotNull IDevice device) throws ExecutionException {
- final List launchTasks = Lists.newArrayList();
-
- String packageName;
- try {
- packageName = applicationIdProvider.getPackageName();
- } catch (ApkProvisionException e) {
- throw new ExecutionException("Unable to determine application id: " + e);
- }
-
- Integer userId = runContext.getUserId(device);
- String userIdFlags = UserIdHelper.getFlagsFromUserId(userId);
- String skipVerification =
- ApkVerifierTracker.getSkipVerificationInstallationFlag(device, packageName);
- String pmInstallOption;
- if (skipVerification != null) {
- pmInstallOption = userIdFlags + " " + skipVerification;
- } else {
- pmInstallOption = userIdFlags;
- }
- launchOptionsBuilder.setPmInstallOptions(d -> pmInstallOption);
-
- LaunchOptions launchOptions = launchOptionsBuilder.build();
-
- // NOTE: Task for opening the profiler tool-window should come before deployment
- // to ensure the tool-window opens correctly. This is required because starting
- // the profiler session requires the tool-window to be open.
- if (isProfilerLaunch(runContext.getExecutor())) {
- launchTasks.add(new BlazeAndroidOpenProfilerWindowTask(project));
- }
-
- // TODO(kovalp): Check if there's any drawback to add these tasks with BlazeLaunchTaskWrapper
- // since it's different with ag/21610897
- if (launchOptions.isClearLogcatBeforeStart()) {
- launchTasks.add(new BlazeLaunchTaskWrapper(new ClearLogcatTask(project)));
- }
-
- launchTasks.add(new BlazeLaunchTaskWrapper(new DismissKeyguardTask()));
-
- if (launchOptions.isDeploy()) {
- ImmutableList deployTasks = runContext.getDeployTasks(device, launchOptions);
- launchTasks.addAll(deployTasks);
- }
-
- try {
- if (launchOptions.isDebug()) {
- launchTasks.add(
- new CheckApkDebuggableTask(project, runContext.getBuildStep().getDeployInfo()));
- }
-
- ImmutableList.Builder amStartOptions = ImmutableList.builder();
- amStartOptions.add(runContext.getAmStartOptions());
- if (isProfilerLaunch(runContext.getExecutor())) {
- amStartOptions.add(
- AndroidProfilerLaunchTaskContributor.getAmStartOptions(
- project,
- packageName,
- runContext.getProfileState(),
- device,
- runContext.getExecutor()));
- launchTasks.add(
- new BlazeLaunchTaskWrapper(
- new AndroidProfilerLaunchTaskContributor.AndroidProfilerToolWindowLaunchTask(
- project, packageName)));
- }
- BlazeLaunchTask appLaunchTask =
- runContext.getApplicationLaunchTask(
- launchOptions, userId, String.join(" ", amStartOptions.build()));
- if (appLaunchTask != null) {
- launchTasks.add(appLaunchTask);
- if (isLiveEditEnabled.getValue()) {
- // TODO(b/277244508): Fix Live Edit for Giraffe
- Set apks =
- runContext.getBuildStep().getDeployInfo().getApksToDeploy().stream()
- .map(f -> f.toPath())
- .collect(ImmutableSet.toImmutableSet());
-
- LiveEditApp app = new LiveEditApp(apks, device.getVersion().getApiLevel());
- launchTasks.add(
- new BlazeLaunchTaskWrapper(
- new StartLiveUpdateMonitoringTask(
- () ->
- LiveEditService.getInstance(project)
- .getDeployMonitor()
- .notifyAppDeploy(packageName, device, app))));
- }
- }
- } catch (ApkProvisionException e) {
- throw new ExecutionException("Unable to determine application id: " + e);
- }
-
- if (launchOptions.isOpenLogcatAutomatically()) {
- launchTasks.add(new BlazeLaunchTaskWrapper(new ShowLogcatTask(project, packageName)));
- }
-
- return ImmutableList.copyOf(launchTasks);
- }
-
- @Override
- @Nullable
- public ConnectDebuggerTask getConnectDebuggerTask() {
- LaunchOptions launchOptions = launchOptionsBuilder.build();
- if (!launchOptions.isDebug()) {
- return null;
- }
-
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = runContext.getBuildStep().getDeployInfo();
- } catch (ApkProvisionException e) {
- LOG.error(e);
- deployInfo = null;
- }
-
- BlazeAndroidDebuggerService debuggerService = BlazeAndroidDebuggerService.getInstance(project);
- if (isNativeDebuggingEnabled(launchOptions)) {
- AndroidDebugger debugger = debuggerService.getNativeDebugger();
- // The below state type should be AutoAndroidDebuggerState, but referencing it will crash the
- // task if the NDK plugin is not loaded.
- AndroidDebuggerState state = debugger.createState();
- debuggerService.configureNativeDebugger(state, deployInfo);
- return runContext.getDebuggerTask(debugger, state);
- } else {
- AndroidDebugger debugger = debuggerService.getDebugger();
- return runContext.getDebuggerTask(debugger, debugger.createState());
- }
- }
-
- private boolean isNativeDebuggingEnabled(LaunchOptions launchOptions) {
- Object flag = launchOptions.getExtraOption(NATIVE_DEBUGGING_ENABLED);
- return flag instanceof Boolean && (Boolean) flag;
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidRunConfigurationRunner.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidRunConfigurationRunner.java
deleted file mode 100644
index 78728d9c46f..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidRunConfigurationRunner.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.AppRunSettings;
-import com.android.tools.idea.execution.common.ApplicationDeployer;
-import com.android.tools.idea.execution.common.ComponentLaunchOptions;
-import com.android.tools.idea.execution.common.DeployOptions;
-import com.android.tools.idea.run.ApkProvider;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.DeviceFutures;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeAndroidConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidComplicationConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutorRunProfileState;
-import com.android.tools.idea.run.configuration.execution.AndroidTileConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidWatchFaceConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.ComplicationLaunchOptions;
-import com.android.tools.idea.run.configuration.execution.TileLaunchOptions;
-import com.android.tools.idea.run.configuration.execution.WatchFaceLaunchOptions;
-import com.android.tools.idea.run.editor.DeployTarget;
-import com.android.tools.idea.run.editor.DeployTargetState;
-import com.android.tools.idea.run.util.LaunchUtils;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep;
-import com.google.idea.blaze.android.run.deployinfo.BlazeApkProviderService;
-import com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator;
-import com.google.idea.blaze.base.command.BlazeInvocationContext.ContextType;
-import com.google.idea.blaze.base.experiments.ExperimentScope;
-import com.google.idea.blaze.base.issueparser.BlazeIssueParser;
-import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationRunner;
-import com.google.idea.blaze.base.scope.BlazeContext;
-import com.google.idea.blaze.base.scope.Scope;
-import com.google.idea.blaze.base.scope.ScopedTask;
-import com.google.idea.blaze.base.scope.output.IssueOutput;
-import com.google.idea.blaze.base.scope.scopes.IdeaLogScope;
-import com.google.idea.blaze.base.scope.scopes.ProblemsViewScope;
-import com.google.idea.blaze.base.scope.scopes.ToolWindowScope;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.settings.BlazeUserSettings;
-import com.google.idea.blaze.base.toolwindow.Task;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunProfileState;
-import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.ui.ConsoleView;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Key;
-import java.util.Collections;
-import java.util.concurrent.CancellationException;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.android.util.AndroidBundle;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Supports the execution. Used by both android_binary and android_test.
- *
- * Builds the APK and installs it, launches and debug tasks, etc.
- *
- *
Any indirection between android_binary/android_test, mobile-install, InstantRun etc. should
- * come via the strategy class.
- */
-public final class BlazeAndroidRunConfigurationRunner
- implements BlazeCommandRunConfigurationRunner {
-
- private static final Logger LOG = Logger.getInstance(BlazeAndroidRunConfigurationRunner.class);
-
- private static final Key RUN_CONTEXT_KEY =
- Key.create("blaze.run.context");
- public static final Key DEVICE_SESSION_KEY =
- Key.create("blaze.device.session");
-
- private final Module module;
- private final BlazeAndroidRunContext runContext;
- private final BlazeCommandRunConfiguration runConfig;
-
- public BlazeAndroidRunConfigurationRunner(
- Module module, BlazeAndroidRunContext runContext, BlazeCommandRunConfiguration runConfig) {
- this.module = module;
- this.runContext = runContext;
- this.runConfig = runConfig;
- }
-
- @Override
- @Nullable
- public final RunProfileState getRunProfileState(final Executor executor, ExecutionEnvironment env)
- throws ExecutionException {
-
- final AndroidFacet facet = AndroidFacet.getInstance(module);
- assert facet != null : "Enforced by fatal validation check in createRunner.";
- final Project project = env.getProject();
-
- boolean isDebug = executor instanceof DefaultDebugExecutor;
-
- BlazeAndroidDeviceSelector deviceSelector = runContext.getDeviceSelector();
- BlazeAndroidDeviceSelector.DeviceSession deviceSession =
- deviceSelector.getDevice(project, executor, env, isDebug, runConfig.getUniqueID());
-
- if (deviceSession == null) {
- return null;
- }
-
- DeployTarget deployTarget = deviceSession.deployTarget;
- if (deployTarget != null && deployTarget.hasCustomRunProfileState(executor)) {
- return deployTarget.getRunProfileState(executor, env, DeployTargetState.DEFAULT_STATE);
- }
-
- DeviceFutures deviceFutures = deviceSession.deviceFutures;
- if (deviceFutures == null) {
- // The user deliberately canceled, or some error was encountered and exposed by the chooser.
- // Quietly exit.
- return null;
- }
-
- if (deviceFutures.get().isEmpty()) {
- throw new ExecutionException(AndroidBundle.message("deployment.target.not.found"));
- }
-
- if (isDebug) {
- String error = canDebug(deviceFutures, facet, module.getName());
- if (error != null) {
- throw new ExecutionException(error);
- }
- }
-
- LaunchOptions.Builder launchOptionsBuilder = getDefaultLaunchOptions().setDebug(isDebug);
- runContext.augmentLaunchOptions(launchOptionsBuilder);
-
- // Store the run context on the execution environment so before-run tasks can access it.
- env.putCopyableUserData(RUN_CONTEXT_KEY, runContext);
- env.putCopyableUserData(DEVICE_SESSION_KEY, deviceSession);
-
- BlazeAndroidConfigurationExecutor runner =
- new BlazeAndroidConfigurationExecutor(
- runContext.getConsoleProvider(),
- runContext.getApplicationIdProvider(),
- env,
- deviceFutures,
- runContext.getLaunchTasksProvider(launchOptionsBuilder),
- LaunchOptions.builder().build());
- return new AndroidConfigurationExecutorRunProfileState(runner);
- }
-
- private RunProfileState getWearExecutor(
- ComponentLaunchOptions launchOptions, ExecutionEnvironment env, DeployTarget deployTarget)
- throws ExecutionException {
-
- AppRunSettings settings =
- new AppRunSettings() {
- @NotNull
- @Override
- public DeployOptions getDeployOptions() {
- return new DeployOptions(Collections.emptyList(), "", true, true);
- }
-
- @NotNull
- @Override
- public ComponentLaunchOptions getComponentLaunchOptions() {
- return launchOptions;
- }
-
- @Override
- public Module getModule() {
- return runConfig.getModules()[0];
- }
- };
-
- AndroidConfigurationExecutor configurationExecutor;
- ApplicationIdProvider appIdProvider = runContext.getApplicationIdProvider();
- ApkProvider apkProvider =
- BlazeApkProviderService.getInstance()
- .getApkProvider(env.getProject(), runContext.getBuildStep());
- DeviceFutures deviceFutures = deployTarget.getDevices(env.getProject());
-
- if (launchOptions instanceof TileLaunchOptions) {
- configurationExecutor =
- new AndroidTileConfigurationExecutor(
- env, deviceFutures, settings, appIdProvider, apkProvider) {
- @NotNull
- @Override
- public ApplicationDeployer getApplicationDeployer(@NotNull ConsoleView console)
- throws ExecutionException {
- if (runContext.getBuildStep() instanceof MobileInstallBuildStep) {
- return new MobileInstallApplicationDeployer(console);
- }
- return super.getApplicationDeployer(console);
- }
- };
- } else if (launchOptions instanceof WatchFaceLaunchOptions) {
- configurationExecutor =
- new AndroidWatchFaceConfigurationExecutor(
- env, deviceFutures, settings, appIdProvider, apkProvider) {
- @NotNull
- @Override
- public ApplicationDeployer getApplicationDeployer(@NotNull ConsoleView console)
- throws ExecutionException {
- if (runContext.getBuildStep() instanceof MobileInstallBuildStep) {
- return new MobileInstallApplicationDeployer(console);
- }
- return super.getApplicationDeployer(console);
- }
- };
- } else if (launchOptions instanceof ComplicationLaunchOptions) {
- configurationExecutor =
- new AndroidComplicationConfigurationExecutor(
- env, deviceFutures, settings, appIdProvider, apkProvider) {
- @NotNull
- @Override
- public ApplicationDeployer getApplicationDeployer(@NotNull ConsoleView console)
- throws ExecutionException {
- if (runContext.getBuildStep() instanceof MobileInstallBuildStep) {
- return new MobileInstallApplicationDeployer(console);
- }
- return super.getApplicationDeployer(console);
- }
- };
- } else {
- throw new RuntimeException("Unknown launch options " + launchOptions.getClass().getName());
- }
-
- return new AndroidConfigurationExecutorRunProfileState(
- new BlazeWrapperForAndroidConfigurationExecutor(configurationExecutor));
- }
-
- @Nullable
- private static String canDebug(
- DeviceFutures deviceFutures, AndroidFacet facet, String moduleName) {
- // If we are debugging on a device, then the app needs to be debuggable
- for (ListenableFuture future : deviceFutures.get()) {
- if (!future.isDone()) {
- // this is an emulator, and we assume that all emulators are debuggable
- continue;
- }
- IDevice device = Futures.getUnchecked(future);
- if (!LaunchUtils.canDebugAppOnDevice(facet, device)) {
- return AndroidBundle.message(
- "android.cannot.debug.noDebugPermissions", moduleName, device.getName());
- }
- }
- return null;
- }
-
- private static LaunchOptions.Builder getDefaultLaunchOptions() {
- return LaunchOptionsCompat.getDefaultLaunchOptions();
- }
-
- @Override
- public boolean executeBeforeRunTask(ExecutionEnvironment env) {
- final Project project = env.getProject();
- BlazeUserSettings settings = BlazeUserSettings.getInstance();
- return Scope.root(
- context -> {
- context
- .push(new ProblemsViewScope(project, settings.getShowProblemsViewOnRun()))
- .push(new ExperimentScope())
- .push(
- new ToolWindowScope.Builder(
- project, new Task(project, "Build apk", Task.Type.BEFORE_LAUNCH))
- .setPopupBehavior(settings.getShowBlazeConsoleOnRun())
- .setIssueParsers(
- BlazeIssueParser.defaultIssueParsers(
- project,
- WorkspaceRoot.fromProject(project),
- ContextType.BeforeRunTask))
- .build())
- .push(new IdeaLogScope());
-
- BlazeAndroidRunContext runContext = env.getCopyableUserData(RUN_CONTEXT_KEY);
- if (runContext == null) {
- IssueOutput.error("Could not find run context. Please try again").submit(context);
- return false;
- }
- BlazeAndroidDeviceSelector.DeviceSession deviceSession =
- env.getCopyableUserData(DEVICE_SESSION_KEY);
-
- ApkBuildStep buildStep = runContext.getBuildStep();
- ScopedTask buildTask =
- new ScopedTask(context) {
- @Override
- protected Void execute(BlazeContext context) {
- buildStep.build(context, deviceSession);
- return null;
- }
- };
-
- try {
- ListenableFuture buildFuture =
- ProgressiveTaskWithProgressIndicator.builder(
- project,
- String.format("Executing %s apk build", Blaze.buildSystemName(project)))
- .submitTaskWithResult(buildTask);
- Futures.getChecked(buildFuture, ExecutionException.class);
- } catch (ExecutionException e) {
- context.setHasError();
- } catch (CancellationException e) {
- context.setCancelled();
- } catch (Exception e) {
- LOG.error(e);
- return false;
- }
- return context.shouldContinue();
- });
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidRunContext.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidRunContext.java
deleted file mode 100644
index c1e33020bae..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeAndroidRunContext.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.common.collect.ImmutableList;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import javax.annotation.Nullable;
-import org.jetbrains.annotations.NotNull;
-
-/** Instantiated when the configuration wants to run. */
-public interface BlazeAndroidRunContext {
-
- BlazeAndroidDeviceSelector getDeviceSelector();
-
- void augmentLaunchOptions(LaunchOptions.Builder options);
-
- ConsoleProvider getConsoleProvider();
-
- ApkBuildStep getBuildStep();
-
- ApplicationIdProvider getApplicationIdProvider() throws ExecutionException;
-
- BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException;
-
- /** Returns the tasks to deploy the application. */
- ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException;
-
- /** Returns the task to launch the application. */
- @Nullable
- BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions,
- @Nullable Integer userId,
- @NotNull String contributorsAmStartOptions)
- throws ExecutionException;
-
- /** Returns the task to connect the debugger. */
- @Nullable
- ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState);
-
- @Nullable
- Integer getUserId(IDevice device) throws ExecutionException;
-
- String getAmStartOptions();
-
- Executor getExecutor();
-
- ProfilerState getProfileState();
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeWrapperForAndroidConfigurationExecutor.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeWrapperForAndroidConfigurationExecutor.java
deleted file mode 100644
index be6f1f8552c..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/BlazeWrapperForAndroidConfigurationExecutor.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.run.DeviceFutures;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutor;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.progress.ProgressIndicator;
-import org.jetbrains.annotations.NotNull;
-
-/** Implementation of {@code AndroidConfigurationExecutor} specific for Blaze project. */
-public class BlazeWrapperForAndroidConfigurationExecutor implements AndroidConfigurationExecutor {
- private final AndroidConfigurationExecutor delegateExecutor;
-
- BlazeWrapperForAndroidConfigurationExecutor(@NotNull AndroidConfigurationExecutor executor) {
- delegateExecutor = executor;
- }
-
- @NotNull
- @Override
- public RunConfiguration getConfiguration() {
- return delegateExecutor.getConfiguration();
- }
-
- @NotNull
- @Override
- public DeviceFutures getDeviceFutures() {
- return delegateExecutor.getDeviceFutures();
- }
-
- @NotNull
- @Override
- public RunContentDescriptor run(@NotNull ProgressIndicator indicator) throws ExecutionException {
- return delegateExecutor.run(indicator);
- }
-
- @NotNull
- @Override
- public RunContentDescriptor debug(@NotNull ProgressIndicator indicator)
- throws ExecutionException {
- return delegateExecutor.debug(indicator);
- }
-
- @NotNull
- @Override
- public RunContentDescriptor applyChanges(@NotNull ProgressIndicator indicator) {
- throw new RuntimeException("Apply code changes is not supported for blaze");
- }
-
- @NotNull
- @Override
- public RunContentDescriptor applyCodeChanges(@NotNull ProgressIndicator indicator) {
- throw new RuntimeException("Apply changes is not supported for blaze");
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/LaunchOptionsCompat.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/LaunchOptionsCompat.java
deleted file mode 100644
index 5a606a8a2ea..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/LaunchOptionsCompat.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.run.LaunchOptions;
-
-/** Compat class for LunchOptions.Builder. */
-public class LaunchOptionsCompat {
-
- private LaunchOptionsCompat() {}
-
- /** Create default launch options to maintain compatibility with #api211. */
- public static LaunchOptions.Builder getDefaultLaunchOptions() {
- return LaunchOptions.builder().setClearLogcatBeforeStart(false);
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/MobileInstallApplicationDeployer.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/MobileInstallApplicationDeployer.java
deleted file mode 100644
index dad762309be..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/runner/MobileInstallApplicationDeployer.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.deployer.ApkParser;
-import com.android.tools.deployer.Deployer;
-import com.android.tools.deployer.DeployerException;
-import com.android.tools.deployer.model.Apk;
-import com.android.tools.deployer.model.App;
-import com.android.tools.idea.execution.common.ApplicationDeployer;
-import com.android.tools.idea.execution.common.DeployOptions;
-import com.android.tools.idea.run.ApkFileUnit;
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.configuration.execution.AdbCommandCaptureLoggerWithConsole;
-import com.intellij.execution.ui.ConsoleView;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.progress.ProgressIndicator;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.stream.Collectors;
-import org.jetbrains.annotations.NotNull;
-
-/** Deploys mobile install application. */
-public class MobileInstallApplicationDeployer implements ApplicationDeployer {
- private static final Logger LOG = Logger.getInstance(MobileInstallApplicationDeployer.class);
- private final ConsoleView myConsole;
-
- public MobileInstallApplicationDeployer(ConsoleView console) {
- myConsole = console;
- }
-
- @NotNull
- @Override
- public Deployer.Result fullDeploy(
- @NotNull IDevice device,
- @NotNull ApkInfo apkInfo,
- @NotNull DeployOptions deployOptions,
- ProgressIndicator indicator)
- throws DeployerException {
- final List apkPaths =
- apkInfo.getFiles().stream()
- .map(ApkFileUnit::getApkPath)
- .map(Path::toString)
- .collect(Collectors.toList());
- final List apks = new ApkParser().parsePaths(apkPaths);
- App app =
- new App(
- apkInfo.getApplicationId(),
- apks,
- device,
- new AdbCommandCaptureLoggerWithConsole(LOG, myConsole));
- return new Deployer.Result(false, false, false, app);
- }
-
- @NotNull
- @Override
- public Deployer.Result applyChangesDeploy(
- @NotNull IDevice device,
- @NotNull ApkInfo app,
- @NotNull DeployOptions deployOptions,
- ProgressIndicator indicator)
- throws DeployerException {
- throw new RuntimeException("Apply changes is not supported for mobile-install");
- }
-
- @NotNull
- @Override
- public Deployer.Result applyCodeChangesDeploy(
- @NotNull IDevice device,
- @NotNull ApkInfo app,
- @NotNull DeployOptions deployOptions,
- ProgressIndicator indicator)
- throws DeployerException {
- throw new RuntimeException("Apply code changes is not supported for mobile-install");
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/BlazeAndroidTestProgramRunner.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/BlazeAndroidTestProgramRunner.java
deleted file mode 100644
index eab7b24890f..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/BlazeAndroidTestProgramRunner.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.tools.idea.run.configuration.AndroidConfigurationProgramRunner;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutor;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfigurationType;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunProfile;
-import com.intellij.execution.configurations.RunProfileState;
-import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.executors.DefaultRunExecutor;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.progress.ProgressIndicator;
-import java.util.Collections;
-import java.util.List;
-import org.jetbrains.annotations.NotNull;
-
-/** Program runner for configurations from {@link BlazeAndroidTestRunConfigurationHandler}. */
-public class BlazeAndroidTestProgramRunner extends AndroidConfigurationProgramRunner {
- @Override
- public boolean canRun(String executorId, RunProfile profile) {
- BlazeAndroidRunConfigurationHandler handler =
- BlazeAndroidRunConfigurationHandler.getHandlerFrom(profile);
- if (!(handler instanceof BlazeAndroidTestRunConfigurationHandler)) {
- return false;
- }
- if (!(profile instanceof BlazeCommandRunConfiguration)) {
- return false;
- }
- return DefaultRunExecutor.EXECUTOR_ID.equals(executorId)
- || DefaultDebugExecutor.EXECUTOR_ID.equals(executorId);
- }
-
- @Override
- public String getRunnerId() {
- return "AndroidTestProgramRunner";
- }
-
- @Override
- protected boolean canRunWithMultipleDevices(@NotNull String executorId) {
- return true;
- }
-
- @NotNull
- @Override
- protected List getSupportedConfigurationTypeIds() {
- return Collections.singletonList(BlazeCommandRunConfigurationType.getInstance().getId());
- }
-
- @NotNull
- @Override
- protected RunContentDescriptor run(
- @NotNull ExecutionEnvironment environment,
- @NotNull RunProfileState state,
- @NotNull ProgressIndicator indicator)
- throws ExecutionException {
- final AndroidConfigurationExecutor state1 = (AndroidConfigurationExecutor) state;
- if (DefaultDebugExecutor.EXECUTOR_ID.equals(environment.getExecutor().getId())) {
- return state1.debug(indicator);
- }
- if (DefaultRunExecutor.EXECUTOR_ID.equals(environment.getExecutor().getId())) {
- return state1.run(indicator);
- }
- throw new RuntimeException("Unsupported executor");
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunConfigurationHandler.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunConfigurationHandler.java
deleted file mode 100644
index 050ddc03fee..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunConfigurationHandler.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import static com.android.tools.idea.run.deployment.DeviceAndSnapshotComboBoxAction.DEPLOYS_TO_LOCAL_DEVICE;
-
-import com.android.tools.idea.run.ValidationError;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.idea.blaze.android.run.ApkBuildStepProvider;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationCommonState;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationValidationUtil;
-import com.google.idea.blaze.android.run.LaunchMetrics;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunConfigurationRunner;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.google.idea.blaze.android.run.runner.FullApkBuildStep;
-import com.google.idea.blaze.android.run.test.BlazeAndroidTestLaunchMethodsProvider.AndroidTestLaunchMethod;
-import com.google.idea.blaze.base.command.BlazeCommandName;
-import com.google.idea.blaze.base.command.BlazeInvocationContext;
-import com.google.idea.blaze.base.model.primitives.Label;
-import com.google.idea.blaze.base.model.primitives.TargetExpression;
-import com.google.idea.blaze.base.projectview.ProjectViewManager;
-import com.google.idea.blaze.base.projectview.ProjectViewSet;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder;
-import com.google.idea.blaze.base.run.ExecutorType;
-import com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationRunner;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.sync.data.BlazeDataStorage;
-import com.google.idea.blaze.base.sync.projectstructure.ModuleFinder;
-import com.google.idea.blaze.java.AndroidBlazeRules;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.JavaExecutionUtil;
-import com.intellij.execution.configurations.RuntimeConfigurationException;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/**
- * {@link com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationHandler} for
- * android_test targets.
- */
-public class BlazeAndroidTestRunConfigurationHandler
- implements BlazeAndroidRunConfigurationHandler {
- private final Project project;
- private final BlazeAndroidTestRunConfigurationState configState;
-
- BlazeAndroidTestRunConfigurationHandler(BlazeCommandRunConfiguration configuration) {
- this.project = configuration.getProject();
- this.configState =
- new BlazeAndroidTestRunConfigurationState(
- Blaze.buildSystemName(configuration.getProject()));
- configuration.putUserData(DEPLOYS_TO_LOCAL_DEVICE, true);
- }
-
- @Override
- public BlazeAndroidTestRunConfigurationState getState() {
- return configState;
- }
-
- @Override
- public BlazeAndroidRunConfigurationCommonState getCommonState() {
- return configState.getCommonState();
- }
-
- @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();
-
- ImmutableList blazeFlags =
- configState
- .getCommonState()
- .getExpandedBuildFlags(
- project,
- projectViewSet,
- BlazeCommandName.TEST,
- BlazeInvocationContext.runConfigContext(
- ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), false));
- ImmutableList exeFlags =
- ImmutableList.copyOf(
- configState.getCommonState().getExeFlagsState().getFlagsForExternalProcesses());
-
- // 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();
- Label label = Label.create(configuration.getSingleTarget().toString());
-
- ApkBuildStep buildStep =
- getTestBuildStep(
- project, configState, configuration, blazeFlags, exeFlags, launchId, label);
-
- BlazeAndroidRunContext runContext =
- new BlazeAndroidTestRunContext(
- project, facet, configuration, env, configState, label, blazeFlags, buildStep);
-
- LaunchMetrics.logTestLaunch(
- launchId, configState.getLaunchMethod().name(), env.getExecutor().getId());
-
- return new BlazeAndroidRunConfigurationRunner(module, runContext, configuration);
- }
-
- private static ApkBuildStep getTestBuildStep(
- Project project,
- BlazeAndroidTestRunConfigurationState configState,
- BlazeCommandRunConfiguration configuration,
- ImmutableList blazeFlags,
- ImmutableList exeFlags,
- String launchId,
- Label label)
- throws ExecutionException {
- if (configuration.getTargetKind()
- == AndroidBlazeRules.RuleTypes.ANDROID_INSTRUMENTATION_TEST.getKind()) {
- boolean useMobileInstall =
- AndroidTestLaunchMethod.MOBILE_INSTALL.equals(configState.getLaunchMethod());
- return ApkBuildStepProvider.getInstance(Blaze.getBuildSystemName(project))
- .getAitBuildStep(
- project,
- useMobileInstall,
- /* nativeDebuggingEnabled= */ false,
- label,
- blazeFlags,
- exeFlags,
- launchId);
- } else {
- // TODO(b/248317444): This path is only invoked for the deprecated {@code android_test}
- // targets, and should eventually be removed.
- return new FullApkBuildStep(project, label, blazeFlags, /* nativeDebuggingEnabled= */ false);
- }
- }
-
- @Override
- public final void checkConfiguration() throws RuntimeConfigurationException {
- BlazeAndroidRunConfigurationValidationUtil.throwTopConfigurationError(validate());
- }
-
- /**
- * We collect errors rather than throwing to avoid missing fatal errors by exiting early for a
- * warning. We use a separate method for the collection so the compiler prevents us from
- * accidentally throwing.
- */
- private List validate() {
- List errors = Lists.newArrayList();
- errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateWorkspaceModule(project));
- errors.addAll(configState.validate(project));
- return errors;
- }
-
- @Override
- @Nullable
- public String suggestedName(BlazeCommandRunConfiguration configuration) {
- TargetExpression target = configuration.getSingleTarget();
- if (target == null) {
- return null;
- }
- BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
-
- boolean isClassTest =
- configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_CLASS;
- boolean isMethodTest =
- configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_METHOD;
- if ((isClassTest || isMethodTest) && configState.getClassName() != null) {
- // Get the class name without the package.
- String className = JavaExecutionUtil.getPresentableClassName(configState.getClassName());
- if (className != null) {
- String targetString = className;
- if (isMethodTest) {
- targetString += "#" + configState.getMethodName();
- }
-
- if (getState().getLaunchMethod().equals(AndroidTestLaunchMethod.NON_BLAZE)) {
- return targetString;
- } else {
- return nameBuilder.setTargetString(targetString).build();
- }
- }
- }
- return nameBuilder.build();
- }
-
- @Override
- @Nullable
- public BlazeCommandName getCommandName() {
- if (getState().getLaunchMethod().equals(AndroidTestLaunchMethod.BLAZE_TEST)) {
- return BlazeCommandName.TEST;
- } else if (getState().getLaunchMethod().equals(AndroidTestLaunchMethod.MOBILE_INSTALL)) {
- return BlazeCommandName.MOBILE_INSTALL;
- }
- return null;
- }
-
- @Override
- public String getHandlerName() {
- return "Android Test Handler";
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunContext.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunContext.java
deleted file mode 100644
index feaec07157c..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunContext.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-import static com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryNormalBuildRunContextBase.getApkInfoToInstall;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApkProvider;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.deployinfo.BlazeApkProviderService;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.google.idea.blaze.android.run.test.BlazeAndroidTestLaunchMethodsProvider.AndroidTestLaunchMethod;
-import com.google.idea.blaze.base.model.primitives.Label;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.smrunner.BlazeTestUiSession;
-import com.google.idea.blaze.base.run.testlogs.BlazeTestResultHolder;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Run context for android_test. */
-public class BlazeAndroidTestRunContext implements BlazeAndroidRunContext {
- protected final Project project;
- protected final AndroidFacet facet;
- protected final BlazeCommandRunConfiguration runConfiguration;
- protected final ExecutionEnvironment env;
- protected final BlazeAndroidTestRunConfigurationState configState;
- protected final Label label;
- protected final ImmutableList blazeFlags;
- protected final List launchTaskCompleteListeners = Lists.newArrayList();
- protected final ConsoleProvider consoleProvider;
- protected final ApkBuildStep buildStep;
- protected final ApplicationIdProvider applicationIdProvider;
- protected final ApkProvider apkProvider;
- private final BlazeTestResultHolder testResultsHolder = new BlazeTestResultHolder();
-
- public BlazeAndroidTestRunContext(
- Project project,
- AndroidFacet facet,
- BlazeCommandRunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidTestRunConfigurationState configState,
- Label label,
- ImmutableList blazeFlags,
- ApkBuildStep buildStep) {
- this.project = project;
- this.facet = facet;
- this.runConfiguration = runConfiguration;
- this.env = env;
- this.label = label;
- this.configState = configState;
- this.buildStep = buildStep;
- this.blazeFlags = blazeFlags;
- switch (configState.getLaunchMethod()) {
- case MOBILE_INSTALL:
- case NON_BLAZE:
- consoleProvider = new AitIdeTestConsoleProvider(runConfiguration, configState);
- break;
- case BLAZE_TEST:
- BlazeTestUiSession session =
- BlazeTestUiSession.create(ImmutableList.of(), testResultsHolder);
- this.consoleProvider = new AitBlazeTestConsoleProvider(project, runConfiguration, session);
- break;
- default:
- throw new IllegalStateException(
- "Unsupported launch method " + configState.getLaunchMethod());
- }
- applicationIdProvider = new BlazeAndroidTestApplicationIdProvider(buildStep);
- apkProvider = BlazeApkProviderService.getInstance().getApkProvider(project, buildStep);
- }
-
- @Override
- public BlazeAndroidDeviceSelector getDeviceSelector() {
- return new BlazeAndroidDeviceSelector.NormalDeviceSelector();
- }
-
- @Override
- public void augmentLaunchOptions(LaunchOptions.Builder options) {
- options.setDeploy(!configState.getLaunchMethod().equals(AndroidTestLaunchMethod.BLAZE_TEST));
- }
-
- @Override
- public ConsoleProvider getConsoleProvider() {
- return consoleProvider;
- }
-
- @Override
- public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
- return applicationIdProvider;
- }
-
- @Nullable
- @Override
- public ApkBuildStep getBuildStep() {
- return buildStep;
- }
-
- @Override
- public ProfilerState getProfileState() {
- return null;
- }
-
- @Override
- public BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException {
- return new BlazeAndroidLaunchTasksProvider(
- project, this, applicationIdProvider, launchOptionsBuilder);
- }
-
- @Override
- public ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException {
- if (configState.getLaunchMethod() != AndroidTestLaunchMethod.NON_BLAZE) {
- return ImmutableList.of();
- }
- return ImmutableList.of(
- DeployTasksCompat.createDeployTask(
- project, getApkInfoToInstall(device, launchOptions, apkProvider), launchOptions));
- }
-
- @Override
- @Nullable
- public BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions, @Nullable Integer userId, String contributorsAmStartOptions)
- throws ExecutionException {
- switch (configState.getLaunchMethod()) {
- case BLAZE_TEST:
- BlazeAndroidTestFilter testFilter =
- new BlazeAndroidTestFilter(
- configState.getTestingType(),
- configState.getClassName(),
- configState.getMethodName(),
- configState.getPackageName());
- return new BlazeAndroidTestLaunchTask(
- project,
- label,
- blazeFlags,
- testFilter,
- this,
- launchOptions.isDebug(),
- testResultsHolder);
- case NON_BLAZE:
- case MOBILE_INSTALL:
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
- return StockAndroidTestLaunchTask.getStockTestLaunchTask(
- configState, applicationIdProvider, launchOptions.isDebug(), deployInfo, project);
- }
- throw new AssertionError();
- }
-
- @Override
- @SuppressWarnings({"unchecked", "rawtypes"}) // Raw type from upstream.
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- switch (configState.getLaunchMethod()) {
- case BLAZE_TEST:
- return new ConnectBlazeTestDebuggerTask(this, androidDebugger, androidDebuggerState);
- case NON_BLAZE:
- case MOBILE_INSTALL:
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet, 30);
- }
- throw new AssertionError();
- }
-
- void onLaunchTaskComplete() {
- for (Runnable runnable : launchTaskCompleteListeners) {
- runnable.run();
- }
- }
-
- void addLaunchTaskCompleteListener(Runnable runnable) {
- launchTaskCompleteListeners.add(runnable);
- }
-
- @Override
- public Executor getExecutor() {
- return env.getExecutor();
- }
-
- @Nullable
- @Override
- public Integer getUserId(IDevice device) {
- return null;
- }
-
- @Override
- public String getAmStartOptions() {
- return "";
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/ConnectBlazeTestDebuggerTask.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/ConnectBlazeTestDebuggerTask.java
deleted file mode 100644
index 3ef2a6c9493..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/ConnectBlazeTestDebuggerTask.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.execution.common.debug.DebugSessionStarter;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.process.ProcessOutputTypes;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.ui.ConsoleView;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.xdebugger.impl.XDebugSessionImpl;
-import java.io.OutputStream;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** Connects the blaze debugger during execution. */
-class ConnectBlazeTestDebuggerTask implements ConnectDebuggerTask {
-
- private final BlazeAndroidTestRunContext runContext;
- private final AndroidDebugger myAndroidDebugger;
- private final S myAndroidDebuggerState;
-
- public ConnectBlazeTestDebuggerTask(
- BlazeAndroidTestRunContext runContext,
- AndroidDebugger androidDebugger,
- S androidDebuggerState) {
- this.runContext = runContext;
- myAndroidDebugger = androidDebugger;
- myAndroidDebuggerState = androidDebuggerState;
- }
-
- /**
- * Wires up listeners to automatically reconnect the debugger for each test method. When you
- * `blaze test` an android_test in debug mode, it kills the instrumentation process between each
- * test method, disconnecting the debugger. We listen for the start of a new method waiting for a
- * debugger, and reconnect. TODO: Support stopping Blaze from the UI. This is hard because we have
- * no way to distinguish process handler termination/debug session ending initiated by the user.
- *
- * @return Promise with debug session or error
- */
- @Override
- public @NotNull XDebugSessionImpl perform(
- @NotNull IDevice device,
- @NotNull String applicationId,
- @NotNull ExecutionEnvironment environment,
- @NotNull ProgressIndicator progressIndicator,
- ConsoleView console) {
- final ProcessHandler masterProcessHandler =
- new ProcessHandler() {
-
- @Override
- protected void destroyProcessImpl() {
- notifyProcessTerminated(0);
- }
-
- @Override
- protected void detachProcessImpl() {
- notifyProcessDetached();
- }
-
- @Override
- public boolean detachIsDefault() {
- return false;
- }
-
- @Override
- public @Nullable OutputStream getProcessInput() {
- return null;
- }
- };
- runContext.addLaunchTaskCompleteListener(
- () -> {
- masterProcessHandler.notifyTextAvailable(
- "Test run completed.\n", ProcessOutputTypes.STDOUT);
- masterProcessHandler.detachProcess();
- });
- return DebugSessionStarter.INSTANCE.attachReattachingDebuggerToStartedProcess(
- device,
- applicationId,
- masterProcessHandler,
- environment,
- myAndroidDebugger,
- myAndroidDebuggerState,
- progressIndicator,
- console,
- Long.MAX_VALUE);
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/StockAndroidTestLaunchTask.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/StockAndroidTestLaunchTask.java
deleted file mode 100644
index b5df308dcea..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/run/test/StockAndroidTestLaunchTask.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.ddmlib.IDevice;
-import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
-import com.android.tools.idea.execution.common.RunConfigurationNotifier;
-import com.android.tools.idea.execution.common.processhandler.AndroidProcessHandler;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchContext;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.configuration.execution.ExecutionUtils;
-import com.android.tools.idea.testartifacts.instrumented.AndroidTestListener;
-import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.android.manifest.ManifestParser;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.ui.ConsoleView;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Computable;
-import com.intellij.openapi.util.text.StringUtil;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.jetbrains.annotations.NotNull;
-
-class StockAndroidTestLaunchTask implements BlazeLaunchTask {
- private static final String ID = "STOCK_ANDROID_TEST";
- private static final Logger LOG = Logger.getInstance(StockAndroidTestLaunchTask.class);
- private final BlazeAndroidTestRunConfigurationState configState;
- private final String instrumentationTestRunner;
- private final String testApplicationId;
- private final boolean waitForDebugger;
-
- StockAndroidTestLaunchTask(
- BlazeAndroidTestRunConfigurationState configState,
- String runner,
- String testPackage,
- boolean waitForDebugger) {
- this.configState = configState;
- this.instrumentationTestRunner = runner;
- this.waitForDebugger = waitForDebugger;
- this.testApplicationId = testPackage;
- }
-
- @Nullable
- public static BlazeLaunchTask getStockTestLaunchTask(
- BlazeAndroidTestRunConfigurationState configState,
- ApplicationIdProvider applicationIdProvider,
- boolean waitForDebugger,
- BlazeAndroidDeployInfo deployInfo,
- Project project)
- throws ExecutionException {
- String testPackage;
- try {
- testPackage = applicationIdProvider.getTestPackageName();
- } catch (ApkProvisionException e) {
- throw new ExecutionException("Unable to determine test package name. " + e.getMessage());
- }
- if (testPackage == null) {
- throw new ExecutionException("Unable to determine test package name.");
- }
- List availableRunners = getRunnersFromManifest(deployInfo);
- if (availableRunners.isEmpty()) {
- RunConfigurationNotifier.INSTANCE.notifyError(
- project,
- "",
- String.format(
- "No instrumentation test runner is defined in the manifest.\n"
- + "At least one instrumentation tag must be defined for the\n"
- + "\"%1$s\" package in the AndroidManifest.xml, e.g.:\n"
- + "\n"
- + "\n"
- + "\n"
- + " \n"
- + " \n"
- + "\n"
- + "",
- testPackage));
- // Note: Gradle users will never see the above message, so don't mention Gradle here.
- // Even if no runners are defined in build.gradle, Gradle will add a default to the manifest.
- throw new ExecutionException("No instrumentation test runner is defined in the manifest.");
- }
- String runner = configState.getInstrumentationRunnerClass();
- if (StringUtil.isEmpty(runner)) {
- // Default to the first available runner.
- runner = availableRunners.get(0);
- }
- if (!availableRunners.contains(runner)) {
- RunConfigurationNotifier.INSTANCE.notifyError(
- project,
- "",
- String.format(
- "Instrumentation test runner \"%2$s\"\n"
- + "is not defined for the \"%1$s\" package in the manifest.\n"
- + "Clear the 'Specific instrumentation runner' field in your configuration\n"
- + "to default to \"%3$s\",\n"
- + "or add the runner to your AndroidManifest.xml:\n"
- + "\n"
- + "\n"
- + "\n"
- + " \n"
- + " \n"
- + "\n"
- + "",
- testPackage, runner, availableRunners.get(0)));
- throw new ExecutionException(
- String.format(
- "Instrumentation test runner \"%2$s\" is not defined for the \"%1$s\" package in the"
- + " manifest.",
- testPackage, runner));
- }
-
- return new StockAndroidTestLaunchTask(configState, runner, testPackage, waitForDebugger);
- }
-
- private static ImmutableList getRunnersFromManifest(
- final BlazeAndroidDeployInfo deployInfo) {
- if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
- return ApplicationManager.getApplication()
- .runReadAction(
- (Computable>) () -> getRunnersFromManifest(deployInfo));
- }
- ManifestParser.ParsedManifest parsedManifest = deployInfo.getMergedManifest();
- if (parsedManifest != null) {
- return ImmutableList.copyOf(parsedManifest.instrumentationClassNames);
- }
- return ImmutableList.of();
- }
-
- @SuppressWarnings("FutureReturnValueIgnored")
- public void run(@NotNull BlazeLaunchContext launchContext) {
- ConsoleView console = launchContext.getConsoleView();
- IDevice device = launchContext.getDevice();
- ExecutionUtils.println(console, "Running tests\n");
- final RemoteAndroidTestRunner runner =
- new RemoteAndroidTestRunner(testApplicationId, instrumentationTestRunner, device);
- switch (configState.getTestingType()) {
- case BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_MODULE:
- break;
- case BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_PACKAGE:
- runner.setTestPackageName(configState.getPackageName());
- break;
- case BlazeAndroidTestRunConfigurationState.TEST_CLASS:
- runner.setClassName(configState.getClassName());
- break;
- case BlazeAndroidTestRunConfigurationState.TEST_METHOD:
- runner.setMethodName(configState.getClassName(), configState.getMethodName());
- break;
- default:
- throw new RuntimeException(
- String.format("Unrecognized testing type: %d", configState.getTestingType()));
- }
- runner.setDebug(waitForDebugger);
- runner.setRunOptions(configState.getExtraOptions());
- ExecutionUtils.printShellCommand(console, runner.getAmInstrumentCommand());
- // run in a separate thread as this will block until the tests complete
- ApplicationManager.getApplication()
- .executeOnPooledThread(
- () -> {
- try {
- // This issues "am instrument" command and blocks execution.
- runner.run(new AndroidTestListener(console));
- // Detach the device from the android process handler manually as soon as "am
- // instrument" command finishes. This is required because the android process
- // handler may overlook target process especially when the test
- // runs really fast (~10ms). Because the android process handler discovers new
- // processes by polling, this race condition happens easily. By detaching the device
- // manually, we can avoid the android process handler waiting for (already finished)
- // process to show up until it times out (10 secs).
- // Note: this is a copy of ag/9593981, but it is worth figuring out a better
- // strategy here if the behavior of AndroidTestListener is not guaranteed.
- ProcessHandler processHandler = launchContext.getProcessHandler();
- if (processHandler instanceof AndroidProcessHandler) {
- ((AndroidProcessHandler) processHandler).detachDevice(launchContext.getDevice());
- }
- } catch (Exception e) {
- ExecutionUtils.printlnError(
- console, "Error: Unexpected exception while running tests: " + e);
- }
- });
- }
-}
diff --git a/aswb/sdkcompat/as223/com/google/idea/blaze/android/sync/model/idea/BlazeAndroidModel.java b/aswb/sdkcompat/as223/com/google/idea/blaze/android/sync/model/idea/BlazeAndroidModel.java
deleted file mode 100644
index 00a9e4a94c9..00000000000
--- a/aswb/sdkcompat/as223/com/google/idea/blaze/android/sync/model/idea/BlazeAndroidModel.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.sync.model.idea;
-
-import com.android.tools.idea.model.AndroidModel;
-import com.android.tools.idea.model.Namespacing;
-import com.android.tools.idea.projectsystem.NamedIdeaSourceProvider;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.intellij.openapi.project.Project;
-import java.io.File;
-
-/** Blaze model for an android project. #api42. */
-public class BlazeAndroidModel extends BlazeAndroidModelBase {
- private final NamedIdeaSourceProvider sourceProvider;
-
- public BlazeAndroidModel(
- Project project,
- File rootDirPath,
- NamedIdeaSourceProvider sourceProvider,
- ListenableFuture applicationId,
- int minSdkVersion,
- boolean desugarJava8Libs) {
- super(project, rootDirPath, applicationId, minSdkVersion, desugarJava8Libs);
- this.sourceProvider = sourceProvider;
- }
-
- public NamedIdeaSourceProvider getDefaultSourceProvider() {
- return sourceProvider;
- }
-
- @Override
- public Namespacing getNamespacing() {
- return Namespacing.DISABLED;
- }
-
- @Override
- protected String uninitializedApplicationId() {
- return AndroidModel.UNINITIALIZED_APPLICATION_ID;
- }
-}
diff --git a/aswb/sdkcompat/as223/org/jetbrains/android/facet/AndroidFacetPropertiesCompat.java b/aswb/sdkcompat/as223/org/jetbrains/android/facet/AndroidFacetPropertiesCompat.java
deleted file mode 100644
index fff25619e8a..00000000000
--- a/aswb/sdkcompat/as223/org/jetbrains/android/facet/AndroidFacetPropertiesCompat.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.facet;
-
-/** Compat class for AndroidFacetProperties. */
-public class AndroidFacetPropertiesCompat {
-
- private AndroidFacetPropertiesCompat() {}
-
- public static void enableSourcesAutogeneration(AndroidFacetProperties props, boolean enable) {}
-}
diff --git a/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidPlatformCompat.java b/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidPlatformCompat.java
deleted file mode 100644
index f745ba55516..00000000000
--- a/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidPlatformCompat.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.android.sdklib.BuildToolInfo;
-import com.android.tools.sdk.AndroidPlatform;
-import com.intellij.openapi.projectRoots.Sdk;
-
-/** Compat class for {@link com.android.tools.sdk.AndroidPlatform} */
-public class AndroidPlatformCompat {
- AndroidPlatform androidPlatform;
-
- public AndroidPlatformCompat(AndroidPlatform androidPlatform) {
- this.androidPlatform = androidPlatform;
- }
-
- public BuildToolInfo getLatestBuildTool(boolean allowBuildTool) {
- return androidPlatform.getSdkData().getLatestBuildTool(allowBuildTool);
- }
-
- public int getApiLevel() {
- return androidPlatform.getApiLevel();
- }
-
- public static int getApiLevel(Sdk sdk) {
- int androidSdkApiLevel = 1;
- AndroidSdkAdditionalData additionalData = (AndroidSdkAdditionalData) sdk.getSdkAdditionalData();
- if (additionalData != null) {
- AndroidPlatform androidPlatform = additionalData.getAndroidPlatform();
- if (androidPlatform != null) {
- androidSdkApiLevel = androidPlatform.getApiLevel();
- }
- }
- return androidSdkApiLevel;
- }
-}
diff --git a/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidPlatformsCompat.java b/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidPlatformsCompat.java
deleted file mode 100644
index d016d7ce236..00000000000
--- a/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidPlatformsCompat.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.projectRoots.Sdk;
-
-/** Compat shim class for {@link AndroidPlatforms} */
-public class AndroidPlatformsCompat {
- private AndroidPlatformsCompat() {}
-
- public static AndroidPlatformCompat getInstance(Sdk sdk) {
- return new AndroidPlatformCompat(AndroidPlatforms.getInstance(sdk));
- }
-
- public static AndroidPlatformCompat getInstance(Module module) {
- return new AndroidPlatformCompat(AndroidPlatforms.getInstance(module));
- }
-}
diff --git a/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidSdkAdditionalDataCompat.java b/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidSdkAdditionalDataCompat.java
deleted file mode 100644
index 6364b6fa8cf..00000000000
--- a/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidSdkAdditionalDataCompat.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.intellij.openapi.projectRoots.Sdk;
-
-/** Compat shim class for {@link AndroidSdkAdditionalData} */
-public class AndroidSdkAdditionalDataCompat {
- private AndroidSdkAdditionalDataCompat() {}
-
- public static AndroidSdkAdditionalData from(Sdk sdk) {
- return AndroidSdkAdditionalData.from(sdk);
- }
-}
diff --git a/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidSdkDataCompat.java b/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidSdkDataCompat.java
deleted file mode 100644
index 4aea6d6e832..00000000000
--- a/aswb/sdkcompat/as223/org/jetbrains/android/sdk/AndroidSdkDataCompat.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.android.sdklib.IAndroidTarget;
-import com.android.tools.sdk.AndroidSdkData;
-import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import java.io.File;
-
-/** Compat class for {@link com.android.tools.sdk.AndroidSdkData} */
-public class AndroidSdkDataCompat {
- AndroidSdkData androidSdkData;
-
- private AndroidSdkDataCompat(File sdkLocation, boolean forceReparse) {
- androidSdkData = AndroidSdkData.getSdkData(sdkLocation, forceReparse);
- }
-
- public static AndroidSdkDataCompat getSdkData(String sdkHomepath) {
- return new AndroidSdkDataCompat(new File(sdkHomepath), false);
- }
-
- @CanIgnoreReturnValue
- public static AndroidSdkDataCompat getSdkData(File sdkLocation, boolean forceReparse) {
- return new AndroidSdkDataCompat(sdkLocation, forceReparse);
- }
-
- public IAndroidTarget[] getTargets() {
- return androidSdkData.getTargets();
- }
-}
diff --git a/aswb/sdkcompat/as231/com/android/tools/idea/model/AndroidManifestIndexCompat.java b/aswb/sdkcompat/as231/com/android/tools/idea/model/AndroidManifestIndexCompat.java
deleted file mode 100644
index 27f94f054c6..00000000000
--- a/aswb/sdkcompat/as231/com/android/tools/idea/model/AndroidManifestIndexCompat.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.model;
-
-/** Compat class for {@link com.android.tools.idea.model.AndroidManifestIndex}. */
-public class AndroidManifestIndexCompat {
-
- private AndroidManifestIndexCompat() {}
-
- /** {@code indexEnabled} was removed in Studio 2021.2. #api211 */
- public static boolean indexEnabled() {
- return true;
- }
-}
diff --git a/aswb/sdkcompat/as231/com/android/tools/idea/progress/StudioLoggerProgressIndicatorCompat.java b/aswb/sdkcompat/as231/com/android/tools/idea/progress/StudioLoggerProgressIndicatorCompat.java
deleted file mode 100644
index e581bd190d8..00000000000
--- a/aswb/sdkcompat/as231/com/android/tools/idea/progress/StudioLoggerProgressIndicatorCompat.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.progress;
-
-/** Compat layer for StudioLoggerProgressIndicator which moved packages in 2021.2. #api211 */
-public class StudioLoggerProgressIndicatorCompat extends StudioLoggerProgressIndicator {
- public StudioLoggerProgressIndicatorCompat(Class> c) {
- super(c);
- }
-}
diff --git a/aswb/sdkcompat/as231/com/android/tools/idea/run/ValidationErrorCompat.java b/aswb/sdkcompat/as231/com/android/tools/idea/run/ValidationErrorCompat.java
deleted file mode 100644
index fb233c7eeb8..00000000000
--- a/aswb/sdkcompat/as231/com/android/tools/idea/run/ValidationErrorCompat.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.run;
-
-/** Compat class for {@link ValidationError} */
-public class ValidationErrorCompat {
- private ValidationErrorCompat() {}
-
- public static ValidationError fatal(String message, Runnable quickFick) {
- return ValidationError.fatal(message, (dataContext) -> quickFick.run());
- }
-}
diff --git a/aswb/sdkcompat/as231/com/android/tools/idea/run/tasks/DeployTasksCompat.java b/aswb/sdkcompat/as231/com/android/tools/idea/run/tasks/DeployTasksCompat.java
deleted file mode 100644
index 500a6786340..00000000000
--- a/aswb/sdkcompat/as231/com/android/tools/idea/run/tasks/DeployTasksCompat.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.run.tasks;
-
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTaskWrapper;
-import com.google.idea.common.experiments.BoolExperiment;
-import com.intellij.openapi.project.Project;
-import java.util.Collection;
-
-/** Compat class for {@link DeployTask} */
-public class DeployTasksCompat {
- private static final BoolExperiment updateCodeViaJvmti =
- new BoolExperiment("android.apply.changes", false);
-
- private DeployTasksCompat() {}
-
- public static BlazeLaunchTask createDeployTask(
- Project project, Collection packages, LaunchOptions launchOptions) {
- // We don't have a device information, fallback to the most conservative
- // install option.
- return new BlazeLaunchTaskWrapper(
- new DeployTask(
- project,
- packages,
- launchOptions.getPmInstallOptions(/* device= */ null),
- launchOptions.getInstallOnAllUsers(),
- launchOptions.getAlwaysInstallWithPm()));
- }
-}
-
diff --git a/aswb/sdkcompat/as231/com/android/tools/rendering/HtmlLinkManagerCompat.java b/aswb/sdkcompat/as231/com/android/tools/rendering/HtmlLinkManagerCompat.java
deleted file mode 100644
index 28ca9471258..00000000000
--- a/aswb/sdkcompat/as231/com/android/tools/rendering/HtmlLinkManagerCompat.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.rendering;
-
-import java.io.File;
-import org.jetbrains.annotations.NotNull;
-
-/** Compat class for {@link HtmlLinkManager} */
-public final class HtmlLinkManagerCompat {
- public static String createFilePositionUrl(@NotNull File file, int line, int column) {
- return HtmlLinkManager.createFilePositionUrl(file, line, column);
- }
-
- private HtmlLinkManagerCompat() {}
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/cppimpl/debug/BlazeAutoAndroidDebugger.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/cppimpl/debug/BlazeAutoAndroidDebugger.java
deleted file mode 100644
index 167fd4433a9..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/cppimpl/debug/BlazeAutoAndroidDebugger.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.cppimpl.debug;
-
-import com.android.ddmlib.Client;
-import com.android.tools.ndk.run.editor.AutoAndroidDebuggerState;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.project.Project;
-import com.intellij.xdebugger.XDebugSession;
-
-/** Shim for #api212 compat. */
-public class BlazeAutoAndroidDebugger extends BlazeAutoAndroidDebuggerBase {
- @Override
- public XDebugSession attachToClient(
- Project project, Client client, AutoAndroidDebuggerState state) throws ExecutionException {
- if (isNativeProject(project)) {
- log.info("Project has native development enabled. Attaching native debugger.");
- return nativeDebugger.attachToClient(project, client, state);
- } else {
- return super.attachToClient(project, client, state);
- }
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebugger.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebugger.java
deleted file mode 100644
index bfa296e12e2..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebugger.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.cppimpl.debug;
-
-/**
- * API compat of {@link BlazeNativeAndroidDebuggerBase} with the following additions:
- *
- *
- * - Creates a run-config setting using {@link BlazeAndroidNativeAttachConfiguration} instead of
- * {@link AndroidNativeAttachConfiguration} to override counterproductive validations.
- *
- *
- * #api4.0
- */
-public class BlazeNativeAndroidDebugger extends BlazeNativeAndroidDebuggerBase {}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebuggerBase.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebuggerBase.java
deleted file mode 100644
index 911d90b7711..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebuggerBase.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.cppimpl.debug;
-
-import com.android.tools.ndk.run.editor.NativeAndroidDebugger;
-import com.google.idea.blaze.base.model.BlazeProjectData;
-import com.google.idea.blaze.base.model.primitives.LanguageClass;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
-import com.intellij.openapi.project.Project;
-
-/**
- * Extension of {@link NativeAndroidDebugger} with the following key differences compared to {@link
- * NativeAndroidDebugger}.
- *
- *
- * - Overrides {@link #supportsProject} so native debugger is only enabled for native support is
- * enabled.
- *
- */
-public class BlazeNativeAndroidDebuggerBase extends NativeAndroidDebugger {
- /**
- * This ID needs to be lexicographically larger than "Java" so it come after the "Java" debugger
- * when sorted lexicographically in the "Attach Debugger to Android Process" dialog. See {@link
- * org.jetbrains.android.actions.AndroidProcessChooserDialog#populateDebuggerTypeCombo}.
- */
- public static final String ID = "Native" + Blaze.defaultBuildSystemName();
-
- @Override
- public String getId() {
- return ID;
- }
-
- @Override
- public String getDisplayName() {
- return "Native Only";
- }
-
- @Override
- public boolean supportsProject(Project project) {
- BlazeProjectData blazeProjectData =
- BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
- return blazeProjectData != null
- && blazeProjectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.C);
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/npw/project/BlazeAndroidModuleTemplate.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/npw/project/BlazeAndroidModuleTemplate.java
deleted file mode 100644
index 8d3b76b90e3..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/npw/project/BlazeAndroidModuleTemplate.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright 2017 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.npw.project;
-
-import com.android.tools.idea.projectsystem.AndroidModulePaths;
-import com.android.tools.idea.projectsystem.IdeaSourceProvider;
-import com.android.tools.idea.projectsystem.NamedModuleTemplate;
-import com.android.tools.idea.projectsystem.SourceProviderManager;
-import com.google.common.collect.Streams;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.vfs.VfsUtilCore;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.JavaDirectoryService;
-import com.intellij.psi.PsiDirectory;
-import com.intellij.psi.PsiManager;
-import com.intellij.psi.PsiPackage;
-import java.io.File;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/**
- * Project paths for a Blaze Android project.
- *
- * We mostly just take whatever directory the user specified and put the new component there.
- * Unlike Gradle, Blaze has no strict requirements regarding the structure of an Android project,
- * but there are some common conventions:
- *
- *
- * google3/
- * |-java/com/google/foo/bar/... (module root)
- * | |-BUILD
- * | |-AndroidManifest.xml (manifest directory)
- * | |-Baz.java (source directory of com.google.foo.bar.Baz)
- * | |-Baz.aidl (aidl directory, option 1)
- * | |-aidl/
- * | | `-com/google/foo/bar/Baz.aidl (aidl directory, option 2)
- * | `-res/... (res directory, one of the few things required by the build system)
- * `-javatest/com/google/foo/bar/...
- * |-BUILD
- * `-BazTest.java (test directory of com.google.foo.bar.BazTest)
- *
- *
- * However, this is also possible (package name unrelated to directory structure):
- *
- *
- * google3/experimental/users/foo/my/own/project/
- * |-Baz.java (com.google.foo.bar.Baz)
- * `-BazTest.java (com.google.foo.bar.BazTest)
- *
- *
- * So is this (versioned paths that aren't reflected by the package name):
- *
- *
- * google3/third_party/com/google/foo/bar/
- * |-v1/Baz.java (com.google.foo.bar.Baz)
- * `-v2/Baz.java (com.google.foo.bar.Baz)
- *
- */
-public class BlazeAndroidModuleTemplate implements AndroidModulePaths {
- @Nullable private File moduleRoot;
- @Nullable private File srcDirectory;
- private List resDirectories = Collections.emptyList();
-
- @Nullable
- @Override
- public File getModuleRoot() {
- return moduleRoot;
- }
-
- @Nullable
- @Override
- public File getSrcDirectory(@Nullable String packageName) {
- return srcDirectory;
- }
-
- @Nullable
- @Override
- public File getTestDirectory(@Nullable String packageName) {
- return srcDirectory;
- }
-
- @Nullable
- @Override
- public File getUnitTestDirectory(@Nullable String packageName) {
- return srcDirectory;
- }
-
- @Override
- public List getResDirectories() {
- return resDirectories;
- }
-
- @Nullable
- @Override
- public File getAidlDirectory(@Nullable String packageName) {
- return srcDirectory;
- }
-
- @Nullable
- @Override
- public File getManifestDirectory() {
- return srcDirectory;
- }
- /**
- * The new component wizard uses {@link NamedModuleTemplate#getName()} for the default package
- * name of the new component. If we can figure it out from the target directory here, then we can
- * pass it to the new component wizard.
- */
- private static String getPackageName(Project project, VirtualFile targetDirectory) {
- PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(targetDirectory);
- if (psiDirectory == null) {
- return null;
- }
- PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
- if (psiPackage == null) {
- return null;
- }
- return psiPackage.getQualifiedName();
- }
-
- public static List getTemplates(
- Module module, @Nullable VirtualFile targetDirectory) {
- AndroidFacet androidFacet = AndroidFacet.getInstance(module);
- if (androidFacet == null) {
- return Collections.emptyList();
- }
- return getTemplates(androidFacet, targetDirectory);
- }
-
- public static List getTemplates(
- AndroidFacet androidFacet, @Nullable VirtualFile targetDirectory) {
- Module module = androidFacet.getModule();
- BlazeAndroidModuleTemplate paths = new BlazeAndroidModuleTemplate();
- VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
- if (roots.length > 0) {
- paths.moduleRoot = VfsUtilCore.virtualToIoFile(roots[0]);
- }
- IdeaSourceProvider sourceProvider =
- SourceProviderManager.getInstance(androidFacet).getSources();
- // If this happens to be a resource package,
- // the module name (resource package) would be more descriptive than the facet name (Android).
- // Otherwise, .workspace is still better than (Android).
- String name = androidFacet.getModule().getName();
- if (targetDirectory != null) {
- String packageName = getPackageName(module.getProject(), targetDirectory);
- if (packageName != null) {
- name = packageName;
- }
- paths.srcDirectory = VfsUtilCore.virtualToIoFile(targetDirectory);
- } else {
- // People usually put the manifest file with their sources.
- //noinspection OptionalGetWithoutIsPresent
- paths.srcDirectory =
- Streams.stream(sourceProvider.getManifestDirectoryUrls())
- .map(it -> new File(VfsUtilCore.urlToPath(it)))
- .findFirst()
- .get();
- }
- // We have a res dir if this happens to be a resource module.
- paths.resDirectories =
- Streams.stream(sourceProvider.getResDirectoryUrls())
- .map(it -> new File(VfsUtilCore.urlToPath(it)))
- .collect(Collectors.toList());
- return Collections.singletonList(new NamedModuleTemplate(name, paths));
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/projectsystem/BlazeProjectSystem.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/projectsystem/BlazeProjectSystem.java
deleted file mode 100755
index b5b20a1b2a7..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/projectsystem/BlazeProjectSystem.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright 2017 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.projectsystem;
-
-import static com.android.tools.idea.projectsystem.SourceProvidersKt.emptySourceProvider;
-import static org.jetbrains.android.facet.SourceProviderUtil.createSourceProvidersForLegacyModule;
-
-import com.android.tools.apk.analyzer.AaptInvoker;
-import com.android.tools.idea.log.LogWrapper;
-import com.android.tools.idea.model.AndroidModel;
-import com.android.tools.idea.model.ClassJarProvider;
-import com.android.tools.idea.projectsystem.AndroidModuleSystem;
-import com.android.tools.idea.projectsystem.AndroidProjectSystem;
-import com.android.tools.idea.projectsystem.NamedIdeaSourceProvider;
-import com.android.tools.idea.projectsystem.ProjectSystemBuildManager;
-import com.android.tools.idea.projectsystem.ProjectSystemSyncManager;
-import com.android.tools.idea.projectsystem.ScopeType;
-import com.android.tools.idea.projectsystem.SourceProviderManager;
-import com.android.tools.idea.projectsystem.SourceProviders;
-import com.android.tools.idea.projectsystem.SourceProvidersFactory;
-import com.android.tools.idea.projectsystem.SourceProvidersImpl;
-import com.android.tools.idea.res.AndroidInnerClassFinder;
-import com.android.tools.idea.res.AndroidResourceClassPsiElementFinder;
-import com.android.tools.idea.sdk.AndroidSdks;
-import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.android.resources.BlazeLightResourceClassService;
-import com.google.idea.blaze.android.sync.model.idea.BlazeAndroidModel;
-import com.google.idea.blaze.android.sync.model.idea.BlazeClassJarProvider;
-import com.google.idea.blaze.base.build.BlazeBuildService;
-import com.google.idea.blaze.base.qsync.QuerySync;
-import com.intellij.facet.ProjectFacetManager;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiElementFinder;
-import com.intellij.psi.search.GlobalSearchScope;
-import java.io.File;
-import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Base class to implement common methods in {@link AndroidProjectSystem} for blaze with different
- * sdk
- */
-public class BlazeProjectSystem implements AndroidProjectSystem {
- protected final Project project;
- protected final ProjectSystemSyncManager syncManager;
- protected final List myFinders;
- private final BlazeProjectSystemBuildManager buildManager;
-
- public BlazeProjectSystem(Project project) {
- this.project = project;
- syncManager = new BlazeProjectSystemSyncManager(project);
- buildManager = new BlazeProjectSystemBuildManager(project);
-
- myFinders =
- Arrays.asList(
- AndroidInnerClassFinder.INSTANCE,
- new AndroidResourceClassPsiElementFinder(getLightResourceClassService()));
- }
-
- @Override
- public boolean allowsFileCreation() {
- return true;
- }
-
- @Nullable
- @Override
- public VirtualFile getDefaultApkFile() {
- return null;
- }
-
- @Override
- public Path getPathToAapt() {
- return AaptInvoker.getPathToAapt(
- AndroidSdks.getInstance().tryToChooseSdkHandler(),
- new LogWrapper(BlazeProjectSystem.class));
- }
-
- // @Override #api42
- public void buildProject() {
- BlazeBuildService.getInstance(project).buildProject();
- }
-
- // @Override #api42
- public ProjectSystemBuildManager getBuildManager() {
- return buildManager;
- }
-
- @Override
- public AndroidModuleSystem getModuleSystem(Module module) {
- return BlazeModuleSystem.getInstance(module);
- }
-
- @Override
- public ProjectSystemSyncManager getSyncManager() {
- return syncManager;
- }
-
- @Override
- public Collection getPsiElementFinders() {
- return myFinders;
- }
-
- @Override
- public BlazeLightResourceClassService getLightResourceClassService() {
- return BlazeLightResourceClassService.getInstance(project);
- }
-
- @Override
- public SourceProvidersFactory getSourceProvidersFactory() {
- return new SourceProvidersFactory() {
- @Override
- public SourceProviders createSourceProvidersFor(AndroidFacet facet) {
- BlazeAndroidModel model = ((BlazeAndroidModel) AndroidModel.get(facet));
- if (model != null) {
- return createForModel(model);
- } else {
- return createSourceProvidersForLegacyModule(facet);
- }
- }
-
- private SourceProviders createForModel(BlazeAndroidModel model) {
- NamedIdeaSourceProvider mainSourceProvider = model.getDefaultSourceProvider();
- if (QuerySync.isEnabled()) {
- return new SourceProvidersImpl(
- mainSourceProvider,
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(),
- ImmutableList.of(),
- ImmutableList.of(),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- emptySourceProvider(ScopeType.MAIN),
- emptySourceProvider(ScopeType.UNIT_TEST),
- emptySourceProvider(ScopeType.ANDROID_TEST),
- emptySourceProvider(ScopeType.TEST_FIXTURES));
- } else {
- return new SourceProvidersImpl(
- mainSourceProvider,
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- emptySourceProvider(ScopeType.MAIN),
- emptySourceProvider(ScopeType.UNIT_TEST),
- emptySourceProvider(ScopeType.ANDROID_TEST),
- emptySourceProvider(ScopeType.TEST_FIXTURES));
- }
- }
- };
- }
-
- // @Override #api212
- public ClassJarProvider getClassJarProvider() {
- return new BlazeClassJarProvider(project);
- }
-
- @Override
- public Collection getAndroidFacetsWithPackageName(
- Project project, String packageName) {
- return getAndroidFacetsWithPackageName(
- project, packageName, GlobalSearchScope.projectScope(project));
- }
-
- private Collection getAndroidFacetsWithPackageName(
- Project project, String packageName, GlobalSearchScope scope) {
- List facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
- return facets.stream()
- .filter(facet -> hasPackageName(facet, packageName))
- .filter(
- facet -> {
- VirtualFile file = SourceProviderManager.getInstance(facet).getMainManifestFile();
- if (file == null) {
- return false;
- } else {
- return scope.contains(file);
- }
- })
- .collect(Collectors.toList());
- }
-
- @Override
- public Collection getSubmodules() {
- return ImmutableList.of();
- }
-
- @Override
- public Collection getBootClasspath(@NotNull Module module) {
- // TODO: b/266586669
- return ImmutableList.of();
- }
-
- private static boolean hasPackageName(AndroidFacet facet, String packageName) {
- String nameFromFacet = PackageNameUtils.getPackageName(facet.getModule());
- if (nameFromFacet == null) {
- return false;
- }
- return nameFromFacet.equals(packageName);
- }
-
- @NotNull
- // @Override #api223
- public List desugarLibraryConfigFiles(@NotNull Project project) {
- return ImmutableList.of();
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/projectsystem/PackageNameUtils.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/projectsystem/PackageNameUtils.java
deleted file mode 100644
index 83a7fcd9b20..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/projectsystem/PackageNameUtils.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.projectsystem;
-
-import com.android.manifmerger.ManifestSystemProperty;
-import com.android.tools.idea.model.AndroidManifestIndex;
-import com.android.tools.idea.model.AndroidManifestIndexCompat;
-import com.android.tools.idea.model.AndroidManifestRawText;
-import com.android.tools.idea.model.MergedManifestModificationTracker;
-import com.android.tools.idea.projectsystem.ManifestOverrides;
-import com.android.tools.idea.projectsystem.SourceProviderManager;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.idea.common.experiments.BoolExperiment;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.DumbService;
-import com.intellij.openapi.project.IndexNotReadyException;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.util.CachedValueProvider;
-import com.intellij.psi.util.CachedValuesManager;
-import org.jetbrains.android.dom.manifest.AndroidManifestUtils;
-import org.jetbrains.android.dom.manifest.AndroidManifestXmlFile;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.Nullable;
-
-/** Utilities to obtain the package name for a given module. */
-public class PackageNameUtils {
- /**
- * Determines whether we use the {@link AndroidManifestIndex} to obtain the raw text package name
- * from a module's primary manifest. Note that we still won't use the index if {@link
- * AndroidManifestIndex#indexEnabled()} returns false.
- *
- * @see PackageNameUtils#getPackageName(Module)
- * @see PackageNameUtils#doGetPackageName(AndroidFacet, boolean)
- */
- private static final BoolExperiment USE_ANDROID_MANIFEST_INDEX =
- new BoolExperiment("use.android.manifest.index", true);
-
- @Nullable
- public static String getPackageName(Module module) {
- AndroidFacet facet = AndroidFacet.getInstance(module);
- assert facet != null;
- return CachedValuesManager.getManager(module.getProject())
- .getCachedValue(
- facet,
- () -> {
- boolean useIndex =
- AndroidManifestIndexCompat.indexEnabled()
- && USE_ANDROID_MANIFEST_INDEX.getValue();
- String packageName = doGetPackageName(facet, useIndex);
- return CachedValueProvider.Result.create(
- StringUtil.nullize(packageName, true),
- MergedManifestModificationTracker.getInstance(module));
- });
- }
-
- /**
- * Returns the package name from an Android module's merged manifest without actually computing
- * the whole merged manifest. This is either
- *
- *
- * - The {@link ManifestSystemProperty#PACKAGE} manifest override if one is specified by the
- * corresponding BUILD target, or
- *
- The result of applying placeholder substitution to the raw package name from the module's
- * primary manifest
- *
- *
- * In the second case, we try to obtain the raw package name using the {@link
- * AndroidManifestIndex} if {@code useIndex} is true. If {@code useIndex} is false or querying the
- * index fails for some reason (e.g. this method is called in a read action but not a *smart* read
- * action), then we resort to parsing the PSI of the module's primary manifest to get the raw
- * package name.
- *
- * @see AndroidModuleSystem#getManifestOverrides()
- * @see AndroidModuleSystem#getPackageName()
- */
- @Nullable
- @VisibleForTesting
- static String doGetPackageName(AndroidFacet facet, boolean useIndex) {
- ManifestOverrides manifestOverrides =
- BlazeModuleSystem.getInstance(facet.getModule()).getManifestOverrides();
- String packageOverride =
- ManifestValueProcessor.getPackageOverride(manifestOverrides.getDirectOverrides());
- if (packageOverride != null) {
- return packageOverride;
- }
- String rawPackageName = null;
- if (useIndex) {
- rawPackageName = getRawPackageNameFromIndex(facet);
- }
- if (rawPackageName == null) {
- rawPackageName = getRawPackageNameFromPsi(facet);
- }
- return rawPackageName == null ? null : manifestOverrides.resolvePlaceholders(rawPackageName);
- }
-
- @Nullable
- private static String getRawPackageNameFromIndex(AndroidFacet facet) {
- VirtualFile primaryManifest = SourceProviderManager.getInstance(facet).getMainManifestFile();
- if (primaryManifest == null) {
- return null;
- }
- Project project = facet.getModule().getProject();
- try {
- AndroidManifestRawText manifestRawText =
- DumbService.getInstance(project)
- .runReadActionInSmartMode(
- () -> AndroidManifestIndex.getDataForManifestFile(project, primaryManifest));
- return manifestRawText == null ? null : manifestRawText.getPackageName();
- } catch (IndexNotReadyException e) {
- // TODO(142681129): runReadActionInSmartMode doesn't work if we already have read access.
- // We need to refactor the callers of AndroidManifestUtils#getPackage to require a *smart*
- // read action, at which point we can remove this try-catch.
- return null;
- }
- }
-
- @Nullable
- private static String getRawPackageNameFromPsi(AndroidFacet facet) {
- AndroidManifestXmlFile primaryManifest = AndroidManifestUtils.getPrimaryManifestXml(facet);
- return primaryManifest == null ? null : primaryManifest.getPackageName();
- }
-
- private PackageNameUtils() {}
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/resources/BlazeRClass.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/resources/BlazeRClass.java
deleted file mode 100644
index f8cfbac94a2..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/resources/BlazeRClass.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.resources;
-
-import static org.jetbrains.android.AndroidResolveScopeEnlarger.LIGHT_CLASS_KEY;
-import static org.jetbrains.android.AndroidResolveScopeEnlarger.MODULE_POINTER_KEY;
-
-import com.android.ide.common.rendering.api.ResourceNamespace;
-import com.android.tools.idea.res.LocalResourceRepository;
-import com.android.tools.idea.res.ResourceRepositoryRClass;
-import com.android.tools.idea.res.StudioResourceRepositoryManager;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.module.ModulePointerManager;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiManager;
-import org.jetbrains.android.augment.AndroidLightField;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Blaze implementation of an R class based on resource repositories. */
-public class BlazeRClass extends ResourceRepositoryRClass {
-
- private final AndroidFacet androidFacet;
-
- public BlazeRClass(PsiManager psiManager, AndroidFacet androidFacet, String packageName) {
- super(
- psiManager,
- new ResourcesSource() {
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- // @Override #api4.1
- public Transitivity getTransitivity() {
- return Transitivity.TRANSITIVE;
- }
-
- @Override
- public StudioResourceRepositoryManager getResourceRepositoryManager() {
- return StudioResourceRepositoryManager.getInstance(androidFacet);
- }
-
- @Override
- public LocalResourceRepository getResourceRepository() {
- return StudioResourceRepositoryManager.getAppResources(androidFacet);
- }
-
- @Override
- public ResourceNamespace getResourceNamespace() {
- return ResourceNamespace.RES_AUTO;
- }
-
- @Override
- public AndroidLightField.FieldModifier getFieldModifier() {
- return AndroidLightField.FieldModifier.NON_FINAL;
- }
- });
- this.androidFacet = androidFacet;
- setModuleInfo(getModule(), false);
- VirtualFile virtualFile = myFile.getViewProvider().getVirtualFile();
- virtualFile.putUserData(
- MODULE_POINTER_KEY, ModulePointerManager.getInstance(getProject()).create(getModule()));
- virtualFile.putUserData(LIGHT_CLASS_KEY, ResourceRepositoryRClass.class);
- }
-
- public Module getModule() {
- return androidFacet.getModule();
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/BlazeAndroidDeploymentService.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/BlazeAndroidDeploymentService.java
deleted file mode 100644
index 6cc3a63459e..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/BlazeAndroidDeploymentService.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run;
-
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.tasks.DeployTask;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.intellij.openapi.project.Project;
-import java.util.Collection;
-
-/** A service that provides {@link DeployTask}. */
-public interface BlazeAndroidDeploymentService {
- static BlazeAndroidDeploymentService getInstance(Project project) {
- return project.getService(BlazeAndroidDeploymentService.class);
- }
-
- /** Returns a {@link DeployTask} to deploy the given files and launch options. */
- BlazeLaunchTask getDeployTask(Collection packages, LaunchOptions launchOptions);
-
- /** A default implementation that uses {@link DeployTasksCompat#createDeployTask}. */
- class DefaultDeploymentService implements BlazeAndroidDeploymentService {
- private final Project project;
-
- public DefaultDeploymentService(Project project) {
- this.project = project;
- }
-
- @Override
- public BlazeLaunchTask getDeployTask(
- Collection packages, LaunchOptions launchOptions) {
- return DeployTasksCompat.createDeployTask(project, packages, launchOptions);
- }
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/BlazeCommandAndroidDebuggerInfoProvider.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/BlazeCommandAndroidDebuggerInfoProvider.java
deleted file mode 100644
index 03dd9f80da7..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/BlazeCommandAndroidDebuggerInfoProvider.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.execution.common.debug.impl.java.AndroidJavaDebugger;
-import com.android.tools.idea.run.editor.AndroidDebuggerInfoProvider;
-import com.google.idea.blaze.android.cppimpl.debug.BlazeNativeAndroidDebugger;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.test.BlazeAndroidTestRunConfigurationState;
-import com.google.idea.blaze.base.model.BlazeProjectData;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.openapi.project.Project;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import org.jetbrains.annotations.Nullable;
-
-/** Provider of blaze project compatible android debuggers. */
-public class BlazeCommandAndroidDebuggerInfoProvider implements AndroidDebuggerInfoProvider {
- @Override
- public boolean supportsProject(Project project) {
- BlazeProjectData blazeProjectData =
- BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
- return blazeProjectData != null;
- }
-
- @Override
- @SuppressWarnings("rawtypes") // List includes multiple AndroidDebuggerState types.
- public List getAndroidDebuggers(RunConfiguration configuration) {
- if (getCommonState(configuration) != null) {
- return Arrays.asList(new BlazeNativeAndroidDebugger(), new AndroidJavaDebugger());
- }
- return Collections.emptyList();
- }
-
- @Nullable
- @Override
- public AndroidDebugger getSelectedAndroidDebugger(
- RunConfiguration configuration) {
- // b/170159822 Always return java debugger because BlazeAutoAndroidDebugger doesn't work and
- // users likely want the java debugger not the native debugger.
- return new AndroidJavaDebugger();
- }
-
- @Nullable
- @Override
- public AndroidDebuggerState getSelectedAndroidDebuggerState(RunConfiguration configuration) {
- AndroidDebugger debugger = getSelectedAndroidDebugger(configuration);
- if (debugger == null) {
- return null;
- }
- return debugger.createState();
- }
-
- @Nullable
- private BlazeAndroidRunConfigurationCommonState getCommonState(RunConfiguration configuration) {
- if (!(configuration instanceof BlazeCommandRunConfiguration)) {
- return null;
- }
- BlazeCommandRunConfiguration blazeRunConfig = (BlazeCommandRunConfiguration) configuration;
- BlazeAndroidBinaryRunConfigurationState binaryState =
- blazeRunConfig.getHandlerStateIfType(BlazeAndroidBinaryRunConfigurationState.class);
- if (binaryState != null) {
- return binaryState.getCommonState();
- }
- BlazeAndroidTestRunConfigurationState testState =
- blazeRunConfig.getHandlerStateIfType(BlazeAndroidTestRunConfigurationState.class);
- if (testState != null) {
- return testState.getCommonState();
- }
- return null;
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryApplicationLaunchTaskProvider.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryApplicationLaunchTaskProvider.java
deleted file mode 100644
index 8a74f3d458f..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryApplicationLaunchTaskProvider.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.activity.StartActivityFlagsProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTaskWrapper;
-import com.android.tools.idea.run.tasks.AndroidDeepLinkLaunchTask;
-import com.android.tools.idea.run.tasks.DefaultActivityLaunchTask;
-import com.android.tools.idea.run.tasks.SpecificActivityLaunchTask;
-import com.google.idea.blaze.android.manifest.ManifestParser;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.diagnostic.Logger;
-
-/** Provides the launch task for android_binary */
-public class BlazeAndroidBinaryApplicationLaunchTaskProvider {
- private static final Logger LOG =
- Logger.getInstance(BlazeAndroidBinaryApplicationLaunchTaskProvider.class);
-
- public static BlazeLaunchTask getApplicationLaunchTask(
- ApplicationIdProvider applicationIdProvider,
- ManifestParser.ParsedManifest mergedManifestParsedManifest,
- BlazeAndroidBinaryRunConfigurationState configState,
- StartActivityFlagsProvider startActivityFlagsProvider)
- throws ExecutionException {
- try {
- String applicationId = applicationIdProvider.getPackageName();
-
- switch (configState.getMode()) {
- case BlazeAndroidBinaryRunConfigurationState.LAUNCH_DEFAULT_ACTIVITY:
- BlazeDefaultActivityLocator activityLocator =
- new BlazeDefaultActivityLocator(mergedManifestParsedManifest);
- return new BlazeLaunchTaskWrapper(
- new DefaultActivityLaunchTask(
- applicationId, activityLocator, startActivityFlagsProvider));
- case BlazeAndroidBinaryRunConfigurationState.LAUNCH_SPECIFIC_ACTIVITY:
- return new BlazeLaunchTaskWrapper(
- new SpecificActivityLaunchTask(
- applicationId, configState.getActivityClass(), startActivityFlagsProvider));
- case BlazeAndroidBinaryRunConfigurationState.LAUNCH_DEEP_LINK:
- return new BlazeLaunchTaskWrapper(
- new AndroidDeepLinkLaunchTask(configState.getDeepLink(), startActivityFlagsProvider));
- case BlazeAndroidBinaryRunConfigurationState.DO_NOTHING:
- default:
- return null;
- }
- } catch (ApkProvisionException e) {
- throw new ExecutionException("Unable to identify application id");
- }
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContext.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContext.java
deleted file mode 100644
index 6b2d10e2dac..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContext.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2019 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.activity.DefaultStartActivityFlagsProvider;
-import com.android.tools.idea.run.activity.StartActivityFlagsProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Compat for #api212 */
-public class BlazeAndroidBinaryNormalBuildRunContext
- extends BlazeAndroidBinaryNormalBuildRunContextBase {
- BlazeAndroidBinaryNormalBuildRunContext(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, runConfiguration, env, configState, buildStep, launchId);
- }
-
- @Override
- public BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions, @Nullable Integer userId, String contributorsAmStartOptions)
- throws ExecutionException {
- String extraFlags = UserIdHelper.getFlagsFromUserId(userId);
- if (!contributorsAmStartOptions.isEmpty()) {
- extraFlags += (extraFlags.isEmpty() ? "" : " ") + contributorsAmStartOptions;
- }
-
- final StartActivityFlagsProvider startActivityFlagsProvider =
- new DefaultStartActivityFlagsProvider(project, launchOptions.isDebug(), extraFlags);
-
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
-
- return BlazeAndroidBinaryApplicationLaunchTaskProvider.getApplicationLaunchTask(
- applicationIdProvider,
- deployInfo.getMergedManifest(),
- configState,
- startActivityFlagsProvider);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-
- @Override
- public Executor getExecutor() {
- return env.getExecutor();
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextBase.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextBase.java
deleted file mode 100644
index bc3517e8fe8..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextBase.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider.NATIVE_DEBUGGING_ENABLED;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.gradle.util.DynamicAppUtils;
-import com.android.tools.idea.run.ApkFileUnit;
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.ApkProvider;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.idea.blaze.android.run.deployinfo.BlazeApkProviderService;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.NotNull;
-
-/** Run context for android_binary. */
-public abstract class BlazeAndroidBinaryNormalBuildRunContextBase
- implements BlazeAndroidRunContext {
- protected final Project project;
- protected final AndroidFacet facet;
- protected final RunConfiguration runConfiguration;
- protected final ExecutionEnvironment env;
- protected final BlazeAndroidBinaryRunConfigurationState configState;
- protected final ConsoleProvider consoleProvider;
- protected final ApkBuildStep buildStep;
- protected final ApkProvider apkProvider;
- protected final ApplicationIdProvider applicationIdProvider;
- private final String launchId;
-
- BlazeAndroidBinaryNormalBuildRunContextBase(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- this.project = project;
- this.facet = facet;
- this.runConfiguration = runConfiguration;
- this.env = env;
- this.configState = configState;
- this.consoleProvider = new BlazeAndroidBinaryConsoleProvider(project);
- this.buildStep = buildStep;
- this.apkProvider = BlazeApkProviderService.getInstance().getApkProvider(project, buildStep);
- this.applicationIdProvider = new BlazeAndroidBinaryApplicationIdProvider(buildStep);
- this.launchId = launchId;
- }
-
- @Override
- public BlazeAndroidDeviceSelector getDeviceSelector() {
- return new BlazeAndroidDeviceSelector.NormalDeviceSelector();
- }
-
- @Override
- public void augmentLaunchOptions(LaunchOptions.Builder options) {
- options.setDeploy(true).setOpenLogcatAutomatically(configState.showLogcatAutomatically());
- options.addExtraOptions(
- ImmutableMap.of(
- "android.profilers.state", // Not used after #api211
- configState.getProfilerState(),
- NATIVE_DEBUGGING_ENABLED,
- configState.getCommonState().isNativeDebuggingEnabled()));
- }
-
- @Override
- public ConsoleProvider getConsoleProvider() {
- return consoleProvider;
- }
-
- @Override
- public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
- return applicationIdProvider;
- }
-
- @Override
- public ApkBuildStep getBuildStep() {
- return buildStep;
- }
-
- @Nullable
- @Override
- public Integer getUserId(IDevice device) throws ExecutionException {
- return UserIdHelper.getUserIdFromConfigurationState(project, device, configState);
- }
-
- @Override
- public BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException {
- return new BlazeAndroidLaunchTasksProvider(
- project, this, applicationIdProvider, launchOptionsBuilder);
- }
-
- @Override
- public String getAmStartOptions() {
- return configState.getAmStartOptions();
- }
-
- @Override
- public ProfilerState getProfileState() {
- return configState.getProfilerState();
- }
-
- @Nullable
- @Override
- public ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException {
- BlazeLaunchTask deployTask =
- DeployTasksCompat.createDeployTask(
- project, getApkInfoToInstall(device, launchOptions, apkProvider), launchOptions);
- return ImmutableList.of(new DeploymentTimingReporterTask(launchId, deployTask));
- }
-
- /** Returns a list of APKs excluding any APKs for features that are disabled. */
- public static List getApkInfoToInstall(
- IDevice device, LaunchOptions launchOptions, ApkProvider apkProvider)
- throws ExecutionException {
- Collection apks;
- try {
- apks = apkProvider.getApks(device);
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
- List disabledFeatures = launchOptions.getDisabledDynamicFeatures();
- return apks.stream()
- .map(apk -> getApkInfoToInstall(apk, disabledFeatures))
- .collect(Collectors.toList());
- }
-
- @NotNull
- private static ApkInfo getApkInfoToInstall(ApkInfo apkInfo, List disabledFeatures) {
- if (apkInfo.getFiles().size() > 1) {
- List filteredApks =
- apkInfo.getFiles().stream()
- .filter(feature -> DynamicAppUtils.isFeatureEnabled(disabledFeatures, feature))
- .collect(Collectors.toList());
- return new ApkInfo(filteredApks, apkInfo.getApplicationId());
- } else {
- return apkInfo;
- }
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextCompat.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextCompat.java
deleted file mode 100644
index d54c472c84b..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextCompat.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Compat class for {@link BlazeAndroidBinaryNormalBuildRunContext}. */
-public class BlazeAndroidBinaryNormalBuildRunContextCompat
- extends BlazeAndroidBinaryNormalBuildRunContext {
-
- BlazeAndroidBinaryNormalBuildRunContextCompat(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, runConfiguration, env, configState, buildStep, launchId);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryProgramRunner.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryProgramRunner.java
deleted file mode 100644
index 50f42d4b2dd..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryProgramRunner.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.intellij.openapi.application.ModalityState.NON_MODAL;
-
-import com.android.tools.idea.profilers.ProfileRunExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutor;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.ExecutionResult;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunProfile;
-import com.intellij.execution.configurations.RunProfileState;
-import com.intellij.execution.configurations.RunnerSettings;
-import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.executors.DefaultRunExecutor;
-import com.intellij.execution.runners.AsyncProgramRunner;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.runners.RunContentBuilder;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.application.ActionsKt;
-import com.intellij.openapi.fileEditor.FileDocumentManager;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.progress.Task;
-import org.jetbrains.concurrency.AsyncPromise;
-import org.jetbrains.concurrency.Promise;
-
-/** Program runner for configurations from {@link BlazeAndroidBinaryRunConfigurationHandler}. */
-public class BlazeAndroidBinaryProgramRunner extends AsyncProgramRunner {
- @Override
- public boolean canRun(String executorId, RunProfile profile) {
- BlazeAndroidRunConfigurationHandler handler =
- BlazeAndroidRunConfigurationHandler.getHandlerFrom(profile);
- if (!(handler instanceof BlazeAndroidBinaryRunConfigurationHandler)) {
- return false;
- }
- return (DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)
- || DefaultRunExecutor.EXECUTOR_ID.equals(executorId)
- || ProfileRunExecutor.EXECUTOR_ID.equals(executorId));
- }
-
- @Override
- protected Promise execute(
- ExecutionEnvironment environment, RunProfileState state) {
- FileDocumentManager.getInstance().saveAllDocuments();
-
- AsyncPromise promise = new AsyncPromise<>();
-
- ProgressManager.getInstance()
- .run(
- new Task.Backgroundable(environment.getProject(), "Launching ${runProfile.name}") {
- @Override
- public void run(ProgressIndicator indicator) {
- try {
- RunContentDescriptor descriptor;
- if (state instanceof AndroidConfigurationExecutor) {
- AndroidConfigurationExecutor configurationExecutor =
- (AndroidConfigurationExecutor) state;
- Executor executor = environment.getExecutor();
- if (executor.getId().equals(DefaultDebugExecutor.EXECUTOR_ID)) {
- descriptor = configurationExecutor.debug(indicator);
- } else if (executor.getId().equals(DefaultRunExecutor.EXECUTOR_ID)
- || executor.getId().equals(ProfileRunExecutor.EXECUTOR_ID)) {
- descriptor = configurationExecutor.run(indicator);
- } else {
- throw new ExecutionException("Unsupported executor");
- }
- } else {
- descriptor = doExecute(state, environment);
- }
- promise.setResult(descriptor);
- } catch (ExecutionException e) {
- boolean unused = promise.setError(e);
- }
- }
-
- @Override
- public void onCancel() {
- super.onCancel();
- promise.setResult(null);
- }
- });
-
- return promise;
- }
-
- private RunContentDescriptor doExecute(
- final RunProfileState state, final ExecutionEnvironment env) throws ExecutionException {
- ExecutionResult result = state.execute(env.getExecutor(), this);
- return ActionsKt.invokeAndWaitIfNeeded(
- NON_MODAL,
- () -> new RunContentBuilder(result, env).showRunContent(env.getContentToReuse()));
- }
-
- @Override
- public String getRunnerId() {
- return "AndroidBinaryProgramRunner";
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/DeploymentTimingReporterTask.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/DeploymentTimingReporterTask.java
deleted file mode 100644
index 81696ad5b1e..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/DeploymentTimingReporterTask.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2021 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import com.android.tools.idea.run.blaze.BlazeLaunchContext;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.google.common.base.Stopwatch;
-import com.google.idea.blaze.android.run.LaunchMetrics;
-import com.intellij.execution.ExecutionException;
-
-/** A wrapper launch task that wraps the given deployment task and logs the deployment latency. */
-public class DeploymentTimingReporterTask implements BlazeLaunchTask {
- private final BlazeLaunchTask deployTask;
- private final String launchId;
-
- public DeploymentTimingReporterTask(String launchId, BlazeLaunchTask deployTask) {
- this.launchId = launchId;
- this.deployTask = deployTask;
- }
-
- @Override
- public void run(BlazeLaunchContext launchContext) throws ExecutionException {
- Stopwatch s = Stopwatch.createStarted();
- try {
- deployTask.run(launchContext);
- LaunchMetrics.logDeploymentTime(launchId, s.elapsed(), true);
- } catch (ExecutionException e) {
- LaunchMetrics.logDeploymentTime(launchId, s.elapsed(), false);
- throw e;
- }
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/UserIdHelper.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/UserIdHelper.java
deleted file mode 100644
index ab71d4747c2..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/UserIdHelper.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import com.android.ddmlib.AdbCommandRejectedException;
-import com.android.ddmlib.CollectingOutputReceiver;
-import com.android.ddmlib.IDevice;
-import com.android.ddmlib.ShellCommandUnresponsiveException;
-import com.android.ddmlib.TimeoutException;
-import com.android.tools.idea.execution.common.RunConfigurationNotifier;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.project.Project;
-import java.io.IOException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.annotation.Nullable;
-
-/** Helpers for user id */
-public final class UserIdHelper {
- private UserIdHelper() {}
-
- private static final Pattern USER_ID_REGEX =
- Pattern.compile("UserInfo\\{([0-9]+):Work profile:[0-9]+\\}");
-
- @Nullable
- public static Integer getUserIdFromConfigurationState(
- Project project, IDevice device, BlazeAndroidBinaryRunConfigurationState state)
- throws ExecutionException {
- if (state.useWorkProfileIfPresent()) {
- try {
- Integer userId = getWorkProfileId(device);
- if (userId == null) {
- RunConfigurationNotifier.INSTANCE.notifyWarning(
- project,
- "",
- "Could not locate work profile on selected device. Launching default user.");
- }
- return userId;
- } catch (TimeoutException
- | AdbCommandRejectedException
- | ShellCommandUnresponsiveException
- | IOException e) {
- throw new ExecutionException(e);
- }
- }
- return state.getUserId();
- }
-
- @Nullable
- public static Integer getWorkProfileId(IDevice device)
- throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
- IOException {
- CollectingOutputReceiver receiver = new CollectingOutputReceiver();
- device.executeShellCommand("pm list users", receiver);
- String result = receiver.getOutput();
- Matcher matcher = USER_ID_REGEX.matcher(result);
- if (matcher.find()) {
- return Integer.parseInt(matcher.group(1));
- }
- return null;
- }
-
- public static String getFlagsFromUserId(@Nullable Integer userId) {
- return userId != null ? ("--user " + userId.intValue()) : "";
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContext.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContext.java
deleted file mode 100644
index c49082cfdaa..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContext.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary.mobileinstall;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.activity.DefaultStartActivityFlagsProvider;
-import com.android.tools.idea.run.activity.StartActivityFlagsProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryApplicationLaunchTaskProvider;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.binary.UserIdHelper;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Run Context for mobile install launches, #api4.0 compat. */
-public class BlazeAndroidBinaryMobileInstallRunContext
- extends BlazeAndroidBinaryMobileInstallRunContextBase {
- public BlazeAndroidBinaryMobileInstallRunContext(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, runConfiguration, env, configState, buildStep, launchId);
- }
-
- @SuppressWarnings("unchecked") // upstream API
- @Override
- public BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions, @Nullable Integer userId, String contributorsAmStartOptions)
- throws ExecutionException {
-
- String extraFlags = UserIdHelper.getFlagsFromUserId(userId);
- if (!contributorsAmStartOptions.isEmpty()) {
- extraFlags += (extraFlags.isEmpty() ? "" : " ") + contributorsAmStartOptions;
- }
-
- final StartActivityFlagsProvider startActivityFlagsProvider =
- new DefaultStartActivityFlagsProvider(project, launchOptions.isDebug(), extraFlags);
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
-
- return BlazeAndroidBinaryApplicationLaunchTaskProvider.getApplicationLaunchTask(
- applicationIdProvider,
- deployInfo.getMergedManifest(),
- configState,
- startActivityFlagsProvider);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-
- @Override
- public Executor getExecutor() {
- return env.getExecutor();
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextBase.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextBase.java
deleted file mode 100644
index 7562174bd25..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextBase.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary.mobileinstall;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.run.ApkFileUnit;
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryApplicationIdProvider;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryConsoleProvider;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.binary.DeploymentTimingReporterTask;
-import com.google.idea.blaze.android.run.binary.UserIdHelper;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.google.idea.blaze.base.sync.data.BlazeDataStorage;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import java.util.Collections;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Run context for android_binary. */
-abstract class BlazeAndroidBinaryMobileInstallRunContextBase implements BlazeAndroidRunContext {
- protected final Project project;
- protected final AndroidFacet facet;
- protected final RunConfiguration runConfiguration;
- protected final ExecutionEnvironment env;
- protected final BlazeAndroidBinaryRunConfigurationState configState;
- protected final ConsoleProvider consoleProvider;
- protected final ApplicationIdProvider applicationIdProvider;
- protected final ApkBuildStep buildStep;
- private final String launchId;
-
- public BlazeAndroidBinaryMobileInstallRunContextBase(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- this.project = project;
- this.facet = facet;
- this.runConfiguration = runConfiguration;
- this.env = env;
- this.configState = configState;
- this.consoleProvider = new BlazeAndroidBinaryConsoleProvider(project);
- this.buildStep = buildStep;
- this.applicationIdProvider = new BlazeAndroidBinaryApplicationIdProvider(buildStep);
- this.launchId = launchId;
- }
-
- @Override
- public BlazeAndroidDeviceSelector getDeviceSelector() {
- return new BlazeAndroidDeviceSelector.NormalDeviceSelector();
- }
-
- @Override
- public void augmentLaunchOptions(LaunchOptions.Builder options) {
- options
- .setDeploy(buildStep.needsIdeDeploy())
- .setOpenLogcatAutomatically(configState.showLogcatAutomatically());
- // This is needed for compatibility with #api211
- options.addExtraOptions(
- ImmutableMap.of("android.profilers.state", configState.getProfilerState()));
- }
-
- @Override
- public ConsoleProvider getConsoleProvider() {
- return consoleProvider;
- }
-
- @Override
- public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
- return applicationIdProvider;
- }
-
- @Override
- public ApkBuildStep getBuildStep() {
- return buildStep;
- }
-
- @Override
- public ProfilerState getProfileState() {
- return configState.getProfilerState();
- }
-
- @Override
- public ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException {
- if (!buildStep.needsIdeDeploy()) {
- return ImmutableList.of();
- }
-
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
-
- String packageName = deployInfo.getMergedManifest().packageName;
- if (packageName == null) {
- throw new ExecutionException("Could not determine package name from deploy info");
- }
-
- ApkInfo info =
- new ApkInfo(
- deployInfo.getApksToDeploy().stream()
- .map(file -> new ApkFileUnit(BlazeDataStorage.WORKSPACE_MODULE_NAME, file))
- .collect(Collectors.toList()),
- packageName);
-
- BlazeLaunchTask deployTask =
- DeployTasksCompat.createDeployTask(project, Collections.singletonList(info), launchOptions);
- return ImmutableList.of(new DeploymentTimingReporterTask(launchId, deployTask));
- }
-
- @Nullable
- @Override
- public Integer getUserId(IDevice device) throws ExecutionException {
- return UserIdHelper.getUserIdFromConfigurationState(project, device, configState);
- }
-
- @Override
- public BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException {
- return new BlazeAndroidLaunchTasksProvider(
- project, this, applicationIdProvider, launchOptionsBuilder);
- }
-
- @Override
- public String getAmStartOptions() {
- return configState.getAmStartOptions();
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextCompat.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextCompat.java
deleted file mode 100644
index 29411ebad5a..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextCompat.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary.mobileinstall;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Compatct class for {@link BlazeAndroidBinaryMobileInstallRunContext}. */
-public class BlazeAndroidBinaryMobileInstallRunContextCompat
- extends BlazeAndroidBinaryMobileInstallRunContext {
-
- public BlazeAndroidBinaryMobileInstallRunContextCompat(
- Project project,
- AndroidFacet facet,
- BlazeCommandRunConfiguration configuration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, configuration, env, configState, buildStep, launchId);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidDebuggerService.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidDebuggerService.java
deleted file mode 100644
index c8658223baa..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidDebuggerService.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.execution.common.debug.impl.java.AndroidJavaDebugger;
-import com.android.tools.ndk.run.editor.AutoAndroidDebuggerState;
-import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.android.cppimpl.debug.BlazeAutoAndroidDebugger;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
-import com.intellij.ide.plugins.PluginManagerCore;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-
-/** Provides android debuggers and debugger states for blaze projects. */
-public interface BlazeAndroidDebuggerService {
-
- static BlazeAndroidDebuggerService getInstance(Project project) {
- return project.getService(BlazeAndroidDebuggerService.class);
- }
-
- /** Returns the standard debugger for non-native (Java) debugging. */
- AndroidDebugger getDebugger();
-
- /** Returns the standard debugger for native (C++) debugging. */
- AndroidDebugger getNativeDebugger();
-
- /**
- * Performs additional necessary setup for native debugging, incorporating info from {@link
- * BlazeAndroidDeployInfo}.
- */
- void configureNativeDebugger(
- AndroidDebuggerState state, @Nullable BlazeAndroidDeployInfo deployInfo);
-
- /** Default debugger service. */
- class DefaultDebuggerService implements BlazeAndroidDebuggerService {
- private final Project project;
-
- public DefaultDebuggerService(Project project) {
- this.project = project;
- }
-
- @Override
- public AndroidDebugger getDebugger() {
- return new AndroidJavaDebugger();
- }
-
- @Override
- public AndroidDebugger getNativeDebugger() {
- return new BlazeAutoAndroidDebugger();
- }
-
- @Override
- public void configureNativeDebugger(
- AndroidDebuggerState rawState, @Nullable BlazeAndroidDeployInfo deployInfo) {
- if (!isNdkPluginLoaded() && !(rawState instanceof AutoAndroidDebuggerState)) {
- return;
- }
- AutoAndroidDebuggerState state = (AutoAndroidDebuggerState) rawState;
-
- // Source code is always relative to the workspace root in a blaze project.
- String workingDirPath = WorkspaceRoot.fromProject(project).directory().getPath();
- state.setWorkingDir(workingDirPath);
-
- // Remote built binaries may use /proc/self/cwd to represent the working directory,
- // so we manually map /proc/self/cwd to the workspace root. We used to use
- // `plugin.symbol-file.dwarf.comp-dir-symlink-paths = "/proc/self/cwd"`
- // to automatically resolve this, but it's no longer supported in newer versions of
- // LLDB.
- String sourceMapToWorkspaceRootCommand =
- "settings append target.source-map /proc/self/cwd/ " + workingDirPath;
-
- ImmutableList startupCommands =
- ImmutableList.builder()
- .addAll(state.getUserStartupCommands())
- .add(sourceMapToWorkspaceRootCommand)
- .build();
- state.setUserStartupCommands(startupCommands);
-
- // NDK plugin will pass symbol directories to LLDB as `settings append
- // target.exec-search-paths`.
- if (deployInfo != null) {
- state.setSymbolDirs(
- deployInfo.getSymbolFiles().stream()
- .map(symbol -> symbol.getParentFile().getAbsolutePath())
- .collect(ImmutableList.toImmutableList()));
- }
- }
- }
-
- static boolean isNdkPluginLoaded() {
- return PluginManagerCore.getLoadedPlugins().stream()
- .anyMatch(
- d -> d.isEnabled() && d.getPluginId().getIdString().equals("com.android.tools.ndk"));
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidDeviceSelector.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidDeviceSelector.java
deleted file mode 100644
index b4fdcf0fd33..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidDeviceSelector.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.execution.common.AndroidSessionInfo;
-import com.android.tools.idea.run.DeviceFutures;
-import com.android.tools.idea.run.editor.DeployTarget;
-import com.google.common.annotations.VisibleForTesting;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-
-/** Selects a device. */
-public interface BlazeAndroidDeviceSelector {
- /** A device session */
- class DeviceSession {
- @Nullable public final DeployTarget deployTarget;
- @Nullable public final DeviceFutures deviceFutures;
-
- public DeviceSession(
- @Nullable DeployTarget deployTarget, @Nullable DeviceFutures deviceFutures) {
- this.deployTarget = deployTarget;
- this.deviceFutures = deviceFutures;
- }
-
- // Only for back compat
- @VisibleForTesting
- public DeviceSession(
- @Nullable DeployTarget deployTarget,
- @Nullable DeviceFutures deviceFutures,
- @Nullable AndroidSessionInfo sessionInfo) {
- this(deployTarget, deviceFutures);
- }
- }
-
- DeviceSession getDevice(
- Project project, Executor executor, ExecutionEnvironment env, boolean debug, int runConfigId)
- throws ExecutionException;
- /** Standard device selector */
- class NormalDeviceSelector implements BlazeAndroidDeviceSelector {
- @Override
- public DeviceSession getDevice(
- Project project,
- Executor executor,
- ExecutionEnvironment env,
- boolean debug,
- int runConfigId) {
- DeployTarget deployTarget = BlazeDeployTargetService.getInstance(project).getDeployTarget();
- if (deployTarget == null) {
- return null;
- }
- DeviceFutures deviceFutures = null;
- if (!deployTarget.hasCustomRunProfileState(executor)) {
- deviceFutures = deployTarget.getDevices(project);
- }
- return new DeviceSession(deployTarget, deviceFutures);
- }
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidLaunchTasksProvider.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidLaunchTasksProvider.java
deleted file mode 100644
index 7a3cd3b2dee..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidLaunchTasksProvider.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import static com.android.tools.idea.profilers.AndroidProfilerLaunchTaskContributor.isProfilerLaunch;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.deployer.ApkVerifierTracker;
-import com.android.tools.idea.editors.literals.LiveEditService;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.profilers.AndroidProfilerLaunchTaskContributor;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTaskWrapper;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.deployment.liveedit.LiveEditApp;
-import com.android.tools.idea.run.tasks.ClearLogcatTask;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.android.tools.idea.run.tasks.DismissKeyguardTask;
-import com.android.tools.idea.run.tasks.ShowLogcatTask;
-import com.android.tools.idea.run.tasks.StartLiveUpdateMonitoringTask;
-import com.android.tools.ndk.run.editor.AutoAndroidDebuggerState;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.idea.blaze.android.run.binary.UserIdHelper;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.common.experiments.BoolExperiment;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Set;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** Normal launch tasks provider. #api4.1 */
-public class BlazeAndroidLaunchTasksProvider implements BlazeLaunchTasksProvider {
- public static final String NATIVE_DEBUGGING_ENABLED = "NATIVE_DEBUGGING_ENABLED";
- private static final Logger LOG = Logger.getInstance(BlazeAndroidLaunchTasksProvider.class);
- private static final BoolExperiment isLiveEditEnabled =
- new BoolExperiment("aswb.live.edit.enabled", false);
-
- private final Project project;
- private final BlazeAndroidRunContext runContext;
- private final ApplicationIdProvider applicationIdProvider;
- private final LaunchOptions.Builder launchOptionsBuilder;
-
- public BlazeAndroidLaunchTasksProvider(
- Project project,
- BlazeAndroidRunContext runContext,
- ApplicationIdProvider applicationIdProvider,
- LaunchOptions.Builder launchOptionsBuilder) {
- this.project = project;
- this.runContext = runContext;
- this.applicationIdProvider = applicationIdProvider;
- this.launchOptionsBuilder = launchOptionsBuilder;
- }
-
- @NotNull
- @Override
- public List getTasks(@NotNull IDevice device) throws ExecutionException {
- final List launchTasks = Lists.newArrayList();
-
- String packageName;
- try {
- packageName = applicationIdProvider.getPackageName();
- } catch (ApkProvisionException e) {
- throw new ExecutionException("Unable to determine application id: " + e);
- }
-
- Integer userId = runContext.getUserId(device);
- String userIdFlags = UserIdHelper.getFlagsFromUserId(userId);
- String skipVerification =
- ApkVerifierTracker.getSkipVerificationInstallationFlag(device, packageName);
- String pmInstallOption;
- if (skipVerification != null) {
- pmInstallOption = userIdFlags + " " + skipVerification;
- } else {
- pmInstallOption = userIdFlags;
- }
- launchOptionsBuilder.setPmInstallOptions(d -> pmInstallOption);
-
- LaunchOptions launchOptions = launchOptionsBuilder.build();
-
- // NOTE: Task for opening the profiler tool-window should come before deployment
- // to ensure the tool-window opens correctly. This is required because starting
- // the profiler session requires the tool-window to be open.
- if (isProfilerLaunch(runContext.getExecutor())) {
- launchTasks.add(new BlazeAndroidOpenProfilerWindowTask(project));
- }
-
- // TODO(kovalp): Check if there's any drawback to add these tasks with BlazeLaunchTaskWrapper
- // since it's different with ag/21610897
- if (launchOptions.isClearLogcatBeforeStart()) {
- launchTasks.add(new BlazeLaunchTaskWrapper(new ClearLogcatTask(project)));
- }
-
- launchTasks.add(new BlazeLaunchTaskWrapper(new DismissKeyguardTask()));
-
- if (launchOptions.isDeploy()) {
- ImmutableList deployTasks = runContext.getDeployTasks(device, launchOptions);
- launchTasks.addAll(deployTasks);
- }
-
- try {
- if (launchOptions.isDebug()) {
- launchTasks.add(
- new CheckApkDebuggableTask(project, runContext.getBuildStep().getDeployInfo()));
- }
-
- ImmutableList.Builder amStartOptions = ImmutableList.builder();
- amStartOptions.add(runContext.getAmStartOptions());
- if (isProfilerLaunch(runContext.getExecutor())) {
- amStartOptions.add(
- AndroidProfilerLaunchTaskContributor.getAmStartOptions(
- project,
- packageName,
- runContext.getProfileState(),
- device,
- runContext.getExecutor()));
- }
- BlazeLaunchTask appLaunchTask =
- runContext.getApplicationLaunchTask(
- launchOptions, userId, String.join(" ", amStartOptions.build()));
- if (appLaunchTask != null) {
- launchTasks.add(appLaunchTask);
- if (isLiveEditEnabled.getValue()) {
- // TODO(b/277244508): Fix Live Edit for Giraffe
- Set apks =
- runContext.getBuildStep().getDeployInfo().getApksToDeploy().stream()
- .map(f -> f.toPath())
- .collect(ImmutableSet.toImmutableSet());
-
- LiveEditApp app = new LiveEditApp(apks, device.getVersion().getApiLevel());
- launchTasks.add(
- new BlazeLaunchTaskWrapper(
- new StartLiveUpdateMonitoringTask(
- () ->
- LiveEditService.getInstance(project)
- .getDeployMonitor()
- .notifyAppDeploy(packageName, device, app))));
- }
- }
- } catch (ApkProvisionException e) {
- throw new ExecutionException("Unable to determine application id: " + e);
- }
-
- if (launchOptions.isOpenLogcatAutomatically()) {
- launchTasks.add(new BlazeLaunchTaskWrapper(new ShowLogcatTask(project, packageName)));
- }
-
- return ImmutableList.copyOf(launchTasks);
- }
-
- @Override
- @Nullable
- public ConnectDebuggerTask getConnectDebuggerTask() {
- LaunchOptions launchOptions = launchOptionsBuilder.build();
- if (!launchOptions.isDebug()) {
- return null;
- }
-
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = runContext.getBuildStep().getDeployInfo();
- } catch (ApkProvisionException e) {
- LOG.error(e);
- deployInfo = null;
- }
-
- BlazeAndroidDebuggerService debuggerService = BlazeAndroidDebuggerService.getInstance(project);
- if (isNativeDebuggingEnabled(launchOptions)) {
- AndroidDebugger debugger = debuggerService.getNativeDebugger();
- // The below state type should be AutoAndroidDebuggerState, but referencing it will crash the
- // task if the NDK plugin is not loaded.
- AndroidDebuggerState state = debugger.createState();
- debuggerService.configureNativeDebugger(state, deployInfo);
- return runContext.getDebuggerTask(debugger, state);
- } else {
- AndroidDebugger debugger = debuggerService.getDebugger();
- return runContext.getDebuggerTask(debugger, debugger.createState());
- }
- }
-
- private boolean isNativeDebuggingEnabled(LaunchOptions launchOptions) {
- Object flag = launchOptions.getExtraOption(NATIVE_DEBUGGING_ENABLED);
- return flag instanceof Boolean && (Boolean) flag;
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidOpenProfilerWindowTask.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidOpenProfilerWindowTask.java
deleted file mode 100644
index b3941316668..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidOpenProfilerWindowTask.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.profilers.ProfilerProgramRunner;
-import com.android.tools.idea.run.blaze.BlazeLaunchContext;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.project.Project;
-
-/** Opens the profiler tool window. */
-public class BlazeAndroidOpenProfilerWindowTask implements BlazeLaunchTask {
- private static final String ID = "OPEN_PROFILER_TOOLWINDOW";
- private final Project project;
-
- public BlazeAndroidOpenProfilerWindowTask(Project project) {
- this.project = project;
- }
-
- @Override
- public void run(BlazeLaunchContext launchContext) {
- ApplicationManager.getApplication()
- .invokeLater(() -> ProfilerProgramRunner.createProfilerToolWindow(project, null));
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidRunConfigurationRunner.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidRunConfigurationRunner.java
deleted file mode 100644
index 78728d9c46f..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidRunConfigurationRunner.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.AppRunSettings;
-import com.android.tools.idea.execution.common.ApplicationDeployer;
-import com.android.tools.idea.execution.common.ComponentLaunchOptions;
-import com.android.tools.idea.execution.common.DeployOptions;
-import com.android.tools.idea.run.ApkProvider;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.DeviceFutures;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeAndroidConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidComplicationConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutorRunProfileState;
-import com.android.tools.idea.run.configuration.execution.AndroidTileConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidWatchFaceConfigurationExecutor;
-import com.android.tools.idea.run.configuration.execution.ComplicationLaunchOptions;
-import com.android.tools.idea.run.configuration.execution.TileLaunchOptions;
-import com.android.tools.idea.run.configuration.execution.WatchFaceLaunchOptions;
-import com.android.tools.idea.run.editor.DeployTarget;
-import com.android.tools.idea.run.editor.DeployTargetState;
-import com.android.tools.idea.run.util.LaunchUtils;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep;
-import com.google.idea.blaze.android.run.deployinfo.BlazeApkProviderService;
-import com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator;
-import com.google.idea.blaze.base.command.BlazeInvocationContext.ContextType;
-import com.google.idea.blaze.base.experiments.ExperimentScope;
-import com.google.idea.blaze.base.issueparser.BlazeIssueParser;
-import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationRunner;
-import com.google.idea.blaze.base.scope.BlazeContext;
-import com.google.idea.blaze.base.scope.Scope;
-import com.google.idea.blaze.base.scope.ScopedTask;
-import com.google.idea.blaze.base.scope.output.IssueOutput;
-import com.google.idea.blaze.base.scope.scopes.IdeaLogScope;
-import com.google.idea.blaze.base.scope.scopes.ProblemsViewScope;
-import com.google.idea.blaze.base.scope.scopes.ToolWindowScope;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.settings.BlazeUserSettings;
-import com.google.idea.blaze.base.toolwindow.Task;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunProfileState;
-import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.ui.ConsoleView;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Key;
-import java.util.Collections;
-import java.util.concurrent.CancellationException;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.android.util.AndroidBundle;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Supports the execution. Used by both android_binary and android_test.
- *
- * Builds the APK and installs it, launches and debug tasks, etc.
- *
- *
Any indirection between android_binary/android_test, mobile-install, InstantRun etc. should
- * come via the strategy class.
- */
-public final class BlazeAndroidRunConfigurationRunner
- implements BlazeCommandRunConfigurationRunner {
-
- private static final Logger LOG = Logger.getInstance(BlazeAndroidRunConfigurationRunner.class);
-
- private static final Key RUN_CONTEXT_KEY =
- Key.create("blaze.run.context");
- public static final Key DEVICE_SESSION_KEY =
- Key.create("blaze.device.session");
-
- private final Module module;
- private final BlazeAndroidRunContext runContext;
- private final BlazeCommandRunConfiguration runConfig;
-
- public BlazeAndroidRunConfigurationRunner(
- Module module, BlazeAndroidRunContext runContext, BlazeCommandRunConfiguration runConfig) {
- this.module = module;
- this.runContext = runContext;
- this.runConfig = runConfig;
- }
-
- @Override
- @Nullable
- public final RunProfileState getRunProfileState(final Executor executor, ExecutionEnvironment env)
- throws ExecutionException {
-
- final AndroidFacet facet = AndroidFacet.getInstance(module);
- assert facet != null : "Enforced by fatal validation check in createRunner.";
- final Project project = env.getProject();
-
- boolean isDebug = executor instanceof DefaultDebugExecutor;
-
- BlazeAndroidDeviceSelector deviceSelector = runContext.getDeviceSelector();
- BlazeAndroidDeviceSelector.DeviceSession deviceSession =
- deviceSelector.getDevice(project, executor, env, isDebug, runConfig.getUniqueID());
-
- if (deviceSession == null) {
- return null;
- }
-
- DeployTarget deployTarget = deviceSession.deployTarget;
- if (deployTarget != null && deployTarget.hasCustomRunProfileState(executor)) {
- return deployTarget.getRunProfileState(executor, env, DeployTargetState.DEFAULT_STATE);
- }
-
- DeviceFutures deviceFutures = deviceSession.deviceFutures;
- if (deviceFutures == null) {
- // The user deliberately canceled, or some error was encountered and exposed by the chooser.
- // Quietly exit.
- return null;
- }
-
- if (deviceFutures.get().isEmpty()) {
- throw new ExecutionException(AndroidBundle.message("deployment.target.not.found"));
- }
-
- if (isDebug) {
- String error = canDebug(deviceFutures, facet, module.getName());
- if (error != null) {
- throw new ExecutionException(error);
- }
- }
-
- LaunchOptions.Builder launchOptionsBuilder = getDefaultLaunchOptions().setDebug(isDebug);
- runContext.augmentLaunchOptions(launchOptionsBuilder);
-
- // Store the run context on the execution environment so before-run tasks can access it.
- env.putCopyableUserData(RUN_CONTEXT_KEY, runContext);
- env.putCopyableUserData(DEVICE_SESSION_KEY, deviceSession);
-
- BlazeAndroidConfigurationExecutor runner =
- new BlazeAndroidConfigurationExecutor(
- runContext.getConsoleProvider(),
- runContext.getApplicationIdProvider(),
- env,
- deviceFutures,
- runContext.getLaunchTasksProvider(launchOptionsBuilder),
- LaunchOptions.builder().build());
- return new AndroidConfigurationExecutorRunProfileState(runner);
- }
-
- private RunProfileState getWearExecutor(
- ComponentLaunchOptions launchOptions, ExecutionEnvironment env, DeployTarget deployTarget)
- throws ExecutionException {
-
- AppRunSettings settings =
- new AppRunSettings() {
- @NotNull
- @Override
- public DeployOptions getDeployOptions() {
- return new DeployOptions(Collections.emptyList(), "", true, true);
- }
-
- @NotNull
- @Override
- public ComponentLaunchOptions getComponentLaunchOptions() {
- return launchOptions;
- }
-
- @Override
- public Module getModule() {
- return runConfig.getModules()[0];
- }
- };
-
- AndroidConfigurationExecutor configurationExecutor;
- ApplicationIdProvider appIdProvider = runContext.getApplicationIdProvider();
- ApkProvider apkProvider =
- BlazeApkProviderService.getInstance()
- .getApkProvider(env.getProject(), runContext.getBuildStep());
- DeviceFutures deviceFutures = deployTarget.getDevices(env.getProject());
-
- if (launchOptions instanceof TileLaunchOptions) {
- configurationExecutor =
- new AndroidTileConfigurationExecutor(
- env, deviceFutures, settings, appIdProvider, apkProvider) {
- @NotNull
- @Override
- public ApplicationDeployer getApplicationDeployer(@NotNull ConsoleView console)
- throws ExecutionException {
- if (runContext.getBuildStep() instanceof MobileInstallBuildStep) {
- return new MobileInstallApplicationDeployer(console);
- }
- return super.getApplicationDeployer(console);
- }
- };
- } else if (launchOptions instanceof WatchFaceLaunchOptions) {
- configurationExecutor =
- new AndroidWatchFaceConfigurationExecutor(
- env, deviceFutures, settings, appIdProvider, apkProvider) {
- @NotNull
- @Override
- public ApplicationDeployer getApplicationDeployer(@NotNull ConsoleView console)
- throws ExecutionException {
- if (runContext.getBuildStep() instanceof MobileInstallBuildStep) {
- return new MobileInstallApplicationDeployer(console);
- }
- return super.getApplicationDeployer(console);
- }
- };
- } else if (launchOptions instanceof ComplicationLaunchOptions) {
- configurationExecutor =
- new AndroidComplicationConfigurationExecutor(
- env, deviceFutures, settings, appIdProvider, apkProvider) {
- @NotNull
- @Override
- public ApplicationDeployer getApplicationDeployer(@NotNull ConsoleView console)
- throws ExecutionException {
- if (runContext.getBuildStep() instanceof MobileInstallBuildStep) {
- return new MobileInstallApplicationDeployer(console);
- }
- return super.getApplicationDeployer(console);
- }
- };
- } else {
- throw new RuntimeException("Unknown launch options " + launchOptions.getClass().getName());
- }
-
- return new AndroidConfigurationExecutorRunProfileState(
- new BlazeWrapperForAndroidConfigurationExecutor(configurationExecutor));
- }
-
- @Nullable
- private static String canDebug(
- DeviceFutures deviceFutures, AndroidFacet facet, String moduleName) {
- // If we are debugging on a device, then the app needs to be debuggable
- for (ListenableFuture future : deviceFutures.get()) {
- if (!future.isDone()) {
- // this is an emulator, and we assume that all emulators are debuggable
- continue;
- }
- IDevice device = Futures.getUnchecked(future);
- if (!LaunchUtils.canDebugAppOnDevice(facet, device)) {
- return AndroidBundle.message(
- "android.cannot.debug.noDebugPermissions", moduleName, device.getName());
- }
- }
- return null;
- }
-
- private static LaunchOptions.Builder getDefaultLaunchOptions() {
- return LaunchOptionsCompat.getDefaultLaunchOptions();
- }
-
- @Override
- public boolean executeBeforeRunTask(ExecutionEnvironment env) {
- final Project project = env.getProject();
- BlazeUserSettings settings = BlazeUserSettings.getInstance();
- return Scope.root(
- context -> {
- context
- .push(new ProblemsViewScope(project, settings.getShowProblemsViewOnRun()))
- .push(new ExperimentScope())
- .push(
- new ToolWindowScope.Builder(
- project, new Task(project, "Build apk", Task.Type.BEFORE_LAUNCH))
- .setPopupBehavior(settings.getShowBlazeConsoleOnRun())
- .setIssueParsers(
- BlazeIssueParser.defaultIssueParsers(
- project,
- WorkspaceRoot.fromProject(project),
- ContextType.BeforeRunTask))
- .build())
- .push(new IdeaLogScope());
-
- BlazeAndroidRunContext runContext = env.getCopyableUserData(RUN_CONTEXT_KEY);
- if (runContext == null) {
- IssueOutput.error("Could not find run context. Please try again").submit(context);
- return false;
- }
- BlazeAndroidDeviceSelector.DeviceSession deviceSession =
- env.getCopyableUserData(DEVICE_SESSION_KEY);
-
- ApkBuildStep buildStep = runContext.getBuildStep();
- ScopedTask buildTask =
- new ScopedTask(context) {
- @Override
- protected Void execute(BlazeContext context) {
- buildStep.build(context, deviceSession);
- return null;
- }
- };
-
- try {
- ListenableFuture buildFuture =
- ProgressiveTaskWithProgressIndicator.builder(
- project,
- String.format("Executing %s apk build", Blaze.buildSystemName(project)))
- .submitTaskWithResult(buildTask);
- Futures.getChecked(buildFuture, ExecutionException.class);
- } catch (ExecutionException e) {
- context.setHasError();
- } catch (CancellationException e) {
- context.setCancelled();
- } catch (Exception e) {
- LOG.error(e);
- return false;
- }
- return context.shouldContinue();
- });
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidRunContext.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidRunContext.java
deleted file mode 100644
index c1e33020bae..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeAndroidRunContext.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.common.collect.ImmutableList;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import javax.annotation.Nullable;
-import org.jetbrains.annotations.NotNull;
-
-/** Instantiated when the configuration wants to run. */
-public interface BlazeAndroidRunContext {
-
- BlazeAndroidDeviceSelector getDeviceSelector();
-
- void augmentLaunchOptions(LaunchOptions.Builder options);
-
- ConsoleProvider getConsoleProvider();
-
- ApkBuildStep getBuildStep();
-
- ApplicationIdProvider getApplicationIdProvider() throws ExecutionException;
-
- BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException;
-
- /** Returns the tasks to deploy the application. */
- ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException;
-
- /** Returns the task to launch the application. */
- @Nullable
- BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions,
- @Nullable Integer userId,
- @NotNull String contributorsAmStartOptions)
- throws ExecutionException;
-
- /** Returns the task to connect the debugger. */
- @Nullable
- ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState);
-
- @Nullable
- Integer getUserId(IDevice device) throws ExecutionException;
-
- String getAmStartOptions();
-
- Executor getExecutor();
-
- ProfilerState getProfileState();
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeWrapperForAndroidConfigurationExecutor.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeWrapperForAndroidConfigurationExecutor.java
deleted file mode 100644
index be6f1f8552c..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/BlazeWrapperForAndroidConfigurationExecutor.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.run.DeviceFutures;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutor;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.progress.ProgressIndicator;
-import org.jetbrains.annotations.NotNull;
-
-/** Implementation of {@code AndroidConfigurationExecutor} specific for Blaze project. */
-public class BlazeWrapperForAndroidConfigurationExecutor implements AndroidConfigurationExecutor {
- private final AndroidConfigurationExecutor delegateExecutor;
-
- BlazeWrapperForAndroidConfigurationExecutor(@NotNull AndroidConfigurationExecutor executor) {
- delegateExecutor = executor;
- }
-
- @NotNull
- @Override
- public RunConfiguration getConfiguration() {
- return delegateExecutor.getConfiguration();
- }
-
- @NotNull
- @Override
- public DeviceFutures getDeviceFutures() {
- return delegateExecutor.getDeviceFutures();
- }
-
- @NotNull
- @Override
- public RunContentDescriptor run(@NotNull ProgressIndicator indicator) throws ExecutionException {
- return delegateExecutor.run(indicator);
- }
-
- @NotNull
- @Override
- public RunContentDescriptor debug(@NotNull ProgressIndicator indicator)
- throws ExecutionException {
- return delegateExecutor.debug(indicator);
- }
-
- @NotNull
- @Override
- public RunContentDescriptor applyChanges(@NotNull ProgressIndicator indicator) {
- throw new RuntimeException("Apply code changes is not supported for blaze");
- }
-
- @NotNull
- @Override
- public RunContentDescriptor applyCodeChanges(@NotNull ProgressIndicator indicator) {
- throw new RuntimeException("Apply changes is not supported for blaze");
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/CheckApkDebuggableTask.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/CheckApkDebuggableTask.java
deleted file mode 100644
index 748734ce06b..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/CheckApkDebuggableTask.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import static com.google.common.collect.ImmutableList.toImmutableList;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.RunConfigurationNotifier;
-import com.android.tools.idea.run.blaze.BlazeLaunchContext;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableList;
-import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceFile;
-import com.google.devrel.gmscore.tools.apk.arsc.Chunk;
-import com.google.devrel.gmscore.tools.apk.arsc.XmlAttribute;
-import com.google.devrel.gmscore.tools.apk.arsc.XmlChunk;
-import com.google.devrel.gmscore.tools.apk.arsc.XmlStartElementChunk;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.project.Project;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.zip.ZipFile;
-import org.jetbrains.annotations.NotNull;
-
-/** Checks APKs to see if they are debuggable and warn the user if they aren't. */
-public class CheckApkDebuggableTask implements BlazeLaunchTask {
- private static final String ID = "APK_DEBUGGABILITY_CHECKER";
- private final BlazeAndroidDeployInfo deployInfo;
-
- public CheckApkDebuggableTask(Project project, BlazeAndroidDeployInfo deployInfo) {
- this.deployInfo = deployInfo;
- }
-
- @Override
- public void run(@NotNull BlazeLaunchContext launchContext) throws ExecutionException {
- checkApkDebuggableTaskDelegate(
- launchContext.getEnv().getProject(), deployInfo, launchContext.getDevice());
- }
-
- /**
- * Checks if all APKs in the deploy info are debuggable and output an error message to console if
- * any of them aren't. This check doesn't apply if the target device is a running a debug build
- * android (e.g. userdebug build) and will simply return.
- */
- @VisibleForTesting
- public static void checkApkDebuggableTaskDelegate(
- Project project, BlazeAndroidDeployInfo deployInfo, IDevice device)
- throws ExecutionException {
- if (isDebugDevice(device)) {
- return;
- }
- try {
- ImmutableList nonDebuggableApkNames =
- getNonDebuggableDeployApks(deployInfo).stream()
- .map(File::getName)
- .collect(toImmutableList());
- if (nonDebuggableApkNames.isEmpty()) {
- return;
- }
- // Use "and" as delimiter because there won't be more than 2 APKs, so "and" makes more sense.
- String message =
- "The \"android:debuggable\" attribute is not set to \"true\" in "
- + String.join(" and ", nonDebuggableApkNames)
- + ". Debugger may not attach properly or attach at all."
- + " Please ensure \"android:debuggable\" attribute is set to true or"
- + " overridden to true via manifest overrides.";
- RunConfigurationNotifier.INSTANCE.notifyWarning(project, "", message);
- } catch (IOException e) {
- throw new ExecutionException("Could not read deploy apks: " + e.getMessage());
- }
- }
-
- private static ImmutableList getNonDebuggableDeployApks(BlazeAndroidDeployInfo deployInfo)
- throws IOException {
- ImmutableList.Builder nonDebuggableApks = ImmutableList.builder();
- for (File apk : deployInfo.getApksToDeploy()) {
- if (!isApkDebuggable(apk)) {
- nonDebuggableApks.add(apk);
- }
- }
- return nonDebuggableApks.build();
- }
-
- /** Returns true if the device is a debug build device. */
- private static boolean isDebugDevice(IDevice device) {
- String roDebuggable = device.getProperty("ro.debuggable");
- return (roDebuggable != null && roDebuggable.equals("1"));
- }
-
- @VisibleForTesting
- public static boolean isApkDebuggable(File apk) throws IOException {
- try (ZipFile zipFile = new ZipFile(apk);
- InputStream stream = zipFile.getInputStream(zipFile.getEntry("AndroidManifest.xml"))) {
- BinaryResourceFile file = BinaryResourceFile.fromInputStream(stream);
- List chunks = file.getChunks();
-
- if (chunks.isEmpty()) {
- throw new IllegalArgumentException("Invalid APK, empty manifest");
- }
-
- if (!(chunks.get(0) instanceof XmlChunk)) {
- throw new IllegalArgumentException("APK manifest chunk[0] != XmlChunk");
- }
-
- XmlChunk xmlChunk = (XmlChunk) chunks.get(0);
- for (Chunk chunk : xmlChunk.getChunks().values()) {
- if (!(chunk instanceof XmlStartElementChunk)) {
- continue;
- }
-
- XmlStartElementChunk startChunk = (XmlStartElementChunk) chunk;
- if (startChunk.getName().equals("application")) {
- for (XmlAttribute attribute : startChunk.getAttributes()) {
- if (attribute.name().equals("debuggable")) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/LaunchOptionsCompat.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/LaunchOptionsCompat.java
deleted file mode 100644
index 5a606a8a2ea..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/LaunchOptionsCompat.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.run.LaunchOptions;
-
-/** Compat class for LunchOptions.Builder. */
-public class LaunchOptionsCompat {
-
- private LaunchOptionsCompat() {}
-
- /** Create default launch options to maintain compatibility with #api211. */
- public static LaunchOptions.Builder getDefaultLaunchOptions() {
- return LaunchOptions.builder().setClearLogcatBeforeStart(false);
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/MobileInstallApplicationDeployer.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/MobileInstallApplicationDeployer.java
deleted file mode 100644
index dad762309be..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/runner/MobileInstallApplicationDeployer.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.deployer.ApkParser;
-import com.android.tools.deployer.Deployer;
-import com.android.tools.deployer.DeployerException;
-import com.android.tools.deployer.model.Apk;
-import com.android.tools.deployer.model.App;
-import com.android.tools.idea.execution.common.ApplicationDeployer;
-import com.android.tools.idea.execution.common.DeployOptions;
-import com.android.tools.idea.run.ApkFileUnit;
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.configuration.execution.AdbCommandCaptureLoggerWithConsole;
-import com.intellij.execution.ui.ConsoleView;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.progress.ProgressIndicator;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.stream.Collectors;
-import org.jetbrains.annotations.NotNull;
-
-/** Deploys mobile install application. */
-public class MobileInstallApplicationDeployer implements ApplicationDeployer {
- private static final Logger LOG = Logger.getInstance(MobileInstallApplicationDeployer.class);
- private final ConsoleView myConsole;
-
- public MobileInstallApplicationDeployer(ConsoleView console) {
- myConsole = console;
- }
-
- @NotNull
- @Override
- public Deployer.Result fullDeploy(
- @NotNull IDevice device,
- @NotNull ApkInfo apkInfo,
- @NotNull DeployOptions deployOptions,
- ProgressIndicator indicator)
- throws DeployerException {
- final List apkPaths =
- apkInfo.getFiles().stream()
- .map(ApkFileUnit::getApkPath)
- .map(Path::toString)
- .collect(Collectors.toList());
- final List apks = new ApkParser().parsePaths(apkPaths);
- App app =
- new App(
- apkInfo.getApplicationId(),
- apks,
- device,
- new AdbCommandCaptureLoggerWithConsole(LOG, myConsole));
- return new Deployer.Result(false, false, false, app);
- }
-
- @NotNull
- @Override
- public Deployer.Result applyChangesDeploy(
- @NotNull IDevice device,
- @NotNull ApkInfo app,
- @NotNull DeployOptions deployOptions,
- ProgressIndicator indicator)
- throws DeployerException {
- throw new RuntimeException("Apply changes is not supported for mobile-install");
- }
-
- @NotNull
- @Override
- public Deployer.Result applyCodeChangesDeploy(
- @NotNull IDevice device,
- @NotNull ApkInfo app,
- @NotNull DeployOptions deployOptions,
- ProgressIndicator indicator)
- throws DeployerException {
- throw new RuntimeException("Apply code changes is not supported for mobile-install");
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestLaunchTask.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestLaunchTask.java
deleted file mode 100644
index dc7dd974c06..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestLaunchTask.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.tools.idea.run.blaze.BlazeLaunchContext;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.configuration.execution.ExecutionUtils;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.idea.blaze.base.async.executor.BlazeExecutor;
-import com.google.idea.blaze.base.async.process.ExternalTask;
-import com.google.idea.blaze.base.async.process.LineProcessingOutputStream;
-import com.google.idea.blaze.base.command.BlazeCommand;
-import com.google.idea.blaze.base.command.BlazeCommandName;
-import com.google.idea.blaze.base.command.BlazeFlags;
-import com.google.idea.blaze.base.command.buildresult.BuildResultHelper;
-import com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException;
-import com.google.idea.blaze.base.command.buildresult.BuildResultHelperBep;
-import com.google.idea.blaze.base.filecache.FileCaches;
-import com.google.idea.blaze.base.ideinfo.AndroidInstrumentationInfo;
-import com.google.idea.blaze.base.ideinfo.TargetIdeInfo;
-import com.google.idea.blaze.base.ideinfo.TargetKey;
-import com.google.idea.blaze.base.model.BlazeProjectData;
-import com.google.idea.blaze.base.model.primitives.Label;
-import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
-import com.google.idea.blaze.base.projectview.ProjectViewManager;
-import com.google.idea.blaze.base.projectview.ProjectViewSet;
-import com.google.idea.blaze.base.run.testlogs.BlazeTestResultHolder;
-import com.google.idea.blaze.base.scope.Scope;
-import com.google.idea.blaze.base.scope.output.IssueOutput;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs;
-import com.google.idea.blaze.base.sync.aspects.BuildResult;
-import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
-import com.google.idea.blaze.base.util.SaveUtil;
-import com.google.idea.blaze.java.AndroidBlazeRules.RuleTypes;
-import com.intellij.execution.process.ProcessAdapter;
-import com.intellij.execution.process.ProcessEvent;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.ui.ConsoleView;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.ide.PooledThreadExecutor;
-
-/**
- * An Android application launcher that invokes `blaze test` on an android_test target, and sets up
- * process handling and debugging for the test run.
- */
-public class BlazeAndroidTestLaunchTask implements BlazeLaunchTask {
- private static final String ID = "BLAZE_ANDROID_TEST";
-
- // Uses a local device/emulator attached to adb to run an android_test.
- public static final String TEST_LOCAL_DEVICE =
- BlazeFlags.TEST_ARG + "--device_broker_type=LOCAL_ADB_SERVER";
- // Uses a local device/emulator attached to adb to run an android_test.
- public static final String TEST_DEBUG = BlazeFlags.TEST_ARG + "--enable_debug";
- // Specifies the serial number for a local test device.
- private static final String TEST_DEVICE_SERIAL = "--device_serial_number=";
- private static final Logger LOG = Logger.getInstance(BlazeAndroidTestLaunchTask.class);
-
- private final Project project;
- private final Label target;
- private final List buildFlags;
- private final BlazeAndroidTestFilter testFilter;
- private final BlazeTestResultHolder testResultsHolder;
-
- private ListenableFuture blazeResult;
-
- private final BlazeAndroidTestRunContext runContext;
-
- private final boolean debug;
-
- public BlazeAndroidTestLaunchTask(
- Project project,
- Label target,
- List buildFlags,
- BlazeAndroidTestFilter testFilter,
- BlazeAndroidTestRunContext runContext,
- boolean debug,
- BlazeTestResultHolder testResultsHolder) {
- this.project = project;
- this.target = target;
- this.buildFlags = buildFlags;
- this.testFilter = testFilter;
- this.runContext = runContext;
- this.debug = debug;
- this.testResultsHolder = testResultsHolder;
- }
-
- @Override
- public void run(@NotNull BlazeLaunchContext launchContext)
- throws com.intellij.execution.ExecutionException {
- BlazeExecutor blazeExecutor = BlazeExecutor.getInstance();
-
- final ProcessHandler processHandler = launchContext.getProcessHandler();
-
- blazeResult =
- blazeExecutor.submit(
- () ->
- Scope.root(
- context -> {
- SaveUtil.saveAllFiles();
-
- ProjectViewSet projectViewSet =
- ProjectViewManager.getInstance(project).getProjectViewSet();
- if (projectViewSet == null) {
- IssueOutput.error("Could not load project view. Please resync project.")
- .submit(context);
- return false;
- }
-
- BlazeProjectData projectData =
- BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
- TargetIdeInfo targetInfo =
- projectData.getTargetMap().get(TargetKey.forPlainTarget(target));
- if (targetInfo == null
- || targetInfo.getKind()
- != RuleTypes.ANDROID_INSTRUMENTATION_TEST.getKind()) {
- IssueOutput.error(
- "Unable to identify target \""
- + target
- + "\". If this is a newly added target, please sync the"
- + " project and try again.")
- .submit(context);
- return null;
- }
- AndroidInstrumentationInfo testInstrumentationInfo =
- targetInfo.getAndroidInstrumentationInfo();
- if (testInstrumentationInfo == null) {
- IssueOutput.error(
- "Required target data missing for \""
- + target
- + "\". Has the target definition changed recently? Please"
- + " sync the project and try again.")
- .submit(context);
- return null;
- }
-
- BlazeCommand.Builder commandBuilder =
- BlazeCommand.builder(
- Blaze.getBuildSystemProvider(project)
- .getBuildSystem()
- .getBuildInvoker(project, context),
- BlazeCommandName.TEST)
- .addTargets(target);
- // Build flags must match BlazeBeforeRunTask.
- commandBuilder.addBlazeFlags(buildFlags);
-
- // Run the test on the selected local device/emulator if no target device is
- // specified.
- Label targetDevice = testInstrumentationInfo.getTargetDevice();
- if (targetDevice == null) {
- commandBuilder
- .addBlazeFlags(TEST_LOCAL_DEVICE, BlazeFlags.TEST_OUTPUT_STREAMED)
- .addBlazeFlags(
- testDeviceSerialFlags(launchContext.getDevice().getSerialNumber()))
- .addBlazeFlags(testFilter.getBlazeFlags());
- }
-
- if (debug) {
- commandBuilder.addBlazeFlags(TEST_DEBUG, BlazeFlags.NO_CACHE_TEST_RESULTS);
- }
-
- ConsoleView console = launchContext.getConsoleView();
- LineProcessingOutputStream.LineProcessor stdoutLineProcessor =
- line -> {
- ExecutionUtils.println(console, line);
- return true;
- };
- LineProcessingOutputStream.LineProcessor stderrLineProcessor =
- line -> {
- ExecutionUtils.println(console, line);
- return true;
- };
-
- ExecutionUtils.println(
- console,
- String.format("Starting %s test...\n", Blaze.buildSystemName(project)));
-
- int retVal;
- try (BuildResultHelper buildResultHelper = new BuildResultHelperBep()) {
- commandBuilder.addBlazeFlags(buildResultHelper.getBuildFlags());
- BlazeCommand command = commandBuilder.build();
- ExecutionUtils.println(console, command + "\n");
-
- retVal =
- ExternalTask.builder(WorkspaceRoot.fromProject(project))
- .addBlazeCommand(command)
- .context(context)
- .stdout(LineProcessingOutputStream.of(stdoutLineProcessor))
- .stderr(LineProcessingOutputStream.of(stderrLineProcessor))
- .build()
- .run();
-
- if (retVal != 0) {
- context.setHasError();
- } else {
- testResultsHolder.setTestResults(
- buildResultHelper.getTestResults(Optional.empty()));
- }
- ListenableFuture unusedFuture =
- FileCaches.refresh(
- project,
- context,
- BlazeBuildOutputs.noOutputs(BuildResult.fromExitCode(retVal)));
- } catch (GetArtifactsException e) {
- LOG.error(e.getMessage());
- }
- return !context.hasErrors();
- }));
-
- blazeResult.addListener(runContext::onLaunchTaskComplete, PooledThreadExecutor.INSTANCE);
-
- // The debug case is set up in ConnectBlazeTestDebuggerTask
- if (!debug) {
- waitAndSetUpForKillingBlazeOnStop(processHandler);
- }
- }
-
- /**
- * Hooks up the Blaze process to be killed if the user hits the 'Stop' button, then waits for the
- * Blaze process to stop. In non-debug mode, we wait for test execution to finish before returning
- * from launch() (this matches the behavior of the stock ddmlib runner).
- */
- @SuppressWarnings("Interruption")
- private void waitAndSetUpForKillingBlazeOnStop(@NotNull final ProcessHandler processHandler) {
- processHandler.addProcessListener(
- new ProcessAdapter() {
- @Override
- public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
- blazeResult.cancel(true /* mayInterruptIfRunning */);
- }
- });
-
- try {
- blazeResult.get();
- } catch (InterruptedException e) {
- // We've been interrupted - cancel the underlying Blaze process.
- blazeResult.cancel(true /* mayInterruptIfRunning */);
- } catch (ExecutionException e) {
- LOG.error(e);
- }
- }
-
- @NotNull
- private static String testDeviceSerialFlags(@NotNull String serial) {
- return BlazeFlags.TEST_ARG + TEST_DEVICE_SERIAL + serial;
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestProgramRunner.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestProgramRunner.java
deleted file mode 100644
index eab7b24890f..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestProgramRunner.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.tools.idea.run.configuration.AndroidConfigurationProgramRunner;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutor;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfigurationType;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunProfile;
-import com.intellij.execution.configurations.RunProfileState;
-import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.executors.DefaultRunExecutor;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.progress.ProgressIndicator;
-import java.util.Collections;
-import java.util.List;
-import org.jetbrains.annotations.NotNull;
-
-/** Program runner for configurations from {@link BlazeAndroidTestRunConfigurationHandler}. */
-public class BlazeAndroidTestProgramRunner extends AndroidConfigurationProgramRunner {
- @Override
- public boolean canRun(String executorId, RunProfile profile) {
- BlazeAndroidRunConfigurationHandler handler =
- BlazeAndroidRunConfigurationHandler.getHandlerFrom(profile);
- if (!(handler instanceof BlazeAndroidTestRunConfigurationHandler)) {
- return false;
- }
- if (!(profile instanceof BlazeCommandRunConfiguration)) {
- return false;
- }
- return DefaultRunExecutor.EXECUTOR_ID.equals(executorId)
- || DefaultDebugExecutor.EXECUTOR_ID.equals(executorId);
- }
-
- @Override
- public String getRunnerId() {
- return "AndroidTestProgramRunner";
- }
-
- @Override
- protected boolean canRunWithMultipleDevices(@NotNull String executorId) {
- return true;
- }
-
- @NotNull
- @Override
- protected List getSupportedConfigurationTypeIds() {
- return Collections.singletonList(BlazeCommandRunConfigurationType.getInstance().getId());
- }
-
- @NotNull
- @Override
- protected RunContentDescriptor run(
- @NotNull ExecutionEnvironment environment,
- @NotNull RunProfileState state,
- @NotNull ProgressIndicator indicator)
- throws ExecutionException {
- final AndroidConfigurationExecutor state1 = (AndroidConfigurationExecutor) state;
- if (DefaultDebugExecutor.EXECUTOR_ID.equals(environment.getExecutor().getId())) {
- return state1.debug(indicator);
- }
- if (DefaultRunExecutor.EXECUTOR_ID.equals(environment.getExecutor().getId())) {
- return state1.run(indicator);
- }
- throw new RuntimeException("Unsupported executor");
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunConfigurationHandler.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunConfigurationHandler.java
deleted file mode 100644
index 050ddc03fee..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunConfigurationHandler.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import static com.android.tools.idea.run.deployment.DeviceAndSnapshotComboBoxAction.DEPLOYS_TO_LOCAL_DEVICE;
-
-import com.android.tools.idea.run.ValidationError;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.idea.blaze.android.run.ApkBuildStepProvider;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationCommonState;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationValidationUtil;
-import com.google.idea.blaze.android.run.LaunchMetrics;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunConfigurationRunner;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.google.idea.blaze.android.run.runner.FullApkBuildStep;
-import com.google.idea.blaze.android.run.test.BlazeAndroidTestLaunchMethodsProvider.AndroidTestLaunchMethod;
-import com.google.idea.blaze.base.command.BlazeCommandName;
-import com.google.idea.blaze.base.command.BlazeInvocationContext;
-import com.google.idea.blaze.base.model.primitives.Label;
-import com.google.idea.blaze.base.model.primitives.TargetExpression;
-import com.google.idea.blaze.base.projectview.ProjectViewManager;
-import com.google.idea.blaze.base.projectview.ProjectViewSet;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder;
-import com.google.idea.blaze.base.run.ExecutorType;
-import com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationRunner;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.sync.data.BlazeDataStorage;
-import com.google.idea.blaze.base.sync.projectstructure.ModuleFinder;
-import com.google.idea.blaze.java.AndroidBlazeRules;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.JavaExecutionUtil;
-import com.intellij.execution.configurations.RuntimeConfigurationException;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/**
- * {@link com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationHandler} for
- * android_test targets.
- */
-public class BlazeAndroidTestRunConfigurationHandler
- implements BlazeAndroidRunConfigurationHandler {
- private final Project project;
- private final BlazeAndroidTestRunConfigurationState configState;
-
- BlazeAndroidTestRunConfigurationHandler(BlazeCommandRunConfiguration configuration) {
- this.project = configuration.getProject();
- this.configState =
- new BlazeAndroidTestRunConfigurationState(
- Blaze.buildSystemName(configuration.getProject()));
- configuration.putUserData(DEPLOYS_TO_LOCAL_DEVICE, true);
- }
-
- @Override
- public BlazeAndroidTestRunConfigurationState getState() {
- return configState;
- }
-
- @Override
- public BlazeAndroidRunConfigurationCommonState getCommonState() {
- return configState.getCommonState();
- }
-
- @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();
-
- ImmutableList blazeFlags =
- configState
- .getCommonState()
- .getExpandedBuildFlags(
- project,
- projectViewSet,
- BlazeCommandName.TEST,
- BlazeInvocationContext.runConfigContext(
- ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), false));
- ImmutableList exeFlags =
- ImmutableList.copyOf(
- configState.getCommonState().getExeFlagsState().getFlagsForExternalProcesses());
-
- // 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();
- Label label = Label.create(configuration.getSingleTarget().toString());
-
- ApkBuildStep buildStep =
- getTestBuildStep(
- project, configState, configuration, blazeFlags, exeFlags, launchId, label);
-
- BlazeAndroidRunContext runContext =
- new BlazeAndroidTestRunContext(
- project, facet, configuration, env, configState, label, blazeFlags, buildStep);
-
- LaunchMetrics.logTestLaunch(
- launchId, configState.getLaunchMethod().name(), env.getExecutor().getId());
-
- return new BlazeAndroidRunConfigurationRunner(module, runContext, configuration);
- }
-
- private static ApkBuildStep getTestBuildStep(
- Project project,
- BlazeAndroidTestRunConfigurationState configState,
- BlazeCommandRunConfiguration configuration,
- ImmutableList blazeFlags,
- ImmutableList exeFlags,
- String launchId,
- Label label)
- throws ExecutionException {
- if (configuration.getTargetKind()
- == AndroidBlazeRules.RuleTypes.ANDROID_INSTRUMENTATION_TEST.getKind()) {
- boolean useMobileInstall =
- AndroidTestLaunchMethod.MOBILE_INSTALL.equals(configState.getLaunchMethod());
- return ApkBuildStepProvider.getInstance(Blaze.getBuildSystemName(project))
- .getAitBuildStep(
- project,
- useMobileInstall,
- /* nativeDebuggingEnabled= */ false,
- label,
- blazeFlags,
- exeFlags,
- launchId);
- } else {
- // TODO(b/248317444): This path is only invoked for the deprecated {@code android_test}
- // targets, and should eventually be removed.
- return new FullApkBuildStep(project, label, blazeFlags, /* nativeDebuggingEnabled= */ false);
- }
- }
-
- @Override
- public final void checkConfiguration() throws RuntimeConfigurationException {
- BlazeAndroidRunConfigurationValidationUtil.throwTopConfigurationError(validate());
- }
-
- /**
- * We collect errors rather than throwing to avoid missing fatal errors by exiting early for a
- * warning. We use a separate method for the collection so the compiler prevents us from
- * accidentally throwing.
- */
- private List validate() {
- List errors = Lists.newArrayList();
- errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateWorkspaceModule(project));
- errors.addAll(configState.validate(project));
- return errors;
- }
-
- @Override
- @Nullable
- public String suggestedName(BlazeCommandRunConfiguration configuration) {
- TargetExpression target = configuration.getSingleTarget();
- if (target == null) {
- return null;
- }
- BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
-
- boolean isClassTest =
- configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_CLASS;
- boolean isMethodTest =
- configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_METHOD;
- if ((isClassTest || isMethodTest) && configState.getClassName() != null) {
- // Get the class name without the package.
- String className = JavaExecutionUtil.getPresentableClassName(configState.getClassName());
- if (className != null) {
- String targetString = className;
- if (isMethodTest) {
- targetString += "#" + configState.getMethodName();
- }
-
- if (getState().getLaunchMethod().equals(AndroidTestLaunchMethod.NON_BLAZE)) {
- return targetString;
- } else {
- return nameBuilder.setTargetString(targetString).build();
- }
- }
- }
- return nameBuilder.build();
- }
-
- @Override
- @Nullable
- public BlazeCommandName getCommandName() {
- if (getState().getLaunchMethod().equals(AndroidTestLaunchMethod.BLAZE_TEST)) {
- return BlazeCommandName.TEST;
- } else if (getState().getLaunchMethod().equals(AndroidTestLaunchMethod.MOBILE_INSTALL)) {
- return BlazeCommandName.MOBILE_INSTALL;
- }
- return null;
- }
-
- @Override
- public String getHandlerName() {
- return "Android Test Handler";
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunContext.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunContext.java
deleted file mode 100644
index feaec07157c..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/BlazeAndroidTestRunContext.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-import static com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryNormalBuildRunContextBase.getApkInfoToInstall;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApkProvider;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.deployinfo.BlazeApkProviderService;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.google.idea.blaze.android.run.test.BlazeAndroidTestLaunchMethodsProvider.AndroidTestLaunchMethod;
-import com.google.idea.blaze.base.model.primitives.Label;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.run.smrunner.BlazeTestUiSession;
-import com.google.idea.blaze.base.run.testlogs.BlazeTestResultHolder;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Run context for android_test. */
-public class BlazeAndroidTestRunContext implements BlazeAndroidRunContext {
- protected final Project project;
- protected final AndroidFacet facet;
- protected final BlazeCommandRunConfiguration runConfiguration;
- protected final ExecutionEnvironment env;
- protected final BlazeAndroidTestRunConfigurationState configState;
- protected final Label label;
- protected final ImmutableList blazeFlags;
- protected final List launchTaskCompleteListeners = Lists.newArrayList();
- protected final ConsoleProvider consoleProvider;
- protected final ApkBuildStep buildStep;
- protected final ApplicationIdProvider applicationIdProvider;
- protected final ApkProvider apkProvider;
- private final BlazeTestResultHolder testResultsHolder = new BlazeTestResultHolder();
-
- public BlazeAndroidTestRunContext(
- Project project,
- AndroidFacet facet,
- BlazeCommandRunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidTestRunConfigurationState configState,
- Label label,
- ImmutableList blazeFlags,
- ApkBuildStep buildStep) {
- this.project = project;
- this.facet = facet;
- this.runConfiguration = runConfiguration;
- this.env = env;
- this.label = label;
- this.configState = configState;
- this.buildStep = buildStep;
- this.blazeFlags = blazeFlags;
- switch (configState.getLaunchMethod()) {
- case MOBILE_INSTALL:
- case NON_BLAZE:
- consoleProvider = new AitIdeTestConsoleProvider(runConfiguration, configState);
- break;
- case BLAZE_TEST:
- BlazeTestUiSession session =
- BlazeTestUiSession.create(ImmutableList.of(), testResultsHolder);
- this.consoleProvider = new AitBlazeTestConsoleProvider(project, runConfiguration, session);
- break;
- default:
- throw new IllegalStateException(
- "Unsupported launch method " + configState.getLaunchMethod());
- }
- applicationIdProvider = new BlazeAndroidTestApplicationIdProvider(buildStep);
- apkProvider = BlazeApkProviderService.getInstance().getApkProvider(project, buildStep);
- }
-
- @Override
- public BlazeAndroidDeviceSelector getDeviceSelector() {
- return new BlazeAndroidDeviceSelector.NormalDeviceSelector();
- }
-
- @Override
- public void augmentLaunchOptions(LaunchOptions.Builder options) {
- options.setDeploy(!configState.getLaunchMethod().equals(AndroidTestLaunchMethod.BLAZE_TEST));
- }
-
- @Override
- public ConsoleProvider getConsoleProvider() {
- return consoleProvider;
- }
-
- @Override
- public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
- return applicationIdProvider;
- }
-
- @Nullable
- @Override
- public ApkBuildStep getBuildStep() {
- return buildStep;
- }
-
- @Override
- public ProfilerState getProfileState() {
- return null;
- }
-
- @Override
- public BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException {
- return new BlazeAndroidLaunchTasksProvider(
- project, this, applicationIdProvider, launchOptionsBuilder);
- }
-
- @Override
- public ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException {
- if (configState.getLaunchMethod() != AndroidTestLaunchMethod.NON_BLAZE) {
- return ImmutableList.of();
- }
- return ImmutableList.of(
- DeployTasksCompat.createDeployTask(
- project, getApkInfoToInstall(device, launchOptions, apkProvider), launchOptions));
- }
-
- @Override
- @Nullable
- public BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions, @Nullable Integer userId, String contributorsAmStartOptions)
- throws ExecutionException {
- switch (configState.getLaunchMethod()) {
- case BLAZE_TEST:
- BlazeAndroidTestFilter testFilter =
- new BlazeAndroidTestFilter(
- configState.getTestingType(),
- configState.getClassName(),
- configState.getMethodName(),
- configState.getPackageName());
- return new BlazeAndroidTestLaunchTask(
- project,
- label,
- blazeFlags,
- testFilter,
- this,
- launchOptions.isDebug(),
- testResultsHolder);
- case NON_BLAZE:
- case MOBILE_INSTALL:
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
- return StockAndroidTestLaunchTask.getStockTestLaunchTask(
- configState, applicationIdProvider, launchOptions.isDebug(), deployInfo, project);
- }
- throw new AssertionError();
- }
-
- @Override
- @SuppressWarnings({"unchecked", "rawtypes"}) // Raw type from upstream.
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- switch (configState.getLaunchMethod()) {
- case BLAZE_TEST:
- return new ConnectBlazeTestDebuggerTask(this, androidDebugger, androidDebuggerState);
- case NON_BLAZE:
- case MOBILE_INSTALL:
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet, 30);
- }
- throw new AssertionError();
- }
-
- void onLaunchTaskComplete() {
- for (Runnable runnable : launchTaskCompleteListeners) {
- runnable.run();
- }
- }
-
- void addLaunchTaskCompleteListener(Runnable runnable) {
- launchTaskCompleteListeners.add(runnable);
- }
-
- @Override
- public Executor getExecutor() {
- return env.getExecutor();
- }
-
- @Nullable
- @Override
- public Integer getUserId(IDevice device) {
- return null;
- }
-
- @Override
- public String getAmStartOptions() {
- return "";
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/ConnectBlazeTestDebuggerTask.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/ConnectBlazeTestDebuggerTask.java
deleted file mode 100644
index 3ef2a6c9493..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/ConnectBlazeTestDebuggerTask.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.execution.common.debug.DebugSessionStarter;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.process.ProcessOutputTypes;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.ui.ConsoleView;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.xdebugger.impl.XDebugSessionImpl;
-import java.io.OutputStream;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** Connects the blaze debugger during execution. */
-class ConnectBlazeTestDebuggerTask implements ConnectDebuggerTask {
-
- private final BlazeAndroidTestRunContext runContext;
- private final AndroidDebugger myAndroidDebugger;
- private final S myAndroidDebuggerState;
-
- public ConnectBlazeTestDebuggerTask(
- BlazeAndroidTestRunContext runContext,
- AndroidDebugger androidDebugger,
- S androidDebuggerState) {
- this.runContext = runContext;
- myAndroidDebugger = androidDebugger;
- myAndroidDebuggerState = androidDebuggerState;
- }
-
- /**
- * Wires up listeners to automatically reconnect the debugger for each test method. When you
- * `blaze test` an android_test in debug mode, it kills the instrumentation process between each
- * test method, disconnecting the debugger. We listen for the start of a new method waiting for a
- * debugger, and reconnect. TODO: Support stopping Blaze from the UI. This is hard because we have
- * no way to distinguish process handler termination/debug session ending initiated by the user.
- *
- * @return Promise with debug session or error
- */
- @Override
- public @NotNull XDebugSessionImpl perform(
- @NotNull IDevice device,
- @NotNull String applicationId,
- @NotNull ExecutionEnvironment environment,
- @NotNull ProgressIndicator progressIndicator,
- ConsoleView console) {
- final ProcessHandler masterProcessHandler =
- new ProcessHandler() {
-
- @Override
- protected void destroyProcessImpl() {
- notifyProcessTerminated(0);
- }
-
- @Override
- protected void detachProcessImpl() {
- notifyProcessDetached();
- }
-
- @Override
- public boolean detachIsDefault() {
- return false;
- }
-
- @Override
- public @Nullable OutputStream getProcessInput() {
- return null;
- }
- };
- runContext.addLaunchTaskCompleteListener(
- () -> {
- masterProcessHandler.notifyTextAvailable(
- "Test run completed.\n", ProcessOutputTypes.STDOUT);
- masterProcessHandler.detachProcess();
- });
- return DebugSessionStarter.INSTANCE.attachReattachingDebuggerToStartedProcess(
- device,
- applicationId,
- masterProcessHandler,
- environment,
- myAndroidDebugger,
- myAndroidDebuggerState,
- progressIndicator,
- console,
- Long.MAX_VALUE);
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/StockAndroidTestLaunchTask.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/StockAndroidTestLaunchTask.java
deleted file mode 100644
index b5df308dcea..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/run/test/StockAndroidTestLaunchTask.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.test;
-
-import com.android.ddmlib.IDevice;
-import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
-import com.android.tools.idea.execution.common.RunConfigurationNotifier;
-import com.android.tools.idea.execution.common.processhandler.AndroidProcessHandler;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchContext;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.configuration.execution.ExecutionUtils;
-import com.android.tools.idea.testartifacts.instrumented.AndroidTestListener;
-import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.android.manifest.ManifestParser;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.ui.ConsoleView;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Computable;
-import com.intellij.openapi.util.text.StringUtil;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.jetbrains.annotations.NotNull;
-
-class StockAndroidTestLaunchTask implements BlazeLaunchTask {
- private static final String ID = "STOCK_ANDROID_TEST";
- private static final Logger LOG = Logger.getInstance(StockAndroidTestLaunchTask.class);
- private final BlazeAndroidTestRunConfigurationState configState;
- private final String instrumentationTestRunner;
- private final String testApplicationId;
- private final boolean waitForDebugger;
-
- StockAndroidTestLaunchTask(
- BlazeAndroidTestRunConfigurationState configState,
- String runner,
- String testPackage,
- boolean waitForDebugger) {
- this.configState = configState;
- this.instrumentationTestRunner = runner;
- this.waitForDebugger = waitForDebugger;
- this.testApplicationId = testPackage;
- }
-
- @Nullable
- public static BlazeLaunchTask getStockTestLaunchTask(
- BlazeAndroidTestRunConfigurationState configState,
- ApplicationIdProvider applicationIdProvider,
- boolean waitForDebugger,
- BlazeAndroidDeployInfo deployInfo,
- Project project)
- throws ExecutionException {
- String testPackage;
- try {
- testPackage = applicationIdProvider.getTestPackageName();
- } catch (ApkProvisionException e) {
- throw new ExecutionException("Unable to determine test package name. " + e.getMessage());
- }
- if (testPackage == null) {
- throw new ExecutionException("Unable to determine test package name.");
- }
- List availableRunners = getRunnersFromManifest(deployInfo);
- if (availableRunners.isEmpty()) {
- RunConfigurationNotifier.INSTANCE.notifyError(
- project,
- "",
- String.format(
- "No instrumentation test runner is defined in the manifest.\n"
- + "At least one instrumentation tag must be defined for the\n"
- + "\"%1$s\" package in the AndroidManifest.xml, e.g.:\n"
- + "\n"
- + "\n"
- + "\n"
- + " \n"
- + " \n"
- + "\n"
- + "",
- testPackage));
- // Note: Gradle users will never see the above message, so don't mention Gradle here.
- // Even if no runners are defined in build.gradle, Gradle will add a default to the manifest.
- throw new ExecutionException("No instrumentation test runner is defined in the manifest.");
- }
- String runner = configState.getInstrumentationRunnerClass();
- if (StringUtil.isEmpty(runner)) {
- // Default to the first available runner.
- runner = availableRunners.get(0);
- }
- if (!availableRunners.contains(runner)) {
- RunConfigurationNotifier.INSTANCE.notifyError(
- project,
- "",
- String.format(
- "Instrumentation test runner \"%2$s\"\n"
- + "is not defined for the \"%1$s\" package in the manifest.\n"
- + "Clear the 'Specific instrumentation runner' field in your configuration\n"
- + "to default to \"%3$s\",\n"
- + "or add the runner to your AndroidManifest.xml:\n"
- + "\n"
- + "\n"
- + "\n"
- + " \n"
- + " \n"
- + "\n"
- + "",
- testPackage, runner, availableRunners.get(0)));
- throw new ExecutionException(
- String.format(
- "Instrumentation test runner \"%2$s\" is not defined for the \"%1$s\" package in the"
- + " manifest.",
- testPackage, runner));
- }
-
- return new StockAndroidTestLaunchTask(configState, runner, testPackage, waitForDebugger);
- }
-
- private static ImmutableList getRunnersFromManifest(
- final BlazeAndroidDeployInfo deployInfo) {
- if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
- return ApplicationManager.getApplication()
- .runReadAction(
- (Computable>) () -> getRunnersFromManifest(deployInfo));
- }
- ManifestParser.ParsedManifest parsedManifest = deployInfo.getMergedManifest();
- if (parsedManifest != null) {
- return ImmutableList.copyOf(parsedManifest.instrumentationClassNames);
- }
- return ImmutableList.of();
- }
-
- @SuppressWarnings("FutureReturnValueIgnored")
- public void run(@NotNull BlazeLaunchContext launchContext) {
- ConsoleView console = launchContext.getConsoleView();
- IDevice device = launchContext.getDevice();
- ExecutionUtils.println(console, "Running tests\n");
- final RemoteAndroidTestRunner runner =
- new RemoteAndroidTestRunner(testApplicationId, instrumentationTestRunner, device);
- switch (configState.getTestingType()) {
- case BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_MODULE:
- break;
- case BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_PACKAGE:
- runner.setTestPackageName(configState.getPackageName());
- break;
- case BlazeAndroidTestRunConfigurationState.TEST_CLASS:
- runner.setClassName(configState.getClassName());
- break;
- case BlazeAndroidTestRunConfigurationState.TEST_METHOD:
- runner.setMethodName(configState.getClassName(), configState.getMethodName());
- break;
- default:
- throw new RuntimeException(
- String.format("Unrecognized testing type: %d", configState.getTestingType()));
- }
- runner.setDebug(waitForDebugger);
- runner.setRunOptions(configState.getExtraOptions());
- ExecutionUtils.printShellCommand(console, runner.getAmInstrumentCommand());
- // run in a separate thread as this will block until the tests complete
- ApplicationManager.getApplication()
- .executeOnPooledThread(
- () -> {
- try {
- // This issues "am instrument" command and blocks execution.
- runner.run(new AndroidTestListener(console));
- // Detach the device from the android process handler manually as soon as "am
- // instrument" command finishes. This is required because the android process
- // handler may overlook target process especially when the test
- // runs really fast (~10ms). Because the android process handler discovers new
- // processes by polling, this race condition happens easily. By detaching the device
- // manually, we can avoid the android process handler waiting for (already finished)
- // process to show up until it times out (10 secs).
- // Note: this is a copy of ag/9593981, but it is worth figuring out a better
- // strategy here if the behavior of AndroidTestListener is not guaranteed.
- ProcessHandler processHandler = launchContext.getProcessHandler();
- if (processHandler instanceof AndroidProcessHandler) {
- ((AndroidProcessHandler) processHandler).detachDevice(launchContext.getDevice());
- }
- } catch (Exception e) {
- ExecutionUtils.printlnError(
- console, "Error: Unexpected exception while running tests: " + e);
- }
- });
- }
-}
diff --git a/aswb/sdkcompat/as231/com/google/idea/blaze/android/sync/model/idea/BlazeAndroidModel.java b/aswb/sdkcompat/as231/com/google/idea/blaze/android/sync/model/idea/BlazeAndroidModel.java
deleted file mode 100644
index 3049cdd0eff..00000000000
--- a/aswb/sdkcompat/as231/com/google/idea/blaze/android/sync/model/idea/BlazeAndroidModel.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.sync.model.idea;
-
-import com.android.tools.idea.model.AndroidModel;
-import com.android.tools.idea.model.Namespacing;
-import com.android.tools.idea.projectsystem.NamedIdeaSourceProvider;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.intellij.openapi.project.Project;
-import java.io.File;
-
-/** Blaze model for an android project. #api42. */
-public class BlazeAndroidModel extends BlazeAndroidModelBase {
- private final NamedIdeaSourceProvider sourceProvider;
-
- public BlazeAndroidModel(
- Project project,
- File rootDirPath,
- NamedIdeaSourceProvider sourceProvider,
- ListenableFuture applicationId,
- int minSdkVersion,
- boolean desugarJava8Libs) {
- super(project, rootDirPath, applicationId, minSdkVersion, desugarJava8Libs);
- this.sourceProvider = sourceProvider;
- }
-
- public NamedIdeaSourceProvider getDefaultSourceProvider() {
- return sourceProvider;
- }
-
- @Override
- public Namespacing getNamespacing() {
- return Namespacing.DISABLED;
- }
-
- @Override
- protected String uninitializedApplicationId() {
- return AndroidModel.UNINITIALIZED_APPLICATION_ID;
- }
-}
diff --git a/aswb/sdkcompat/as231/org/jetbrains/android/facet/AndroidFacetPropertiesCompat.java b/aswb/sdkcompat/as231/org/jetbrains/android/facet/AndroidFacetPropertiesCompat.java
deleted file mode 100644
index fff25619e8a..00000000000
--- a/aswb/sdkcompat/as231/org/jetbrains/android/facet/AndroidFacetPropertiesCompat.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.facet;
-
-/** Compat class for AndroidFacetProperties. */
-public class AndroidFacetPropertiesCompat {
-
- private AndroidFacetPropertiesCompat() {}
-
- public static void enableSourcesAutogeneration(AndroidFacetProperties props, boolean enable) {}
-}
diff --git a/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidPlatformCompat.java b/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidPlatformCompat.java
deleted file mode 100644
index f745ba55516..00000000000
--- a/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidPlatformCompat.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.android.sdklib.BuildToolInfo;
-import com.android.tools.sdk.AndroidPlatform;
-import com.intellij.openapi.projectRoots.Sdk;
-
-/** Compat class for {@link com.android.tools.sdk.AndroidPlatform} */
-public class AndroidPlatformCompat {
- AndroidPlatform androidPlatform;
-
- public AndroidPlatformCompat(AndroidPlatform androidPlatform) {
- this.androidPlatform = androidPlatform;
- }
-
- public BuildToolInfo getLatestBuildTool(boolean allowBuildTool) {
- return androidPlatform.getSdkData().getLatestBuildTool(allowBuildTool);
- }
-
- public int getApiLevel() {
- return androidPlatform.getApiLevel();
- }
-
- public static int getApiLevel(Sdk sdk) {
- int androidSdkApiLevel = 1;
- AndroidSdkAdditionalData additionalData = (AndroidSdkAdditionalData) sdk.getSdkAdditionalData();
- if (additionalData != null) {
- AndroidPlatform androidPlatform = additionalData.getAndroidPlatform();
- if (androidPlatform != null) {
- androidSdkApiLevel = androidPlatform.getApiLevel();
- }
- }
- return androidSdkApiLevel;
- }
-}
diff --git a/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidPlatformsCompat.java b/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidPlatformsCompat.java
deleted file mode 100644
index d016d7ce236..00000000000
--- a/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidPlatformsCompat.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.projectRoots.Sdk;
-
-/** Compat shim class for {@link AndroidPlatforms} */
-public class AndroidPlatformsCompat {
- private AndroidPlatformsCompat() {}
-
- public static AndroidPlatformCompat getInstance(Sdk sdk) {
- return new AndroidPlatformCompat(AndroidPlatforms.getInstance(sdk));
- }
-
- public static AndroidPlatformCompat getInstance(Module module) {
- return new AndroidPlatformCompat(AndroidPlatforms.getInstance(module));
- }
-}
diff --git a/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidSdkAdditionalDataCompat.java b/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidSdkAdditionalDataCompat.java
deleted file mode 100644
index 6364b6fa8cf..00000000000
--- a/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidSdkAdditionalDataCompat.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.intellij.openapi.projectRoots.Sdk;
-
-/** Compat shim class for {@link AndroidSdkAdditionalData} */
-public class AndroidSdkAdditionalDataCompat {
- private AndroidSdkAdditionalDataCompat() {}
-
- public static AndroidSdkAdditionalData from(Sdk sdk) {
- return AndroidSdkAdditionalData.from(sdk);
- }
-}
diff --git a/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidSdkDataCompat.java b/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidSdkDataCompat.java
deleted file mode 100644
index 4aea6d6e832..00000000000
--- a/aswb/sdkcompat/as231/org/jetbrains/android/sdk/AndroidSdkDataCompat.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.android.sdk;
-
-import com.android.sdklib.IAndroidTarget;
-import com.android.tools.sdk.AndroidSdkData;
-import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import java.io.File;
-
-/** Compat class for {@link com.android.tools.sdk.AndroidSdkData} */
-public class AndroidSdkDataCompat {
- AndroidSdkData androidSdkData;
-
- private AndroidSdkDataCompat(File sdkLocation, boolean forceReparse) {
- androidSdkData = AndroidSdkData.getSdkData(sdkLocation, forceReparse);
- }
-
- public static AndroidSdkDataCompat getSdkData(String sdkHomepath) {
- return new AndroidSdkDataCompat(new File(sdkHomepath), false);
- }
-
- @CanIgnoreReturnValue
- public static AndroidSdkDataCompat getSdkData(File sdkLocation, boolean forceReparse) {
- return new AndroidSdkDataCompat(sdkLocation, forceReparse);
- }
-
- public IAndroidTarget[] getTargets() {
- return androidSdkData.getTargets();
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/android/tools/idea/model/AndroidManifestIndexCompat.java b/aswb/sdkcompat/asdev/com/android/tools/idea/model/AndroidManifestIndexCompat.java
deleted file mode 100644
index 82eb27bee0c..00000000000
--- a/aswb/sdkcompat/asdev/com/android/tools/idea/model/AndroidManifestIndexCompat.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.model;
-
-/** Compat class for {@link com.android.tools.idea.model.AndroidManifestIndex}. */
-public class AndroidManifestIndexCompat {
-
- private AndroidManifestIndexCompat() {}
-
- /** {@code indexEnabled} was removed in Studio 2021.2. #api211 */
- public static boolean indexEnabled() {
- return true;
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/android/tools/idea/progress/StudioLoggerProgressIndicatorCompat.java b/aswb/sdkcompat/asdev/com/android/tools/idea/progress/StudioLoggerProgressIndicatorCompat.java
deleted file mode 100644
index 7f9654b2ccf..00000000000
--- a/aswb/sdkcompat/asdev/com/android/tools/idea/progress/StudioLoggerProgressIndicatorCompat.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.progress;
-
-/** Compat layer for StudioLoggerProgressIndicator which moved packages in 2021.2. #api211 */
-public class StudioLoggerProgressIndicatorCompat extends StudioLoggerProgressIndicator {
- public StudioLoggerProgressIndicatorCompat(Class> c) {
- super(c);
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/android/tools/idea/run/AndroidSessionInfoCompat.java b/aswb/sdkcompat/asdev/com/android/tools/idea/run/AndroidSessionInfoCompat.java
deleted file mode 100644
index 783ad5d39e4..00000000000
--- a/aswb/sdkcompat/asdev/com/android/tools/idea/run/AndroidSessionInfoCompat.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.run;
-
-import com.android.ddmlib.Client;
-import com.android.tools.idea.execution.common.AndroidSessionInfo;
-import com.intellij.debugger.engine.RemoteDebugProcessHandler;
-import com.intellij.execution.ExecutionTarget;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.ui.RunContentDescriptor;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** Compat class for AndroidSessionInfo */
-public class AndroidSessionInfoCompat {
-
- private AndroidSessionInfoCompat() {}
-
- public static AndroidSessionInfo create(
- @NotNull ProcessHandler processHandler,
- @NotNull RunContentDescriptor descriptor,
- @Nullable RunConfiguration runConfiguration,
- @NotNull String executorId,
- @NotNull String executorActionName,
- @NotNull ExecutionTarget executionTarget) {
- return AndroidSessionInfo.create(processHandler, runConfiguration, executorId, executionTarget);
- }
-
- @Nullable
- public static RunContentDescriptor getDescriptor(AndroidSessionInfo session) {
- return null;
- }
-
- public static void putAndroidDebugClient(RemoteDebugProcessHandler handler, Client client) {}
-}
diff --git a/aswb/sdkcompat/asdev/com/android/tools/idea/run/ValidationErrorCompat.java b/aswb/sdkcompat/asdev/com/android/tools/idea/run/ValidationErrorCompat.java
deleted file mode 100644
index fb233c7eeb8..00000000000
--- a/aswb/sdkcompat/asdev/com/android/tools/idea/run/ValidationErrorCompat.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.run;
-
-/** Compat class for {@link ValidationError} */
-public class ValidationErrorCompat {
- private ValidationErrorCompat() {}
-
- public static ValidationError fatal(String message, Runnable quickFick) {
- return ValidationError.fatal(message, (dataContext) -> quickFick.run());
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/android/tools/idea/run/editor/DeployTargetCompat.java b/aswb/sdkcompat/asdev/com/android/tools/idea/run/editor/DeployTargetCompat.java
deleted file mode 100644
index faa6faec6fe..00000000000
--- a/aswb/sdkcompat/asdev/com/android/tools/idea/run/editor/DeployTargetCompat.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.run.editor;
-
-import com.android.tools.idea.run.DeviceFutures;
-import com.intellij.openapi.project.Project;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** SDK Compat class for {@link DeployTarget#getDevices}. */
-public class DeployTargetCompat {
-
- private DeployTargetCompat() {}
-
- @Nullable
- public static DeviceFutures getDevices(
- DeployTarget target, AndroidFacet facet, @NotNull Project project) {
- return target.getDevices(project);
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/android/tools/idea/run/tasks/DeployTasksCompat.java b/aswb/sdkcompat/asdev/com/android/tools/idea/run/tasks/DeployTasksCompat.java
deleted file mode 100644
index 500a6786340..00000000000
--- a/aswb/sdkcompat/asdev/com/android/tools/idea/run/tasks/DeployTasksCompat.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.idea.run.tasks;
-
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTaskWrapper;
-import com.google.idea.common.experiments.BoolExperiment;
-import com.intellij.openapi.project.Project;
-import java.util.Collection;
-
-/** Compat class for {@link DeployTask} */
-public class DeployTasksCompat {
- private static final BoolExperiment updateCodeViaJvmti =
- new BoolExperiment("android.apply.changes", false);
-
- private DeployTasksCompat() {}
-
- public static BlazeLaunchTask createDeployTask(
- Project project, Collection packages, LaunchOptions launchOptions) {
- // We don't have a device information, fallback to the most conservative
- // install option.
- return new BlazeLaunchTaskWrapper(
- new DeployTask(
- project,
- packages,
- launchOptions.getPmInstallOptions(/* device= */ null),
- launchOptions.getInstallOnAllUsers(),
- launchOptions.getAlwaysInstallWithPm()));
- }
-}
-
diff --git a/aswb/sdkcompat/asdev/com/android/tools/rendering/HtmlLinkManagerCompat.java b/aswb/sdkcompat/asdev/com/android/tools/rendering/HtmlLinkManagerCompat.java
deleted file mode 100644
index 594132f69af..00000000000
--- a/aswb/sdkcompat/asdev/com/android/tools/rendering/HtmlLinkManagerCompat.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2023 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tools.rendering;
-
-import com.android.tools.idea.rendering.HtmlLinkManager;
-import java.io.File;
-import org.jetbrains.annotations.NotNull;
-
-/** Compat class for {@link HtmlLinkManager} */
-public final class HtmlLinkManagerCompat {
- public static String createFilePositionUrl(@NotNull File file, int line, int column) {
- return HtmlLinkManager.createFilePositionUrl(file, line, column);
- }
-
- private HtmlLinkManagerCompat() {}
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/cppimpl/debug/BlazeAutoAndroidDebugger.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/cppimpl/debug/BlazeAutoAndroidDebugger.java
deleted file mode 100644
index 167fd4433a9..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/cppimpl/debug/BlazeAutoAndroidDebugger.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.cppimpl.debug;
-
-import com.android.ddmlib.Client;
-import com.android.tools.ndk.run.editor.AutoAndroidDebuggerState;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.project.Project;
-import com.intellij.xdebugger.XDebugSession;
-
-/** Shim for #api212 compat. */
-public class BlazeAutoAndroidDebugger extends BlazeAutoAndroidDebuggerBase {
- @Override
- public XDebugSession attachToClient(
- Project project, Client client, AutoAndroidDebuggerState state) throws ExecutionException {
- if (isNativeProject(project)) {
- log.info("Project has native development enabled. Attaching native debugger.");
- return nativeDebugger.attachToClient(project, client, state);
- } else {
- return super.attachToClient(project, client, state);
- }
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebugger.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebugger.java
deleted file mode 100644
index e92afddc27c..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebugger.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.cppimpl.debug;
-
-/**
- * API compat of {@link BlazeNativeAndroidDebuggerBase} with the following additions:
- *
- *
- * - Creates a run-config setting using {@link BlazeAndroidNativeAttachConfiguration} instead of
- * {@link AndroidNativeAttachConfiguration} to override counterproductive validations.
- *
- *
- * #api4.0
- */
-public class BlazeNativeAndroidDebugger extends BlazeNativeAndroidDebuggerBase {}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebuggerBase.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebuggerBase.java
deleted file mode 100644
index 911d90b7711..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/cppimpl/debug/BlazeNativeAndroidDebuggerBase.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.cppimpl.debug;
-
-import com.android.tools.ndk.run.editor.NativeAndroidDebugger;
-import com.google.idea.blaze.base.model.BlazeProjectData;
-import com.google.idea.blaze.base.model.primitives.LanguageClass;
-import com.google.idea.blaze.base.settings.Blaze;
-import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
-import com.intellij.openapi.project.Project;
-
-/**
- * Extension of {@link NativeAndroidDebugger} with the following key differences compared to {@link
- * NativeAndroidDebugger}.
- *
- *
- * - Overrides {@link #supportsProject} so native debugger is only enabled for native support is
- * enabled.
- *
- */
-public class BlazeNativeAndroidDebuggerBase extends NativeAndroidDebugger {
- /**
- * This ID needs to be lexicographically larger than "Java" so it come after the "Java" debugger
- * when sorted lexicographically in the "Attach Debugger to Android Process" dialog. See {@link
- * org.jetbrains.android.actions.AndroidProcessChooserDialog#populateDebuggerTypeCombo}.
- */
- public static final String ID = "Native" + Blaze.defaultBuildSystemName();
-
- @Override
- public String getId() {
- return ID;
- }
-
- @Override
- public String getDisplayName() {
- return "Native Only";
- }
-
- @Override
- public boolean supportsProject(Project project) {
- BlazeProjectData blazeProjectData =
- BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
- return blazeProjectData != null
- && blazeProjectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.C);
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/npw/project/BlazeAndroidModuleTemplate.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/npw/project/BlazeAndroidModuleTemplate.java
deleted file mode 100644
index 8d3b76b90e3..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/npw/project/BlazeAndroidModuleTemplate.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright 2017 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.npw.project;
-
-import com.android.tools.idea.projectsystem.AndroidModulePaths;
-import com.android.tools.idea.projectsystem.IdeaSourceProvider;
-import com.android.tools.idea.projectsystem.NamedModuleTemplate;
-import com.android.tools.idea.projectsystem.SourceProviderManager;
-import com.google.common.collect.Streams;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.vfs.VfsUtilCore;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.JavaDirectoryService;
-import com.intellij.psi.PsiDirectory;
-import com.intellij.psi.PsiManager;
-import com.intellij.psi.PsiPackage;
-import java.io.File;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/**
- * Project paths for a Blaze Android project.
- *
- * We mostly just take whatever directory the user specified and put the new component there.
- * Unlike Gradle, Blaze has no strict requirements regarding the structure of an Android project,
- * but there are some common conventions:
- *
- *
- * google3/
- * |-java/com/google/foo/bar/... (module root)
- * | |-BUILD
- * | |-AndroidManifest.xml (manifest directory)
- * | |-Baz.java (source directory of com.google.foo.bar.Baz)
- * | |-Baz.aidl (aidl directory, option 1)
- * | |-aidl/
- * | | `-com/google/foo/bar/Baz.aidl (aidl directory, option 2)
- * | `-res/... (res directory, one of the few things required by the build system)
- * `-javatest/com/google/foo/bar/...
- * |-BUILD
- * `-BazTest.java (test directory of com.google.foo.bar.BazTest)
- *
- *
- * However, this is also possible (package name unrelated to directory structure):
- *
- *
- * google3/experimental/users/foo/my/own/project/
- * |-Baz.java (com.google.foo.bar.Baz)
- * `-BazTest.java (com.google.foo.bar.BazTest)
- *
- *
- * So is this (versioned paths that aren't reflected by the package name):
- *
- *
- * google3/third_party/com/google/foo/bar/
- * |-v1/Baz.java (com.google.foo.bar.Baz)
- * `-v2/Baz.java (com.google.foo.bar.Baz)
- *
- */
-public class BlazeAndroidModuleTemplate implements AndroidModulePaths {
- @Nullable private File moduleRoot;
- @Nullable private File srcDirectory;
- private List resDirectories = Collections.emptyList();
-
- @Nullable
- @Override
- public File getModuleRoot() {
- return moduleRoot;
- }
-
- @Nullable
- @Override
- public File getSrcDirectory(@Nullable String packageName) {
- return srcDirectory;
- }
-
- @Nullable
- @Override
- public File getTestDirectory(@Nullable String packageName) {
- return srcDirectory;
- }
-
- @Nullable
- @Override
- public File getUnitTestDirectory(@Nullable String packageName) {
- return srcDirectory;
- }
-
- @Override
- public List getResDirectories() {
- return resDirectories;
- }
-
- @Nullable
- @Override
- public File getAidlDirectory(@Nullable String packageName) {
- return srcDirectory;
- }
-
- @Nullable
- @Override
- public File getManifestDirectory() {
- return srcDirectory;
- }
- /**
- * The new component wizard uses {@link NamedModuleTemplate#getName()} for the default package
- * name of the new component. If we can figure it out from the target directory here, then we can
- * pass it to the new component wizard.
- */
- private static String getPackageName(Project project, VirtualFile targetDirectory) {
- PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(targetDirectory);
- if (psiDirectory == null) {
- return null;
- }
- PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
- if (psiPackage == null) {
- return null;
- }
- return psiPackage.getQualifiedName();
- }
-
- public static List getTemplates(
- Module module, @Nullable VirtualFile targetDirectory) {
- AndroidFacet androidFacet = AndroidFacet.getInstance(module);
- if (androidFacet == null) {
- return Collections.emptyList();
- }
- return getTemplates(androidFacet, targetDirectory);
- }
-
- public static List getTemplates(
- AndroidFacet androidFacet, @Nullable VirtualFile targetDirectory) {
- Module module = androidFacet.getModule();
- BlazeAndroidModuleTemplate paths = new BlazeAndroidModuleTemplate();
- VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
- if (roots.length > 0) {
- paths.moduleRoot = VfsUtilCore.virtualToIoFile(roots[0]);
- }
- IdeaSourceProvider sourceProvider =
- SourceProviderManager.getInstance(androidFacet).getSources();
- // If this happens to be a resource package,
- // the module name (resource package) would be more descriptive than the facet name (Android).
- // Otherwise, .workspace is still better than (Android).
- String name = androidFacet.getModule().getName();
- if (targetDirectory != null) {
- String packageName = getPackageName(module.getProject(), targetDirectory);
- if (packageName != null) {
- name = packageName;
- }
- paths.srcDirectory = VfsUtilCore.virtualToIoFile(targetDirectory);
- } else {
- // People usually put the manifest file with their sources.
- //noinspection OptionalGetWithoutIsPresent
- paths.srcDirectory =
- Streams.stream(sourceProvider.getManifestDirectoryUrls())
- .map(it -> new File(VfsUtilCore.urlToPath(it)))
- .findFirst()
- .get();
- }
- // We have a res dir if this happens to be a resource module.
- paths.resDirectories =
- Streams.stream(sourceProvider.getResDirectoryUrls())
- .map(it -> new File(VfsUtilCore.urlToPath(it)))
- .collect(Collectors.toList());
- return Collections.singletonList(new NamedModuleTemplate(name, paths));
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/projectsystem/BlazeProjectSystem.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/projectsystem/BlazeProjectSystem.java
deleted file mode 100755
index b5b20a1b2a7..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/projectsystem/BlazeProjectSystem.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright 2017 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.projectsystem;
-
-import static com.android.tools.idea.projectsystem.SourceProvidersKt.emptySourceProvider;
-import static org.jetbrains.android.facet.SourceProviderUtil.createSourceProvidersForLegacyModule;
-
-import com.android.tools.apk.analyzer.AaptInvoker;
-import com.android.tools.idea.log.LogWrapper;
-import com.android.tools.idea.model.AndroidModel;
-import com.android.tools.idea.model.ClassJarProvider;
-import com.android.tools.idea.projectsystem.AndroidModuleSystem;
-import com.android.tools.idea.projectsystem.AndroidProjectSystem;
-import com.android.tools.idea.projectsystem.NamedIdeaSourceProvider;
-import com.android.tools.idea.projectsystem.ProjectSystemBuildManager;
-import com.android.tools.idea.projectsystem.ProjectSystemSyncManager;
-import com.android.tools.idea.projectsystem.ScopeType;
-import com.android.tools.idea.projectsystem.SourceProviderManager;
-import com.android.tools.idea.projectsystem.SourceProviders;
-import com.android.tools.idea.projectsystem.SourceProvidersFactory;
-import com.android.tools.idea.projectsystem.SourceProvidersImpl;
-import com.android.tools.idea.res.AndroidInnerClassFinder;
-import com.android.tools.idea.res.AndroidResourceClassPsiElementFinder;
-import com.android.tools.idea.sdk.AndroidSdks;
-import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.android.resources.BlazeLightResourceClassService;
-import com.google.idea.blaze.android.sync.model.idea.BlazeAndroidModel;
-import com.google.idea.blaze.android.sync.model.idea.BlazeClassJarProvider;
-import com.google.idea.blaze.base.build.BlazeBuildService;
-import com.google.idea.blaze.base.qsync.QuerySync;
-import com.intellij.facet.ProjectFacetManager;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiElementFinder;
-import com.intellij.psi.search.GlobalSearchScope;
-import java.io.File;
-import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Base class to implement common methods in {@link AndroidProjectSystem} for blaze with different
- * sdk
- */
-public class BlazeProjectSystem implements AndroidProjectSystem {
- protected final Project project;
- protected final ProjectSystemSyncManager syncManager;
- protected final List myFinders;
- private final BlazeProjectSystemBuildManager buildManager;
-
- public BlazeProjectSystem(Project project) {
- this.project = project;
- syncManager = new BlazeProjectSystemSyncManager(project);
- buildManager = new BlazeProjectSystemBuildManager(project);
-
- myFinders =
- Arrays.asList(
- AndroidInnerClassFinder.INSTANCE,
- new AndroidResourceClassPsiElementFinder(getLightResourceClassService()));
- }
-
- @Override
- public boolean allowsFileCreation() {
- return true;
- }
-
- @Nullable
- @Override
- public VirtualFile getDefaultApkFile() {
- return null;
- }
-
- @Override
- public Path getPathToAapt() {
- return AaptInvoker.getPathToAapt(
- AndroidSdks.getInstance().tryToChooseSdkHandler(),
- new LogWrapper(BlazeProjectSystem.class));
- }
-
- // @Override #api42
- public void buildProject() {
- BlazeBuildService.getInstance(project).buildProject();
- }
-
- // @Override #api42
- public ProjectSystemBuildManager getBuildManager() {
- return buildManager;
- }
-
- @Override
- public AndroidModuleSystem getModuleSystem(Module module) {
- return BlazeModuleSystem.getInstance(module);
- }
-
- @Override
- public ProjectSystemSyncManager getSyncManager() {
- return syncManager;
- }
-
- @Override
- public Collection getPsiElementFinders() {
- return myFinders;
- }
-
- @Override
- public BlazeLightResourceClassService getLightResourceClassService() {
- return BlazeLightResourceClassService.getInstance(project);
- }
-
- @Override
- public SourceProvidersFactory getSourceProvidersFactory() {
- return new SourceProvidersFactory() {
- @Override
- public SourceProviders createSourceProvidersFor(AndroidFacet facet) {
- BlazeAndroidModel model = ((BlazeAndroidModel) AndroidModel.get(facet));
- if (model != null) {
- return createForModel(model);
- } else {
- return createSourceProvidersForLegacyModule(facet);
- }
- }
-
- private SourceProviders createForModel(BlazeAndroidModel model) {
- NamedIdeaSourceProvider mainSourceProvider = model.getDefaultSourceProvider();
- if (QuerySync.isEnabled()) {
- return new SourceProvidersImpl(
- mainSourceProvider,
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(),
- ImmutableList.of(),
- ImmutableList.of(),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- emptySourceProvider(ScopeType.MAIN),
- emptySourceProvider(ScopeType.UNIT_TEST),
- emptySourceProvider(ScopeType.ANDROID_TEST),
- emptySourceProvider(ScopeType.TEST_FIXTURES));
- } else {
- return new SourceProvidersImpl(
- mainSourceProvider,
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- ImmutableList.of(mainSourceProvider),
- emptySourceProvider(ScopeType.MAIN),
- emptySourceProvider(ScopeType.UNIT_TEST),
- emptySourceProvider(ScopeType.ANDROID_TEST),
- emptySourceProvider(ScopeType.TEST_FIXTURES));
- }
- }
- };
- }
-
- // @Override #api212
- public ClassJarProvider getClassJarProvider() {
- return new BlazeClassJarProvider(project);
- }
-
- @Override
- public Collection getAndroidFacetsWithPackageName(
- Project project, String packageName) {
- return getAndroidFacetsWithPackageName(
- project, packageName, GlobalSearchScope.projectScope(project));
- }
-
- private Collection getAndroidFacetsWithPackageName(
- Project project, String packageName, GlobalSearchScope scope) {
- List facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
- return facets.stream()
- .filter(facet -> hasPackageName(facet, packageName))
- .filter(
- facet -> {
- VirtualFile file = SourceProviderManager.getInstance(facet).getMainManifestFile();
- if (file == null) {
- return false;
- } else {
- return scope.contains(file);
- }
- })
- .collect(Collectors.toList());
- }
-
- @Override
- public Collection getSubmodules() {
- return ImmutableList.of();
- }
-
- @Override
- public Collection getBootClasspath(@NotNull Module module) {
- // TODO: b/266586669
- return ImmutableList.of();
- }
-
- private static boolean hasPackageName(AndroidFacet facet, String packageName) {
- String nameFromFacet = PackageNameUtils.getPackageName(facet.getModule());
- if (nameFromFacet == null) {
- return false;
- }
- return nameFromFacet.equals(packageName);
- }
-
- @NotNull
- // @Override #api223
- public List desugarLibraryConfigFiles(@NotNull Project project) {
- return ImmutableList.of();
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/projectsystem/PackageNameUtils.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/projectsystem/PackageNameUtils.java
deleted file mode 100644
index 83a7fcd9b20..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/projectsystem/PackageNameUtils.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.projectsystem;
-
-import com.android.manifmerger.ManifestSystemProperty;
-import com.android.tools.idea.model.AndroidManifestIndex;
-import com.android.tools.idea.model.AndroidManifestIndexCompat;
-import com.android.tools.idea.model.AndroidManifestRawText;
-import com.android.tools.idea.model.MergedManifestModificationTracker;
-import com.android.tools.idea.projectsystem.ManifestOverrides;
-import com.android.tools.idea.projectsystem.SourceProviderManager;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.idea.common.experiments.BoolExperiment;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.project.DumbService;
-import com.intellij.openapi.project.IndexNotReadyException;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.util.CachedValueProvider;
-import com.intellij.psi.util.CachedValuesManager;
-import org.jetbrains.android.dom.manifest.AndroidManifestUtils;
-import org.jetbrains.android.dom.manifest.AndroidManifestXmlFile;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.Nullable;
-
-/** Utilities to obtain the package name for a given module. */
-public class PackageNameUtils {
- /**
- * Determines whether we use the {@link AndroidManifestIndex} to obtain the raw text package name
- * from a module's primary manifest. Note that we still won't use the index if {@link
- * AndroidManifestIndex#indexEnabled()} returns false.
- *
- * @see PackageNameUtils#getPackageName(Module)
- * @see PackageNameUtils#doGetPackageName(AndroidFacet, boolean)
- */
- private static final BoolExperiment USE_ANDROID_MANIFEST_INDEX =
- new BoolExperiment("use.android.manifest.index", true);
-
- @Nullable
- public static String getPackageName(Module module) {
- AndroidFacet facet = AndroidFacet.getInstance(module);
- assert facet != null;
- return CachedValuesManager.getManager(module.getProject())
- .getCachedValue(
- facet,
- () -> {
- boolean useIndex =
- AndroidManifestIndexCompat.indexEnabled()
- && USE_ANDROID_MANIFEST_INDEX.getValue();
- String packageName = doGetPackageName(facet, useIndex);
- return CachedValueProvider.Result.create(
- StringUtil.nullize(packageName, true),
- MergedManifestModificationTracker.getInstance(module));
- });
- }
-
- /**
- * Returns the package name from an Android module's merged manifest without actually computing
- * the whole merged manifest. This is either
- *
- *
- * - The {@link ManifestSystemProperty#PACKAGE} manifest override if one is specified by the
- * corresponding BUILD target, or
- *
- The result of applying placeholder substitution to the raw package name from the module's
- * primary manifest
- *
- *
- * In the second case, we try to obtain the raw package name using the {@link
- * AndroidManifestIndex} if {@code useIndex} is true. If {@code useIndex} is false or querying the
- * index fails for some reason (e.g. this method is called in a read action but not a *smart* read
- * action), then we resort to parsing the PSI of the module's primary manifest to get the raw
- * package name.
- *
- * @see AndroidModuleSystem#getManifestOverrides()
- * @see AndroidModuleSystem#getPackageName()
- */
- @Nullable
- @VisibleForTesting
- static String doGetPackageName(AndroidFacet facet, boolean useIndex) {
- ManifestOverrides manifestOverrides =
- BlazeModuleSystem.getInstance(facet.getModule()).getManifestOverrides();
- String packageOverride =
- ManifestValueProcessor.getPackageOverride(manifestOverrides.getDirectOverrides());
- if (packageOverride != null) {
- return packageOverride;
- }
- String rawPackageName = null;
- if (useIndex) {
- rawPackageName = getRawPackageNameFromIndex(facet);
- }
- if (rawPackageName == null) {
- rawPackageName = getRawPackageNameFromPsi(facet);
- }
- return rawPackageName == null ? null : manifestOverrides.resolvePlaceholders(rawPackageName);
- }
-
- @Nullable
- private static String getRawPackageNameFromIndex(AndroidFacet facet) {
- VirtualFile primaryManifest = SourceProviderManager.getInstance(facet).getMainManifestFile();
- if (primaryManifest == null) {
- return null;
- }
- Project project = facet.getModule().getProject();
- try {
- AndroidManifestRawText manifestRawText =
- DumbService.getInstance(project)
- .runReadActionInSmartMode(
- () -> AndroidManifestIndex.getDataForManifestFile(project, primaryManifest));
- return manifestRawText == null ? null : manifestRawText.getPackageName();
- } catch (IndexNotReadyException e) {
- // TODO(142681129): runReadActionInSmartMode doesn't work if we already have read access.
- // We need to refactor the callers of AndroidManifestUtils#getPackage to require a *smart*
- // read action, at which point we can remove this try-catch.
- return null;
- }
- }
-
- @Nullable
- private static String getRawPackageNameFromPsi(AndroidFacet facet) {
- AndroidManifestXmlFile primaryManifest = AndroidManifestUtils.getPrimaryManifestXml(facet);
- return primaryManifest == null ? null : primaryManifest.getPackageName();
- }
-
- private PackageNameUtils() {}
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/resources/BlazeRClass.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/resources/BlazeRClass.java
deleted file mode 100644
index 5a8cbf8e450..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/resources/BlazeRClass.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2018 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.resources;
-
-import static org.jetbrains.android.AndroidResolveScopeEnlarger.LIGHT_CLASS_KEY;
-import static org.jetbrains.android.AndroidResolveScopeEnlarger.MODULE_POINTER_KEY;
-
-import com.android.ide.common.rendering.api.ResourceNamespace;
-import com.android.tools.idea.res.LocalResourceRepository;
-import com.android.tools.idea.res.ResourceRepositoryRClass;
-import com.android.tools.idea.res.StudioResourceRepositoryManager;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.module.ModulePointerManager;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiManager;
-import org.jetbrains.android.augment.AndroidLightField;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Blaze implementation of an R class based on resource repositories. */
-public class BlazeRClass extends ResourceRepositoryRClass {
-
- private final AndroidFacet androidFacet;
-
- public BlazeRClass(PsiManager psiManager, AndroidFacet androidFacet, String packageName) {
- super(
- psiManager,
- new ResourcesSource() {
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public Transitivity getTransitivity() {
- return Transitivity.TRANSITIVE;
- }
-
- @Override
- public StudioResourceRepositoryManager getResourceRepositoryManager() {
- return StudioResourceRepositoryManager.getInstance(androidFacet);
- }
-
- @Override
- public LocalResourceRepository getResourceRepository() {
- return StudioResourceRepositoryManager.getAppResources(androidFacet);
- }
-
- @Override
- public ResourceNamespace getResourceNamespace() {
- return ResourceNamespace.RES_AUTO;
- }
-
- @Override
- public AndroidLightField.FieldModifier getFieldModifier() {
- return AndroidLightField.FieldModifier.NON_FINAL;
- }
- });
- this.androidFacet = androidFacet;
- setModuleInfo(getModule(), false);
- VirtualFile virtualFile = myFile.getViewProvider().getVirtualFile();
- virtualFile.putUserData(
- MODULE_POINTER_KEY, ModulePointerManager.getInstance(getProject()).create(getModule()));
- virtualFile.putUserData(LIGHT_CLASS_KEY, ResourceRepositoryRClass.class);
- }
-
- public Module getModule() {
- return androidFacet.getModule();
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/BlazeAndroidDeploymentService.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/BlazeAndroidDeploymentService.java
deleted file mode 100644
index 6cc3a63459e..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/BlazeAndroidDeploymentService.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2020 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run;
-
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.tasks.DeployTask;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.intellij.openapi.project.Project;
-import java.util.Collection;
-
-/** A service that provides {@link DeployTask}. */
-public interface BlazeAndroidDeploymentService {
- static BlazeAndroidDeploymentService getInstance(Project project) {
- return project.getService(BlazeAndroidDeploymentService.class);
- }
-
- /** Returns a {@link DeployTask} to deploy the given files and launch options. */
- BlazeLaunchTask getDeployTask(Collection packages, LaunchOptions launchOptions);
-
- /** A default implementation that uses {@link DeployTasksCompat#createDeployTask}. */
- class DefaultDeploymentService implements BlazeAndroidDeploymentService {
- private final Project project;
-
- public DefaultDeploymentService(Project project) {
- this.project = project;
- }
-
- @Override
- public BlazeLaunchTask getDeployTask(
- Collection packages, LaunchOptions launchOptions) {
- return DeployTasksCompat.createDeployTask(project, packages, launchOptions);
- }
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/BlazeCommandAndroidDebuggerInfoProvider.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/BlazeCommandAndroidDebuggerInfoProvider.java
deleted file mode 100644
index 03dd9f80da7..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/BlazeCommandAndroidDebuggerInfoProvider.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.execution.common.debug.impl.java.AndroidJavaDebugger;
-import com.android.tools.idea.run.editor.AndroidDebuggerInfoProvider;
-import com.google.idea.blaze.android.cppimpl.debug.BlazeNativeAndroidDebugger;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.test.BlazeAndroidTestRunConfigurationState;
-import com.google.idea.blaze.base.model.BlazeProjectData;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.openapi.project.Project;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import org.jetbrains.annotations.Nullable;
-
-/** Provider of blaze project compatible android debuggers. */
-public class BlazeCommandAndroidDebuggerInfoProvider implements AndroidDebuggerInfoProvider {
- @Override
- public boolean supportsProject(Project project) {
- BlazeProjectData blazeProjectData =
- BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
- return blazeProjectData != null;
- }
-
- @Override
- @SuppressWarnings("rawtypes") // List includes multiple AndroidDebuggerState types.
- public List getAndroidDebuggers(RunConfiguration configuration) {
- if (getCommonState(configuration) != null) {
- return Arrays.asList(new BlazeNativeAndroidDebugger(), new AndroidJavaDebugger());
- }
- return Collections.emptyList();
- }
-
- @Nullable
- @Override
- public AndroidDebugger getSelectedAndroidDebugger(
- RunConfiguration configuration) {
- // b/170159822 Always return java debugger because BlazeAutoAndroidDebugger doesn't work and
- // users likely want the java debugger not the native debugger.
- return new AndroidJavaDebugger();
- }
-
- @Nullable
- @Override
- public AndroidDebuggerState getSelectedAndroidDebuggerState(RunConfiguration configuration) {
- AndroidDebugger debugger = getSelectedAndroidDebugger(configuration);
- if (debugger == null) {
- return null;
- }
- return debugger.createState();
- }
-
- @Nullable
- private BlazeAndroidRunConfigurationCommonState getCommonState(RunConfiguration configuration) {
- if (!(configuration instanceof BlazeCommandRunConfiguration)) {
- return null;
- }
- BlazeCommandRunConfiguration blazeRunConfig = (BlazeCommandRunConfiguration) configuration;
- BlazeAndroidBinaryRunConfigurationState binaryState =
- blazeRunConfig.getHandlerStateIfType(BlazeAndroidBinaryRunConfigurationState.class);
- if (binaryState != null) {
- return binaryState.getCommonState();
- }
- BlazeAndroidTestRunConfigurationState testState =
- blazeRunConfig.getHandlerStateIfType(BlazeAndroidTestRunConfigurationState.class);
- if (testState != null) {
- return testState.getCommonState();
- }
- return null;
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryApplicationLaunchTaskProvider.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryApplicationLaunchTaskProvider.java
deleted file mode 100644
index 8a74f3d458f..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryApplicationLaunchTaskProvider.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.activity.StartActivityFlagsProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTaskWrapper;
-import com.android.tools.idea.run.tasks.AndroidDeepLinkLaunchTask;
-import com.android.tools.idea.run.tasks.DefaultActivityLaunchTask;
-import com.android.tools.idea.run.tasks.SpecificActivityLaunchTask;
-import com.google.idea.blaze.android.manifest.ManifestParser;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.diagnostic.Logger;
-
-/** Provides the launch task for android_binary */
-public class BlazeAndroidBinaryApplicationLaunchTaskProvider {
- private static final Logger LOG =
- Logger.getInstance(BlazeAndroidBinaryApplicationLaunchTaskProvider.class);
-
- public static BlazeLaunchTask getApplicationLaunchTask(
- ApplicationIdProvider applicationIdProvider,
- ManifestParser.ParsedManifest mergedManifestParsedManifest,
- BlazeAndroidBinaryRunConfigurationState configState,
- StartActivityFlagsProvider startActivityFlagsProvider)
- throws ExecutionException {
- try {
- String applicationId = applicationIdProvider.getPackageName();
-
- switch (configState.getMode()) {
- case BlazeAndroidBinaryRunConfigurationState.LAUNCH_DEFAULT_ACTIVITY:
- BlazeDefaultActivityLocator activityLocator =
- new BlazeDefaultActivityLocator(mergedManifestParsedManifest);
- return new BlazeLaunchTaskWrapper(
- new DefaultActivityLaunchTask(
- applicationId, activityLocator, startActivityFlagsProvider));
- case BlazeAndroidBinaryRunConfigurationState.LAUNCH_SPECIFIC_ACTIVITY:
- return new BlazeLaunchTaskWrapper(
- new SpecificActivityLaunchTask(
- applicationId, configState.getActivityClass(), startActivityFlagsProvider));
- case BlazeAndroidBinaryRunConfigurationState.LAUNCH_DEEP_LINK:
- return new BlazeLaunchTaskWrapper(
- new AndroidDeepLinkLaunchTask(configState.getDeepLink(), startActivityFlagsProvider));
- case BlazeAndroidBinaryRunConfigurationState.DO_NOTHING:
- default:
- return null;
- }
- } catch (ApkProvisionException e) {
- throw new ExecutionException("Unable to identify application id");
- }
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContext.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContext.java
deleted file mode 100644
index 6b2d10e2dac..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContext.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2019 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.activity.DefaultStartActivityFlagsProvider;
-import com.android.tools.idea.run.activity.StartActivityFlagsProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Compat for #api212 */
-public class BlazeAndroidBinaryNormalBuildRunContext
- extends BlazeAndroidBinaryNormalBuildRunContextBase {
- BlazeAndroidBinaryNormalBuildRunContext(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, runConfiguration, env, configState, buildStep, launchId);
- }
-
- @Override
- public BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions, @Nullable Integer userId, String contributorsAmStartOptions)
- throws ExecutionException {
- String extraFlags = UserIdHelper.getFlagsFromUserId(userId);
- if (!contributorsAmStartOptions.isEmpty()) {
- extraFlags += (extraFlags.isEmpty() ? "" : " ") + contributorsAmStartOptions;
- }
-
- final StartActivityFlagsProvider startActivityFlagsProvider =
- new DefaultStartActivityFlagsProvider(project, launchOptions.isDebug(), extraFlags);
-
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
-
- return BlazeAndroidBinaryApplicationLaunchTaskProvider.getApplicationLaunchTask(
- applicationIdProvider,
- deployInfo.getMergedManifest(),
- configState,
- startActivityFlagsProvider);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-
- @Override
- public Executor getExecutor() {
- return env.getExecutor();
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextBase.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextBase.java
deleted file mode 100644
index bc3517e8fe8..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextBase.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider.NATIVE_DEBUGGING_ENABLED;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.gradle.util.DynamicAppUtils;
-import com.android.tools.idea.run.ApkFileUnit;
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.ApkProvider;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.idea.blaze.android.run.deployinfo.BlazeApkProviderService;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-import org.jetbrains.annotations.NotNull;
-
-/** Run context for android_binary. */
-public abstract class BlazeAndroidBinaryNormalBuildRunContextBase
- implements BlazeAndroidRunContext {
- protected final Project project;
- protected final AndroidFacet facet;
- protected final RunConfiguration runConfiguration;
- protected final ExecutionEnvironment env;
- protected final BlazeAndroidBinaryRunConfigurationState configState;
- protected final ConsoleProvider consoleProvider;
- protected final ApkBuildStep buildStep;
- protected final ApkProvider apkProvider;
- protected final ApplicationIdProvider applicationIdProvider;
- private final String launchId;
-
- BlazeAndroidBinaryNormalBuildRunContextBase(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- this.project = project;
- this.facet = facet;
- this.runConfiguration = runConfiguration;
- this.env = env;
- this.configState = configState;
- this.consoleProvider = new BlazeAndroidBinaryConsoleProvider(project);
- this.buildStep = buildStep;
- this.apkProvider = BlazeApkProviderService.getInstance().getApkProvider(project, buildStep);
- this.applicationIdProvider = new BlazeAndroidBinaryApplicationIdProvider(buildStep);
- this.launchId = launchId;
- }
-
- @Override
- public BlazeAndroidDeviceSelector getDeviceSelector() {
- return new BlazeAndroidDeviceSelector.NormalDeviceSelector();
- }
-
- @Override
- public void augmentLaunchOptions(LaunchOptions.Builder options) {
- options.setDeploy(true).setOpenLogcatAutomatically(configState.showLogcatAutomatically());
- options.addExtraOptions(
- ImmutableMap.of(
- "android.profilers.state", // Not used after #api211
- configState.getProfilerState(),
- NATIVE_DEBUGGING_ENABLED,
- configState.getCommonState().isNativeDebuggingEnabled()));
- }
-
- @Override
- public ConsoleProvider getConsoleProvider() {
- return consoleProvider;
- }
-
- @Override
- public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
- return applicationIdProvider;
- }
-
- @Override
- public ApkBuildStep getBuildStep() {
- return buildStep;
- }
-
- @Nullable
- @Override
- public Integer getUserId(IDevice device) throws ExecutionException {
- return UserIdHelper.getUserIdFromConfigurationState(project, device, configState);
- }
-
- @Override
- public BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException {
- return new BlazeAndroidLaunchTasksProvider(
- project, this, applicationIdProvider, launchOptionsBuilder);
- }
-
- @Override
- public String getAmStartOptions() {
- return configState.getAmStartOptions();
- }
-
- @Override
- public ProfilerState getProfileState() {
- return configState.getProfilerState();
- }
-
- @Nullable
- @Override
- public ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException {
- BlazeLaunchTask deployTask =
- DeployTasksCompat.createDeployTask(
- project, getApkInfoToInstall(device, launchOptions, apkProvider), launchOptions);
- return ImmutableList.of(new DeploymentTimingReporterTask(launchId, deployTask));
- }
-
- /** Returns a list of APKs excluding any APKs for features that are disabled. */
- public static List getApkInfoToInstall(
- IDevice device, LaunchOptions launchOptions, ApkProvider apkProvider)
- throws ExecutionException {
- Collection apks;
- try {
- apks = apkProvider.getApks(device);
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
- List disabledFeatures = launchOptions.getDisabledDynamicFeatures();
- return apks.stream()
- .map(apk -> getApkInfoToInstall(apk, disabledFeatures))
- .collect(Collectors.toList());
- }
-
- @NotNull
- private static ApkInfo getApkInfoToInstall(ApkInfo apkInfo, List disabledFeatures) {
- if (apkInfo.getFiles().size() > 1) {
- List filteredApks =
- apkInfo.getFiles().stream()
- .filter(feature -> DynamicAppUtils.isFeatureEnabled(disabledFeatures, feature))
- .collect(Collectors.toList());
- return new ApkInfo(filteredApks, apkInfo.getApplicationId());
- } else {
- return apkInfo;
- }
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextCompat.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextCompat.java
deleted file mode 100644
index d54c472c84b..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryNormalBuildRunContextCompat.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Compat class for {@link BlazeAndroidBinaryNormalBuildRunContext}. */
-public class BlazeAndroidBinaryNormalBuildRunContextCompat
- extends BlazeAndroidBinaryNormalBuildRunContext {
-
- BlazeAndroidBinaryNormalBuildRunContextCompat(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, runConfiguration, env, configState, buildStep, launchId);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryProgramRunner.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryProgramRunner.java
deleted file mode 100644
index 97b3d36aec1..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/BlazeAndroidBinaryProgramRunner.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import static com.intellij.openapi.application.ModalityState.NON_MODAL;
-
-import com.android.tools.idea.profilers.ProfileRunExecutor;
-import com.android.tools.idea.run.configuration.execution.AndroidConfigurationExecutor;
-import com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.ExecutionResult;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunProfile;
-import com.intellij.execution.configurations.RunProfileState;
-import com.intellij.execution.configurations.RunnerSettings;
-import com.intellij.execution.executors.DefaultDebugExecutor;
-import com.intellij.execution.executors.DefaultRunExecutor;
-import com.intellij.execution.runners.AsyncProgramRunner;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.runners.RunContentBuilder;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.application.ActionsKt;
-import com.intellij.openapi.fileEditor.FileDocumentManager;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.progress.Task;
-import org.jetbrains.concurrency.AsyncPromise;
-import org.jetbrains.concurrency.Promise;
-
-/** Program runner for configurations from {@link BlazeAndroidBinaryRunConfigurationHandler}. */
-public class BlazeAndroidBinaryProgramRunner extends AsyncProgramRunner {
- @Override
- public boolean canRun(String executorId, RunProfile profile) {
- BlazeAndroidRunConfigurationHandler handler =
- BlazeAndroidRunConfigurationHandler.getHandlerFrom(profile);
- if (!(handler instanceof BlazeAndroidBinaryRunConfigurationHandler)) {
- return false;
- }
- return (DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)
- || DefaultRunExecutor.EXECUTOR_ID.equals(executorId)
- || ProfileRunExecutor.EXECUTOR_ID.equals(executorId));
- }
-
- @Override
- protected Promise execute(
- ExecutionEnvironment environment, RunProfileState state) {
- FileDocumentManager.getInstance().saveAllDocuments();
-
- AsyncPromise promise = new AsyncPromise<>();
-
- ProgressManager.getInstance()
- .run(
- new Task.Backgroundable(environment.getProject(), "Launching ${runProfile.name}") {
- @Override
- public void run(ProgressIndicator indicator) {
- try {
- RunContentDescriptor descriptor;
- if (state instanceof AndroidConfigurationExecutor) {
- AndroidConfigurationExecutor configurationExecutor =
- (AndroidConfigurationExecutor) state;
- Executor executor = environment.getExecutor();
- if (executor.getId().equals(DefaultDebugExecutor.EXECUTOR_ID)) {
- descriptor = configurationExecutor.debug(indicator);
- } else if (executor.getId().equals(DefaultRunExecutor.EXECUTOR_ID)
- || executor.getId().equals(ProfileRunExecutor.EXECUTOR_ID)) {
- descriptor = configurationExecutor.run(indicator);
- } else {
- throw new ExecutionException("Unsupported executor");
- }
- } else {
- descriptor = doExecute(state, environment);
- }
- promise.setResult(descriptor);
- } catch (ExecutionException e) {
- var unused = promise.setError(e);
- }
- }
-
- @Override
- public void onCancel() {
- super.onCancel();
- promise.setResult(null);
- }
- });
-
- return promise;
- }
-
- private RunContentDescriptor doExecute(
- final RunProfileState state, final ExecutionEnvironment env) throws ExecutionException {
- ExecutionResult result = state.execute(env.getExecutor(), this);
- return ActionsKt.invokeAndWaitIfNeeded(
- NON_MODAL,
- () -> new RunContentBuilder(result, env).showRunContent(env.getContentToReuse()));
- }
-
- @Override
- public String getRunnerId() {
- return "AndroidBinaryProgramRunner";
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/DeploymentTimingReporterTask.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/DeploymentTimingReporterTask.java
deleted file mode 100644
index 81696ad5b1e..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/DeploymentTimingReporterTask.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2021 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import com.android.tools.idea.run.blaze.BlazeLaunchContext;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.google.common.base.Stopwatch;
-import com.google.idea.blaze.android.run.LaunchMetrics;
-import com.intellij.execution.ExecutionException;
-
-/** A wrapper launch task that wraps the given deployment task and logs the deployment latency. */
-public class DeploymentTimingReporterTask implements BlazeLaunchTask {
- private final BlazeLaunchTask deployTask;
- private final String launchId;
-
- public DeploymentTimingReporterTask(String launchId, BlazeLaunchTask deployTask) {
- this.launchId = launchId;
- this.deployTask = deployTask;
- }
-
- @Override
- public void run(BlazeLaunchContext launchContext) throws ExecutionException {
- Stopwatch s = Stopwatch.createStarted();
- try {
- deployTask.run(launchContext);
- LaunchMetrics.logDeploymentTime(launchId, s.elapsed(), true);
- } catch (ExecutionException e) {
- LaunchMetrics.logDeploymentTime(launchId, s.elapsed(), false);
- throw e;
- }
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/UserIdHelper.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/UserIdHelper.java
deleted file mode 100644
index ab71d4747c2..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/UserIdHelper.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary;
-
-import com.android.ddmlib.AdbCommandRejectedException;
-import com.android.ddmlib.CollectingOutputReceiver;
-import com.android.ddmlib.IDevice;
-import com.android.ddmlib.ShellCommandUnresponsiveException;
-import com.android.ddmlib.TimeoutException;
-import com.android.tools.idea.execution.common.RunConfigurationNotifier;
-import com.intellij.execution.ExecutionException;
-import com.intellij.openapi.project.Project;
-import java.io.IOException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.annotation.Nullable;
-
-/** Helpers for user id */
-public final class UserIdHelper {
- private UserIdHelper() {}
-
- private static final Pattern USER_ID_REGEX =
- Pattern.compile("UserInfo\\{([0-9]+):Work profile:[0-9]+\\}");
-
- @Nullable
- public static Integer getUserIdFromConfigurationState(
- Project project, IDevice device, BlazeAndroidBinaryRunConfigurationState state)
- throws ExecutionException {
- if (state.useWorkProfileIfPresent()) {
- try {
- Integer userId = getWorkProfileId(device);
- if (userId == null) {
- RunConfigurationNotifier.INSTANCE.notifyWarning(
- project,
- "",
- "Could not locate work profile on selected device. Launching default user.");
- }
- return userId;
- } catch (TimeoutException
- | AdbCommandRejectedException
- | ShellCommandUnresponsiveException
- | IOException e) {
- throw new ExecutionException(e);
- }
- }
- return state.getUserId();
- }
-
- @Nullable
- public static Integer getWorkProfileId(IDevice device)
- throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
- IOException {
- CollectingOutputReceiver receiver = new CollectingOutputReceiver();
- device.executeShellCommand("pm list users", receiver);
- String result = receiver.getOutput();
- Matcher matcher = USER_ID_REGEX.matcher(result);
- if (matcher.find()) {
- return Integer.parseInt(matcher.group(1));
- }
- return null;
- }
-
- public static String getFlagsFromUserId(@Nullable Integer userId) {
- return userId != null ? ("--user " + userId.intValue()) : "";
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContext.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContext.java
deleted file mode 100644
index c49082cfdaa..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContext.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary.mobileinstall;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.activity.DefaultStartActivityFlagsProvider;
-import com.android.tools.idea.run.activity.StartActivityFlagsProvider;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryApplicationLaunchTaskProvider;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.binary.UserIdHelper;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Run Context for mobile install launches, #api4.0 compat. */
-public class BlazeAndroidBinaryMobileInstallRunContext
- extends BlazeAndroidBinaryMobileInstallRunContextBase {
- public BlazeAndroidBinaryMobileInstallRunContext(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, runConfiguration, env, configState, buildStep, launchId);
- }
-
- @SuppressWarnings("unchecked") // upstream API
- @Override
- public BlazeLaunchTask getApplicationLaunchTask(
- LaunchOptions launchOptions, @Nullable Integer userId, String contributorsAmStartOptions)
- throws ExecutionException {
-
- String extraFlags = UserIdHelper.getFlagsFromUserId(userId);
- if (!contributorsAmStartOptions.isEmpty()) {
- extraFlags += (extraFlags.isEmpty() ? "" : " ") + contributorsAmStartOptions;
- }
-
- final StartActivityFlagsProvider startActivityFlagsProvider =
- new DefaultStartActivityFlagsProvider(project, launchOptions.isDebug(), extraFlags);
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
-
- return BlazeAndroidBinaryApplicationLaunchTaskProvider.getApplicationLaunchTask(
- applicationIdProvider,
- deployInfo.getMergedManifest(),
- configState,
- startActivityFlagsProvider);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-
- @Override
- public Executor getExecutor() {
- return env.getExecutor();
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextBase.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextBase.java
deleted file mode 100644
index 7562174bd25..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextBase.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary.mobileinstall;
-
-import com.android.ddmlib.IDevice;
-import com.android.tools.idea.run.ApkFileUnit;
-import com.android.tools.idea.run.ApkInfo;
-import com.android.tools.idea.run.ApkProvisionException;
-import com.android.tools.idea.run.ApplicationIdProvider;
-import com.android.tools.idea.run.ConsoleProvider;
-import com.android.tools.idea.run.LaunchOptions;
-import com.android.tools.idea.run.blaze.BlazeLaunchTask;
-import com.android.tools.idea.run.blaze.BlazeLaunchTasksProvider;
-import com.android.tools.idea.run.editor.ProfilerState;
-import com.android.tools.idea.run.tasks.DeployTasksCompat;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryApplicationIdProvider;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryConsoleProvider;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.binary.DeploymentTimingReporterTask;
-import com.google.idea.blaze.android.run.binary.UserIdHelper;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidLaunchTasksProvider;
-import com.google.idea.blaze.android.run.runner.BlazeAndroidRunContext;
-import com.google.idea.blaze.base.sync.data.BlazeDataStorage;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.configurations.RunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import java.util.Collections;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Run context for android_binary. */
-abstract class BlazeAndroidBinaryMobileInstallRunContextBase implements BlazeAndroidRunContext {
- protected final Project project;
- protected final AndroidFacet facet;
- protected final RunConfiguration runConfiguration;
- protected final ExecutionEnvironment env;
- protected final BlazeAndroidBinaryRunConfigurationState configState;
- protected final ConsoleProvider consoleProvider;
- protected final ApplicationIdProvider applicationIdProvider;
- protected final ApkBuildStep buildStep;
- private final String launchId;
-
- public BlazeAndroidBinaryMobileInstallRunContextBase(
- Project project,
- AndroidFacet facet,
- RunConfiguration runConfiguration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- this.project = project;
- this.facet = facet;
- this.runConfiguration = runConfiguration;
- this.env = env;
- this.configState = configState;
- this.consoleProvider = new BlazeAndroidBinaryConsoleProvider(project);
- this.buildStep = buildStep;
- this.applicationIdProvider = new BlazeAndroidBinaryApplicationIdProvider(buildStep);
- this.launchId = launchId;
- }
-
- @Override
- public BlazeAndroidDeviceSelector getDeviceSelector() {
- return new BlazeAndroidDeviceSelector.NormalDeviceSelector();
- }
-
- @Override
- public void augmentLaunchOptions(LaunchOptions.Builder options) {
- options
- .setDeploy(buildStep.needsIdeDeploy())
- .setOpenLogcatAutomatically(configState.showLogcatAutomatically());
- // This is needed for compatibility with #api211
- options.addExtraOptions(
- ImmutableMap.of("android.profilers.state", configState.getProfilerState()));
- }
-
- @Override
- public ConsoleProvider getConsoleProvider() {
- return consoleProvider;
- }
-
- @Override
- public ApplicationIdProvider getApplicationIdProvider() throws ExecutionException {
- return applicationIdProvider;
- }
-
- @Override
- public ApkBuildStep getBuildStep() {
- return buildStep;
- }
-
- @Override
- public ProfilerState getProfileState() {
- return configState.getProfilerState();
- }
-
- @Override
- public ImmutableList getDeployTasks(IDevice device, LaunchOptions launchOptions)
- throws ExecutionException {
- if (!buildStep.needsIdeDeploy()) {
- return ImmutableList.of();
- }
-
- BlazeAndroidDeployInfo deployInfo;
- try {
- deployInfo = buildStep.getDeployInfo();
- } catch (ApkProvisionException e) {
- throw new ExecutionException(e);
- }
-
- String packageName = deployInfo.getMergedManifest().packageName;
- if (packageName == null) {
- throw new ExecutionException("Could not determine package name from deploy info");
- }
-
- ApkInfo info =
- new ApkInfo(
- deployInfo.getApksToDeploy().stream()
- .map(file -> new ApkFileUnit(BlazeDataStorage.WORKSPACE_MODULE_NAME, file))
- .collect(Collectors.toList()),
- packageName);
-
- BlazeLaunchTask deployTask =
- DeployTasksCompat.createDeployTask(project, Collections.singletonList(info), launchOptions);
- return ImmutableList.of(new DeploymentTimingReporterTask(launchId, deployTask));
- }
-
- @Nullable
- @Override
- public Integer getUserId(IDevice device) throws ExecutionException {
- return UserIdHelper.getUserIdFromConfigurationState(project, device, configState);
- }
-
- @Override
- public BlazeLaunchTasksProvider getLaunchTasksProvider(LaunchOptions.Builder launchOptionsBuilder)
- throws ExecutionException {
- return new BlazeAndroidLaunchTasksProvider(
- project, this, applicationIdProvider, launchOptionsBuilder);
- }
-
- @Override
- public String getAmStartOptions() {
- return configState.getAmStartOptions();
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextCompat.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextCompat.java
deleted file mode 100644
index 29411ebad5a..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/binary/mobileinstall/BlazeAndroidBinaryMobileInstallRunContextCompat.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2022 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.binary.mobileinstall;
-
-import static com.android.tools.idea.run.tasks.DefaultConnectDebuggerTaskKt.getBaseDebuggerTask;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.run.tasks.ConnectDebuggerTask;
-import com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState;
-import com.google.idea.blaze.android.run.runner.ApkBuildStep;
-import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-import org.jetbrains.android.facet.AndroidFacet;
-
-/** Compatct class for {@link BlazeAndroidBinaryMobileInstallRunContext}. */
-public class BlazeAndroidBinaryMobileInstallRunContextCompat
- extends BlazeAndroidBinaryMobileInstallRunContext {
-
- public BlazeAndroidBinaryMobileInstallRunContextCompat(
- Project project,
- AndroidFacet facet,
- BlazeCommandRunConfiguration configuration,
- ExecutionEnvironment env,
- BlazeAndroidBinaryRunConfigurationState configState,
- ApkBuildStep buildStep,
- String launchId) {
- super(project, facet, configuration, env, configState, buildStep, launchId);
- }
-
- @Nullable
- @Override
- @SuppressWarnings("unchecked")
- public ConnectDebuggerTask getDebuggerTask(
- AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState) {
- return getBaseDebuggerTask(androidDebugger, androidDebuggerState, env, facet);
- }
-}
diff --git a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/runner/BlazeAndroidDebuggerService.java b/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/runner/BlazeAndroidDebuggerService.java
deleted file mode 100644
index c8658223baa..00000000000
--- a/aswb/sdkcompat/asdev/com/google/idea/blaze/android/run/runner/BlazeAndroidDebuggerService.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2016 The Bazel Authors. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.idea.blaze.android.run.runner;
-
-import com.android.tools.idea.execution.common.debug.AndroidDebugger;
-import com.android.tools.idea.execution.common.debug.AndroidDebuggerState;
-import com.android.tools.idea.execution.common.debug.impl.java.AndroidJavaDebugger;
-import com.android.tools.ndk.run.editor.AutoAndroidDebuggerState;
-import com.google.common.collect.ImmutableList;
-import com.google.idea.blaze.android.cppimpl.debug.BlazeAutoAndroidDebugger;
-import com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo;
-import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
-import com.intellij.ide.plugins.PluginManagerCore;
-import com.intellij.openapi.project.Project;
-import javax.annotation.Nullable;
-
-/** Provides android debuggers and debugger states for blaze projects. */
-public interface BlazeAndroidDebuggerService {
-
- static BlazeAndroidDebuggerService getInstance(Project project) {
- return project.getService(BlazeAndroidDebuggerService.class);
- }
-
- /** Returns the standard debugger for non-native (Java) debugging. */
- AndroidDebugger