From 045f3cbc9104d21a40a558c29b25d05d956c2c8a Mon Sep 17 00:00:00 2001 From: Snjezana Peco Date: Tue, 23 Jan 2024 22:44:32 +0100 Subject: [PATCH] Take the version for an annotation processor from project dependencyManagement Signed-off-by: Snjezana Peco --- org.eclipse.m2e.apt.core/META-INF/MANIFEST.MF | 2 +- .../utils/PluginDependencyResolver.java | 16 ++++++- .../projects/p15/pom.xml | 47 +++++++++++++++++++ .../p15/src/main/java/foo/bar/Dummy.java | 18 +++++++ .../p15/src/main/java/foo/bar/DummyStuff.java | 8 ++++ .../tests/M2eAptProjectconfiguratorTest.java | 9 ++++ 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 org.eclipse.m2e.apt.tests/projects/p15/pom.xml create mode 100644 org.eclipse.m2e.apt.tests/projects/p15/src/main/java/foo/bar/Dummy.java create mode 100644 org.eclipse.m2e.apt.tests/projects/p15/src/main/java/foo/bar/DummyStuff.java diff --git a/org.eclipse.m2e.apt.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.apt.core/META-INF/MANIFEST.MF index 9d20a8bcce..671de7ffda 100644 --- a/org.eclipse.m2e.apt.core/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.apt.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.apt.core;singleton:=true -Bundle-Version: 2.2.200.qualifier +Bundle-Version: 2.2.201.qualifier Bundle-Localization: plugin Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.27.0,4.0.0)", org.eclipse.core.resources, diff --git a/org.eclipse.m2e.apt.core/src/org/eclipse/m2e/apt/internal/utils/PluginDependencyResolver.java b/org.eclipse.m2e.apt.core/src/org/eclipse/m2e/apt/internal/utils/PluginDependencyResolver.java index 66ccad36a8..248fac8d4a 100644 --- a/org.eclipse.m2e.apt.core/src/org/eclipse/m2e/apt/internal/utils/PluginDependencyResolver.java +++ b/org.eclipse.m2e.apt.core/src/org/eclipse/m2e/apt/internal/utils/PluginDependencyResolver.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,6 +48,7 @@ import org.apache.maven.RepositoryUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Plugin; import org.apache.maven.project.MavenProject; @@ -93,8 +95,20 @@ public synchronized List getResolvedPluginDependencies(MavenSession mavenS request.setRepositories(mavenProject.getRemoteProjectRepositories()); Collection dependencies = getDependencies(plugin); - for(Dependency dependency : dependencies) { + if(dependency.getVersion() == null) { + DependencyManagement depMngt = mavenProject.getDependencyManagement(); + if(depMngt != null) { + Dependency mngtDep = depMngt.getDependencies().stream() + .filter(d -> Objects.equals(d.getGroupId(), dependency.getGroupId()) + && Objects.equals(d.getArtifactId(), dependency.getArtifactId()) + && Objects.equals(d.getType(), dependency.getType())) + .findFirst().get(); + if(mngtDep != null) { + dependency.setVersion(mngtDep.getVersion()); + } + } + } request.addDependency(RepositoryUtils.toDependency(dependency, stereotypes)); } diff --git a/org.eclipse.m2e.apt.tests/projects/p15/pom.xml b/org.eclipse.m2e.apt.tests/projects/p15/pom.xml new file mode 100644 index 0000000000..0a5f4af540 --- /dev/null +++ b/org.eclipse.m2e.apt.tests/projects/p15/pom.xml @@ -0,0 +1,47 @@ + + 4.0.0 + foo.bar + p15 + 0.0.1-SNAPSHOT + + jdt_apt + 17 + + + + + io.quarkus.platform + quarkus-bom + 3.6.7 + pom + import + + + + + + + maven-compiler-plugin + 3.12.1 + + + -parameters + + + + org.hibernate.orm + hibernate-jpamodelgen + + + + + + + + + io.quarkus + quarkus-hibernate-orm + + + diff --git a/org.eclipse.m2e.apt.tests/projects/p15/src/main/java/foo/bar/Dummy.java b/org.eclipse.m2e.apt.tests/projects/p15/src/main/java/foo/bar/Dummy.java new file mode 100644 index 0000000000..d0418a0305 --- /dev/null +++ b/org.eclipse.m2e.apt.tests/projects/p15/src/main/java/foo/bar/Dummy.java @@ -0,0 +1,18 @@ +package foo.bar; + +import jakarta.persistence.Entity; + +@Entity +public class Dummy { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/org.eclipse.m2e.apt.tests/projects/p15/src/main/java/foo/bar/DummyStuff.java b/org.eclipse.m2e.apt.tests/projects/p15/src/main/java/foo/bar/DummyStuff.java new file mode 100644 index 0000000000..5018d06cfc --- /dev/null +++ b/org.eclipse.m2e.apt.tests/projects/p15/src/main/java/foo/bar/DummyStuff.java @@ -0,0 +1,8 @@ +package foo.bar; + +public class DummyStuff { + + public void nonSense() { + System.err.println(Dummy_.name); + } +} diff --git a/org.eclipse.m2e.apt.tests/src/org/eclipse/m2e/apt/tests/M2eAptProjectconfiguratorTest.java b/org.eclipse.m2e.apt.tests/src/org/eclipse/m2e/apt/tests/M2eAptProjectconfiguratorTest.java index 646d919662..7f741d5e8e 100644 --- a/org.eclipse.m2e.apt.tests/src/org/eclipse/m2e/apt/tests/M2eAptProjectconfiguratorTest.java +++ b/org.eclipse.m2e.apt.tests/src/org/eclipse/m2e/apt/tests/M2eAptProjectconfiguratorTest.java @@ -435,4 +435,13 @@ public void testAnnotationPluginsDisabled() throws Exception { } } } + + @Test + public void testDependencyManagement() throws Exception { + IProject p = importProject("projects/p15/pom.xml"); + waitForJobsToComplete(); + IJavaProject javaProject = JavaCore.create(p); + assertNotNull(javaProject); + assertNoErrors(p); + } }