@@ -92,13 +92,11 @@ public TreeVisitor<?, ExecutionContext> getScanner(List<SourceFile> acc) {
92
92
93
93
@ Override
94
94
public Collection <? extends SourceFile > generate (List <SourceFile > generate , ExecutionContext executionContext ) {
95
- // Collection<? extends SourceFile> generate = super.generate(acc, executionContext);
96
-
97
95
// create the required classes
98
- initBeans (executionContext );
96
+ initBeans ();
99
97
100
98
// transform nodes to SourceFiles
101
- List <SourceFile > sourceFiles = generate . stream (). filter ( SourceFile . class :: isInstance ). map ( SourceFile . class :: cast ). toList () ;
99
+ List <SourceFile > sourceFiles = generate ;
102
100
103
101
// FIXME: base dir calculation is fake
104
102
Path baseDir = Path .of ("." ).resolve ("testcode/jee/jaxrs/bootify-jaxrs/given" ).toAbsolutePath ().normalize (); //executionContext.getMessage("base.dir");
@@ -114,61 +112,19 @@ public Collection<? extends SourceFile> generate(List<SourceFile> generate, Exec
114
112
RewriteRecipeLoader recipeLoader = new RewriteRecipeLoader ();
115
113
new MigrateJaxRsRecipe ().jaxRs (recipeLoader ).apply (pc );
116
114
117
- // Merge back result
118
- List <? extends SourceFile > modifiedNodes = merge (sourceFiles , pc .getProjectResources ());
119
-
120
- return modifiedNodes ;
121
- }
122
-
123
- private List <? extends SourceFile > merge (List <SourceFile > nodes , ProjectResourceSet projectResources ) {
124
- // merge the changed results into the given list and return the result
125
- ArrayList <SourceFile > merged = new ArrayList <>();
126
- merged .addAll (nodes );
127
- projectResources .stream ()
128
- .filter (r -> r .hasChanges ())
129
- .forEach (changed -> {
130
- int pos = findPosition (merged , changed );
131
- merged .add (pos , changed .getSourceFile ());
132
- });
133
- return merged ;
134
- }
115
+ List <? extends SourceFile > list = pc .getProjectResources ().stream ()
116
+ .map (pr -> pr .getSourceFile ())
117
+ .toList ();
135
118
136
- private int findPosition (List <SourceFile > merged , RewriteSourceFileHolder <? extends SourceFile > changed ) {
137
- List <String > paths = merged .stream ().map (f -> f .getSourcePath ().toString ()).toList ();
138
- return paths .indexOf (changed .getSourcePath ().toString ());
119
+ return list ;
139
120
}
140
121
141
-
142
- private void initBeans ( ExecutionContext executionContext ) {
122
+ private void initBeans () {
123
+ // ExecutionContext is not retrieved from OpenRewrite here
143
124
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ("org.springframework.freemarker" , "org.springframework.sbm" , "org.springframework.rewrite" );
144
125
ctx .register (Configuration .class );
145
126
this .projectContextFactory = ctx .getBean (ProjectContextFactory .class );
146
127
this .projectResourceSetFactory = ctx .getBean (ProjectResourceSetFactory .class );
147
- // RewriteSourceFileWrapper sourceFileWrapper = new RewriteSourceFileWrapper();
148
- // SbmApplicationProperties sbmApplicationProperties = new SbmApplicationProperties();
149
- // JavaParserBuilder parserBuilder = new JavaParserBuilder();
150
- // List<ProjectResourceWrapper> projectResourceWrappers = new ArrayList<>();
151
- // RewriteMigrationResultMerger merger = new RewriteMigrationResultMerger(sourceFileWrapper);
152
- // ProjectResourceSetHolder holder = new ProjectResourceSetHolder(executionContext, merger);
153
- // JavaRefactoringFactory refactoringFactory = new JavaRefactoringFactoryImpl(holder, executionContext);
154
- // projectResourceWrappers.add(new JavaSourceProjectResourceWrapper(refactoringFactory, parserBuilder, executionContext));
155
- // ProjectMetadata projectMetadata = new ProjectMetadata();
156
- // MavenBuildFileRefactoringFactory buildFileRefactoringFactory = new MavenBuildFileRefactoringFactory(holder, new RewriteMavenParser(new MavenSettingsInitializer(executionContext, projectMetadata), executionContext), executionContext);
157
- // projectResourceWrappers.add(new BuildFileResourceWrapper(
158
- // event -> System.out.println(event),
159
- // buildFileRefactoringFactory,
160
- // executionContext,
161
- // new RewriteMavenArtifactDownloader(new LocalMavenArtifactCache(Path.of(System.getProperty("user.dir")).resolve(".m2/repository")), new MavenSettings(), t -> {throw new RuntimeException(t);}))
162
- // );
163
- //
164
- //
165
- // projectResourceSetFactory = new ProjectResourceSetFactory(new RewriteMigrationResultMerger(sourceFileWrapper), sourceFileWrapper, executionContext);
166
- // ProjectResourceWrapperRegistry registry = new ProjectResourceWrapperRegistry(projectResourceWrappers);
167
- // BasePackageCalculator calculator = new BasePackageCalculator(sbmApplicationProperties);
168
- //
169
- // ProjectResourceSetFactory resourceSetFactory = new ProjectResourceSetFactory(merger, sourceFileWrapper, executionContext);
170
- //
171
- // projectContextFactory = new ProjectContextFactory(registry, holder, refactoringFactory, calculator, parserBuilder, executionContext, merger, resourceSetFactory);
172
128
}
173
129
174
130
}
0 commit comments