Search in sources :

Example 21 with IdeModifiableModelsProviderImpl

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

the class MiscImportingTest method testCheckingIfModuleIsNotDisposedBeforeCommitOnImport.

public void testCheckingIfModuleIsNotDisposedBeforeCommitOnImport() throws Exception {
    if (ignore())
        return;
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<modules>" + "  <module>m1</module>" + "  <module>m2</module>" + "</modules>");
    createModulePom("m1", "<groupId>test</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>");
    createModulePom("m2", "<groupId>test</groupId>" + "<artifactId>m2</artifactId>" + "<version>1</version>");
    importProject();
    assertModules("project", "m1", "m2");
    myProjectsManager.scheduleImportInTests(myProjectsManager.getProjectsFiles());
    myProjectsManager.importProjects(new IdeModifiableModelsProviderImpl(myProject) {

        @Override
        public void commit() {
            ModifiableModuleModel model = ModuleManager.getInstance(myProject).getModifiableModel();
            model.disposeModule(model.findModuleByName("m1"));
            model.disposeModule(model.findModuleByName("m2"));
            model.commit();
            super.commit();
        }
    });
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)

Example 22 with IdeModifiableModelsProviderImpl

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

the class GradleCompositeImportingTest method testCompositeBuildWithProjectNameDuplicates.

@Test
@TargetVersions("3.3+")
public void testCompositeBuildWithProjectNameDuplicates() throws Exception {
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(myProject);
    modelsProvider.newModule(getProjectPath() + "/api.iml", StdModuleTypes.JAVA.getId());
    modelsProvider.newModule(getProjectPath() + "/my-app-api.iml", StdModuleTypes.JAVA.getId());
    modelsProvider.newModule(getProjectPath() + "/my-app-api_main.iml", StdModuleTypes.JAVA.getId());
    edt(() -> ApplicationManager.getApplication().runWriteAction(modelsProvider::commit));
    createSettingsFile("rootProject.name='adhoc'\n" + "\n" + "includeBuild '../my-app'\n" + "includeBuild '../my-utils'");
    createProjectSubFile("../my-app/settings.gradle", "rootProject.name = 'my-app'\n" + "include 'api'\n");
    createProjectSubFile("../my-app/build.gradle", "apply plugin: 'java'\n" + "group 'org.sample'\n" + "version '1.0'\n" + "\n" + "dependencies {\n" + "  compile 'org.sample:number-utils:1.0'\n" + "  compile 'org.sample:string-utils:1.0'\n" + "}\n" + "project(':api') {\n" + "  apply plugin: 'java'\n" + "  dependencies {\n" + "    compile 'commons-lang:commons-lang:2.6'\n" + "  }\n" + "}\n");
    createProjectSubFile("../my-utils/settings.gradle", "rootProject.name = 'my-utils'\n" + "include 'number-utils', 'string-utils', 'api'");
    createProjectSubFile("../my-utils/build.gradle", "subprojects {\n" + "  apply plugin: 'java'\n" + "\n" + "  group 'org.sample'\n" + "  version '1.0'\n" + "}\n" + "\n" + "project(':string-utils') {\n" + "  dependencies {\n" + "    compile 'org.apache.commons:commons-lang3:3.4'\n" + "  }\n" + "}\n" + "project(':api') {\n" + "  dependencies {\n" + "    compile 'junit:junit:4.11'\n" + "  }\n" + "}");
    importProject();
    assertModules("adhoc", "api", "api_main", "api_test", "my-app", "my-app_main", "my-app_test", "my-app-api", "my-app-api~1", "my-app-api_main", "my-utils", "string-utils", "string-utils_main", "string-utils_test", "number-utils", "number-utils_main", "number-utils_test", "my-utils-api", "my-utils-api_main", "my-utils-api_test");
    String[] emptyModules = new String[] { "api", "adhoc", "my-app", "my-app-api", "my-app-api_main", "my-app-api~1", "my-utils", "my-utils-api", "string-utils", "number-utils" };
    for (String rootModule : emptyModules) {
        assertModuleLibDeps(rootModule);
        assertModuleModuleDeps(rootModule);
    }
    assertModuleModuleDeps("my-app_main", "number-utils_main", "string-utils_main");
    assertModuleModuleDepScope("my-app_main", "number-utils_main", COMPILE);
    assertModuleModuleDepScope("my-app_main", "string-utils_main", COMPILE);
    assertModuleLibDepScope("my-app_main", "Gradle: org.apache.commons:commons-lang3:3.4", COMPILE);
    // my-app api project
    assertModuleModuleDeps("api_main");
    assertModuleLibDeps("api_main", "Gradle: commons-lang:commons-lang:2.6");
    assertModuleLibDepScope("api_main", "Gradle: commons-lang:commons-lang:2.6", COMPILE);
    assertModuleModuleDeps("my-utils-api_main");
    //assertModuleLibDeps("my-utils-api_main", "Gradle: junit:junit:4.11");
    assertModuleLibDepScope("my-utils-api_main", "Gradle: junit:junit:4.11", COMPILE);
//assertModuleLibDepScope("my-utils-api_main", "Gradle: org.hamcrest:hamcrest-core:1.3", COMPILE);
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) TargetVersions(org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions) Test(org.junit.Test)

Example 23 with IdeModifiableModelsProviderImpl

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

the class MavenFoldersImporter method updateProjectFolders.

public static void updateProjectFolders(final Project project, final boolean updateTargetFoldersOnly) {
    final MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    final MavenImportingSettings settings = manager.getImportingSettings();
    WriteAction.run(() -> {
        List<ModifiableRootModel> rootModels = new ArrayList<>();
        for (Module each : ModuleManager.getInstance(project).getModules()) {
            MavenProject mavenProject = manager.findProject(each);
            if (mavenProject == null)
                continue;
            MavenRootModelAdapter a = new MavenRootModelAdapter(mavenProject, each, new IdeModifiableModelsProviderImpl(project));
            new MavenFoldersImporter(mavenProject, settings, a).config(updateTargetFoldersOnly);
            ModifiableRootModel model = a.getRootModel();
            if (model.isChanged()) {
                rootModels.add(model);
            } else {
                model.dispose();
            }
        }
        if (!rootModels.isEmpty()) {
            ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels.get((0)).getProject()).getModifiableModel());
        }
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) ArrayList(java.util.ArrayList) MavenImportingSettings(org.jetbrains.idea.maven.project.MavenImportingSettings) Module(com.intellij.openapi.module.Module)

Example 24 with IdeModifiableModelsProviderImpl

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

the class ModuleModelDataServiceTest method testImportDataWithEmptyDataNodeCollection.

public void testImportDataWithEmptyDataNodeCollection() {
    Collection<DataNode<NdkModuleModel>> toImport = new ArrayList<>();
    Project project = getProject();
    IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(project);
    MyModuleModelDataService dataService = new MyModuleModelDataService();
    dataService.importData(toImport, mock(ProjectData.class), project, modelsProvider);
    assertTrue(dataService.onModelsNotFoundInvoked);
    assertFalse(dataService.importDataInvoked);
}
Also used : Project(com.intellij.openapi.project.Project) DataNode(com.intellij.openapi.externalSystem.model.DataNode) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) ArrayList(java.util.ArrayList) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 25 with IdeModifiableModelsProviderImpl

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

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