Search in sources :

Example 21 with ModifiableFacetModel

use of com.intellij.facet.ModifiableFacetModel in project android by JetBrains.

the class JavaFacetModuleSetupStep method setAndGetJavaGradleFacet.

@NotNull
private static JavaFacet setAndGetJavaGradleFacet(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider) {
    JavaFacet facet = findFacet(module, modelsProvider, JavaFacet.getFacetTypeId());
    if (facet != null) {
        return facet;
    }
    FacetManager facetManager = FacetManager.getInstance(module);
    ModifiableFacetModel model = modelsProvider.getModifiableFacetModel(module);
    facet = facetManager.createFacet(JavaFacet.getFacetType(), JavaFacet.getFacetName(), null);
    model.addFacet(facet);
    return facet;
}
Also used : JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with ModifiableFacetModel

use of com.intellij.facet.ModifiableFacetModel in project android by JetBrains.

the class AndroidTestCase method addAndroidFacet.

private static AndroidFacet addAndroidFacet(Module module, boolean attachSdk) {
    FacetManager facetManager = FacetManager.getInstance(module);
    AndroidFacet facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
    if (attachSdk) {
        addLatestAndroidSdk(module);
    }
    ModifiableFacetModel facetModel = facetManager.createModifiableModel();
    facetModel.addFacet(facet);
    ApplicationManager.getApplication().runWriteAction(facetModel::commit);
    return facet;
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 23 with ModifiableFacetModel

use of com.intellij.facet.ModifiableFacetModel in project android by JetBrains.

the class GradleModuleSetup method setUpModule.

public void setUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull GradleModuleModel model) {
    GradleFacet facet = findFacet(module, ideModelsProvider, GradleFacet.getFacetTypeId());
    if (facet == null) {
        ModifiableFacetModel facetModel = ideModelsProvider.getModifiableFacetModel(module);
        GradleFacetType facetType = GradleFacet.getFacetType();
        facet = facetType.createFacet(module, GradleFacet.getFacetName(), facetType.createDefaultConfiguration(), null);
        facetModel.addFacet(facet);
    }
    facet.setGradleModuleModel(model);
    String gradleVersion = model.getGradleVersion();
    GradleSyncSummary syncReport = GradleSyncState.getInstance(module.getProject()).getSummary();
    if (isNotEmpty(gradleVersion) && syncReport.getGradleVersion() == null) {
        syncReport.setGradleVersion(GradleVersion.parse(gradleVersion));
    }
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) GradleFacetType(com.android.tools.idea.gradle.project.facet.gradle.GradleFacetType) GradleSyncSummary(com.android.tools.idea.gradle.project.sync.GradleSyncSummary)

Example 24 with ModifiableFacetModel

use of com.intellij.facet.ModifiableFacetModel in project android by JetBrains.

the class GradleProjectInfoTest method removeAndroidGradleFacetFromModule.

private void removeAndroidGradleFacetFromModule() {
    FacetManager facetManager = FacetManager.getInstance(getModule());
    GradleFacet facet = facetManager.findFacet(GradleFacet.getFacetTypeId(), GradleFacet.getFacetName());
    if (facet != null) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            ModifiableFacetModel facetModel = facetManager.createModifiableModel();
            facetModel.removeFacet(facet);
            facetModel.commit();
        });
    }
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) FacetManager(com.intellij.facet.FacetManager)

Example 25 with ModifiableFacetModel

use of com.intellij.facet.ModifiableFacetModel in project android by JetBrains.

the class FacetsTest method testRemoveAllFacetsWithAndroidGradleFacets.

public void testRemoveAllFacetsWithAndroidGradleFacets() throws Exception {
    createAndAddGradleFacet(myModule);
    FacetManager facetManager = FacetManager.getInstance(myModule);
    assertEquals(1, facetManager.getFacetsByType(GradleFacet.getFacetTypeId()).size());
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    ModifiableFacetModel facetModel = modelsProvider.getModifiableFacetModel(myModule);
    Facets.removeAllFacets(facetModel, GradleFacet.getFacetTypeId());
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    assertEquals(0, facetManager.getFacetsByType(GradleFacet.getFacetTypeId()).size());
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) FacetManager(com.intellij.facet.FacetManager)

Aggregations

ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)29 FacetManager (com.intellij.facet.FacetManager)15 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)9 NotNull (org.jetbrains.annotations.NotNull)5 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)4 Module (com.intellij.openapi.module.Module)4 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)3 Result (com.intellij.openapi.application.Result)3 WriteAction (com.intellij.openapi.application.WriteAction)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)2 NdkFacetType (com.android.tools.idea.gradle.project.facet.ndk.NdkFacetType)2 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)2 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 File (java.io.File)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 GradleFacetType (com.android.tools.idea.gradle.project.facet.gradle.GradleFacetType)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1 GradleSyncSummary (com.android.tools.idea.gradle.project.sync.GradleSyncSummary)1