|
17 | 17 |
|
18 | 18 | import org.gradle.api.Project; |
19 | 19 | import org.gradle.api.artifacts.*; |
20 | | -import org.gradle.api.artifacts.Dependency; |
21 | | -import org.gradle.api.artifacts.ResolvedDependency; |
22 | 20 | import org.gradle.api.artifacts.repositories.ArtifactRepository; |
23 | 21 | import org.gradle.api.artifacts.repositories.MavenArtifactRepository; |
24 | 22 | import org.gradle.api.attributes.Attribute; |
|
31 | 29 | import org.gradle.util.GradleVersion; |
32 | 30 | import org.jspecify.annotations.Nullable; |
33 | 31 | import org.openrewrite.gradle.attributes.Category; |
34 | | -import org.openrewrite.maven.tree.*; |
| 32 | +import org.openrewrite.maven.tree.GroupArtifact; |
| 33 | +import org.openrewrite.maven.tree.GroupArtifactVersion; |
| 34 | +import org.openrewrite.maven.tree.MavenRepository; |
| 35 | +import org.openrewrite.maven.tree.ResolvedGroupArtifactVersion; |
35 | 36 |
|
36 | 37 | import java.lang.reflect.InvocationTargetException; |
37 | 38 | import java.lang.reflect.Method; |
38 | 39 | import java.util.*; |
39 | 40 | import java.util.concurrent.ConcurrentHashMap; |
| 41 | + |
40 | 42 | import static java.util.Collections.*; |
41 | 43 | import static java.util.stream.Collectors.*; |
42 | | -import static java.util.stream.Collectors.toSet; |
43 | 44 | import static org.openrewrite.Tree.randomId; |
44 | 45 | import static org.openrewrite.gradle.marker.GradleSettingsBuilder.GRADLE_PLUGIN_PORTAL; |
45 | 46 |
|
@@ -287,16 +288,16 @@ private static List<org.openrewrite.gradle.marker.GradleDependencyConstraint> co |
287 | 288 | private static org.openrewrite.maven.tree.Dependency dependency(Dependency dep, Configuration configuration) { |
288 | 289 | GroupArtifactVersion gav = groupArtifactVersion(dep); |
289 | 290 | return requestedCache.computeIfAbsent(gav, it -> { |
290 | | - Map<String, String> attributes = attributes(dep); |
| 291 | + Map<String, String> attributes = attributes(dep); |
291 | 292 |
|
292 | | - String type = "jar"; |
293 | | - if(Optional.ofNullable(Category.from(attributes.get(Category.key()))) |
294 | | - .filter(cat -> cat == Category.REGULAR_PLATFORM || cat == Category.ENFORCED_PLATFORM) |
295 | | - .isPresent()) { |
296 | | - type = "pom"; |
297 | | - } |
| 293 | + String type = "jar"; |
| 294 | + if (Optional.ofNullable(Category.from(attributes.get(Category.key()))) |
| 295 | + .filter(cat -> cat == Category.REGULAR_PLATFORM || cat == Category.ENFORCED_PLATFORM) |
| 296 | + .isPresent()) { |
| 297 | + type = "pom"; |
| 298 | + } |
298 | 299 |
|
299 | | - return org.openrewrite.maven.tree.Dependency.builder() |
| 300 | + return org.openrewrite.maven.tree.Dependency.builder() |
300 | 301 | .gav(gav) |
301 | 302 | .type(type) |
302 | 303 | .scope(configuration.getName()) |
@@ -330,12 +331,12 @@ private static String projectPath(ProjectDependency pd) { |
330 | 331 | try { |
331 | 332 | // ProjectDependency.getPath introduced in gradle 8.11 |
332 | 333 | Method getPath = ProjectDependency.class.getMethod("getPath"); |
333 | | - return (String) getPath.invoke(pd); |
| 334 | + return (String) getPath.invoke(pd); |
334 | 335 | } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
335 | 336 | // ProjectDependency.getDependencyProject() scheduled for removal in Gradle 9.0 |
336 | 337 | try { |
337 | 338 | Method getDependencyProject = ProjectDependency.class.getMethod("getDependencyProject"); |
338 | | - return ((Project)getDependencyProject.invoke(pd)).getPath(); |
| 339 | + return ((Project) getDependencyProject.invoke(pd)).getPath(); |
339 | 340 | } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { |
340 | 341 | // All supported versions of Gradle have getPath(), getDependencyProject(), or both, so this hopefully never happens |
341 | 342 | throw new IllegalStateException(e); |
@@ -388,10 +389,10 @@ private static org.openrewrite.maven.tree.Dependency dependency(ResolvedDependen |
388 | 389 | return requestedCache.computeIfAbsent(gav, it -> { |
389 | 390 | // Synthesize a Category attribute if this is a BOM |
390 | 391 | String type = "jar"; |
391 | | - Map<String, String> attributes = Collections.emptyMap(); |
| 392 | + Map<String, String> attributes = emptyMap(); |
392 | 393 | // Both enforcedPlatform() and platform() appear the same in this context, so assume platform() |
393 | 394 | if (dep.getConfiguration().startsWith("platform-")) { |
394 | | - attributes = Collections.singletonMap(Category.key(), "platform"); |
| 395 | + attributes = singletonMap(Category.key(), "platform"); |
395 | 396 | type = "pom"; |
396 | 397 | } |
397 | 398 |
|
|
0 commit comments