Add InitializrMetadataCustomizer callback

This commit is contained in:
Dave Syer
2015-02-26 14:34:34 +00:00
parent a9ef95be74
commit d93a390af7
3 changed files with 50 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ import io.spring.initializr.mapper.InitializrMetadataV2JsonMapper
import io.spring.initializr.support.InvalidVersionException
import io.spring.initializr.support.VersionRange
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties
/**
@@ -65,6 +66,9 @@ class InitializrMetadata {
final Env env = new Env()
private final Map<String, Dependency> indexedDependencies = [:]
@Autowired
List<InitializrMetadataCustomizer> customizers = []
/**
* Return the {@link Dependency} with the specified id or {@code null} if
@@ -170,7 +174,12 @@ class InitializrMetadata {
*/
@PostConstruct
void validate() {
for (DependencyGroup group : dependencies) {
customizers.each { customizer ->
customizer.customize(this)
}
dependencies.each { group ->
group.content.each { dependency ->
validateDependency(dependency)
indexDependency(dependency.id, dependency)

View File

@@ -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)
}

View File

@@ -139,6 +139,21 @@ class InitializrMetadataTests {
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
void indexedDependencies() {
def dependency = createDependency('first')