public static ImmutableList<VariantType> getTestingTypes() { ImmutableList.Builder<VariantType> result = ImmutableList.builder(); for (VariantType variantType : values()) { if (variantType.isForTesting()) { result.add(variantType); } } return result.build(); }
public static ImmutableList<VariantType> getTestingTypes() { ImmutableList.Builder<VariantType> result = ImmutableList.builder(); for (VariantType variantType : values()) { if (variantType.isForTesting()) { result.add(variantType); } } return result.build(); }
/** * Reads the package name from the manifest. This is unmodified by the build type. */ @Nullable public String getPackageFromManifest() { checkState(!mType.isForTesting()); String packageName = getManifestAttributeSupplier().getPackage(); if (packageName == null) { throw new RuntimeException(String.format("Cannot read packageName from %1$s", mDefaultSourceProvider.getManifestFile().getAbsolutePath())); } return packageName; }
@Nullable public String getTestedApplicationId() { if (mType.isForTesting()) { checkState(mTestedConfig != null); if (mTestedConfig.mType == VariantType.LIBRARY) { return getApplicationId(); } else { return mTestedConfig.getApplicationId(); } } return null; }
/** * Reads the package name from the manifest. This is unmodified by the build type. */ @Nullable public String getPackageFromManifest() { checkState(!mType.isForTesting()); File manifestLocation = mDefaultSourceProvider.getManifestFile(); String packageName = sManifestParser.getPackage(manifestLocation); if (packageName == null) { throw new RuntimeException(String.format("Cannot read packageName from %1$s", mDefaultSourceProvider.getManifestFile().getAbsolutePath())); } return packageName; }
@Nullable public String getTestedApplicationId() { if (mType.isForTesting()) { checkState(mTestedConfig != null); if (mTestedConfig.mType == VariantType.LIBRARY) { return getApplicationId(); } else { return mTestedConfig.getApplicationId(); } } return null; }
@NonNull public String getTestApplicationId(){ checkState(mType.isForTesting()); if (!Strings.isNullOrEmpty(mMergedFlavor.getTestApplicationId())) { // if it's specified through build file read from there return mMergedFlavor.getTestApplicationId(); } else { // otherwise getApplicationId() contains rules for getting the // applicationId for the test app from the tested application return getApplicationId(); } }
/** * Returns the instrumentationRunner arguments to use to test this variant, or if the * variant is a test, the ones to use to test the tested variant */ @NonNull public Map<String, String> getInstrumentationRunnerArguments() { VariantConfiguration config = this; if (mType.isForTesting()) { config = getTestedConfig(); checkState(config != null); } return config.mMergedFlavor.getTestInstrumentationRunnerArguments(); }
/** * Returns the instrumentationRunner arguments to use to test this variant, or if the * variant is a test, the ones to use to test the tested variant */ @NonNull public Map<String, String> getInstrumentationRunnerArguments() { VariantConfiguration config = this; if (mType.isForTesting()) { config = getTestedConfig(); checkState(config != null); } return config.mMergedFlavor.getTestInstrumentationRunnerArguments(); }
/** * Returns the instrumentationRunner to use to test this variant, or if the * variant is a test, the one to use to test the tested variant. * @return the instrumentation test runner name */ @NonNull public String getInstrumentationRunner() { VariantConfiguration config = this; if (mType.isForTesting()) { config = getTestedConfig(); checkState(config != null); } String runner = config.mMergedFlavor.getTestInstrumentationRunner(); return runner != null ? runner : DEFAULT_TEST_RUNNER; }
/** * Returns handleProfiling value to use to test this variant, or if the * variant is a test, the one to use to test the tested variant. * @return the handleProfiling value */ @NonNull public Boolean getHandleProfiling() { VariantConfiguration config = this; if (mType.isForTesting()) { config = getTestedConfig(); checkState(config != null); } Boolean handleProfiling = config.mMergedFlavor.getTestHandleProfiling(); return handleProfiling != null ? handleProfiling : DEFAULT_HANDLE_PROFILING; }
/** * Returns functionalTest value to use to test this variant, or if the * variant is a test, the one to use to test the tested variant. * @return the functionalTest value */ @NonNull public Boolean getFunctionalTest() { VariantConfiguration config = this; if (mType.isForTesting()) { config = getTestedConfig(); checkState(config != null); } Boolean functionalTest = config.mMergedFlavor.getTestFunctionalTest(); return functionalTest != null ? functionalTest : DEFAULT_FUNCTIONAL_TEST; }
/** * Is the given variant relevant for lint? */ private static boolean isLintVariant( @NonNull BaseVariantData<? extends BaseVariantOutputData> baseVariantData) { // Only create lint targets for variants like debug and release, not debugTest VariantConfiguration config = baseVariantData.getVariantConfiguration(); return !config.getType().isForTesting(); }
/** * Is the given variant relevant for lint? */ private static boolean isLintVariant( @NonNull BaseVariantData<? extends BaseVariantOutputData> baseVariantData) { // Only create lint targets for variants like debug and release, not debugTest VariantConfiguration config = baseVariantData.getVariantConfiguration(); return !config.getType().isForTesting(); }
/** * Returns the original application ID before any overrides from flavors. * If the variant is a test variant, then the application ID is the one coming from the * configuration of the tested variant, and this call is similar to {@link #getApplicationId()} * @return the original application ID */ @Nullable public String getOriginalApplicationId() { if (mType.isForTesting()) { return getApplicationId(); } return getPackageFromManifest(); }
/** * Returns the original application ID before any overrides from flavors. * If the variant is a test variant, then the application ID is the one coming from the * configuration of the tested variant, and this call is similar to {@link #getApplicationId()} * @return the original application ID */ @Nullable public String getOriginalApplicationId() { if (mType.isForTesting()) { return getApplicationId(); } return getPackageFromManifest(); }
/** * Returns the version code for this variant. This could be coming from the manifest or * could be overridden through the product flavors, and can have a suffix specified by * the build type. * * @return the version code or -1 if there was non defined. */ public int getVersionCode() { int versionCode = mMergedFlavor.getVersionCode() != null ? mMergedFlavor.getVersionCode() : -1; if (versionCode == -1 && !mType.isForTesting()) { versionCode = getVersionCodeFromManifest(); } return versionCode; }
/** * Returns the version code for this variant. This could be coming from the manifest or * could be overridden through the product flavors, and can have a suffix specified by * the build type. * * @return the version code or -1 if there was non defined. */ public int getVersionCode() { int versionCode = mMergedFlavor.getVersionCode() != null ? mMergedFlavor.getVersionCode() : -1; if (versionCode == -1 && !mType.isForTesting()) { versionCode = getVersionCodeFromManifest(); } return versionCode; }
/** * Returns whether the configuration has minification enabled. */ public boolean isMinifyEnabled() { VariantType type = getType(); // if type == test then getTestedConfig always returns non-null //noinspection ConstantConditions return getBuildType().isMinifyEnabled() && (!type.isForTesting() || (getTestedConfig().getType() != VariantType.LIBRARY)); }
/** * Returns whether the configuration has minification enabled. */ public boolean isMinifyEnabled() { VariantType type = getType(); // if type == test then getTestedConfig always returns non-null //noinspection ConstantConditions return getBuildType().isMinifyEnabled() && (!type.isForTesting() || (getTestedConfig().getType() != VariantType.LIBRARY)); }