Search in sources :

Example 1 with ChooseFileIntentionAction

use of org.jetbrains.idea.maven.dom.intentions.ChooseFileIntentionAction 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)

Aggregations

IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 XmlCodeStyleSettings (com.intellij.psi.formatter.xml.XmlCodeStyleSettings)1 ChooseFileIntentionAction (org.jetbrains.idea.maven.dom.intentions.ChooseFileIntentionAction)1 MavenDomDependency (org.jetbrains.idea.maven.dom.model.MavenDomDependency)1 MavenDomProjectModel (org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)1