use of com.intellij.compiler.options.CompileStepBeforeRun in project android by JetBrains.
the class MakeBeforeRunTaskProvider method executeTask.
@Override
public boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, MakeBeforeRunTask task) {
if (!AndroidProjectInfo.getInstance(myProject).requiresAndroidModel() || !isDirectGradleInvocationEnabled(myProject)) {
CompileStepBeforeRun regularMake = new CompileStepBeforeRun(myProject);
return regularMake.executeTask(context, configuration, env, new CompileStepBeforeRun.MakeBeforeRunTask());
}
AtomicReference<String> errorMsgRef = new AtomicReference<>();
if (AndroidGradleBuildConfiguration.getInstance(myProject).SYNC_PROJECT_BEFORE_BUILD) {
// If the model needs a sync, we need to sync "synchronously" before running.
// See: https://code.google.com/p/android/issues/detail?id=70718
GradleSyncState syncState = GradleSyncState.getInstance(myProject);
if (syncState.isSyncNeeded() != ThreeState.NO) {
GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setRunInBackground(false);
GradleSyncInvoker.getInstance().requestProjectSync(myProject, request, new GradleSyncListener.Adapter() {
@Override
public void syncFailed(@NotNull Project project, @NotNull String errorMessage) {
errorMsgRef.set(errorMessage);
}
});
}
}
String errorMsg = errorMsgRef.get();
if (errorMsg != null) {
// Sync failed. There is no point on continuing, because most likely the model is either not there, or has stale information,
// including the path of the APK.
LOG.info("Unable to launch '" + TASK_NAME + "' task. Project sync failed with message: " + errorMsg);
return false;
}
if (myProject.isDisposed()) {
return false;
}
// Some configurations (e.g. native attach) don't require a build while running the configuration
if (configuration instanceof RunConfigurationBase && ((RunConfigurationBase) configuration).excludeCompileBeforeLaunchOption()) {
return true;
}
// Note: this before run task provider may be invoked from a context such as Java unit tests, in which case it doesn't have
// the android run config context
AndroidRunConfigContext runConfigContext = env.getCopyableUserData(AndroidRunConfigContext.KEY);
DeviceFutures deviceFutures = runConfigContext == null ? null : runConfigContext.getTargetDevices();
List<AndroidDevice> targetDevices = deviceFutures == null ? Collections.emptyList() : deviceFutures.getDevices();
List<String> cmdLineArgs = getCommonArguments(configuration, targetDevices);
BeforeRunBuilder builder = createBuilder(env, getModules(myProject, context, configuration), configuration, runConfigContext, task.getGoal());
try {
boolean success = builder.build(GradleTaskRunner.newRunner(myProject), cmdLineArgs);
LOG.info("Gradle invocation complete, success = " + success);
return success;
} catch (InvocationTargetException e) {
LOG.info("Unexpected error while launching gradle before run tasks", e);
return false;
} catch (InterruptedException e) {
LOG.info("Interrupted while launching gradle before run tasks");
Thread.currentThread().interrupt();
return false;
}
}
Aggregations