use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project intellij-community by JetBrains.
the class BaseGradleProjectResolverExtension method populateModuleDependencies.
@Override
public void populateModuleDependencies(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule, @NotNull final DataNode<ProjectData> ideProject) {
ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class);
if (externalProject != null) {
final Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap = ideProject.getUserData(GradleProjectResolver.RESOLVED_SOURCE_SETS);
final Map<String, String> artifactsMap = ideProject.getUserData(CONFIGURATION_ARTIFACTS);
assert artifactsMap != null;
if (resolverCtx.isResolveModulePerSourceSet()) {
assert sourceSetMap != null;
processSourceSets(resolverCtx, gradleModule, externalProject, ideModule, new SourceSetsProcessor() {
@Override
public void process(@NotNull DataNode<? extends ModuleData> dataNode, @NotNull ExternalSourceSet sourceSet) {
buildDependencies(resolverCtx, sourceSetMap, artifactsMap, dataNode, sourceSet.getDependencies(), ideProject);
}
});
return;
}
}
final List<? extends IdeaDependency> dependencies = gradleModule.getDependencies().getAll();
if (dependencies == null)
return;
List<String> orphanModules = ContainerUtil.newArrayList();
for (IdeaDependency dependency : dependencies) {
if (dependency == null) {
continue;
}
DependencyScope scope = parseScope(dependency.getScope());
if (dependency instanceof IdeaModuleDependency) {
ModuleDependencyData d = buildDependency(resolverCtx, ideModule, (IdeaModuleDependency) dependency, ideProject);
d.setExported(dependency.getExported());
if (scope != null) {
d.setScope(scope);
}
ideModule.createChild(ProjectKeys.MODULE_DEPENDENCY, d);
ModuleData targetModule = d.getTarget();
if (targetModule.getId().isEmpty() && targetModule.getLinkedExternalProjectPath().isEmpty()) {
orphanModules.add(targetModule.getExternalName());
}
} else if (dependency instanceof IdeaSingleEntryLibraryDependency) {
LibraryDependencyData d = buildDependency(gradleModule, ideModule, (IdeaSingleEntryLibraryDependency) dependency, ideProject);
d.setExported(dependency.getExported());
if (scope != null) {
d.setScope(scope);
}
ideModule.createChild(ProjectKeys.LIBRARY_DEPENDENCY, d);
}
}
if (!orphanModules.isEmpty()) {
ExternalSystemTaskId taskId = resolverCtx.getExternalSystemTaskId();
Project project = taskId.findProject();
if (project != null) {
String msg = "Can't find the following module" + (orphanModules.size() > 1 ? "s" : "") + ": " + StringUtil.join(orphanModules, ", ") + "\nIt can be caused by composite build configuration inside your *.gradle scripts with Gradle version older than 3.3." + "\nTry Gradle 3.3 or better or enable 'Create separate module per source set' option";
NotificationData notification = new NotificationData("Gradle project structure problems", msg, NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
ExternalSystemNotificationManager.getInstance(project).showNotification(taskId.getProjectSystemId(), notification);
}
}
}
use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId 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.ExternalSystemTaskId in project freeline by alibaba.
the class UpdateAction method updateAction.
/**
* 更新操作
*
* @param newVersion
* @param gradleBuildModels
*/
protected void updateAction(final String newVersion, final Map<GradleBuildModel, List<ArtifactDependencyModel>> gradleBuildModels) {
CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
for (GradleBuildModel file : gradleBuildModels.keySet()) {
List<ArtifactDependencyModel> models = gradleBuildModels.get(file);
for (ArtifactDependencyModel dependencyModel1 : models) {
ArtifactDependencyModelWrapper dependencyModel = new ArtifactDependencyModelWrapper(dependencyModel1);
if (isClasspathLibrary(dependencyModel)) {
dependencyModel1.setVersion(newVersion);
}
if (isDependencyLibrary(dependencyModel)) {
file.dependencies().remove(dependencyModel1);
}
}
file.applyChanges();
}
GradleUtil.executeTask(currentProject, "initFreeline", "-Pmirror", new ExternalSystemTaskNotificationListenerAdapter() {
@Override
public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) {
super.onTaskOutput(id, text, stdOut);
}
});
}
});
}
});
}
use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project intellij-community by JetBrains.
the class ExternalSystemResolveProjectTask method doExecute.
@SuppressWarnings("unchecked")
protected void doExecute() throws Exception {
final ExternalSystemFacadeManager manager = ServiceManager.getService(ExternalSystemFacadeManager.class);
Project ideProject = getIdeProject();
RemoteExternalSystemProjectResolver resolver = manager.getFacade(ideProject, myProjectPath, getExternalSystemId()).getResolver();
ExternalSystemExecutionSettings settings = ExternalSystemApiUtil.getExecutionSettings(ideProject, myProjectPath, getExternalSystemId());
if (StringUtil.isNotEmpty(myVmOptions)) {
settings.withVmOptions(ParametersListUtil.parse(myVmOptions));
}
if (StringUtil.isNotEmpty(myArguments)) {
settings.withArguments(ParametersListUtil.parse(myArguments));
}
ExternalSystemProgressNotificationManagerImpl progressNotificationManager = (ExternalSystemProgressNotificationManagerImpl) ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
ExternalSystemTaskId id = getId();
progressNotificationManager.onStart(id, myProjectPath);
try {
DataNode<ProjectData> project = resolver.resolveProjectInfo(id, myProjectPath, myIsPreviewMode, settings);
if (project != null) {
myExternalProject.set(project);
ExternalSystemManager<?, ?, ?, ?, ?> systemManager = ExternalSystemApiUtil.getManager(getExternalSystemId());
assert systemManager != null;
Set<String> externalModulePaths = ContainerUtil.newHashSet();
Collection<DataNode<ModuleData>> moduleNodes = ExternalSystemApiUtil.findAll(project, ProjectKeys.MODULE);
for (DataNode<ModuleData> node : moduleNodes) {
externalModulePaths.add(node.getData().getLinkedExternalProjectPath());
}
String projectPath = project.getData().getLinkedExternalProjectPath();
ExternalProjectSettings linkedProjectSettings = systemManager.getSettingsProvider().fun(ideProject).getLinkedProjectSettings(projectPath);
if (linkedProjectSettings != null) {
linkedProjectSettings.setModules(externalModulePaths);
}
}
progressNotificationManager.onSuccess(id);
} finally {
progressNotificationManager.onEnd(id);
}
}
use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId 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);
}
Aggregations