use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter 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.model.task.ExternalSystemTaskNotificationListenerAdapter 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.ExternalSystemTaskNotificationListenerAdapter 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);
}
use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter 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.ExternalSystemTaskNotificationListenerAdapter in project freeline by alibaba.
the class GradleUtil method executeTask.
/**
* 执行task
*
* @param project
* @param taskName
* @param args
* @param listener
*/
public static void executeTask(Project project, String taskName, String args, ExternalSystemTaskNotificationListener listener) {
AndroidGradleTaskManager manager = new AndroidGradleTaskManager();
List<String> taskNames = new ArrayList<String>();
if (taskName != null) {
taskNames.add(taskName);
}
List<String> vmOptions = new ArrayList<String>();
List<String> params = new ArrayList<String>();
if (args != null) {
params.add(args);
}
if (listener == null) {
listener = new ExternalSystemTaskNotificationListenerAdapter() {
};
}
manager.executeTasks(ExternalSystemTaskId.create(GradleConstants.SYSTEM_ID, ExternalSystemTaskType.EXECUTE_TASK, project), taskNames, project.getBasePath(), null, vmOptions, params, null, listener);
}
Aggregations