Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.xtext.gradle;
  
  import  com.google.common.base.Objects;
  import  com.google.common.collect.Iterables;
  import  com.google.common.collect.Maps;
  import java.io.File;
  import java.util.Map;
  import java.util.Set;
 import  javax.inject.Inject;
 import  org.eclipse.xtend2.lib.StringConcatenation;
 import  org.eclipse.xtext.xbase.lib.CollectionExtensions;
 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.NamedDomainObjectContainer;
 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.Dependency;
 import  org.gradle.api.artifacts.ExternalModuleDependency;
 import  org.gradle.api.artifacts.dsl.DependencyHandler;
 import  org.gradle.api.file.SourceDirectorySet;
 import  org.gradle.api.internal.file.FileResolver;
 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.TaskContainer;
 import  org.gradle.plugins.ide.eclipse.EclipsePlugin;
 import  org.gradle.plugins.ide.eclipse.model.EclipseModel;
 import  org.gradle.plugins.ide.eclipse.model.EclipseProject;
 
 public class XtextPlugin implements Plugin<Project> {
   private FileResolver fileResolver;
   
   @Inject
   public XtextPlugin(final FileResolver fileResolver) {
     this. = fileResolver;
   }
   
   private String getPluginVersion() {
     Class<? extends XtextPlugin_class = this.getClass();
     Package _package = _class.getPackage();
     return _package.getImplementationVersion();
   }
   
   public void apply(final Project project) {
     PluginContainer _plugins = project.getPlugins();
     _plugins.<BasePlugin>apply(BasePlugin.class);
     PluginContainer _plugins_1 = project.getPlugins();
     _plugins_1.<EclipsePlugin>apply(EclipsePlugin.class);
     ExtensionContainer _extensions = project.getExtensions();
     final XtextExtension xtext = _extensions.<XtextExtension>create("xtext"XtextExtension.classprojectthis.);
     ConfigurationContainer _configurations = project.getConfigurations();
     final Configuration xtextTooling = _configurations.create("xtextTooling");
     ConfigurationContainer _configurations_1 = project.getConfigurations();
     final Configuration xtextDependencies = _configurations_1.create("xtext");
     TaskContainer _tasks = project.getTasks();
     final XtextEclipseSettings settingsTask = _tasks.<XtextEclipseSettings>create("xtextEclipseSettings"XtextEclipseSettings.class);
     settingsTask.configure(xtext);
     TaskContainer _tasks_1 = project.getTasks();
     String _eCLIPSE_TASK_NAME = EclipsePlugin.getECLIPSE_TASK_NAME();
     Task _at = _tasks_1.getAt(_eCLIPSE_TASK_NAME);
     _at.dependsOn(settingsTask);
     ExtensionContainer _extensions_1 = project.getExtensions();
     final EclipseModel eclipse = _extensions_1.<EclipseModel>getByType(EclipseModel.class);
     EclipseProject _project = eclipse.getProject();
     _project.buildCommand("org.eclipse.xtext.ui.shared.xtextBuilder");
     EclipseProject _project_1 = eclipse.getProject();
     _project_1.natures("org.eclipse.xtext.ui.shared.xtextNature");
     TaskContainer _tasks_2 = project.getTasks();
     final XtextGenerate generatorTask = _tasks_2.<XtextGenerate>create("xtextGenerate"XtextGenerate.class);
     final Action<Project> _function = new Action<Project>() {
       public void execute(final Project it) {
         DependencyHandler _dependencies = project.getDependencies();
         final Procedure1<DependencyHandler> _function = new Procedure1<DependencyHandler>() {
           public void apply(final DependencyHandler it) {
             StringConcatenation _builder = new StringConcatenation();
             _builder.append("org.eclipse.xtext:org.eclipse.xtext.builder.standalone:");
             String _version = xtext.getVersion();
             _builder.append(_version"");
             final Procedure1<ExternalModuleDependency> _function = new Procedure1<ExternalModuleDependency>() {
               public void apply(final ExternalModuleDependency it) {
                it.setForce(true);
                Map<StringString_xsetliteral = null;
                Map<StringString_tempMap = Maps.<StringString>newHashMap();
                _tempMap.put("group""asm");
                _xsetliteral = Collections.<StringString>unmodifiableMap(_tempMap);
                it.exclude(_xsetliteral);
              }
            };
            Dependency _externalModule = GradleExtensions.externalModule(it_builder.toString(), _function);
            it.add(
              "xtextTooling"_externalModule);
            StringConcatenation _builder_1 = new StringConcatenation();
            _builder_1.append("org.xtext:xtext-gradle-lib:");
            String _pluginVersion = XtextPlugin.this.getPluginVersion();
            _builder_1.append(_pluginVersion"");
            it.add("xtextTooling"_builder_1);
            it.add("xtextTooling""com.google.inject:guice:4.0-beta4");
          }
        };
        ObjectExtensions.<DependencyHandler>operator_doubleArrow(_dependencies_function);
        Convention _convention = project.getConvention();
        final JavaPluginConvention java = _convention.<JavaPluginConvention>findPlugin(JavaPluginConvention.class);
        boolean _notEquals = (!Objects.equal(javanull));
        if (_notEquals) {
          SourceSetContainer _sourceSets = java.getSourceSets();
          final Procedure1<SourceSet> _function_1 = new Procedure1<SourceSet>() {
            public void apply(final SourceSet sourceSet) {
              SourceDirectorySet _java = sourceSet.getJava();
              final Set<FilesourceDirs = _java.getSrcDirs();
              NamedDomainObjectContainer<Language_languages = xtext.getLanguages();
              final Function1<LanguageIterable<File>> _function = new Function1<LanguageIterable<File>>() {
                public Iterable<Fileapply(final Language it) {
                  NamedDomainObjectContainer<OutputConfiguration_outputs = it.getOutputs();
                  final Function1<OutputConfigurationFile_function = new Function1<OutputConfigurationFile>() {
                    public File apply(final OutputConfiguration it) {
                      Object _dir = it.getDir();
                      return project.file(_dir);
                    }
                  };
                  return IterableExtensions.<OutputConfigurationFile>map(_outputs_function);
                }
              };
              Iterable<Iterable<File>> _map = IterableExtensions.<LanguageIterable<File>>map(_languages_function);
              final Iterable<FilextextOutputDirs = Iterables.<File>concat(_map);
              CollectionExtensions.<File>removeAll(sourceDirsxtextOutputDirs);
              SourceDirectorySet _sources = xtext.getSources();
              Object[] _array = sourceDirs.toArray();
              _sources.srcDirs(_array);
            }
          };
          IterableExtensions.<SourceSet>forEach(_sourceSets_function_1);
          ConfigurationContainer _configurations = project.getConfigurations();
          Configuration _at = _configurations.getAt(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME);
          xtextDependencies.extendsFrom(_at);
          NamedDomainObjectContainer<Language_languages = xtext.getLanguages();
          final Procedure1<Language_function_2 = new Procedure1<Language>() {
            public void apply(final Language language) {
              NamedDomainObjectContainer<OutputConfiguration_outputs = language.getOutputs();
              final Procedure1<OutputConfiguration_function = new Procedure1<OutputConfiguration>() {
                public void apply(final OutputConfiguration output) {
                  SourceSet _javaSourceSet = output.getJavaSourceSet();
                  boolean _tripleNotEquals = (_javaSourceSet != null);
                  if (_tripleNotEquals) {
                    DependencyHandler _dependencies = project.getDependencies();
                    StringConcatenation _builder = new StringConcatenation();
                    _builder.append("org.eclipse.xtext:org.eclipse.xtext.xbase.lib:");
                    String _version = xtext.getVersion();
                    _builder.append(_version"");
                    _dependencies.add("compile"_builder);
                    SourceSet _javaSourceSet_1 = output.getJavaSourceSet();
                    SourceDirectorySet _java = _javaSourceSet_1.getJava();
                    Object _dir = output.getDir();
                    _java.srcDir(_dir);
                  }
                }
              };
              IterableExtensions.<OutputConfiguration>forEach(_outputs_function);
            }
          };
          IterableExtensions.<Language>forEach(_languages_function_2);
          TaskContainer _tasks = project.getTasks();
          Task _at_1 = _tasks.getAt(JavaPlugin.COMPILE_JAVA_TASK_NAME);
          _at_1.dependsOn(generatorTask);
        }
        generatorTask.configure(xtext);
        generatorTask.setXtextClasspath(xtextTooling);
        generatorTask.setClasspath(xtextDependencies);
        TaskContainer _tasks_1 = project.getTasks();
        Task _at_2 = _tasks_1.getAt(BasePlugin.ASSEMBLE_TASK_NAME);
        _at_2.dependsOn(generatorTask);
      }
    };
    project.afterEvaluate(_function);
  }
New to GrepCode? Check out our FAQ X