You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2017/01/03 13:09:16 UTC
svn commit: r1777115 - in
/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave:
Meecrowave.java runner/Cli.java runner/cli/CliOption.java
Author: rmannibucau
Date: Tue Jan 3 13:09:15 2017
New Revision: 1777115
URL: http://svn.apache.org/viewvc?rev=1777115&view=rev
Log:
OWB-1166 fixing shared-librairies name
Modified:
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/cli/CliOption.java
Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java?rev=1777115&r1=1777114&r2=1777115&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java Tue Jan 3 13:09:15 2017
@@ -924,7 +924,7 @@ public class Meecrowave implements AutoC
@CliOption(name = "tomcat-skip-jmx", description = "(Experimental) Should Tomcat MBeans be skipped.")
private boolean tomcatNoJmx = true;
- @CliOption(name = "shared-librairies", description = "A folder containing shared libraries.")
+ @CliOption(name = "shared-libraries", description = "A folder containing shared libraries.", alias = "shared-librairies")
private String sharedLibraries;
@CliOption(name = "log4j2-jul-bridge", description = "Should JUL logs be redirected to Log4j2 - only works before JUL usage.")
@@ -1608,7 +1608,10 @@ public class Meecrowave implements AutoC
return;
}
final String name = field.getName();
- ofNullable(config.getProperty(annotation.name())).ifPresent(val -> {
+ Stream.of(Stream.of(annotation.name()), Stream.of(annotation.alias()))
+ .flatMap(a -> a)
+ .map(config::getProperty)
+ .findFirst().ifPresent(val -> {
final Object toSet;
if (field.getType() == String.class) {
toSet = val;
@@ -1696,9 +1699,12 @@ public class Meecrowave implements AutoC
.filter(f -> f.isAnnotationPresent(CliOption.class))
.forEach(f -> {
final CliOption annotation = f.getAnnotation(CliOption.class);
- final String value = properties.getProperty(annotation.name());
+ String value = properties.getProperty(annotation.name());
if (value == null) {
- return;
+ value = Stream.of(annotation.alias()).map(properties::getProperty).findFirst().orElse(null);
+ if (value == null) {
+ return;
+ }
}
if (!f.isAccessible()) {
Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java?rev=1777115&r1=1777114&r2=1777115&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java Tue Jan 3 13:09:15 2017
@@ -34,6 +34,7 @@ import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.stream.Stream;
@@ -62,11 +63,15 @@ public class Cli {
.collect(toMap(identity(), o -> Stream.of(o.getClass().getDeclaredFields()).filter(f -> f.isAnnotationPresent(CliOption.class)).collect(toList())));
fields.forEach(f -> {
final CliOption opt = f.getAnnotation(CliOption.class);
- options.addOption(null, opt.name(), true /*even for booleans otherwise no way to set false for true by default ones*/, opt.description());
+ final String description = opt.description();
+ options.addOption(null, opt.name(), true /*even for booleans otherwise no way to set false for true by default ones*/, description);
+ Stream.of(opt.alias()).forEach(a -> options.addOption(null, a, true, description));
});
propertiesOptions.values().forEach(all -> all.forEach(f -> {
final CliOption opt = f.getAnnotation(CliOption.class);
- options.addOption(null, opt.name(), true, opt.description());
+ final String description = opt.description();
+ options.addOption(null, opt.name(), true, description);
+ Stream.of(opt.alias()).forEach(a -> options.addOption(null, a, true, description));
}));
final CommandLineParser parser = new PosixParser();
@@ -111,8 +116,12 @@ public class Cli {
private static void bind(final CommandLine line, final List<Field> fields, final Object config) {
fields.forEach(f -> {
final CliOption opt = f.getAnnotation(CliOption.class);
- final String name = opt.name();
- if (line.hasOption(name)) {
+ final Optional<String> first = Stream.of(Stream.of(opt.name()), Stream.of(opt.alias()))
+ .flatMap(a -> a)
+ .filter(line::hasOption)
+ .findFirst();
+ if (first.isPresent()) {
+ final String name = first.get();
ofNullable(f.getType() == boolean.class ?
ofNullable(line.getOptionValue(name)).map(Boolean::parseBoolean).orElse(true) :
toValue(name, line.getOptionValues(name), f.getType()))
Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/cli/CliOption.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/cli/CliOption.java?rev=1777115&r1=1777114&r2=1777115&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/cli/CliOption.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/cli/CliOption.java Tue Jan 3 13:09:15 2017
@@ -29,4 +29,5 @@ import static java.lang.annotation.Reten
public @interface CliOption {
String name();
String description();
+ String[] alias() default {};
}