From 5aa8b78b3cdf9b7da460a1f9f2e578a0e19c567b Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Thu, 25 Nov 2021 16:31:35 +0100 Subject: [PATCH] Issue #155 - replace resolveParentProject by parent.getProject() It's not clear why a project resolution is required, although it's a very expansive operation and we already have the parent project at hand. Just skip resolution for now. --- org.eclipse.m2e.core/META-INF/MANIFEST.MF | 2 +- org.eclipse.m2e.core/pom.xml | 2 +- .../src/org/eclipse/m2e/core/embedder/IMaven.java | 11 +++++++++++ .../AnnotationMappingMetadataSource.java | 9 +++++++-- .../lifecyclemapping/LifecycleMappingFactory.java | 4 +--- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF index c8c8599e4d..59741e15e6 100644 --- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.m2e.core;singleton:=true -Bundle-Version: 1.18.3.qualifier +Bundle-Version: 1.18.4.qualifier Bundle-Activator: org.eclipse.m2e.core.internal.MavenPluginActivator Bundle-Vendor: %Bundle-Vendor Bundle-Localization: plugin diff --git a/org.eclipse.m2e.core/pom.xml b/org.eclipse.m2e.core/pom.xml index ea44831e80..3dc154eac9 100644 --- a/org.eclipse.m2e.core/pom.xml +++ b/org.eclipse.m2e.core/pom.xml @@ -19,7 +19,7 @@ org.eclipse.m2e.core - 1.18.3-SNAPSHOT + 1.18.4-SNAPSHOT eclipse-plugin Maven Integration for Eclipse Core Plug-in diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java index c050491ba0..a40071ae63 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java @@ -147,6 +147,17 @@ Map readMavenProjects(Collection pomFiles, @Deprecated MavenProject resolveParentProject(MavenExecutionRequest request, MavenProject project, IProgressMonitor monitor) throws CoreException; + /** + * Returns MavenProject parent project or null if no such project. + * + * @param project + * @param monitor + * @return + * @throws CoreException + * @deprecated directly use project.getParent() whenever possible, and if parent needs to be re-resolved, + * it's a responsibility of the consumer to do it in its code. + */ + @Deprecated MavenProject resolveParentProject(MavenProject project, IProgressMonitor monitor) throws CoreException; // execution diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/AnnotationMappingMetadataSource.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/AnnotationMappingMetadataSource.java index 59d0170191..d36d9deda4 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/AnnotationMappingMetadataSource.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/AnnotationMappingMetadataSource.java @@ -170,9 +170,14 @@ private PluginExecutionMetadata createMetadata(Xpp3Dom action) { } private static List parsePIs(MavenProject project) { - - File pom = project.getFile(); InputSource source = project.getModel().getLocation(SELF).getSource(); + File pom = project.getFile(); + if((pom == null || !pom.isFile()) && source.getLocation() != null) { + pom = new File(source.getLocation()); + } + if(pom == null || !pom.isFile()) { + return List.of(); + } List pis = new ArrayList<>(); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java index 7a527d8aa9..4df04830cb 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java @@ -851,9 +851,7 @@ public static List getPomMappingMetadataSources(MavenProj maven.detachFromSession(project); // don't cache maven session } - // TODO ideally, we need to reuse the same parent MavenProject instance in all child modules - // each instance takes ~1M, so we can easily save 100M+ of heap for larger workspaces - project = maven.resolveParentProject(project, monitor); + project = project.getParent(); } while(project != null); return sources;