Search in sources :

Example 26 with IdeModifiableModelsProviderImpl

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

the class NdkModuleModelDataServiceTest method testOnModelsNotFound.

// See: https://code.google.com/p/android/issues/detail?id=229806
public void testOnModelsNotFound() {
    createAndAddNdkFacet(myModule);
    myModelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    myDataService.onModelsNotFound(myModelsProvider);
    ApplicationManager.getApplication().runWriteAction(() -> myModelsProvider.commit());
    assertNull(NdkFacet.getInstance(myModule));
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)

Example 27 with IdeModifiableModelsProviderImpl

use of com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl 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 28 with IdeModifiableModelsProviderImpl

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

Example 29 with IdeModifiableModelsProviderImpl

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

the class DependenciesModuleSetupStepTest method testUpdateLibraryDependencyWithLibraryInModule.

public void testUpdateLibraryDependencyWithLibraryInModule() throws IOException {
    Module module = getModule();
    createContentRoot(module);
    VirtualFile moduleFolder = getModuleFolder(module);
    // Create "build" folder inside the module.
    String name = "build";
    VirtualFile buildFolder = createFolder(moduleFolder, name);
    AndroidProject androidProject = mock(AndroidProject.class);
    when(androidProject.getBuildFolder()).thenReturn(virtualToIoFile(buildFolder));
    // Create "jars" folder inside the module's "build" folder.
    VirtualFile jarsFolder = createFolder(buildFolder, "jars");
    File jarsFolderPath = virtualToIoFile(jarsFolder);
    // We simulate the dependency to set up being inside the "jars" folder. We expect the "jars" folder to be excluded to avoid unnecessary
    // indexing of the jar files.
    LibraryDependency dependency = createFakeLibraryDependency(jarsFolderPath);
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    mySetupStep.updateLibraryDependency(module, modelsProvider, dependency, androidProject);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    // Make sure DependenciesSetup#setUpLibraryDependency was invoked.
    verify(myDependenciesSetup).setUpLibraryDependency(module, modelsProvider, "myLibrary", COMPILE, dependency.getArtifactPath(), dependency.getPaths(BINARY), dependency.getPaths(DOCUMENTATION));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) LibraryDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency) AndroidProject(com.android.builder.model.AndroidProject) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)

Example 30 with IdeModifiableModelsProviderImpl

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

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