in its/core-it-support/core-it-plugins/maven-it-plugin-expression/src/main/java/org/apache/maven/plugin/coreit/PropertyUtil.java [70:159]
private static void store(Properties props, String key, Object obj, Collection visited) {
if (obj != null && !visited.contains(obj)) {
visited.add(obj);
if ((obj instanceof String)
|| (obj instanceof Number)
|| (obj instanceof Boolean)
|| (obj instanceof File)
|| (obj instanceof Path)) {
props.put(key, obj.toString());
} else if (obj instanceof Collection) {
Collection coll = (Collection) obj;
props.put(key, Integer.toString(coll.size()));
int index = 0;
for (Iterator it = coll.iterator(); it.hasNext(); index++) {
Object elem = it.next();
store(props, key + "." + index, elem, visited);
}
} else if (obj instanceof Map) {
Map map = (Map) obj;
props.put(key, Integer.toString(map.size()));
@SuppressWarnings("checkstyle:UnusedLocalVariable")
int index = 0;
for (Iterator it = map.entrySet().iterator(); it.hasNext(); index++) {
Map.Entry entry = (Map.Entry) it.next();
store(props, key + "." + entry.getKey(), entry.getValue(), visited);
}
} else if (obj.getClass().isArray()) {
int length = Array.getLength(obj);
props.put(key, Integer.toString(length));
for (int index = 0; index < length; index++) {
Object elem = Array.get(obj, index);
store(props, key + "." + index, elem, visited);
}
} else if (obj.getClass().getName().endsWith("Xpp3Dom")) {
Class type = obj.getClass();
try {
Method getValue = type.getMethod("getValue", NO_PARAMS);
String value = (String) getValue.invoke(obj, NO_ARGS);
if (value != null) {
props.put(key + ".value", value);
}
Method getName = type.getMethod("getName", NO_PARAMS);
Method getChildren = type.getMethod("getChildren", NO_PARAMS);
Object[] children = (Object[]) getChildren.invoke(obj, NO_ARGS);
props.put(key + ".children", Integer.toString(children.length));
Map indices = new HashMap();
for (Object child : children) {
String name = (String) getName.invoke(child, NO_ARGS);
Integer index = (Integer) indices.get(name);
if (index == null) {
index = 0;
}
store(props, key + ".children." + name + "." + index, child, visited);
indices.put(name, index + 1);
}
} catch (Exception e) {
// can't happen
}
} else {
Class type = obj.getClass();
Method[] methods = type.getMethods();
for (Method method : methods) {
if (Modifier.isStatic(method.getModifiers())
|| method.getParameterTypes().length > 0
|| !method.getName().matches("(get|is)\\p{Lu}.*")
|| method.getName().endsWith("AsMap")
|| Class.class.isAssignableFrom(method.getReturnType())
|| Object.class.equals(method.getReturnType())) {
continue;
}
try {
Object value = method.invoke(obj, NO_ARGS);
store(props, key + "." + getPropertyName(method.getName()), value, visited);
} catch (Exception e) {
// just ignore
}
}
}
visited.remove(obj);
}
}