com.android.builder.model.ProductFlavorContainer Java Examples

The following examples show how to use com.android.builder.model.ProductFlavorContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IconDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds in the resConfig values specified by the given flavor container, assuming
 * it's in one of the relevant variantFlavors, into the given set
 */
private static void addResConfigsFromFlavor(@NonNull Set<String> relevantDensities,
                                            @Nullable List<String> variantFlavors,
                                            @NonNull ProductFlavorContainer container) {
    ProductFlavor flavor = container.getProductFlavor();
    if (variantFlavors == null || variantFlavors.contains(flavor.getName())) {
        if (!flavor.getResourceConfigurations().isEmpty()) {
            for (String densityName : flavor.getResourceConfigurations()) {
                Density density = Density.getEnum(densityName);
                if (density != null && density.isRecommended()
                        && density != Density.NODPI && density != Density.ANYDPI) {
                    relevantDensities.add(densityName);
                }
            }
        }
    }
}
 
Example #2
Source File: AndroidSupport.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
private static Map<String, Set<File>> getAndroidSources(ProductFlavorContainer defaultConfig) {

    Map<String, Set<File>> sources = new HashMap<>(8);
    ProductFlavor productFlavor = defaultConfig.getProductFlavor();
    String name = productFlavor.getName();

    SourceProvider sourceProvider = defaultConfig.getSourceProvider();
    AndroidSupport.setAndroidSources(sources, sourceProvider, false);

    // extra
    Collection<SourceProviderContainer> extraSourceProviders =
        defaultConfig.getExtraSourceProviders();
    extraSourceProviders.forEach(
        sourceProviderContainer -> {
          String artifactName = sourceProviderContainer.getArtifactName();
          SourceProvider provider = sourceProviderContainer.getSourceProvider();
          boolean isTest = artifactName.contains(TEST_SUFFIX);
          AndroidSupport.setAndroidSources(sources, provider, isTest);
        });

    return sources;
  }
 
Example #3
Source File: TranslationDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds in the resConfig values specified by the given flavor container, assuming
 * it's in one of the relevant variantFlavors, into the given set
 */
private static void addResConfigsFromFlavor(@NonNull Set<String> relevantLanguages,
        @Nullable List<String> variantFlavors,
        @NonNull ProductFlavorContainer container) {
    ProductFlavor flavor = container.getProductFlavor();
    if (variantFlavors == null || variantFlavors.contains(flavor.getName())) {
        if (!flavor.getResourceConfigurations().isEmpty()) {
            for (String resConfig : flavor.getResourceConfigurations()) {
                // Look for languages; these are of length 2. (ResConfigs
                // can also refer to densities, etc.)
                if (resConfig.length() == 2) {
                    relevantLanguages.add(resConfig);
                }
            }
        }
    }
}
 
Example #4
Source File: TranslationDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
private static List<String> getResConfigLanguages(@NonNull Project project) {
    if (project.isGradleProject() && project.getGradleProjectModel() != null &&
            project.getCurrentVariant() != null) {
        Set<String> relevantDensities = Sets.newHashSet();
        Variant variant = project.getCurrentVariant();
        List<String> variantFlavors = variant.getProductFlavors();
        AndroidProject gradleProjectModel = project.getGradleProjectModel();

        addResConfigsFromFlavor(relevantDensities, null,
                project.getGradleProjectModel().getDefaultConfig());
        for (ProductFlavorContainer container : gradleProjectModel.getProductFlavors()) {
            addResConfigsFromFlavor(relevantDensities, variantFlavors, container);
        }
        if (!relevantDensities.isEmpty()) {
            ArrayList<String> strings = Lists.newArrayList(relevantDensities);
            Collections.sort(strings);
            return strings;
        }
    }

    return null;
}
 
Example #5
Source File: Project.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds in the resConfig values specified by the given flavor container, assuming
 * it's in one of the relevant variantFlavors, into the given set
 */
private static void addResConfigsFromFlavor(@NonNull Set<String> relevantDensities,
        @Nullable List<String> variantFlavors,
        @NonNull ProductFlavorContainer container) {
    ProductFlavor flavor = container.getProductFlavor();
    if (variantFlavors == null || variantFlavors.contains(flavor.getName())) {
        if (!flavor.getResourceConfigurations().isEmpty()) {
            for (String densityName : flavor.getResourceConfigurations()) {
                Density density = Density.getEnum(densityName);
                if (density != null && density.isRecommended()
                        && density != Density.NODPI && density != Density.ANYDPI) {
                    relevantDensities.add(densityName);
                }
            }
        }
    }
}
 
Example #6
Source File: ProductFlavorContainerImpl.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a ProductFlavorContainer from a ProductFlavorData
 *
 * @param productFlavorData        the product flavor data
 * @param sourceProviderContainers collection of extra source providers
 * @return a non-null ProductFlavorContainer
 */
@NonNull
static ProductFlavorContainer createProductFlavorContainer(
        @NonNull ProductFlavorData productFlavorData,
        @NonNull Collection<SourceProviderContainer> sourceProviderContainers) {

    List<SourceProviderContainer> clonedContainers =
            SourceProviderContainerImpl.cloneCollection(sourceProviderContainers);

    return new ProductFlavorContainerImpl(
            ProductFlavorImpl.cloneFlavor(productFlavorData.getProductFlavor(), null, null),
            SourceProviderImpl.cloneProvider(productFlavorData.getSourceSet()),
            clonedContainers);
}
 
Example #7
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private List<SourceProvider> getSourceProviders() {
    if (mProviders == null) {
        List<SourceProvider> providers = Lists.newArrayList();
        AndroidArtifact mainArtifact = mVariant.getMainArtifact();

        providers.add(mProject.getDefaultConfig().getSourceProvider());

        for (String flavorName : mVariant.getProductFlavors()) {
            for (ProductFlavorContainer flavor : mProject.getProductFlavors()) {
                if (flavorName.equals(flavor.getProductFlavor().getName())) {
                    providers.add(flavor.getSourceProvider());
                    break;
                }
            }
        }

        SourceProvider multiProvider = mainArtifact.getMultiFlavorSourceProvider();
        if (multiProvider != null) {
            providers.add(multiProvider);
        }

        String buildTypeName = mVariant.getBuildType();
        for (BuildTypeContainer buildType : mProject.getBuildTypes()) {
            if (buildTypeName.equals(buildType.getBuildType().getName())) {
                providers.add(buildType.getSourceProvider());
                break;
            }
        }

        SourceProvider variantProvider = mainArtifact.getVariantSourceProvider();
        if (variantProvider != null) {
            providers.add(variantProvider);
        }

        mProviders = providers;
    }

    return mProviders;
}
 
Example #8
Source File: ProductFlavors.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ProductFlavorContainer findFlavorByName(Iterable<ProductFlavorContainer> flavors, final String name) {
    return flavors == null || name == null
            ? null
            : Iterables.find(
                    flavors,
                    new Predicate<ProductFlavorContainer>() {

                @Override
                public boolean apply(ProductFlavorContainer t) {
                    return name.equals(t.getProductFlavor().getName());
                }
            },
                    null);
}
 
Example #9
Source File: ProductFlavors.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Nullable
public static SourceProviderContainer getSourceProviderContainer(ProductFlavorContainer pfc, final String name) {
    return pfc == null || name == null
            ? null
            : Iterables.find(
                    pfc.getExtraSourceProviders(),
                    new Predicate<SourceProviderContainer>() {
                @Override
                public boolean apply(SourceProviderContainer t) {
                    return name.equals(t.getArtifactName());
                }
            },
                    null);
}
 
Example #10
Source File: DefaultAndroidProject.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public ProductFlavorContainer getDefaultConfig() {
    return defaultConfig;
}
 
Example #11
Source File: DefaultAndroidProject.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
DefaultAndroidProject setDefaultConfig(@NonNull ProductFlavorContainer defaultConfigContainer) {
    defaultConfig = defaultConfigContainer;
    return this;
}
 
Example #12
Source File: DefaultAndroidProject.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public Collection<ProductFlavorContainer> getProductFlavors() {
    return productFlavors;
}
 
Example #13
Source File: Project.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the set of applicable densities for this project. If null, there are no density
 * restrictions and all densities apply.
 *
 * @return the list of specific densities that apply in this project, or null if all densities
 * apply
 */
@Nullable
public List<String> getApplicableDensities() {
    if (mCachedApplicableDensities == null) {
        // Use the gradle API to set up relevant densities. For example, if the
        // build.gradle file contains this:
        // android {
        //     defaultConfig {
        //         resConfigs "nodpi", "hdpi"
        //     }
        // }
        // ...then we should only enforce hdpi densities, not all these others!
        if (isGradleProject() && getGradleProjectModel() != null &&
                getCurrentVariant() != null) {
            Set<String> relevantDensities = Sets.newHashSet();
            Variant variant = getCurrentVariant();
            List<String> variantFlavors = variant.getProductFlavors();
            AndroidProject gradleProjectModel = getGradleProjectModel();

            addResConfigsFromFlavor(relevantDensities, null,
                    getGradleProjectModel().getDefaultConfig());
            for (ProductFlavorContainer container : gradleProjectModel.getProductFlavors()) {
                addResConfigsFromFlavor(relevantDensities, variantFlavors, container);
            }

            // Are there any splits that specify densities?
            if (relevantDensities.isEmpty()) {
                AndroidArtifact mainArtifact = variant.getMainArtifact();
                Collection<AndroidArtifactOutput> outputs = mainArtifact.getOutputs();
                for (AndroidArtifactOutput output : outputs) {
                    for (OutputFile file : output.getOutputs()) {
                        final String DENSITY_NAME = OutputFile.FilterType.DENSITY.name();
                        if (file.getFilterTypes().contains(DENSITY_NAME)) {
                            for (FilterData data : file.getFilters()) {
                                if (DENSITY_NAME.equals(data.getFilterType())) {
                                    relevantDensities.add(data.getIdentifier());
                                }
                            }
                        }
                    }
                }
            }

            if (!relevantDensities.isEmpty()) {
                mCachedApplicableDensities = Lists.newArrayListWithExpectedSize(10);
                for (String density : relevantDensities) {
                    String folder = ResourceFolderType.DRAWABLE.getName() + '-' + density;
                    mCachedApplicableDensities.add(folder);
                }
                Collections.sort(mCachedApplicableDensities);
            } else {
                mCachedApplicableDensities = Collections.emptyList();
            }
        } else {
            mCachedApplicableDensities = Collections.emptyList();
        }
    }

    return mCachedApplicableDensities.isEmpty() ? null : mCachedApplicableDensities;
}
 
Example #14
Source File: DefaultAndroidProject.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
DefaultAndroidProject addProductFlavors(
        @NonNull ProductFlavorContainer productFlavorContainer) {
    productFlavors.add(productFlavorContainer);
    return this;
}
 
Example #15
Source File: GradleSourceForBinaryQuery.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
private Iterable<? extends File> sourceRootsForVariant(Variant variant) {
    Collection<File> javaDirs = androidProjectModel != null
            ? androidProjectModel.getDefaultConfig().getSourceProvider().getJavaDirectories()
            : Collections.<File>emptySet();
    BuildTypeContainer buildTypeContainer = buildConfig.getCurrentBuildTypeContainer();
    Collection<File> typeJavaDirs = buildTypeContainer != null
            ? buildTypeContainer.getSourceProvider().getJavaDirectories()
            : Collections.<File>emptySet();
    Iterable<File> variantJavaDirs = variant != null
            ? Iterables.concat(
                    Iterables.transform(
                            variant.getProductFlavors(),
                            new Function<String, Collection<File>>() {
                        @Override
                        public Collection<File> apply(String f) {
                            if (androidProjectModel == null) {
                                return Collections.<File>emptySet();
                            }
                            final ProductFlavorContainer flavor
                                    = ProductFlavors.findFlavorByName(androidProjectModel.getProductFlavors(), f);
                            if (flavor == null) {
                                return Collections.<File>emptySet();
                            }
                            return flavor.getSourceProvider().getJavaDirectories();
                        }
                    }))
            : Collections.<File>emptySet();
    Collection<File> generatedJavaDirs = variant != null
            ? variant.getMainArtifact().getGeneratedSourceFolders()
            : Collections.<File>emptyList();
    if (variant!=null) {
        RTools.PluginVersionResult result = RTools.handlePluginVersion(androidProjectModel, variant, null);
        if(result!=null){
            generatedJavaDirs.add(FileUtil.toFile(result.getSrc()));
        }
    }
    return Iterables.concat(
            javaDirs,
            typeJavaDirs,
            variantJavaDirs,
            generatedJavaDirs);
}
 
Example #16
Source File: AndroidClassPathProvider.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends File> get() {
    Collection<File> javaDirs = androidProjectModel != null
            ? androidProjectModel.getDefaultConfig().getSourceProvider().getJavaDirectories()
            : Collections.<File>emptySet();
    BuildTypeContainer buildTypeContainer = buildConfig.getCurrentBuildTypeContainer();
    Collection<File> typeJavaDirs = buildTypeContainer != null
            ? buildTypeContainer.getSourceProvider().getJavaDirectories()
            : Collections.<File>emptySet();
    Variant variant = buildConfig.getCurrentVariant();
    Iterable<File> variantJavaDirs = variant != null
            ? Iterables.concat(
                    Iterables.transform(
                            variant.getProductFlavors(),
                            new Function<String, Collection<File>>() {
                        @Override
                        public Collection<File> apply(String f) {
                            if (androidProjectModel == null) {
                                return Collections.<File>emptySet();
                            }
                            final ProductFlavorContainer flavor = ProductFlavors.findFlavorByName(androidProjectModel.getProductFlavors(), f);
                            if (flavor == null) {
                                return Collections.<File>emptySet();
                            }
                            return flavor.getSourceProvider().getJavaDirectories();
                        }
                    }))
            : Collections.<File>emptySet();
    Collection<File> generatedJavaDirs = variant != null
            ? variant.getMainArtifact().getGeneratedSourceFolders()
            : Collections.<File>emptyList();
    if (variant != null) {
        RTools.PluginVersionResult result = RTools.handlePluginVersion(androidProjectModel, variant, null);
        if (result != null) {
            generatedJavaDirs.add(FileUtil.toFile(result.getSrc()));
        }
    }
    return Iterables.concat(
            javaDirs,
            typeJavaDirs,
            variantJavaDirs,
            generatedJavaDirs);
}
 
Example #17
Source File: AndroidClassPathProvider.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends File> get() {
    SourceProviderContainer spc = androidProjectModel != null
            ? ProductFlavors.getSourceProviderContainer(androidProjectModel.getDefaultConfig(), AndroidProject.ARTIFACT_ANDROID_TEST)
            : null;
    Collection<File> javaDirs = spc != null
            ? spc.getSourceProvider().getJavaDirectories()
            : Collections.<File>emptySet();
    Variant variant = buildConfig.getCurrentVariant();
    Iterable<File> variantJavaDirs = variant != null
            ? Iterables.concat(
                    Iterables.transform(
                            variant.getProductFlavors(),
                            new Function<String, Collection<File>>() {
                        @Override
                        public Collection<File> apply(String f) {
                            if (androidProjectModel == null) {
                                return Collections.<File>emptySet();
                            }
                            final ProductFlavorContainer flavor = ProductFlavors.findFlavorByName(androidProjectModel.getProductFlavors(), f);
                            if (flavor == null) {
                                return Collections.<File>emptySet();
                            }
                            SourceProviderContainer flavorSPC = ProductFlavors.getSourceProviderContainer(
                                    flavor, AndroidProject.ARTIFACT_ANDROID_TEST);
                            if (flavorSPC == null) {
                                return Collections.<File>emptySet();
                            }
                            return flavorSPC.getSourceProvider().getJavaDirectories();
                        }
                    }))
            : Collections.<File>emptySet();
    AndroidArtifact testArtifact = variant != null
            ? AndroidBuildVariants.instrumentTestArtifact(variant.getExtraAndroidArtifacts())
            : null;
    Collection<File> generatedJavaDirs = testArtifact != null
            ? testArtifact.getGeneratedSourceFolders()
            : Collections.<File>emptyList();
    return Iterables.concat(
            javaDirs,
            variantJavaDirs,
            generatedJavaDirs);
}