Search in sources :

Example 16 with IdeModifiableModelsProvider

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

the class FacetsTest method testRemoveAllFacetsWithAndroidGradleFacets.

public void testRemoveAllFacetsWithAndroidGradleFacets() throws Exception {
    createAndAddGradleFacet(myModule);
    FacetManager facetManager = FacetManager.getInstance(myModule);
    assertEquals(1, facetManager.getFacetsByType(GradleFacet.getFacetTypeId()).size());
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    ModifiableFacetModel facetModel = modelsProvider.getModifiableFacetModel(myModule);
    Facets.removeAllFacets(facetModel, GradleFacet.getFacetTypeId());
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    assertEquals(0, facetManager.getFacetsByType(GradleFacet.getFacetTypeId()).size());
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) FacetManager(com.intellij.facet.FacetManager)

Example 17 with IdeModifiableModelsProvider

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

the class FacetsTest method testRemoveAllFacetsWithAndroidFacets.

public void testRemoveAllFacetsWithAndroidFacets() throws Exception {
    createAndAddAndroidFacet(myModule);
    FacetManager facetManager = FacetManager.getInstance(myModule);
    assertEquals(1, facetManager.getFacetsByType(AndroidFacet.ID).size());
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    ModifiableFacetModel facetModel = modelsProvider.getModifiableFacetModel(myModule);
    Facets.removeAllFacets(facetModel, AndroidFacet.ID);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    assertEquals(0, facetManager.getFacetsByType(AndroidFacet.ID).size());
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) FacetManager(com.intellij.facet.FacetManager)

Example 18 with IdeModifiableModelsProvider

use of com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider 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)

Example 19 with IdeModifiableModelsProvider

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

the class ArtifactsByConfigurationModuleSetupStepTest method testDoSetUpModule.

public void testDoSetUpModule() throws IOException {
    Module module = getModule();
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    File jarFilePath = createTempFile("fake.jar", "");
    Map<String, Set<File>> artifactsByConfiguration = new HashMap<>();
    artifactsByConfiguration.put("default", Collections.singleton(jarFilePath));
    JavaModuleModel model = new JavaModuleModel(module.getName(), Collections.emptyList(), Collections.emptyList(), artifactsByConfiguration, null, null, null, true, false);
    mySetupStep.doSetUpModule(module, modelsProvider, model, null, null);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    assertJarIsLibrary(jarFilePath);
    // This is the first time we create the library, it shouldn't be marked as "used".
    verify(myLibraryRegistry, never()).markAsUsed(any(), any());
}
Also used : Project(com.intellij.openapi.project.Project) Set(java.util.Set) HashMap(java.util.HashMap) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) File(java.io.File)

Example 20 with IdeModifiableModelsProvider

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

the class ArtifactsByConfigurationModuleSetupStepTest method testDoSetUpModuleWithExistingLibrary.

public void testDoSetUpModuleWithExistingLibrary() throws IOException {
    File jarFilePath = createTempFile("fake.jar", "");
    // Create the library, to ensure that is marked as "used".
    Library library = createLibrary(jarFilePath);
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    Map<String, Set<File>> artifactsByConfiguration = new HashMap<>();
    artifactsByConfiguration.put("default", Collections.singleton(jarFilePath));
    Module module = getModule();
    JavaModuleModel model = new JavaModuleModel(module.getName(), Collections.emptyList(), Collections.emptyList(), artifactsByConfiguration, null, null, null, true, false);
    mySetupStep.doSetUpModule(module, modelsProvider, model, null, null);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    assertJarIsLibrary(jarFilePath);
    // This is an existing library, it should be marked as "used".
    verify(myLibraryRegistry, times(1)).markAsUsed(library, jarFilePath);
}
Also used : Project(com.intellij.openapi.project.Project) Set(java.util.Set) HashMap(java.util.HashMap) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) Library(com.intellij.openapi.roots.libraries.Library) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) Module(com.intellij.openapi.module.Module) File(java.io.File)

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