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

org.xtend.gradle.XtendAndroidPlugin Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
package org.xtend.gradle;

import com.android.build.gradle.AppExtension;
import com.android.build.gradle.BaseExtension;
import com.android.build.gradle.LibraryExtension;
import com.android.build.gradle.api.BaseVariant;
import com.android.build.gradle.api.BaseVariantOutput;
import com.android.build.gradle.api.LibraryVariant;
import com.android.build.gradle.tasks.AidlCompile;
import com.android.build.gradle.tasks.GenerateBuildConfig;
import com.android.build.gradle.tasks.ProcessAndroidResources;
import com.android.build.gradle.tasks.RenderscriptCompile;
import com.android.builder.model.SourceProvider;
import com.google.common.collect.Iterables;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
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.ListExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.eclipse.xtext.xbase.lib.StringExtensions;
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.file.ConfigurableFileCollection;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.internal.DefaultDomainObjectSet;
import org.gradle.api.internal.file.FileResolver;
import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.plugins.PluginContainer;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.compile.JavaCompile;
import org.xtend.gradle.GradleExtensions;
import org.xtend.gradle.XtendBasePlugin;
import org.xtend.gradle.tasks.DefaultXtendSourceSet;
import org.xtend.gradle.tasks.XtendCompile;
import org.xtend.gradle.tasks.XtendCompileOptions;
import org.xtend.gradle.tasks.XtendRuntime;

@SuppressWarnings("all")
public class XtendAndroidPlugin implements Plugin {
  private FileResolver fileResolver;
  
  @Inject
  public XtendAndroidPlugin(final FileResolver fileResolver) {
    this.fileResolver = fileResolver;
  }
  
  public void apply(final Project project) {
    PluginContainer _plugins = project.getPlugins();
    _plugins.apply(XtendBasePlugin.class);
    ExtensionContainer _extensions = project.getExtensions();
    final XtendRuntime xtend = _extensions.getByType(XtendRuntime.class);
    final Action _function = new Action() {
      public void execute(final Project it) {
        ExtensionContainer _extensions = project.getExtensions();
        Object _byName = _extensions.getByName("android");
        final BaseExtension android = ((BaseExtension) _byName);
        DefaultDomainObjectSet _xifexpression = null;
        if ((android instanceof AppExtension)) {
          _xifexpression = ((AppExtension)android).getApplicationVariants();
        } else {
          DefaultDomainObjectSet _xifexpression_1 = null;
          if ((android instanceof LibraryExtension)) {
            _xifexpression_1 = ((LibraryExtension)android).getLibraryVariants();
          } else {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("Unknown packaging type ");
            Class _class = android.getClass();
            String _simpleName = _class.getSimpleName();
            _builder.append(_simpleName, "");
            throw new GradleException(_builder.toString());
          }
          _xifexpression = _xifexpression_1;
        }
        final DefaultDomainObjectSet variants = _xifexpression;
        final Action _function = new Action() {
          public void execute(final BaseVariant variant) {
            JavaCompile _javaCompile = variant.getJavaCompile();
            JavaCompile _javaCompile_1 = variant.getJavaCompile();
            FileCollection _classpath = _javaCompile_1.getClasspath();
            ConfigurationContainer _configurations = project.getConfigurations();
            Configuration _at = _configurations.getAt("xtendCompileOnly");
            FileCollection _plus = GradleExtensions.operator_plus(_classpath, _at);
            _javaCompile.setClasspath(_plus);
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("compile");
            String _name = variant.getName();
            String _firstUpper = StringExtensions.toFirstUpper(_name);
            _builder.append(_firstUpper, "");
            _builder.append("Xtend");
            final String compileTaskName = _builder.toString();
            final DefaultXtendSourceSet xtendSources = new DefaultXtendSourceSet(XtendAndroidPlugin.this.fileResolver);
            final ArrayList sourceDirs = CollectionLiterals.newArrayList();
            List _sourceSets = variant.getSourceSets();
            final Function1> _function = new Function1>() {
              public Collection apply(final SourceProvider it) {
                return it.getJavaDirectories();
              }
            };
            List> _map = ListExtensions.>map(_sourceSets, _function);
            Iterable _flatten = Iterables.concat(_map);
            final Function1 _function_1 = new Function1() {
              public Boolean apply(final File it) {
                return Boolean.valueOf(it.isDirectory());
              }
            };
            final Iterable javaDirs = IterableExtensions.filter(_flatten, _function_1);
            Iterables.addAll(sourceDirs, javaDirs);
            AidlCompile _aidlCompile = variant.getAidlCompile();
            File _sourceOutputDir = _aidlCompile.getSourceOutputDir();
            GenerateBuildConfig _generateBuildConfig = variant.getGenerateBuildConfig();
            File _sourceOutputDir_1 = _generateBuildConfig.getSourceOutputDir();
            RenderscriptCompile _renderscriptCompile = variant.getRenderscriptCompile();
            File _sourceOutputDir_2 = _renderscriptCompile.getSourceOutputDir();
            Iterables.addAll(sourceDirs, Collections.unmodifiableList(CollectionLiterals.newArrayList(_sourceOutputDir, _sourceOutputDir_1, _sourceOutputDir_2)));
            List _outputs = variant.getOutputs();
            final Function1 _function_2 = new Function1() {
              public File apply(final BaseVariantOutput it) {
                ProcessAndroidResources _processResources = it.getProcessResources();
                return _processResources.getSourceOutputDir();
              }
            };
            List _map_1 = ListExtensions.map(_outputs, _function_2);
            Iterables.addAll(sourceDirs, _map_1);
            SourceDirectorySet _xtend = xtendSources.getXtend();
            _xtend.setSrcDirs(sourceDirs);
            StringConcatenation _builder_1 = new StringConcatenation();
            File _buildDir = project.getBuildDir();
            _builder_1.append(_buildDir, "");
            _builder_1.append("/generated/source/xtend/");
            String _name_1 = variant.getName();
            _builder_1.append(_name_1, "");
            xtendSources.setXtendOutputDir(_builder_1);
            TaskContainer _tasks = project.getTasks();
            final XtendCompile xtendCompile = _tasks.create(compileTaskName, XtendCompile.class);
            SourceDirectorySet _xtend_1 = xtendSources.getXtend();
            xtendCompile.setSrcDirs(_xtend_1);
            JavaCompile _javaCompile_2 = variant.getJavaCompile();
            FileCollection _classpath_1 = _javaCompile_2.getClasspath();
            xtendCompile.setClasspath(_classpath_1);
            File _xtendOutputDir = xtendSources.getXtendOutputDir();
            xtendCompile.setDestinationDir(_xtendOutputDir);
            List _bootClasspath = android.getBootClasspath();
            String _join = IterableExtensions.join(_bootClasspath, File.pathSeparator);
            xtendCompile.setBootClasspath(_join);
            FileCollection _classpath_2 = xtendCompile.getClasspath();
            List _bootClasspath_1 = android.getBootClasspath();
            ConfigurableFileCollection _files = project.files(_bootClasspath_1);
            FileCollection _plus_1 = GradleExtensions.operator_plus(_classpath_2, _files);
            xtendCompile.setClasspath(_plus_1);
            JavaCompile _javaCompile_3 = variant.getJavaCompile();
            File _destinationDir = _javaCompile_3.getDestinationDir();
            xtendCompile.setClassesDir(_destinationDir);
            XtendCompileOptions _options = xtendCompile.getOptions();
            _options.setXtendAsPrimaryDebugSource(true);
            JavaCompile _javaCompile_4 = variant.getJavaCompile();
            String _sourceCompatibility = _javaCompile_4.getSourceCompatibility();
            xtendCompile.setSourceCompatibility(_sourceCompatibility);
            final Procedure1 _function_3 = new Procedure1() {
              public void apply(final XtendCompile it) {
                FileCollection _classpath = it.getClasspath();
                FileCollection _inferXtendClasspath = xtend.inferXtendClasspath(_classpath);
                it.setXtendClasspath(_inferXtendClasspath);
              }
            };
            GradleExtensions.beforeExecute(xtendCompile, _function_3);
            StringConcatenation _builder_2 = new StringConcatenation();
            _builder_2.append("Compiles the ");
            String _name_2 = variant.getName();
            _builder_2.append(_name_2, "");
            _builder_2.append(" Xtend sources");
            xtendCompile.setDescription(_builder_2.toString());
            File _destinationDir_1 = xtendCompile.getDestinationDir();
            variant.registerJavaGeneratingTask(xtendCompile, _destinationDir_1);
            AidlCompile _aidlCompile_1 = variant.getAidlCompile();
            RenderscriptCompile _renderscriptCompile_1 = variant.getRenderscriptCompile();
            GenerateBuildConfig _generateBuildConfig_1 = variant.getGenerateBuildConfig();
            xtendCompile.dependsOn(_aidlCompile_1, _renderscriptCompile_1, _generateBuildConfig_1);
            List _outputs_1 = variant.getOutputs();
            final Function1 _function_4 = new Function1() {
              public ProcessAndroidResources apply(final BaseVariantOutput it) {
                return it.getProcessResources();
              }
            };
            List _map_2 = ListExtensions.map(_outputs_1, _function_4);
            xtendCompile.dependsOn(_map_2);
            JavaCompile _javaCompile_5 = variant.getJavaCompile();
            final Action _function_5 = new Action() {
              public void execute(final Task it) {
                xtendCompile.enhance();
              }
            };
            _javaCompile_5.doLast(_function_5);
          }
        };
        variants.all(_function);
      }
    };
    project.afterEvaluate(_function);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy