Skip to content

Commit a177487

Browse files
authored
Merge branch 'main' into webapp-demo
2 parents 5eff674 + fb52fb1 commit a177487

File tree

4 files changed

+85
-83
lines changed

4 files changed

+85
-83
lines changed

applications/spring-shell/src/test/java/org/springframework/sbm/recipes/MigrateJaxRsAnnotationsRecipeIntegrationTest.java

Lines changed: 82 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -33,89 +33,90 @@ protected String getTestSubDir() {
3333
}
3434

3535
private final String expectedJavaSource =
36-
"package com.example.jee.app;\n" +
37-
"\n" +
38-
"import org.springframework.http.MediaType;\n" +
39-
"import org.springframework.web.bind.annotation.PathVariable;\n" +
40-
"import org.springframework.web.bind.annotation.RequestMapping;\n" +
41-
"import org.springframework.web.bind.annotation.RequestMethod;\n" +
42-
"import org.springframework.web.bind.annotation.RestController;\n" +
43-
"\n" +
44-
"@RestController\n" +
45-
"@RequestMapping(value = \"/\")\n" +
46-
"public class PersonController {\n" +
47-
"\n" +
48-
" @RequestMapping(value = \"/json/{name}\", produces = \"application/json\", consumes = \"application/json\", method = RequestMethod.POST)\n" +
49-
" public String getHelloWorldJSON(@PathVariable(\"name\") String name) throws Exception {\n" +
50-
" System.out.println(\"name: \" + name);\n" +
51-
" return \"{\\\"Hello\\\":\\\"\" + name + \"\\\"\";\n" +
52-
" }\n" +
53-
"\n" +
54-
" @RequestMapping(value = \"/json\", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)\n" +
55-
" public String getAllPersons() throws Exception {\n" +
56-
" return \"{\\\"message\\\":\\\"No person here...\\\"\";\n" +
57-
" }\n" +
58-
"\n" +
59-
"\n" +
60-
" @RequestMapping(value = \"/xml/{name}\", produces = MediaType.APPLICATION_XML_VALUE, consumes = MediaType.APPLICATION_XML_VALUE, method = RequestMethod.POST)\n" +
61-
" public String getHelloWorldXML(@PathVariable(\"name\") String name) throws Exception {\n" +
62-
" System.out.println(\"name: \" + name);\n" +
63-
" return \"<xml>Hello \"+name+\"</xml>\";\n" +
64-
" }\n" +
65-
"\n" +
66-
"}\n";
36+
"""
37+
package com.example.jee.app;
38+
39+
import org.springframework.http.MediaType;
40+
import org.springframework.web.bind.annotation.*;
41+
42+
@RestController
43+
@RequestMapping(value = "/")
44+
public class PersonController {
45+
46+
@RequestMapping(value = "/json/{name}", produces = "application/json", consumes = "application/json", method = RequestMethod.POST)
47+
public String getHelloWorldJSON(@PathVariable("name") String name) throws Exception {
48+
System.out.println("name: " + name);
49+
return "{\\"Hello\\":\\"" + name + "\\"";
50+
}
51+
52+
@RequestMapping(value = "/json", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
53+
public String getAllPersons(@RequestParam(required = false, value = "q") String searchBy) throws Exception {
54+
return "{\\"message\\":\\"No person here...\\"";
55+
}
56+
57+
58+
@RequestMapping(value = "/xml/{name}", produces = MediaType.APPLICATION_XML_VALUE, consumes = MediaType.APPLICATION_XML_VALUE, method = RequestMethod.POST)
59+
public String getHelloWorldXML(@PathVariable("name") String name) throws Exception {
60+
System.out.println("name: " + name);
61+
return "<xml>Hello "+name+"</xml>";
62+
}
63+
64+
}
65+
""";
6766

6867
private final String expectedPomSource =
69-
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
70-
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
71-
" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n" +
72-
" <modelVersion>4.0.0</modelVersion>\n" +
73-
" <groupId>org.springframework.sbm.examples</groupId>\n" +
74-
" <artifactId>migrate-jax-rs</artifactId>\n" +
75-
" <packaging>jar</packaging>\n" +
76-
" <version>0.0.1-SNAPSHOT</version>\n" +
77-
" <properties>\n" +
78-
" <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n" +
79-
" </properties>\n" +
80-
" <build>\n" +
81-
" <plugins>\n" +
82-
" <plugin>\n" +
83-
" <groupId>org.apache.maven.plugins</groupId>\n" +
84-
" <artifactId>maven-compiler-plugin</artifactId>\n" +
85-
" <version>3.5.1</version>\n" +
86-
" <configuration>\n" +
87-
" <source>1.8</source>\n" +
88-
" <target>1.8</target>\n" +
89-
" </configuration>\n" +
90-
" </plugin>\n" +
91-
" </plugins>\n" +
92-
" </build>\n" +
93-
" <dependencies>\n" +
94-
" <dependency>\n" +
95-
" <groupId>org.springframework.boot</groupId>\n" +
96-
" <artifactId>spring-boot-starter-web</artifactId>\n" +
97-
" <version>2.3.4.RELEASE</version>\n" +
98-
" </dependency>\n" +
99-
" <dependency>\n" +
100-
" <groupId>org.jboss.spec.javax.ws.rs</groupId>\n" +
101-
" <artifactId>jboss-jaxrs-api_2.1_spec</artifactId>\n" +
102-
" <version>1.0.1.Final</version>\n" +
103-
" <scope>runtime</scope>\n" +
104-
" </dependency>\n" +
105-
" </dependencies>\n" +
106-
" <repositories>\n" +
107-
" <repository>\n" +
108-
" <id>jcenter</id>\n" +
109-
" <name>jcenter</name>\n" +
110-
" <url>https://jcenter.bintray.com</url>\n" +
111-
" </repository>\n" +
112-
" <repository>\n" +
113-
" <id>mavencentral</id>\n" +
114-
" <name>mavencentral</name>\n" +
115-
" <url>https://repo.maven.apache.org/maven2</url>\n" +
116-
" </repository>\n" +
117-
" </repositories>\n" +
118-
"</project>\n";
68+
"""
69+
<?xml version="1.0" encoding="UTF-8"?>
70+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
71+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
72+
<modelVersion>4.0.0</modelVersion>
73+
<groupId>org.springframework.sbm.examples</groupId>
74+
<artifactId>migrate-jax-rs</artifactId>
75+
<packaging>jar</packaging>
76+
<version>0.0.1-SNAPSHOT</version>
77+
<properties>
78+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
79+
</properties>
80+
<build>
81+
<plugins>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-compiler-plugin</artifactId>
85+
<version>3.5.1</version>
86+
<configuration>
87+
<source>1.8</source>
88+
<target>1.8</target>
89+
</configuration>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
<dependencies>
94+
<dependency>
95+
<groupId>org.springframework.boot</groupId>
96+
<artifactId>spring-boot-starter-web</artifactId>
97+
<version>2.3.4.RELEASE</version>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.jboss.spec.javax.ws.rs</groupId>
101+
<artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
102+
<version>1.0.1.Final</version>
103+
<scope>runtime</scope>
104+
</dependency>
105+
</dependencies>
106+
<repositories>
107+
<repository>
108+
<id>jcenter</id>
109+
<name>jcenter</name>
110+
<url>https://jcenter.bintray.com</url>
111+
</repository>
112+
<repository>
113+
<id>mavencentral</id>
114+
<name>mavencentral</name>
115+
<url>https://repo.maven.apache.org/maven2</url>
116+
</repository>
117+
</repositories>
118+
</project>
119+
""";
119120

120121

121122
@Test

applications/spring-shell/src/test/resources/testcode/bootify-jaxrs/src/main/java/com/example/jee/app/PersonController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public String getHelloWorldJSON(@PathParam("name") String name) throws Exception
2020
@Path("/json")
2121
@Produces(MediaType.APPLICATION_JSON)
2222
@Consumes(MediaType.APPLICATION_JSON)
23-
public String getAllPersons() throws Exception {
23+
public String getAllPersons(@QueryParam("q") String searchBy) throws Exception {
2424
return "{\"message\":\"No person here...\"";
2525
}
2626

components/sbm-core/src/main/java/org/springframework/sbm/engine/git/GitSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public void commitWhenGitAvailable(ProjectContext context, String appliedRecipeN
252252
.map(r -> context.getProjectRootDirectory().relativize(Path.of(r)).toString())
253253
.collect(Collectors.toList());
254254

255-
if (sbmApplicationProperties.isGitSupportEnabled()) {
255+
if (sbmApplicationProperties.isGitSupportEnabled() && !(modifiedResources.isEmpty() || deletedResources.isEmpty())) {
256256
File repoDir = context.getProjectRootDirectory().toFile();
257257
if (repoExists(repoDir)) {
258258
String commitMessage = "SBM: applied recipe '" + appliedRecipeName + "'";

components/sbm-recipes-jee-to-boot/src/main/java/org/springframework/sbm/jee/jaxrs/MigrateJaxRsRecipe.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public Recipe jaxRs(RewriteRecipeLoader rewriteRecipeLoader, RewriteRecipeRunner
139139
name: org.springframework.sbm.jee.MakeRequestParamsOptional
140140
displayName: Set required=false for @RequestParam without 'required'
141141
description: Set required=false for @RequestParam without 'required'
142+
causesAnotherCycle: true
142143
recipeList:
143144
- org.openrewrite.java.AddOrUpdateAnnotationAttribute:
144145
annotationType: "org.springframework.web.bind.annotation.RequestParam"

0 commit comments

Comments
 (0)