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

com.stanfy.helium.gradle.SourceGenDslDelegate.groovy Maven / Gradle / Ivy

package com.stanfy.helium.gradle

import com.stanfy.helium.handler.codegen.java.constants.ConstantsGeneratorOptions
import com.stanfy.helium.handler.codegen.java.retrofit.RetrofitGeneratorOptions
import com.stanfy.helium.utils.DslUtils
import groovy.transform.PackageScope

import com.stanfy.helium.handler.codegen.java.entity.EntitiesGeneratorOptions

/**
 * Delegate for DSL
 * 
 *   sourceGen {
 *     entities {
 *     }
 *     constants {
 *     }
 *   }
 * 
 */
class SourceGenDslDelegate {

  public static final String DEFAULT_PACKAGE = "api"

  private EntitiesDslDelegate entities
  private ConstantsDslDelegate constants
  private RetrofitDslDelegate retrofit

  private final Object owner

  public SourceGenDslDelegate(final Object owner) {
    this.owner = owner
  }

  @PackageScope
  EntitiesDslDelegate getEntities() {
    return entities
  }

  @PackageScope
  ConstantsDslDelegate getConstants() {
    return constants
  }

  @PackageScope
  RetrofitDslDelegate getRetrofit() {
    return retrofit
  }

  @PackageScope
  void setEntities(EntitiesDslDelegate value) {
    this.entities = value
  }

  @PackageScope
  void setConstants(ConstantsDslDelegate value) {
    this.constants = value
  }

  @PackageScope
  void setRetrofit(RetrofitDslDelegate value) {
    this.retrofit = value
  }

  void entities(Closure config) {
    entities = new EntitiesDslDelegate()
    DslUtils.runWithProxy(entities, config)
  }

  void constants(Closure config) {
    constants = new ConstantsDslDelegate()
    DslUtils.runWithProxy(constants, config)
  }

  void retrofit(Closure config) {
    retrofit = new RetrofitDslDelegate()
    DslUtils.runWithProxy(retrofit, config)
  }

  abstract class BaseDslDelegate {

    T genOptions

    File output

    void output(File output) {
      this.output = output;
    }

    void options(Closure config) {
      DslUtils.runWithProxy(genOptions, config)
    }

  }

  class EntitiesDslDelegate extends BaseDslDelegate {

    EntitiesDslDelegate() {
      genOptions = EntitiesGeneratorOptions.defaultOptions(DEFAULT_PACKAGE)
    }

  }

  class ConstantsDslDelegate extends BaseDslDelegate {

    ConstantsDslDelegate() {
      genOptions = ConstantsGeneratorOptions.defaultOptions(DEFAULT_PACKAGE)
    }

  }

  class RetrofitDslDelegate extends BaseDslDelegate {

    RetrofitDslDelegate() {
      genOptions = RetrofitGeneratorOptions.defaultOptions(DEFAULT_PACKAGE)
    }

  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy