Search in sources :

Example 6 with ModifiableFacetModel

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

the class ModuleFactory method createModule.

@NotNull
Module createModule(@NotNull IdeaModule ideaModule, @NotNull SyncAction.ModuleModels moduleModels) {
    File imlFilePath = getModuleImlFilePath(ideaModule, moduleModels);
    Module newModule = myModelsProvider.newModule(imlFilePath.getPath(), StdModuleTypes.JAVA.getId());
    ModifiableRootModel rootModel = myModelsProvider.getModifiableRootModel(newModule);
    rootModel.inheritSdk();
    // Remove all dependencies.
    DependencyRemover dependencyRemover = new DependencyRemover(rootModel);
    for (OrderEntry orderEntry : rootModel.getOrderEntries()) {
        orderEntry.accept(dependencyRemover, null);
    }
    // Remove all facets.
    ModifiableFacetModel facetModel = myModelsProvider.getModifiableFacetModel(newModule);
    for (Facet facet : facetModel.getAllFacets()) {
        facetModel.removeFacet(facet);
    }
    return newModule;
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Module(com.intellij.openapi.module.Module) File(java.io.File) Facet(com.intellij.facet.Facet) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ModifiableFacetModel

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

the class AndroidUtils method addAndroidFacet.

@NotNull
public static AndroidFacet addAndroidFacet(final Module module, @NotNull VirtualFile contentRoot, boolean library) {
    final FacetManager facetManager = FacetManager.getInstance(module);
    ModifiableFacetModel model = facetManager.createModifiableModel();
    AndroidFacet facet = model.getFacetByType(AndroidFacet.ID);
    if (facet == null) {
        facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
        AndroidFacetConfiguration configuration = facet.getConfiguration();
        configuration.init(module, contentRoot);
        if (library) {
            facet.setProjectType(PROJECT_TYPE_LIBRARY);
        }
        model.addFacet(facet);
    }
    model.commit();
    return facet;
}
Also used : AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) ProjectFacetManager(com.intellij.facet.ProjectFacetManager) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ModifiableFacetModel

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

the class JavaFacetModuleSetupStep method gradleModelNotFound.

@Override
protected void gradleModelNotFound(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider) {
    ModifiableFacetModel facetModel = ideModelsProvider.getModifiableFacetModel(module);
    removeAllFacets(facetModel, JavaFacet.getFacetTypeId());
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel)

Example 9 with ModifiableFacetModel

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

the class NdkFacetModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull NdkModuleModel ndkModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    NdkFacet facet = findFacet(module, ideModelsProvider, NdkFacet.getFacetTypeId());
    if (facet != null) {
        configureFacet(facet, ndkModuleModel);
    } else {
        // Module does not have Native Android facet. Create one and add it.
        ModifiableFacetModel model = ideModelsProvider.getModifiableFacetModel(module);
        NdkFacetType facetType = NdkFacet.getFacetType();
        facet = facetType.createFacet(module, NdkFacet.getFacetName(), facetType.createDefaultConfiguration(), null);
        model.addFacet(facet);
        configureFacet(facet, ndkModuleModel);
    }
}
Also used : NdkFacetType(com.android.tools.idea.gradle.project.facet.ndk.NdkFacetType) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)

Example 10 with ModifiableFacetModel

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

the class ProjectSetupImplTest method simulateAndroidFacetLookup.

private void simulateAndroidFacetLookup(@NotNull Module module, @Nullable AndroidFacet facetToFind) {
    ModifiableFacetModel facetModel = mock(ModifiableFacetModel.class);
    when(myModelsProvider.getModifiableFacetModel(module)).thenReturn(facetModel);
    when(facetModel.getFacetByType(AndroidFacet.ID)).thenReturn(facetToFind);
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel)

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