Search in sources :

Example 36 with IdeModifiableModelsProviderImpl

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

the class AndroidModuleDependenciesSetupTest method testSetUpLibraryWithExistingLibrary.

public void testSetUpLibraryWithExistingLibrary() throws IOException {
    File binaryPath = createTempFile("fakeLibrary", "jar");
    File sourcePath = createTempFile("fakeLibrary-src", "jar");
    Library newLibrary = createLibrary(binaryPath, 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);
    LibraryOrderEntry libraryOrderEntry = libraryOrderEntries.get(0);
    // The existing library should not have been changed.
    assertSame(newLibrary, libraryOrderEntry.getLibrary());
    verify(myLibraryRegistry).markAsUsed(newLibrary, binaryPaths);
    // Should not attemp to look up sources for existing libraries.
    verify(myLibraryFilePaths, never()).findSourceJarPath(binaryPath);
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) File(java.io.File)

Aggregations

IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)36 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)18 Module (com.intellij.openapi.module.Module)16 Project (com.intellij.openapi.project.Project)9 File (java.io.File)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 DataNode (com.intellij.openapi.externalSystem.model.DataNode)4 Library (com.intellij.openapi.roots.libraries.Library)4 JavaModuleModel (com.android.tools.idea.gradle.project.model.JavaModuleModel)3 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 FacetManager (com.intellij.facet.FacetManager)2 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)2 IdeUIModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider)2 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 ArrayList (java.util.ArrayList)2 MavenRootModelAdapter (org.jetbrains.idea.maven.importing.MavenRootModelAdapter)2 AndroidProject (com.android.builder.model.AndroidProject)1