49 |
50 |
51 |
--------------------------------------------------------------------------------
/ci/scripts/stage.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | source $(dirname $0)/common.sh
5 | repository=$(pwd)/distribution-repository
6 |
7 | pushd git-repo > /dev/null
8 | git fetch --tags --all > /dev/null
9 | popd > /dev/null
10 |
11 | git clone git-repo stage-git-repo > /dev/null
12 |
13 | pushd stage-git-repo > /dev/null
14 |
15 | snapshotVersion=$( get_revision_from_pom )
16 | stageVersion=$( get_next_release $snapshotVersion)
17 | nextVersion=$( bump_version_number $snapshotVersion)
18 | echo "Staging $stageVersion (next version will be $nextVersion)"
19 |
20 | set_revision_to_pom "$stageVersion"
21 | git config user.name "Spring Buildmaster" > /dev/null
22 | git config user.email "buildmaster@springframework.org" > /dev/null
23 | git add pom.xml > /dev/null
24 | git commit -m"Release v$stageVersion" > /dev/null
25 | git tag -a "v$stageVersion" -m"Release v$stageVersion" > /dev/null
26 |
27 | ./mvnw clean deploy -U -Pfull -DaltDeploymentRepository=distribution::default::file://${repository}
28 |
29 | git reset --hard HEAD^ > /dev/null
30 | if [[ $nextVersion != $snapshotVersion ]]; then
31 | echo "Setting next development version (v$nextVersion)"
32 | set_revision_to_pom "$nextVersion"
33 | git add pom.xml > /dev/null
34 | git commit -m"Next development version (v$nextVersion)" > /dev/null
35 | fi;
36 |
37 | echo "DONE"
38 |
39 | popd > /dev/null
40 |
--------------------------------------------------------------------------------
/initializr-docs/src/test/java/io/spring/initializr/stub/SampleApp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.stub;
18 |
19 | import io.spring.initializr.actuate.autoconfigure.InitializrActuatorEndpointsAutoConfiguration;
20 | import io.spring.initializr.web.autoconfigure.InitializrAutoConfiguration;
21 |
22 | import org.springframework.boot.autoconfigure.SpringBootApplication;
23 |
24 | /**
25 | * A sample app where the Initializr auto-configuration has been disabled.
26 | *
27 | * @author Stephane Nicoll
28 | */
29 | @SpringBootApplication(exclude = { InitializrAutoConfiguration.class,
30 | InitializrActuatorEndpointsAutoConfiguration.class })
31 | public class SampleApp {
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/kotlin/previous/build.gradle.gen:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | kotlinVersion = '1.1.1'
4 | springBootVersion = '1.5.18.RELEASE'
5 | }
6 | repositories {
7 | mavenCentral()
8 | }
9 | dependencies {
10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
11 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
12 | classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
13 | }
14 | }
15 |
16 | apply plugin: 'kotlin'
17 | apply plugin: 'kotlin-spring'
18 | apply plugin: 'org.springframework.boot'
19 |
20 | group = 'com.example'
21 | version = '0.0.1-SNAPSHOT'
22 | sourceCompatibility = '1.8'
23 |
24 | repositories {
25 | mavenCentral()
26 | }
27 |
28 | dependencies {
29 | implementation 'org.springframework.boot:spring-boot-starter'
30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
31 | implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
32 | testImplementation 'org.springframework.boot:spring-boot-starter-test'
33 | }
34 |
35 | compileKotlin {
36 | kotlinOptions {
37 | freeCompilerArgs = ['-Xjsr305=strict']
38 | jvmTarget = '1.8'
39 | }
40 | }
41 |
42 | compileTestKotlin {
43 | kotlinOptions {
44 | freeCompilerArgs = ['-Xjsr305=strict']
45 | jvmTarget = '1.8'
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/StatsPropertiesTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.actuate.stat;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | import static org.assertj.core.api.Assertions.assertThat;
22 |
23 | /**
24 | * Tests for {@link StatsProperties}.
25 | *
26 | * @author Stephane Nicoll
27 | */
28 | class StatsPropertiesTests {
29 |
30 | private final StatsProperties properties = new StatsProperties();
31 |
32 | @Test
33 | void cleanTrailingSlash() {
34 | this.properties.getElastic().setUri("http://example.com/");
35 | assertThat(this.properties.getElastic().getUri()).isEqualTo("http://example.com");
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/gradle/kotlin-java11-build.gradle.gen:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | kotlinVersion = '1.1.1'
4 | springBootVersion = '2.1.1.RELEASE'
5 | }
6 | repositories {
7 | mavenCentral()
8 | }
9 | dependencies {
10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
11 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
12 | classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
13 | }
14 | }
15 |
16 | apply plugin: 'kotlin'
17 | apply plugin: 'kotlin-spring'
18 | apply plugin: 'org.springframework.boot'
19 | apply plugin: 'io.spring.dependency-management'
20 |
21 | group = 'com.example'
22 | version = '0.0.1-SNAPSHOT'
23 | sourceCompatibility = '11'
24 |
25 | repositories {
26 | mavenCentral()
27 | }
28 |
29 | dependencies {
30 | implementation 'org.springframework.boot:spring-boot-starter'
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
32 | implementation "org.jetbrains.kotlin:kotlin-reflect"
33 | testImplementation 'org.springframework.boot:spring-boot-starter-test'
34 | }
35 |
36 | compileKotlin {
37 | kotlinOptions {
38 | freeCompilerArgs = ['-Xjsr305=strict']
39 | jvmTarget = '1.8'
40 | }
41 | }
42 |
43 | compileTestKotlin {
44 | kotlinOptions {
45 | freeCompilerArgs = ['-Xjsr305=strict']
46 | jvmTarget = '1.8'
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/kotlin/standard/build.gradle.gen:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | kotlinVersion = '1.1.1'
4 | springBootVersion = '2.1.1.RELEASE'
5 | }
6 | repositories {
7 | mavenCentral()
8 | }
9 | dependencies {
10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
11 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
12 | classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
13 | }
14 | }
15 |
16 | apply plugin: 'kotlin'
17 | apply plugin: 'kotlin-spring'
18 | apply plugin: 'org.springframework.boot'
19 | apply plugin: 'io.spring.dependency-management'
20 |
21 | group = 'com.example'
22 | version = '0.0.1-SNAPSHOT'
23 | sourceCompatibility = '1.8'
24 |
25 | repositories {
26 | mavenCentral()
27 | }
28 |
29 | dependencies {
30 | implementation 'org.springframework.boot:spring-boot-starter'
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
32 | implementation "org.jetbrains.kotlin:kotlin-reflect"
33 | testImplementation 'org.springframework.boot:spring-boot-starter-test'
34 | }
35 |
36 | compileKotlin {
37 | kotlinOptions {
38 | freeCompilerArgs = ['-Xjsr305=strict']
39 | jvmTarget = '1.8'
40 | }
41 | }
42 |
43 | compileTestKotlin {
44 | kotlinOptions {
45 | freeCompilerArgs = ['-Xjsr305=strict']
46 | jvmTarget = '1.8'
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/generator/ProjectFailedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.generator;
18 |
19 | /**
20 | * Event published when an error occurred trying to generate a project.
21 | *
22 | * @author Stephane Nicoll
23 | */
24 | public class ProjectFailedEvent extends ProjectRequestEvent {
25 |
26 | private final Exception cause;
27 |
28 | public ProjectFailedEvent(ProjectRequest projectRequest, Exception cause) {
29 | super(projectRequest);
30 | this.cause = cause;
31 | }
32 |
33 | /**
34 | * Return the cause of the failure.
35 | * @return the cause of the failure
36 | */
37 | public Exception getCause() {
38 | return this.cause;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/metadata/DependencyMetadataProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | import io.spring.initializr.util.Version;
20 |
21 | /**
22 | * Provide the {@link DependencyMetadata} for a given spring boot version.
23 | *
24 | * @author Stephane Nicoll
25 | */
26 | public interface DependencyMetadataProvider {
27 |
28 | /**
29 | * Return the dependency metadata to use for the specified {@code bootVersion}.
30 | * @param metadata the intializr metadata
31 | * @param bootVersion the Spring Boot version
32 | * @return the dependency metadata
33 | */
34 | DependencyMetadata get(InitializrMetadata metadata, Version bootVersion);
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/java/previous/pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 1.5.18.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-maven-plugin
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/java/standard/pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-maven-plugin
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/kotlin/standard/war-build.gradle.gen:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | kotlinVersion = '1.1.1'
4 | springBootVersion = '2.1.1.RELEASE'
5 | }
6 | repositories {
7 | mavenCentral()
8 | }
9 | dependencies {
10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
11 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
12 | classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
13 | }
14 | }
15 |
16 | apply plugin: 'kotlin'
17 | apply plugin: 'kotlin-spring'
18 | apply plugin: 'org.springframework.boot'
19 | apply plugin: 'io.spring.dependency-management'
20 | apply plugin: 'war'
21 |
22 | group = 'com.example'
23 | version = '0.0.1-SNAPSHOT'
24 | sourceCompatibility = '1.8'
25 |
26 | repositories {
27 | mavenCentral()
28 | }
29 |
30 | dependencies {
31 | implementation 'org.springframework.boot:spring-boot-starter-web'
32 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
33 | implementation "org.jetbrains.kotlin:kotlin-reflect"
34 | providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
35 | testImplementation 'org.springframework.boot:spring-boot-starter-test'
36 | }
37 |
38 | compileKotlin {
39 | kotlinOptions {
40 | freeCompilerArgs = ['-Xjsr305=strict']
41 | jvmTarget = '1.8'
42 | }
43 | }
44 |
45 | compileTestKotlin {
46 | kotlinOptions {
47 | freeCompilerArgs = ['-Xjsr305=strict']
48 | jvmTarget = '1.8'
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/java/io/spring/initializr/test/generator/GradleSettingsAssert.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.test.generator;
18 |
19 | import static org.assertj.core.api.Assertions.assertThat;
20 |
21 | /**
22 | * Very simple assertions for the gradle settings.
23 | *
24 | * @author Stephane Nicoll
25 | */
26 | public class GradleSettingsAssert {
27 |
28 | private final String content;
29 |
30 | public GradleSettingsAssert(String content) {
31 | this.content = content;
32 | }
33 |
34 | public GradleSettingsAssert hasProjectName(String name) {
35 | return contains(String.format("rootProject.name = '%s'", name));
36 | }
37 |
38 | public GradleSettingsAssert contains(String expression) {
39 | assertThat(this.content).contains(expression);
40 | return this;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/initializr-docs/src/main/asciidoc/index.adoc:
--------------------------------------------------------------------------------
1 | = Spring Initializr Reference Guide
2 | Stéphane Nicoll; Dave Syer
3 | :doctype: book
4 | :idprefix:
5 | :idseparator: -
6 | :toc: left
7 | :toclevels: 4
8 | :tabsize: 4
9 | :numbered:
10 | :sectanchors:
11 | :sectnums:
12 | :icons: font
13 | :hide-uri-scheme:
14 | :docinfo: shared,private
15 |
16 | :test-examples: ../../test/java/io/spring/initializr
17 | :initializr-repo: snapshot
18 | :github-tag: master
19 | :github-repo: spring-io/initializr
20 | :github-raw: https://raw.github.com/{github-repo}/{github-tag}
21 | :github-code: https://github.com/{github-repo}/tree/{github-tag}
22 | :github-wiki: https://github.com/{github-repo}/wiki
23 | :github-master-code: https://github.com/{github-repo}/tree/master
24 | :sc-initializr-generator: {github-code}/initializr-generator/src/main/java/io/spring/initializr
25 | :spring-initializr-docs-version: current
26 | :spring-initializr-docs: http://docs.spring.io/initializr/docs/{spring-initializr-docs-version}/reference
27 | :spring-initializr-docs-current: http://docs.spring.io/initializr/docs/current/reference/html
28 | :spring-boot-reference: http://docs.spring.io/spring-boot/docs/{spring-boot-docs-version}/reference/htmlsingle
29 |
30 | // ======================================================================================
31 |
32 | include::documentation-overview.adoc[]
33 | include::user-guide.adoc[]
34 | include::configuration-guide.adoc[]
35 | include::api-guide.adoc[]
36 | // ======================================================================================
37 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/maven/version-override-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 | 0.2.0.RELEASE
20 | 0.1.0.RELEASE
21 |
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-web
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-test
32 | test
33 |
34 |
35 |
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-maven-plugin
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataVersion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.mapper;
18 |
19 | import org.springframework.http.MediaType;
20 |
21 | /**
22 | * Define the supported metadata version.
23 | *
24 | * @author Stephane Nicoll
25 | */
26 | public enum InitializrMetadataVersion {
27 |
28 | /**
29 | * HAL-compliant metadata.
30 | */
31 | V2("application/vnd.initializr.v2+json"),
32 |
33 | /**
34 | * Add "versionRange" attribute to any dependency to specify which Spring Boot
35 | * versions are compatible with it. Also provide a separate "dependencies" endpoint to
36 | * query dependencies metadata.
37 | */
38 | V2_1("application/vnd.initializr.v2.1+json");
39 |
40 | private final MediaType mediaType;
41 |
42 | InitializrMetadataVersion(String mediaType) {
43 | this.mediaType = MediaType.parseMediaType(mediaType);
44 | }
45 |
46 | public MediaType getMediaType() {
47 | return this.mediaType;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/metadata/ServiceCapabilityType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | /**
20 | * Defines the supported service capability type.
21 | *
22 | * @author Stephane Nicoll
23 | */
24 | public enum ServiceCapabilityType {
25 |
26 | /**
27 | * A special type that defines the action to use.
28 | */
29 | ACTION("action"),
30 |
31 | /**
32 | * A simple text value with no option.
33 | */
34 | TEXT("text"),
35 |
36 | /**
37 | * A simple value to be chosen amongst the specified options.
38 | */
39 | SINGLE_SELECT("single-select"),
40 |
41 | /**
42 | * A hierarchical set of values (values in values) with the ability to select multiple
43 | * values.
44 | */
45 | HIERARCHICAL_MULTI_SELECT("hierarchical-multi-select");
46 |
47 | private final String name;
48 |
49 | ServiceCapabilityType(String name) {
50 | this.name = name;
51 | }
52 |
53 | public String getName() {
54 | return this.name;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/java/standard/war-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | war
15 | demo
16 | Demo project for Spring Boot
17 |
18 |
19 | 1.8
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-web
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-tomcat
31 | provided
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-maven-plugin
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/initializr-web/src/test/java/io/spring/initializr/web/AbstractFullStackInitializrIntegrationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web;
18 |
19 | import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config;
20 |
21 | import org.springframework.boot.test.context.SpringBootTest;
22 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
23 | import org.springframework.boot.web.server.LocalServerPort;
24 |
25 | /**
26 | * @author Stephane Nicoll
27 | * @author Dave Syer
28 | */
29 | @SpringBootTest(classes = Config.class, webEnvironment = WebEnvironment.RANDOM_PORT)
30 | public abstract class AbstractFullStackInitializrIntegrationTests
31 | extends AbstractInitializrIntegrationTests {
32 |
33 | @LocalServerPort
34 | protected int port;
35 |
36 | protected String host = "localhost";
37 |
38 | @Override
39 | protected String createUrl(String context) {
40 | return "http://" + this.host + ":" + this.port
41 | + (context.startsWith("/") ? context : "/" + context);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/initializr-web/src/test/resources/metadata/dependencies/test-dependencies-2.1.4.json:
--------------------------------------------------------------------------------
1 | {
2 | "bootVersion": "2.1.4.RELEASE",
3 | "repositories": {
4 | "my-api-repo-1": {
5 | "name": "repo1",
6 | "url": "http://example.com/repo1",
7 | "snapshotEnabled": false
8 | }
9 | },
10 | "boms": {
11 | "my-api-bom": {
12 | "groupId": "org.acme",
13 | "artifactId": "my-api-bom",
14 | "version": "1.0.0.RELEASE",
15 | "repositories": [
16 | "my-api-repo-1"
17 | ]
18 | }
19 | },
20 | "dependencies": {
21 | "web": {
22 | "groupId": "org.springframework.boot",
23 | "scope": "compile",
24 | "artifactId": "spring-boot-starter-web"
25 | },
26 | "security": {
27 | "groupId": "org.springframework.boot",
28 | "scope": "compile",
29 | "artifactId": "spring-boot-starter-security"
30 | },
31 | "data-jpa": {
32 | "groupId": "org.springframework.boot",
33 | "scope": "compile",
34 | "artifactId": "spring-boot-starter-data-jpa"
35 | },
36 | "org.acme:foo": {
37 | "groupId": "org.acme",
38 | "scope": "compile",
39 | "artifactId": "foo",
40 | "version": "1.3.5"
41 | },
42 | "org.acme:bar": {
43 | "groupId": "org.acme",
44 | "scope": "compile",
45 | "artifactId": "bar",
46 | "version": "2.1.0"
47 | },
48 | "org.acme:bur": {
49 | "groupId": "org.acme",
50 | "scope": "test",
51 | "artifactId": "bur",
52 | "version": "2.1.0"
53 | },
54 | "my-api": {
55 | "groupId": "org.acme",
56 | "scope": "provided",
57 | "artifactId": "my-api",
58 | "bom": "my-api-bom"
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/initializr-web/src/test/resources/metadata/dependencies/test-dependencies-2.2.1.json:
--------------------------------------------------------------------------------
1 | {
2 | "bootVersion": "2.2.1.RELEASE",
3 | "repositories": {
4 | "my-api-repo-2": {
5 | "name": "repo2",
6 | "url": "http://example.com/repo2",
7 | "snapshotEnabled": false
8 | }
9 | },
10 | "boms": {
11 | "my-api-bom": {
12 | "groupId": "org.acme",
13 | "artifactId": "my-api-bom",
14 | "version": "2.0.0.RELEASE",
15 | "repositories": [
16 | "my-api-repo-2"
17 | ]
18 | }
19 | },
20 | "dependencies": {
21 | "web": {
22 | "groupId": "org.springframework.boot",
23 | "scope": "compile",
24 | "artifactId": "spring-boot-starter-web"
25 | },
26 | "security": {
27 | "groupId": "org.springframework.boot",
28 | "scope": "compile",
29 | "artifactId": "spring-boot-starter-security"
30 | },
31 | "data-jpa": {
32 | "groupId": "org.springframework.boot",
33 | "scope": "compile",
34 | "artifactId": "spring-boot-starter-data-jpa"
35 | },
36 | "org.acme:foo": {
37 | "groupId": "org.acme",
38 | "scope": "compile",
39 | "artifactId": "foo",
40 | "version": "1.3.5"
41 | },
42 | "org.acme:bar": {
43 | "groupId": "org.acme",
44 | "scope": "compile",
45 | "artifactId": "bar",
46 | "version": "2.1.0"
47 | },
48 | "org.acme:biz": {
49 | "groupId": "org.acme",
50 | "scope": "runtime",
51 | "artifactId": "biz",
52 | "version": "1.3.5"
53 | },
54 | "my-api": {
55 | "groupId": "org.acme",
56 | "scope": "provided",
57 | "artifactId": "my-api",
58 | "bom": "my-api-bom"
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/metadata/MetadataElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | /**
20 | * A basic metadata element.
21 | *
22 | * @author Stephane Nicoll
23 | */
24 | public class MetadataElement {
25 |
26 | /**
27 | * A visual representation of this element.
28 | */
29 | private String name;
30 |
31 | /**
32 | * The unique id of this element for a given capability.
33 | */
34 | private String id;
35 |
36 | public MetadataElement() {
37 | }
38 |
39 | public MetadataElement(MetadataElement other) {
40 | this(other.id, other.name);
41 | }
42 |
43 | public MetadataElement(String id, String name) {
44 | this.id = id;
45 | this.name = name;
46 | }
47 |
48 | public String getName() {
49 | return (this.name != null) ? this.name : this.id;
50 | }
51 |
52 | public String getId() {
53 | return this.id;
54 | }
55 |
56 | public void setId(String id) {
57 | this.id = id;
58 | }
59 |
60 | public void setName(String name) {
61 | this.name = name;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/metadata/TextCapability.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | import com.fasterxml.jackson.annotation.JsonCreator;
20 | import com.fasterxml.jackson.annotation.JsonProperty;
21 |
22 | /**
23 | * A {@link ServiceCapabilityType#TEXT text} capability.
24 | *
25 | * @author Stephane Nicoll
26 | */
27 | public class TextCapability extends ServiceCapability {
28 |
29 | private String content;
30 |
31 | @JsonCreator
32 | TextCapability(@JsonProperty("id") String id) {
33 | this(id, null, null);
34 | }
35 |
36 | TextCapability(String id, String title, String description) {
37 | super(id, ServiceCapabilityType.TEXT, title, description);
38 | }
39 |
40 | @Override
41 | public String getContent() {
42 | return this.content;
43 | }
44 |
45 | public void setContent(String content) {
46 | this.content = content;
47 | }
48 |
49 | @Override
50 | public void merge(String otherContent) {
51 | if (otherContent != null) {
52 | this.content = otherContent;
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/generator/ProjectRequestEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.generator;
18 |
19 | /**
20 | * Event published when a {@link ProjectRequest} has been processed.
21 | *
22 | * @author Stephane Nicoll
23 | * @see ProjectGeneratedEvent
24 | * @see ProjectFailedEvent
25 | */
26 | public abstract class ProjectRequestEvent {
27 |
28 | private final ProjectRequest projectRequest;
29 |
30 | private final long timestamp;
31 |
32 | protected ProjectRequestEvent(ProjectRequest projectRequest) {
33 | this.projectRequest = projectRequest;
34 | this.timestamp = System.currentTimeMillis();
35 | }
36 |
37 | /**
38 | * Return the {@link ProjectRequest} used to generate the project.
39 | * @return the project request
40 | */
41 | public ProjectRequest getProjectRequest() {
42 | return this.projectRequest;
43 | }
44 |
45 | /**
46 | * Return the timestamp at which the request was processed.
47 | * @return the timestamp that the request was processed
48 | */
49 | public long getTimestamp() {
50 | return this.timestamp;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/maven/compile-only-dependency-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-data-jpa
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-web
29 |
30 |
31 |
32 | org.acme
33 | foo
34 | true
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-test
39 | test
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-maven-plugin
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/maven/bom-property-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 | 1.3.3
20 |
21 |
22 |
23 |
24 | org.acme
25 | foo
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-test
31 | test
32 |
33 |
34 |
35 |
36 |
37 |
38 | org.acme
39 | foo-bom
40 | ${foo.version}
41 | pom
42 | import
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-maven-plugin
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/maven/annotation-processor-dependency-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-data-jpa
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-web
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-configuration-processor
34 | true
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-test
39 | test
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-maven-plugin
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/metadata/DefaultMetadataElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | /**
20 | * A {@link MetadataElement} that specifies if its the default for a given capability.
21 | *
22 | * @author Stephane Nicoll
23 | */
24 | public class DefaultMetadataElement extends MetadataElement {
25 |
26 | private boolean defaultValue;
27 |
28 | public DefaultMetadataElement() {
29 | }
30 |
31 | public DefaultMetadataElement(String id, String name, boolean defaultValue) {
32 | super(id, name);
33 | this.defaultValue = defaultValue;
34 | }
35 |
36 | public DefaultMetadataElement(String id, boolean defaultValue) {
37 | this(id, null, defaultValue);
38 | }
39 |
40 | public void setDefault(boolean defaultValue) {
41 | this.defaultValue = defaultValue;
42 | }
43 |
44 | public boolean isDefault() {
45 | return this.defaultValue;
46 | }
47 |
48 | public static DefaultMetadataElement create(String id, boolean defaultValue) {
49 | return new DefaultMetadataElement(id, defaultValue);
50 | }
51 |
52 | public static DefaultMetadataElement create(String id, String name,
53 | boolean defaultValue) {
54 | return new DefaultMetadataElement(id, name, defaultValue);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/initializr-actuator/src/main/java/io/spring/initializr/actuate/autoconfigure/InitializrActuatorEndpointsAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.actuate.autoconfigure;
18 |
19 | import io.spring.initializr.actuate.info.BomRangesInfoContributor;
20 | import io.spring.initializr.actuate.info.DependencyRangesInfoContributor;
21 | import io.spring.initializr.metadata.InitializrMetadataProvider;
22 |
23 | import org.springframework.context.annotation.Bean;
24 | import org.springframework.context.annotation.Configuration;
25 |
26 | /**
27 | * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
28 | * Auto-configuration} to improve actuator endpoints with initializr specific information.
29 | *
30 | * @author Stephane Nicoll
31 | */
32 | @Configuration
33 | public class InitializrActuatorEndpointsAutoConfiguration {
34 |
35 | @Bean
36 | public BomRangesInfoContributor bomRangesInfoContributor(
37 | InitializrMetadataProvider metadataProvider) {
38 | return new BomRangesInfoContributor(metadataProvider);
39 | }
40 |
41 | @Bean
42 | public DependencyRangesInfoContributor dependencyRangesInfoContributor(
43 | InitializrMetadataProvider metadataProvider) {
44 | return new DependencyRangesInfoContributor(metadataProvider);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/maven/repositories-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.acme
24 | bar
25 |
26 |
27 | org.acme
28 | foo
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 |
46 |
47 |
48 |
49 | foo-repository
50 | foo-repo
51 | https://example.com/foo
52 |
53 |
54 | bar-repository
55 | bar-repo
56 | https://example.com/bar
57 |
58 | true
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/generator/BuildProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.generator;
18 |
19 | import java.util.Map;
20 | import java.util.TreeMap;
21 | import java.util.function.Supplier;
22 |
23 | import io.spring.initializr.util.VersionProperty;
24 |
25 | /**
26 | * Build properties associated to a project request.
27 | *
28 | * @author Stephane Nicoll
29 | */
30 | public class BuildProperties {
31 |
32 | /**
33 | * Maven-specific build properties, added to the regular {@code properties} element.
34 | */
35 | private final TreeMap> maven = new TreeMap<>();
36 |
37 | /**
38 | * Gradle-specific build properties, added to the {@code buildscript} section of the
39 | * gradle build.
40 | */
41 | private final TreeMap> gradle = new TreeMap<>();
42 |
43 | /**
44 | * Version properties. Shared between the two build systems.
45 | */
46 | private final TreeMap> versions = new TreeMap<>();
47 |
48 | public Map> getMaven() {
49 | return this.maven;
50 | }
51 |
52 | public Map> getGradle() {
53 | return this.gradle;
54 | }
55 |
56 | public Map> getVersions() {
57 | return this.versions;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/initializr-actuator/src/test/java/io/spring/initializr/actuate/test/MetricsAssert.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.actuate.test;
18 |
19 | import java.util.Arrays;
20 |
21 | import io.micrometer.core.instrument.MeterRegistry;
22 | import io.micrometer.core.instrument.search.Search;
23 |
24 | import static org.assertj.core.api.Assertions.assertThat;
25 |
26 | /**
27 | * Metrics assertion based on {@link MeterRegistry}.
28 | *
29 | * @author Stephane Nicoll
30 | */
31 | public class MetricsAssert {
32 |
33 | private final MeterRegistry meterRegistry;
34 |
35 | public MetricsAssert(MeterRegistry meterRegistry) {
36 | this.meterRegistry = meterRegistry;
37 | }
38 |
39 | public MetricsAssert hasValue(long value, String... metrics) {
40 | Arrays.asList(metrics).forEach(
41 | (metric) -> assertThat(this.meterRegistry.get(metric).counter().count())
42 | .isEqualTo(value));
43 | return this;
44 | }
45 |
46 | public MetricsAssert hasNoValue(String... metrics) {
47 | Arrays.asList(metrics).forEach((metric) -> assertThat(
48 | Search.in(this.meterRegistry).name((n) -> n.startsWith(metric)).counter())
49 | .isNull());
50 | return this;
51 | }
52 |
53 | public MetricsAssert metricsCount(int count) {
54 | assertThat(Search.in(this.meterRegistry).meters()).hasSize(count);
55 | return this;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/metadata/DependencyMetadata.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | import java.util.Map;
20 |
21 | import io.spring.initializr.util.Version;
22 |
23 | /**
24 | * Dependency metadata for a given spring boot {@link Version}.
25 | *
26 | * @author Stephane Nicoll
27 | */
28 | public class DependencyMetadata {
29 |
30 | final Version bootVersion;
31 |
32 | final Map dependencies;
33 |
34 | final Map repositories;
35 |
36 | final Map boms;
37 |
38 | public DependencyMetadata() {
39 | this(null, null, null, null);
40 | }
41 |
42 | public DependencyMetadata(Version bootVersion, Map dependencies,
43 | Map repositories, Map boms) {
44 | this.bootVersion = bootVersion;
45 | this.dependencies = dependencies;
46 | this.repositories = repositories;
47 | this.boms = boms;
48 | }
49 |
50 | public Version getBootVersion() {
51 | return this.bootVersion;
52 | }
53 |
54 | public Map getDependencies() {
55 | return this.dependencies;
56 | }
57 |
58 | public Map getRepositories() {
59 | return this.repositories;
60 | }
61 |
62 | public Map getBoms() {
63 | return this.boms;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/AbstractInitializrStatTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.actuate.stat;
18 |
19 | import io.spring.initializr.generator.ProjectRequest;
20 | import io.spring.initializr.metadata.InitializrMetadata;
21 | import io.spring.initializr.metadata.InitializrMetadataProvider;
22 | import io.spring.initializr.metadata.SimpleInitializrMetadataProvider;
23 | import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
24 |
25 | /**
26 | * @author Stephane Nicoll
27 | */
28 | abstract class AbstractInitializrStatTests {
29 |
30 | private final InitializrMetadata metadata = InitializrMetadataTestBuilder
31 | .withDefaults().addDependencyGroup("core", "security", "validation", "aop")
32 | .addDependencyGroup("web", "web", "data-rest", "jersey")
33 | .addDependencyGroup("data", "data-jpa", "jdbc")
34 | .addDependencyGroup("database", "h2", "mysql").build();
35 |
36 | protected InitializrMetadataProvider createProvider(InitializrMetadata metadata) {
37 | return new SimpleInitializrMetadataProvider(metadata);
38 | }
39 |
40 | protected ProjectRequest createProjectRequest() {
41 | ProjectRequest request = new ProjectRequest();
42 | request.initialize(this.metadata);
43 | return request;
44 | }
45 |
46 | public InitializrMetadata getMetadata() {
47 | return this.metadata;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/metadata/Type.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | import java.util.LinkedHashMap;
20 | import java.util.Map;
21 |
22 | /**
23 | * Defines a particular project type. Each type is associated to a concrete action that
24 | * should be invoked to generate the content of that type.
25 | *
26 | * @author Stephane Nicoll
27 | */
28 | public class Type extends DefaultMetadataElement implements Describable {
29 |
30 | private String description;
31 |
32 | @Deprecated
33 | private String stsId;
34 |
35 | private String action;
36 |
37 | private final Map tags = new LinkedHashMap<>();
38 |
39 | public void setAction(String action) {
40 | String actionToUse = action;
41 | if (!actionToUse.startsWith("/")) {
42 | actionToUse = "/" + actionToUse;
43 | }
44 | this.action = actionToUse;
45 | }
46 |
47 | @Override
48 | public String getDescription() {
49 | return this.description;
50 | }
51 |
52 | public void setDescription(String description) {
53 | this.description = description;
54 | }
55 |
56 | public String getStsId() {
57 | return this.stsId;
58 | }
59 |
60 | public void setStsId(String stsId) {
61 | this.stsId = stsId;
62 | }
63 |
64 | public String getAction() {
65 | return this.action;
66 | }
67 |
68 | public Map getTags() {
69 | return this.tags;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/initializr-actuator/src/main/java/io/spring/initializr/actuate/autoconfigure/InitializrMetricsAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.actuate.autoconfigure;
18 |
19 | import io.micrometer.core.instrument.MeterRegistry;
20 | import io.spring.initializr.actuate.metric.ProjectGenerationMetricsListener;
21 |
22 | import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
23 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
26 | import org.springframework.context.annotation.Bean;
27 | import org.springframework.context.annotation.Configuration;
28 |
29 | /**
30 | * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
31 | * Auto-configuration} to handle the metrics of an initializr instance.
32 | *
33 | * @author Dave Syer
34 | */
35 | @Configuration
36 | @ConditionalOnClass(MeterRegistry.class)
37 | @AutoConfigureAfter(CompositeMeterRegistryAutoConfiguration.class)
38 | public class InitializrMetricsAutoConfiguration {
39 |
40 | @Bean
41 | @ConditionalOnSingleCandidate(MeterRegistry.class)
42 | public ProjectGenerationMetricsListener metricsListener(MeterRegistry meterRegistry) {
43 | return new ProjectGenerationMetricsListener(meterRegistry);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/maven/bom-ordering-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.acme
24 | foo
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.acme
38 | foo-bom
39 | 1.0
40 | pom
41 | import
42 |
43 |
44 | org.acme
45 | biz-bom
46 | 1.0
47 | pom
48 | import
49 |
50 |
51 | org.acme
52 | bar-bom
53 | 1.0
54 | pom
55 | import
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | org.springframework.boot
64 | spring-boot-maven-plugin
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/groovy/previous/pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 1.5.18.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter
25 |
26 |
27 | org.codehaus.groovy
28 | groovy
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 | org.codehaus.gmavenplus
46 | gmavenplus-plugin
47 | 1.5
48 |
49 |
50 |
51 | addSources
52 | addTestSources
53 | generateStubs
54 | compile
55 | testGenerateStubs
56 | testCompile
57 | removeStubs
58 | removeTestStubs
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/groovy/standard/pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter
25 |
26 |
27 | org.codehaus.groovy
28 | groovy
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 | org.codehaus.gmavenplus
46 | gmavenplus-plugin
47 | 1.5
48 |
49 |
50 |
51 | addSources
52 | addTestSources
53 | generateStubs
54 | compile
55 | testGenerateStubs
56 | testCompile
57 | removeStubs
58 | removeTestStubs
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/metadata/TypeCapability.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * An {@link ServiceCapabilityType#ACTION action} capability.
24 | *
25 | * @author Stephane Nicoll
26 | */
27 | public class TypeCapability extends ServiceCapability>
28 | implements Defaultable {
29 |
30 | private final List content = new ArrayList<>();
31 |
32 | public TypeCapability() {
33 | super("type", ServiceCapabilityType.ACTION, "Type", "project type");
34 | }
35 |
36 | @Override
37 | public List getContent() {
38 | return this.content;
39 | }
40 |
41 | /**
42 | * Return the {@link Type} with the specified id or {@code null} if no such type
43 | * exists.
44 | * @param id the ID to find
45 | * @return the Type or {@code null}
46 | */
47 | public Type get(String id) {
48 | return this.content.stream()
49 | .filter((it) -> id.equals(it.getId()) || id.equals(it.getStsId()))
50 | .findFirst().orElse(null);
51 | }
52 |
53 | /**
54 | * Return the default {@link Type}.
55 | */
56 | @Override
57 | public Type getDefault() {
58 | return this.content.stream().filter(DefaultMetadataElement::isDefault).findFirst()
59 | .orElse(null);
60 | }
61 |
62 | @Override
63 | public void merge(List otherContent) {
64 | otherContent.forEach((it) -> {
65 | if (get(it.getId()) == null) {
66 | this.content.add(it);
67 | }
68 | });
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/initializr-web/src/test/java/io/spring/initializr/web/test/MockMvcClientHttpRequestFactoryTestExecutionListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.test;
18 |
19 | import org.springframework.beans.factory.config.ConfigurableBeanFactory;
20 | import org.springframework.test.context.TestContext;
21 | import org.springframework.test.context.support.AbstractTestExecutionListener;
22 | import org.springframework.test.web.servlet.MockMvc;
23 |
24 | /**
25 | * @author Dave Syer
26 | */
27 | public final class MockMvcClientHttpRequestFactoryTestExecutionListener
28 | extends AbstractTestExecutionListener {
29 |
30 | private MockMvcClientHttpRequestFactory factory;
31 |
32 | @Override
33 | public void beforeTestClass(TestContext testContext) throws Exception {
34 | ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) testContext
35 | .getApplicationContext().getAutowireCapableBeanFactory();
36 | if (!beanFactory.containsBean("mockMvcClientHttpRequestFactory")) {
37 | this.factory = new MockMvcClientHttpRequestFactory(
38 | beanFactory.getBean(MockMvc.class));
39 | beanFactory.registerSingleton("mockMvcClientHttpRequestFactory",
40 | this.factory);
41 | }
42 | else {
43 | this.factory = beanFactory.getBean("mockMvcClientHttpRequestFactory",
44 | MockMvcClientHttpRequestFactory.class);
45 | }
46 | }
47 |
48 | @Override
49 | public void beforeTestMethod(TestContext testContext) throws Exception {
50 | if (this.factory != null) {
51 | this.factory.setTest(testContext.getTestClass(), testContext.getTestMethod());
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/initializr-actuator/src/main/java/io/spring/initializr/actuate/info/BomRangesInfoContributor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.actuate.info;
18 |
19 | import java.util.LinkedHashMap;
20 | import java.util.Map;
21 |
22 | import io.spring.initializr.metadata.InitializrMetadataProvider;
23 |
24 | import org.springframework.boot.actuate.info.Info;
25 | import org.springframework.boot.actuate.info.InfoContributor;
26 |
27 | /**
28 | * An {@link InfoContributor} that exposes the actual ranges used by each bom defined in
29 | * the project.
30 | *
31 | * @author Stephane Nicoll
32 | */
33 | public class BomRangesInfoContributor implements InfoContributor {
34 |
35 | private final InitializrMetadataProvider metadataProvider;
36 |
37 | public BomRangesInfoContributor(InitializrMetadataProvider metadataProvider) {
38 | this.metadataProvider = metadataProvider;
39 | }
40 |
41 | @Override
42 | public void contribute(Info.Builder builder) {
43 | Map details = new LinkedHashMap<>();
44 | this.metadataProvider.get().getConfiguration().getEnv().getBoms()
45 | .forEach((k, v) -> {
46 | if (v.getMappings() != null && !v.getMappings().isEmpty()) {
47 | Map bom = new LinkedHashMap<>();
48 | v.getMappings().forEach((it) -> {
49 | String requirement = "Spring Boot "
50 | + it.determineVersionRangeRequirement();
51 | bom.put(it.getVersion(), requirement);
52 | });
53 | details.put(k, bom);
54 | }
55 | });
56 | if (!details.isEmpty()) {
57 | builder.withDetail("bom-ranges", details);
58 | }
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/generator/ProjectRequestResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.generator;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import io.spring.initializr.metadata.InitializrMetadata;
23 |
24 | import org.springframework.util.Assert;
25 |
26 | /**
27 | * Resolve {@link ProjectRequest} instances, honouring callback hook points.
28 | *
29 | * @author Stephane Nicoll
30 | */
31 | public class ProjectRequestResolver {
32 |
33 | private final List postProcessors;
34 |
35 | public ProjectRequestResolver(List postProcessors) {
36 | this.postProcessors = new ArrayList<>(postProcessors);
37 | }
38 |
39 | public ProjectRequest resolve(ProjectRequest request, InitializrMetadata metadata) {
40 | Assert.notNull(request, "Request must not be null");
41 | applyPostProcessBeforeResolution(request, metadata);
42 | request.resolve(metadata);
43 | applyPostProcessAfterResolution(request, metadata);
44 | return request;
45 | }
46 |
47 | private void applyPostProcessBeforeResolution(ProjectRequest request,
48 | InitializrMetadata metadata) {
49 | for (ProjectRequestPostProcessor processor : this.postProcessors) {
50 | processor.postProcessBeforeResolution(request, metadata);
51 | }
52 | }
53 |
54 | private void applyPostProcessAfterResolution(ProjectRequest request,
55 | InitializrMetadata metadata) {
56 | for (ProjectRequestPostProcessor processor : this.postProcessors) {
57 | processor.postProcessAfterResolution(request, metadata);
58 | }
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerDefaultsIntegrationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.project;
18 |
19 | import io.spring.initializr.test.generator.PomAssert;
20 | import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
21 | import org.junit.jupiter.api.Test;
22 |
23 | import org.springframework.test.context.ActiveProfiles;
24 |
25 | import static org.assertj.core.api.Assertions.assertThat;
26 |
27 | /**
28 | * @author Stephane Nicoll
29 | */
30 | @ActiveProfiles({ "test-default", "test-custom-defaults" })
31 | class MainControllerDefaultsIntegrationTests
32 | extends AbstractInitializrControllerIntegrationTests {
33 |
34 | // see defaults customization
35 |
36 | @Test
37 | void generateDefaultPom() {
38 | String content = getRestTemplate().getForObject(createUrl("/pom.xml?style=web"),
39 | String.class);
40 | PomAssert pomAssert = new PomAssert(content);
41 | pomAssert.hasGroupId("org.foo").hasArtifactId("foo-bar")
42 | .hasVersion("1.2.4-SNAPSHOT").hasPackaging("jar").hasName("FooBar")
43 | .hasDescription("FooBar Project");
44 | }
45 |
46 | @Test
47 | void defaultsAppliedToHome() {
48 | String body = htmlHome();
49 | assertThat(body).as("custom groupId not found").contains("org.foo");
50 | assertThat(body).as("custom artifactId not found").contains("foo-bar");
51 | assertThat(body).as("custom name not found").contains("FooBar");
52 | assertThat(body).as("custom description not found").contains("FooBar Project");
53 | assertThat(body).as("custom package not found").contains("org.foo.demo");
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/java/io/spring/initializr/util/VersionPropertyTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.util;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | import static org.assertj.core.api.Assertions.assertThat;
22 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
23 |
24 | /**
25 | * Tests for {@link VersionProperty}.
26 | *
27 | * @author Stephane Nicoll
28 | */
29 | class VersionPropertyTests {
30 |
31 | @Test
32 | void testStandardProperty() {
33 | assertThat(VersionProperty.of("spring-boot.version").toStandardFormat())
34 | .isEqualTo("spring-boot.version");
35 | }
36 |
37 | @Test
38 | void testCamelCaseProperty() {
39 | assertThat(VersionProperty.of("spring-boot.version").toCamelCaseFormat())
40 | .isEqualTo("springBootVersion");
41 | }
42 |
43 | @Test
44 | void testStandardPropertyWithNoSeparator() {
45 | assertThat(VersionProperty.of("springbootversion").toStandardFormat())
46 | .isEqualTo("springbootversion");
47 | }
48 |
49 | @Test
50 | void testCamelCasePropertyWithNoSeparator() {
51 | assertThat(VersionProperty.of("springbootversion").toCamelCaseFormat())
52 | .isEqualTo("springbootversion");
53 | }
54 |
55 | @Test
56 | void testInvalidPropertyUpperCase() {
57 | assertThatIllegalArgumentException()
58 | .isThrownBy(() -> VersionProperty.of("Spring-boot.version"));
59 | }
60 |
61 | @Test
62 | void testInvalidPropertyIllegalCharacter() {
63 | assertThatIllegalArgumentException()
64 | .isThrownBy(() -> VersionProperty.of("spring-boot_version"))
65 | .withMessageContaining("Unsupported character");
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/maven/repositories-milestone-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.2.0.M1
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.acme
24 | foo
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-maven-plugin
39 |
40 |
41 |
42 |
43 |
44 |
45 | spring-snapshots
46 | Spring Snapshots
47 | https://repo.spring.io/snapshot
48 |
49 | true
50 |
51 |
52 |
53 | spring-milestones
54 | Spring Milestones
55 | https://repo.spring.io/milestone
56 |
57 |
58 |
59 |
60 | spring-snapshots
61 | Spring Snapshots
62 | https://repo.spring.io/snapshot
63 |
64 | true
65 |
66 |
67 |
68 | spring-milestones
69 | Spring Milestones
70 | https://repo.spring.io/milestone
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/initializr-web/src/test/java/io/spring/initializr/web/ui/UiControllerIntegrationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.ui;
18 |
19 | import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
20 | import org.json.JSONException;
21 | import org.json.JSONObject;
22 | import org.junit.jupiter.api.Test;
23 | import org.skyscreamer.jsonassert.JSONAssert;
24 | import org.skyscreamer.jsonassert.JSONCompareMode;
25 |
26 | import org.springframework.http.MediaType;
27 | import org.springframework.http.ResponseEntity;
28 | import org.springframework.test.context.ActiveProfiles;
29 |
30 | /**
31 | * @author Stephane Nicoll
32 | */
33 | @ActiveProfiles("test-default")
34 | class UiControllerIntegrationTests extends AbstractInitializrControllerIntegrationTests {
35 |
36 | @Test
37 | void dependenciesNoVersion() throws JSONException {
38 | ResponseEntity response = execute("/ui/dependencies", String.class, null);
39 | validateContentType(response, MediaType.APPLICATION_JSON);
40 | validateDependenciesOutput("all", response.getBody());
41 | }
42 |
43 | @Test
44 | void dependenciesSpecificVersion() throws JSONException {
45 | ResponseEntity response = execute(
46 | "/ui/dependencies?version=1.1.2.RELEASE", String.class, null);
47 | validateContentType(response, MediaType.APPLICATION_JSON);
48 | validateDependenciesOutput("1.1.2", response.getBody());
49 | }
50 |
51 | protected void validateDependenciesOutput(String version, String actual)
52 | throws JSONException {
53 | JSONObject expected = readJsonFrom(
54 | "metadata/ui/test-dependencies-" + version + ".json");
55 | JSONAssert.assertEquals(expected, new JSONObject(actual), JSONCompareMode.STRICT);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/java/io/spring/initializr/metadata/TextCapabilityTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | import static org.assertj.core.api.Assertions.assertThat;
22 |
23 | /**
24 | * @author Stephane Nicoll
25 | */
26 | class TextCapabilityTests {
27 |
28 | @Test
29 | void mergeValue() {
30 | TextCapability capability = new TextCapability("foo");
31 | capability.setContent("1234");
32 | TextCapability another = new TextCapability("foo");
33 | another.setContent("4567");
34 | capability.merge(another);
35 | assertThat(capability.getId()).isEqualTo("foo");
36 | assertThat(capability.getType()).isEqualTo(ServiceCapabilityType.TEXT);
37 | assertThat(capability.getContent()).isEqualTo("4567");
38 | }
39 |
40 | @Test
41 | void mergeTitle() {
42 | TextCapability capability = new TextCapability("foo", "Foo", "my desc");
43 | capability.merge(new TextCapability("foo", "AnotherFoo", ""));
44 | assertThat(capability.getId()).isEqualTo("foo");
45 | assertThat(capability.getType()).isEqualTo(ServiceCapabilityType.TEXT);
46 | assertThat(capability.getTitle()).isEqualTo("AnotherFoo");
47 | assertThat(capability.getDescription()).isEqualTo("my desc");
48 | }
49 |
50 | @Test
51 | void mergeDescription() {
52 | TextCapability capability = new TextCapability("foo", "Foo", "my desc");
53 | capability.merge(new TextCapability("foo", "", "another desc"));
54 | assertThat(capability.getId()).isEqualTo("foo");
55 | assertThat(capability.getType()).isEqualTo(ServiceCapabilityType.TEXT);
56 | assertThat(capability.getTitle()).isEqualTo("Foo");
57 | assertThat(capability.getDescription()).isEqualTo("another desc");
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/groovy/standard/war-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | war
15 | demo
16 | Demo project for Spring Boot
17 |
18 |
19 | 1.8
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-web
26 |
27 |
28 | org.codehaus.groovy
29 | groovy
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-tomcat
35 | provided
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-test
40 | test
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-maven-plugin
49 |
50 |
51 | org.codehaus.gmavenplus
52 | gmavenplus-plugin
53 | 1.5
54 |
55 |
56 |
57 | addSources
58 | addTestSources
59 | generateStubs
60 | compile
61 | testGenerateStubs
62 | testCompile
63 | removeStubs
64 | removeTestStubs
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/initializr-actuator/src/test/java/io/spring/initializr/actuate/autoconfigure/InitializrActuatorEndpointsAutoConfigurationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.actuate.autoconfigure;
18 |
19 | import io.spring.initializr.actuate.info.BomRangesInfoContributor;
20 | import io.spring.initializr.actuate.info.DependencyRangesInfoContributor;
21 | import io.spring.initializr.web.autoconfigure.InitializrAutoConfiguration;
22 | import org.junit.jupiter.api.Test;
23 |
24 | import org.springframework.boot.autoconfigure.AutoConfigurations;
25 | import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
26 | import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
27 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
28 |
29 | import static org.assertj.core.api.Assertions.assertThat;
30 |
31 | /**
32 | * Tests for {@link InitializrActuatorEndpointsAutoConfiguration}.
33 | *
34 | * @author Madhura Bhave
35 | */
36 | class InitializrActuatorEndpointsAutoConfigurationTests {
37 |
38 | private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
39 | .withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class,
40 | InitializrAutoConfiguration.class,
41 | RestTemplateAutoConfiguration.class,
42 | InitializrActuatorEndpointsAutoConfiguration.class));
43 |
44 | @Test
45 | void autoConfigRegistersBomRangesInfoContributor() {
46 | this.contextRunner.run((context) -> assertThat(context)
47 | .hasSingleBean(BomRangesInfoContributor.class));
48 | }
49 |
50 | @Test
51 | void autoConfigRegistersDependencyRangesInfoContributor() {
52 | this.contextRunner.run((context) -> assertThat(context)
53 | .hasSingleBean(DependencyRangesInfoContributor.class));
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/initializr-actuator/src/test/java/io/spring/initializr/actuate/autoconfigure/InitializrMetricsAutoConfigurationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.actuate.autoconfigure;
18 |
19 | import io.micrometer.core.instrument.MeterRegistry;
20 | import io.spring.initializr.actuate.metric.ProjectGenerationMetricsListener;
21 | import org.junit.jupiter.api.Test;
22 |
23 | import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
24 | import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
25 | import org.springframework.boot.autoconfigure.AutoConfigurations;
26 | import org.springframework.boot.test.context.FilteredClassLoader;
27 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
28 |
29 | import static org.assertj.core.api.Assertions.assertThat;
30 |
31 | /**
32 | * Tests for {@link InitializrMetricsAutoConfiguration}.
33 | *
34 | * @author Madhura Bhave
35 | */
36 | class InitializrMetricsAutoConfigurationTests {
37 |
38 | private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
39 | .withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class,
40 | CompositeMeterRegistryAutoConfiguration.class,
41 | InitializrMetricsAutoConfiguration.class));
42 |
43 | @Test
44 | void autoConfigRegistersProjectGenerationMetricsListenerBean() {
45 | this.contextRunner.run((context) -> assertThat(context)
46 | .hasSingleBean(ProjectGenerationMetricsListener.class));
47 | }
48 |
49 | @Test
50 | void autoConfigConditionalOnMeterRegistryClass() {
51 | this.contextRunner.withClassLoader(new FilteredClassLoader(MeterRegistry.class))
52 | .run((context) -> assertThat(context)
53 | .doesNotHaveBean(ProjectGenerationMetricsListener.class));
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.adoc:
--------------------------------------------------------------------------------
1 | = Contributor Code of Conduct
2 |
3 | As contributors and maintainers of this project, and in the interest of fostering an open
4 | and welcoming community, we pledge to respect all people who contribute through reporting
5 | issues, posting feature requests, updating documentation, submitting pull requests or
6 | patches, and other activities.
7 |
8 | We are committed to making participation in this project a harassment-free experience for
9 | everyone, regardless of level of experience, gender, gender identity and expression,
10 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age,
11 | religion, or nationality.
12 |
13 | Examples of unacceptable behavior by participants include:
14 |
15 | * The use of sexualized language or imagery
16 | * Personal attacks
17 | * Trolling or insulting/derogatory comments
18 | * Public or private harassment
19 | * Publishing other's private information, such as physical or electronic addresses,
20 | without explicit permission
21 | * Other unethical or unprofessional conduct
22 |
23 | Project maintainers have the right and responsibility to remove, edit, or reject comments,
24 | commits, code, wiki edits, issues, and other contributions that are not aligned to this
25 | Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors
26 | that they deem inappropriate, threatening, offensive, or harmful.
27 |
28 | By adopting this Code of Conduct, project maintainers commit themselves to fairly and
29 | consistently applying these principles to every aspect of managing this project. Project
30 | maintainers who do not follow or enforce the Code of Conduct may be permanently removed
31 | from the project team.
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an
34 | individual is representing the project or its community.
35 |
36 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
37 | contacting a project maintainer at spring-code-of-conduct@pivotal.io . All complaints will
38 | be reviewed and investigated and will result in a response that is deemed necessary and
39 | appropriate to the circumstances. Maintainers are obligated to maintain confidentiality
40 | with regard to the reporter of an incident.
41 |
42 | This Code of Conduct is adapted from the
43 | http://contributor-covenant.org[Contributor Covenant], version 1.3.0, available at
44 | http://contributor-covenant.org/version/1/3/0/[contributor-covenant.org/version/1/3/0/]
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/kotlin/standard/pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 | 1.1.1
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter
26 |
27 |
28 | org.jetbrains.kotlin
29 | kotlin-reflect
30 |
31 |
32 | org.jetbrains.kotlin
33 | kotlin-stdlib-jdk8
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-test
39 | test
40 |
41 |
42 |
43 |
44 | ${project.basedir}/src/main/kotlin
45 | ${project.basedir}/src/test/kotlin
46 |
47 |
48 | org.springframework.boot
49 | spring-boot-maven-plugin
50 |
51 |
52 | org.jetbrains.kotlin
53 | kotlin-maven-plugin
54 |
55 |
56 | -Xjsr305=strict
57 |
58 |
59 | spring
60 |
61 |
62 |
63 |
64 | org.jetbrains.kotlin
65 | kotlin-maven-allopen
66 | ${kotlin.version}
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/maven/kotlin-java11-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | demo
15 | Demo project for Spring Boot
16 |
17 |
18 | 11
19 | 1.1.1
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter
26 |
27 |
28 | org.jetbrains.kotlin
29 | kotlin-reflect
30 |
31 |
32 | org.jetbrains.kotlin
33 | kotlin-stdlib-jdk8
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-test
39 | test
40 |
41 |
42 |
43 |
44 | ${project.basedir}/src/main/kotlin
45 | ${project.basedir}/src/test/kotlin
46 |
47 |
48 | org.springframework.boot
49 | spring-boot-maven-plugin
50 |
51 |
52 | org.jetbrains.kotlin
53 | kotlin-maven-plugin
54 |
55 |
56 | -Xjsr305=strict
57 |
58 |
59 | spring
60 |
61 |
62 |
63 |
64 | org.jetbrains.kotlin
65 | kotlin-maven-allopen
66 | ${kotlin.version}
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/generator/ProjectResourceLocator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.generator;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 | import java.net.URL;
22 | import java.nio.charset.Charset;
23 |
24 | import org.springframework.cache.annotation.Cacheable;
25 | import org.springframework.util.ResourceUtils;
26 | import org.springframework.util.StreamUtils;
27 |
28 | /**
29 | * Locate project resources.
30 | *
31 | * @author Stephane Nicoll
32 | */
33 | public class ProjectResourceLocator {
34 |
35 | private static final Charset UTF_8 = Charset.forName("UTF-8");
36 |
37 | /**
38 | * Return the binary content of the resource at the specified location.
39 | * @param location a resource location
40 | * @return the content of the resource
41 | */
42 | @Cacheable("initializr.project-resources")
43 | public byte[] getBinaryResource(String location) {
44 | try (InputStream stream = getInputStream(location)) {
45 | return StreamUtils.copyToByteArray(stream);
46 | }
47 | catch (IOException ex) {
48 | throw new IllegalStateException("Cannot get resource", ex);
49 | }
50 | }
51 |
52 | /**
53 | * Return the textual content of the resource at the specified location.
54 | * @param location a resource location
55 | * @return the content of the resource
56 | */
57 | @Cacheable("initializr.project-resources")
58 | public String getTextResource(String location) {
59 | try (InputStream stream = getInputStream(location)) {
60 | return StreamUtils.copyToString(stream, UTF_8);
61 | }
62 | catch (IOException ex) {
63 | throw new IllegalStateException("Cannot get resource", ex);
64 | }
65 | }
66 |
67 | private InputStream getInputStream(String location) throws IOException {
68 | URL url = ResourceUtils.getURL(location);
69 | return url.openStream();
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/initializr-generator/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | io.spring.initializr
6 | initializr
7 | ${revision}
8 |
9 | initializr-generator
10 | Spring Initializr :: Generator
11 |
12 |
13 | ${basedir}/..
14 |
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot
20 |
21 |
22 |
23 | org.slf4j
24 | slf4j-api
25 |
26 |
27 | com.samskivert
28 | jmustache
29 |
30 |
31 | com.fasterxml.jackson.core
32 | jackson-databind
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-configuration-processor
38 | true
39 |
40 |
41 |
42 | org.junit.jupiter
43 | junit-jupiter
44 | test
45 |
46 |
47 | org.assertj
48 | assertj-core
49 | test
50 |
51 |
52 | org.mockito
53 | mockito-junit-jupiter
54 | test
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-starter
59 | test
60 |
61 |
62 | xmlunit
63 | xmlunit
64 | test
65 |
66 |
67 |
68 |
69 |
70 |
71 | org.apache.maven.plugins
72 | maven-jar-plugin
73 |
74 |
75 |
76 | test-jar
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/generator/ProjectRequestPostProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.generator;
18 |
19 | import io.spring.initializr.metadata.InitializrMetadata;
20 |
21 | /**
22 | * Project generation hook that allows for custom modification of {@link ProjectRequest}
23 | * instances, e.g. adding custom dependencies or forcing certain settings based on custom
24 | * logic.
25 | *
26 | * @author Stephane Nicoll
27 | */
28 | public interface ProjectRequestPostProcessor {
29 |
30 | /**
31 | * Apply this post processor to the given {@code ProjectRequest} before it gets
32 | * resolved against the specified {@code InitializrMetadata}.
33 | *
34 | * Consider using this hook to customize basic settings of the {@code request}; for
35 | * more advanced logic (in particular with regards to dependencies), consider using
36 | * {@code postProcessAfterResolution}.
37 | * @param request an unresolved {@link ProjectRequest}
38 | * @param metadata the metadata to use to resolve this request
39 | * @see ProjectRequest#resolve(InitializrMetadata)
40 | */
41 | default void postProcessBeforeResolution(ProjectRequest request,
42 | InitializrMetadata metadata) {
43 | }
44 |
45 | /**
46 | * Apply this post processor to the given {@code ProjectRequest} after it has
47 | * been resolved against the specified {@code InitializrMetadata}.
48 | *
49 | * Dependencies, repositories, bills of materials, default properties and others
50 | * aspects of the request will have been resolved prior to invocation. In particular,
51 | * note that no further validation checks will be performed.
52 | * @param request an resolved {@code ProjectRequest}
53 | * @param metadata the metadata that were used to resolve this request
54 | */
55 | default void postProcessAfterResolution(ProjectRequest request,
56 | InitializrMetadata metadata) {
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerEnvIntegrationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.project;
18 |
19 | import java.net.URI;
20 |
21 | import io.spring.initializr.test.generator.ProjectAssert;
22 | import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
23 | import org.junit.jupiter.api.Test;
24 |
25 | import org.springframework.http.HttpStatus;
26 | import org.springframework.http.ResponseEntity;
27 | import org.springframework.test.context.ActiveProfiles;
28 |
29 | import static org.assertj.core.api.Assertions.assertThat;
30 |
31 | /**
32 | * Integration tests with custom environment.
33 | *
34 | * @author Stephane Nicoll
35 | */
36 | @ActiveProfiles({ "test-default", "test-custom-env" })
37 | class MainControllerEnvIntegrationTests
38 | extends AbstractInitializrControllerIntegrationTests {
39 |
40 | @Test
41 | void downloadCliWithCustomRepository() throws Exception {
42 | ResponseEntity> entity = getRestTemplate().getForEntity(createUrl("/spring"),
43 | String.class);
44 | assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
45 | String expected = "https://repo.spring.io/lib-release/org/springframework/boot/spring-boot-cli/2.1.4.RELEASE/spring-boot-cli-2.1.4.RELEASE-bin.zip";
46 | assertThat(entity.getHeaders().getLocation()).isEqualTo(new URI(expected));
47 | }
48 |
49 | @Test
50 | void generateProjectWithInvalidName() {
51 | downloadZip("/starter.zip?style=data-jpa&name=Invalid")
52 | .isJavaProject(ProjectAssert.DEFAULT_PACKAGE_NAME, "FooBarApplication")
53 | .isMavenProject().hasStaticAndTemplatesResources(false).pomAssert()
54 | .hasDependenciesCount(2).hasSpringBootStarterDependency("data-jpa")
55 | .hasSpringBootStarterTest();
56 | }
57 |
58 | @Test
59 | void googleAnalytics() {
60 | String body = htmlHome();
61 | assertThat(body).contains("https://www.googletagmanager.com/gtm.js");
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/java/io/spring/initializr/metadata/SingleSelectCapabilityTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | import static org.assertj.core.api.Assertions.assertThat;
22 |
23 | /**
24 | * @author Stephane Nicoll
25 | */
26 | class SingleSelectCapabilityTests {
27 |
28 | @Test
29 | void defaultEmpty() {
30 | SingleSelectCapability capability = new SingleSelectCapability("test");
31 | assertThat(capability.getDefault()).isNull();
32 | }
33 |
34 | @Test
35 | void defaultNoDefault() {
36 | SingleSelectCapability capability = new SingleSelectCapability("test");
37 | capability.getContent().add(DefaultMetadataElement.create("foo", false));
38 | capability.getContent().add(DefaultMetadataElement.create("bar", false));
39 | assertThat(capability.getDefault()).isNull();
40 | }
41 |
42 | @Test
43 | void defaultType() {
44 | SingleSelectCapability capability = new SingleSelectCapability("test");
45 | capability.getContent().add(DefaultMetadataElement.create("foo", false));
46 | DefaultMetadataElement second = DefaultMetadataElement.create("bar", true);
47 | capability.getContent().add(second);
48 | assertThat(capability.getDefault()).isEqualTo(second);
49 | }
50 |
51 | @Test
52 | void mergeAddEntry() {
53 | SingleSelectCapability capability = new SingleSelectCapability("test");
54 | DefaultMetadataElement foo = DefaultMetadataElement.create("foo", false);
55 | capability.getContent().add(foo);
56 |
57 | SingleSelectCapability anotherCapability = new SingleSelectCapability("test");
58 | DefaultMetadataElement bar = DefaultMetadataElement.create("bar", false);
59 | anotherCapability.getContent().add(bar);
60 |
61 | capability.merge(anotherCapability);
62 | assertThat(capability.getContent()).hasSize(2);
63 | assertThat(capability.get("foo")).isEqualTo(foo);
64 | assertThat(capability.get("bar")).isEqualTo(bar);
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/resources/project/gradle3/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/resources/project/gradle4/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/initializr-generator/src/main/java/io/spring/initializr/metadata/SingleSelectCapability.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | import java.util.List;
20 | import java.util.concurrent.CopyOnWriteArrayList;
21 |
22 | import com.fasterxml.jackson.annotation.JsonCreator;
23 | import com.fasterxml.jackson.annotation.JsonProperty;
24 |
25 | /**
26 | * A {@link ServiceCapabilityType#SINGLE_SELECT single select} capability.
27 | *
28 | * @author Stephane Nicoll
29 | */
30 | public class SingleSelectCapability
31 | extends ServiceCapability>
32 | implements Defaultable {
33 |
34 | private final List content = new CopyOnWriteArrayList<>();
35 |
36 | @JsonCreator
37 | SingleSelectCapability(@JsonProperty("id") String id) {
38 | this(id, null, null);
39 | }
40 |
41 | public SingleSelectCapability(String id, String title, String description) {
42 | super(id, ServiceCapabilityType.SINGLE_SELECT, title, description);
43 | }
44 |
45 | @Override
46 | public List getContent() {
47 | return this.content;
48 | }
49 |
50 | /**
51 | * Return the default element of this capability.
52 | */
53 | @Override
54 | public DefaultMetadataElement getDefault() {
55 | return this.content.stream().filter(DefaultMetadataElement::isDefault).findFirst()
56 | .orElse(null);
57 | }
58 |
59 | /**
60 | * Return the element with the specified id or {@code null} if no such element exists.
61 | * @param id the ID of the element to find
62 | * @return the element or {@code null}
63 | */
64 | public DefaultMetadataElement get(String id) {
65 | return this.content.stream().filter((it) -> id.equals(it.getId())).findFirst()
66 | .orElse(null);
67 | }
68 |
69 | @Override
70 | public void merge(List otherContent) {
71 | otherContent.forEach((it) -> {
72 | if (get(it.getId()) == null) {
73 | this.content.add(it);
74 | }
75 | });
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerDependenciesTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.project;
18 |
19 | import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
20 | import org.json.JSONException;
21 | import org.json.JSONObject;
22 | import org.junit.jupiter.api.Test;
23 | import org.skyscreamer.jsonassert.JSONAssert;
24 | import org.skyscreamer.jsonassert.JSONCompareMode;
25 |
26 | import org.springframework.http.HttpHeaders;
27 | import org.springframework.http.ResponseEntity;
28 | import org.springframework.test.context.ActiveProfiles;
29 |
30 | import static org.assertj.core.api.Assertions.assertThat;
31 |
32 | /**
33 | * @author Stephane Nicoll
34 | */
35 | @ActiveProfiles("test-default")
36 | class MainControllerDependenciesTests
37 | extends AbstractInitializrControllerIntegrationTests {
38 |
39 | @Test
40 | void noBootVersion() throws JSONException {
41 | ResponseEntity response = execute("/dependencies", String.class, null,
42 | "application/json");
43 | assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
44 | validateContentType(response, CURRENT_METADATA_MEDIA_TYPE);
45 | validateDependenciesOutput("2.1.4", response.getBody());
46 | }
47 |
48 | @Test
49 | void filteredDependencies() throws JSONException {
50 | ResponseEntity response = execute(
51 | "/dependencies?bootVersion=2.2.1.RELEASE", String.class, null,
52 | "application/json");
53 | assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
54 | validateContentType(response, CURRENT_METADATA_MEDIA_TYPE);
55 | validateDependenciesOutput("2.2.1", response.getBody());
56 | }
57 |
58 | protected void validateDependenciesOutput(String version, String actual)
59 | throws JSONException {
60 | JSONObject expected = readJsonFrom(
61 | "metadata/dependencies/test-dependencies-" + version + ".json");
62 | JSONAssert.assertEquals(expected, new JSONObject(actual), JSONCompareMode.STRICT);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/resources/project/kotlin/standard/war-pom.xml.gen:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.example
12 | demo
13 | 0.0.1-SNAPSHOT
14 | war
15 | demo
16 | Demo project for Spring Boot
17 |
18 |
19 | 1.8
20 | 1.1.1
21 |
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-web
27 |
28 |
29 | org.jetbrains.kotlin
30 | kotlin-reflect
31 |
32 |
33 | org.jetbrains.kotlin
34 | kotlin-stdlib-jdk8
35 |
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-tomcat
40 | provided
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-starter-test
45 | test
46 |
47 |
48 |
49 |
50 | ${project.basedir}/src/main/kotlin
51 | ${project.basedir}/src/test/kotlin
52 |
53 |
54 | org.springframework.boot
55 | spring-boot-maven-plugin
56 |
57 |
58 | org.jetbrains.kotlin
59 | kotlin-maven-plugin
60 |
61 |
62 | -Xjsr305=strict
63 |
64 |
65 | spring
66 |
67 |
68 |
69 |
70 | org.jetbrains.kotlin
71 | kotlin-maven-allopen
72 | ${kotlin.version}
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/java/io/spring/initializr/test/generator/SourceCodeAssert.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.test.generator;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 | import java.nio.charset.Charset;
22 |
23 | import org.springframework.core.io.Resource;
24 | import org.springframework.util.StreamUtils;
25 |
26 | import static org.assertj.core.api.Assertions.assertThat;
27 |
28 | /**
29 | * Source code assertions.
30 | *
31 | * @author Stephane Nicoll
32 | */
33 | public class SourceCodeAssert {
34 |
35 | private final String name;
36 |
37 | private final String content;
38 |
39 | public SourceCodeAssert(String name, String content) {
40 | this.name = name;
41 | this.content = content.replaceAll("\r\n", "\n");
42 | }
43 |
44 | public SourceCodeAssert equalsTo(Resource expected) {
45 | try (InputStream stream = expected.getInputStream()) {
46 | String expectedContent = StreamUtils.copyToString(stream,
47 | Charset.forName("UTF-8"));
48 | assertThat(this.content).describedAs("Content for %s", this.name)
49 | .isEqualTo(expectedContent.replaceAll("\r\n", "\n"));
50 | }
51 | catch (IOException ex) {
52 | throw new IllegalStateException("Cannot read file", ex);
53 | }
54 | return this;
55 | }
56 |
57 | public SourceCodeAssert hasImports(String... classNames) {
58 | for (String className : classNames) {
59 | contains("import " + className);
60 | }
61 | return this;
62 | }
63 |
64 | public SourceCodeAssert doesNotHaveImports(String... classNames) {
65 | for (String className : classNames) {
66 | doesNotContain("import " + className);
67 | }
68 | return this;
69 | }
70 |
71 | public SourceCodeAssert contains(String... expressions) {
72 | assertThat(this.content).describedAs("Content for %s", this.name)
73 | .contains(expressions);
74 | return this;
75 | }
76 |
77 | public SourceCodeAssert doesNotContain(String... expressions) {
78 | assertThat(this.content).describedAs("Content for %s", this.name)
79 | .doesNotContain(expressions);
80 | return this;
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/initializr-web/src/main/java/io/spring/initializr/web/support/SpringBootMetadataReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.support;
18 |
19 | import java.io.IOException;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | import com.fasterxml.jackson.databind.JsonNode;
24 | import com.fasterxml.jackson.databind.ObjectMapper;
25 | import com.fasterxml.jackson.databind.node.ArrayNode;
26 | import io.spring.initializr.metadata.DefaultMetadataElement;
27 |
28 | import org.springframework.web.client.RestTemplate;
29 |
30 | /**
31 | * Reads metadata from the main spring.io website. This is a stateful service: create a
32 | * new instance whenever you need to refresh the content.
33 | *
34 | * @author Stephane Nicoll
35 | */
36 | public class SpringBootMetadataReader {
37 |
38 | private final JsonNode content;
39 |
40 | /**
41 | * Parse the content of the metadata at the specified url.
42 | * @param objectMapper the object mapper
43 | * @param restTemplate the rest template
44 | * @param url the metadata URL
45 | * @throws IOException on load error
46 | */
47 | public SpringBootMetadataReader(ObjectMapper objectMapper, RestTemplate restTemplate,
48 | String url) throws IOException {
49 | this.content = objectMapper
50 | .readTree(restTemplate.getForObject(url, String.class));
51 | }
52 |
53 | /**
54 | * Return the boot versions parsed by this instance.
55 | * @return the versions
56 | */
57 | public List getBootVersions() {
58 | ArrayNode releases = (ArrayNode) this.content.get("projectReleases");
59 | List list = new ArrayList<>();
60 | for (JsonNode node : releases) {
61 | DefaultMetadataElement version = new DefaultMetadataElement();
62 | version.setId(node.get("version").textValue());
63 | String name = node.get("versionDisplayName").textValue();
64 | version.setName(
65 | node.get("snapshot").booleanValue() ? name + " (SNAPSHOT)" : name);
66 | version.setDefault(node.get("current").booleanValue());
67 | list.add(version);
68 | }
69 | return list;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/initializr-web/src/main/java/io/spring/initializr/web/mapper/LinkMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.mapper;
18 |
19 | import java.util.ArrayList;
20 | import java.util.LinkedHashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | import com.fasterxml.jackson.databind.node.ArrayNode;
25 | import com.fasterxml.jackson.databind.node.JsonNodeFactory;
26 | import com.fasterxml.jackson.databind.node.ObjectNode;
27 | import io.spring.initializr.metadata.Link;
28 |
29 | /**
30 | * Generate a json representation for {@link Link}.
31 | *
32 | * @author Stephane Nicoll
33 | */
34 | public final class LinkMapper {
35 |
36 | private static final JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
37 |
38 | private LinkMapper() {
39 | }
40 |
41 | /**
42 | * Map the specified links to a json model. If several links share the same relation,
43 | * they are grouped together.
44 | * @param links the links to map
45 | * @return a model for the specified links
46 | */
47 | public static ObjectNode mapLinks(List links) {
48 | ObjectNode result = nodeFactory.objectNode();
49 | Map> byRel = new LinkedHashMap<>();
50 | links.forEach((it) -> byRel.computeIfAbsent(it.getRel(), (k) -> new ArrayList<>())
51 | .add(it));
52 | byRel.forEach((rel, l) -> {
53 | if (l.size() == 1) {
54 | ObjectNode root = JsonNodeFactory.instance.objectNode();
55 | mapLink(l.get(0), root);
56 | result.set(rel, root);
57 | }
58 | else {
59 | ArrayNode root = JsonNodeFactory.instance.arrayNode();
60 | l.forEach((link) -> {
61 | ObjectNode node = JsonNodeFactory.instance.objectNode();
62 | mapLink(link, node);
63 | root.add(node);
64 | });
65 | result.set(rel, root);
66 | }
67 | });
68 | return result;
69 | }
70 |
71 | private static void mapLink(Link link, ObjectNode node) {
72 | node.put("href", link.getHref());
73 | if (link.isTemplated()) {
74 | node.put("templated", true);
75 | }
76 | if (link.getDescription() != null) {
77 | node.put("title", link.getDescription());
78 | }
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/initializr-web/src/test/java/io/spring/initializr/web/project/ProjectGenerationPostProcessorTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.project;
18 |
19 | import io.spring.initializr.generator.ProjectRequest;
20 | import io.spring.initializr.generator.ProjectRequestPostProcessor;
21 | import io.spring.initializr.metadata.InitializrMetadata;
22 | import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
23 | import io.spring.initializr.web.project.ProjectGenerationPostProcessorTests.ProjectRequestPostProcessorConfiguration;
24 | import org.junit.jupiter.api.Test;
25 |
26 | import org.springframework.context.annotation.Bean;
27 | import org.springframework.context.annotation.Configuration;
28 | import org.springframework.context.annotation.Import;
29 | import org.springframework.core.annotation.Order;
30 | import org.springframework.test.context.ActiveProfiles;
31 |
32 | @ActiveProfiles("test-default")
33 | @Import(ProjectRequestPostProcessorConfiguration.class)
34 | class ProjectGenerationPostProcessorTests
35 | extends AbstractInitializrControllerIntegrationTests {
36 |
37 | @Test
38 | void postProcessorsInvoked() {
39 | downloadZip("/starter.zip?bootVersion=2.0.4.RELEASE&javaVersion=1.8")
40 | .isJavaProject().isMavenProject().pomAssert()
41 | .hasSpringBootParent("2.2.3.RELEASE").hasProperty("java.version", "1.7");
42 | }
43 |
44 | @Configuration
45 | static class ProjectRequestPostProcessorConfiguration {
46 |
47 | @Bean
48 | @Order(2)
49 | ProjectRequestPostProcessor secondPostProcessor() {
50 | return new ProjectRequestPostProcessor() {
51 | @Override
52 | public void postProcessBeforeResolution(ProjectRequest request,
53 | InitializrMetadata metadata) {
54 | request.setJavaVersion("1.7");
55 | }
56 | };
57 | }
58 |
59 | @Bean
60 | @Order(1)
61 | ProjectRequestPostProcessor firstPostProcessor() {
62 | return new ProjectRequestPostProcessor() {
63 | @Override
64 | public void postProcessBeforeResolution(ProjectRequest request,
65 | InitializrMetadata metadata) {
66 | request.setJavaVersion("1.2");
67 | request.setBootVersion("2.2.3.RELEASE");
68 | }
69 | };
70 | }
71 |
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/initializr-web/src/test/java/io/spring/initializr/web/mapper/DependencyMetadataJsonMapperTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.web.mapper;
18 |
19 | import java.net.URL;
20 | import java.util.Collections;
21 |
22 | import io.spring.initializr.metadata.BillOfMaterials;
23 | import io.spring.initializr.metadata.Dependency;
24 | import io.spring.initializr.metadata.DependencyMetadata;
25 | import io.spring.initializr.metadata.Repository;
26 | import io.spring.initializr.util.Version;
27 | import org.json.JSONObject;
28 | import org.junit.jupiter.api.Test;
29 |
30 | import static org.assertj.core.api.Assertions.assertThat;
31 |
32 | /**
33 | * @author Stephane Nicoll
34 | */
35 | class DependencyMetadataJsonMapperTests {
36 |
37 | private final DependencyMetadataJsonMapper mapper = new DependencyMetadataV21JsonMapper();
38 |
39 | @Test
40 | void mapDependency() throws Exception {
41 | Dependency d = Dependency.withId("foo", "org.foo", "foo");
42 | d.setRepository("my-repo");
43 | d.setBom("my-bom");
44 | Repository repository = new Repository();
45 | repository.setName("foo-repo");
46 | repository.setUrl(new URL("http://example.com/foo"));
47 | BillOfMaterials bom = BillOfMaterials.create("org.foo", "foo-bom",
48 | "1.0.0.RELEASE");
49 | DependencyMetadata metadata = new DependencyMetadata(
50 | Version.parse("1.2.0.RELEASE"), Collections.singletonMap(d.getId(), d),
51 | Collections.singletonMap("repo-id", repository),
52 | Collections.singletonMap("bom-id", bom));
53 | JSONObject content = new JSONObject(this.mapper.write(metadata));
54 | assertThat(content.getJSONObject("dependencies").getJSONObject("foo")
55 | .getString("bom")).isEqualTo("my-bom");
56 | assertThat(content.getJSONObject("dependencies").getJSONObject("foo")
57 | .getString("repository")).isEqualTo("my-repo");
58 | assertThat(content.getJSONObject("repositories").getJSONObject("repo-id")
59 | .getString("name")).isEqualTo("foo-repo");
60 | assertThat(content.getJSONObject("boms").getJSONObject("bom-id")
61 | .getString("artifactId")).isEqualTo("foo-bom");
62 | assertThat(content.getJSONObject("boms").getJSONObject("bom-id")
63 | .getString("version")).isEqualTo("1.0.0.RELEASE");
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/initializr-generator/src/test/java/io/spring/initializr/metadata/TypeCapabilityTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.spring.initializr.metadata;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | import static org.assertj.core.api.Assertions.assertThat;
22 |
23 | /**
24 | * @author Stephane Nicoll
25 | */
26 | class TypeCapabilityTests {
27 |
28 | @Test
29 | void defaultEmpty() {
30 | TypeCapability capability = new TypeCapability();
31 | assertThat(capability.getDefault()).isNull();
32 | }
33 |
34 | @Test
35 | void defaultNoDefault() {
36 | TypeCapability capability = new TypeCapability();
37 | Type first = new Type();
38 | first.setId("foo");
39 | first.setDefault(false);
40 | Type second = new Type();
41 | second.setId("bar");
42 | second.setDefault(false);
43 | capability.getContent().add(first);
44 | capability.getContent().add(second);
45 | assertThat(capability.getDefault()).isNull();
46 | }
47 |
48 | @Test
49 | void defaultType() {
50 | TypeCapability capability = new TypeCapability();
51 | Type first = new Type();
52 | first.setId("foo");
53 | first.setDefault(false);
54 | Type second = new Type();
55 | second.setId("bar");
56 | second.setDefault(true);
57 | capability.getContent().add(first);
58 | capability.getContent().add(second);
59 | assertThat(capability.getDefault()).isEqualTo(second);
60 | }
61 |
62 | @Test
63 | void mergeAddEntry() {
64 | TypeCapability capability = new TypeCapability();
65 | Type first = new Type();
66 | first.setId("foo");
67 | first.setDefault(false);
68 | capability.getContent().add(first);
69 |
70 | TypeCapability anotherCapability = new TypeCapability();
71 | Type another = new Type();
72 | another.setId("foo");
73 | another.setDefault(false);
74 | Type second = new Type();
75 | second.setId("bar");
76 | second.setDefault(true);
77 | anotherCapability.getContent().add(another);
78 | anotherCapability.getContent().add(second);
79 |
80 | capability.merge(anotherCapability);
81 | assertThat(capability.getContent()).hasSize(2);
82 | assertThat(capability.get("foo")).isEqualTo(first);
83 | assertThat(capability.get("bar")).isEqualTo(second);
84 | assertThat(capability.getDefault()).isEqualTo(second);
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------