use of com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager in project intellij-community by JetBrains.
the class GradleDependenciesImportingTest method assertCompileClasspathOrdering.
protected void assertCompileClasspathOrdering(String moduleName) {
Module module = getModule(moduleName);
String sourceSetName = getSourceSetName(module);
assertNotNull("Can not find the sourceSet for the module", sourceSetName);
ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
settings.setExternalProjectPath(getExternalProjectPath(module));
String id = getExternalProjectId(module);
String gradlePath = id.startsWith(":") ? trimEnd(id, sourceSetName) : "";
settings.setTaskNames(Collections.singletonList(gradlePath + ":print" + capitalize(sourceSetName) + "CompileDependencies"));
settings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
settings.setScriptParameters("--quiet");
ExternalSystemProgressNotificationManager notificationManager = ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
StringBuilder gradleClasspath = new StringBuilder();
ExternalSystemTaskNotificationListenerAdapter listener = new ExternalSystemTaskNotificationListenerAdapter() {
@Override
public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) {
gradleClasspath.append(text);
}
};
notificationManager.addNotificationListener(listener);
ExternalSystemUtil.runTask(settings, DefaultRunExecutor.EXECUTOR_ID, myProject, GradleConstants.SYSTEM_ID, null, ProgressExecutionMode.NO_PROGRESS_SYNC);
notificationManager.removeNotificationListener(listener);
List<String> ideClasspath = ContainerUtil.newArrayList();
ModuleRootManager.getInstance(module).orderEntries().withoutSdk().withoutModuleSourceEntries().compileOnly().productionOnly().forEach(entry -> {
if (entry instanceof ModuleOrderEntry) {
Module moduleDep = ((ModuleOrderEntry) entry).getModule();
String sourceSetDepName = getSourceSetName(moduleDep);
assert sourceSetDepName != "main";
String gradleProjectDepName = trimStart(trimEnd(getExternalProjectId(moduleDep), ":main"), ":");
String version = getExternalProjectVersion(moduleDep);
version = "unspecified".equals(version) ? "" : "-" + version;
ideClasspath.add(gradleProjectDepName + version + ".jar");
} else {
ideClasspath.add(entry.getFiles(OrderRootType.CLASSES)[0].getName());
}
return true;
});
assertEquals(join(ideClasspath, " "), gradleClasspath.toString().trim());
}
use of com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager 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