|
22 | 22 | import org.openrewrite.SourceFile;
|
23 | 23 | import org.openrewrite.internal.ListUtils;
|
24 | 24 | import org.openrewrite.internal.lang.Nullable;
|
| 25 | +import org.openrewrite.java.migrate.MavenUtils; |
25 | 26 | import org.openrewrite.maven.AddDependencyVisitor;
|
26 | 27 | import org.openrewrite.maven.RemoveDependency;
|
27 |
| -import org.openrewrite.maven.tree.*; |
| 28 | +import org.openrewrite.maven.tree.GroupArtifactVersion; |
| 29 | +import org.openrewrite.maven.tree.MavenResolutionResult; |
| 30 | +import org.openrewrite.maven.tree.ResolvedDependency; |
| 31 | +import org.openrewrite.maven.tree.Scope; |
28 | 32 |
|
29 | 33 | import java.time.Duration;
|
30 |
| -import java.util.HashMap; |
31 | 34 | import java.util.List;
|
32 | 35 | import java.util.Map;
|
| 36 | +import java.util.function.Function; |
| 37 | +import java.util.stream.Collectors; |
33 | 38 |
|
34 | 39 | import static org.openrewrite.java.migrate.MavenUtils.getMavenModel;
|
35 | 40 | import static org.openrewrite.java.migrate.MavenUtils.isMavenSource;
|
@@ -62,19 +67,19 @@ public Duration getEstimatedEffortPerOccurrence() {
|
62 | 67 | @Override
|
63 | 68 | protected List<SourceFile> visit(List<SourceFile> before, ExecutionContext ctx) {
|
64 | 69 | //remove legacy jaxws-ri library (in favor of the jakarta runtime)
|
65 |
| - doNext(new RemoveDependency("com.sun.xml.ws", "jaxws-ri", null)); |
| 70 | + doNext(new RemoveDependency(SUN_JAXWS_RUNTIME_GROUP, "jaxws-ri", null)); |
66 | 71 |
|
67 | 72 | //Collect a map of gav coordinates to pom models for any maven files in the source set (other visitors may have
|
68 | 73 | //made changes to those models)
|
69 |
| - Map<GroupArtifactVersion, MavenResolutionResult> gavToModel = new HashMap<>(); |
70 |
| - List<SourceFile> sources = ListUtils.map(before, s -> { |
71 |
| - if (isMavenSource(s)) { |
72 |
| - MavenResolutionResult mavenModel = getMavenModel(s); |
73 |
| - gavToModel.put(new GroupArtifactVersion(mavenModel.getPom().getGroupId(),mavenModel.getPom().getArtifactId(), mavenModel.getPom().getVersion()), mavenModel); |
74 |
| - } |
75 |
| - return s; |
76 |
| - }); |
77 |
| - |
| 74 | + Map<GroupArtifactVersion, MavenResolutionResult> gavToModel = before.stream() |
| 75 | + .filter(MavenUtils::isMavenSource) |
| 76 | + .map(MavenUtils::getMavenModel) |
| 77 | + .collect(Collectors.toMap( |
| 78 | + mavenModel -> new GroupArtifactVersion( |
| 79 | + mavenModel.getPom().getGroupId(), |
| 80 | + mavenModel.getPom().getArtifactId(), |
| 81 | + mavenModel.getPom().getVersion()), |
| 82 | + Function.identity())); |
78 | 83 | return ListUtils.map(before, s -> {
|
79 | 84 | if (isMavenSource(s)) {
|
80 | 85 | MavenResolutionResult mavenModel = getMavenModel(s);
|
@@ -107,8 +112,7 @@ protected List<SourceFile> visit(List<SourceFile> before, ExecutionContext ctx)
|
107 | 112 | * @return The highest scope of the given dependency or null if the dependency does not exist.
|
108 | 113 | */
|
109 | 114 | @Nullable
|
110 |
| - private Scope getTransitiveDependencyScope(MavenResolutionResult mavenModel, String groupId, String artifactId, Map<GroupArtifactVersion, MavenResolutionResult> gavToModels) { |
111 |
| - |
| 115 | + private static Scope getTransitiveDependencyScope(MavenResolutionResult mavenModel, String groupId, String artifactId, Map<GroupArtifactVersion, MavenResolutionResult> gavToModels) { |
112 | 116 | Scope maxScope = null;
|
113 | 117 | for (Map.Entry<Scope, List<ResolvedDependency>> entry : mavenModel.getDependencies().entrySet()) {
|
114 | 118 | for (ResolvedDependency dependency : entry.getValue()) {
|
|
0 commit comments