Browse Source

Add aliases to the runtime modes

pull/221/head
Decebal Suiu 7 years ago
parent
commit
c2f888d9ac
  1. 33
      pf4j/src/main/java/org/pf4j/RuntimeMode.java

33
pf4j/src/main/java/org/pf4j/RuntimeMode.java

@ -24,21 +24,26 @@ import java.util.NoSuchElementException;
*/ */
public enum RuntimeMode { public enum RuntimeMode {
DEVELOPMENT("development"), // development DEVELOPMENT("development", "dev"), // development
DEPLOYMENT("deployment"); // deployment DEPLOYMENT("deployment", "prod"); // deployment
private final String name; private final String name;
private final String[] aliases;
private static final Map<String, RuntimeMode> map = new HashMap<>(); private static final Map<String, RuntimeMode> map = new HashMap<>();
static { static {
for (RuntimeMode mode : RuntimeMode.values()) { for (RuntimeMode mode : RuntimeMode.values()) {
map.put(mode.name, mode); map.put(mode.name, mode);
} for (String alias : mode.aliases) {
} map.put(alias, mode);
}
}
}
private RuntimeMode(final String name) { private RuntimeMode(final String name, final String... aliases) {
this.name = name; this.name = name;
this.aliases = aliases;
} }
@Override @Override
@ -47,12 +52,12 @@ public enum RuntimeMode {
} }
public static RuntimeMode byName(String name) { public static RuntimeMode byName(String name) {
if (map.containsKey(name)) { if (map.containsKey(name)) {
return map.get(name); return map.get(name);
} }
throw new NoSuchElementException("Cannot found PF4J runtime mode with name '" + name + throw new NoSuchElementException("Cannot found PF4J runtime mode with name '" + name + "'." +
"'. Must be 'development' or 'deployment'."); "Must be one value from '" + map.keySet() + ".");
} }
} }

Loading…
Cancel
Save