use of org.gradle.tooling.CancellationTokenSource in project android by JetBrains.
the class BuildStopper method attemptToStopBuild.
void attemptToStopBuild(@NotNull ExternalSystemTaskId id, @Nullable ProgressIndicator progressIndicator) {
if (progressIndicator != null) {
if (progressIndicator.isCanceled()) {
return;
}
if (progressIndicator.isRunning()) {
progressIndicator.setText("Stopping Gradle build...");
progressIndicator.cancel();
}
}
CancellationTokenSource token = remove(id);
if (token != null) {
token.cancel();
}
}
use of org.gradle.tooling.CancellationTokenSource in project android by JetBrains.
the class BuildStopper method createAndRegisterTokenSource.
@NotNull
CancellationTokenSource createAndRegisterTokenSource(@NotNull ExternalSystemTaskId id) {
CancellationTokenSource tokenSource = GradleConnector.newCancellationTokenSource();
myMap.put(id, tokenSource);
return tokenSource;
}
use of org.gradle.tooling.CancellationTokenSource in project android by JetBrains.
the class BuildStopperTest method createAndRegisterTokenSource.
@Test
public void createAndRegisterTokenSource() {
CancellationTokenSource tokenSource = myMapping.createAndRegisterTokenSource(myId);
assertSame(tokenSource, myMapping.get(myId));
}
use of org.gradle.tooling.CancellationTokenSource in project intellij-community by JetBrains.
the class GradleTaskManager method executeTasks.
@Override
public void executeTasks(@NotNull final ExternalSystemTaskId id, @NotNull final List<String> taskNames, @NotNull String projectPath, @Nullable GradleExecutionSettings settings, @Nullable final String jvmAgentSetup, @NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {
// TODO add support for external process mode
if (ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID)) {
for (GradleTaskManagerExtension gradleTaskManagerExtension : GradleTaskManagerExtension.EP_NAME.getExtensions()) {
if (gradleTaskManagerExtension.executeTasks(id, taskNames, projectPath, settings, jvmAgentSetup, listener)) {
return;
}
}
}
GradleExecutionSettings effectiveSettings = settings == null ? new GradleExecutionSettings(null, null, DistributionType.BUNDLED, false) : settings;
Function<ProjectConnection, Void> f = connection -> {
final List<String> initScripts = ContainerUtil.newArrayList();
final GradleProjectResolverExtension projectResolverChain = GradleProjectResolver.createProjectResolverChain(effectiveSettings);
for (GradleProjectResolverExtension resolverExtension = projectResolverChain; resolverExtension != null; resolverExtension = resolverExtension.getNext()) {
final String resolverClassName = resolverExtension.getClass().getName();
resolverExtension.enhanceTaskProcessing(taskNames, jvmAgentSetup, script -> {
if (StringUtil.isNotEmpty(script)) {
ContainerUtil.addAllNotNull(initScripts, "//-- Generated by " + resolverClassName, script, "//");
}
});
}
final String initScript = effectiveSettings.getUserData(INIT_SCRIPT_KEY);
if (StringUtil.isNotEmpty(initScript)) {
ContainerUtil.addAll(initScripts, "//-- Additional script", initScript, "//");
}
if (!initScripts.isEmpty()) {
try {
File tempFile = GradleExecutionHelper.writeToFileGradleInitScript(StringUtil.join(initScripts, SystemProperties.getLineSeparator()));
effectiveSettings.withArguments(GradleConstants.INIT_SCRIPT_CMD_OPTION, tempFile.getAbsolutePath());
} catch (IOException e) {
throw new ExternalSystemException(e);
}
}
GradleVersion gradleVersion = GradleExecutionHelper.getGradleVersion(connection);
if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.5")) < 0) {
listener.onStatusChange(new ExternalSystemTaskExecutionEvent(id, new ExternalSystemProgressEventUnsupportedImpl(gradleVersion + " does not support executions view")));
}
for (GradleBuildParticipant buildParticipant : effectiveSettings.getExecutionWorkspace().getBuildParticipants()) {
effectiveSettings.withArguments(GradleConstants.INCLUDE_BUILD_CMD_OPTION, buildParticipant.getProjectPath());
}
BuildLauncher launcher = myHelper.getBuildLauncher(id, connection, effectiveSettings, listener);
launcher.forTasks(ArrayUtil.toStringArray(taskNames));
if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.1")) < 0) {
myCancellationMap.put(id, new UnsupportedCancellationToken());
} else {
final CancellationTokenSource cancellationTokenSource = GradleConnector.newCancellationTokenSource();
launcher.withCancellationToken(cancellationTokenSource.token());
myCancellationMap.put(id, cancellationTokenSource);
}
try {
launcher.run();
} finally {
myCancellationMap.remove(id);
}
return null;
};
myHelper.execute(projectPath, effectiveSettings, f);
}
use of org.gradle.tooling.CancellationTokenSource in project android by JetBrains.
the class NewGradleSync method sync.
@VisibleForTesting
@NotNull
Callback sync(@NotNull Project project) {
Callback callback = new Callback();
if (project.isDisposed()) {
callback.reject(String.format("Project '%1$s' is already disposed", project.getName()));
}
// TODO: Handle sync cancellation.
// TODO: Show Gradle output.
GradleExecutionSettings executionSettings = getOrCreateGradleExecutionSettings(project, useEmbeddedGradle());
Function<ProjectConnection, Void> syncFunction = connection -> {
List<Class<?>> modelTypes = Lists.newArrayList(AndroidProject.class, NativeAndroidProject.class, GradleBuild.class, ModuleExtendedModel.class);
BuildActionExecuter<SyncAction.ProjectModels> executor = connection.action(new SyncAction(modelTypes));
ExternalSystemTaskNotificationListener listener = new ExternalSystemTaskNotificationListenerAdapter() {
};
List<String> commandLineArgs = myCommandLineArgs.get(project);
ExternalSystemTaskId id = createId(project);
prepare(executor, id, executionSettings, listener, Collections.emptyList(), commandLineArgs, connection);
CancellationTokenSource cancellationTokenSource = newCancellationTokenSource();
executor.withCancellationToken(cancellationTokenSource.token());
try {
SyncAction.ProjectModels models = executor.run();
callback.setDone(models);
} catch (RuntimeException e) {
callback.setRejected(e);
}
return null;
};
myHelper.execute(getBaseDirPath(project).getPath(), executionSettings, syncFunction);
return callback;
}
Aggregations