Search in sources :

Example 51 with MavenProjectsManager

use of org.jetbrains.idea.maven.project.MavenProjectsManager in project moe-ide-integration by multi-os-engine.

the class MOEMavenTask method getMavenProject.

private MavenProject getMavenProject() {
    String pomXmlPath = findPomXml(module);
    if (pomXmlPath == null || pomXmlPath.isEmpty()) {
        return null;
    }
    VirtualFile file = LocalFileSystem.getInstance().findFileByPath(pomXmlPath);
    if (file == null)
        return null;
    MavenProjectsManager manager = MavenProjectsManager.getInstance(module.getProject());
    if (manager == null) {
        return null;
    }
    return manager.findProject(file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager)

Example 52 with MavenProjectsManager

use of org.jetbrains.idea.maven.project.MavenProjectsManager in project component-runtime by Talend.

the class TalendModuleBuilder method createModule.

@Override
public Module createModule(final ModifiableModuleModel moduleModel) throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, ConfigurationException, JDOMException {
    final Module module = super.createModule(moduleModel);
    getApplication().invokeLater(() -> {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final ProjectDownloader downloader = new ProjectDownloader(this, request);
            try {
                downloader.download(ProgressManager.getInstance().getProgressIndicator());
            } catch (IOException e) {
                getApplication().invokeLater(() -> MessagesEx.showErrorDialog(e.getMessage(), getMessage("download.project.file.error")));
            }
        }, getMessage("download.project.file"), true, null);
        final Project moduleProject = module.getProject();
        switch(jsonProject.get("buildType").getAsString()) {
            case "Maven":
                final VirtualFile pomFile = findFileUnderRootInModule(module, "pom.xml");
                if (pomFile != null) {
                    final MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(moduleProject);
                    mavenProjectsManager.addManagedFiles(singletonList(pomFile));
                }
                break;
            case "Gradle":
                final VirtualFile gradleFile = findFileUnderRootInModule(module, "build.gradle");
                if (gradleFile != null) {
                    final ProjectDataManager projectDataManager = getService(ProjectDataManager.class);
                    final GradleProjectImportBuilder importBuilder = new GradleProjectImportBuilder(projectDataManager);
                    final GradleProjectImportProvider importProvider = new GradleProjectImportProvider(importBuilder);
                    final AddModuleWizard addModuleWizard = new AddModuleWizard(moduleProject, gradleFile.getPath(), importProvider);
                    if (addModuleWizard.getStepCount() == 0 && addModuleWizard.showAndGet()) {
                        // user chose to import via the gradle import prompt
                        importBuilder.commit(moduleProject, null, null);
                    }
                }
                break;
            default:
                break;
        }
    }, ModalityState.current());
    return module;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GradleProjectImportProvider(org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportProvider) ProjectDataManager(com.intellij.openapi.externalSystem.service.project.ProjectDataManager) GradleProjectImportBuilder(org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportBuilder) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) AddModuleWizard(com.intellij.ide.util.newProjectWizard.AddModuleWizard) IOException(java.io.IOException) Module(com.intellij.openapi.module.Module) FileUtil.findFileUnderRootInModule(org.talend.sdk.component.intellij.util.FileUtil.findFileUnderRootInModule)

Aggregations

MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)52 MavenProject (org.jetbrains.idea.maven.project.MavenProject)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Project (com.intellij.openapi.project.Project)13 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 Nullable (org.jetbrains.annotations.Nullable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)6 PsiFile (com.intellij.psi.PsiFile)6 Notification (com.intellij.notification.Notification)4 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)4 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)4 NotificationListener (com.intellij.notification.NotificationListener)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 XmlElement (com.intellij.psi.xml.XmlElement)2 List (java.util.List)2