org.jetbrains.idea.maven.project.MavenProjectsManager Java Examples
The following examples show how to use
org.jetbrains.idea.maven.project.MavenProjectsManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MavenToolDelegate.java From intellij-quarkus with Eclipse Public License 2.0 | 6 votes |
@Override public void processImport(Module module) { Project project = module.getProject(); VirtualFile pomFile = null; VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots(); for(VirtualFile contentRoot : contentRoots) { VirtualFile child = contentRoot.findChild("pom.xml"); if (child != null) { pomFile = child; break; } } if (pomFile != null) { MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project); mavenProjectsManager.addManagedFiles(Collections.singletonList(pomFile)); } }
Example #2
Source File: MavenMonitor.java From spring-javaformat with Apache License 2.0 | 6 votes |
private void attachListener(MavenProjectsManager mavenProjectsManager) { mavenProjectsManager.addProjectsTreeListener(new Listener() { @Override public void projectsUpdated(List<Pair<MavenProject, MavenProjectChanges>> updated, List<MavenProject> deleted) { check(); } @Override public void projectResolved(Pair<MavenProject, MavenProjectChanges> projectWithChanges, NativeMavenProjectHolder nativeMavenProject) { check(); } @Override public void pluginsResolved(MavenProject project) { check(); } }); }
Example #3
Source File: SlingMavenModuleBuilder.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 6 votes |
public void setupRootModel(ModifiableRootModel rootModel) { final Project project = rootModel.getProject(); final VirtualFile root = createAndGetContentEntry(); rootModel.addContentEntry(root); // todo this should be moved to generic ModuleBuilder if (myJdk != null){ rootModel.setSdk(myJdk); } else { rootModel.inheritSdk(); } MavenUtil.runWhenInitialized( project, new DumbAwareRunnable() { public void run() { if (myEnvironmentForm != null) { myEnvironmentForm.setData(MavenProjectsManager.getInstance(project).getGeneralSettings()); } new MavenModuleBuilderHelper(myProjectId, myAggregatorProject, myParentProject, myInheritGroupId, myInheritVersion, archetypeTemplate.getMavenArchetype(), myPropertiesToCreateByArtifact, "Create new Sling Maven module").configure(project, root, false); } } ); }
Example #4
Source File: MuleBeforeRunTasksProvider.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private MavenProject getMavenProject(Module module) { //RunConfiguration runConfiguration, Project project) final MavenProjectsManager instance = MavenProjectsManager.getInstance(module.getProject()); return instance.findProject(module); // // if (runConfiguration instanceof MuleConfiguration) // { // MuleConfiguration muleConfiguration = (MuleConfiguration) runConfiguration; // return instance.findProject(muleConfiguration.getModule()); // } // return null; }
Example #5
Source File: CreateCustomGoalAction.java From MavenHelper with Apache License 2.0 | 5 votes |
public void actionPerformed(AnActionEvent e) { ApplicationService instance = ApplicationService.getInstance(); ApplicationSettings state = instance.getState(); DataContext context = e.getDataContext(); Project project = MavenActionUtil.getProject(context); String pomDir = Utils.getPomDirAsString(context, mavenProject); MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context); PsiFile data = LangDataKeys.PSI_FILE.getData(e.getDataContext()); ConfigurationContext configurationContext = ConfigurationContext.getFromContext(e.getDataContext()); GoalEditor editor = new GoalEditor("Create and Run", "", state, true, e.getProject(), e.getDataContext()); if (editor.showAndGet()) { String s = editor.getCmd(); if (StringUtils.isNotBlank(s)) { Goal goal = new Goal(s); PropertiesComponent.getInstance().setValue(GoalEditor.SAVE, editor.isPersist(), true); if (editor.isPersist()) { state.getGoals().add(goal); instance.registerAction(goal, getRunGoalAction(goal)); } if (runGoal) { getRunGoalAction(goal).actionPerformed(project, pomDir, projectsManager, data, configurationContext); } } } }
Example #6
Source File: RunGoalAction.java From MavenHelper with Apache License 2.0 | 5 votes |
public void actionPerformed(Project project, String pomDir, MavenProjectsManager projectsManager, PsiFile psiFile, ConfigurationContext configurationContext) { if (pomDir != null) { List<String> goalsToRun = goal.parse(psiFile, configurationContext); MavenRunnerParameters params = new MavenRunnerParameters(true, pomDir, null, goalsToRun, projectsManager.getExplicitProfiles()); params.setResolveToWorkspace(ApplicationSettings.get().isResolveWorkspaceArtifacts()); run(params, project); } }
Example #7
Source File: RunGoalAction.java From MavenHelper with Apache License 2.0 | 5 votes |
public void actionPerformed(AnActionEvent e) { final DataContext context = e.getDataContext(); Project project = MavenActionUtil.getProject(context); String pomDir = Utils.getPomDirAsString(context, mavenProject); MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context); PsiFile data = LangDataKeys.PSI_FILE.getData(e.getDataContext()); ConfigurationContext configurationContext = ConfigurationContext.getFromContext(e.getDataContext()); actionPerformed(project, pomDir, projectsManager, data, configurationContext); }
Example #8
Source File: MainMavenActionGroup.java From MavenHelper with Apache License 2.0 | 5 votes |
private void addPluginGoals(Project project, MavenPlugin mavenPlugin, DefaultActionGroup pluginGroup, MavenProjectInfo mavenProject) { MavenPluginInfo pluginInfo = MavenArtifactUtil.readPluginInfo( MavenProjectsManager.getInstance(project).getLocalRepository(), mavenPlugin.getMavenId()); if (pluginInfo != null) { for (MavenPluginInfo.Mojo mojo : pluginInfo.getMojos()) { pluginGoalsSet.add(mojo.getDisplayName()); pluginGroup.add(createGoalRunAction(new Goal(mojo.getDisplayName()), MyIcons.PLUGIN_GOAL, true, mavenProject)); } } }
Example #9
Source File: MyReimportProjectAction.java From MavenHelper with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { final DataContext context = e.getDataContext(); MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context); if (projectsManager != null) { perform(projectsManager, Arrays.asList(mavenProject.mavenProject), e); } }
Example #10
Source File: RootMavenActionGroup.java From MavenHelper with Apache License 2.0 | 5 votes |
@NotNull @Override protected MavenProjectInfo getMavenProject(DataContext dataContext) { MavenProject mavenProject = MavenActionUtil.getMavenProject(dataContext); if (mavenProject == null) { return new MavenProjectInfo(null, false); } MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(dataContext); List<MavenProject> rootProjects = projectsManager.getRootProjects(); MavenProject root = null; if (rootProjects.contains(mavenProject)) { root = mavenProject; } else { MavenId parentId = mavenProject.getParentId(); while (parentId != null) { mavenProject = projectsManager.findProject(parentId); if (mavenProject == null) { break; } if (rootProjects.contains(mavenProject)) { root = mavenProject; break; } parentId = mavenProject.getParentId(); } } return new MavenProjectInfo(root, true); }
Example #11
Source File: BaseAction.java From MavenHelper with Apache License 2.0 | 5 votes |
private static VirtualFile getVirtualFile(MavenArtifactNode myArtifactNode, Project project, MavenProject mavenProject) { final MavenArtifactNode parent = myArtifactNode.getParent(); final VirtualFile file; if (parent == null) { file = mavenProject.getFile(); } else { // final MavenId id = parent.getArtifact().getMavenId(); //this doesn't work for snapshots MavenArtifact artifact = parent.getArtifact(); final MavenId id = new MavenId(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); final MavenProject pr = MavenProjectsManager.getInstance(project).findProject(id); file = pr == null ? MavenNavigationUtil.getArtifactFile(project, id) : pr.getFile(); } return file; }
Example #12
Source File: MyFileEditorProvider.java From MavenHelper with Apache License 2.0 | 5 votes |
private boolean isPomFile(@NotNull final Project project, @NotNull final VirtualFile file) { final String path = file.getPath(); if (!path.endsWith("/" + MavenConstants.POM_XML)) return false; MavenProjectsManager instance = MavenProjectsManager.getInstance(project); final MavenProject mavenProject = instance == null ? null : instance.findProject(file); if (mavenProject != null) { return mavenProject.getPath().equals(path); } return false; }
Example #13
Source File: UIFormEditor.java From MavenHelper with Apache License 2.0 | 5 votes |
public UIFormEditor(final Project project, final VirtualFile file) { final MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(file); if (mavenProject == null) { throw new RuntimeException("Report this bug please. MavenProject not found for file " + file.getPath()); } myEditor = new GuiForm(project, file, mavenProject); }
Example #14
Source File: ArchetypePropertiesStep.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
private void initComponents() { myEnvironmentForm = new MavenEnvironmentForm(); Project project = myProjectOrNull == null ? ProjectManager.getInstance().getDefaultProject() : myProjectOrNull; myEnvironmentForm.getData(MavenProjectsManager.getInstance(project).getGeneralSettings().clone()); myEnvironmentPanel.add(myEnvironmentForm.createComponent(), BorderLayout.CENTER); //AS TODO: If we keep on using the archetype properties we might add a description to the Required Properties //AS TODO: but then we need to copy this class over and add the description to the dialog. myMavenPropertiesPanel = new MavenPropertiesPanel(myAvailableProperties); myPropertiesPanel.add(myMavenPropertiesPanel); doFillIn.setSelected(true); artifactName.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent keyEvent) { super.keyReleased(keyEvent); if(doFillIn.isSelected()) { updateProperties(); } } } ); artifactName.addFocusListener( new FocusAdapter() { @Override public void focusLost(FocusEvent focusEvent) { super.focusLost(focusEvent); if(doFillIn.isSelected()) { updateProperties(); } } } ); }
Example #15
Source File: SpringBootModuleBuilder.java From crud-intellij-plugin with Apache License 2.0 | 5 votes |
private void initProject(Project project, Selection selection) throws Exception { initMavenStructure(); //pom.xml生成 PsiFileUtils.createPOMXML(project, createAndGetContentEntry(), selection); //swagger生成 PsiFileUtils.createSwagger(project, createPackageDir(selection.getPackage() + ".config"), selection); //Application类生成 PsiFileUtils.createApplicationJava(project, createPackageDir(selection.getPackage()), selection); //application.yml配置生成 PsiFileUtils.createApplicationYml(project, createResourceDir("/"), selection); selection.setModelPackage(selection.getPackage() + ".model"); selection.setDaoPackage(selection.getPackage() + ".dao"); if (selection.getOrmType() == SelectionContext.MYBATIS) { selection.setMapperDir(getContentEntryPath() + "/src/main/resources/mapper"); } selection.setServicePackage(selection.getPackage() + ".service"); selection.setControllerPackage(selection.getPackage() + ".controller"); PsiFileUtils.createCrud(project, selection, getContentEntryPath()); //解决依赖 try { MavenProjectsManager.getInstance(project).forceUpdateAllProjectsOrFindAllAvailablePomFiles(); } catch (Exception ignored) { } //优化生成的所有Java类 CrudUtils.doOptimize(project); }
Example #16
Source File: MuleAppManager.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
@NotNull public File getMuleApp(@NotNull Module module) throws ExecutionException { final MavenProjectsManager instance = MavenProjectsManager.getInstance(module.getProject()); if (instance.hasProjects()) { return new MuleAppMavenHandler().getMuleApp(module); } throw new ExecutionException("Unable to find application builder"); }
Example #17
Source File: MavenModuleBuilderPostProcessor.java From intellij-spring-assistant with MIT License | 5 votes |
@Override public boolean postProcess(Module module) { // TODO: Find a way to use GradleModuleBuilder instead of GradleProjectImportBuilder when adding a child module to the parent Project project = module.getProject(); VirtualFile pomFile = findFileUnderRootInModule(module, "pom.xml"); if (pomFile == null) { // not a maven project return true; } else { MavenProjectsManager mavenProjectsManager = getInstance(project); mavenProjectsManager.addManagedFiles(singletonList(pomFile)); return false; } }
Example #18
Source File: MavenToolDelegate.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
@Override public List<VirtualFile>[] getDeploymentFiles(Module module) { MavenProject mavenProject = MavenProjectsManager.getInstance(module.getProject()).findProject(module); List<VirtualFile>[] result = ToolDelegate.initDeploymentFiles(); if (mavenProject != null) { getDeploymentFiles(module, mavenProject, result); } return result; }
Example #19
Source File: MuleBeforeRunTasksProvider.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
@Override public boolean executeTask(DataContext dataContext, RunConfiguration runConfiguration, ExecutionEnvironment executionEnvironment, MuleBeforeRunTask muleBeforeRunTask) { final Semaphore targetDone = new Semaphore(); final List<Boolean> results = new ArrayList<>(); final Project project = executionEnvironment.getProject(); MuleConfiguration muleConfiguration = (MuleConfiguration) runConfiguration; Module[] modules = muleConfiguration.getModules(); for (Module nextModule : modules) { //final MavenProject mavenProject = getMavenProject(runConfiguration, project); final MavenProject mavenProject = getMavenProject(nextModule); try { ApplicationManager.getApplication().invokeAndWait(new Runnable() { public void run() { if (!project.isDisposed() && mavenProject != null) { FileDocumentManager.getInstance().saveAllDocuments(); final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles(); final MavenRunner mavenRunner = MavenRunner.getInstance(project); targetDone.down(); (new Task.Backgroundable(project, TasksBundle.message("maven.tasks.executing"), true) { public void run(@NotNull ProgressIndicator indicator) { try { MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), ParametersListUtil.parse("package"), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles()); boolean result = mavenRunner.runBatch(Collections.singletonList(params), null, null, TasksBundle.message("maven.tasks.executing"), indicator); results.add(result); } finally { targetDone.up(); } } public boolean shouldStartInBackground() { return MavenRunner.getInstance(project).getSettings().isRunMavenInBackground(); } public void processSentToBackground() { MavenRunner.getInstance(project).getSettings().setRunMavenInBackground(true); } }).queue(); } } }, ModalityState.NON_MODAL); } catch (Exception exeception) { return false; } targetDone.waitFor(); } boolean endResult = true; for (Boolean nextResult : results) { endResult = endResult && nextResult; } return endResult; }
Example #20
Source File: RoboVmModuleBuilder.java From robovm-idea with GNU General Public License v2.0 | 4 votes |
private void applyBuildSystem(final Project project) { if (buildSystem == BuildSystem.Gradle) { File baseDir = VfsUtilCore.virtualToIoFile(project.getBaseDir()); File[] files = baseDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return FileUtil.namesEqual("build.gradle", name); } }); if (files != null && files.length != 0) { project.putUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT, Boolean.TRUE); ProjectDataManager projectDataManager = (ProjectDataManager) ServiceManager .getService(ProjectDataManager.class); GradleProjectImportBuilder gradleProjectImportBuilder = new GradleProjectImportBuilder( projectDataManager); gradleProjectImportBuilder.getControl(project).getProjectSettings() .setDistributionType(DistributionType.WRAPPED); GradleProjectImportProvider gradleProjectImportProvider = new GradleProjectImportProvider( gradleProjectImportBuilder); AddModuleWizard wizard = new AddModuleWizard((Project) null, files[0].getPath(), new ProjectImportProvider[] { gradleProjectImportProvider }); if (wizard.getStepCount() <= 0 || wizard.showAndGet()) { ImportModuleAction.createFromWizard(project, wizard); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { ModifiableModuleModel modifiableModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : modifiableModel.getModules()) { try { LanguageLevelModuleExtensionImpl langModel = (LanguageLevelModuleExtensionImpl) LanguageLevelModuleExtensionImpl.getInstance(module).getModifiableModel(true); langModel.setLanguageLevel(LanguageLevel.JDK_1_8); langModel.commit(); } catch(Throwable t) { // could be a non-Java project t.printStackTrace(); } } modifiableModel.commit(); } }); } } } else { FileDocumentManager.getInstance().saveAllDocuments(); MavenProjectsManager.getInstance(project).forceUpdateAllProjectsOrFindAllAvailablePomFiles(); } }
Example #21
Source File: TalendModuleBuilder.java From component-runtime with Apache License 2.0 | 4 votes |
@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); // todo: move to JavaGradleProjectImportBuilder 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; }
Example #22
Source File: GoalEditor.java From MavenHelper with Apache License 2.0 | 4 votes |
public GoalEditor(String title, String initialValue, ApplicationSettings applicationSettings, boolean persist, Project project, DataContext dataContext) { super(true); setTitle(title); saveGoalCheckBox.setSelected(PropertiesComponent.getInstance().getBoolean(SAVE, true)); saveGoalCheckBox.setVisible(persist); try { // optionsPanel.add(new JBLabel("Append:")); // optionsPanel.setLayout(new WrapLayout()); optionsPanel.add(getLinkLabel("-DskipTests", null)); optionsPanel.add(getLinkLabel(new ListItem("--update-snapshots", "Forces a check for updated releases and snapshots on remote repositories"))); optionsPanel.add(getLinkLabel(new ListItem("--offline", "Work offline"))); optionsPanel.add(getLinkLabel(new ListItem("--debug", "Produce execution debug output"))); optionsPanel.add(getLinkLabel(new ListItem("--non-recursive", "Do not recurse into sub-projects"))); // optionsPanel2.setLayout(new WrapLayout()); optionsPanel2.add(listPopup("Option...", getOptions(false), false)); optionsPanel2.add(listPopup("Short Option...", getOptions(true), true)); optionsPanel2.add(listPopup("Alias...", toListItems(applicationSettings.getAliases().getAliases()), false)); // goalsPanel.add(new JBLabel("Goals:")); // goalsPanel.setLayout(new WrapLayout()); goalsPanel.add(listPopup("Lifecycle Goal...", getGoals(), false)); goalsPanel.add(listPopup("Existing Goal...", getExistingGoals(applicationSettings), false)); goalsPanel.add(listPopup("Util...", getHelpfulGoals(), false)); if (dataContext != null) { MavenProject mavenProject = MavenActionUtil.getMavenProject(dataContext); if (mavenProject != null) { List<ListItem> listItems = new ArrayList<>(); for (MavenPlugin mavenPlugin : mavenProject.getDeclaredPlugins()) { MavenPluginInfo pluginInfo = MavenArtifactUtil.readPluginInfo( MavenProjectsManager.getInstance(project).getLocalRepository(), mavenPlugin.getMavenId()); if (pluginInfo != null) { boolean first = true; for (MavenPluginInfo.Mojo mojo : pluginInfo.getMojos()) { ListItem listItem = new ListItem(mojo.getDisplayName()); if (first) { listItem.separatorAbove = new ListItem(mavenPlugin.getArtifactId()); } listItems.add(listItem); first = false; } } } goalsPanel.add(listPopup("Plugin Goal...", listItems.toArray(new ListItem[0]), false)); } } } catch (Throwable e) { LOG.error(Objects.toString(e), e); } // aliasesPanel.add(new JBLabel("Aliases:")); init(); myEditor.getDocument().addDocumentListener(new DocumentListener() { @Override public void documentChanged(@NotNull DocumentEvent event) { updateControls(); } }); append(initialValue); updateControls(); // IdeFocusManager.findInstanceByComponent(mainPanel).requestFocus(myEditor.getComponent(), true); }
Example #23
Source File: MavenMonitor.java From spring-javaformat with Apache License 2.0 | 4 votes |
public static Factory factory() { return (project, trigger) -> { MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project); return (mavenProjectsManager == null ? null : new MavenMonitor(project, trigger, mavenProjectsManager)); }; }
Example #24
Source File: MavenMonitor.java From spring-javaformat with Apache License 2.0 | 4 votes |
public MavenMonitor(Project project, Trigger trigger, MavenProjectsManager mavenProjectsManager) { super(project, trigger); this.mavenProjectsManager = mavenProjectsManager; attachListener(mavenProjectsManager); check(); }
Example #25
Source File: MavenTestCase.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
protected MavenImportingSettings getMavenImporterSettings() { return MavenProjectsManager.getInstance(myProject).getImportingSettings(); }
Example #26
Source File: MavenTestCase.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
protected MavenGeneralSettings getMavenGeneralSettings() { return MavenProjectsManager.getInstance(myProject).getGeneralSettings(); }
Example #27
Source File: MavenImportingTestCase.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
@Override protected void setUpInWriteAction() throws Exception { super.setUpInWriteAction(); myProjectsManager = MavenProjectsManager.getInstance(myProject); removeFromLocalRepository("test"); }