Search in sources :

Example 1 with ProductFlavorContainer

use of com.android.builder.model.ProductFlavorContainer in project kotlin by JetBrains.

the class Project method getApplicableDensities.

/**
     * 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) {
        // ...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;
}
Also used : Variant(com.android.builder.model.Variant) OutputFile(com.android.build.OutputFile) ProductFlavorContainer(com.android.builder.model.ProductFlavorContainer) FilterData(com.android.build.FilterData) AndroidProject(com.android.builder.model.AndroidProject) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) AndroidArtifact(com.android.builder.model.AndroidArtifact) Nullable(com.android.annotations.Nullable)

Example 2 with ProductFlavorContainer

use of com.android.builder.model.ProductFlavorContainer in project android by JetBrains.

the class IdeaSourceProviderTest method testFindSourceProvider.

public void testFindSourceProvider() throws Exception {
    assertNotNull(myAppFacet.getAndroidModel());
    VirtualFile moduleFile = myAppFacet.getAndroidModel().getRootDir();
    assertNotNull(moduleFile);
    // Try finding main flavor
    IdeaSourceProvider mainFlavorSourceProvider = myAppFacet.getMainIdeaSourceProvider();
    assertNotNull(mainFlavorSourceProvider);
    VirtualFile javaMainSrcFile = moduleFile.findFileByRelativePath("src/main/java/com/example/projectwithappandlib/");
    assertNotNull(javaMainSrcFile);
    Collection<IdeaSourceProvider> providers = IdeaSourceProvider.getIdeaSourceProvidersForFile(myAppFacet, javaMainSrcFile, null);
    assertEquals(1, providers.size());
    IdeaSourceProvider actualProvider = providers.iterator().next();
    assertEquals(mainFlavorSourceProvider.getManifestFile(), actualProvider.getManifestFile());
    // Try finding paid flavor
    ProductFlavorContainer paidFlavor = AndroidModuleModel.get(myAppFacet).findProductFlavor("paid");
    assertNotNull(paidFlavor);
    IdeaSourceProvider paidFlavorSourceProvider = IdeaSourceProvider.create(paidFlavor.getSourceProvider());
    assertNotNull(paidFlavorSourceProvider);
    VirtualFile javaSrcFile = moduleFile.findFileByRelativePath("src/paid/java/com/example/projectwithappandlib/app/paid");
    assertNotNull(javaSrcFile);
    providers = IdeaSourceProvider.getIdeaSourceProvidersForFile(myAppFacet, javaSrcFile, null);
    assertEquals(1, providers.size());
    actualProvider = providers.iterator().next();
    assertEquals(paidFlavorSourceProvider.getManifestFile(), actualProvider.getManifestFile());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProductFlavorContainer(com.android.builder.model.ProductFlavorContainer)

Example 3 with ProductFlavorContainer

use of com.android.builder.model.ProductFlavorContainer in project android by JetBrains.

the class IdeaSourceProviderTest method testSourceProviderIsContainedByFolder.

public void testSourceProviderIsContainedByFolder() throws Exception {
    assertNotNull(myAppFacet.getAndroidModel());
    ProductFlavorContainer paidFlavor = AndroidModuleModel.get(myAppFacet).findProductFlavor("paid");
    assertNotNull(paidFlavor);
    IdeaSourceProvider paidFlavorSourceProvider = IdeaSourceProvider.create(paidFlavor.getSourceProvider());
    assertNotNull(paidFlavorSourceProvider);
    VirtualFile moduleFile = myAppFacet.getAndroidModel().getRootDir();
    assertNotNull(moduleFile);
    VirtualFile javaSrcFile = moduleFile.findFileByRelativePath("src/paid/java/com/example/projectwithappandlib/app/paid");
    assertNotNull(javaSrcFile);
    assertFalse(paidFlavorSourceProvider.isContainedBy(javaSrcFile));
    VirtualFile flavorRoot = moduleFile.findFileByRelativePath("src/paid");
    assertNotNull(flavorRoot);
    assertTrue(paidFlavorSourceProvider.isContainedBy(flavorRoot));
    VirtualFile srcFile = moduleFile.findChild("src");
    assertNotNull(srcFile);
    assertTrue(paidFlavorSourceProvider.isContainedBy(srcFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProductFlavorContainer(com.android.builder.model.ProductFlavorContainer)

Example 4 with ProductFlavorContainer

use of com.android.builder.model.ProductFlavorContainer in project kotlin by JetBrains.

the class RegistrationDetector method reportMissing.

private static void reportMissing(@NonNull JavaContext context, @NonNull PsiClass node, @NonNull String className, @NonNull String tag) {
    if (tag.equals(TAG_RECEIVER)) {
        // Receivers can be registered in code; don't flag these.
        return;
    }
    // Don't flag activities registered in test source sets
    if (context.getProject().isGradleProject()) {
        AndroidProject model = context.getProject().getGradleProjectModel();
        if (model != null) {
            String javaSource = context.file.getPath();
            for (SourceProviderContainer extra : model.getDefaultConfig().getExtraSourceProviders()) {
                String artifactName = extra.getArtifactName();
                if (AndroidProject.ARTIFACT_ANDROID_TEST.equals(artifactName)) {
                    for (File file : extra.getSourceProvider().getJavaDirectories()) {
                        if (SdkUtils.startsWithIgnoreCase(javaSource, file.getPath())) {
                            return;
                        }
                    }
                }
            }
            for (ProductFlavorContainer container : model.getProductFlavors()) {
                for (SourceProviderContainer extra : container.getExtraSourceProviders()) {
                    String artifactName = extra.getArtifactName();
                    if (AndroidProject.ARTIFACT_ANDROID_TEST.equals(artifactName)) {
                        for (File file : extra.getSourceProvider().getJavaDirectories()) {
                            if (SdkUtils.startsWithIgnoreCase(javaSource, file.getPath())) {
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    Location location = context.getNameLocation(node);
    String message = String.format("The `<%1$s> %2$s` is not registered in the manifest", tag, className);
    context.report(ISSUE, node, location, message);
}
Also used : ProductFlavorContainer(com.android.builder.model.ProductFlavorContainer) AndroidProject(com.android.builder.model.AndroidProject) SourceProviderContainer(com.android.builder.model.SourceProviderContainer) File(java.io.File) Location(com.android.tools.klint.detector.api.Location)

Example 5 with ProductFlavorContainer

use of com.android.builder.model.ProductFlavorContainer in project android by JetBrains.

the class UniqueParameterTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    loadProject(PROJECT_WITH_APPAND_LIB);
    assertNotNull(myAndroidFacet);
    AndroidModel androidModel = AndroidModuleModel.get(myAndroidFacet);
    assertNotNull(androidModel);
    // Set up modules
    for (Module m : ModuleManager.getInstance(getProject()).getModules()) {
        if (m.getName().equals("app")) {
            myAppModule = m;
            break;
        }
    }
    assertNotNull(myAppModule);
    myAppFacet = AndroidFacet.getInstance(myAppModule);
    assertNotNull(myAppFacet);
    addLatestAndroidSdk(myAppModule);
    assertNotNull(AndroidPlatform.getInstance(myAppModule));
    assertNotNull(myAppFacet.getAndroidModel());
    // TODO: b/23032990
    ProductFlavorContainer paidFlavor = AndroidModuleModel.get(myAppFacet).findProductFlavor("paid");
    assertNotNull(paidFlavor);
    myPaidSourceProvider = paidFlavor.getSourceProvider();
    assertNotNull(myPaidSourceProvider);
    myMainSourceProvider = myAppFacet.getMainSourceProvider();
    assertNotNull(myMainSourceProvider);
    TemplateMetadata mockMetadata = Mockito.mock(TemplateMetadata.class);
    Element elem = new IIOMetadataNode();
    elem.setAttribute(ATTR_TYPE, Parameter.Type.STRING.toString());
    elem.setAttribute(ATTR_ID, "testParam");
    elem.setAttribute(ATTR_DEFAULT, "");
    elem.setAttribute(ATTR_SUGGEST, null);
    elem.setAttribute(ATTR_NAME, "Test Param");
    elem.setAttribute(ATTR_HELP, "This is a test parameter");
    elem.setAttribute(ATTR_CONSTRAINTS, "");
    myParameter = new Parameter(mockMetadata, elem);
}
Also used : ProductFlavorContainer(com.android.builder.model.ProductFlavorContainer) AndroidModel(com.android.tools.idea.model.AndroidModel) Element(org.w3c.dom.Element) Module(com.intellij.openapi.module.Module) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Aggregations

ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 AndroidProject (com.android.builder.model.AndroidProject)2 Nullable (com.android.annotations.Nullable)1 FilterData (com.android.build.FilterData)1 OutputFile (com.android.build.OutputFile)1 AndroidArtifact (com.android.builder.model.AndroidArtifact)1 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)1 SourceProviderContainer (com.android.builder.model.SourceProviderContainer)1 Variant (com.android.builder.model.Variant)1 AndroidModel (com.android.tools.idea.model.AndroidModel)1 Location (com.android.tools.klint.detector.api.Location)1 Module (com.intellij.openapi.module.Module)1 File (java.io.File)1 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)1 Element (org.w3c.dom.Element)1