use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener 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 com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener 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.ExternalSystemTaskNotificationListener 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