Search in sources :

Example 1 with MavenDomDependency

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

the class MavenNavigationUtil method createNavigatableForDependency.

@Nullable
public static Navigatable createNavigatableForDependency(final Project project, final VirtualFile file, final MavenArtifact artifact) {
    return new NavigatableAdapter() {

        public void navigate(boolean requestFocus) {
            if (!file.isValid())
                return;
            MavenDomProjectModel projectModel = MavenDomUtil.getMavenDomProjectModel(project, file);
            if (projectModel == null)
                return;
            MavenDomDependency dependency = findDependency(projectModel, artifact.getGroupId(), artifact.getArtifactId());
            if (dependency == null)
                return;
            XmlTag artifactId = dependency.getArtifactId().getXmlTag();
            if (artifactId == null)
                return;
            navigate(project, artifactId.getContainingFile().getVirtualFile(), artifactId.getTextOffset() + artifactId.getName().length() + 2, requestFocus);
        }
    };
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) NavigatableAdapter(com.intellij.pom.NavigatableAdapter) MavenDomDependency(org.jetbrains.idea.maven.dom.model.MavenDomDependency) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with MavenDomDependency

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

the class MavenDuplicateDependenciesInspection method checkManagedDependencies.

private static void checkManagedDependencies(@NotNull MavenDomProjectModel projectModel, @NotNull DomElementAnnotationHolder holder) {
    MultiMap<DependencyConflictId, MavenDomDependency> duplicates = MultiMap.createSet();
    collect(duplicates, projectModel.getDependencyManagement().getDependencies());
    for (Map.Entry<DependencyConflictId, Collection<MavenDomDependency>> entry : duplicates.entrySet()) {
        Collection<MavenDomDependency> set = entry.getValue();
        if (set.size() <= 1)
            continue;
        for (MavenDomDependency dependency : set) {
            holder.createProblem(dependency, HighlightSeverity.WARNING, "Duplicated dependency");
        }
    }
}
Also used : DependencyConflictId(org.jetbrains.idea.maven.dom.DependencyConflictId) MultiMap(com.intellij.util.containers.MultiMap) MavenDomDependency(org.jetbrains.idea.maven.dom.model.MavenDomDependency)

Example 3 with MavenDomDependency

use of org.jetbrains.idea.maven.dom.model.MavenDomDependency 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 4 with MavenDomDependency

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

the class MavenDependencyCompletionAndResolutionTest method testChooseFileIntentionForSystemDependency.

public void testChooseFileIntentionForSystemDependency() throws Throwable {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency><caret>" + "    <groupId>xxx</groupId>" + "    <artifactId>xxx</artifactId>" + "    <version>xxx</version>" + "    <scope>system</system>" + "  </dependency>" + "</dependencies>");
    IntentionAction action = getIntentionAtCaret("Choose File");
    assertNotNull(action);
    String libPath = myIndicesFixture.getRepositoryHelper().getTestDataPath("local1/junit/junit/4.0/junit-4.0.jar");
    final VirtualFile libFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(libPath);
    ((ChooseFileIntentionAction) ((IntentionActionWrapper) action).getDelegate()).setFileChooser(() -> new VirtualFile[] { libFile });
    XmlCodeStyleSettings xmlSettings = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings().getCustomSettings(XmlCodeStyleSettings.class);
    int prevValue = xmlSettings.XML_TEXT_WRAP;
    try {
        // prevent file path from wrapping.
        xmlSettings.XML_TEXT_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
        myFixture.launchAction(action);
    } finally {
        xmlSettings.XML_TEXT_WRAP = prevValue;
        ((ChooseFileIntentionAction) ((IntentionActionWrapper) action).getDelegate()).setFileChooser(null);
    }
    MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(myProject, myProjectPom);
    MavenDomDependency dep = model.getDependencies().getDependencies().get(0);
    assertEquals(findPsiFile(libFile), dep.getSystemPath().getValue());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) ChooseFileIntentionAction(org.jetbrains.idea.maven.dom.intentions.ChooseFileIntentionAction) ChooseFileIntentionAction(org.jetbrains.idea.maven.dom.intentions.ChooseFileIntentionAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) XmlCodeStyleSettings(com.intellij.psi.formatter.xml.XmlCodeStyleSettings) MavenDomDependency(org.jetbrains.idea.maven.dom.model.MavenDomDependency)

Example 5 with MavenDomDependency

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

the class ChooseFileIntentionAction method invoke.

public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final MavenDomDependency dep = getDependency(file, editor);
    final VirtualFile[] files;
    if (myFileChooser == null) {
        final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, true, false, false);
        final PsiFile currentValue = dep != null ? dep.getSystemPath().getValue() : null;
        final VirtualFile toSelect = currentValue == null ? null : currentValue.getVirtualFile();
        files = FileChooser.chooseFiles(descriptor, project, toSelect);
    } else {
        files = myFileChooser.produce();
    }
    if (files == null || files.length == 0)
        return;
    final PsiFile selectedFile = PsiManager.getInstance(project).findFile(files[0]);
    if (selectedFile == null)
        return;
    if (dep != null) {
        if (!FileModificationService.getInstance().prepareFileForWrite(file))
            return;
        new WriteCommandAction(project) {

            protected void run(@NotNull Result result) throws Throwable {
                dep.getSystemPath().setValue(selectedFile);
            }
        }.execute();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) PsiFile(com.intellij.psi.PsiFile) MavenDomDependency(org.jetbrains.idea.maven.dom.model.MavenDomDependency) Result(com.intellij.openapi.application.Result)

Aggregations

MavenDomDependency (org.jetbrains.idea.maven.dom.model.MavenDomDependency)12 MavenDomProjectModel (org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 DomElement (com.intellij.util.xml.DomElement)2 Nullable (org.jetbrains.annotations.Nullable)2 DependencyConflictId (org.jetbrains.idea.maven.dom.DependencyConflictId)2 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 LookupElementDecorator (com.intellij.codeInsight.lookup.LookupElementDecorator)1 CaretModel (com.intellij.openapi.editor.CaretModel)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 Project (com.intellij.openapi.project.Project)1 NavigatableAdapter (com.intellij.pom.NavigatableAdapter)1 XmlCodeStyleSettings (com.intellij.psi.formatter.xml.XmlCodeStyleSettings)1