|
23 | 23 | import java.util.stream.Collectors; |
24 | 24 | import org.apache.maven.artifact.Artifact; |
25 | 25 | import org.apache.maven.artifact.DefaultArtifact; |
26 | | -import org.apache.maven.artifact.factory.ArtifactFactory; |
27 | 26 | import org.apache.maven.artifact.resolver.filter.ArtifactFilter; |
28 | 27 | import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; |
29 | 28 | import org.apache.maven.execution.MavenSession; |
|
37 | 36 | import org.apache.maven.shared.dependency.graph.DependencyCollectorBuilder; |
38 | 37 | import org.apache.maven.shared.dependency.graph.DependencyNode; |
39 | 38 | import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; |
40 | | -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver; |
41 | | -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult; |
42 | 39 |
|
43 | 40 | /** |
44 | 41 | * Entry point for the lock file generation. This class is responsible for generating the lock file for a project. |
@@ -98,11 +95,12 @@ public static LockFile generateLockFileFromProject( |
98 | 95 | MavenProject project, |
99 | 96 | DependencyCollectorBuilder dependencyCollectorBuilder, |
100 | 97 | AbstractChecksumCalculator checksumCalculator, |
101 | | - MetaData metadata) { |
| 98 | + MetaData metadata, |
| 99 | + ProjectBuilder projectBuilder) { |
102 | 100 | PluginLogManager.getLog().info(String.format("Generating lock file for project %s", project.getArtifactId())); |
103 | 101 | Set<MavenPlugin> plugins = new TreeSet<>(); |
104 | 102 | if (metadata.getConfig().isIncludeMavenPlugins()) { |
105 | | - plugins = getAllPlugins(project, session, dependencyCollectorBuilder, checksumCalculator); |
| 103 | + plugins = getAllPlugins(project, session, dependencyCollectorBuilder, checksumCalculator, projectBuilder); |
106 | 104 | } |
107 | 105 | // Get all the artifacts for the dependencies in the project |
108 | 106 | var graph = LockFileFacade.graph( |
@@ -130,7 +128,8 @@ private static Set<MavenPlugin> getAllPlugins( |
130 | 128 | MavenProject project, |
131 | 129 | MavenSession session, |
132 | 130 | DependencyCollectorBuilder dependencyCollectorBuilder, |
133 | | - AbstractChecksumCalculator checksumCalculator) { |
| 131 | + AbstractChecksumCalculator checksumCalculator, |
| 132 | + ProjectBuilder projectBuilder) { |
134 | 133 | Set<MavenPlugin> plugins = new TreeSet<>(); |
135 | 134 |
|
136 | 135 | // Build a map of user-declared plugin dependencies |
@@ -158,7 +157,8 @@ private static Set<MavenPlugin> getAllPlugins( |
158 | 157 | project, |
159 | 158 | dependencyCollectorBuilder, |
160 | 159 | checksumCalculator, |
161 | | - userDeclaredDeps); |
| 160 | + userDeclaredDeps, |
| 161 | + projectBuilder); |
162 | 162 | plugins.add(new MavenPlugin( |
163 | 163 | GroupId.of(pluginArtifact.getGroupId()), |
164 | 164 | ArtifactId.of(pluginArtifact.getArtifactId()), |
@@ -189,7 +189,8 @@ private static Set<io.github.chains_project.maven_lockfile.graph.DependencyNode> |
189 | 189 | MavenProject project, |
190 | 190 | DependencyCollectorBuilder dependencyCollectorBuilder, |
191 | 191 | AbstractChecksumCalculator checksumCalculator, |
192 | | - List<Dependency> userDeclaredDeps) { |
| 192 | + List<Dependency> userDeclaredDeps, |
| 193 | + ProjectBuilder projectBuilder) { |
193 | 194 | PluginLogManager.getLog() |
194 | 195 | .debug(String.format("Attempting to resolve dependencies for plugin %s", pluginArtifact)); |
195 | 196 | try { |
@@ -230,29 +231,9 @@ private static Set<io.github.chains_project.maven_lockfile.graph.DependencyNode> |
230 | 231 | if (Files.exists(localPomPath)) { |
231 | 232 | pluginPomFile = localPomPath.toFile(); |
232 | 233 | } else { |
233 | | - // If not in local repo, try to resolve it using artifact resolver |
234 | | - @SuppressWarnings("deprecation") |
235 | | - ArtifactFactory artifactFactory = session.getContainer().lookup(ArtifactFactory.class); |
236 | | - Artifact pomArtifact = artifactFactory.createArtifact( |
237 | | - pluginArtifact.getGroupId(), |
238 | | - pluginArtifact.getArtifactId(), |
239 | | - pluginArtifact.getVersion(), |
240 | | - null, |
241 | | - "pom"); |
242 | | - |
243 | | - ProjectBuildingRequest pomBuildingRequest = |
244 | | - new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); |
245 | | - pomBuildingRequest.setRemoteRepositories(project.getPluginArtifactRepositories()); |
246 | | - |
247 | | - @SuppressWarnings("deprecation") |
248 | | - ArtifactResolver artifactResolver = |
249 | | - session.getContainer().lookup(ArtifactResolver.class); |
250 | | - ArtifactResult result = artifactResolver.resolveArtifact(pomBuildingRequest, pomArtifact); |
251 | | - if (result != null |
252 | | - && result.getArtifact() != null |
253 | | - && result.getArtifact().getFile() != null) { |
254 | | - pluginPomFile = result.getArtifact().getFile(); |
255 | | - } |
| 234 | + PluginLogManager.getLog() |
| 235 | + .debug(String.format( |
| 236 | + "POM not found in local repository for plugin %s", pluginArtifact)); |
256 | 237 | } |
257 | 238 | } catch (Exception e) { |
258 | 239 | PluginLogManager.getLog() |
@@ -282,9 +263,6 @@ private static Set<io.github.chains_project.maven_lockfile.graph.DependencyNode> |
282 | 263 | buildingRequest.setProcessPlugins(false); |
283 | 264 | buildingRequest.setResolveDependencies(true); |
284 | 265 |
|
285 | | - // Note: getContainer() is deprecated but there's no clear replacement in the current Maven API |
286 | | - @SuppressWarnings("deprecation") |
287 | | - ProjectBuilder projectBuilder = session.getContainer().lookup(ProjectBuilder.class); |
288 | 266 | ProjectBuildingResult result = projectBuilder.build(pluginPomFile, buildingRequest); |
289 | 267 |
|
290 | 268 | if (result.getProblems() != null && !result.getProblems().isEmpty()) { |
|
0 commit comments