Config.java revision 81a928816f4cf068ff3fe636df2a25db269c73c8
1cfb3d242306311ce27ec51bf511764377c173a7cKiran Ryali + Christian Williamspackage org.robolectric.annotation;
2dd40f718cf785a56e63c0685feeb73d266c13e3fWenhui Yao
39cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrishimport android.app.Application;
4f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williamsimport org.jetbrains.annotations.NotNull;
5f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams
6f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williamsimport java.lang.annotation.Annotation;
7f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williamsimport java.lang.annotation.Documented;
8f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williamsimport java.lang.annotation.ElementType;
9f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williamsimport java.lang.annotation.Retention;
10f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williamsimport java.lang.annotation.RetentionPolicy;
11f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williamsimport java.lang.annotation.Target;
12f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williamsimport java.util.Arrays;
13c77f5791f081893a18f9db753bb5022269a7c5a6Simon Arlottimport java.util.HashSet;
1423a26cc3e5b33c0503a99847292ac99817f5af43Christian Williamsimport java.util.Properties;
15c77f5791f081893a18f9db753bb5022269a7c5a6Simon Arlottimport java.util.Set;
16f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams
17dd40f718cf785a56e63c0685feeb73d266c13e3fWenhui Yao/**
18c7482da584ddaa03f91afa7b785ed17fa084aa47Erich Douglass * Configuration settings that can be used on a per-class or per-test basis.
19dd40f718cf785a56e63c0685feeb73d266c13e3fWenhui Yao */
20f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams@Documented
21f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams@Retention(RetentionPolicy.RUNTIME)
22f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams@Target({ElementType.TYPE, ElementType.METHOD})
237be4d2ba0e45483ad70cbd994955ae1b70afafdcKiran Ryali + Christian Williamspublic @interface Config {
240bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass  String NONE = "--none";
250bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass  String DEFAULT = "--default";
260bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass  String DEFAULT_RES_FOLDER = "res";
270bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass  String DEFAULT_ASSET_FOLDER = "assets";
2829a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
2929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  /**
30074a38a2ee8dd8cb1904853aebf2f30146d563a2Mike Grafton   * The Android SDK level to emulate. If not specified, Robolectric defaults to API 16.
318c45d4a57fa380436885166f8e89b3e20d20290cErich Douglass   * This value will also be set as Build.VERSION.SDK_INT.
3283bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   *
3383bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   * @return The Android SDK level to emulate.
3429a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   */
3581a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish  int[] sdk() default {};
3629a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
3729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  /**
3829a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   * The Android manifest file to load; Robolectric will look relative to the current directory.
3929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   * Resources and assets will be loaded relative to the manifest.
4029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   *
4129a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   * If not specified, Robolectric defaults to {@code AndroidManifest.xml}.
4229a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   *
4329a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   * If your project has no manifest or resources, use {@link Config#NONE}.
4483bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   *
4583bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   * @return The Android manifest file to load.
4629a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   */
4729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  String manifest() default DEFAULT;
4829a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
4929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  /**
500bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass   * Reference to the BuildConfig class created by the Gradle build system.
510bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass   *
520bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass   * @return Reference to BuildConfig class.
530bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass   */
540bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass  Class<?> constants() default Void.class;
550bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass
560bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass  /**
579cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish   * The {@link android.app.Application} class to use in the test, this takes precedence over any application
589cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish   * specified in the AndroidManifest.xml.
5983bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   *
6083bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   * @return The {@link android.app.Application} class to use in the test.
619cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish   */
629cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish  Class<? extends Application> application() default Application.class;
639cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish
649cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish  /**
65bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   * Java package name where the "R.class" file is located. This only needs to be specified if you define
66bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   * an {@code applicationId} associated with {@code productFlavors} or specify {@code applicationIdSuffix}
67bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   * in your build.gradle.
68bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   *
69bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   * <p>If not specified, Robolectric defaults to the {@code applicationId}.</p>
70bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   *
71bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   * @return The java package name for R.class.
72bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   */
73bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass  String packageName() default "";
74bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass
75bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass  /**
7629a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   * Qualifiers for the resource resolution, such as "fr-normal-port-hdpi".
7729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   *
7883bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   * @return Qualifiers used for resource resolution.
7929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   */
8029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  String qualifiers() default "";
8129a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
8229a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  /**
836b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass   * The directory from which to load resources.  This should be relative to the directory containing AndroidManifest.xml.
8483bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   *
85bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   * <p>If not specified, Robolectric defaults to {@code res}.</p>
8683bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   *
8783bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   * @return Android resource directory.
885277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John   */
896b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass  String resourceDir() default DEFAULT_RES_FOLDER;
906b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass
916b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass  /**
926b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass   * The directory from which to load assets. This should be relative to the directory containing AndroidManifest.xml.
9383bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   *
94bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass   * <p>If not specified, Robolectric defaults to {@code assets}.</p>
9583bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   *
9683bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   * @return Android asset directory.
976b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass   */
986b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass  String assetDir() default DEFAULT_ASSET_FOLDER;
995277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John
1005277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John  /**
10129a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   * A list of shadow classes to enable, in addition to those that are already present.
10283bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   *
10383bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   * @return A list of additional shadow classes to enable.
10429a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams   */
10529a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  Class<?>[] shadows() default {};
10629a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
107ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson  /**
108ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson   * A list of folders containing Android Libraries on which this project depends.
10983bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   *
11083bcaf5aa4b64a2223cfada134ef02e5c8ff660aErich Douglass   * @return A list of Android Libraries.
111ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson   */
112ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson  String[] libraries() default {};
113ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson
1140bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass  class Implementation implements Config {
11581a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish    private final int[] sdk;
11629a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    private final String manifest;
11729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    private final String qualifiers;
1185277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John    private final String resourceDir;
1196b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    private final String assetDir;
120bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass    private final String packageName;
1210bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass    private final Class<?> constants;
12229a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    private final Class<?>[] shadows;
1239cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish    private final Class<? extends Application> application;
124ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson    private final String[] libraries;
12529a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams
1260bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass    public static Config fromProperties(Properties properties) {
1270bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      if (properties == null || properties.size() == 0) return null;
12829a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      return new Implementation(
12981a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish          parseIntArrayProperty(properties.getProperty("sdk", "")),
1300bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass          properties.getProperty("manifest", DEFAULT),
1310bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass          properties.getProperty("qualifiers", ""),
132bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass          properties.getProperty("packageName", ""),
1330bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass          properties.getProperty("resourceDir", Config.DEFAULT_RES_FOLDER),
1340bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass          properties.getProperty("assetDir", Config.DEFAULT_ASSET_FOLDER),
1350bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass          parseClasses(properties.getProperty("shadows", "")),
1360bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass          parseApplication(properties.getProperty("application", "android.app.Application")),
13781a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish          parseStringArrayProperty(properties.getProperty("libraries", "")),
1380bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass          parseClass(properties.getProperty("constants", ""))
13929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      );
14029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
14123a26cc3e5b33c0503a99847292ac99817f5af43Christian Williams
1420bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass    private static Class<?> parseClass(String className) {
1430bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      if (className.isEmpty()) return null;
1440bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      try {
1450bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass        return Implementation.class.getClassLoader().loadClass(className);
1460bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      } catch (ClassNotFoundException e) {
1470bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass        throw new RuntimeException("Could not load class: " + className);
1480bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      }
1490bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass    }
1500bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass
1510bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass    private static Class<?>[] parseClasses(String input) {
1520bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      if (input.isEmpty()) return new Class[0];
1530bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      final String[] classNames = input.split("[, ]+");
1540bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      final Class[] classes = new Class[classNames.length];
15529a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      for (int i = 0; i < classNames.length; i++) {
1560bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass        classes[i] = parseClass(classNames[i]);
15729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      }
15829a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      return classes;
15929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
16023a26cc3e5b33c0503a99847292ac99817f5af43Christian Williams
1610bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass    @SuppressWarnings("unchecked")
1629cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish    private static <T extends Application> Class<T> parseApplication(String className) {
1630bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      return (Class<T>) parseClass(className);
1649cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish    }
1659cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish
16681a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish    private static String[] parseStringArrayProperty(String property) {
16781a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish      if (property.isEmpty()) return new String[0];
16881a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish      return property.split("[, ]+");
169ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson    }
170ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson
17181a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish    private static int[] parseIntArrayProperty(String property) {
17281a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish      String[] parts = parseStringArrayProperty(property);
17381a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish      int[] result = new int[parts.length];
17481a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish      for (int i = 0; i < parts.length; i++) {
17581a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish        result[i] = Integer.parseInt(parts[i]);
17681a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish      }
17781a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish
17881a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish      return result;
17981a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish    }
18081a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish
18181a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish    public Implementation(int[] sdk, String manifest, String qualifiers, String packageName, String resourceDir, String assetDir, Class<?>[] shadows, Class<? extends Application> application, String[] libraries, Class<?> constants) {
1828c45d4a57fa380436885166f8e89b3e20d20290cErich Douglass      this.sdk = sdk;
18329a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      this.manifest = manifest;
18429a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      this.qualifiers = qualifiers;
185bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass      this.packageName = packageName;
1865277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John      this.resourceDir = resourceDir;
1876b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass      this.assetDir = assetDir;
18829a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      this.shadows = shadows;
1899cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish      this.application = application;
190ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson      this.libraries = libraries;
1910bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      this.constants = constants;
19229a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
193f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams
19428950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom    public Implementation(Config other) {
1958c45d4a57fa380436885166f8e89b3e20d20290cErich Douglass      this.sdk = other.sdk();
19628950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom      this.manifest = other.manifest();
19728950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom      this.qualifiers = other.qualifiers();
198bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass      this.packageName = other.packageName();
19928950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom      this.resourceDir = other.resourceDir();
20028950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom      this.assetDir = other.assetDir();
20128950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom      this.constants = other.constants();
20228950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom      this.shadows = other.shadows();
20328950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom      this.application = other.application();
20428950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom      this.libraries = other.libraries();
20528950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom    }
20628950f540f7c7bf50fbfb8d9bc8cbf7c2d14e1faAlexander Blom
20729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    public Implementation(Config baseConfig, Config overlayConfig) {
20881a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish      this.sdk = pickSdk(baseConfig.sdk(), overlayConfig.sdk(), new int[0]);
20929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      this.manifest = pick(baseConfig.manifest(), overlayConfig.manifest(), DEFAULT);
21029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      this.qualifiers = pick(baseConfig.qualifiers(), overlayConfig.qualifiers(), "");
211bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass      this.packageName = pick(baseConfig.packageName(), overlayConfig.packageName(), "");
2126b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass      this.resourceDir = pick(baseConfig.resourceDir(), overlayConfig.resourceDir(), Config.DEFAULT_RES_FOLDER);
2136b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass      this.assetDir = pick(baseConfig.assetDir(), overlayConfig.assetDir(), Config.DEFAULT_ASSET_FOLDER);
214b3c13990ef697c1f25635529ff485760cb5cf644Jen Mendez      this.constants = pick(baseConfig.constants(), overlayConfig.constants(), Void.class);
215ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson
2160bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      Set<Class<?>> shadows = new HashSet<>();
21729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      shadows.addAll(Arrays.asList(baseConfig.shadows()));
21829a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      shadows.addAll(Arrays.asList(overlayConfig.shadows()));
21929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      this.shadows = shadows.toArray(new Class[shadows.size()]);
220ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson
2219cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish      this.application = pick(baseConfig.application(), overlayConfig.application(), null);
222ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson
2230bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      Set<String> libraries = new HashSet<>();
224ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson      libraries.addAll(Arrays.asList(baseConfig.libraries()));
225ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson      libraries.addAll(Arrays.asList(overlayConfig.libraries()));
226ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson      this.libraries = libraries.toArray(new String[libraries.size()]);
22729a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
228f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams
22929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    private <T> T pick(T baseValue, T overlayValue, T nullValue) {
2300bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      return overlayValue != null ? (overlayValue.equals(nullValue) ? baseValue : overlayValue) : null;
23129a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
232f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams
23381a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish    private int[] pickSdk(int[] baseValue, int[] overlayValue, int[] nullValue) {
23481a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish      return Arrays.equals(overlayValue, nullValue) ? baseValue : overlayValue;
23581a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish    }
23681a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish
2376b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    @Override
23881a928816f4cf068ff3fe636df2a25db269c73c8Jonathan Gerrish    public int[] sdk() {
2398c45d4a57fa380436885166f8e89b3e20d20290cErich Douglass      return sdk;
24029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
241f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams
2426b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    @Override
2436b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    public String manifest() {
24429a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      return manifest;
24529a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
24648f95f3e0955035946f7c416dec56219a9b19886Christian Williams
2479cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish    @Override
2480bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass    public Class<?> constants() {
2490bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass      return constants;
2500bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass    }
2510bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass
2520bbbacc2633146b2725cce97c24dc121ffa0e89bErich Douglass    @Override
2539cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish    public Class<? extends Application> application() {
2549cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish      return application;
2559cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish    }
2569cc9bde8928b83e5de9cd1c521e157e1a584b2fdJonathan Gerrish
2576b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    @Override
2586b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    public String qualifiers() {
25929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      return qualifiers;
26029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
261f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams
2625277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John    @Override
263bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass    public String packageName() {
264bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass      return packageName;
265bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass    }
266bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass
267bbdc3ce45195e6896254a2c7aa24370f2c55d57cErich Douglass    @Override
2685277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John    public String resourceDir() {
2695277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John      return resourceDir;
2705277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John    }
2715277f871bca2be31c657ace35ae305285b2e0c55Ryan Spore and Trevor John
2726b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    @Override
2736b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    public String assetDir() {
2746b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass      return assetDir;
2756b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    }
2766b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass
2776b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    @Override
2786b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    public Class<?>[] shadows() {
27929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      return shadows;
28029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
281f6df8a55ac378dee35324bc865fb4d741dcb4824Christian Williams
2826b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    @Override
2836b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    public String[] libraries() {
284ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson      return libraries;
285ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson    }
286ed898f2b5b7312af4779636638d081aa6ebd9e13Andrew Richardson
2876b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    @NotNull @Override
2886b00d4156e2e6bb2d262458a2650a109ddc76c76Erich Douglass    public Class<? extends Annotation> annotationType() {
28929a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams      return Config.class;
29029a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams    }
29129a8359eaef1ee9f40c967d3c4b5c1117c8c2a43Christian Williams  }
292dd40f718cf785a56e63c0685feeb73d266c13e3fWenhui Yao}
293