use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent in project intellij-community by JetBrains.
the class GradleExecutionHelper method prepare.
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
public static void prepare(@NotNull LongRunningOperation operation, @NotNull final ExternalSystemTaskId id, @NotNull GradleExecutionSettings settings, @NotNull final ExternalSystemTaskNotificationListener listener, @NotNull ProjectConnection connection, @NotNull final OutputStream standardOutput, @NotNull final OutputStream standardError) {
Set<String> jvmArgs = settings.getVmOptions();
if (!jvmArgs.isEmpty()) {
// merge gradle args e.g. defined in gradle.properties
BuildEnvironment buildEnvironment = getBuildEnvironment(connection);
Collection<String> merged = buildEnvironment != null ? mergeJvmArgs(settings.getServiceDirectory(), buildEnvironment.getJava().getJvmArguments(), jvmArgs) : jvmArgs;
// filter nulls and empty strings
List<String> filteredArgs = ContainerUtil.mapNotNull(merged, s -> StringUtil.isEmpty(s) ? null : s);
operation.setJvmArguments(ArrayUtil.toStringArray(filteredArgs));
}
if (settings.isOfflineWork()) {
settings.withArgument(GradleConstants.OFFLINE_MODE_CMD_OPTION);
}
final Application application = ApplicationManager.getApplication();
if (application != null && application.isUnitTestMode()) {
if (!settings.getArguments().contains("--quiet")) {
settings.withArgument("--info");
}
settings.withArgument("--recompile-scripts");
}
if (!settings.getArguments().isEmpty()) {
LOG.info("Passing command-line args to Gradle Tooling API: " + StringUtil.join(settings.getArguments(), " "));
// filter nulls and empty strings
List<String> filteredArgs = ContainerUtil.mapNotNull(settings.getArguments(), s -> StringUtil.isEmpty(s) ? null : s);
// TODO remove this replacement when --tests option will become available for tooling API
replaceTestCommandOptionWithInitScript(filteredArgs);
operation.withArguments(ArrayUtil.toStringArray(filteredArgs));
}
final String javaHome = settings.getJavaHome();
if (javaHome != null && new File(javaHome).isDirectory()) {
operation.setJavaHome(new File(javaHome));
}
operation.addProgressListener(new ProgressListener() {
@Override
public void statusChanged(ProgressEvent event) {
listener.onStatusChange(new ExternalSystemTaskNotificationEvent(id, event.getDescription()));
}
});
operation.addProgressListener(new org.gradle.tooling.events.ProgressListener() {
@Override
public void statusChanged(org.gradle.tooling.events.ProgressEvent event) {
listener.onStatusChange(GradleProgressEventConverter.convert(id, event));
}
});
operation.setStandardOutput(standardOutput);
operation.setStandardError(standardError);
}
use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent in project intellij-community by JetBrains.
the class GradleProgressEventConverter method convert.
@NotNull
public static ExternalSystemTaskNotificationEvent convert(ExternalSystemTaskId id, ProgressEvent event) {
final InternalOperationDescriptor internalDesc = event.getDescriptor() instanceof DefaultOperationDescriptor ? ((DefaultOperationDescriptor) event.getDescriptor()).getInternalOperationDescriptor() : null;
final String eventId = internalDesc == null ? event.getDescriptor().getDisplayName() : internalDesc.getId().toString();
final String parentEventId;
if (event.getDescriptor().getParent() == null) {
parentEventId = null;
} else {
parentEventId = internalDesc == null ? event.getDescriptor().getParent().getDisplayName() : internalDesc.getParentId().toString();
}
final String description = event.getDescriptor().getName();
if (event instanceof StartEvent) {
final OperationDescriptor descriptor = convert(event.getDescriptor(), event.getEventTime());
return new ExternalSystemTaskExecutionEvent(id, new ExternalSystemStartEventImpl<>(eventId, parentEventId, descriptor));
} else if (event instanceof FinishEvent) {
final OperationDescriptor descriptor = convert(event.getDescriptor(), event.getEventTime());
return new ExternalSystemTaskExecutionEvent(id, new ExternalSystemFinishEventImpl<>(eventId, parentEventId, descriptor, convert(((FinishEvent) event).getResult())));
} else if (event instanceof TaskProgressEvent) {
final OperationDescriptor descriptor = convert(event.getDescriptor(), event.getEventTime());
return new ExternalSystemTaskExecutionEvent(id, new BaseExternalSystemProgressEvent<>(eventId, parentEventId, descriptor));
} else {
return new ExternalSystemTaskNotificationEvent(id, description);
}
}
use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent in project intellij-community by JetBrains.
the class GradleRunnerUtil method attachTaskExecutionView.
public static DuplexConsoleView attachTaskExecutionView(@NotNull final Project project, @NotNull final ConsoleView consoleView, final boolean isTaskConsoleEnabledByDefault, @Nullable final String stateStorageKey, @NotNull final ProcessHandler processHandler, @NotNull final ExternalSystemTaskId taskId) {
final String tripleStateStorageKey = stateStorageKey != null ? stateStorageKey + "_str" : null;
if (stateStorageKey != null && isTaskConsoleEnabledByDefault && !PropertiesComponent.getInstance().isValueSet(tripleStateStorageKey)) {
PropertiesComponent.getInstance().setValue(tripleStateStorageKey, Boolean.TRUE.toString());
PropertiesComponent.getInstance().setValue(stateStorageKey, Boolean.TRUE);
}
final TaskExecutionView gradleExecutionConsole = new TaskExecutionView(project);
final Ref<DuplexConsoleView> duplexConsoleViewRef = Ref.create();
final DuplexConsoleView duplexConsoleView = new DuplexConsoleView<ConsoleView, ConsoleView>(gradleExecutionConsole, consoleView, stateStorageKey) {
@Override
public void enableConsole(boolean primary) {
super.enableConsole(primary);
if (stateStorageKey != null) {
PropertiesComponent.getInstance().setValue(tripleStateStorageKey, Boolean.toString(primary));
}
}
@NotNull
@Override
public AnAction[] createConsoleActions() {
final DefaultActionGroup textActionGroup = new DefaultActionGroup() {
@Override
public void update(AnActionEvent e) {
super.update(e);
if (duplexConsoleViewRef.get() != null) {
e.getPresentation().setVisible(!duplexConsoleViewRef.get().isPrimaryConsoleEnabled());
}
}
};
final AnAction[] consoleActions = consoleView.createConsoleActions();
for (AnAction anAction : consoleActions) {
textActionGroup.add(anAction);
}
final List<AnAction> anActions = ContainerUtil.newArrayList(super.createConsoleActions());
anActions.add(textActionGroup);
return ArrayUtil.toObjectArray(anActions, AnAction.class);
}
};
duplexConsoleViewRef.set(duplexConsoleView);
duplexConsoleView.setDisableSwitchConsoleActionOnProcessEnd(false);
duplexConsoleView.getSwitchConsoleActionPresentation().setIcon(AllIcons.Actions.ChangeView);
duplexConsoleView.getSwitchConsoleActionPresentation().setText(GradleBundle.message("gradle.runner.toggle.tree.text.action.name"));
final ExternalSystemProgressNotificationManager progressManager = ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
final ExternalSystemTaskNotificationListenerAdapter taskListener = new ExternalSystemTaskNotificationListenerAdapter() {
@Override
public void onStatusChange(@NotNull final ExternalSystemTaskNotificationEvent event) {
if (event instanceof ExternalSystemTaskExecutionEvent) {
UIUtil.invokeLaterIfNeeded(() -> {
if (((ExternalSystemTaskExecutionEvent) event).getProgressEvent() instanceof ExternalSystemProgressEventUnsupported) {
duplexConsoleView.enableConsole(false);
}
gradleExecutionConsole.onStatusChange((ExternalSystemTaskExecutionEvent) event);
});
}
}
@Override
public void onQueued(@NotNull ExternalSystemTaskId id, final String workingDir) {
UIUtil.invokeLaterIfNeeded(() -> gradleExecutionConsole.setWorkingDir(workingDir));
}
@Override
public void onFailure(@NotNull ExternalSystemTaskId id, @NotNull final Exception e) {
UIUtil.invokeLaterIfNeeded(() -> gradleExecutionConsole.onFailure(e));
}
@Override
public void onEnd(@NotNull ExternalSystemTaskId id) {
progressManager.removeNotificationListener(this);
}
};
progressManager.addNotificationListener(taskId, taskListener);
return duplexConsoleView;
}
Aggregations