Skip to content

Commit 2ad7734

Browse files
committed
Mark deprecated Flux command options in help output. (metafacture/metafacture-documentation#19. #447)
1 parent 61efabc commit 2ad7734

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

metafacture-commons/src/main/java/org/metafacture/commons/reflection/ConfigurableClass.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,25 @@ private boolean isSetter(final Method method) {
9898
return false;
9999
}
100100

101+
/**
102+
* Gets the parameter type of the setter method.
103+
*
104+
* @param method the setter method
105+
* @return the type
106+
*/
107+
public Class<?> getSetterType(final Method method) {
108+
return method.getParameterTypes()[0];
109+
}
110+
101111
/**
102112
* Gets the parameter types of the setter methods.
103113
*
104114
* @return a Map of the setter method names and their types
105115
*/
106116
public Map<String, Class<?>> getSetterTypes() {
107117
final Map<String, Class<?>> setterTypes = new HashMap<>();
108-
for (final Map.Entry<String, Method> method : getSetters().entrySet()) {
109-
final Class<?> setterType = method.getValue().getParameterTypes()[0];
110-
setterTypes.put(method.getKey(), setterType);
118+
for (final Map.Entry<String, Method> entry : getSetters().entrySet()) {
119+
setterTypes.put(entry.getKey(), getSetterType(entry.getValue()));
111120
}
112121
return setterTypes;
113122
}

metafacture-flux/src/main/java/org/metafacture/flux/HelpPrinter.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.metafacture.flux;
1818

1919
import org.metafacture.commons.ResourceUtil;
20+
import org.metafacture.commons.reflection.ConfigurableClass;
2021
import org.metafacture.commons.reflection.ObjectFactory;
2122
import org.metafacture.framework.MetafactureException;
2223
import org.metafacture.framework.annotations.Description;
@@ -80,8 +81,9 @@ private static String getVersionInfo() {
8081
}
8182
}
8283

83-
private static <T> void describe(final String name, final ObjectFactory<T> factory, final PrintStream out) {
84-
final Class<? extends T> moduleClass = factory.get(name).getPlainClass();
84+
private static <T> void describe(final String name, final ObjectFactory<T> factory, final PrintStream out) { // checkstyle-disable-line ExecutableStatementCount
85+
final ConfigurableClass<? extends T> configurableClass = factory.get(name);
86+
final Class<? extends T> moduleClass = configurableClass.getPlainClass();
8587
final Description desc = moduleClass.getAnnotation(Description.class);
8688

8789
out.println(name);
@@ -96,22 +98,29 @@ private static <T> void describe(final String name, final ObjectFactory<T> facto
9698
out.println("- arguments:\t" + arguments);
9799
}
98100

99-
final Map<String, Class<?>> attributes = factory.get(name).getSetterTypes();
101+
final Map<String, Method> attributes = configurableClass.getSetters();
100102

101103
if (!attributes.isEmpty()) {
102104
out.print("- options:\t");
103105
final StringBuilder builder = new StringBuilder();
104-
for (final Entry<String, Class<?>> entry : attributes.entrySet()) {
105-
if (entry.getValue().isEnum()) {
106+
for (final Entry<String, Method> entry : attributes.entrySet()) {
107+
final Method method = entry.getValue();
108+
final Class<?> type = configurableClass.getSetterType(method);
109+
110+
if (method.isAnnotationPresent(Deprecated.class)) {
111+
builder.append("[deprecated] ");
112+
}
113+
114+
if (type.isEnum()) {
106115
builder.append(entry.getKey())
107116
.append(" ")
108-
.append(Arrays.asList(entry.getValue().getEnumConstants()))
117+
.append(Arrays.asList(type.getEnumConstants()))
109118
.append(", ");
110119
}
111120
else {
112121
builder.append(entry.getKey())
113122
.append(" (")
114-
.append(entry.getValue().getSimpleName())
123+
.append(type.getSimpleName())
115124
.append("), ");
116125
}
117126

metafacture-yaml/src/main/java/org/metafacture/yaml/YamlEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* @author Jens Wille
4747
*
4848
*/
49-
@Description("Serialises an object as YAML. The paramter 'prettyprinting (boolean)' is deprecated since it's not possible to not pretty print.")
49+
@Description("Serialises an object as YAML.")
5050
@In(StreamReceiver.class)
5151
@Out(String.class)
5252
@FluxCommand("encode-yaml")

0 commit comments

Comments
 (0)