16
16
package org .springframework .rewrite ;
17
17
18
18
import org .apache .maven .execution .ExecutionEvent ;
19
+ import org .apache .maven .rtinfo .RuntimeInformation ;
20
+ import org .codehaus .plexus .component .repository .exception .ComponentLookupException ;
19
21
import org .jetbrains .annotations .NotNull ;
20
22
import org .openrewrite .ExecutionContext ;
21
23
import org .openrewrite .SourceFile ;
37
39
import org .springframework .rewrite .parser .events .SuccessfullyParsedProjectEvent ;
38
40
import org .springframework .rewrite .parser .maven .MavenBuildFileParser ;
39
41
import org .springframework .rewrite .parser .maven .MavenProject ;
40
- import org .springframework .rewrite .parser .maven .MavenProjectAnalyzer ;
42
+ import org .springframework .rewrite .parser .maven .MavenRuntimeInformation ;
41
43
import org .springframework .rewrite .parser .maven .ProvenanceMarkerFactory ;
42
44
import org .springframework .rewrite .scopes .ScanScope ;
43
45
import org .springframework .util .StringUtils ;
@@ -98,16 +100,13 @@ public class RewriteProjectParser {
98
100
99
101
private final ExecutionContext executionContext ;
100
102
101
- private final MavenProjectAnalyzer mavenProjectAnalyzer ;
102
-
103
103
private final MavenArtifactDownloader artifactDownloader ;
104
104
105
105
public RewriteProjectParser (ProvenanceMarkerFactory provenanceMarkerFactory , MavenBuildFileParser buildFileParser ,
106
106
SourceFileParser sourceFileParser , StyleDetector styleDetector ,
107
107
SpringRewriteProperties springRewriteProperties , ParsingEventListener parsingEventListener ,
108
108
ApplicationEventPublisher eventPublisher , ScanScope scanScope , ConfigurableListableBeanFactory beanFactory ,
109
- ProjectScanner scanner , ExecutionContext executionContext , MavenProjectAnalyzer mavenProjectAnalyzer ,
110
- MavenArtifactDownloader artifactDownloader ) {
109
+ ProjectScanner scanner , ExecutionContext executionContext , MavenArtifactDownloader artifactDownloader ) {
111
110
this .provenanceMarkerFactory = provenanceMarkerFactory ;
112
111
this .buildFileParser = buildFileParser ;
113
112
this .sourceFileParser = sourceFileParser ;
@@ -119,7 +118,6 @@ public RewriteProjectParser(ProvenanceMarkerFactory provenanceMarkerFactory, Mav
119
118
this .beanFactory = beanFactory ;
120
119
this .scanner = scanner ;
121
120
this .executionContext = executionContext ;
122
- this .mavenProjectAnalyzer = mavenProjectAnalyzer ;
123
121
this .artifactDownloader = artifactDownloader ;
124
122
}
125
123
@@ -157,13 +155,16 @@ public RewriteProjectParsingResult parse(Path givenBaseDir, List<Resource> resou
157
155
return new RewriteProjectParsingResult (sourceFilesRef .get (), executionContext );
158
156
}
159
157
160
- private List <SourceFile > runInMavenSession (ExecutionEvent onSuccess , Path baseDir , List <Resource > resources ) {
158
+ private List <SourceFile > runInMavenSession (ExecutionEvent executionEvent , Path baseDir , List <Resource > resources ) {
161
159
List <NamedStyles > styles = List .of ();
162
- List <MavenProject > sortedProjects = onSuccess .getSession ()
160
+
161
+ final RuntimeInformation runtimeInformation = getRuntimeInformation (executionEvent );
162
+
163
+ List <MavenProject > sortedProjects = executionEvent .getSession ()
163
164
.getProjectDependencyGraph ()
164
165
.getSortedProjects ()
165
166
.stream ()
166
- .map (p -> this .mavenProjectToMavenProject (p , artifactDownloader , resources ))
167
+ .map (p -> this .mavenProjectToMavenProject (p , artifactDownloader , resources , runtimeInformation ))
167
168
.toList ();
168
169
169
170
ParserContext parserContext = new ParserContext (baseDir , resources , sortedProjects );
@@ -197,15 +198,29 @@ private List<SourceFile> runInMavenSession(ExecutionEvent onSuccess, Path baseDi
197
198
return sourceFiles ;
198
199
}
199
200
201
+ private static RuntimeInformation getRuntimeInformation (ExecutionEvent onSuccess ) {
202
+ RuntimeInformation runtimeInformation ;
203
+ try {
204
+ runtimeInformation = onSuccess .getSession ().getContainer ().lookup (RuntimeInformation .class );
205
+ }
206
+ catch (ComponentLookupException e ) {
207
+ throw new RuntimeException (e );
208
+ }
209
+ return runtimeInformation ;
210
+ }
211
+
200
212
private MavenProject mavenProjectToMavenProject (org .apache .maven .project .MavenProject mavenProject ,
201
- MavenArtifactDownloader artifactDownloader , List <Resource > resources ) {
213
+ MavenArtifactDownloader artifactDownloader , List <Resource > resources ,
214
+ RuntimeInformation runtimeInformation ) {
202
215
Path baseDir = mavenProject .getBasedir ().toPath ();
203
216
File file = mavenProject .getExecutionProject ().getFile ();
204
217
Resource rootPom = new FileSystemResource (file );
205
- MavenProject newMavenProject = new MavenProject (baseDir , rootPom , artifactDownloader , resources );
218
+
219
+ MavenProject newMavenProject = new MavenProject (baseDir , rootPom , artifactDownloader , resources ,
220
+ new MavenRuntimeInformation (runtimeInformation .getMavenVersion ()));
206
221
List <MavenProject > mavenProjects = mavenProject .getCollectedProjects ()
207
222
.stream ()
208
- .map (p -> this .mavenProjectToMavenProject (p , artifactDownloader , resources ))
223
+ .map (p -> this .mavenProjectToMavenProject (p , artifactDownloader , resources , runtimeInformation ))
209
224
.toList ();
210
225
newMavenProject .setReactorProjects (mavenProjects );
211
226
return newMavenProject ;
0 commit comments