Search in sources :

Example 16 with ModifiableFacetModel

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

the class AbstractAndroidQuickFixMultiFileTest method addAndroidFacet.

private void addAndroidFacet() {
    FacetManager facetManager = FacetManager.getInstance(myModule);
    AndroidFacet facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
    final ModifiableFacetModel facetModel = facetManager.createModifiableModel();
    facetModel.addFacet(facet);
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            facetModel.commit();
        }
    });
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 17 with ModifiableFacetModel

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

the class NewProjectImportGradleSyncListener method createTopLevelModule.

@VisibleForTesting
public static void createTopLevelModule(@NotNull Project project) {
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    File projectRootDir = getBaseDirPath(project);
    VirtualFile contentRoot = findFileByIoFile(projectRootDir, true);
    if (contentRoot != null) {
        File moduleFile = new File(projectRootDir, projectRootDir.getName() + ".iml");
        Module module = moduleManager.newModule(moduleFile.getPath(), JAVA.getId());
        // This prevents the balloon "Unsupported Modules detected".
        ExternalSystemModulePropertyManager.getInstance(module).setExternalId(GRADLE_SYSTEM_ID);
        ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        model.addContentEntry(contentRoot);
        if (IdeInfo.getInstance().isAndroidStudio()) {
            // If sync fails, make sure that the project has a JDK, otherwise Groovy indices won't work (a common scenario where
            // users will update build.gradle files to fix Gradle sync.)
            // See: https://code.google.com/p/android/issues/detail?id=194621
            Sdk jdk = IdeSdks.getInstance().getJdk();
            if (jdk != null) {
                model.setSdk(jdk);
            }
        }
        model.commit();
        FacetManager facetManager = FacetManager.getInstance(module);
        ModifiableFacetModel facetModel = facetManager.createModifiableModel();
        try {
            GradleFacet gradleFacet = GradleFacet.getInstance(module);
            if (gradleFacet == null) {
                // Add "gradle" facet, to avoid balloons about unsupported compilation of modules.
                gradleFacet = facetManager.createFacet(GradleFacet.getFacetType(), GradleFacet.getFacetName(), null);
                facetModel.addFacet(gradleFacet);
            }
            gradleFacet.getConfiguration().GRADLE_PROJECT_PATH = GRADLE_PATH_SEPARATOR;
            // Add "android" facet to avoid the balloon "Android Framework detected".
            AndroidFacet androidFacet = AndroidFacet.getInstance(module);
            if (androidFacet == null) {
                androidFacet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
                facetModel.addFacet(androidFacet);
            }
            // This is what actually stops Studio from showing the balloon.
            androidFacet.getProperties().ALLOW_USER_CONFIGURATION = false;
        } finally {
            facetModel.commit();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) Sdk(com.intellij.openapi.projectRoots.Sdk) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 18 with ModifiableFacetModel

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

the class NdkFacetModuleSetupStep method gradleModelNotFound.

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

Example 19 with ModifiableFacetModel

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

the class AndroidFacetModuleSetupStep method createAndAddFacet.

@NotNull
private static AndroidFacet createAndAddFacet(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider) {
    ModifiableFacetModel model = ideModelsProvider.getModifiableFacetModel(module);
    AndroidFacetType facetType = AndroidFacet.getFacetType();
    AndroidFacet facet = facetType.createFacet(module, AndroidFacet.NAME, facetType.createDefaultConfiguration(), null);
    model.addFacet(facet);
    return facet;
}
Also used : AndroidFacetType(org.jetbrains.android.facet.AndroidFacetType) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with ModifiableFacetModel

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

the class AndroidFacetModuleSetupStep method gradleModelNotFound.

@Override
protected void gradleModelNotFound(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider) {
    ModifiableFacetModel facetModel = ideModelsProvider.getModifiableFacetModel(module);
    removeAllFacets(facetModel, AndroidFacet.ID);
}
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