use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenDuplicateDependenciesInspection method checkFileElement.
@Override
public void checkFileElement(DomFileElement<MavenDomProjectModel> domFileElement, DomElementAnnotationHolder holder) {
MavenDomProjectModel projectModel = domFileElement.getRootElement();
checkManagedDependencies(projectModel, holder);
checkDependencies(projectModel, holder);
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenDuplicateDependenciesInspection method addProblem.
private static void addProblem(@NotNull MavenDomDependency dependency, @NotNull Collection<MavenDomDependency> dependencies, @NotNull DomElementAnnotationHolder holder) {
StringBuilder sb = new StringBuilder();
Set<MavenDomProjectModel> processed = new HashSet<>();
for (MavenDomDependency domDependency : dependencies) {
if (dependency.equals(domDependency))
continue;
MavenDomProjectModel model = domDependency.getParentOfType(MavenDomProjectModel.class, false);
if (model != null && !processed.contains(model)) {
if (processed.size() > 0)
sb.append(", ");
sb.append(createLinkText(model, domDependency));
processed.add(model);
}
}
holder.createProblem(dependency, HighlightSeverity.WARNING, MavenDomBundle.message("MavenDuplicateDependenciesInspection.has.duplicates", sb.toString()));
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class AddMavenDependencyQuickFix method invoke.
public void invoke(@NotNull final Project project, Editor editor, final PsiFile file) throws IncorrectOperationException {
if (!myRef.isValid())
return;
MavenProject mavenProject = MavenDomUtil.findContainingProject(file);
if (mavenProject == null)
return;
final List<MavenId> ids = MavenArtifactSearchDialog.searchForClass(project, getReferenceText());
if (ids.isEmpty())
return;
final MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(project, mavenProject.getFile());
if (model == null)
return;
new WriteCommandAction(project, "Add Maven Dependency", DomUtil.getFile(model)) {
@Override
protected void run(@NotNull Result result) throws Throwable {
boolean isTestSource = false;
VirtualFile virtualFile = file.getOriginalFile().getVirtualFile();
if (virtualFile != null) {
isTestSource = ProjectRootManager.getInstance(project).getFileIndex().isInTestSourceContent(virtualFile);
}
for (MavenId each : ids) {
MavenDomDependency dependency = MavenDomUtil.createDomDependency(model, null, each);
if (isTestSource) {
dependency.getScope().setStringValue("test");
}
}
}
}.execute();
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenParentRelativePathConverter method getVariants.
@NotNull
@Override
public Collection<PsiFile> getVariants(ConvertContext context) {
List<PsiFile> result = new ArrayList<>();
PsiFile currentFile = context.getFile().getOriginalFile();
for (DomFileElement<MavenDomProjectModel> each : MavenDomUtil.collectProjectModels(context.getFile().getProject())) {
PsiFile file = each.getOriginalFile();
if (file == currentFile)
continue;
result.add(file);
}
return result;
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel 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