Search in sources :

Example 11 with IdeModifiableModelsProvider

use of com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider in project android by JetBrains.

the class JavaLanguageLevelModuleSetupStepTest method testSetUpModuleWithLanguageLevelComingFromAndroidModules.

public void testSetUpModuleWithLanguageLevelComingFromAndroidModules() {
    createAndroidModule("app", JDK_1_7);
    createAndroidModule("androidLib", JDK_1_8);
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    when(myJavaModuleModel.getJavaLanguageLevel()).thenReturn(null);
    Module module = getModule();
    mySetupStep.setUpModule(module, modelsProvider, myJavaModuleModel, null, null);
    // Commit changes to verify results.
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    verifyLanguageLevel(module, JDK_1_7);
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) Module(com.intellij.openapi.module.Module)

Example 12 with IdeModifiableModelsProvider

use of com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider in project android by JetBrains.

the class AndroidModuleModelDataServiceTest method testImportData.

public void testImportData() throws Exception {
    loadSimpleApplication();
    Module appModule = myModules.getAppModule();
    AndroidModuleModel androidModel = AndroidModuleModel.get(appModule);
    assertNotNull(androidModel);
    DataNode<AndroidModuleModel> dataNode = new DataNode<>(ANDROID_MODEL, androidModel, null);
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    myService.importData(Lists.newArrayList(dataNode), mock(ProjectData.class), project, modelsProvider);
    verify(myModuleSetup).setUpModule(appModule, modelsProvider, androidModel, null, null);
    verify(myValidator).validate(appModule, androidModel);
    verify(myValidator).fixAndReportFoundIssues();
}
Also used : Project(com.intellij.openapi.project.Project) DataNode(com.intellij.openapi.externalSystem.model.DataNode) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 13 with IdeModifiableModelsProvider

use of com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider in project android by JetBrains.

the class JavaModuleSetupTest method testSetUpAndroidModuleWithoutVariants.

public void testSetUpAndroidModuleWithoutVariants() {
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    when(myJavaModuleModel.isAndroidModuleWithoutVariants()).thenReturn(true);
    Module module = getModule();
    // Add AndroidFacet to verify that is removed.
    createAndAddAndroidFacet(module);
    ApplicationManager.getApplication().runWriteAction(() -> {
        // Add source folders and excluded folders to verify that they are removed.
        ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
        ContentEntry contentEntry = modifiableModel.addContentEntry("file://fakePath");
        contentEntry.addSourceFolder("file://fakePath/sourceFolder", false);
        contentEntry.addExcludeFolder("file://fakePath/excludedFolder");
        modifiableModel.commit();
    });
    myModuleSetup.setUpModule(module, modelsProvider, myJavaModuleModel, myModuleModels, null);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    // Verify AndroidFacet was removed.
    assertNull(AndroidFacet.getInstance(module));
    // Verify source folders and excluded folders were removed.
    ContentEntry[] contentEntries = ModuleRootManager.getInstance(module).getContentEntries();
    assertThat(contentEntries).hasLength(1);
    ContentEntry contentEntry = contentEntries[0];
    assertThat(contentEntry.getSourceFolders()).isEmpty();
    assertThat(contentEntry.getExcludeFolderUrls()).isEmpty();
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) Module(com.intellij.openapi.module.Module)

Example 14 with IdeModifiableModelsProvider

use of com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider in project android by JetBrains.

the class ModuleDisposerTest method testDisposeModulesAndMarkImlFilesForDeletion.

public void testDisposeModulesAndMarkImlFilesForDeletion() {
    // This module should be disposed.
    Module libModule = createModule("lib");
    File libImlFilePath = new File(toSystemDependentName(libModule.getModuleFilePath()));
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    myModuleDisposer.disposeModulesAndMarkImlFilesForDeletion(Collections.singletonList(libModule), project, modelsProvider);
    // Apply changes
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    // Make sure module "lib" was disposed and its .iml file was deleted.
    assertTrue(Disposer.isDisposed(libModule));
    verify(myDisposedModules, times(1)).markImlFilesForDeletion(Collections.singletonList(libImlFilePath));
}
Also used : Project(com.intellij.openapi.project.Project) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) File(java.io.File)

Example 15 with IdeModifiableModelsProvider

use of com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider in project android by JetBrains.

the class ModuleDisposerTest method testDisposeModulesAndMarkImlFilesForDeletionWithNoModules.

public void testDisposeModulesAndMarkImlFilesForDeletionWithNoModules() {
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    myModuleDisposer.disposeModulesAndMarkImlFilesForDeletion(Collections.emptyList(), project, modelsProvider);
    // Apply changes
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    //noinspection unchecked
    verify(myDisposedModules, never()).markImlFilesForDeletion(anyList());
}
Also used : Project(com.intellij.openapi.project.Project) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)

Aggregations

IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)22 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)18 Module (com.intellij.openapi.module.Module)16 Project (com.intellij.openapi.project.Project)7 File (java.io.File)7 Library (com.intellij.openapi.roots.libraries.Library)4 JavaModuleModel (com.android.tools.idea.gradle.project.model.JavaModuleModel)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 FacetManager (com.intellij.facet.FacetManager)2 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)2 DataNode (com.intellij.openapi.externalSystem.model.DataNode)2 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)2 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)2 AndroidProject (com.android.builder.model.AndroidProject)1 ImportedModule (com.android.tools.idea.gradle.ImportedModule)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 LibraryDependency (com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency)1 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)1 IdeUIModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider)1