You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2012/02/25 12:54:51 UTC

svn commit: r1293581 - in /oodt/trunk/cli/src: main/java/org/apache/oodt/cas/cli/ main/java/org/apache/oodt/cas/cli/option/ main/java/org/apache/oodt/cas/cli/option/handler/ main/java/org/apache/oodt/cas/cli/printer/ main/java/org/apache/oodt/cas/cli/u...

Author: bfoster
Date: Sat Feb 25 11:54:50 2012
New Revision: 1293581

URL: http://svn.apache.org/viewvc?rev=1293581&view=rev
Log:
- Fix help option sorting and added handler initialization

--------------
OODT-379

Added:
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/OptionPropertyRegister.java   (with props)
Modified:
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java?rev=1293581&r1=1293580&r2=1293581&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java Sat Feb 25 11:54:50 2012
@@ -17,11 +17,13 @@
 package org.apache.oodt.cas.cli;
 
 //OODT static imports
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.asAdvancedOption;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineFailedValidation;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineRequired;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.findFirstActionOption;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.findHelpOption;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.findPrintSupportedActionsOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.isAdvancedOption;
 
 //JDK imports
 import java.util.HashSet;
@@ -205,6 +207,7 @@ public class CmdLineUtility {
 
       // Load supported options.
       Set<CmdLineOption> validOptions = optionStore.loadSupportedOptions();
+      initializeHandlers(validOptions);
 
       // Insure help options is present if required.
       if (findHelpOption(validOptions) == null) {
@@ -229,6 +232,21 @@ public class CmdLineUtility {
    }
 
    /**
+    * Initializes each {@link CmdLineOptionHandler} with their assigned
+    * {@link CmdLineOption}.
+    * 
+    * @param options
+    */
+   public void initializeHandlers(Set<CmdLineOption> options) {
+      for (CmdLineOption option : options) {
+         if (isAdvancedOption(option)
+               && asAdvancedOption(option).getHandler() != null) {
+            asAdvancedOption(option).getHandler().initialize(option);
+         }
+      }
+   }
+
+   /**
     * Checks if help option was specified and if so prints out help.
     * 
     * @param cmdLineArgs

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java?rev=1293581&r1=1293580&r2=1293581&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java Sat Feb 25 11:54:50 2012
@@ -33,5 +33,6 @@ public class ActionCmdLineOption extends
       this.setArgsDescription("action-name");
       this.setType(String.class);
       this.setPerformAndQuit(false);
+      this.setRequired(true);
    }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java?rev=1293581&r1=1293580&r2=1293581&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java Sat Feb 25 11:54:50 2012
@@ -56,6 +56,10 @@ public class ApplyToActionHandler implem
       return applyToActions;
    }
 
+   public void initialize(CmdLineOption option) {
+      // Do nothing.
+   }
+
    public void handleOption(CmdLineAction action,
          CmdLineOptionInstance optionInstance) {
       try {

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java?rev=1293581&r1=1293580&r2=1293581&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java Sat Feb 25 11:54:50 2012
@@ -29,6 +29,14 @@ import org.apache.oodt.cas.cli.option.Cm
  */
 public interface CmdLineOptionHandler {
 
+   /**
+    * Called after handler construction to allow handler to setup
+    * state before it is required to handle the option later. This
+    * is also called when help is run so allows registration to take
+    * place if necessary for help analysis.
+    */
+   public abstract void initialize(CmdLineOption option);
+
    public abstract void handleOption(CmdLineAction selectedAction,
          CmdLineOptionInstance optionInstance);
 
@@ -43,6 +51,11 @@ public interface CmdLineOptionHandler {
     */
    public abstract String getHelp(CmdLineOption option);
 
+   /**
+    * If this handler causes the argument descriptor to be different for
+    * certain {@link CmdLineAction}s, then should return the arg
+    * description here.
+    */
    public abstract String getArgDescription(CmdLineAction action,
          CmdLineOption option);
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java?rev=1293581&r1=1293580&r2=1293581&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java Sat Feb 25 11:54:50 2012
@@ -27,6 +27,7 @@ import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cli.action.CmdLineAction;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cli.util.OptionPropertyRegister;
 
 /**
  * {@link CmdLineOptionHandler} which sets Java Properties equals to the
@@ -39,6 +40,12 @@ public class SetJavaPropertiesHandler im
 
    private List<String> propertyNames;
 
+   public void initialize(CmdLineOption option) {
+      for (String property : propertyNames) {
+         OptionPropertyRegister.registerOption(property, option);
+      }
+   }
+
    public void handleOption(CmdLineAction selectedAction,
          CmdLineOptionInstance optionInstance) {
       Validate.notNull(propertyNames);

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java?rev=1293581&r1=1293580&r2=1293581&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java Sat Feb 25 11:54:50 2012
@@ -25,6 +25,7 @@ import static org.apache.oodt.cas.cli.ut
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.getFormattedString;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.isGroupOption;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.sortActions;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.sortOptions;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.sortOptionsByRequiredStatus;
 
 //JDK imports
@@ -88,14 +89,14 @@ public class StdCmdLinePrinter implement
       StringBuffer sb = new StringBuffer("> USAGE:\n");
       sb.append(getRequiredSubHeader()).append("\n");
       Set<CmdLineOption> requiredOptions = determineRequired(action, options);
-      List<CmdLineOption> sortedRequiredOptions = sortOptionsByRequiredStatus(requiredOptions);
+      List<CmdLineOption> sortedRequiredOptions = sortOptions(requiredOptions);
       for (CmdLineOption option : sortedRequiredOptions) {
          sb.append(getRequiredOptionHelp(action, option)).append("\n");
       }
 
       sb.append(getOptionalSubHeader()).append("\n");
       Set<CmdLineOption> optionalOptions = determineOptional(action, options);
-      List<CmdLineOption> sortedOptionalOptions = sortOptionsByRequiredStatus(optionalOptions);
+      List<CmdLineOption> sortedOptionalOptions = sortOptions(optionalOptions);
       for (CmdLineOption option : sortedOptionalOptions) {
          sb.append(getOptionalOptionHelp(action, option)).append("\n");
       }
@@ -153,7 +154,7 @@ public class StdCmdLinePrinter implement
 
       String argHelp = null;
       if (option instanceof ActionCmdLineOption && option.hasArgs()) {
-         argHelp = action.getName();
+         argHelp = " " + action.getName();
       } else {
          argHelp = (option.hasArgs() ? " <"
                + (argDescription != null ? argDescription : option
@@ -252,10 +253,13 @@ public class StdCmdLinePrinter implement
 
       if (option instanceof AdvancedCmdLineOption) {
          if (((AdvancedCmdLineOption) option).hasHandler()) {
-            optionUsage += "\n"
-                  + getFormattedString("Handler:", 62, 113)
-                  + getFormattedString(((AdvancedCmdLineOption) option)
-                        .getHandler().getHelp(option), 63, 113);
+            String handlerHelp = ((AdvancedCmdLineOption) option).getHandler()
+                  .getHelp(option);
+            if (handlerHelp != null) {
+               optionUsage += "\n"
+                     + getFormattedString("Handler:", 62, 113)
+                     + getFormattedString(handlerHelp, 63, 113);
+            }
          }
       } else if (isGroupOption(option)) {
          GroupCmdLineOption groupOption = asGroupOption(option);

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java?rev=1293581&r1=1293580&r2=1293581&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java Sat Feb 25 11:54:50 2012
@@ -31,6 +31,7 @@ import org.apache.commons.lang.StringUti
 import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cli.action.CmdLineAction;
 import org.apache.oodt.cas.cli.option.ActionCmdLineOption;
+import org.apache.oodt.cas.cli.option.AdvancedCmdLineOption;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
 import org.apache.oodt.cas.cli.option.GroupCmdLineOption;
@@ -59,24 +60,35 @@ public class CmdLineUtils {
    }
 
    /**
-    * Determines which of the given {@link CmdLineOption}s are required because
-    * the given {@link CmdLineAction} was specified.
+    * Determines which of the given {@link CmdLineOption}s are either always
+    * required and are required because the given {@link CmdLineAction} was
+    * specified.
     * 
     * @param action
     *           The {@link CmdLineAction} which was specified.
     * @param options
     *           The {@link CmdLineOption}s in question of being required or not.
-    * @return The {@link Set} of {@link CmdLineOption}s where are required
-    *         because the given {@link CmdLineAction} was specified.
+    * @return The {@link Set} of {@link CmdLineOption}s which are either always
+    *         required or are required because the given {@link CmdLineAction}
+    *         was specified.
     */
    public static Set<CmdLineOption> determineRequired(CmdLineAction action,
          Set<CmdLineOption> options) {
+      return determineRequired(action, options, false);
+   }
+
+   /**
+    * Same as method above but optionally allows action options to be ignored.
+    */
+   public static Set<CmdLineOption> determineRequired(CmdLineAction action,
+         Set<CmdLineOption> options, boolean ignoreActionOption) {
       Validate.notNull(action);
       Validate.notNull(options);
 
-      Set<CmdLineOption> requiredOptions = getRequiredOptions(options);
+      Set<CmdLineOption> requiredOptions = Sets.newHashSet();
       for (CmdLineOption option : options) {
-         if (isRequired(action, option)) {
+         if (!(ignoreActionOption && isActionOption(option))
+               && isRequired(action, option)) {
             requiredOptions.add(option);
          }
       }
@@ -84,7 +96,7 @@ public class CmdLineUtils {
    }
 
    /**
-    * Determines the given {@link GroupCmdLineOption}'s sub-options which are
+    * Determines the given {@link GroupCmdLineOption}'s sub-options which
     * affect the given {@link CmdLineAction}.
     * 
     * @param action
@@ -101,9 +113,8 @@ public class CmdLineUtils {
          CmdLineAction action, GroupCmdLineOption option) {
       Set<CmdLineOption> relevantOptions = Sets.newHashSet();
       for (GroupSubOption subOption : option.getSubOptions()) {
-         if (subOption.isRequired()
-               || isRequired(action, subOption.getOption())
-               || isOptional(action, subOption.getOption())) {
+         if (isRequired(action, subOption.getOption())
+               || isStrictlyOptional(action, subOption.getOption())) {
             relevantOptions.add(subOption.getOption());
          }
       }
@@ -151,8 +162,7 @@ public class CmdLineUtils {
 
       Set<CmdLineOption> requiredOptions = Sets.newHashSet();
       for (GroupSubOption subOption : option.getSubOptions()) {
-         if (subOption.isRequired()
-               || isRequired(action, subOption.getOption())) {
+         if (isRequired(action, subOption.getOption())) {
             requiredOptions.add(subOption.getOption());
          }
       }
@@ -161,7 +171,7 @@ public class CmdLineUtils {
 
    /**
     * Determines if the given {@link CmdLineOption} is required because the
-    * given {@link CmdLineAction} was specified.
+    * given {@link CmdLineAction} was specified or because it is always required.
     * 
     * @param action
     *           The {@link CmdLineAction} which was specified.
@@ -178,7 +188,7 @@ public class CmdLineUtils {
             return true;
          }
       }
-      return false;
+      return option.getRequirementRules().isEmpty() && option.isRequired();
    }
 
    /**
@@ -207,8 +217,9 @@ public class CmdLineUtils {
    }
 
    /**
-    * Determines if the given {@link CmdLineOption} is optional because the
-    * given {@link CmdLineAction} was specified.
+    * Determines if the given {@link CmdLineOption} is optional either because
+    * it is always optional or because the given {@link CmdLineAction} was
+    * specified.
     * 
     * @param action
     *           The {@link CmdLineAction} which was specified.
@@ -220,6 +231,32 @@ public class CmdLineUtils {
       Validate.notNull(action);
       Validate.notNull(option);
 
+      if (isHelpOption(option) || isPrintSupportedActionsOption(option)) {
+         return false;
+      }
+
+      for (RequirementRule requirementRule : option.getRequirementRules()) {
+         if (requirementRule.getRelation(action) == Relation.OPTIONAL) {
+            return true;
+         }
+      }
+      return option.getRequirementRules().isEmpty() && !option.isRequired();
+   }
+
+   /**
+    * Determines if the given {@link CmdLineOption} is optional ONLY because the
+    * given {@link CmdLineAction} was specified.
+    * 
+    * @param action
+    *           The {@link CmdLineAction} which was specified.
+    * @param option
+    *           The {@link CmdLineOption} in question of being optional or not.
+    * @return True is option is optional, false otherwise.
+    */   
+   public static boolean isStrictlyOptional(CmdLineAction action, CmdLineOption option) {
+      Validate.notNull(action);
+      Validate.notNull(option);
+
       for (RequirementRule requirementRule : option.getRequirementRules()) {
          if (requirementRule.getRelation(action) == Relation.OPTIONAL) {
             return true;
@@ -294,7 +331,12 @@ public class CmdLineUtils {
                   + (!option1.getRequirementRules().isEmpty() ? 1 : 0);
             int compareScore = (option2.isRequired() ? 2 : 0)
                   + (!option2.getRequirementRules().isEmpty() ? 1 : 0);
-            return new Integer(thisScore).compareTo(compareScore);
+            if (thisScore == compareScore) {
+               return option2.getLongOption()
+                     .compareTo(option1.getLongOption());
+            } else {
+               return new Integer(thisScore).compareTo(compareScore);
+            }
          }
       });
       Collections.reverse(optionsList);
@@ -302,6 +344,23 @@ public class CmdLineUtils {
    }
 
    /**
+    * Sorts {@link CmdLineOption}s by there long name.
+    *
+    * @param options The {@link CmdLineOption}s to be sorted
+    * @return Sorted {@link List} of {@link CmdLineOption}s
+    */
+   public static List<CmdLineOption> sortOptions(Set<CmdLineOption> options) {
+      List<CmdLineOption> optionList = Lists.newArrayList(options);
+      Collections.sort(optionList, new Comparator<CmdLineOption>() {
+         @Override
+         public int compare(CmdLineOption o1, CmdLineOption o2) {
+            return o1.getLongOption().compareTo(o2.getLongOption());
+         }
+      });
+      return optionList;
+   }
+   
+   /**
     * Sorts {@link CmdLineAction}s by there name.
     *
     * @param actions The {@link CmdLineAction}s to be sorted
@@ -563,6 +622,35 @@ public class CmdLineUtils {
    }
 
    /**
+    * Checks if {@link CmdLineOption} is a {@link AdvancedCmdLineOption}.
+    * 
+    * @param option
+    *           The {@link CmdLineOption} checked if it is a
+    *           {@link AdvancedCmdLineOption}
+    * @return True if {@link CmdLineOption} is a {@link AdvancedCmdLineOption},
+    *         false otherwise
+    */
+   public static boolean isAdvancedOption(CmdLineOption option) {
+      Validate.notNull(option);
+
+      return option instanceof AdvancedCmdLineOption;
+   }
+
+   /**
+    * Casts the {@link CmdLineOption} to a {@link AdvancedCmdLineOption}.
+    * 
+    * @param option
+    *           The {@link CmdLineOption} to cast as a
+    *           {@link AdvancedCmdLineOption}
+    * @return The casted {@link CmdLineOption}
+    */
+   public static AdvancedCmdLineOption asAdvancedOption(CmdLineOption option) {
+      Validate.isTrue(isAdvancedOption(option));
+
+      return (AdvancedCmdLineOption) option;
+   }
+
+   /**
     * Checks if {@link CmdLineOption} is a {@link SimpleCmdLineOption}.
     * 
     * @param option

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/OptionPropertyRegister.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/OptionPropertyRegister.java?rev=1293581&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/OptionPropertyRegister.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/OptionPropertyRegister.java Sat Feb 25 11:54:50 2012
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.cli.util;
+
+//JDK imports
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+//Apache imports
+import org.apache.commons.lang.Validate;
+
+//OODT imports
+import org.apache.oodt.cas.cli.option.CmdLineOption;
+
+//Google imports
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+/**
+ * Register for determining if a Java Property is required or optional and
+ * thus determining which options become required or optional because
+ * said property has been registered.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class OptionPropertyRegister {
+
+   private static Map<String, CmdLineOption> optionRegistrations = Maps.newHashMap();
+
+   private OptionPropertyRegister() {
+      throw new RuntimeException("Do not instantiate OptionPropertyRegister");
+   }
+
+   public static void registerOption(String property, CmdLineOption option) {
+      Validate.isTrue(!optionRegistrations.containsKey(property),
+            "Property '" + property + "' is already registered to: "
+            + optionRegistrations.get(property));
+
+      optionRegistrations.put(property, option);
+   }
+
+   public static CmdLineOption getRegisteredOption(String property) {
+      for (Entry<String, CmdLineOption> optionRegistration : optionRegistrations.entrySet()) {
+         if (optionRegistration.getKey().equals(property)) {
+            return optionRegistration.getValue();
+         }
+      }
+      return null;
+   }
+   
+   public static Set<String> getProperties(CmdLineOption specifiedOption) {
+      Set<String> properties = Sets.newHashSet();
+      for (Entry<String, CmdLineOption> optionRegistration : optionRegistrations.entrySet()) {
+         if (optionRegistration.getValue().equals(specifiedOption)) {
+            properties.add(optionRegistration.getKey());
+         }
+      }
+      return properties;
+   }
+
+   public static void clearRegister() {
+      optionRegistrations.clear();
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/OptionPropertyRegister.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java?rev=1293581&r1=1293580&r2=1293581&view=diff
==============================================================================
--- oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java (original)
+++ oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java Sat Feb 25 11:54:50 2012
@@ -26,7 +26,6 @@ import static org.apache.oodt.cas.cli.ut
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.getOptionByName;
 
 //JDK imports
-import java.util.List;
 import java.util.Set;
 
 //OODT imports
@@ -42,7 +41,6 @@ import org.apache.oodt.cas.cli.option.Pr
 import org.apache.oodt.cas.cli.option.validator.ArgRegExpCmdLineOptionValidator;
 import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result;
 import org.apache.oodt.cas.cli.test.util.TestUtils;
-import org.apache.oodt.cas.cli.util.CmdLineUtils;
 
 //Google imports
 import com.google.common.collect.Lists;

Modified: oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java?rev=1293581&r1=1293580&r2=1293581&view=diff
==============================================================================
--- oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java (original)
+++ oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java Sat Feb 25 11:54:50 2012
@@ -69,33 +69,36 @@ public class TestCmdLineUtils extends Te
 
    public void testDetermineRequired() {
       CmdLineAction action = createAction("TestAction");
-      CmdLineOption urlOption, passOption;
+      CmdLineOption urlOption, passOption, actionOption;
 
       HashSet<CmdLineOption> options = Sets.newHashSet(
             urlOption = createSimpleOption("url",
                   createRequiredRequirementRule(action)),
             passOption = createSimpleOption("pass", false),
-            createSimpleOption("user", false), createActionOption("operation"));
+            createSimpleOption("user", false),
+            actionOption = createActionOption("operation"));
 
       Set<CmdLineOption> requiredOptions = CmdLineUtils.determineRequired(
             action, options);
-      assertEquals(Sets.newHashSet(urlOption), requiredOptions);
+      assertEquals(Sets.newHashSet(urlOption, actionOption), requiredOptions);
 
       options = Sets.newHashSet(
             urlOption = createSimpleOption("url",
                   createRequiredRequirementRule(action)),
             passOption = createSimpleOption("pass", true),
-            createSimpleOption("user", false), createActionOption("operation"));
+            createSimpleOption("user", false),
+            actionOption = createActionOption("operation"));
 
       requiredOptions = CmdLineUtils.determineRequired(action, options);
-      assertEquals(Sets.newHashSet(urlOption, passOption), requiredOptions);
+      assertEquals(Sets.newHashSet(urlOption, passOption, actionOption),
+            requiredOptions);
    }
 
    public void testIsRequired() {
       CmdLineAction action = createAction("TestAction");
       assertTrue(CmdLineUtils.isRequired(action,
             createSimpleOption("url", createRequiredRequirementRule(action))));
-      assertFalse(CmdLineUtils.isRequired(action,
+      assertTrue(CmdLineUtils.isRequired(action,
             createSimpleOption("url", true)));
       assertFalse(CmdLineUtils.isRequired(action,
             createSimpleOption("url", false)));
@@ -104,15 +107,16 @@ public class TestCmdLineUtils extends Te
    public void testDetermineOptional() {
       CmdLineAction action = createAction("TestAction");
       CmdLineOption actionOption = new ActionCmdLineOption();
+      CmdLineOption passOption, userOption;
 
       HashSet<CmdLineOption> options = Sets.newHashSet(
             createSimpleOption("url", createRequiredRequirementRule(action)),
-            createSimpleOption("pass", false),
-            createSimpleOption("user", false), actionOption);
+            passOption = createSimpleOption("pass", false),
+            userOption = createSimpleOption("user", false), actionOption);
 
       Set<CmdLineOption> optionalOptions = CmdLineUtils.determineOptional(
             action, options);
-      assertTrue(optionalOptions.isEmpty());
+      assertEquals(Sets.newHashSet(passOption, userOption), optionalOptions);
 
       options = Sets.newHashSet(createSimpleOption("pass", true),
             createSimpleOption("user", true), actionOption);
@@ -120,7 +124,6 @@ public class TestCmdLineUtils extends Te
       optionalOptions = CmdLineUtils.determineOptional(action, options);
       assertTrue(optionalOptions.isEmpty());
 
-      CmdLineOption passOption, userOption;
       options = Sets.newHashSet(
             passOption = createSimpleOption("pass",
                   createOptionalRequirementRule(action)),
@@ -137,7 +140,7 @@ public class TestCmdLineUtils extends Te
             createSimpleOption("url", createOptionalRequirementRule(action))));
       assertFalse(CmdLineUtils.isOptional(action,
             createSimpleOption("url", true)));
-      assertFalse(CmdLineUtils.isOptional(action,
+      assertTrue(CmdLineUtils.isOptional(action,
             createSimpleOption("url", false)));
    }
 
@@ -483,16 +486,21 @@ public class TestCmdLineUtils extends Te
 
       // Test case when option has a handler.
       option.setHandler(new CmdLineOptionHandler() {
+         @Override
+         public void initialize(CmdLineOption option) {}
 
+         @Override
          public void handleOption(CmdLineAction selectedAction,
                CmdLineOptionInstance optionInstance) {
             selectedAction.setDescription("handler modified description");
          }
 
+         @Override
          public String getHelp(CmdLineOption option) {
             return null;
          }
 
+         @Override
          public String getArgDescription(CmdLineAction action,
                CmdLineOption option) {
             return null;