Skip to content

Commit

Permalink
Take the version for an annotation processor from project dependencyM…
Browse files Browse the repository at this point in the history
…anagement

Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
  • Loading branch information
snjeza authored and fbricon committed Jan 25, 2024
1 parent 1b6a28d commit 045f3cb
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.m2e.apt.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -93,8 +95,20 @@ public synchronized List<File> getResolvedPluginDependencies(MavenSession mavenS
request.setRepositories(mavenProject.getRemoteProjectRepositories());

Collection<Dependency> 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));
}

Expand Down
47 changes: 47 additions & 0 deletions org.eclipse.m2e.apt.tests/projects/p15/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar</groupId>
<artifactId>p15</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-bom</artifactId>
<version>3.6.7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package foo.bar;

public class DummyStuff {

public void nonSense() {
System.err.println(Dummy_.name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 045f3cb

Please sign in to comment.