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);
}
};
}
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");
}
}
}
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);
}
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());
}
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();
}
}
Aggregations