Skip to content

Commit c25a88d

Browse files
committed
Replace custom hazardous Maven uses by Mima
1 parent bd883ee commit c25a88d

33 files changed

+390
-657
lines changed

pom.xml

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
<maven.compiler.source>17</maven.compiler.source>
1818
<maven.compiler.target>17</maven.compiler.target>
1919

20-
<maven-core.version>3.8.1</maven-core.version>
21-
<maven-invoker.version>3.1.0</maven-invoker.version>
22-
<maven-resolver.version>1.7.0</maven-resolver.version>
20+
<logback.version>1.5.3</logback.version>
21+
<mima.version>2.4.10</mima.version>
22+
<maven-resolver.version>1.9.18</maven-resolver.version>
2323

2424
<junit.jupiter.version>5.10.2</junit.jupiter.version>
2525
<assertj.version>3.25.3</assertj.version>
2626
<mockito-core.version>5.11.0</mockito-core.version>
27-
<log4j.version>2.14.1</log4j.version>
2827

2928
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
3029
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
@@ -62,24 +61,45 @@
6261

6362
<dependencies>
6463
<dependency>
65-
<groupId>org.apache.maven</groupId>
66-
<artifactId>maven-core</artifactId>
67-
<version>${maven-core.version}</version>
64+
<groupId>ch.qos.logback</groupId>
65+
<artifactId>logback-classic</artifactId>
66+
<version>${logback.version}</version>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>eu.maveniverse.maven.mima</groupId>
71+
<artifactId>context</artifactId>
72+
<version>${mima.version}</version>
6873
</dependency>
6974
<dependency>
70-
<groupId>org.apache.maven.shared</groupId>
71-
<artifactId>maven-invoker</artifactId>
72-
<version>${maven-invoker.version}</version>
75+
<groupId>eu.maveniverse.maven.mima.runtime</groupId>
76+
<artifactId>standalone-static</artifactId>
77+
<version>${mima.version}</version>
78+
<scope>runtime</scope>
7379
</dependency>
7480
<dependency>
7581
<groupId>org.apache.maven.resolver</groupId>
76-
<artifactId>maven-resolver-connector-basic</artifactId>
82+
<artifactId>maven-resolver-api</artifactId>
7783
<version>${maven-resolver.version}</version>
84+
<scope>provided</scope>
7885
</dependency>
7986
<dependency>
8087
<groupId>org.apache.maven.resolver</groupId>
81-
<artifactId>maven-resolver-transport-http</artifactId>
88+
<artifactId>maven-resolver-spi</artifactId>
8289
<version>${maven-resolver.version}</version>
90+
<scope>provided</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.apache.maven.resolver</groupId>
94+
<artifactId>maven-resolver-impl</artifactId>
95+
<version>${maven-resolver.version}</version>
96+
<scope>provided</scope>
97+
</dependency>
98+
99+
<dependency>
100+
<groupId>com.fasterxml.jackson.dataformat</groupId>
101+
<artifactId>jackson-dataformat-xml</artifactId>
102+
<version>2.17.0</version>
83103
</dependency>
84104

85105
<dependency>
@@ -109,9 +129,9 @@
109129
<scope>test</scope>
110130
</dependency>
111131
<dependency>
112-
<groupId>org.apache.logging.log4j</groupId>
113-
<artifactId>log4j-slf4j-impl</artifactId>
114-
<version>${log4j.version}</version>
132+
<groupId>com.google.guava</groupId>
133+
<artifactId>guava</artifactId>
134+
<version>32.1.2-jre</version>
115135
<scope>test</scope>
116136
</dependency>
117137
</dependencies>

src/main/java/com/github/fridujo/classpath/junit/extension/Classpath.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package com.github.fridujo.classpath.junit.extension;
22

3-
import static java.util.Arrays.stream;
3+
import com.github.fridujo.classpath.junit.extension.buildtool.Artifact;
4+
import com.github.fridujo.classpath.junit.extension.buildtool.BuildTool;
5+
import com.github.fridujo.classpath.junit.extension.buildtool.BuildToolFactory;
6+
import com.github.fridujo.classpath.junit.extension.utils.Streams;
47

58
import java.io.File;
69
import java.net.URL;
710
import java.net.URLClassLoader;
8-
import java.util.Arrays;
9-
import java.util.Collections;
10-
import java.util.HashSet;
11-
import java.util.Set;
12-
import java.util.TreeSet;
11+
import java.util.*;
1312
import java.util.stream.Collectors;
1413

15-
import com.github.fridujo.classpath.junit.extension.buildtool.Artifact;
16-
import com.github.fridujo.classpath.junit.extension.buildtool.BuildTool;
17-
import com.github.fridujo.classpath.junit.extension.buildtool.BuildToolFactory;
18-
import com.github.fridujo.classpath.junit.extension.utils.Streams;
14+
import static java.util.Arrays.stream;
1915

2016
public class Classpath {
2117

@@ -83,7 +79,7 @@ public Classpath addDependency(String absoluteGavDescription) {
8379

8480
Set<PathElement> newPaths = new TreeSet<>(pathElements);
8581
Set<Artifact> artifactsToAdd = buildTool.downloadDependency(gav);
86-
newPaths.addAll(artifactsToAdd.stream().map(a -> a.path).collect(Collectors.toSet()));
82+
newPaths.addAll(artifactsToAdd.stream().map(Artifact::path).collect(Collectors.toSet()));
8783

8884
return new Classpath(newPaths, buildTool);
8985
}
@@ -97,13 +93,13 @@ private Classpath removeDependencyWithMatchingPath(Gav gav, PathElement matching
9793
if (!artifactsToRemove.isEmpty()) {
9894
Set<Artifact> gavsToKeep = new HashSet<>();
9995
for (PathElement pe : pathElements) {
100-
if (!pe.matches(gav) && artifactsToRemove.stream().noneMatch(a -> pe.matches(a.gav))) {
96+
if (!pe.matches(gav) && artifactsToRemove.stream().noneMatch(a -> pe.matches(a.gav()))) {
10197
gavsToKeep.addAll(buildTool.listDependencies(pe));
10298
}
10399
}
104100

105101
artifactsToRemove.removeAll(gavsToKeep);
106-
Set<Gav> gavsToRemove = artifactsToRemove.stream().map(a -> a.gav).collect(Collectors.toSet());
102+
Set<Gav> gavsToRemove = artifactsToRemove.stream().map(Artifact::gav).collect(Collectors.toSet());
107103
newPaths.removeIf(pe -> pe.matches(gavsToRemove));
108104
}
109105
return new Classpath(newPaths, buildTool);

src/main/java/com/github/fridujo/classpath/junit/extension/Gav.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ public Gav(String artifactId, String groupId, String version) {
2020
this.jarPattern = buildJarPattern(artifactId, groupId, version);
2121
}
2222

23-
public String getArtifactId() {
24-
return artifactId;
25-
}
26-
27-
public String getGroupId() {
28-
return groupId;
29-
}
30-
3123
private static Pattern buildJarPattern(String artifactId, String groupId, String version) {
3224
if (artifactId == null) {
3325
return null;
@@ -62,8 +54,16 @@ public static Gav parseAbsolute(String gav) {
6254
return new Gav(matcher.group("artifactId"), matcher.group("groupId"), matcher.group("version"));
6355
}
6456

57+
public String getArtifactId() {
58+
return artifactId;
59+
}
60+
61+
public String getGroupId() {
62+
return groupId;
63+
}
64+
6565
public boolean matchesJar(String rawJarPath) {
66-
return jarPattern != null ? jarPattern.matcher(rawJarPath).matches() : false;
66+
return jarPattern != null && jarPattern.matcher(rawJarPath).matches();
6767
}
6868

6969
public String toRelativePath() {

src/main/java/com/github/fridujo/classpath/junit/extension/buildtool/Artifact.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
11
package com.github.fridujo.classpath.junit.extension.buildtool;
22

3-
import java.util.Objects;
4-
53
import com.github.fridujo.classpath.junit.extension.Gav;
64
import com.github.fridujo.classpath.junit.extension.PathElement;
75

8-
public class Artifact implements Comparable<Artifact> {
9-
public final Gav gav;
10-
public final PathElement path;
11-
12-
public Artifact(Gav gav, PathElement path) {
13-
this.gav = gav;
14-
this.path = path;
15-
}
16-
17-
@Override
18-
public boolean equals(Object o) {
19-
if (this == o) return true;
20-
if (o == null || getClass() != o.getClass()) return false;
21-
Artifact artifact = (Artifact) o;
22-
return gav.equals(artifact.gav) &&
23-
path.equals(artifact.path);
24-
}
25-
26-
@Override
27-
public int hashCode() {
28-
return Objects.hash(gav, path);
29-
}
30-
31-
@Override
32-
public String toString() {
33-
return gav + " (" + path + ")";
34-
}
6+
public record Artifact(Gav gav, PathElement path) implements Comparable<Artifact> {
357

368
@Override
379
public int compareTo(Artifact o) {
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package com.github.fridujo.classpath.junit.extension.buildtool;
22

3-
import java.util.Set;
4-
53
import com.github.fridujo.classpath.junit.extension.Gav;
64
import com.github.fridujo.classpath.junit.extension.PathElement;
75

6+
import java.nio.file.Path;
7+
import java.util.Set;
8+
89
public interface BuildTool {
910

1011
Set<Artifact> listDependencies(PathElement path);
1112

1213
Set<Artifact> downloadDependency(Gav absoluteGav);
1314

1415
Gav toGav(PathElement pathElement);
16+
17+
Path deleteLocalDependency(Gav gav);
1518
}

src/main/java/com/github/fridujo/classpath/junit/extension/buildtool/BuildToolFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.github.fridujo.classpath.junit.extension.buildtool;
22

3-
import static java.util.Optional.empty;
3+
import com.github.fridujo.classpath.junit.extension.PathElement;
4+
import com.github.fridujo.classpath.junit.extension.utils.Streams;
45

56
import java.util.Optional;
67
import java.util.ServiceLoader;
78
import java.util.Set;
89

9-
import com.github.fridujo.classpath.junit.extension.PathElement;
10-
import com.github.fridujo.classpath.junit.extension.utils.Streams;
10+
import static java.util.Optional.empty;
1111

1212
public class BuildToolFactory {
1313

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.github.fridujo.classpath.junit.extension.buildtool;
2+
3+
import org.eclipse.aether.resolution.DependencyResolutionException;
4+
5+
public class RuntimeDependencyResolutionException extends RuntimeException {
6+
public RuntimeDependencyResolutionException(DependencyResolutionException e) {
7+
super(e);
8+
}
9+
10+
public RuntimeDependencyResolutionException(String message) {
11+
super(message);
12+
}
13+
}

src/main/java/com/github/fridujo/classpath/junit/extension/buildtool/maven/DependencyDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.github.fridujo.classpath.junit.extension.buildtool.maven;
22

3-
import java.util.Set;
4-
53
import com.github.fridujo.classpath.junit.extension.Gav;
64
import com.github.fridujo.classpath.junit.extension.buildtool.Artifact;
75

6+
import java.util.Set;
7+
88
class DependencyDescriptor {
99

1010
final Gav gav;

0 commit comments

Comments
 (0)