mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-79445 maven: add navigation between plugin and pluginManagement
This commit is contained in:
+94
-38
@@ -156,8 +156,7 @@ public class MavenDomProjectProcessorUtils {
|
||||
|
||||
|
||||
@NotNull
|
||||
public static Set<MavenDomDependency> searchDependencyUsages(@NotNull final MavenDomDependency dependency,
|
||||
@NotNull final Project project) {
|
||||
public static Set<MavenDomDependency> searchDependencyUsages(@NotNull final MavenDomDependency dependency) {
|
||||
final MavenDomProjectModel model = dependency.getParentOfType(MavenDomProjectModel.class, false);
|
||||
if (model != null) {
|
||||
final String artifactId = dependency.getArtifactId().getStringValue();
|
||||
@@ -206,6 +205,43 @@ public class MavenDomProjectProcessorUtils {
|
||||
return usages;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<MavenDomPlugin> searchManagedPluginUsages(@NotNull final MavenDomPlugin plugin) {
|
||||
String artifactId = plugin.getArtifactId().getStringValue();
|
||||
if (artifactId == null) return Collections.emptyList();
|
||||
|
||||
String groupId = plugin.getGroupId().getStringValue();
|
||||
|
||||
MavenDomProjectModel model = plugin.getParentOfType(MavenDomProjectModel.class, false);
|
||||
if (model == null) return Collections.emptyList();
|
||||
|
||||
return searchManagedPluginUsages(model, groupId, artifactId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<MavenDomPlugin> searchManagedPluginUsages(@NotNull final MavenDomProjectModel model,
|
||||
@Nullable final String groupId,
|
||||
@NotNull final String artifactId) {
|
||||
Project project = model.getManager().getProject();
|
||||
|
||||
final Set<MavenDomPlugin> usages = new HashSet<MavenDomPlugin>();
|
||||
|
||||
Processor<MavenDomProjectModel> collectProcessor = new Processor<MavenDomProjectModel>() {
|
||||
public boolean process(MavenDomProjectModel mavenDomProjectModel) {
|
||||
for (MavenDomPlugin domPlugin : mavenDomProjectModel.getBuild().getPlugins().getPlugins()) {
|
||||
if (MavenPluginDomUtil.isPlugin(domPlugin, groupId, artifactId)) {
|
||||
usages.add(domPlugin);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
processChildrenRecursively(model, collectProcessor, project, new HashSet<MavenDomProjectModel>(), true);
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public static void processChildrenRecursively(@Nullable MavenDomProjectModel model,
|
||||
@NotNull Processor<MavenDomProjectModel> processor) {
|
||||
processChildrenRecursively(model, processor, true);
|
||||
@@ -291,65 +327,85 @@ public class MavenDomProjectProcessorUtils {
|
||||
return processor.myResult;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MavenDomPlugin searchManagingPlugin(@NotNull final MavenDomPlugin plugin) {
|
||||
final String artifactId = plugin.getArtifactId().getStringValue();
|
||||
final String groupId = plugin.getGroupId().getStringValue();
|
||||
if (artifactId == null) return null;
|
||||
|
||||
final MavenDomProjectModel model = plugin.getParentOfType(MavenDomProjectModel.class, false);
|
||||
if (model == null) return null;
|
||||
|
||||
SearchProcessor<MavenDomPlugin, MavenDomPlugins> processor = new SearchProcessor<MavenDomPlugin, MavenDomPlugins>() {
|
||||
@Override
|
||||
protected MavenDomPlugin find(MavenDomPlugins mavenDomPlugins) {
|
||||
if (!model.equals(mavenDomPlugins.getParentOfType(MavenDomProjectModel.class, true))) {
|
||||
for (MavenDomPlugin domPlugin : mavenDomPlugins.getPlugins()) {
|
||||
if (MavenPluginDomUtil.isPlugin(domPlugin, groupId, artifactId)) {
|
||||
return domPlugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Function<MavenDomProjectModelBase, MavenDomPlugins> domProfileFunction = new Function<MavenDomProjectModelBase, MavenDomPlugins>() {
|
||||
public MavenDomPlugins fun(MavenDomProjectModelBase mavenDomProfile) {
|
||||
return mavenDomProfile.getBuild().getPluginManagement().getPlugins();
|
||||
}
|
||||
};
|
||||
|
||||
process(model, processor, model.getManager().getProject(), domProfileFunction, domProfileFunction);
|
||||
|
||||
return processor.myResult;
|
||||
}
|
||||
|
||||
|
||||
public static boolean processDependenciesInDependencyManagement(@NotNull MavenDomProjectModel projectDom,
|
||||
@NotNull final Processor<MavenDomDependencies> processor,
|
||||
@NotNull final Project project) {
|
||||
|
||||
Function<MavenDomProfile, MavenDomDependencies> domProfileFunction = new Function<MavenDomProfile, MavenDomDependencies>() {
|
||||
public MavenDomDependencies fun(MavenDomProfile mavenDomProfile) {
|
||||
Function<MavenDomProjectModelBase, MavenDomDependencies> domFunction = new Function<MavenDomProjectModelBase, MavenDomDependencies>() {
|
||||
public MavenDomDependencies fun(MavenDomProjectModelBase mavenDomProfile) {
|
||||
return mavenDomProfile.getDependencyManagement().getDependencies();
|
||||
}
|
||||
};
|
||||
Function<MavenDomProjectModel, MavenDomDependencies> projectDomFunction = new Function<MavenDomProjectModel, MavenDomDependencies>() {
|
||||
public MavenDomDependencies fun(MavenDomProjectModel mavenDomProjectModel) {
|
||||
return mavenDomProjectModel.getDependencyManagement().getDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
return process(projectDom, processor, project, domProfileFunction, projectDomFunction);
|
||||
return process(projectDom, processor, project, domFunction, domFunction);
|
||||
}
|
||||
|
||||
public static boolean processDependencies(@NotNull MavenDomProjectModel projectDom,
|
||||
@NotNull final Processor<MavenDomDependencies> processor) {
|
||||
|
||||
Function<MavenDomProfile, MavenDomDependencies> domProfileFunction = new Function<MavenDomProfile, MavenDomDependencies>() {
|
||||
public MavenDomDependencies fun(MavenDomProfile mavenDomProfile) {
|
||||
Function<MavenDomProjectModelBase, MavenDomDependencies> domFunction = new Function<MavenDomProjectModelBase, MavenDomDependencies>() {
|
||||
public MavenDomDependencies fun(MavenDomProjectModelBase mavenDomProfile) {
|
||||
return mavenDomProfile.getDependencies();
|
||||
}
|
||||
};
|
||||
Function<MavenDomProjectModel, MavenDomDependencies> projectDomFunction = new Function<MavenDomProjectModel, MavenDomDependencies>() {
|
||||
public MavenDomDependencies fun(MavenDomProjectModel mavenDomProjectModel) {
|
||||
return mavenDomProjectModel.getDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
return process(projectDom, processor, projectDom.getManager().getProject(), domProfileFunction, projectDomFunction);
|
||||
return process(projectDom, processor, projectDom.getManager().getProject(), domFunction, domFunction);
|
||||
}
|
||||
|
||||
public static boolean processProperties(@NotNull MavenDomProjectModel projectDom,
|
||||
@NotNull final Processor<MavenDomProperties> processor,
|
||||
@NotNull final Project project) {
|
||||
|
||||
Function<MavenDomProfile, MavenDomProperties> domProfileFunction = new Function<MavenDomProfile, MavenDomProperties>() {
|
||||
public MavenDomProperties fun(MavenDomProfile mavenDomProfile) {
|
||||
Function<MavenDomProjectModelBase, MavenDomProperties> domFunction = new Function<MavenDomProjectModelBase, MavenDomProperties>() {
|
||||
public MavenDomProperties fun(MavenDomProjectModelBase mavenDomProfile) {
|
||||
return mavenDomProfile.getProperties();
|
||||
}
|
||||
};
|
||||
Function<MavenDomProjectModel, MavenDomProperties> projectDomFunction = new Function<MavenDomProjectModel, MavenDomProperties>() {
|
||||
public MavenDomProperties fun(MavenDomProjectModel mavenDomProjectModel) {
|
||||
return mavenDomProjectModel.getProperties();
|
||||
}
|
||||
};
|
||||
|
||||
return process(projectDom, processor, project, domProfileFunction, projectDomFunction);
|
||||
return process(projectDom, processor, project, domFunction, domFunction);
|
||||
}
|
||||
|
||||
public static <T> boolean process(@NotNull MavenDomProjectModel projectDom,
|
||||
@NotNull final Processor<T> processor,
|
||||
@NotNull final Project project,
|
||||
@NotNull final Function<MavenDomProfile, T> domProfileFunction,
|
||||
@NotNull final Function<MavenDomProjectModel, T> projectDomFunction) {
|
||||
@NotNull final Function<? super MavenDomProfile , T> domProfileFunction,
|
||||
@NotNull final Function<? super MavenDomProjectModel, T> projectDomFunction) {
|
||||
|
||||
return process(projectDom, processor, project, domProfileFunction, projectDomFunction, new HashSet<MavenDomProjectModel>());
|
||||
}
|
||||
@@ -358,8 +414,8 @@ public class MavenDomProjectProcessorUtils {
|
||||
public static <T> boolean process(@NotNull MavenDomProjectModel projectDom,
|
||||
@NotNull final Processor<T> processor,
|
||||
@NotNull final Project project,
|
||||
@NotNull final Function<MavenDomProfile, T> domProfileFunction,
|
||||
@NotNull final Function<MavenDomProjectModel, T> projectDomFunction,
|
||||
@NotNull final Function<? super MavenDomProfile, T> domProfileFunction,
|
||||
@NotNull final Function<? super MavenDomProjectModel, T> projectDomFunction,
|
||||
final Set<MavenDomProjectModel> processed) {
|
||||
if (processed.contains(projectDom)) return true;
|
||||
processed.add(projectDom);
|
||||
@@ -375,8 +431,8 @@ public class MavenDomProjectProcessorUtils {
|
||||
private static <T> boolean processParentProjectFile(MavenDomProjectModel projectDom,
|
||||
final Processor<T> processor,
|
||||
final Project project,
|
||||
final Function<MavenDomProfile, T> domProfileFunction,
|
||||
final Function<MavenDomProjectModel, T> projectDomFunction,
|
||||
final Function<? super MavenDomProfile, T> domProfileFunction,
|
||||
final Function<? super MavenDomProjectModel, T> projectDomFunction,
|
||||
final Set<MavenDomProjectModel> processed) {
|
||||
Boolean aBoolean = new DomParentProjectFileProcessor<Boolean>(MavenProjectsManager.getInstance(project)) {
|
||||
protected Boolean doProcessParent(VirtualFile parentFile) {
|
||||
@@ -395,7 +451,7 @@ public class MavenDomProjectProcessorUtils {
|
||||
private static <T> boolean processSettingsXml(@Nullable MavenProject mavenProject,
|
||||
@NotNull Processor<T> processor,
|
||||
@NotNull Project project,
|
||||
Function<MavenDomProfile, T> domProfileFunction) {
|
||||
Function<? super MavenDomProfile, T> domProfileFunction) {
|
||||
MavenGeneralSettings settings = MavenProjectsManager.getInstance(project).getGeneralSettings();
|
||||
|
||||
for (VirtualFile each : settings.getEffectiveSettingsFiles()) {
|
||||
@@ -411,8 +467,8 @@ public class MavenDomProjectProcessorUtils {
|
||||
MavenProject mavenProjectOrNull,
|
||||
Processor<T> processor,
|
||||
Project project,
|
||||
Function<MavenDomProfile, T> domProfileFunction,
|
||||
Function<MavenDomProjectModel, T> projectDomFunction) {
|
||||
Function<? super MavenDomProfile, T> domProfileFunction,
|
||||
Function<? super MavenDomProjectModel, T> projectDomFunction) {
|
||||
|
||||
if (processProfilesXml(MavenDomUtil.getVirtualFile(projectDom), mavenProjectOrNull, processor, project, domProfileFunction)) {
|
||||
return true;
|
||||
@@ -428,7 +484,7 @@ public class MavenDomProjectProcessorUtils {
|
||||
MavenProject mavenProjectOrNull,
|
||||
Processor<T> processor,
|
||||
Project project,
|
||||
Function<MavenDomProfile, T> f) {
|
||||
Function<? super MavenDomProfile, T> f) {
|
||||
VirtualFile profilesFile = MavenUtil.findProfilesXmlFile(projectFile);
|
||||
if (profilesFile == null) return false;
|
||||
|
||||
@@ -441,7 +497,7 @@ public class MavenDomProjectProcessorUtils {
|
||||
private static <T> boolean processProfiles(MavenDomProfiles profilesDom,
|
||||
MavenProject mavenProjectOrNull,
|
||||
Processor<T> processor,
|
||||
Function<MavenDomProfile, T> f) {
|
||||
Function<? super MavenDomProfile, T> f) {
|
||||
Collection<String> activePropfiles = mavenProjectOrNull == null ? null : mavenProjectOrNull.getActivatedProfilesIds();
|
||||
for (MavenDomProfile each : profilesDom.getProfiles()) {
|
||||
XmlTag idTag = each.getId().getXmlTag();
|
||||
@@ -455,7 +511,7 @@ public class MavenDomProjectProcessorUtils {
|
||||
|
||||
private static <T> boolean processProfile(MavenDomProfile profileDom,
|
||||
Processor<T> processor,
|
||||
Function<MavenDomProfile, T> f) {
|
||||
Function<? super MavenDomProfile, T> f) {
|
||||
T t = f.fun(profileDom);
|
||||
return t != null && processor.process(t);
|
||||
}
|
||||
|
||||
@@ -44,18 +44,22 @@ public class MavenPluginDomUtil {
|
||||
return MavenDomUtil.getMavenDomModel(p, pluginXmlFile, MavenDomPluginModel.class);
|
||||
}
|
||||
|
||||
public static boolean isPlugin(@NotNull MavenDomConfiguration configuration, @NotNull String groupId, @NotNull String artifactId) {
|
||||
public static boolean isPlugin(@NotNull MavenDomConfiguration configuration, @Nullable String groupId, @NotNull String artifactId) {
|
||||
MavenDomPlugin domPlugin = configuration.getParentOfType(MavenDomPlugin.class, true);
|
||||
if (domPlugin == null) return false;
|
||||
|
||||
return isPlugin(domPlugin, groupId, artifactId);
|
||||
}
|
||||
|
||||
public static boolean isPlugin(@NotNull MavenDomPlugin plugin, @NotNull String groupId, @NotNull String artifactId) {
|
||||
public static boolean isPlugin(@NotNull MavenDomPlugin plugin, @Nullable String groupId, @NotNull String artifactId) {
|
||||
if (!artifactId.equals(plugin.getArtifactId().getStringValue())) return false;
|
||||
|
||||
String pluginGroupId = plugin.getGroupId().getStringValue();
|
||||
|
||||
if (groupId == null) {
|
||||
return pluginGroupId == null || (pluginGroupId.equals("org.apache.maven.plugins") || pluginGroupId.equals("org.codehaus.mojo"));
|
||||
}
|
||||
|
||||
if (pluginGroupId == null && (groupId.equals("org.apache.maven.plugins") || groupId.equals("org.codehaus.mojo"))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+155
-102
@@ -44,6 +44,152 @@ import java.util.Set;
|
||||
|
||||
public class MavenDomGutterAnnotator implements Annotator {
|
||||
|
||||
private static void annotateDependencyUsages(@NotNull MavenDomDependency dependency, AnnotationHolder holder) {
|
||||
final XmlTag tag = dependency.getXmlTag();
|
||||
if (tag == null) return;
|
||||
|
||||
final Set<MavenDomDependency> children = MavenDomProjectProcessorUtils.searchDependencyUsages(dependency);
|
||||
if (children.size() > 0) {
|
||||
final NavigationGutterIconBuilder<MavenDomDependency> iconBuilder =
|
||||
NavigationGutterIconBuilder.create(AllIcons.General.OverridenMethod, DependencyConverter.INSTANCE);
|
||||
iconBuilder.
|
||||
setTargets(children).
|
||||
setPopupTitle(MavenDomBundle.message("navigate.parent.dependency.title")).
|
||||
setCellRenderer(MyListCellRenderer.INSTANCE).
|
||||
setTooltipText(MavenDomBundle.message("overriding.dependency.title")).
|
||||
install(holder, dependency.getXmlTag());
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateManagedDependency(MavenDomDependency dependency, AnnotationHolder holder) {
|
||||
final XmlTag tag = dependency.getXmlTag();
|
||||
if (tag == null) return;
|
||||
|
||||
final List<MavenDomDependency> children = getManagingDependencies(dependency);
|
||||
if (children.size() > 0) {
|
||||
|
||||
final NavigationGutterIconBuilder<MavenDomDependency> iconBuilder =
|
||||
NavigationGutterIconBuilder.create(AllIcons.General.OverridingMethod, DependencyConverter.INSTANCE);
|
||||
iconBuilder.
|
||||
setTargets(children).
|
||||
setTooltipText(MavenDomBundle.message("overriden.dependency.title")).
|
||||
install(holder, tag);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<MavenDomDependency> getManagingDependencies(@NotNull MavenDomDependency dependency) {
|
||||
Project project = dependency.getManager().getProject();
|
||||
MavenDomDependency parentDependency = MavenDomProjectProcessorUtils.searchManagingDependency(dependency, project);
|
||||
|
||||
if (parentDependency != null) {
|
||||
return Collections.singletonList(parentDependency);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
|
||||
if (psiElement instanceof XmlTag) {
|
||||
final DomElement element = DomManager.getDomManager(psiElement.getProject()).getDomElement((XmlTag)psiElement);
|
||||
if (element instanceof MavenDomDependency) {
|
||||
if (element.getParentOfType(MavenDomPlugin.class, true) != null) return;
|
||||
|
||||
MavenDomDependency dependency = (MavenDomDependency)element;
|
||||
if (isDependencyManagementSection(dependency)) {
|
||||
annotateDependencyUsages(dependency, holder);
|
||||
}
|
||||
else {
|
||||
annotateManagedDependency(dependency, holder);
|
||||
}
|
||||
}
|
||||
else if (element instanceof MavenDomParent) {
|
||||
annotateMavenDomParent((MavenDomParent)element, holder);
|
||||
}
|
||||
else if (element instanceof MavenDomProjectModel) {
|
||||
annotateMavenDomProjectChildren((MavenDomProjectModel)element, holder);
|
||||
}
|
||||
else if (element instanceof MavenDomPlugin) {
|
||||
annotateMavenDomPlugin((MavenDomPlugin)element, holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateMavenDomPlugin(@NotNull MavenDomPlugin plugin, @NotNull AnnotationHolder holder) {
|
||||
XmlTag xmlTag = plugin.getArtifactId().getXmlTag();
|
||||
if (xmlTag == null) return;
|
||||
|
||||
DomElement plugins = plugin.getParent();
|
||||
if (plugins == null) return;
|
||||
|
||||
DomElement parent = plugins.getParent();
|
||||
if (parent instanceof MavenDomPluginManagement) {
|
||||
annotateMavenDomPluginInManagement(plugin, holder);
|
||||
return;
|
||||
}
|
||||
|
||||
MavenDomPlugin managingPlugin = MavenDomProjectProcessorUtils.searchManagingPlugin(plugin);
|
||||
|
||||
if (managingPlugin != null) {
|
||||
NavigationGutterIconBuilder<MavenDomPlugin> iconBuilder =
|
||||
NavigationGutterIconBuilder.create(AllIcons.General.OverridingMethod, PluginConverter.INSTANCE);
|
||||
|
||||
iconBuilder.
|
||||
setTargets(Collections.singletonList(managingPlugin)).
|
||||
setTooltipText(MavenDomBundle.message("overriden.plugin.title")).
|
||||
install(holder, xmlTag);
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateMavenDomPluginInManagement(@NotNull MavenDomPlugin plugin, @NotNull AnnotationHolder holder) {
|
||||
XmlTag xmlTag = plugin.getArtifactId().getXmlTag();
|
||||
if (xmlTag == null) return;
|
||||
|
||||
Collection<MavenDomPlugin> children = MavenDomProjectProcessorUtils.searchManagedPluginUsages(plugin);
|
||||
|
||||
if (children.size() > 0) {
|
||||
NavigationGutterIconBuilder<MavenDomPlugin> iconBuilder =
|
||||
NavigationGutterIconBuilder.create(AllIcons.General.OverridenMethod, PluginConverter.INSTANCE);
|
||||
|
||||
iconBuilder.
|
||||
setTargets(children).
|
||||
setPopupTitle(MavenDomBundle.message("navigate.parent.plugin.title")).
|
||||
setCellRenderer(MyListCellRenderer.INSTANCE).
|
||||
setTooltipText(MavenDomBundle.message("overriding.plugin.title")).
|
||||
install(holder, xmlTag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void annotateMavenDomParent(@NotNull MavenDomParent mavenDomParent, @NotNull AnnotationHolder holder) {
|
||||
MavenDomProjectModel parent = MavenDomProjectProcessorUtils.findParent(mavenDomParent, mavenDomParent.getManager().getProject());
|
||||
|
||||
if (parent != null) {
|
||||
NavigationGutterIconBuilder.create(icons.MavenIcons.ParentProject, MavenProjectConverter.INSTANCE).
|
||||
setTargets(parent).
|
||||
setTooltipText(MavenDomBundle.message("parent.pom.title")).
|
||||
install(holder, mavenDomParent.getXmlElement());
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateMavenDomProjectChildren(MavenDomProjectModel model, AnnotationHolder holder) {
|
||||
MavenProject mavenProject = MavenDomUtil.findProject(model);
|
||||
if (mavenProject != null) {
|
||||
Set<MavenDomProjectModel> children = MavenDomProjectProcessorUtils.getChildrenProjects(model);
|
||||
|
||||
if (children.size() > 0) {
|
||||
NavigationGutterIconBuilder.create(icons.MavenIcons.ChildrenProjects, MavenProjectConverter.INSTANCE).
|
||||
setTargets(children).
|
||||
setCellRenderer(MyListCellRenderer.INSTANCE).
|
||||
setPopupTitle(MavenDomBundle.message("navigate.children.poms.title")).
|
||||
setTooltipText(MavenDomBundle.message("children.poms.title")).
|
||||
install(holder, model.getXmlElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isDependencyManagementSection(@NotNull MavenDomDependency dependency) {
|
||||
return dependency.getParentOfType(MavenDomDependencyManagement.class, false) != null;
|
||||
}
|
||||
|
||||
private static class MyListCellRenderer extends PsiElementListCellRenderer<XmlTag> {
|
||||
public static final MyListCellRenderer INSTANCE = new MyListCellRenderer();
|
||||
|
||||
@@ -91,6 +237,15 @@ public class MavenDomGutterAnnotator implements Annotator {
|
||||
}
|
||||
}
|
||||
|
||||
private static class PluginConverter implements NotNullFunction<MavenDomPlugin, Collection<? extends PsiElement>> {
|
||||
public static final PluginConverter INSTANCE = new PluginConverter();
|
||||
|
||||
@NotNull
|
||||
public Collection<? extends PsiElement> fun(final MavenDomPlugin pointer) {
|
||||
return ContainerUtil.createMaybeSingletonList(pointer.getXmlTag());
|
||||
}
|
||||
}
|
||||
|
||||
private static class MavenProjectConverter implements NotNullFunction<MavenDomProjectModel, Collection<? extends PsiElement>> {
|
||||
public static final MavenProjectConverter INSTANCE = new MavenProjectConverter();
|
||||
|
||||
@@ -99,106 +254,4 @@ public class MavenDomGutterAnnotator implements Annotator {
|
||||
return ContainerUtil.createMaybeSingletonList(pointer.getXmlTag());
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateDependencyUsages(@NotNull MavenDomDependency dependency, AnnotationHolder holder) {
|
||||
final XmlTag tag = dependency.getXmlTag();
|
||||
if (tag == null) return;
|
||||
|
||||
final Set<MavenDomDependency> children = getDependencyUsages(dependency);
|
||||
if (children.size() > 0) {
|
||||
final NavigationGutterIconBuilder<MavenDomDependency> iconBuilder =
|
||||
NavigationGutterIconBuilder.create(AllIcons.General.OverridenMethod, DependencyConverter.INSTANCE);
|
||||
iconBuilder.
|
||||
setTargets(children).
|
||||
setPopupTitle(MavenDomBundle.message("navigate.parent.dependency.title")).
|
||||
setCellRenderer(MyListCellRenderer.INSTANCE).
|
||||
setTooltipText(MavenDomBundle.message("overriding.dependency.title")).
|
||||
install(holder, dependency.getXmlTag());
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateManagedDependency(MavenDomDependency dependency, AnnotationHolder holder) {
|
||||
final XmlTag tag = dependency.getXmlTag();
|
||||
if (tag == null) return;
|
||||
|
||||
final List<MavenDomDependency> children = getManagingDependencies(dependency);
|
||||
if (children.size() > 0) {
|
||||
|
||||
final NavigationGutterIconBuilder<MavenDomDependency> iconBuilder =
|
||||
NavigationGutterIconBuilder.create(AllIcons.General.OverridingMethod, DependencyConverter.INSTANCE);
|
||||
iconBuilder.
|
||||
setTargets(children).
|
||||
setTooltipText(MavenDomBundle.message("overriden.dependency.title")).
|
||||
install(holder, dependency.getXmlTag());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<MavenDomDependency> getManagingDependencies(@NotNull MavenDomDependency dependency) {
|
||||
Project project = dependency.getManager().getProject();
|
||||
MavenDomDependency parentDependency = MavenDomProjectProcessorUtils.searchManagingDependency(dependency, project);
|
||||
|
||||
if (parentDependency != null) {
|
||||
return Collections.singletonList(parentDependency);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<MavenDomDependency> getDependencyUsages(@NotNull MavenDomDependency dependency) {
|
||||
return MavenDomProjectProcessorUtils.searchDependencyUsages(dependency, dependency.getManager().getProject());
|
||||
}
|
||||
|
||||
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
|
||||
if (psiElement instanceof XmlTag) {
|
||||
final DomElement element = DomManager.getDomManager(psiElement.getProject()).getDomElement((XmlTag)psiElement);
|
||||
if (element instanceof MavenDomDependency) {
|
||||
if (element.getParentOfType(MavenDomPlugin.class, true) != null) return;
|
||||
|
||||
MavenDomDependency dependency = (MavenDomDependency)element;
|
||||
if (isDependencyManagementSection(dependency)) {
|
||||
annotateDependencyUsages(dependency, holder);
|
||||
}
|
||||
else {
|
||||
annotateManagedDependency(dependency, holder);
|
||||
}
|
||||
}
|
||||
else if (element instanceof MavenDomParent) {
|
||||
annotateMavenDomParent((MavenDomParent)element, holder);
|
||||
}
|
||||
else if (element instanceof MavenDomProjectModel) {
|
||||
annotateMavenDomProjectChildren((MavenDomProjectModel)element, holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateMavenDomParent(@NotNull MavenDomParent mavenDomParent, @NotNull AnnotationHolder holder) {
|
||||
MavenDomProjectModel parent = MavenDomProjectProcessorUtils.findParent(mavenDomParent, mavenDomParent.getManager().getProject());
|
||||
|
||||
if (parent != null) {
|
||||
NavigationGutterIconBuilder.create(icons.MavenIcons.ParentProject, MavenProjectConverter.INSTANCE).
|
||||
setTargets(parent).
|
||||
setTooltipText(MavenDomBundle.message("parent.pom.title")).
|
||||
install(holder, mavenDomParent.getXmlElement());
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateMavenDomProjectChildren(MavenDomProjectModel model, AnnotationHolder holder) {
|
||||
MavenProject mavenProject = MavenDomUtil.findProject(model);
|
||||
if (mavenProject != null) {
|
||||
Set<MavenDomProjectModel> children = MavenDomProjectProcessorUtils.getChildrenProjects(model);
|
||||
|
||||
if (children.size() > 0) {
|
||||
NavigationGutterIconBuilder.create(icons.MavenIcons.ChildrenProjects, MavenProjectConverter.INSTANCE).
|
||||
setTargets(children).
|
||||
setCellRenderer(MyListCellRenderer.INSTANCE).
|
||||
setPopupTitle(MavenDomBundle.message("navigate.children.poms.title")).
|
||||
setTooltipText(MavenDomBundle.message("children.poms.title")).
|
||||
install(holder, model.getXmlElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isDependencyManagementSection(@NotNull MavenDomDependency dependency) {
|
||||
return dependency.getParentOfType(MavenDomDependencyManagement.class, false) != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,11 @@ generate.repository.template=Repository Template
|
||||
generate.parent=Parent
|
||||
|
||||
overriden.dependency.title=Navigate to Managing Dependency
|
||||
overriden.plugin.title=Navigate to 'pluginManagement' section
|
||||
overriding.dependency.title=Navigate to Dependency Usages
|
||||
overriding.plugin.title=Navigate to Plugin Usages
|
||||
navigate.parent.dependency.title=Choose Dependency to Navigate to
|
||||
navigate.parent.plugin.title=Choose Plugin to Navigate to
|
||||
|
||||
parent.pom.title=Navigate to Parent
|
||||
children.poms.title=Navigate to Children Projects
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package org.jetbrains.idea.maven.dom
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
class MavenDomAnnotatorTest extends MavenDomTestCase {
|
||||
|
||||
public void testAnnotatePlugin() {
|
||||
def modulePom = createModulePom("m", """
|
||||
<parent>
|
||||
<groupId>test</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1</version>
|
||||
</parent>
|
||||
<artifactId>m</artifactId>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
""")
|
||||
|
||||
importProject("""
|
||||
<groupId>test</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1</version>
|
||||
|
||||
<modules>
|
||||
<module>m</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
""")
|
||||
|
||||
checkGutters(PsiManager.getInstance(myProject).findFile(modulePom), "<artifactId>maven-compiler-plugin</artifactId>", """<parent>
|
||||
<groupId>test</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1</version>
|
||||
</parent>""")
|
||||
}
|
||||
|
||||
protected void checkGutters(PsiFile file, String ... expectedProperties) {
|
||||
myFixture.configureFromExistingVirtualFile(file.virtualFile);
|
||||
|
||||
String text = file.getText();
|
||||
|
||||
Set<String> actualProperties = new HashSet<String>();
|
||||
|
||||
for (com.intellij.codeInsight.daemon.impl.HighlightInfo h : myFixture.doHighlighting()) {
|
||||
if (h.getGutterIconRenderer() != null) {
|
||||
String s = text.substring(h.getStartOffset(), h.getEndOffset());
|
||||
actualProperties.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(ContainerUtil.newHashSet(expectedProperties), actualProperties);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user