3333import org .openrewrite .java .JavaIsoVisitor ;
3434import org .openrewrite .java .JavaVisitor ;
3535import org .openrewrite .java .MethodMatcher ;
36- import org .openrewrite .java .marker .JavaProject ;
37- import org .openrewrite .java .marker .JavaSourceSet ;
3836import org .openrewrite .java .tree .Expression ;
3937import org .openrewrite .java .tree .J ;
4038import org .openrewrite .java .tree .JavaSourceFile ;
4139import org .openrewrite .kotlin .tree .K ;
42- import org .openrewrite .maven .utilities .JavaSourceSetUpdater ;
4340import org .openrewrite .marker .Markup ;
4441import org .openrewrite .maven .MavenDownloadingException ;
4542import org .openrewrite .maven .internal .MavenPomDownloader ;
@@ -134,8 +131,6 @@ public static class DependencyVersionState {
134131 Map <GroupArtifact , @ Nullable Object > gaToNewVersion = new HashMap <>();
135132
136133 Map <String , Map <GroupArtifact , Set <String >>> configurationPerGAPerModule = new HashMap <>();
137-
138- Map <JavaProject , Set <ResolvedDependency >> modulesWithDependency = new HashMap <>();
139134 }
140135
141136 @ Override
@@ -161,24 +156,6 @@ public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) {
161156 public @ Nullable J visit (@ Nullable Tree tree , ExecutionContext ctx ) {
162157 if (tree instanceof JavaSourceFile ) {
163158 gradleProject = tree .getMarkers ().findFirst (GradleProject .class ).orElse (null );
164- // Record modules with matching resolved dependencies for JavaSourceSet updates
165- if (gradleProject != null ) {
166- Optional <JavaProject > maybeJp = tree .getMarkers ().findFirst (JavaProject .class );
167- if (maybeJp .isPresent () && !acc .modulesWithDependency .containsKey (maybeJp .get ())) {
168- DependencyMatcher depMatcher = new DependencyMatcher (groupId , artifactId , null );
169- Set <ResolvedDependency > matched = new HashSet <>();
170- for (GradleDependencyConfiguration config : gradleProject .getConfigurations ()) {
171- for (ResolvedDependency resolved : config .getDirectResolvedShallow ()) {
172- if (depMatcher .matches (resolved .getGroupId (), resolved .getArtifactId ())) {
173- matched .add (resolved );
174- }
175- }
176- }
177- if (!matched .isEmpty ()) {
178- acc .modulesWithDependency .put (maybeJp .get (), matched );
179- }
180- }
181- }
182159 }
183160 return super .visit (tree , ctx );
184161 }
@@ -311,21 +288,13 @@ private void gatherVariables(GradleDependency gradleDependency) {
311288
312289 @ Override
313290 public TreeVisitor <?, ExecutionContext > getVisitor (DependencyVersionState acc ) {
314- boolean hasModulesWithDep = !acc .modulesWithDependency .isEmpty ();
315291 return new TreeVisitor <Tree , ExecutionContext >() {
316292 private final UpdateGradle updateGradle = new UpdateGradle (acc );
317293 private final UpdateProperties updateProperties = new UpdateProperties (acc );
318- @ Nullable
319- private JavaSourceSetUpdater jssUpdater ;
320- private final Map <String , JavaSourceSet > updatedSourceSets = new HashMap <>();
321294
322295 @ Override
323296 public boolean isAcceptable (SourceFile sf , ExecutionContext ctx ) {
324- if (updateProperties .isAcceptable (sf , ctx ) || updateGradle .isAcceptable (sf , ctx )) {
325- return true ;
326- }
327- return hasModulesWithDep && sf instanceof JavaSourceFile
328- && !(sf instanceof G .CompilationUnit ) && !(sf instanceof K .CompilationUnit );
297+ return updateProperties .isAcceptable (sf , ctx ) || updateGradle .isAcceptable (sf , ctx );
329298 }
330299
331300 @ Override
@@ -334,11 +303,6 @@ public boolean isAcceptable(SourceFile sf, ExecutionContext ctx) {
334303 Tree t = tree ;
335304 if (t instanceof SourceFile ) {
336305 SourceFile sf = (SourceFile ) t ;
337- // Handle regular Java source files for JavaSourceSet updates
338- if (hasModulesWithDep && sf instanceof JavaSourceFile
339- && !(sf instanceof G .CompilationUnit ) && !(sf instanceof K .CompilationUnit )) {
340- return updateJavaSourceSet (sf , ctx );
341- }
342306 if (updateProperties .isAcceptable (sf , ctx )) {
343307 t = updateProperties .visitNonNull (t , ctx );
344308 } else if (updateGradle .isAcceptable (sf , ctx )) {
@@ -395,41 +359,6 @@ public boolean isAcceptable(SourceFile sf, ExecutionContext ctx) {
395359 return t ;
396360 }
397361
398- private SourceFile updateJavaSourceSet (SourceFile sf , ExecutionContext ctx ) {
399- Optional <JavaProject > maybeJp = sf .getMarkers ().findFirst (JavaProject .class );
400- if (!maybeJp .isPresent ()) {
401- return sf ;
402- }
403- Set <ResolvedDependency > oldDeps = acc .modulesWithDependency .get (maybeJp .get ());
404- if (oldDeps == null || oldDeps .isEmpty ()) {
405- return sf ;
406- }
407- return JavaSourceSet .updateOnSourceFile (sf , updatedSourceSets , sourceSet -> {
408- if (sourceSet .getGavToTypes ().isEmpty ()) {
409- return sourceSet ;
410- }
411- if (jssUpdater == null ) {
412- jssUpdater = new JavaSourceSetUpdater (ctx );
413- }
414- JavaSourceSet result = sourceSet ;
415- for (ResolvedDependency oldDep : oldDeps ) {
416- GroupArtifact ga = new GroupArtifact (oldDep .getGroupId (), oldDep .getArtifactId ());
417- Object newVersionObj = acc .gaToNewVersion .get (ga );
418- if (!(newVersionObj instanceof String )) {
419- continue ;
420- }
421- String resolvedNewVersion = (String ) newVersionObj ;
422- ResolvedGroupArtifactVersion newGav = new ResolvedGroupArtifactVersion (
423- oldDep .getGav ().getRepository (),
424- oldDep .getGroupId (), oldDep .getArtifactId (), resolvedNewVersion , null );
425- ResolvedDependency newDep = oldDep
426- .withGav (newGav )
427- .withRepository (MavenRepository .MAVEN_CENTRAL );
428- result = jssUpdater .changeDependency (result , oldDep , newDep );
429- }
430- return result ;
431- });
432- }
433362 };
434363 }
435364
0 commit comments