Initial support for services validation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014-2016 Pivotal, Inc.
|
||||
* Copyright (c) 2014-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -12,6 +12,8 @@ package org.springframework.ide.vscode.commons.util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
@@ -22,7 +24,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
public class EnumValueParser implements ValueParser {
|
||||
|
||||
private String typeName;
|
||||
private Collection<String> values;
|
||||
private Provider<Collection<String>> values;
|
||||
|
||||
|
||||
public EnumValueParser(String typeName, String... values) {
|
||||
@@ -30,12 +32,16 @@ public class EnumValueParser implements ValueParser {
|
||||
}
|
||||
|
||||
public EnumValueParser(String typeName, Collection<String> values) {
|
||||
this(typeName, () -> values);
|
||||
}
|
||||
|
||||
public EnumValueParser(String typeName, Provider<Collection<String>> values) {
|
||||
this.typeName = typeName;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public Object parse(String str) {
|
||||
Collection<String> values = this.values;
|
||||
Collection<String> values = this.values.get();
|
||||
//If values is not known (null) then just assume the str is acceptable.
|
||||
if (values==null || values.contains(str)) {
|
||||
return str;
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.Renderables;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YType;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YTypedPropertyImpl;
|
||||
@@ -56,10 +55,12 @@ public class ManifestYmlSchema implements YamlSchema {
|
||||
YAtomicType t_buildpack = f.yatomic("Buildpack");
|
||||
t_buildpack.addHintProvider(this.buildpackProvider);
|
||||
|
||||
YType t_service_string = f.yatomic("String");
|
||||
if (servicesProvider != null && t_service_string instanceof AbstractType) {
|
||||
((AbstractType)t_service_string).addHintProvider(servicesProvider);
|
||||
}
|
||||
YAtomicType t_service_string = f.yatomic("String");
|
||||
if (servicesProvider != null) {
|
||||
t_service_string.addHintProvider(servicesProvider);
|
||||
t_service_string
|
||||
.parseWith(ManifestYmlValueParsers.fromHints(t_service_string.toString(), servicesProvider));
|
||||
}
|
||||
YType t_services = f.yseq(t_service_string);
|
||||
|
||||
YAtomicType t_boolean = f.yenum("boolean", "true", "false");
|
||||
|
||||
@@ -10,12 +10,18 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.manifest.yaml;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.EnumValueParser;
|
||||
import org.springframework.ide.vscode.commons.util.ValueParser;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YValueHint;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
@@ -87,4 +93,22 @@ public class ManifestYmlValueParsers {
|
||||
};
|
||||
}
|
||||
|
||||
public static ValueParser fromHints(String typeName, Provider<Collection<YValueHint>> hintProvider) {
|
||||
Provider<Collection<String>> values= () -> {
|
||||
Collection<YValueHint> hints = hintProvider.get();
|
||||
if (hints != null) {
|
||||
Builder<String> builder = ImmutableSet.builder();
|
||||
|
||||
for (YValueHint hint : hints ) {
|
||||
builder.add(hint.getValue());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
return new EnumValueParser(typeName, values);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user