Search in sources :

Example 6 with MavenDomProjectModel

use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.

the class MavenSourceDirectoryConverter method isSoft.

@Override
public boolean isSoft(@NotNull DomElement element) {
    DomElement buildElement = element.getParent();
    if (!(buildElement instanceof MavenDomBuild)) {
        return false;
    }
    DomElement mavenProject = buildElement.getParent();
    if (!(mavenProject instanceof MavenDomProjectModel)) {
        return false;
    }
    return "pom".equals(((MavenDomProjectModel) mavenProject).getPackaging().getStringValue());
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) DomElement(com.intellij.util.xml.DomElement) MavenDomBuild(org.jetbrains.idea.maven.dom.model.MavenDomBuild)

Example 7 with MavenDomProjectModel

use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.

the class MavenDuplicatePluginInspection method checkFileElement.

@Override
public void checkFileElement(DomFileElement<MavenDomProjectModel> domFileElement, DomElementAnnotationHolder holder) {
    MavenDomProjectModel projectModel = domFileElement.getRootElement();
    MultiMap<Pair<String, String>, MavenDomPlugin> duplicates = MultiMap.createSet();
    for (MavenDomPlugin plugin : projectModel.getBuild().getPlugins().getPlugins()) {
        String groupId = plugin.getGroupId().getStringValue();
        String artifactId = plugin.getArtifactId().getStringValue();
        if (StringUtil.isEmptyOrSpaces(artifactId))
            continue;
        if ("".equals(groupId) || "org.apache.maven.plugins".equals(groupId) || "org.codehaus.mojo".equals(groupId)) {
            groupId = null;
        }
        duplicates.putValue(Pair.create(groupId, artifactId), plugin);
    }
    for (Map.Entry<Pair<String, String>, Collection<MavenDomPlugin>> entry : duplicates.entrySet()) {
        Collection<MavenDomPlugin> set = entry.getValue();
        if (set.size() <= 1)
            continue;
        for (MavenDomPlugin dependency : set) {
            holder.createProblem(dependency, HighlightSeverity.WARNING, "Duplicated plugin declaration");
        }
    }
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) MavenDomPlugin(org.jetbrains.idea.maven.dom.model.MavenDomPlugin) Collection(java.util.Collection) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) Pair(com.intellij.openapi.util.Pair)

Example 8 with MavenDomProjectModel

use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.

the class MavenRedundantGroupIdInspection method checkFile.

@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    if (file instanceof XmlFile && (file.isPhysical() || ApplicationManager.getApplication().isUnitTestMode())) {
        DomFileElement<MavenDomProjectModel> model = DomManager.getDomManager(file.getProject()).getFileElement((XmlFile) file, MavenDomProjectModel.class);
        if (model != null) {
            MavenDomProjectModel projectModel = model.getRootElement();
            String groupId = projectModel.getGroupId().getStringValue();
            if (groupId != null && groupId.length() > 0) {
                MavenDomParent parent = projectModel.getMavenParent();
                String parentGroupId = parent.getGroupId().getStringValue();
                if (groupId.equals(parentGroupId)) {
                    XmlTag xmlTag = projectModel.getGroupId().getXmlTag();
                    LocalQuickFix fix = new LocalQuickFixBase("Remove unnecessary <groupId>") {

                        @Override
                        public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
                            descriptor.getPsiElement().delete();
                        }
                    };
                    return new ProblemDescriptor[] { manager.createProblemDescriptor(xmlTag, "Definition of groupId is redundant, because it's inherited from the parent", fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly) };
                }
            }
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) XmlFile(com.intellij.psi.xml.XmlFile) MavenDomParent(org.jetbrains.idea.maven.dom.model.MavenDomParent) NotNull(org.jetbrains.annotations.NotNull) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with MavenDomProjectModel

use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.

the class ExtractManagedDependenciesAction method findDependencyAndParent.

private static Pair<MavenDomDependency, Set<MavenDomProjectModel>> findDependencyAndParent(PsiFile file, Editor editor) {
    final MavenDomDependency dependency = DomUtil.findDomElement(file.findElementAt(editor.getCaretModel().getOffset()), MavenDomDependency.class);
    if (dependency == null || isManagedDependency(dependency))
        return null;
    Set<MavenDomProjectModel> parents = getParentProjects(file);
    if (parents.isEmpty())
        return null;
    return Pair.create(dependency, parents);
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) MavenDomDependency(org.jetbrains.idea.maven.dom.model.MavenDomDependency)

Example 10 with MavenDomProjectModel

use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.

the class SelectMavenProjectDialog method updateControls.

private void updateControls() {
    MavenDomProjectModel project = getSelectedProject();
    Integer count = myOccurrencesCountFunction.fun(project).size();
    myReplaceAllCheckBox.setText(RefactoringBundle.message("replace.all.occurences", count));
    myReplaceAllCheckBox.setEnabled(count != 0);
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)

Aggregations

MavenDomProjectModel (org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)5 MavenDomDependency (org.jetbrains.idea.maven.dom.model.MavenDomDependency)5 Nullable (org.jetbrains.annotations.Nullable)4 PsiFile (com.intellij.psi.PsiFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 DomElement (com.intellij.util.xml.DomElement)3 MavenProject (org.jetbrains.idea.maven.project.MavenProject)3 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 MavenId (org.jetbrains.idea.maven.model.MavenId)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 IProperty (com.intellij.lang.properties.IProperty)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 Pair (com.intellij.openapi.util.Pair)1 TextRange (com.intellij.openapi.util.TextRange)1