protected void readProjects(VirtualFile... files) { List<MavenProject> projects = new ArrayList<MavenProject>(); for (VirtualFile each : files) { projects.add(myProjectsManager.findProject(each)); } myProjectsManager.forceUpdateProjects(projects); waitForReadingCompletion(); }
@Nullable public static MavenProject findProject(@NotNull MavenDomProjectModel projectDom) { XmlElement element = projectDom.getXmlElement(); if (element == null) return null; VirtualFile file = getVirtualFile(element); if (file == null) return null; MavenProjectsManager manager = MavenProjectsManager.getInstance(element.getProject()); return manager.findProject(file); }
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { GenericDomValue el = (GenericDomValue) myContext.getInvocationElement(); MavenId id = MavenArtifactCoordinatesHelper.getId(myContext); MavenProjectsManager manager = MavenProjectsManager.getInstance(project); MavenProject parentFile = manager.findProject(id); if (parentFile != null) { VirtualFile currentFile = myContext.getFile().getVirtualFile(); el.setStringValue( MavenDomUtil.calcRelativePath(currentFile.getParent(), parentFile.getFile())); } }
private static File dumpModulesPaths(@NotNull Project project) throws IOException { ApplicationManager.getApplication().assertReadAccessAllowed(); Properties res = new Properties(); MavenProjectsManager manager = MavenProjectsManager.getInstance(project); for (Module module : ModuleManager.getInstance(project).getModules()) { if (manager.isMavenizedModule(module)) { MavenProject mavenProject = manager.findProject(module); if (mavenProject != null && !manager.isIgnored(mavenProject)) { res.setProperty( mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ":pom" + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getFile().getPath()); res.setProperty( mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ':' + mavenProject.getPackaging() + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getOutputDirectory()); } } } File file = new File( PathManager.getSystemPath(), "Maven/idea-projects-state-" + project.getLocationHash() + ".properties"); file.getParentFile().mkdirs(); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { res.store(out, null); } finally { out.close(); } return file; }
public static void actionPerformed( @NotNull final Project project, @NotNull final VirtualFile file) { final MavenProjectsManager manager = MavenProjectsManager.getInstance(project); final MavenProject mavenProject = manager.findProject(file); assert mavenProject != null; manager.evaluateEffectivePom( mavenProject, new NullableConsumer<String>() { @Override public void consume(final String s) { ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { if (project.isDisposed()) return; if (s == null) { // null means UnsupportedOperationException new Notification( MavenUtil.MAVEN_NOTIFICATION_GROUP, "Error", "Failed to evaluate effective pom.", NotificationType.ERROR) .notify(project); return; } String fileName = mavenProject.getMavenId().getArtifactId() + "-effective-pom.xml"; PsiFile file = PsiFileFactory.getInstance(project) .createFileFromText(fileName, XMLLanguage.INSTANCE, s); try { //noinspection ConstantConditions file.getVirtualFile().setWritable(false); } catch (IOException e) { LOG.error(e); } file.navigate(true); } }); } }); }
private static void notifyUserIfNeeded( DataContext context, MavenProjectsManager projectsManager, List<VirtualFile> selectedFiles, VirtualFile pomXml) { MavenProject mavenProject = projectsManager.findProject(pomXml); assert mavenProject != null; MavenProject aggregator = projectsManager.findAggregator(mavenProject); while (aggregator != null && !projectsManager.isManagedFile(aggregator.getFile())) { aggregator = projectsManager.findAggregator(aggregator); } if (aggregator != null && !selectedFiles.contains(aggregator.getFile())) { notifyUser(context, mavenProject, aggregator); } }
@Nullable private static VirtualFile findPomXml(@NotNull DataContext dataContext) { VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); if (file == null) return null; if (file.isDirectory()) { file = file.findChild("pom.xml"); if (file == null) return null; } MavenProjectsManager manager = MavenActionUtil.getProjectsManager(dataContext); if (manager == null) return null; MavenProject mavenProject = manager.findProject(file); if (mavenProject == null) return null; return file; }
private MavenRunnerParameters createBuildParameters(Location l) { final PsiElement element = l.getPsiElement(); final Project project = l.getProject(); final Module module = ModuleUtil.findModuleForPsiElement(element); if (module == null) return null; final MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project); final MavenProject mavenProject = mavenProjectsManager.findProject(module); if (mavenProject == null) return null; // todo: check this code final List<MavenArtifact> dependencies = mavenProject.getDependencies(); MavenArtifact artifact = null; for (MavenArtifact dependence : dependencies) { if (dependence.getArtifactId().equals(GROUP_ID_LIFT)) { artifact = dependence; break; } else if (dependence.getArtifactId().equals(ARTIFACT_ID_LIFT)) { artifact = dependence; break; } } // final MavenArtifact artifact = mavenProjectModel.findDependency(GROUP_ID_LIFT, // ARTIFACT_ID_LIFT); if (artifact == null) return null; mySourceElement = element; MavenExplicitProfiles profiles = MavenProjectsManager.getInstance(project).getExplicitProfiles(); List<String> goals = new ArrayList<String>(); goals.add(JETTY_RUN); final VirtualFile file = module.getModuleFile(); if (file == null) return null; final VirtualFile parent = file.getParent(); if (parent == null) return null; return new MavenRunnerParameters(true, parent.getPath(), goals, profiles); }
private static boolean isExistingProjectFile(DataContext context, VirtualFile file) { MavenProjectsManager manager = MavenActionUtil.getProjectsManager(context); return manager.findProject(file) != null; }
protected VirtualFile findManagedFile(@NotNull MavenId id) { MavenProject project = myManager.findProject(id); return project == null ? null : project.getFile(); }