concourse: Allow redefinition of built in resource types
See: https://github.com/spring-projects/sts4/issues/196
This commit is contained in:
@@ -372,25 +372,27 @@ public class ConcourseModel {
|
||||
});
|
||||
}
|
||||
|
||||
public Multiset<String> getResourceTypeNames(DynamicSchemaContext dc) {
|
||||
Collection<YValueHint> hints = getResourceTypeNameHints(dc);
|
||||
public Multiset<String> getResourceTypeNames(DynamicSchemaContext dc, boolean includeBuiltin) {
|
||||
Collection<YValueHint> hints = getResourceTypeNameHints(dc, includeBuiltin);
|
||||
if (hints!=null) {
|
||||
return ImmutableMultiset.copyOf(YTypeFactory.values(hints));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<YValueHint> getResourceTypeNameHints(DynamicSchemaContext dc) {
|
||||
public Collection<YValueHint> getResourceTypeNameHints(DynamicSchemaContext dc, boolean includeBuiltin) {
|
||||
IDocument doc = dc.getDocument();
|
||||
Multiset<String> userDefined = getStringsFromAst(doc, RESOURCE_TYPE_NAMES_PATH);
|
||||
if (userDefined!=null) {
|
||||
Builder<YValueHint> builder = ImmutableMultiset.builder();
|
||||
builder.addAll(YTypeFactory.hints(userDefined));
|
||||
builder.addAll(
|
||||
Arrays.stream(PipelineYmlSchema.BUILT_IN_RESOURCE_TYPES)
|
||||
.map(h -> addExtraInsertion(h, dc))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
if (includeBuiltin) {
|
||||
builder.addAll(
|
||||
Arrays.stream(PipelineYmlSchema.BUILT_IN_RESOURCE_TYPES)
|
||||
.map(h -> addExtraInsertion(h, dc))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ConcourseValueParsers {
|
||||
}
|
||||
|
||||
public static SchemaContextAware<ValueParser> resourceTypeNameDef(ConcourseModel models) {
|
||||
return acceptOnlyUniqueNames(models::getResourceTypeNames, "resource-type name");
|
||||
return acceptOnlyUniqueNames(dc -> models.getResourceTypeNames(dc, false), "resource-type name");
|
||||
}
|
||||
|
||||
public static SchemaContextAware<ValueParser> acceptOnlyUniqueNames(
|
||||
|
||||
@@ -183,7 +183,7 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
return "The '"+parseString+"' Resource Type does not exist. Existing types: "+validValues;
|
||||
},
|
||||
(DynamicSchemaContext dc) -> {
|
||||
return PartialCollection.compute(() -> models.getResourceTypeNameHints(dc));
|
||||
return PartialCollection.compute(() -> models.getResourceTypeNameHints(dc, true));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user