mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-17 01:46:19 +08:00
Polish .gitignore generation
See gh-131
This commit is contained in:
parent
7bd1253c5d
commit
2be67fdba7
@ -220,8 +220,6 @@ class ProjectGenerator {
|
|||||||
*/
|
*/
|
||||||
protected void generateGitIgnore(File dir, ProjectRequest request) {
|
protected void generateGitIgnore(File dir, ProjectRequest request) {
|
||||||
def model = [:]
|
def model = [:]
|
||||||
def agent = extractAgent(request)
|
|
||||||
model['agent'] = agent ? agent.id.id : null
|
|
||||||
model['build'] = isGradleBuild(request) ? 'gradle' : 'maven'
|
model['build'] = isGradleBuild(request) ? 'gradle' : 'maven'
|
||||||
write(new File(dir, '.gitignore'), 'gitignore.tmpl', model)
|
write(new File(dir, '.gitignore'), 'gitignore.tmpl', model)
|
||||||
}
|
}
|
||||||
@ -321,16 +319,6 @@ class ProjectGenerator {
|
|||||||
"import $type$end"
|
"import $type$end"
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Agent extractAgent(ProjectRequest request) {
|
|
||||||
if (request.parameters['user-agent']) {
|
|
||||||
Agent agent = Agent.fromUserAgent(request.parameters['user-agent'])
|
|
||||||
if (agent) {
|
|
||||||
return agent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
private static isGradleBuild(ProjectRequest request) {
|
private static isGradleBuild(ProjectRequest request) {
|
||||||
return 'gradle'.equals(request.build)
|
return 'gradle'.equals(request.build)
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
<% if (build=='maven') { %>target/
|
<% if (build=='maven') { %>target/
|
||||||
!.mvn/wrapper/maven-wrapper.jar<% } else { %>.gradle
|
!.mvn/wrapper/maven-wrapper.jar<% } else { %>.gradle
|
||||||
/build/
|
/build/
|
||||||
!gradle/wrapper/gradle-wrapper.jar<% } %><% if ('sts'==agent) { %>
|
!gradle/wrapper/gradle-wrapper.jar<% } %>
|
||||||
|
|
||||||
### STS ###
|
### STS ###
|
||||||
.classpath
|
.classpath
|
||||||
|
.factorypath
|
||||||
.project
|
.project
|
||||||
.settings<% } %><% if ('intellijidea'==agent) { %>
|
.settings
|
||||||
|
.springBeans
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
.idea
|
.idea
|
||||||
*.iws
|
*.iws
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr<% } %><% if ('netbeans'==agent) { %>
|
*.ipr
|
||||||
|
|
||||||
### NetBeans ###
|
### NetBeans ###
|
||||||
nbproject/private/
|
nbproject/private/
|
||||||
@ -20,4 +22,4 @@ build/
|
|||||||
nbbuild/
|
nbbuild/
|
||||||
dist/
|
dist/
|
||||||
nbdist/
|
nbdist/
|
||||||
.nb-gradle/<% } %>
|
.nb-gradle/
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2016 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.spring.initializr.generator
|
|
||||||
|
|
||||||
import io.spring.initializr.util.Agent
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.junit.runners.Parameterized
|
|
||||||
|
|
||||||
import org.springframework.core.io.ClassPathResource
|
|
||||||
import org.springframework.core.io.Resource
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Project generator tests for {@code .gitignore}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
class ProjectGeneratorGitIgnoreTests extends AbstractProjectGeneratorTests {
|
|
||||||
|
|
||||||
@Parameterized.Parameters(name = "{0}")
|
|
||||||
static Object[] parameters() {
|
|
||||||
def list = []
|
|
||||||
list << 'STS 3.7.2'
|
|
||||||
list << 'IntelliJ IDEA'
|
|
||||||
list << 'nb-springboot-plugin/0.1'
|
|
||||||
list << 'HTTPie/0.8.0'
|
|
||||||
list << 'Googlebot-Mobile'
|
|
||||||
list
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String userAgent
|
|
||||||
private final Agent agent
|
|
||||||
|
|
||||||
ProjectGeneratorGitIgnoreTests(String userAgent) {
|
|
||||||
this.userAgent = userAgent
|
|
||||||
this.agent = Agent.fromUserAgent(userAgent)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void gitIgnoreMaven() {
|
|
||||||
def request = createProjectRequest()
|
|
||||||
request.type = 'maven-project'
|
|
||||||
def project = generateProject(request)
|
|
||||||
project.sourceCodeAssert(".gitignore")
|
|
||||||
.equalsTo(getResourceFor('maven'))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void gitIgnoreGradle() {
|
|
||||||
def request = createProjectRequest()
|
|
||||||
request.type = 'gradle-project'
|
|
||||||
def project = generateProject(request)
|
|
||||||
project.sourceCodeAssert(".gitignore")
|
|
||||||
.equalsTo(getResourceFor('gradle'))
|
|
||||||
}
|
|
||||||
|
|
||||||
private Resource getResourceFor(String build) {
|
|
||||||
String id = agent ? agent.id.id : 'none'
|
|
||||||
return new ClassPathResource("project/$build/gitignore-${id}.gen")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
ProjectRequest createProjectRequest(String... styles) {
|
|
||||||
def request = super.createProjectRequest(styles)
|
|
||||||
request.parameters['user-agent'] = this.userAgent
|
|
||||||
request
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
import org.springframework.context.annotation.ComponentScan
|
import org.springframework.context.annotation.ComponentScan
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.core.io.ClassPathResource
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.containsString
|
import static org.hamcrest.CoreMatchers.containsString
|
||||||
import static org.junit.Assert.assertThat
|
import static org.junit.Assert.assertThat
|
||||||
@ -671,6 +672,24 @@ class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
|||||||
new Dependency(id: 'foo', groupId: 'org.acme', artifactId: 'foo', version: '1.2.0'))
|
new Dependency(id: 'foo', groupId: 'org.acme', artifactId: 'foo', version: '1.2.0'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gitIgnoreMaven() {
|
||||||
|
def request = createProjectRequest()
|
||||||
|
request.type = 'maven-project'
|
||||||
|
def project = generateProject(request)
|
||||||
|
project.sourceCodeAssert(".gitignore")
|
||||||
|
.equalsTo(new ClassPathResource("project/maven/gitignore.gen"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gitIgnoreGradle() {
|
||||||
|
def request = createProjectRequest()
|
||||||
|
request.type = 'gradle-project'
|
||||||
|
def project = generateProject(request)
|
||||||
|
project.sourceCodeAssert(".gitignore")
|
||||||
|
.equalsTo(new ClassPathResource("project/gradle/gitignore.gen"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void invalidProjectTypeMavenPom() {
|
void invalidProjectTypeMavenPom() {
|
||||||
def request = createProjectRequest('web')
|
def request = createProjectRequest('web')
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
.gradle
|
|
||||||
/build/
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
|
@ -1,9 +0,0 @@
|
|||||||
.gradle
|
|
||||||
/build/
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
|
||||||
.idea
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
@ -1,3 +0,0 @@
|
|||||||
.gradle
|
|
||||||
/build/
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
|
@ -1,8 +0,0 @@
|
|||||||
.gradle
|
|
||||||
/build/
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
### STS ###
|
|
||||||
.classpath
|
|
||||||
.project
|
|
||||||
.settings
|
|
@ -2,6 +2,19 @@
|
|||||||
/build/
|
/build/
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
### NetBeans ###
|
### NetBeans ###
|
||||||
nbproject/private/
|
nbproject/private/
|
||||||
build/
|
build/
|
@ -1,2 +0,0 @@
|
|||||||
target/
|
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
|
@ -1,8 +0,0 @@
|
|||||||
target/
|
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
|
||||||
.idea
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
@ -1,2 +0,0 @@
|
|||||||
target/
|
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
|
@ -1,7 +0,0 @@
|
|||||||
target/
|
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
|
||||||
|
|
||||||
### STS ###
|
|
||||||
.classpath
|
|
||||||
.project
|
|
||||||
.settings
|
|
@ -1,6 +1,19 @@
|
|||||||
target/
|
target/
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
### NetBeans ###
|
### NetBeans ###
|
||||||
nbproject/private/
|
nbproject/private/
|
||||||
build/
|
build/
|
Loading…
Reference in New Issue
Block a user