mirror of
https://gitee.com/dcren/initializr.git
synced 2025-11-08 10:24:58 +08:00
Update project layout for Groovy-based projects
A groovy-based project on Maven provides a better developer experience if the sources are located in src/main/java and src/test/java. This commit updates the generator to use this new location while keeping the existing src/main/groovy project for Gradle builds. Fixes gh-71
This commit is contained in:
@@ -7,6 +7,7 @@ order.
|
|||||||
|
|
||||||
=== Release 1.0.0 (In progress)
|
=== Release 1.0.0 (In progress)
|
||||||
|
|
||||||
|
* https://github.com/spring-io/initializr/issues/71[#71]: update project layout for Groovy-based projects.
|
||||||
* https://github.com/spring-io/initializr/issues/69[#69]: improve the structure of templated urls.
|
* https://github.com/spring-io/initializr/issues/69[#69]: improve the structure of templated urls.
|
||||||
* https://github.com/spring-io/initializr/issues/70[#70]: explicit support for HTTPie (similar to curl).
|
* https://github.com/spring-io/initializr/issues/70[#70]: explicit support for HTTPie (similar to curl).
|
||||||
* https://github.com/spring-io/initializr/issues/67[#67]: explicit support for curl by returning a text
|
* https://github.com/spring-io/initializr/issues/67[#67]: explicit support for curl by returning a text
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ class ProjectGenerator {
|
|||||||
|
|
||||||
def dir = initializerProjectDir(rootDir, request)
|
def dir = initializerProjectDir(rootDir, request)
|
||||||
|
|
||||||
if ('gradle'.equals(request.build)) {
|
boolean gradleBuild = 'gradle'.equals(request.build)
|
||||||
|
if (gradleBuild) {
|
||||||
def gradle = new String(doGenerateGradleBuild(model))
|
def gradle = new String(doGenerateGradleBuild(model))
|
||||||
new File(dir, 'build.gradle').write(gradle)
|
new File(dir, 'build.gradle').write(gradle)
|
||||||
} else {
|
} else {
|
||||||
@@ -92,7 +93,8 @@ class ProjectGenerator {
|
|||||||
def applicationName = request.applicationName
|
def applicationName = request.applicationName
|
||||||
def language = request.language
|
def language = request.language
|
||||||
|
|
||||||
def src = new File(new File(dir, "src/main/$language"), request.packageName.replace('.', '/'))
|
String codeLocation = ((language.equals("groovy") && gradleBuild) ? 'groovy': 'java')
|
||||||
|
def src = new File(new File(dir, "src/main/$codeLocation"), request.packageName.replace('.', '/'))
|
||||||
src.mkdirs()
|
src.mkdirs()
|
||||||
write(new File(src, "${applicationName}.${language}"), "Application.$language", model)
|
write(new File(src, "${applicationName}.${language}"), "Application.$language", model)
|
||||||
|
|
||||||
@@ -101,7 +103,7 @@ class ProjectGenerator {
|
|||||||
write(new File(src, fileName), fileName, model)
|
write(new File(src, fileName), fileName, model)
|
||||||
}
|
}
|
||||||
|
|
||||||
def test = new File(new File(dir, "src/test/$language"), request.packageName.replace('.', '/'))
|
def test = new File(new File(dir, "src/test/$codeLocation"), request.packageName.replace('.', '/'))
|
||||||
test.mkdirs()
|
test.mkdirs()
|
||||||
if (request.hasWebFacet()) {
|
if (request.hasWebFacet()) {
|
||||||
model.testAnnotations = '@WebAppConfiguration\n'
|
model.testAnnotations = '@WebAppConfiguration\n'
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ class ProjectGeneratorTests {
|
|||||||
request.bootVersion = '1.1.9.RELEASE'
|
request.bootVersion = '1.1.9.RELEASE'
|
||||||
request.name = 'MyDemo'
|
request.name = 'MyDemo'
|
||||||
request.packageName = 'foo'
|
request.packageName = 'foo'
|
||||||
generateProject(request).sourceCodeAssert('src/main/groovy/foo/MyDemoApplication.groovy')
|
generateProject(request).sourceCodeAssert('src/main/java/foo/MyDemoApplication.groovy')
|
||||||
.hasImports(EnableAutoConfiguration.class.name, ComponentScan.class.name, Configuration.class.name)
|
.hasImports(EnableAutoConfiguration.class.name, ComponentScan.class.name, Configuration.class.name)
|
||||||
.doesNotHaveImports(SpringBootApplication.class.name)
|
.doesNotHaveImports(SpringBootApplication.class.name)
|
||||||
.contains('@EnableAutoConfiguration', '@Configuration', '@ComponentScan')
|
.contains('@EnableAutoConfiguration', '@Configuration', '@ComponentScan')
|
||||||
@@ -198,7 +198,7 @@ class ProjectGeneratorTests {
|
|||||||
request.bootVersion = '1.2.0.RC1'
|
request.bootVersion = '1.2.0.RC1'
|
||||||
request.name = 'MyDemo'
|
request.name = 'MyDemo'
|
||||||
request.packageName = 'foo'
|
request.packageName = 'foo'
|
||||||
generateProject(request).sourceCodeAssert('src/main/groovy/foo/MyDemoApplication.groovy')
|
generateProject(request).sourceCodeAssert('src/main/java/foo/MyDemoApplication.groovy')
|
||||||
.hasImports(SpringBootApplication.class.name)
|
.hasImports(SpringBootApplication.class.name)
|
||||||
.doesNotHaveImports(EnableAutoConfiguration.class.name, ComponentScan.class.name, Configuration.class.name)
|
.doesNotHaveImports(EnableAutoConfiguration.class.name, ComponentScan.class.name, Configuration.class.name)
|
||||||
.contains('@SpringBootApplication')
|
.contains('@SpringBootApplication')
|
||||||
@@ -214,6 +214,22 @@ class ProjectGeneratorTests {
|
|||||||
.isMavenProject()
|
.isMavenProject()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void groovyWithMavenUsesJavaDir() {
|
||||||
|
def request = createProjectRequest('web')
|
||||||
|
request.type = 'maven-project'
|
||||||
|
request.language = 'groovy'
|
||||||
|
generateProject(request).isMavenProject().isGroovyProject()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void groovyWithGradleUsesGroovyDir() {
|
||||||
|
def request = createProjectRequest('web')
|
||||||
|
request.type = 'gradle-project'
|
||||||
|
request.language = 'groovy'
|
||||||
|
generateProject(request).isGradleProject().isGroovyProject()
|
||||||
|
}
|
||||||
|
|
||||||
PomAssert generateMavenPom(ProjectRequest request) {
|
PomAssert generateMavenPom(ProjectRequest request) {
|
||||||
def content = new String(projectGenerator.generateMavenPom(request))
|
def content = new String(projectGenerator.generateMavenPom(request))
|
||||||
new PomAssert(content).validateProjectRequest(request)
|
new PomAssert(content).validateProjectRequest(request)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class ProjectAssert {
|
|||||||
private static final DEFAULT_APPLICATION_NAME = generateDefaultApplicationName()
|
private static final DEFAULT_APPLICATION_NAME = generateDefaultApplicationName()
|
||||||
|
|
||||||
final File dir
|
final File dir
|
||||||
|
Boolean mavenProject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance with the directory holding the generated project.
|
* Create a new instance with the directory holding the generated project.
|
||||||
@@ -80,10 +81,14 @@ class ProjectAssert {
|
|||||||
|
|
||||||
ProjectAssert isMavenProject() {
|
ProjectAssert isMavenProject() {
|
||||||
hasFile('pom.xml').hasNoFile('build.gradle')
|
hasFile('pom.xml').hasNoFile('build.gradle')
|
||||||
|
mavenProject = true
|
||||||
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectAssert isGradleProject() {
|
ProjectAssert isGradleProject() {
|
||||||
hasFile('build.gradle').hasNoFile('pom.xml')
|
hasFile('build.gradle').hasNoFile('pom.xml')
|
||||||
|
mavenProject = false
|
||||||
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectAssert isJavaProject(String expectedApplicationName) {
|
ProjectAssert isJavaProject(String expectedApplicationName) {
|
||||||
@@ -97,8 +102,9 @@ class ProjectAssert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProjectAssert isGroovyProject(String expectedApplicationName) {
|
ProjectAssert isGroovyProject(String expectedApplicationName) {
|
||||||
hasFile("src/main/groovy/demo/${expectedApplicationName}.groovy",
|
String codeLocation = (mavenProject ? 'java' : 'groovy')
|
||||||
"src/test/groovy/demo/${expectedApplicationName}Tests.groovy",
|
hasFile("src/main/$codeLocation/demo/${expectedApplicationName}.groovy",
|
||||||
|
"src/test/$codeLocation/demo/${expectedApplicationName}Tests.groovy",
|
||||||
'src/main/resources/application.properties')
|
'src/main/resources/application.properties')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user