Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.xtext.gradle.tasks;
 
 import java.io.File;
 import java.net.URI;
import  org.gradle.api.DefaultTask;
import  org.gradle.api.NamedDomainObjectContainer;
import  org.gradle.api.Project;
import  org.gradle.api.tasks.TaskAction;
public class XtextEclipseSettings extends DefaultTask {
  private XtextExtension xtext;
  
  public XtextExtension configure(final XtextExtension xtext) {
    return this. = xtext;
  }
  
  @TaskAction
  public void writeSettings() {
    NamedDomainObjectContainer<Language_languages = this..getLanguages();
    final Procedure1<Language_function = new Procedure1<Language>() {
      public void apply(final Language language) {
        try {
          Project _project = XtextEclipseSettings.this.getProject();
          String _name = language.getName();
          final XtextEclipsePreferences prefs = new XtextEclipsePreferences(_project_name);
          prefs.load();
          prefs.putBoolean("is_project_specific"true);
          NamedDomainObjectContainer<OutputConfiguration_outputs = language.getOutputs();
          final Procedure1<OutputConfiguration_function = new Procedure1<OutputConfiguration>() {
            public void apply(final OutputConfiguration output) {
              String _key = XtextEclipseSettings.this.getKey(output"directory");
              Project _project = XtextEclipseSettings.this.getProject();
              Object _dir = output.getDir();
              File _file = _project.file(_dir);
              String _projectRelativePath = XtextEclipseSettings.this.projectRelativePath(_file);
              prefs.put(_key_projectRelativePath);
            }
          };
          IterableExtensions.<OutputConfiguration>forEach(_outputs_function);
          prefs.save();
        } catch (Throwable _e) {
          throw Exceptions.sneakyThrow(_e);
        }
      }
    };
    IterableExtensions.<Language>forEach(_languages_function);
  }
  
  public String getKey(final OutputConfiguration outputfinal String preferenceName) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("outlet.");
    String _name = output.getName();
    _builder.append(_name"");
    _builder.append(".");
    _builder.append(preferenceName"");
    return _builder.toString();
  }
  
  private String projectRelativePath(final File file) {
    Project _project = this.getProject();
    File _projectDir = _project.getProjectDir();
    URI _uRI = _projectDir.toURI();
    URI _uRI_1 = file.toURI();
    URI _relativize = _uRI.relativize(_uRI_1);
    String _path = _relativize.getPath();
    return this.trimTrailingSeparator(_path);
  }
  
  private String trimTrailingSeparator(final String path) {
    CharMatcher _anyOf = CharMatcher.anyOf("/\\");
    return _anyOf.trimTrailingFrom(path);
  }
New to GrepCode? Check out our FAQ X