All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xtext.gradle.tasks.internal.DefaultXtextSourceDirectorySet Maven / Gradle / Ivy

There is a newer version: 2.0.9-alpha.3
Show newest version
package org.xtext.gradle.tasks.internal;

import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import groovy.lang.Closure;
import java.io.File;
import java.util.List;
import java.util.Set;
import org.eclipse.xtend.lib.annotations.Accessors;
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.Pure;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.FileTreeElement;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.util.PatternFilterable;
import org.gradle.api.tasks.util.PatternSet;
import org.gradle.util.ConfigureUtil;
import org.xtext.gradle.tasks.XtextExtension;
import org.xtext.gradle.tasks.XtextSourceDirectorySet;
import org.xtext.gradle.tasks.XtextSourceSetOutputs;
import org.xtext.gradle.tasks.internal.DefaultXtextSourceSetOutputs;

@SuppressWarnings("all")
public class DefaultXtextSourceDirectorySet implements XtextSourceDirectorySet {
  @Accessors
  private final String name;
  
  @Accessors
  private final XtextSourceSetOutputs output;
  
  @Accessors
  private final PatternSet filter = new PatternSet();
  
  private Project project;
  
  private List source = CollectionLiterals.newArrayList();
  
  public DefaultXtextSourceDirectorySet(final String name, final Project project, final XtextExtension xtext) {
    this.name = name;
    this.project = project;
    DefaultXtextSourceSetOutputs _defaultXtextSourceSetOutputs = new DefaultXtextSourceSetOutputs(project, xtext);
    this.output = _defaultXtextSourceSetOutputs;
  }
  
  @Override
  public XtextSourceDirectorySet srcDir(final Object srcDir) {
    this.source.add(srcDir);
    return this;
  }
  
  @Override
  public XtextSourceDirectorySet srcDirs(final Object... srcDirs) {
    this.source.add(srcDirs);
    return this;
  }
  
  @Override
  public XtextSourceDirectorySet setSrcDirs(final Iterable srcDirs) {
    this.source.clear();
    Iterables.addAll(this.source, srcDirs);
    return this;
  }
  
  @Override
  public FileTree getFiles() {
    Set _srcDirs = this.getSrcDirs();
    ConfigurableFileCollection _files = this.project.files(_srcDirs);
    FileTree _asFileTree = _files.getAsFileTree();
    return _asFileTree.matching(this.filter);
  }
  
  @Override
  public Set getSrcDirs() {
    ConfigurableFileCollection _files = this.project.files(this.source);
    Set _files_1 = _files.getFiles();
    final Function1 _function = new Function1() {
      @Override
      public Boolean apply(final File it) {
        FileCollection _dirs = DefaultXtextSourceDirectorySet.this.output.getDirs();
        boolean _contains = _dirs.contains(it);
        return Boolean.valueOf((!_contains));
      }
    };
    Iterable _filter = IterableExtensions.filter(_files_1, _function);
    return IterableExtensions.toSet(_filter);
  }
  
  @Override
  public PatternFilterable getFilter() {
    return this.filter;
  }
  
  @Override
  public Set getIncludes() {
    return this.filter.getIncludes();
  }
  
  @Override
  public Set getExcludes() {
    return this.filter.getExcludes();
  }
  
  @Override
  public PatternFilterable setIncludes(final Iterable includes) {
    this.filter.setIncludes(includes);
    return this;
  }
  
  @Override
  public PatternFilterable setExcludes(final Iterable excludes) {
    this.filter.setExcludes(excludes);
    return this;
  }
  
  @Override
  public PatternFilterable include(final String... includes) {
    this.filter.include(includes);
    return this;
  }
  
  @Override
  public PatternFilterable include(final Iterable includes) {
    this.filter.include(includes);
    return this;
  }
  
  @Override
  public PatternFilterable include(final Spec includeSpec) {
    this.filter.include(includeSpec);
    return this;
  }
  
  @Override
  public PatternFilterable include(final Closure includeSpec) {
    this.filter.include(includeSpec);
    return this;
  }
  
  @Override
  public PatternFilterable exclude(final Iterable excludes) {
    this.filter.exclude(excludes);
    return this;
  }
  
  @Override
  public PatternFilterable exclude(final String... excludes) {
    this.filter.exclude(excludes);
    return this;
  }
  
  @Override
  public PatternFilterable exclude(final Spec excludeSpec) {
    this.filter.exclude(excludeSpec);
    return this;
  }
  
  @Override
  public PatternFilterable exclude(final Closure excludeSpec) {
    this.filter.exclude(excludeSpec);
    return this;
  }
  
  @Override
  public void output(final Closure configureAction) {
    ConfigureUtil.configure(configureAction, this.output);
  }
  
  @Override
  public String getGeneratorTaskName() {
    String _xifexpression = null;
    boolean _equals = Objects.equal(this.name, "main");
    if (_equals) {
      _xifexpression = "generateXtext";
    } else {
      String _firstUpper = StringExtensions.toFirstUpper(this.name);
      String _plus = ("generate" + _firstUpper);
      _xifexpression = (_plus + "Xtext");
    }
    return _xifexpression;
  }
  
  @Override
  public String toString() {
    return this.source.toString();
  }
  
  @Pure
  public String getName() {
    return this.name;
  }
  
  @Pure
  public XtextSourceSetOutputs getOutput() {
    return this.output;
  }
}