mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-19 10:08:22 +08:00
Only expose project type in the HTML UI
While the service can generate a project or a single build file, the latter option is rarely used in practice. We now filter the available types so that only "project" format types are kept. See gh-145
This commit is contained in:
@@ -18,6 +18,8 @@ package io.spring.initializr.metadata
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude
|
import com.fasterxml.jackson.annotation.JsonInclude
|
||||||
|
import groovy.transform.AutoClone
|
||||||
|
import groovy.transform.AutoCloneStyle
|
||||||
|
|
||||||
import org.springframework.util.Assert
|
import org.springframework.util.Assert
|
||||||
|
|
||||||
@@ -30,6 +32,7 @@ import org.springframework.util.Assert
|
|||||||
*/
|
*/
|
||||||
@JsonIgnoreProperties(["default", "all"])
|
@JsonIgnoreProperties(["default", "all"])
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
@AutoClone(style = AutoCloneStyle.COPY_CONSTRUCTOR)
|
||||||
abstract class ServiceCapability<T> {
|
abstract class ServiceCapability<T> {
|
||||||
|
|
||||||
final String id
|
final String id
|
||||||
|
@@ -16,12 +16,16 @@
|
|||||||
|
|
||||||
package io.spring.initializr.metadata
|
package io.spring.initializr.metadata
|
||||||
|
|
||||||
|
import groovy.transform.AutoClone
|
||||||
|
import groovy.transform.AutoCloneStyle
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link ServiceCapabilityType#ACTION action} capability.
|
* An {@link ServiceCapabilityType#ACTION action} capability.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
|
@AutoClone(style = AutoCloneStyle.COPY_CONSTRUCTOR)
|
||||||
class TypeCapability extends ServiceCapability<List<Type>> {
|
class TypeCapability extends ServiceCapability<List<Type>> {
|
||||||
|
|
||||||
final List<Type> content = []
|
final List<Type> content = []
|
||||||
|
@@ -49,7 +49,17 @@ abstract class AbstractInitializrController {
|
|||||||
protected String renderHome(String templatePath) {
|
protected String renderHome(String templatePath) {
|
||||||
def model = [:]
|
def model = [:]
|
||||||
model['serviceUrl'] = generateAppUrl()
|
model['serviceUrl'] = generateAppUrl()
|
||||||
metadataProvider.get().properties.each { model[it.key] = it.value }
|
metadataProvider.get().properties.each {
|
||||||
|
if (it.key.equals('types')) {
|
||||||
|
model['types'] = it.value.clone()
|
||||||
|
} else {
|
||||||
|
model[it.key] = it.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only keep project type
|
||||||
|
model['types'].content.removeAll { t -> !'project'.equals(t.tags['format']) }
|
||||||
|
|
||||||
template templatePath, model
|
template templatePath, model
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,6 +34,7 @@ import static org.hamcrest.CoreMatchers.allOf
|
|||||||
import static org.hamcrest.CoreMatchers.containsString
|
import static org.hamcrest.CoreMatchers.containsString
|
||||||
import static org.hamcrest.core.IsNot.not
|
import static org.hamcrest.core.IsNot.not
|
||||||
import static org.junit.Assert.assertEquals
|
import static org.junit.Assert.assertEquals
|
||||||
|
import static org.junit.Assert.assertFalse
|
||||||
import static org.junit.Assert.assertNotNull
|
import static org.junit.Assert.assertNotNull
|
||||||
import static org.junit.Assert.assertThat
|
import static org.junit.Assert.assertThat
|
||||||
import static org.junit.Assert.assertTrue
|
import static org.junit.Assert.assertTrue
|
||||||
@@ -357,8 +358,6 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
|||||||
downloadZip('/starter.zip?style=foo').pomAssert().hasSpringBootStarterDependency('foo')
|
downloadZip('/starter.zip?style=foo').pomAssert().hasSpringBootStarterDependency('foo')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Existing tests for backward compatibility
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void homeIsForm() {
|
void homeIsForm() {
|
||||||
def body = htmlHome()
|
def body = htmlHome()
|
||||||
@@ -405,6 +404,13 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
|||||||
assertTrue("Wrong body:\n$body", body.contains('1.2.0.BUILD-SNAPSHOT"'))
|
assertTrue("Wrong body:\n$body", body.contains('1.2.0.BUILD-SNAPSHOT"'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void homeHasOnlyProjectFormatTypes() {
|
||||||
|
def body = htmlHome()
|
||||||
|
assertTrue 'maven project not found', body.contains('Maven Project')
|
||||||
|
assertFalse 'maven pom type should have been filtered', body.contains('Maven POM')
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void downloadStarter() {
|
void downloadStarter() {
|
||||||
def body = restTemplate.getForObject(createUrl('starter.zip'), byte[])
|
def body = restTemplate.getForObject(createUrl('starter.zip'), byte[])
|
||||||
|
@@ -17,8 +17,6 @@
|
|||||||
package io.spring.initializr.web
|
package io.spring.initializr.web
|
||||||
|
|
||||||
import geb.Browser
|
import geb.Browser
|
||||||
import io.spring.initializr.test.GradleBuildAssert
|
|
||||||
import io.spring.initializr.test.PomAssert
|
|
||||||
import io.spring.initializr.web.test.HomePage
|
import io.spring.initializr.web.test.HomePage
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
@@ -172,33 +170,6 @@ class ProjectGenerationSmokeTests extends AbstractInitializrControllerIntegratio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void createMavenBuild() {
|
|
||||||
toHome {
|
|
||||||
page.type = 'maven-build'
|
|
||||||
page.dependency('data-jpa').click()
|
|
||||||
page.artifactId = 'my-maven-project'
|
|
||||||
page.generateProject.click()
|
|
||||||
at HomePage
|
|
||||||
|
|
||||||
pomAssert().hasArtifactId('my-maven-project')
|
|
||||||
.hasSpringBootStarterDependency('data-jpa')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void createGradleBuild() {
|
|
||||||
toHome {
|
|
||||||
page.type = 'gradle-build'
|
|
||||||
page.javaVersion = '1.6'
|
|
||||||
page.artifactId = 'my-gradle-project'
|
|
||||||
page.generateProject.click()
|
|
||||||
at HomePage
|
|
||||||
|
|
||||||
gradleBuildAssert().hasArtifactId('my-gradle-project').hasJavaVersion('1.6')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void dependencyHiddenAccordingToRange() {
|
void dependencyHiddenAccordingToRange() {
|
||||||
toHome { // bur: [1.1.4.RELEASE,1.2.0.BUILD-SNAPSHOT)
|
toHome { // bur: [1.1.4.RELEASE,1.2.0.BUILD-SNAPSHOT)
|
||||||
@@ -236,14 +207,6 @@ class ProjectGenerationSmokeTests extends AbstractInitializrControllerIntegratio
|
|||||||
browser
|
browser
|
||||||
}
|
}
|
||||||
|
|
||||||
private GradleBuildAssert gradleBuildAssert() {
|
|
||||||
new GradleBuildAssert(getArchive('build.gradle').text)
|
|
||||||
}
|
|
||||||
|
|
||||||
private PomAssert pomAssert() {
|
|
||||||
new PomAssert(getArchive('pom.xml').text)
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] from(String fileName) {
|
private byte[] from(String fileName) {
|
||||||
getArchive(fileName).bytes
|
getArchive(fileName).bytes
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user