private static String extract( String key, String prefix, Map<String, String> configuration, VariableResolver variables, boolean mandatory) { assert key != null; assert prefix != null; assert configuration != null; assert variables != null; String value = configuration.get(key); if (value == null) { if (mandatory) { throw new IllegalArgumentException(MessageFormat.format( "Mandatory entry \"{0}\" is not set", prefix + '.' + key)); } else { return null; } } try { return variables.replace(value, true); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(MessageFormat.format( "Failed to resolve variables in \"{0}\": {1}", prefix + '.' + key, value)); } }
context.getContextType().addResolver(new VariableResolver());
while (matcher.find(start)) { String placeholder = matcher.group(1); String replacement = resolve(placeholder); if (replacement == null) { if (strict) {
private static String resolve(ServiceProfile<?> profile, String key, String value) { assert profile != null; assert key != null; assert value != null; try { return profile.getContext().getContextParameters().replace(value, true); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(MessageFormat.format( "Failed to resolve {0} ({1})", key, value), e); } }
/** * Creates a new context with system variables as context parameters. * @param classLoader current class loader * @return the created context object * @throws IllegalArgumentException if some parameters were {@code null} */ public static ProfileContext system(ClassLoader classLoader) { return new ProfileContext(classLoader, new VariableResolver(System.getenv())); }
} else { for (String token : ordered.values()) { String resolved = variables.replace(token, true); results.add(resolved);
/** * Creates a new instance from environment variables and system properties. * If both have same entry, the system properties takes precedence over the environment variables. * @return the created instance */ public static VariableResolver system() { Map<String, String> entries = new HashMap<>(); entries.putAll(System.getenv()); for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); if (key instanceof String && value instanceof String) { entries.put((String) key, (String) value); } } return new VariableResolver(entries); }
String valueString = entry.getValue(); try { valueString = variables.replace(valueString, true); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(MessageFormat.format(
env.putAll(System.getenv()); env.putAll(toMap(variables)); result.context = new ProfileContext(loader, new VariableResolver(env)); Properties properties = CommandLineUtil.loadProperties(file); result.profile = YaessProfile.load(properties, result.context);
if (resolve) { try { string = getContext().getContextParameters().replace(string, true); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(MessageFormat.format(
String unresolved = entry.getValue(); try { String value = profile.getContext().getContextParameters().replace(unresolved, true); resolved.put(key, value); } catch (IllegalArgumentException e) {
String unresolved = entry.getValue(); try { String value = profile.getContext().getContextParameters().replace(unresolved, true); resolved.put(key, value); } catch (IllegalArgumentException e) {