in meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java [467:543]
private Object getConfig(final Class<?> configClass) throws Exception {
final Object config = configClass.newInstance();
for (final Field field : MeecrowaveTask.class.getDeclaredFields()) {
try {
final Field configField = configClass.getDeclaredField(field.getName());
if (!configField.getType().equals(field.getType())) {
getLogger().debug("Skipping " + field.getName() + " since type doesnt match");
continue;
}
if (!field.isAccessible()) {
field.setAccessible(true);
}
final Object value = field.get(this);
if (value != null) {
if (!configField.isAccessible()) {
configField.setAccessible(true);
}
configField.set(config, value);
getLogger().debug("using " + field.getName() + " = " + value);
}
} catch (final NoSuchFieldException nsfe) {
// ignored
} catch (final Exception e) {
getLogger().warn("can't initialize attribute " + field.getName(), e);
}
}
if (securityConstraints != null) {
configClass.getMethod("setSecurityConstraints", Collection.class).invoke(config, securityConstraints.stream()
.map(item -> {
try {
final Class<?> recipeType = configClass.getClassLoader().loadClass("org.apache.xbean.recipe.ObjectRecipe");
final Class<?> builderType = configClass.getClassLoader().loadClass("org.apache.meecrowave.Meecrowave$SecurityConstaintBuilder");
final Object recipe = recipeType.getConstructor(Class.class).newInstance(builderType);
Stream.of(item.split(";"))
.map(v -> v.split("="))
.forEach(v -> {
try {
recipe.getClass().getMethod("setProperty", String.class, String.class).invoke(recipe, v[0], v[1]);
} catch (final NoSuchMethodException | IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (final InvocationTargetException e) {
throw new IllegalStateException(e.getCause());
}
});
return recipe.getClass().getMethod("create", ClassLoader.class).invoke(recipe, configClass.getClassLoader());
} catch (final Exception cnfe) {
throw new IllegalArgumentException(item);
}
}).collect(toList()));
}
ofNullable(loginConfig).ifPresent(lc -> {
try {
final Class<?> recipeType = configClass.getClassLoader().loadClass("org.apache.xbean.recipe.ObjectRecipe");
final Class<?> builderType = configClass.getClassLoader().loadClass("org.apache.meecrowave.Meecrowave$LoginConfigBuilder");
final Object recipe = recipeType.getConstructor(Class.class).newInstance(builderType);
Stream.of(loginConfig.split(";"))
.map(v -> v.split("="))
.forEach(v -> {
try {
recipe.getClass().getMethod("setProperty", String.class, String.class).invoke(recipe, v[0], v[1]);
} catch (final NoSuchMethodException | IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (final InvocationTargetException e) {
throw new IllegalStateException(e.getCause());
}
});
configClass.getMethod("setLoginConfig", Collection.class)
.invoke(config, recipe.getClass().getMethod("create", ClassLoader.class).invoke(recipe, configClass.getClassLoader()));
} catch (final Exception cnfe) {
throw new IllegalArgumentException(loginConfig);
}
});
return config;
}