org.xtext.gradle.idea.IdeaComponentPlugin 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.Collections;
import java.util.HashSet;
import java.util.List;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
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.Pair;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.gradle.api.Action;
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.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.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.listener.ActionBroadcast;
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.xtext.gradle.idea.IdeaDevelopmentPlugin;
import org.xtext.gradle.idea.tasks.AssembleSandbox;
import org.xtext.gradle.idea.tasks.DownloadIdea;
import org.xtext.gradle.idea.tasks.DownloadPlugins;
import org.xtext.gradle.idea.tasks.IdeaExtension;
import org.xtext.gradle.idea.tasks.IdeaPluginDependencies;
import org.xtext.gradle.idea.tasks.RunIdea;
@SuppressWarnings("all")
public class IdeaComponentPlugin implements Plugin {
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, IdeaComponentPlugin.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(IdeaComponentPlugin.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());
}
}
};
@Override
public void apply(final Project project) {
PluginContainer _plugins = project.getPlugins();
_plugins.apply(IdeaDevelopmentPlugin.class);
PluginContainer _plugins_1 = project.getPlugins();
_plugins_1.apply(JavaPlugin.class);
ExtensionContainer _extensions = project.getExtensions();
final IdeaExtension idea = _extensions.getByType(IdeaExtension.class);
Convention _convention = project.getConvention();
final JavaPluginConvention java = _convention.getPlugin(JavaPluginConvention.class);
ConfigurationContainer _configurations = project.getConfigurations();
final Configuration compile = _configurations.getAt(JavaPlugin.COMPILE_CONFIGURATION_NAME);
Pair _mappedTo = Pair.of("module", "guava");
compile.exclude(Collections.unmodifiableMap(CollectionLiterals.newHashMap(_mappedTo)));
Pair _mappedTo_1 = Pair.of("module", "log4j");
compile.exclude(Collections.unmodifiableMap(CollectionLiterals.newHashMap(_mappedTo_1)));
ConfigurationContainer _configurations_1 = project.getConfigurations();
final Configuration ideaProvided = _configurations_1.create(IdeaComponentPlugin.IDEA_PROVIDED_CONFIGURATION_NAME);
SourceSetContainer _sourceSets = java.getSourceSets();
final Action _function = new Action() {
@Override
public void execute(final SourceSet it) {
FileCollection _compileClasspath = it.getCompileClasspath();
FileCollection _plus = _compileClasspath.plus(ideaProvided);
it.setCompileClasspath(_plus);
FileCollection _runtimeClasspath = it.getRuntimeClasspath();
FileCollection _plus_1 = _runtimeClasspath.plus(ideaProvided);
ConfigurableFileCollection _olsJar = idea.toolsJar();
FileCollection _plus_2 = _plus_1.plus(_olsJar);
it.setRuntimeClasspath(_plus_2);
}
};
_sourceSets.all(_function);
TaskContainer _tasks = project.getTasks();
AssembleSandbox _create = _tasks.create(IdeaComponentPlugin.ASSEMBLE_SANDBOX_TASK_NAME, AssembleSandbox.class);
final Procedure1 _function_1 = 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 AssembleSandbox assembleSandboxTask = ObjectExtensions.operator_doubleArrow(_create, _function_1);
final Action _function_2 = new Action() {
@Override
public void execute(final Project it) {
List