Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.xtext.gradle;
 
 import  groovy.lang.Closure;
 import java.util.Map;
import  org.gradle.api.Project;
import  org.gradle.api.Task;
import  org.gradle.api.artifacts.Dependency;
import  org.gradle.api.artifacts.ExternalModuleDependency;
import  org.gradle.api.artifacts.dsl.DependencyHandler;
import  org.gradle.api.file.CopySpec;
import  org.gradle.api.internal.ConventionMapping;
import  org.gradle.api.internal.IConventionAware;
import  org.gradle.api.tasks.WorkResult;
import  org.gradle.process.ExecResult;
import  org.gradle.process.JavaExecSpec;
public class GradleExtensions {
  public static void conventionMapping(final Task taskfinal Map<String, ? extends Function0<?>> mappings) {
    final Procedure2<StringFunction0<?>> _function = new Procedure2<StringFunction0<?>>() {
      @Override
      public void apply(final String keyfinal Function0<?> value) {
        ConventionMapping _conventionMapping = GradleExtensions.conventionMapping(task);
        _conventionMapping.map(keynew Callable<Object>() {
            public Object call() {
              return value.apply();
            }
        });
      }
    };
    MapExtensions.forEach(mappings_function);
  }
  
  public static ConventionMapping conventionMapping(final Task task) {
    return ((IConventionAware) task).getConventionMapping();
  }
  
  public static Dependency externalModule(final DependencyHandler dependencyHandlerfinal String coordinatesfinal Procedure1<ExternalModuleDependency> config) {
    Dependency _xblockexpression = null;
    {
      final Dependency dependency = dependencyHandler.create(coordinates);
      config.apply(((ExternalModuleDependency) dependency));
      _xblockexpression = dependency;
    }
    return _xblockexpression;
  }
  
  public static WorkResult copy(final Project projectfinal Procedure1<CopySpec> copySpec) {
    Closure<Void_groovyClosure = GradleExtensions.<CopySpec>toGroovyClosure(copySpec);
    return project.copy(_groovyClosure);
  }
  
  public static ExecResult javaexec(final Project projectfinal Procedure1<JavaExecSpec> execSpec) {
    Closure<Void_groovyClosure = GradleExtensions.<JavaExecSpec>toGroovyClosure(execSpec);
    return project.javaexec(_groovyClosure);
  }
  
  public static <T extends Object> Closure<T> toGroovyClosure(final Function0<T> function) {
    return new Closure<T>(null) {
      @Override
      public T call() {
        return function.apply();
      }
    };
  }
  
  public static <T extends Object> Closure<VoidtoGroovyClosure(final Procedure1<T> function) {
    return new Closure<Void>(null) {
      @Override
      public int getMaximumNumberOfParameters() {
        return 1;
      }
      
      @Override
      public Void call(final Object arg) {
        Object _xblockexpression = null;
        {
          function.apply(((T) arg));
          _xblockexpression = null;
        }
        return ((Void)_xblockexpression);
      }
    };
  }
New to GrepCode? Check out our FAQ X