# HG changeset patch # User Omair Majid # Date 1362005463 18000 # Node ID 2bb2a1d1aa03892e4e7bfc3bf099cd34b6ae477a # Parent d13774aae51813da72bfb2b559deca565aebbf41 Allow plugins to use common options Reviewed-by: ebaron Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005924.html diff -r d13774aae518 -r 2bb2a1d1aa03 launcher/src/main/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParser.java --- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParser.java Wed Feb 27 14:52:27 2013 -0500 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParser.java Wed Feb 27 17:51:03 2013 -0500 @@ -98,6 +98,10 @@ * <required>true</required> * <description>some required and long option</description> * </option> + * <options common="true"> + * <long>dbUrl</long> + * <required>true</required> + * </option> * </options> * <bundles> * <bundle>hello-world-plugin-0.1-SNAPSHOT.jar</bundle> @@ -301,7 +305,9 @@ opts.addOptionGroup(group); } else if (node.getNodeName().equals("option")) { Option option = parseOption(node); - opts.addOption(option); + if (option != null) { + opts.addOption(option); + } } } @@ -316,7 +322,9 @@ Node node = nodes.item(i); if (node.getNodeName().equals("option")) { Option option = parseOption(node); - group.addOption(option); + if (option != null) { + group.addOption(option); + } } else if (node.getNodeName().equals("required")) { group.setRequired(Boolean.valueOf(node.getTextContent().trim())); } @@ -326,6 +334,54 @@ } private Option parseOption(Node optionNode) { + Option option; + Node type = optionNode.getAttributes().getNamedItem("common"); + if (type != null && Boolean.valueOf(type.getNodeValue())) { + option = parseCommonOption(optionNode); + } else { + option = parseNormalOption(optionNode); + } + + return option; + } + + private Option parseCommonOption(Node optionNode) { + String longName = null; + String shortName = null; + boolean required = false; + Option option = null; + + NodeList nodes = optionNode.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeName().equals("long")) { + longName = node.getTextContent().trim(); + } else if (node.getNodeName().equals("short")) { + shortName = node.getTextContent().trim(); + } else if (node.getNodeName().equals("required")) { + required = Boolean.valueOf(node.getTextContent().trim()); + } + } + + List