Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add customFields to InitializrConfiguration #1580

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ public void validate() {
this.env.validate();
}

/**
* The customFields feature in Spring Initializr enables additional, adaptable
* metadata beyond the standard fields. This allows organizations to set
* environment-specific values like default configurations, dependencies, version
* control, or deployment options—aligning generated projects directly with their
* standards. By using customFields, organizations can add new metadata flexibly
* without altering core configurations, making Initializr more adaptable and valuable
* for various use cases.
*/
private Map<String, Object> customFields = Collections.emptyMap();

public Map<String, Object> getCustomFields() {
return this.customFields;
}

public void setCustomFields(Map<String, Object> customFields) {
this.customFields = customFields;
}

public void merge(InitializrConfiguration other) {
this.env.merge(other.env);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.initializr.web.controller;

import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;

/**
* Integration tests for {@link ProjectMetadataController} on a real http server.
*
* @author Joar Varpe
*/
@ActiveProfiles("test-custom-fields")
class ProjectMetadataControllerCustomFieldsIntegrationTests extends AbstractFullStackInitializrIntegrationTests {

@Test
void validateJson() throws JSONException {
ResponseEntity<String> response = execute("/metadata/config", String.class, null, "application/json");
validateContentType(response, MediaType.APPLICATION_JSON);
JSONObject json = new JSONObject(response.getBody());
JSONObject expected = readJsonFrom("metadata/config/test-custom-fields.json");
JSONAssert.assertEquals(expected, json, JSONCompareMode.STRICT);
}

}
173 changes: 173 additions & 0 deletions initializr-web/src/test/resources/application-test-custom-fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
info:
spring-boot:
version: 2.4.4

initializr:
customFields:
exampleField1: "Example String Value"
exampleField2: 123
exampleField3: true
nestedField:
nestedKey1: "Nested value"
nestedKey2: 42
env:
boms:
my-api-bom:
groupId: org.acme
artifactId: my-api-bom
versionProperty: my-api.version
additionalBoms: ['my-api-dependencies-bom']
mappings:
- compatibilityRange: "[2.3.0.RELEASE,2.4.6)"
version: 1.0.0.RELEASE
repositories: my-api-repo-1
- compatibilityRange: "2.4.6"
version: 2.0.0.RELEASE
repositories: my-api-repo-2
my-api-dependencies-bom:
groupId: org.acme
artifactId: my-api-dependencies-bom
version: 1.0.0.RELEASE
repositories: my-api-repo-3
kotlin:
defaultVersion: 1.5
mappings:
- compatibilityRange: "[2.3.0.RELEASE,2.4.0-M1)"
version: 1.3.72
- compatibilityRange: "[2.4.0-M1,2.5.0-M1)"
version: 1.4.31
repositories:
my-api-repo-1:
name: repo1
url: https://example.com/repo1
my-api-repo-2:
name: repo2
url: https://example.com/repo2
my-api-repo-3:
name: repo3
url: https://example.com/repo3
dependencies:
- name: Core
content:
- name: Web
id: web
description: Web dependency description
facets:
- web
links:
- rel: guide
href: https://example.com/guide
description: Building a RESTful Web Service
- rel: reference
href: https://example.com/doc
- name: Security
id: security
- name: Data JPA
id: data-jpa
aliases:
- jpa
- name: Other
content:
- name: Foo
groupId: org.acme
artifactId: foo
version: 1.3.5
weight: 42
keywords:
- thefoo
- dafoo
links:
- rel: guide
href: https://example.com/guide1
- rel: reference
href: https://example.com/{bootVersion}/doc
- rel: guide
href: https://example.com/guide2
description: Some guide for foo
- name: Bar
id: org.acme:bar
version: 2.1.0
- name: Biz
groupId: org.acme
artifactId: biz
scope: runtime
version: 1.3.5
compatibilityRange: 2.6.0-SNAPSHOT
- name: Bur
id: org.acme:bur
version: 2.1.0
scope: test
compatibilityRange: "[2.4.4,2.5.0-SNAPSHOT)"
- name: My API
id : my-api
groupId: org.acme
artifactId: my-api
scope: provided
bom: my-api-bom
types:
- name: Maven POM
id: maven-build
tags:
build: maven
format: build
default: false
action: /pom.xml
- name: Maven Project
id: maven-project
tags:
build: maven
format: project
default: true
action: /starter.zip
- name: Gradle Config
id: gradle-build
tags:
build: gradle
format: build
default: false
action: /build.gradle
- name: Gradle Project
id: gradle-project
tags:
build: gradle
format: project
default: false
action: /starter.zip
packagings:
- name: Jar
id: jar
default: true
- name: War
id: war
default: false
javaVersions:
- id: 1.6
default: false
- id: 1.7
default: false
- id: 1.8
default: true
languages:
- name: Groovy
id: groovy
default: false
- name: Java
id: java
default: true
- name: Kotlin
id: kotlin
default: false
bootVersions:
- name : Latest SNAPSHOT
id: 2.5.0-SNAPSHOT
default: false
- name: 2.4.4
id: 2.4.4
default: true
- name: 2.3.10
id: 2.3.10.RELEASE
default: false

server:
error:
include-message: always
Loading