mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-19 10:08:22 +08:00
Add .groovy lang support
This commit is contained in:
29
app.groovy
29
app.groovy
@@ -22,7 +22,13 @@ class MainController {
|
||||
@Autowired
|
||||
private Projects projects
|
||||
|
||||
@RequestMapping('/')
|
||||
@RequestMapping(value='/')
|
||||
@ResponseBody
|
||||
Projects projects() {
|
||||
projects
|
||||
}
|
||||
|
||||
@RequestMapping(value='/', produces='text/html')
|
||||
@ResponseBody
|
||||
String home() {
|
||||
def model = [:]
|
||||
@@ -31,6 +37,7 @@ class MainController {
|
||||
model['types'] = projects.types.sort { it.name }
|
||||
model['packagings'] = projects.packagings.sort { it.name }
|
||||
model['javaVersions'] = projects.javaVersions
|
||||
model['languages'] = projects.languages
|
||||
template 'home.html', model
|
||||
}
|
||||
|
||||
@@ -112,15 +119,17 @@ class MainController {
|
||||
new File(dir, 'pom.xml').write(pom)
|
||||
}
|
||||
|
||||
File src = new File(new File(dir, 'src/main/java'),request.packageName.replace('.', '/'))
|
||||
String language = request.language
|
||||
|
||||
File src = new File(new File(dir, 'src/main/' + language),request.packageName.replace('.', '/'))
|
||||
src.mkdirs()
|
||||
write(src, 'Application.java', model)
|
||||
write(src, 'Application.' + language, model)
|
||||
|
||||
if (request.packaging=='war') {
|
||||
write(src, 'ServletInitializer.java', model)
|
||||
write(src, 'ServletInitializer.' + language, model)
|
||||
}
|
||||
|
||||
File test = new File(new File(dir, 'src/test/java'),request.packageName.replace('.', '/'))
|
||||
File test = new File(new File(dir, 'src/test/' + language),request.packageName.replace('.', '/'))
|
||||
test.mkdirs()
|
||||
if (model.styles.contains('-web')) {
|
||||
model.testAnnotations = '@WebAppConfiguration\n'
|
||||
@@ -129,7 +138,7 @@ class MainController {
|
||||
model.testAnnotations = ''
|
||||
model.testImports = ''
|
||||
}
|
||||
write(test, 'ApplicationTests.java', model)
|
||||
write(test, 'ApplicationTests.' + language, model)
|
||||
|
||||
File resources = new File(dir, 'src/main/resources')
|
||||
resources.mkdirs()
|
||||
@@ -180,6 +189,7 @@ class MainController {
|
||||
model.packageName = request.packageName
|
||||
model.packaging = request.packaging
|
||||
model.javaVersion = request.javaVersion
|
||||
model.language = request.language
|
||||
|
||||
if (style==null || style.size()==0) {
|
||||
style = ['']
|
||||
@@ -237,6 +247,7 @@ class PomRequest {
|
||||
String artifactId
|
||||
String version = '0.0.1-SNAPSHOT'
|
||||
String packaging = 'jar'
|
||||
String language = 'java'
|
||||
String packageName
|
||||
String javaVersion = '1.7'
|
||||
String getArtifactId() {
|
||||
@@ -254,6 +265,12 @@ class Projects {
|
||||
List<Type> types
|
||||
List<Packaging> packagings
|
||||
List<JavaVersion> javaVersions
|
||||
List<Language> languages
|
||||
static class Language {
|
||||
String name
|
||||
String value
|
||||
boolean selected
|
||||
}
|
||||
static class JavaVersion {
|
||||
String value
|
||||
boolean selected
|
||||
|
@@ -87,3 +87,10 @@ projects:
|
||||
selected: true
|
||||
- value: 1.8
|
||||
selected: false
|
||||
languages:
|
||||
- name: Groovy
|
||||
value: groovy
|
||||
selected: false
|
||||
- name: Java
|
||||
value: java
|
||||
selected: true
|
||||
|
16
templates/Application.groovy
Normal file
16
templates/Application.groovy
Normal file
@@ -0,0 +1,16 @@
|
||||
package ${packageName}
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@EnableAutoConfiguration
|
||||
class Application {
|
||||
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run Application, args
|
||||
}
|
||||
}
|
16
templates/ApplicationTests.groovy
Normal file
16
templates/ApplicationTests.groovy
Normal file
@@ -0,0 +1,16 @@
|
||||
package ${packageName}
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
${testImports}import org.springframework.boot.test.SpringApplicationConfiguration
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner)
|
||||
@SpringApplicationConfiguration(classes = Application)
|
||||
${testAnnotations}class ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
13
templates/ServletInitializer.groovy
Normal file
13
templates/ServletInitializer.groovy
Normal file
@@ -0,0 +1,13 @@
|
||||
package ${packageName}
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder
|
||||
import org.springframework.boot.context.web.SpringBootServletInitializer
|
||||
|
||||
class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
application.sources(Application)
|
||||
}
|
||||
|
||||
}
|
@@ -64,6 +64,12 @@
|
||||
<input type="radio" name="javaVersion" value="${it.value}"${it.selected==true ? ' checked="true"' : ''}/>
|
||||
${it.value}
|
||||
</label><% } %>
|
||||
<label>Language:</label>
|
||||
<% languages.each { %>
|
||||
<label class="radio">
|
||||
<input type="radio" name="language" value="${it.value}"${it.selected==true ? ' checked="true"' : ''}/>
|
||||
${it.name}
|
||||
</label><% } %>
|
||||
<button type="submit" class="btn">Generate</button>
|
||||
</form>
|
||||
</div>
|
||||
|
@@ -13,7 +13,7 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: '${language}'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'spring-boot' <% if (packaging=='war') { %>
|
||||
@@ -35,8 +35,9 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {<% styles.each { %>
|
||||
compile("org.springframework.boot:spring-boot-starter${it}:\${springBootVersion}")<% } %>
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test:\${springBootVersion}")
|
||||
compile("org.springframework.boot:spring-boot-starter${it}")<% } %>
|
||||
<% if (language=='groovy') { %>compile("org.codehaus.groovy:groovy")<% } %>
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
|
@@ -22,6 +22,10 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter${it}</artifactId>
|
||||
</dependency><% } %><% if (language=='groovy') { %>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
</dependency><% } %>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -41,7 +45,31 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugin><% if (language=='groovy') { %>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<compilerId>groovy-eclipse-compiler</compilerId>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>2.8.0-01</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-batch</artifactId>
|
||||
<version>2.1.8-01</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>2.8.0-01</version>
|
||||
<extensions>true</extensions>
|
||||
</plugin><% } %>
|
||||
</plugins>
|
||||
</build><% if (!bootVersion.contains("RELEASE")) { %>
|
||||
|
||||
|
@@ -8,13 +8,25 @@ class IntegrationTests {
|
||||
|
||||
@Value('${local.server.port}')
|
||||
int port
|
||||
|
||||
private String home() {
|
||||
HttpHeaders headers = new HttpHeaders()
|
||||
headers.setAccept([MediaType.TEXT_HTML])
|
||||
new TestRestTemplate().exchange('http://localhost:' + port, HttpMethod.GET, new HttpEntity<Void>(headers), String).body
|
||||
}
|
||||
|
||||
@Test
|
||||
void homeIsForm() {
|
||||
String body = new TestRestTemplate().getForObject('http://localhost:' + port, String)
|
||||
String body = home()
|
||||
assertTrue('Wrong body:\n' + body, body.contains('action="/starter.zip"'))
|
||||
}
|
||||
|
||||
@Test
|
||||
void homeIsJson() {
|
||||
String body = new TestRestTemplate().getForObject('http://localhost:' + port, String)
|
||||
assertTrue('Wrong body:\n' + body, body.contains('{"styles"'))
|
||||
}
|
||||
|
||||
@Test
|
||||
void webIsAdded() {
|
||||
String body = new TestRestTemplate().getForObject('http://localhost:' + port + '/pom.xml?packaging=war', String)
|
||||
@@ -29,7 +41,7 @@ class IntegrationTests {
|
||||
|
||||
@Test
|
||||
void homeHasWebStyle() {
|
||||
String body = new TestRestTemplate().getForObject('http://localhost:' + port, String)
|
||||
String body = home()
|
||||
assertTrue('Wrong body:\n' + body, body.contains('name="style" value="web"'))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user