use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class MavenShowEffectivePom method actionPerformed.
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, s -> ApplicationManager.getApplication().invokeLater(() -> {
if (project.isDisposed())
return;
if (s == null) {
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 file1 = PsiFileFactory.getInstance(project).createFileFromText(fileName, XMLLanguage.INSTANCE, s);
try {
file1.getVirtualFile().setWritable(false);
} catch (IOException e) {
LOG.error(e);
}
file1.navigate(true);
}));
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class OpenOrCreateSettingsXmlAction method getFiles.
protected List<File> getFiles(AnActionEvent e) {
final MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e.getDataContext());
if (projectsManager == null)
return Collections.emptyList();
File file = projectsManager.getGeneralSettings().getEffectiveUserSettingsIoFile();
return file != null ? Collections.singletonList(file) : Collections.emptyList();
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class ToggleIgnoredProjectsAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final DataContext context = e.getDataContext();
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
if (projectsManager == null)
return;
List<MavenProject> projects = MavenActionUtil.getMavenProjects(context);
final Project project = MavenActionUtil.getProject(context);
if (project == null)
return;
if (isIgnoredInSettings(projectsManager, projects)) {
ShowSettingsUtil.getInstance().editConfigurable(project, new MavenIgnoredFilesConfigurable(project));
} else {
projectsManager.setIgnoredState(projects, !isIgnored(projectsManager, projects));
}
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class ToggleIgnoredProjectsAction method update.
@Override
public void update(AnActionEvent e) {
super.update(e);
if (!isAvailable(e))
return;
final DataContext context = e.getDataContext();
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
if (projectsManager == null)
return;
List<MavenProject> projects = MavenActionUtil.getMavenProjects(context);
if (isIgnoredInSettings(projectsManager, projects)) {
e.getPresentation().setText(ProjectBundle.message("maven.ignore.edit"));
} else if (isIgnored(projectsManager, projects)) {
e.getPresentation().setText(ProjectBundle.message("maven.unignore"));
} else {
e.getPresentation().setText(ProjectBundle.message("maven.ignore"));
}
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class MavenModuleBuilderHelper method configure.
public void configure(final Project project, final VirtualFile root, final boolean isInteractive) {
PsiFile[] psiFiles = myAggregatorProject != null ? new PsiFile[] { getPsiFile(project, myAggregatorProject.getFile()) } : PsiFile.EMPTY_ARRAY;
final VirtualFile pom = new WriteCommandAction<VirtualFile>(project, myCommandName, psiFiles) {
@Override
protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
VirtualFile file;
try {
file = root.createChildData(this, MavenConstants.POM_XML);
MavenUtil.runOrApplyMavenProjectFileTemplate(project, file, myProjectId, isInteractive);
result.setResult(file);
} catch (IOException e) {
showError(project, e);
return;
}
updateProjectPom(project, file);
if (myAggregatorProject != null) {
MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(project, myAggregatorProject.getFile());
if (model != null) {
model.getPackaging().setStringValue("pom");
MavenDomModule module = model.getModules().addModule();
module.setValue(getPsiFile(project, file));
}
}
}
}.execute().getResultObject();
if (pom == null)
return;
if (myAggregatorProject == null) {
MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
manager.addManagedFilesOrUnignore(Collections.singletonList(pom));
}
if (myArchetype == null) {
try {
VfsUtil.createDirectories(root.getPath() + "/src/main/java");
VfsUtil.createDirectories(root.getPath() + "/src/main/resources");
VfsUtil.createDirectories(root.getPath() + "/src/test/java");
} catch (IOException e) {
MavenLog.LOG.info(e);
}
}
// execute when current dialog is closed (e.g. Project Structure)
MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> {
if (!pom.isValid())
return;
EditorHelper.openInEditor(getPsiFile(project, pom));
if (myArchetype != null)
generateFromArchetype(project, pom);
});
}
Aggregations