org.xtext.gradle.idea.IdeaDevelopmentPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xtext-idea-gradle-plugin Show documentation
Show all versions of xtext-idea-gradle-plugin Show documentation
A plugin for for building IntelliJ IDEA Xtext plugins
package org.xtext.gradle.idea;
import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.function.Consumer;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.gradle.api.Action;
import org.gradle.api.DomainObjectCollection;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.execution.TaskExecutionGraph;
import org.gradle.api.execution.TaskExecutionGraphListener;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.CopySpec;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.file.copy.CopySpecInternal;
import org.gradle.api.internal.file.copy.DestinationRootCopySpec;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.Convention;
import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.PluginContainer;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskCollection;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.testing.Test;
import org.gradle.plugins.ide.api.XmlFileContentMerger;
import org.gradle.plugins.ide.eclipse.EclipsePlugin;
import org.gradle.plugins.ide.eclipse.model.Classpath;
import org.gradle.plugins.ide.eclipse.model.ClasspathEntry;
import org.gradle.plugins.ide.eclipse.model.EclipseClasspath;
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import org.gradle.plugins.ide.eclipse.model.FileReference;
import org.gradle.plugins.ide.eclipse.model.Library;
import org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory;
import org.gradle.plugins.ide.idea.IdeaPlugin;
import org.gradle.plugins.ide.idea.model.IdeaModel;
import org.gradle.plugins.ide.idea.model.IdeaModule;
import org.xtext.gradle.idea.tasks.AssembleSandbox;
import org.xtext.gradle.idea.tasks.DownloadIdea;
import org.xtext.gradle.idea.tasks.DownloadIdeaPlugins;
import org.xtext.gradle.idea.tasks.GradleExtensions;
import org.xtext.gradle.idea.tasks.IdeaExtension;
import org.xtext.gradle.idea.tasks.IdeaPluginDependencies;
import org.xtext.gradle.idea.tasks.IdeaPluginDependency;
import org.xtext.gradle.idea.tasks.IdeaPluginRepositories;
import org.xtext.gradle.idea.tasks.RunIdea;
@SuppressWarnings("all")
public class IdeaDevelopmentPlugin implements Plugin {
public final static String IDEA_DEVELOPMENT_EXTENSION_NAME = "ideaDevelopment";
public final static String IDEA_TASK_GROUP = "Intellij Idea";
public final static String IDEA_PROVIDED_CONFIGURATION_NAME = "ideaProvided";
public final static String ASSEMBLE_SANDBOX_TASK_NAME = "assembleSandbox";
public final static String RUN_IDEA_TASK_NAME = "runIdea";
private final static TaskExecutionGraphListener runIdeaValidator = new TaskExecutionGraphListener() {
@Override
public void graphPopulated(final TaskExecutionGraph graph) {
List _allTasks = graph.getAllTasks();
final Function1 _function = new Function1() {
@Override
public Boolean apply(final Task it) {
String _name = it.getName();
return Boolean.valueOf(Objects.equal(_name, IdeaDevelopmentPlugin.RUN_IDEA_TASK_NAME));
}
};
final Iterable runTasks = IterableExtensions.filter(_allTasks, _function);
int _size = IterableExtensions.size(runTasks);
boolean _greaterThan = (_size > 1);
if (_greaterThan) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("There are multiple ");
_builder.append(IdeaDevelopmentPlugin.RUN_IDEA_TASK_NAME, "");
_builder.append(" tasks in the task graph.");
_builder.newLineIfNotEmpty();
_builder.append("When calling runIdea on an aggregate project, make sure you fully qualify the task name,");
_builder.newLine();
_builder.append("e.g. \':myProject:runIdea\'");
_builder.newLine();
throw new GradleException(_builder.toString());
}
}
};
private IdeaExtension idea;
private DownloadIdea downloadIdea;
private DownloadIdeaPlugins downloadPlugins;
private AssembleSandbox assembleSandbox;
private RunIdea runIdea;
private JavaPluginConvention java;
private Configuration ideaProvided;
@Override
public void apply(final Project project) {
ExtensionContainer _extensions = project.getExtensions();
IdeaExtension _create = _extensions.create(IdeaDevelopmentPlugin.IDEA_DEVELOPMENT_EXTENSION_NAME, IdeaExtension.class, project);
this.idea = _create;
this.configureDownloadIdeaTask(project);
this.configureDownloadPluginsTask(project);
this.configureassembleSandboxTask(project);
this.configureRunIdeaTask(project);
this.integrateWithJavaPlugin(project);
}
private void configureDownloadIdeaTask(final Project project) {
TaskContainer _tasks = project.getTasks();
DownloadIdea _create = _tasks.create("downloadIdea", DownloadIdea.class);
final Procedure1 _function = new Procedure1() {
@Override
public void apply(final DownloadIdea it) {
it.setGroup(IdeaDevelopmentPlugin.IDEA_TASK_GROUP);
it.setDescription("Downloads Intellij Idea");
final Action _function = new Action() {
@Override
public void execute(final Project p) {
File _ideaHome = IdeaDevelopmentPlugin.this.idea.getIdeaHome();
it.setIdeaHome(_ideaHome);
String _ideaVersion = IdeaDevelopmentPlugin.this.idea.getIdeaVersion();
it.setIdeaVersion(_ideaVersion);
}
};
project.afterEvaluate(_function);
}
};
DownloadIdea _doubleArrow = ObjectExtensions.operator_doubleArrow(_create, _function);
this.downloadIdea = _doubleArrow;
this.idea.setDownloadIdea(this.downloadIdea);
}
private void configureDownloadPluginsTask(final Project project) {
TaskContainer _tasks = project.getTasks();
DownloadIdeaPlugins _create = _tasks.create("downloadIdeaPlugins", DownloadIdeaPlugins.class);
final Procedure1 _function = new Procedure1() {
@Override
public void apply(final DownloadIdeaPlugins it) {
it.setDescription("Downloads Idea plugin dependencies");
it.setGroup(IdeaDevelopmentPlugin.IDEA_TASK_GROUP);
final Action _function = new Action() {
@Override
public void execute(final Project p) {
File _pluginsCache = IdeaDevelopmentPlugin.this.idea.getPluginsCache();
it.setDestinationDir(_pluginsCache);
IdeaPluginRepositories _pluginRepositories = IdeaDevelopmentPlugin.this.idea.getPluginRepositories();
it.setPluginRepositories(_pluginRepositories);
IdeaPluginDependencies _pluginDependencies = IdeaDevelopmentPlugin.this.idea.getPluginDependencies();
it.setPluginDependencies(_pluginDependencies);
}
};
project.afterEvaluate(_function);
}
};
DownloadIdeaPlugins _doubleArrow = ObjectExtensions.operator_doubleArrow(_create, _function);
this.downloadPlugins = _doubleArrow;
this.idea.setDownloadPlugins(this.downloadPlugins);
}
private AssembleSandbox configureassembleSandboxTask(final Project project) {
TaskContainer _tasks = project.getTasks();
AssembleSandbox _create = _tasks.create(IdeaDevelopmentPlugin.ASSEMBLE_SANDBOX_TASK_NAME, AssembleSandbox.class);
final Procedure1 _function = new Procedure1() {
@Override
public void apply(final AssembleSandbox it) {
it.setDescription("Creates a folder containing the plugins to run Idea with");
it.setGroup(BasePlugin.BUILD_GROUP);
final Action _function = new Action() {
@Override
public void execute(final Project p) {
File _sandboxDir = IdeaDevelopmentPlugin.this.idea.getSandboxDir();
it.setDestinationDir(_sandboxDir);
CopySpec _plugin = it.getPlugin();
String _name = project.getName();
_plugin.into(_name);
IdeaPluginDependencies _pluginDependencies = IdeaDevelopmentPlugin.this.idea.getPluginDependencies();
Iterable _externalDependencies = _pluginDependencies.getExternalDependencies();
final Consumer _function = new Consumer() {
@Override
public void accept(final IdeaPluginDependency dependency) {
DestinationRootCopySpec _rootSpec = it.getRootSpec();
CopySpecInternal _addChild = _rootSpec.addChild();
String _id = dependency.getId();
CopySpec _into = _addChild.into(_id);
File _pluginsCache = IdeaDevelopmentPlugin.this.idea.getPluginsCache();
String _id_1 = dependency.getId();
File _divide = GradleExtensions.operator_divide(_pluginsCache, _id_1);
String _version = dependency.getVersion();
File _divide_1 = GradleExtensions.operator_divide(_divide, _version);
_into.from(_divide_1);
}
};
_externalDependencies.forEach(_function);
IdeaPluginDependencies _pluginDependencies_1 = IdeaDevelopmentPlugin.this.idea.getPluginDependencies();
Iterable _endorsedDependencies = _pluginDependencies_1.getEndorsedDependencies();
final Consumer _function_1 = new Consumer() {
@Override
public void accept(final IdeaPluginDependency dependency) {
DestinationRootCopySpec _rootSpec = it.getRootSpec();
CopySpecInternal _addChild = _rootSpec.addChild();
String _id = dependency.getId();
CopySpec _into = _addChild.into(_id);
File _ideaHome = IdeaDevelopmentPlugin.this.idea.getIdeaHome();
File _divide = GradleExtensions.operator_divide(_ideaHome, "plugins");
String _id_1 = dependency.getId();
File _divide_1 = GradleExtensions.operator_divide(_divide, _id_1);
_into.from(_divide_1);
}
};
_endorsedDependencies.forEach(_function_1);
IdeaPluginDependencies _pluginDependencies_2 = IdeaDevelopmentPlugin.this.idea.getPluginDependencies();
TreeSet _projectDependencies = _pluginDependencies_2.getProjectDependencies();
final Function1 _function_2 = new Function1() {
@Override
public Project apply(final IdeaPluginDependency it) {
String _id = it.getId();
return project.project(_id);
}
};
Iterable _map = IterableExtensions.map(_projectDependencies, _function_2);
final Function1 _function_3 = new Function1() {
@Override
public Task apply(final Project it) {
TaskContainer _tasks = it.getTasks();
return _tasks.getAt(IdeaDevelopmentPlugin.ASSEMBLE_SANDBOX_TASK_NAME);
}
};
final Iterable upstreamSandBoxTasks = IterableExtensions.map(_map, _function_3);
it.from(upstreamSandBoxTasks);
}
};
project.afterEvaluate(_function);
}
};
AssembleSandbox _doubleArrow = ObjectExtensions.operator_doubleArrow(_create, _function);
return this.assembleSandbox = _doubleArrow;
}
private void configureRunIdeaTask(final Project project) {
TaskContainer _tasks = project.getTasks();
RunIdea _create = _tasks.create(IdeaDevelopmentPlugin.RUN_IDEA_TASK_NAME, RunIdea.class);
final Procedure1 _function = new Procedure1() {
@Override
public void apply(final RunIdea it) {
it.dependsOn(IdeaDevelopmentPlugin.this.assembleSandbox);
it.setDescription("Runs Intellij IDEA with this project and its dependencies installed");
it.setGroup(IdeaDevelopmentPlugin.IDEA_TASK_GROUP);
final Action _function = new Action() {
@Override
public void execute(final Project p) {
File _sandboxDir = IdeaDevelopmentPlugin.this.idea.getSandboxDir();
it.setSandboxDir(_sandboxDir);
File _ideaHome = IdeaDevelopmentPlugin.this.idea.getIdeaHome();
it.setIdeaHome(_ideaHome);
FileCollection _ideaRunClasspath = IdeaDevelopmentPlugin.this.idea.getIdeaRunClasspath();
it.setClasspath(_ideaRunClasspath);
}
};
project.afterEvaluate(_function);
}
};
RunIdea _doubleArrow = ObjectExtensions.operator_doubleArrow(_create, _function);
this.runIdea = _doubleArrow;
Gradle _gradle = project.getGradle();
TaskExecutionGraph _taskGraph = _gradle.getTaskGraph();
_taskGraph.addTaskExecutionGraphListener(IdeaDevelopmentPlugin.runIdeaValidator);
}
private DomainObjectCollection integrateWithJavaPlugin(final Project project) {
PluginContainer _plugins = project.getPlugins();
final Action _function = new Action() {
@Override
public void execute(final JavaBasePlugin it) {
Convention _convention = project.getConvention();
JavaPluginConvention _plugin = _convention.getPlugin(JavaPluginConvention.class);
IdeaDevelopmentPlugin.this.java = _plugin;
PluginContainer _plugins = project.getPlugins();
final Action _function = new Action() {
@Override
public void execute(final JavaPlugin it) {
IdeaDevelopmentPlugin.this.addIdeaProvidedDependencies(project);
IdeaDevelopmentPlugin.this.addIdeaDependenciesToEclipseClasspath(project);
IdeaDevelopmentPlugin.this.addIdeaDependenciesToIntelliJClasspath(project);
IdeaDevelopmentPlugin.this.adjustTestEnvironment(project);
}
};
_plugins.withType(JavaPlugin.class, _function);
}
};
return _plugins.withType(JavaBasePlugin.class, _function);
}
private void addIdeaProvidedDependencies(final Project project) {
ConfigurationContainer _configurations = project.getConfigurations();
Configuration _create = _configurations.create(IdeaDevelopmentPlugin.IDEA_PROVIDED_CONFIGURATION_NAME);
this.ideaProvided = _create;
SourceSetContainer _sourceSets = this.java.getSourceSets();
final Action _function = new Action() {
@Override
public void execute(final SourceSet it) {
FileCollection _compileClasspath = it.getCompileClasspath();
FileCollection _plus = _compileClasspath.plus(IdeaDevelopmentPlugin.this.ideaProvided);
it.setCompileClasspath(_plus);
FileCollection _runtimeClasspath = it.getRuntimeClasspath();
FileCollection _plus_1 = _runtimeClasspath.plus(IdeaDevelopmentPlugin.this.ideaProvided);
ConfigurableFileCollection _olsJar = IdeaDevelopmentPlugin.this.idea.toolsJar();
FileCollection _plus_2 = _plus_1.plus(_olsJar);
it.setRuntimeClasspath(_plus_2);
}
};
_sourceSets.all(_function);
final Action _function_1 = new Action() {
@Override
public void execute(final Project it) {
List