Search in sources :

Example 1 with IdeModifiableModelsProvider

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

the class ModuleDisposalDataServiceTest method testImportDataWithAndroidStudioAndSuccessfulSync.

public void testImportDataWithAndroidStudioAndSuccessfulSync() {
    when(myIdeInfo.isAndroidStudio()).thenReturn(true);
    when(mySyncState.lastSyncFailedOrHasIssues()).thenReturn(false);
    IdeaModule moduleModel = mock(IdeaModule.class);
    when(moduleModel.getName()).thenReturn(getModule().getName());
    ImportedModule importedModule = new ImportedModule(moduleModel);
    // This module should be disposed.
    Module libModule = createModule("lib");
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    Collection<DataNode<ImportedModule>> nodes = Collections.singleton(new DataNode<>(IMPORTED_MODULE, importedModule, null));
    myDataService.importData(nodes, null, project, modelsProvider);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::dispose);
    Collection<Module> modulesToDispose = Collections.singletonList(libModule);
    verify(myModuleDisposer).disposeModulesAndMarkImlFilesForDeletion(modulesToDispose, getProject(), modelsProvider);
}
Also used : Project(com.intellij.openapi.project.Project) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ImportedModule(com.android.tools.idea.gradle.ImportedModule) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) ImportedModule(com.android.tools.idea.gradle.ImportedModule) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)

Example 2 with IdeModifiableModelsProvider

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

the class ModuleDisposalDataServiceTest method testImportDataWithIdeNotAndroidStudio.

public void testImportDataWithIdeNotAndroidStudio() {
    when(myIdeInfo.isAndroidStudio()).thenReturn(false);
    IdeModifiableModelsProvider modelsProvider = mock(IdeModifiableModelsProvider.class);
    myDataService.importData(Collections.emptyList(), null, getProject(), modelsProvider);
    //noinspection unchecked
    verify(myModuleDisposer, never()).disposeModulesAndMarkImlFilesForDeletion(anyList(), same(getProject()), same(modelsProvider));
}
Also used : IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)

Example 3 with IdeModifiableModelsProvider

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

the class ModuleDisposalDataServiceTest method testImportDataWithAndroidStudioAndSyncFailed.

public void testImportDataWithAndroidStudioAndSyncFailed() {
    when(myIdeInfo.isAndroidStudio()).thenReturn(true);
    when(mySyncState.lastSyncFailedOrHasIssues()).thenReturn(true);
    IdeModifiableModelsProvider modelsProvider = mock(IdeModifiableModelsProvider.class);
    myDataService.importData(Collections.emptyList(), null, getProject(), modelsProvider);
    //noinspection unchecked
    verify(myModuleDisposer, never()).disposeModulesAndMarkImlFilesForDeletion(anyList(), same(getProject()), same(modelsProvider));
}
Also used : IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)

Example 4 with IdeModifiableModelsProvider

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

the class AndroidModuleDependenciesSetupTest method testSetUpLibraryWithNewLibrary.

public void testSetUpLibraryWithNewLibrary() throws IOException {
    File binaryPath = createTempFile("fakeLibrary", "jar");
    File sourcePath = createTempFile("fakeLibrary-src", "jar");
    when(myLibraryFilePaths.findSourceJarPath(binaryPath)).thenReturn(sourcePath);
    String libraryName = binaryPath.getName();
    Module module = getModule();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    File[] binaryPaths = { binaryPath };
    myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, libraryName, COMPILE, binaryPath, binaryPaths, EMPTY_FILE_ARRAY);
    // Apply changes before checking state.
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    List<LibraryOrderEntry> libraryOrderEntries = getLibraryOrderEntries(module);
    // Only one library should be in the library table.
    assertThat(libraryOrderEntries).hasSize(1);
    Library library = libraryOrderEntries.get(0).getLibrary();
    assertNotNull(library);
    assertEquals(libraryName, library.getName());
    String[] binaryUrls = library.getUrls(CLASSES);
    assertThat(binaryUrls).hasLength(1);
    assertEquals(pathToIdeaUrl(binaryPath), binaryUrls[0]);
    String[] sourceUrls = library.getUrls(SOURCES);
    assertThat(sourceUrls).hasLength(1);
    assertEquals(pathToIdeaUrl(sourcePath), sourceUrls[0]);
    // Should not mark new libraries as "used"
    verify(myLibraryRegistry, never()).markAsUsed(library, binaryPaths);
    verify(myLibraryFilePaths).findSourceJarPath(binaryPath);
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) File(java.io.File)

Example 5 with IdeModifiableModelsProvider

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

the class JavaModuleSetupTest method testSetUpModuleWithoutProgressIndicator.

public void testSetUpModuleWithoutProgressIndicator() {
    when(myJavaModuleModel.isAndroidModuleWithoutVariants()).thenReturn(false);
    IdeModifiableModelsProvider modelsProvider = mock(IdeModifiableModelsProvider.class);
    Module module = getModule();
    myModuleSetup.setUpModule(module, modelsProvider, myJavaModuleModel, myModuleModels, null);
    verify(mySetupStep1, times(1)).setUpModule(module, modelsProvider, myJavaModuleModel, myModuleModels, null);
    verify(mySetupStep2, times(1)).setUpModule(module, modelsProvider, myJavaModuleModel, myModuleModels, null);
    verify(mySetupStep1, never()).displayDescription(same(module), any());
    verify(mySetupStep2, never()).displayDescription(same(module), any());
}
Also used : IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) Module(com.intellij.openapi.module.Module)

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