Skip to content

Commit 63a331e

Browse files
committed
Merge branch 'version/revamp' into 858-incorporate-new-parser-into-core
2 parents 1eae0bb + 0fe60f7 commit 63a331e

File tree

13 files changed

+113
-80
lines changed

13 files changed

+113
-80
lines changed

components/sbm-core/src/main/java/org/springframework/sbm/build/impl/OpenRewriteMavenBuildFile.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public List<Dependency> getDeclaredDependencies(Scope... scopes) {
290290
} else {
291291
// FIXME: scope test should also return compile!
292292
return Arrays.stream(scopes).anyMatch(scope -> {
293-
String effectiveScope = d.getScope();
293+
String effectiveScope = d.getScope() == null ? "compile" : d.getScope();
294294
return scope.toString().equalsIgnoreCase(effectiveScope);
295295
});
296296
}
@@ -306,9 +306,9 @@ public List<Dependency> getDeclaredDependencies(Scope... scopes) {
306306
public List<Dependency> getRequestedDependencies() {
307307
List<org.openrewrite.maven.tree.Dependency> requestedDependencies = getPom().getPom().getRequestedDependencies();
308308
// FIXME: #7 use getPom().getDependencies() instead ?
309-
return requestedDependencies.stream()
309+
List<Dependency> declaredDependenciesWithEffectiveVersions = requestedDependencies.stream()
310310
.map(this::mapDependency)
311-
.peek(d -> {
311+
.map(d -> {
312312
if(d.getType() == null || d.getClassifier() == null || d.getVersion() == null) {
313313

314314
// resolve values for properties like ${my.artifactId} or ${dep.version}
@@ -339,11 +339,16 @@ public List<Dependency> getRequestedDependencies() {
339339

340340
if(d.getScope() == null ) {
341341
String s = resolveScope(resolvedGroupId, resolvedArtifactId, d.getType(), d.getClassifier());
342+
if(s == null) {
343+
s = "compile";
344+
}
342345
d.setScope(s.toLowerCase());
343346
}
344347
}
348+
return d;
345349
})
346350
.collect(Collectors.toList());
351+
return declaredDependenciesWithEffectiveVersions;
347352
}
348353

349354
@Override
@@ -563,7 +568,9 @@ public List<Dependency> getEffectiveDependencyManagement() {
563568
@Override
564569
public List<Dependency> getRequestedDependencyManagement() {
565570
MavenResolutionResult pom = getPom();
566-
pom.getPom().getRequested();
571+
if (pom.getPom().getRequested().getDependencyManagement() == null) {
572+
return Collections.emptyList();
573+
}
567574
return pom.getPom().getRequested().getDependencyManagement().stream()
568575
.map(this::getDependency)
569576
.distinct()
@@ -646,14 +653,19 @@ public Set<Path> getClasspath(Scope scope) {
646653
return classpath;
647654
}
648655

656+
@NotNull
657+
private boolean filterProjectDependencies(ResolvedDependency rd) {
658+
return rd.getRepository() != null;
659+
}
660+
649661
@Override
650662
public boolean hasPlugin(Plugin plugin) {
651663
// TODO: [FK] discuss how to handle conditions. This code is exactly the same as in #AddMavenPluginVisitor.pluginDefinitionExists(Maven.Pom pom) which is private and the test would repeat the test for AddMavenPluginVisitor
652664
Xml.Document sourceFile = getSourceFile();
653665
Optional<Xml.Tag> pluginDefinition = sourceFile.getRoot().getChildren("build").stream()
654666
.flatMap(b -> b.getChildren("plugins").stream())
655667
.flatMap(b -> b.getChildren("plugin").stream())
656-
.filter(p -> !p.getChildren("groupId").isEmpty())
668+
.filter(p -> p.getChildren("groupId") != null && !p.getChildren("groupId").isEmpty())
657669
.filter(p -> {
658670
List<? extends Content> groupId1 = p.getChildren("groupId").get(0).getContent();
659671
if(groupId1 == null) {
@@ -724,7 +736,11 @@ final public void setProperty(String key, String value) {
724736

725737
@Override
726738
public String getPackaging() {
727-
return getPom().getPom().getPackaging();
739+
String packaging = getPom().getPom().getPackaging();
740+
if (packaging == null) {
741+
packaging = "jar";
742+
}
743+
return packaging;
728744
}
729745

730746
@Override

components/sbm-core/src/main/java/org/springframework/sbm/java/impl/OpenRewriteMember.java

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public boolean hasAnnotation(String annotationFqName) {
111111
public void addAnnotation(String fqName) {
112112
String snippet = "@" + fqName.substring(fqName.lastIndexOf('.') + 1);
113113
AddAnnotationVisitor addAnnotationVisitor = new AddAnnotationVisitor(() -> javaParserBuilder, getVariableDeclarations(), snippet, fqName);
114+
AddAnnotationVisitor addAnnotationVisitor = new AddAnnotationVisitor(() -> javaParserBuilder.getBuilder(), getVariableDeclarations(), snippet, fqName);
114115
refactoring.refactor(rewriteSourceFileHolder, addAnnotationVisitor);
115116
}
116117

components/sbm-core/src/main/java/org/springframework/sbm/project/parser/MavenProjectParser.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public class MavenProjectParser {
7272
private final MavenConfigHandler mavenConfigHandler;
7373
private final ProjectMetadata projectMetadata;
7474
private final ExecutionContext executionContext;
75-
private final RewriteMavenProjectParser parser;
75+
private final RewriteProjectParser parser;
7676

7777
public List<SourceFile> parse(Path projectDirectory, List<Resource> resources) {
78-
return parser.parse(projectDirectory).sourceFiles();
78+
return parser.parse(projectDirectory, resources, executionContext).sourceFiles();
7979
}
8080

8181

components/sbm-core/src/test/java/org/springframework/sbm/archfitfun/ExecutionScopeArchFitTest.java

+18-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
1919
import lombok.Getter;
2020
import lombok.extern.slf4j.Slf4j;
21-
import org.junit.jupiter.api.Disabled;
2221
import org.junit.jupiter.api.Test;
2322
import org.openrewrite.ExecutionContext;
2423
import org.openrewrite.maven.MavenSettings;
@@ -33,7 +32,10 @@
3332
import org.springframework.sbm.engine.commands.ApplicableRecipeListCommand;
3433
import org.springframework.sbm.engine.commands.ApplyCommand;
3534
import org.springframework.sbm.engine.commands.ScanCommand;
36-
import org.springframework.sbm.engine.context.*;
35+
import org.springframework.sbm.engine.context.ProjectContext;
36+
import org.springframework.sbm.engine.context.ProjectContextFactory;
37+
import org.springframework.sbm.engine.context.ProjectContextSerializer;
38+
import org.springframework.sbm.engine.context.ProjectRootPathResolver;
3739
import org.springframework.sbm.engine.git.GitSupport;
3840
import org.springframework.sbm.engine.git.ProjectSyncVerifier;
3941
import org.springframework.sbm.engine.precondition.PreconditionVerifier;
@@ -100,35 +102,34 @@
100102
* @author Fabian Krüger
101103
*/
102104
@Slf4j
103-
@Disabled()
104105
@SpringBootTest(classes = {
105-
// ScanScope.class,
106-
// ExecutionScope.class,
106+
ScanScope.class,
107+
ExecutionScope.class,
107108
ScanCommand.class,
108109
ProjectRootPathResolver.class,
109-
// PathScanner.class,
110+
PathScanner.class,
110111
SbmApplicationProperties.class,
111112
ResourceHelper.class,
112113
PreconditionVerifier.class,
113114
ProjectContextInitializer.class,
114115
ProjectContextFactory.class,
115116
ProjectResourceWrapperRegistry.class,
116117
ProjectResourceSetHolder.class,
117-
ProjectContextHolder.class,
118118
JavaRefactoringFactoryImpl.class,
119119
BasePackageCalculator.class,
120120
JavaParserBuilder.class,
121-
// RewriteParserConfiguration.class,
122-
// RewriteProjectParser.class,
123-
// ResourceParser.class,
124-
// RewriteJsonParser.class,
125-
// RewriteXmlParser.class,
126-
// RewriteYamlParser.class,
127-
// RewritePropertiesParser.class,
128-
// RewritePlainTextParser.class,
129-
// RewriteMavenParser.class,
121+
RewriteParserConfiguration.class,
122+
RewriteProjectParser.class,
123+
ResourceParser.class,
124+
RewriteJsonParser.class,
125+
RewriteXmlParser.class,
126+
RewriteYamlParser.class,
127+
RewritePropertiesParser.class,
128+
RewritePlainTextParser.class,
129+
RewriteMavenParser.class,
130130
MavenSettingsInitializer.class,
131131
RewriteMigrationResultMerger.class,
132+
RewriteMavenArtifactDownloader.class,
132133
JavaProvenanceMarkerFactory.class,
133134
MavenConfigHandler.class,
134135
RewriteSourceFileWrapper.class,
@@ -145,9 +146,7 @@
145146
ExecutionScopeArchFitTestContext.class,
146147
SbmSupportRewriteConfiguration.class
147148
},
148-
properties = {
149-
"spring.main.allow-bean-definition-overriding=true", // required to provide custom ProjectMetadata
150-
"debug=true"}
149+
properties = "spring.main.allow-bean-definition-overriding=true"
151150
)
152151
public class ExecutionScopeArchFitTest {
153152
public static final String TEST_RECIPE_NAME = "dummy-recipe";

components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ interface SomeClass extends K<String, String> {
110110
""";
111111

112112

113-
assertThrows(MavenExecutionResultException.class, () ->
113+
assertThrows(UnsatisfiedDependencyException.class, () ->
114114
TestProjectContext.buildProjectContext().withJavaSources(sourceCode).build()
115115
).getMessage().contains("src/main/java/a/b/c/SomeClass.java:[2,13] cannot find symbol");
116116

components/sbm-core/src/test/java/org/springframework/sbm/project/buildfile/OpenRewriteMavenBuildFileTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ void addDependencyShouldPublishEvent() {
533533
)
534534
.withJavaSource("src/main/java",
535535
"""
536-
import javax.validation.constraints.Email;
536+
import jakarta.validation.constraints.Email;
537537
public class Cat {
538538
@Email
539539
private String email;

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ limitations under the License.
364364
<!-- @formatter:on -->
365365
</inlineHeader>
366366
<excludes>
367+
<exclude>sbm-support-rewrite/**</exclude>
367368
<exclude>**/demo/**</exclude>
368369
<exclude>**/.sdkmanrc</exclude>
369370
<exclude>**/*.adoc</exclude>

sbm-support-rewrite/pom.xml

+52-29
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@
9393
</dependencyManagement>
9494

9595
<dependencies>
96+
<dependency>
97+
<groupId>org.springframework.boot</groupId>
98+
<artifactId>spring-boot-starter</artifactId>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.springframework.boot</groupId>
102+
<artifactId>spring-boot-configuration-processor</artifactId>
103+
<optional>true</optional>
104+
</dependency>
96105
<dependency>
97106
<groupId>com.squareup.okhttp3</groupId>
98107
<artifactId>okhttp</artifactId>
@@ -137,15 +146,6 @@
137146
<artifactId>rewrite-maven-plugin</artifactId>
138147
<version>${rewrite-maven-plugin.version}</version>
139148
</dependency>
140-
<dependency>
141-
<groupId>org.springframework.boot</groupId>
142-
<artifactId>spring-boot-starter</artifactId>
143-
</dependency>
144-
<dependency>
145-
<groupId>org.springframework.boot</groupId>
146-
<artifactId>spring-boot-configuration-processor</artifactId>
147-
<optional>true</optional>
148-
</dependency>
149149
<dependency>
150150
<groupId>org.projectlombok</groupId>
151151
<artifactId>lombok</artifactId>
@@ -176,16 +176,6 @@
176176
<artifactId>maven-resolver-provider</artifactId>
177177
<version>${maven.version}</version>
178178
</dependency>
179-
<dependency>
180-
<groupId>org.apache.maven</groupId>
181-
<artifactId>maven-core</artifactId>
182-
<version>${maven.version}</version>
183-
</dependency>
184-
<dependency>
185-
<groupId>org.apache.maven</groupId>
186-
<artifactId>maven-artifact</artifactId>
187-
<version>${maven.version}</version>
188-
</dependency>
189179
<dependency>
190180
<groupId>org.apache.maven</groupId>
191181
<artifactId>maven-compat</artifactId>
@@ -207,20 +197,11 @@
207197
<artifactId>plexus-cipher</artifactId>
208198
<version>${plexus-cypher.version}</version>
209199
</dependency>
210-
<dependency>
211-
<groupId>org.apache.maven</groupId>
212-
<artifactId>maven-model</artifactId>
213-
<version>${maven.version}</version>
214-
</dependency>
215-
<dependency>
216-
<groupId>org.apache.maven</groupId>
217-
<artifactId>maven-model-builder</artifactId>
218-
<version>${maven.version}</version>
219-
</dependency>
220200
<dependency>
221201
<groupId>org.apache.maven.shared</groupId>
222202
<artifactId>maven-invoker</artifactId>
223203
<version>${maven-invoker.version}</version>
204+
<scope>test</scope>
224205
</dependency>
225206
<dependency>
226207
<groupId>javax.xml.bind</groupId>
@@ -493,6 +474,48 @@ limitations under the License.
493474
<localCheckout>true</localCheckout>
494475
</configuration>
495476
</plugin>
477+
<plugin>
478+
<groupId>org.codehaus.mojo</groupId>
479+
<artifactId>flatten-maven-plugin</artifactId>
480+
<version>1.4.1</version>
481+
<executions>
482+
<execution>
483+
<id>flatten</id>
484+
<phase>process-resources</phase>
485+
<goals>
486+
<goal>flatten</goal>
487+
</goals>
488+
<configuration>
489+
<updatePomFile>true</updatePomFile>
490+
<flattenMode>oss</flattenMode>
491+
<pomElements>
492+
<distributionManagement>remove</distributionManagement>
493+
<properties>remove</properties>
494+
<repositories>remove</repositories>
495+
<profiles>remove</profiles>
496+
</pomElements>
497+
</configuration>
498+
</execution>
499+
<execution>
500+
<id>flatten-clean</id>
501+
<phase>clean</phase>
502+
<goals>
503+
<goal>clean</goal>
504+
</goals>
505+
</execution>
506+
</executions>
507+
</plugin>
508+
<plugin>
509+
<groupId>org.apache.maven.plugins</groupId>
510+
<artifactId>maven-release-plugin</artifactId>
511+
<version>3.0.0</version>
512+
<configuration>
513+
<releaseProfiles>sonatype</releaseProfiles>
514+
<pushChanges>false</pushChanges>
515+
<tagNameFormat>@{project.version}</tagNameFormat>
516+
<localCheckout>true</localCheckout>
517+
</configuration>
518+
</plugin>
496519
</plugins>
497520
</build>
498521
<profiles>

sbm-support-rewrite/src/main/java/org/springframework/sbm/boot/autoconfigure/SbmSupportRewriteConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
* @author Fabian Krüger
2323
*/
2424
@AutoConfiguration
25-
@Import(DiscoveryConfiguration.class)
25+
@Import({DiscoveryConfiguration.class, ScannerConfiguration.class})
2626
public class SbmSupportRewriteConfiguration {
2727
}

sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/ProjectScanner.java

-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ private boolean isAccepted(Path baseDir, Resource r, List<PathMatcher> pathMatch
9898
.filter(matcher -> {
9999
Path resourcePath = ResourceUtil.getPath(r);
100100
boolean matches = matcher.matches(resourcePath);
101-
if(matches && log.isInfoEnabled()) {
102-
log.info("Resource '%s' matches ignore pattern '%s'".formatted(resourcePath, matcher));
103-
}
104101
return matches;
105102
})
106103
.findFirst();

sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteParserConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.context.annotation.Bean;
3030
import org.springframework.context.annotation.Import;
3131
import org.springframework.sbm.boot.autoconfigure.ParserPropertiesPostProcessor;
32+
import org.springframework.sbm.boot.autoconfigure.ScannerConfiguration;
3233
import org.springframework.sbm.parsers.events.RewriteParsingEventListenerAdapter;
3334
import org.springframework.sbm.scopes.ProjectMetadata;
3435
import org.springframework.sbm.scopes.ScanScope;
@@ -47,7 +48,7 @@
4748
* @author Fabian Krüger
4849
*/
4950
@Slf4j
50-
@AutoConfiguration(after = ScopeConfiguration.class)
51+
@AutoConfiguration(after = {ScopeConfiguration.class})
5152
@EnableConfigurationProperties(ParserProperties.class)
5253
@Import({ScanScope.class, ScopeConfiguration.class})
5354
public class RewriteParserConfiguration {

0 commit comments

Comments
 (0)