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

com.apollographql.android.gradle.ApolloClassGenTask Maven / Gradle / Ivy

There is a newer version: 0.2.2
Show newest version
package com.apollographql.android.gradle;

import com.google.common.base.Joiner;

import com.apollographql.android.compiler.GraphQLCompiler;

import org.gradle.api.Action;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.SourceTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.incremental.IncrementalTaskInputs;
import org.gradle.api.tasks.incremental.InputFileDetails;

import java.io.File;
import java.util.List;
import java.util.Map;

public class ApolloClassGenTask extends SourceTask {
  static final String NAME = "generate%sApolloClasses";

  @Internal private List config;
  @Internal private String variant;
  @Internal private boolean generateClasses;
  @Internal private Map customTypeMapping;
  @OutputDirectory private File outputDir;

  public void init(String buildVariant, List extensionsConfig, boolean genClasses,
      Map typeMapping) {
    variant = buildVariant;
    generateClasses = genClasses;
    customTypeMapping = typeMapping;
    config = extensionsConfig;
    // TODO: change to constant once ApolloPlugin is in java
    setGroup("apollo");
    setDescription("Generate Android classes for " + Utils.capitalize(variant) + " GraphQL queries");
    dependsOn(getProject().getTasks().findByName(String.format(ApolloIRGenTask.NAME, Utils.capitalize(variant))));
    outputDir = new File(getProject().getBuildDir() + "/" + Joiner.on(File.separator).join(GraphQLCompiler.Companion
        .getOUTPUT_DIRECTORY()));
  }

  @TaskAction
  void generateClasses(IncrementalTaskInputs inputs) {
    inputs.outOfDate(new Action() {
      @Override
      public void execute(InputFileDetails inputFileDetails) {
        new GraphQLCompiler().write(inputFileDetails.getFile(), outputDir, generateClasses, customTypeMapping);
      }
    });
  }

  public List getConfig() {
    return config;
  }

  public void setConfig(List config) {
    this.config = config;
  }

  public String getVariant() {
    return variant;
  }

  public void setVariant(String variant) {
    this.variant = variant;
  }

  public boolean isGenerateClasses() {
    return generateClasses;
  }

  public void setGenerateClasses(boolean generateClasses) {
    this.generateClasses = generateClasses;
  }

  public File getOutputDir() {
    return outputDir;
  }

  public void setOutputDir(File outputDir) {
    this.outputDir = outputDir;
  }

  public Map getCustomTypeMapping() {
    return customTypeMapping;
  }

  public void setCustomTypeMapping(Map customTypeMapping) {
    this.customTypeMapping = customTypeMapping;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy