Github user richardcloudsoft commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/639#discussion_r30224198
--- Diff:
locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
---
@@ -1050,42 +1050,59 @@ public void apply(TemplateOptions t, ConfigBag
props, Object v) {
public void apply(TemplateOptions t, ConfigBag props,
Object v) {
t.networks((String)v);
}})
- .put(TEMPLATE_OPTIONS, new CustomizeTemplateOptions() {
- @Override
- public void apply(TemplateOptions options, ConfigBag
config, Object v) {
- if (v == null) return;
- @SuppressWarnings("unchecked") Map<String, String>
optionsMap = (Map<String, String>) v;
- if (optionsMap.isEmpty()) return;
-
- Class<? extends TemplateOptions> clazz =
options.getClass();
- Iterable<Method> methods =
Arrays.asList(clazz.getMethods());
- for(final Map.Entry<String, String> option :
optionsMap.entrySet()) {
- Optional<Method> methodOptional =
Iterables.tryFind(methods, new Predicate<Method>() {
- @Override
- public boolean apply(@Nullable Method input)
{
- // Matches a method with the expected
name, and a single parameter that TypeCoercions
- // can coerce to
- if (input == null) return false;
- if
(!input.getName().equals(option.getKey())) return false;
- Type[] parameterTypes =
input.getGenericParameterTypes();
- return parameterTypes.length == 1
- &&
TypeCoercions.tryCoerce(option.getValue(),
TypeToken.of(parameterTypes[0])).isPresentAndNonNull();
- }
- });
- if(methodOptional.isPresent()) {
- try {
- Method method = methodOptional.get();
- method.invoke(options,
TypeCoercions.coerce(option.getValue(),
TypeToken.of(method.getGenericParameterTypes()[0])));
- } catch (IllegalAccessException e) {
- throw Exceptions.propagate(e);
- } catch (InvocationTargetException e) {
- throw Exceptions.propagate(e);
- }
- } else {
- LOG.warn("Ignoring request to set template
option {} because this is not supported by {}", new Object[] { option.getKey(),
clazz.getCanonicalName() });
- }
- }
- }
+ .put(TEMPLATE_OPTIONS, new CustomizeTemplateOptions() {
+ @Override
+ public void apply(TemplateOptions options, ConfigBag
config, Object v) {
+ if (v == null) return;
+ @SuppressWarnings("unchecked") Map<String, Object>
optionsMap = (Map<String, Object>) v;
+ if (optionsMap.isEmpty()) return;
+
+ Class<? extends TemplateOptions> clazz =
options.getClass();
+ Iterable<Method> methods =
Arrays.asList(clazz.getMethods());
+ for(final Map.Entry<String, Object> option :
optionsMap.entrySet()) {
+ Optional<Method> methodOptional =
Iterables.tryFind(methods, new Predicate<Method>() {
+ @Override
+ public boolean apply(@Nullable Method input) {
+ // Matches a method with the expected
name, and a single parameter that TypeCoercions
+ // can coerce to
+ if (input == null) return false;
+ if
(!input.getName().equals(option.getKey())) return false;
+ int numOptionParams = option.getValue()
instanceof List ? ((List)option.getValue()).size() : 1;
+ Type[] parameterTypes =
input.getGenericParameterTypes();
+ if (parameterTypes.length !=
numOptionParams) return false;
+ if (numOptionParams == 1 &&
!(option.getValue() instanceof List) && parameterTypes.length == 1) {
--- End diff --
A comment to explain this would be helpful
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---