mirror of
https://gitee.com/dcren/initializr.git
synced 2025-11-09 10:55:05 +08:00
Add InitializrMetadataCustomizer callback
This commit is contained in:
@@ -26,6 +26,7 @@ import io.spring.initializr.mapper.InitializrMetadataV2JsonMapper
|
|||||||
import io.spring.initializr.support.InvalidVersionException
|
import io.spring.initializr.support.InvalidVersionException
|
||||||
import io.spring.initializr.support.VersionRange
|
import io.spring.initializr.support.VersionRange
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,6 +66,9 @@ class InitializrMetadata {
|
|||||||
final Env env = new Env()
|
final Env env = new Env()
|
||||||
|
|
||||||
private final Map<String, Dependency> indexedDependencies = [:]
|
private final Map<String, Dependency> indexedDependencies = [:]
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
List<InitializrMetadataCustomizer> customizers = []
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link Dependency} with the specified id or {@code null} if
|
* Return the {@link Dependency} with the specified id or {@code null} if
|
||||||
@@ -170,7 +174,12 @@ class InitializrMetadata {
|
|||||||
*/
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
void validate() {
|
void validate() {
|
||||||
for (DependencyGroup group : dependencies) {
|
|
||||||
|
customizers.each { customizer ->
|
||||||
|
customizer.customize(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies.each { group ->
|
||||||
group.content.each { dependency ->
|
group.content.each { dependency ->
|
||||||
validateDependency(dependency)
|
validateDependency(dependency)
|
||||||
indexDependency(dependency.id, dependency)
|
indexDependency(dependency.id, dependency)
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014-2015 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.spring.initializr
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Dave Syer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
interface InitializrMetadataCustomizer {
|
||||||
|
void customize(InitializrMetadata metadata)
|
||||||
|
}
|
||||||
@@ -139,6 +139,21 @@ class InitializrMetadataTests {
|
|||||||
dependency.generateId()
|
dependency.generateId()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addDependencyInCustomizer() {
|
||||||
|
def group = new InitializrMetadata.DependencyGroup()
|
||||||
|
group.name = 'Extra'
|
||||||
|
def dependency = createDependency('com.foo:foo:1.0.0')
|
||||||
|
group.content.add(dependency)
|
||||||
|
metadata.setCustomizers([new InitializrMetadataCustomizer() {
|
||||||
|
void customize(InitializrMetadata metadata) {
|
||||||
|
metadata.dependencies.add(group)
|
||||||
|
}
|
||||||
|
}])
|
||||||
|
metadata.validate()
|
||||||
|
assertEquals 1, metadata.dependencies.size()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void indexedDependencies() {
|
void indexedDependencies() {
|
||||||
def dependency = createDependency('first')
|
def dependency = createDependency('first')
|
||||||
|
|||||||
Reference in New Issue
Block a user