mirror of
https://gitee.com/dcren/initializr.git
synced 2025-04-05 17:38:06 +08:00
Add support for pom.xml generation as well as test in starter project
This commit is contained in:
parent
786219a548
commit
a71d4182d8
26
app.groovy
26
app.groovy
@ -1,6 +1,6 @@
|
||||
package app
|
||||
|
||||
@Grab("org.springframework.boot:spring-boot-starter-actuator:0.5.0.BUILD-SNAPSHOT")
|
||||
@Grab("spring-boot-starter-actuator")
|
||||
@Grab("org.codehaus.groovy:groovy-ant:2.1.6")
|
||||
|
||||
@Controller
|
||||
@ -25,7 +25,7 @@ class MainController {
|
||||
model["styles"] << [name:"Security", value:"security"]
|
||||
model["styles"] << [name:"Batch", value:"batch"]
|
||||
model["styles"] << [name:"JPA", value:"data-jpa"]
|
||||
model["types"] = [[name:"Maven POM", value:"pom", selected: false], [name:"Maven Project", value:"pomproject", selected: true]]
|
||||
model["types"] = [[name:"Maven POM", value:"pom.xml", selected: false], [name:"Maven Project", value:"starter.zip", selected: true]]
|
||||
template "home.html", model
|
||||
}
|
||||
|
||||
@ -60,11 +60,12 @@ class MainController {
|
||||
|
||||
File src = new File(new File(dir, "src/main/java"),request.packageName.replace(".", "/"))
|
||||
src.mkdirs()
|
||||
|
||||
def body = template "Application.java", model
|
||||
log.info("Creating: " + src + "/Application.java")
|
||||
new File(src, "Application.java").write(body)
|
||||
write(src, "Application.java", model)
|
||||
|
||||
File test = new File(new File(dir, "src/test/java"),request.packageName.replace(".", "/"))
|
||||
test.mkdirs()
|
||||
write(test, "ApplicationTests.java", model)
|
||||
|
||||
File download = new File(tmpdir, dir.name + ".zip")
|
||||
log.info("Creating: " + download)
|
||||
tempFiles << download
|
||||
@ -80,6 +81,12 @@ class MainController {
|
||||
result
|
||||
}
|
||||
|
||||
def write(File src, String name, def model) {
|
||||
def body = template name, model
|
||||
log.info("Creating: " + src + "/" + name)
|
||||
new File(src, name).write(body)
|
||||
}
|
||||
|
||||
@RequestMapping("/pom")
|
||||
@ResponseBody
|
||||
ResponseEntity<byte[]> pom(PomRequest request, Map model) {
|
||||
@ -87,6 +94,9 @@ class MainController {
|
||||
def style = request.style
|
||||
log.info("Styles requested: " + style)
|
||||
|
||||
def type = request.type
|
||||
log.info("Type requested: " + type)
|
||||
|
||||
model.groupId = request.groupId
|
||||
model.artifactId = request.artifactId
|
||||
model.version = request.version
|
||||
@ -100,6 +110,7 @@ class MainController {
|
||||
if (!style.class.isArray() && !(style instanceof Collection)) {
|
||||
style = [style]
|
||||
}
|
||||
style = style.collect{ it=="jpa" ? "data-jpa" : it }
|
||||
model["styles"] = style.collect{ it=="" ? "" : "-" + it }
|
||||
|
||||
log.info("Model: " + model)
|
||||
@ -163,10 +174,11 @@ class PomRequest {
|
||||
def style = []
|
||||
|
||||
String name = "demo"
|
||||
String type = "starter"
|
||||
String description = "Demo project for Spring Boot"
|
||||
String groupId = "org.test"
|
||||
String artifactId
|
||||
String version = "0.0.1.SNAPSHOT"
|
||||
String version = "0.0.1-SNAPSHOT"
|
||||
String packageName
|
||||
String getArtifactId() {
|
||||
artifactId == null ? name : artifactId
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml"/>
|
||||
|
||||
<logger name="org.springframework" level="DEBUG"/>
|
||||
<!--logger name="org.springframework" level="DEBUG"/-->
|
||||
<logger name="org.springframework.core.env" level="WARN"/>
|
||||
<logger name="org.springframework.jndi" level="WARN"/>
|
||||
|
||||
|
17
templates/ApplicationTests.java
Normal file
17
templates/ApplicationTests.java
Normal file
@ -0,0 +1,17 @@
|
||||
package ${packageName};
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.SpringApplicationContextLoader;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = Application.class, loader=SpringApplicationContextLoader.class)
|
||||
public class ApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -34,7 +34,7 @@
|
||||
</div>
|
||||
<h1>Spring Initializr</h1>
|
||||
<div>
|
||||
<form action="/starter.zip" method="get">
|
||||
<form id="form" action="/starter.zip" method="get">
|
||||
<label for="groupId">Group:</label> <input id="groupId" type="text" value="org.demo" name="groupId"/>
|
||||
<label for="artifactId">Artifact:</label> <input id="artifactId" type="text" value="demo" name="artifactId"/>
|
||||
<label for="name">Name:</label> <input id="name" type="text" value="demo" name="name"/>
|
||||
@ -49,7 +49,7 @@
|
||||
<label>Type:</label>
|
||||
<% types.each { %>
|
||||
<label class="radio">
|
||||
<input type="radio" name="type" value="${it.value}"${it.selected ? ' checked="true"' : ''}/>
|
||||
<input type="radio" name="type" value="${it.value}"${it.selected ? ' checked="true"' : ''} onclick="javascript:this.form.action='/${it.value}'"/>
|
||||
${it.name}
|
||||
</label><% } %>
|
||||
<button type="submit" class="btn">Generate</button>
|
||||
|
@ -21,6 +21,11 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter${it}</artifactId>
|
||||
</dependency><% } %>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
Loading…
Reference in New Issue
Block a user