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

wtf.emulator.EwExtension Maven / Gradle / Ivy

Go to download

With this Gradle plugin you can run your Android instrumentation tests with emulator.wtf

The newest version!
package wtf.emulator;

import org.gradle.api.Action;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;

import javax.inject.Inject;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import static java.util.function.Function.identity;

public abstract class EwExtension implements EwInvokeConfiguration {
  private final Property variantCount;

  public abstract Property getRepositoryCheckEnabled();

  public abstract Property getVersion();

  public abstract Property getToken();

  public abstract DirectoryProperty getBaseOutputDir();

  public abstract ListProperty> getDevices();

  public abstract MapProperty getEnvironmentVariables();

  private Action filter = null;

  @Inject
  public EwExtension(ObjectFactory objectFactory) {
    getVersion().convention("0.11.1");
    getSideEffects().convention(false);
    getOutputs().convention(Collections.emptyList());

    // discover proxy settings from System properties
    sysPropConvention(getProxyHost(), "https.proxyHost", "http.proxyHost");
    sysPropConvention(getProxyPort(), Arrays.asList("https.proxyPort", "http.proxyPort"), Integer::parseInt);
    sysPropConvention(getProxyUser(), "https.proxyUser", "http.proxyUser");
    sysPropConvention(getProxyPassword(), "https.proxyPassword", "http.proxyPassword");

    this.variantCount = objectFactory.property(Integer.class).convention(0);
  }

  @SuppressWarnings("unused")
  public void variantFilter(Action filter) {
    this.filter = filter;
  }

  protected Action getFilter() {
    return this.filter;
  }

  protected Property getVariantCount() {
    return this.variantCount;
  }

  private static void sysPropConvention(Property extProp, String... keys) {
    sysPropConvention(extProp, Arrays.asList(keys), identity());
  }

  private static  void sysPropConvention(Property extProp, List keys, Function transform) {
    for (String key : keys) {
      String sysPropValue = System.getProperty(key);
      if (sysPropValue != null && !sysPropValue.isBlank()) {
        try {
          T transformed = transform.apply(sysPropValue);
          if (transformed != null) {
            extProp.convention(transformed);
            return;
          }
        }
        catch (Exception e) {
          // ignore transform failures, e.g. failing to parse an int
        }
      }
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy