use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId 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;
}
use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId 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;
}
use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project android by JetBrains.
the class FastGradleSync method requestProjectSync.
@NotNull
public Callback requestProjectSync(@NotNull Project project) {
Callback callback = new Callback();
GradleExecutionSettings settings = getGradleExecutionSettings(project);
ExternalSystemTaskId id = ExternalSystemTaskId.create(GRADLE_SYSTEM_ID, RESOLVE_PROJECT, project);
String projectPath = project.getBasePath();
assert projectPath != null;
ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
DataNode<ProjectData> projectDataNode = myProjectResolver.resolveProjectInfo(id, projectPath, false, settings, NULL_OBJECT);
assert projectDataNode != null;
invokeAndWaitIfNeeded((ThrowableRunnable) () -> populate(project, projectDataNode, null, false));
callback.setDone();
} catch (Throwable e) {
callback.setRejected(e);
}
});
return callback;
}
use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project android by JetBrains.
the class AndroidGradleProjectResolverIdeaTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
initMocks(this);
myProjectModel = new IdeaProjectStub("multiProject");
myAndroidProject = TestProjects.createBasicProject(myProjectModel.getRootDir());
myNativeAndroidProject = TestProjects.createNativeProject(myProjectModel.getRootDir());
myAndroidModuleModel = myProjectModel.addModule(myAndroidProject.getName(), "androidTask");
myNativeAndroidModuleModel = myProjectModel.addModule(myNativeAndroidProject.getName(), "nativeAndroidTask");
myJavaModuleModel = myProjectModel.addModule("util", "compileJava", "jar", "classes");
myProjectModel.addModule("notReallyAGradleProject");
ProjectImportAction.AllModels allModels = new ProjectImportAction.AllModels(myProjectModel);
allModels.addExtraProject(myAndroidProject, AndroidProject.class, myAndroidModuleModel);
allModels.addExtraProject(myNativeAndroidProject, NativeAndroidProject.class, myNativeAndroidModuleModel);
ExternalSystemTaskId id = ExternalSystemTaskId.create(SYSTEM_ID, RESOLVE_PROJECT, myProjectModel.getName());
String projectPath = toSystemDependentName(myProjectModel.getBuildFile().getParent());
ExternalSystemTaskNotificationListener notificationListener = new ExternalSystemTaskNotificationListenerAdapter() {
};
myResolverCtx = new DefaultProjectResolverContext(id, projectPath, null, mock(ProjectConnection.class), notificationListener, true);
myResolverCtx.setModels(allModels);
myProjectResolver = new AndroidGradleProjectResolver(myCommandLineArgs, myErrorHandler, myProjectFinder, myVariantSelector);
myProjectResolver.setProjectResolverContext(myResolverCtx);
GradleProjectResolverExtension next = new BaseGradleProjectResolverExtension();
next.setProjectResolverContext(myResolverCtx);
myProjectResolver.setNext(next);
}
Aggregations