Search in sources :

Example 1 with AndroidProject

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

the class Project method getResourceVisibility.

/**
     * Returns a shared {@link ResourceVisibilityLookup}
     *
     * @return a shared provider for looking up resource visibility
     */
@NonNull
public ResourceVisibilityLookup getResourceVisibility() {
    if (mResourceVisibility == null) {
        if (isGradleProject()) {
            AndroidProject project = getGradleProjectModel();
            Variant variant = getCurrentVariant();
            if (project != null && variant != null) {
                mResourceVisibility = mClient.getResourceVisibilityProvider().get(project, variant);
            } else if (getGradleLibraryModel() != null) {
                try {
                    mResourceVisibility = mClient.getResourceVisibilityProvider().get(getGradleLibraryModel());
                } catch (Exception ignore) {
                // Handle talking to older Gradle plugins (where we don't
                // have access to the model version to check up front
                }
            }
        }
        if (mResourceVisibility == null) {
            mResourceVisibility = ResourceVisibilityLookup.NONE;
        }
    }
    return mResourceVisibility;
}
Also used : Variant(com.android.builder.model.Variant) AndroidProject(com.android.builder.model.AndroidProject) CircularDependencyException(com.android.tools.klint.client.api.CircularDependencyException) IOException(java.io.IOException) NonNull(com.android.annotations.NonNull)

Example 2 with AndroidProject

use of com.android.builder.model.AndroidProject 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 3 with AndroidProject

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

the class AndroidGeneratedSourcesFilterTest method createAndroidModel.

@NotNull
private static AndroidModuleModel createAndroidModel(@NotNull VirtualFile buildFolder) {
    AndroidProject androidProject = mock(AndroidProject.class);
    when(androidProject.getBuildFolder()).thenReturn(virtualToIoFile(buildFolder));
    AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
    when(androidModel.getAndroidProject()).thenReturn(androidProject);
    return androidModel;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidProject(com.android.builder.model.AndroidProject) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with AndroidProject

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

the class InternalAndroidModelView method updateContents.

private void updateContents() {
    myTree.setRootVisible(true);
    if (GradleSyncState.getInstance(myProject).isSyncInProgress()) {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Gradle project sync in progress ...")));
        return;
    } else {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Loading ...")));
    }
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(myProject.getName());
        for (Module module : ModuleManager.getInstance(myProject).getModules()) {
            AndroidModuleModel androidModel = AndroidModuleModel.get(module);
            if (androidModel != null) {
                DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module.getName());
                AndroidProject androidProject = androidModel.waitForAndGetProxyAndroidProject();
                addProxyObject(moduleNode, androidProject);
                rootNode.add(moduleNode);
            }
            NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
            if (ndkModuleModel != null) {
                String nodeName = androidModel == null ? module.getName() : module.getName() + " (native)";
                DefaultMutableTreeNode nativeModuleNode = new DefaultMutableTreeNode(nodeName);
                NativeAndroidProject nativeAndroidProject = ndkModuleModel.waitForAndGetProxyAndroidProject();
                addProxyObject(nativeModuleNode, nativeAndroidProject);
                rootNode.add(nativeModuleNode);
            }
        }
        invokeLaterIfNeeded(() -> {
            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
            renderer.setOpenIcon(AllIcons.Nodes.NewFolder);
            renderer.setClosedIcon(AllIcons.Nodes.NewFolder);
            renderer.setLeafIcon(AllIcons.ObjectBrowser.ShowModules);
            myTree.setCellRenderer(renderer);
            DefaultTreeModel model = new DefaultTreeModel(rootNode);
            myTree.setRootVisible(false);
            myTree.setModel(model);
        });
    });
}
Also used : NativeAndroidProject(com.android.builder.model.NativeAndroidProject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) AndroidProject(com.android.builder.model.AndroidProject) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 5 with AndroidProject

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

the class ModuleSetup method setUpModule.

public void setUpModule(@NotNull Module module, @NotNull SyncAction.ModuleModels models, @NotNull ProgressIndicator indicator) {
    boolean isProjectRootFolder = false;
    File gradleSettingsFile = new File(getModulePath(module), FN_SETTINGS_GRADLE);
    if (gradleSettingsFile.isFile() && !models.hasModel(AndroidProject.class) && !models.hasModel(NativeAndroidProject.class)) {
        // This is just a root folder for a group of Gradle projects. We don't set an IdeaGradleProject so the JPS builder won't try to
        // compile it using Gradle. We still need to create the module to display files inside it.
        isProjectRootFolder = true;
    }
    myGradleModuleSetup.setUpModule(module, myIdeModelsProvider, models);
    AndroidProject androidProject = models.findModel(AndroidProject.class);
    if (androidProject != null) {
        AndroidModuleModel androidModel = createAndroidModel(module, androidProject);
        if (androidModel != null) {
            // This is an Android module without variants.
            myAndroidModuleSetup.setUpModule(module, myIdeModelsProvider, androidModel, models, indicator);
        } else {
            // This is an Android module without variants. Treat as a non-buildable Java module.
            removeAndroidFacetFrom(module);
            setUpJavaModule(module, models, indicator, true);
        }
        return;
    }
    // This is not an Android module. Remove any AndroidFacet set in a previous sync operation.
    removeAndroidFacetFrom(module);
    NativeAndroidProject nativeAndroidProject = models.findModel(NativeAndroidProject.class);
    if (nativeAndroidProject != null) {
        NdkModuleModel ndkModuleModel = new NdkModuleModel(module.getName(), getModulePath(module), nativeAndroidProject);
        myNdkModuleSetup.setUpModule(module, myIdeModelsProvider, ndkModuleModel, models, indicator);
        return;
    }
    // This is not an Android module. Remove any AndroidFacet set in a previous sync operation.
    removeAllFacets(myIdeModelsProvider.getModifiableFacetModel(module), NdkFacet.getFacetTypeId());
    if (!isProjectRootFolder) {
        setUpJavaModule(module, models, indicator, false);
    }
}
Also used : NativeAndroidProject(com.android.builder.model.NativeAndroidProject) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidProject(com.android.builder.model.AndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) File(java.io.File)

Aggregations

AndroidProject (com.android.builder.model.AndroidProject)37 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)12 File (java.io.File)8 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)7 Variant (com.android.builder.model.Variant)6 Module (com.intellij.openapi.module.Module)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 NotNull (org.jetbrains.annotations.NotNull)6 ModuleNodeBuilder (com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 IOException (java.io.IOException)4 NonNull (com.android.annotations.NonNull)3 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)3 Project (com.intellij.openapi.project.Project)3 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 LintOptions (com.android.builder.model.LintOptions)2 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)2 LibraryDependency (com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency)2 GradleUtil.getAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject)2 GradleUtil.getNativeAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject)2