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 2011/10/31 00:32:42 UTC
svn commit: r1195279 - in /oodt/branches/cas-cl/src:
main/java/org/apache/oodt/cas/cl/ main/java/org/apache/oodt/cas/cl/action/
main/java/org/apache/oodt/cas/cl/help/
main/java/org/apache/oodt/cas/cl/help/presenter/
main/java/org/apache/oodt/cas/cl/hel...
Author: bfoster
Date: Sun Oct 30 23:32:42 2011
New Revision: 1195279
URL: http://svn.apache.org/viewvc?rev=1195279&view=rev
Log:
- added unit-tests and updated javadoc
* CAS-CL is almost ready to ship! *
Added:
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java (contents, props changed)
- copied, changed from r1195126, oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java (contents, props changed)
- copied, changed from r1195126, oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionHelpPrinter.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToAction.java (with props)
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToActionHandler.java (with props)
Removed:
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionHelpPrinter.java
Modified:
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java Sun Oct 30 23:32:42 2011
@@ -27,8 +27,10 @@ import static org.apache.oodt.cas.cl.uti
import java.util.HashSet;
import java.util.Set;
-//OODT imports
+//Apache imports
import org.apache.commons.lang.Validate;
+
+//OODT imports
import org.apache.oodt.cas.cl.action.CmdLineAction;
import org.apache.oodt.cas.cl.option.ActionCmdLineOption;
import org.apache.oodt.cas.cl.option.CmdLineOption;
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java Sun Oct 30 23:32:42 2011
@@ -36,9 +36,9 @@ import org.apache.oodt.cas.cl.help.prese
import org.apache.oodt.cas.cl.help.presenter.StdCmdLineOptionHelpPresenter;
import org.apache.oodt.cas.cl.help.printer.CmdLineActionHelpPrinter;
import org.apache.oodt.cas.cl.help.printer.CmdLineActionsHelpPrinter;
-import org.apache.oodt.cas.cl.help.printer.CmdLineOptionHelpPrinter;
+import org.apache.oodt.cas.cl.help.printer.CmdLineOptionsHelpPrinter;
import org.apache.oodt.cas.cl.help.printer.StdCmdLineActionHelpPrinter;
-import org.apache.oodt.cas.cl.help.printer.StdCmdLineOptionHelpPrinter;
+import org.apache.oodt.cas.cl.help.printer.StdCmdLineOptionsHelpPrinter;
import org.apache.oodt.cas.cl.option.ActionCmdLineOption;
import org.apache.oodt.cas.cl.option.CmdLineOption;
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
@@ -65,7 +65,7 @@ public class CmdLineUtility {
private CmdLineOptionParser parser;
private CmdLineOptionStore optionStore;
private CmdLineActionStore actionStore;
- private CmdLineOptionHelpPrinter optionHelpPrinter;
+ private CmdLineOptionsHelpPrinter optionHelpPrinter;
private CmdLineActionHelpPrinter actionHelpPrinter;
private CmdLineActionsHelpPrinter actionsHelpPrinter;
private CmdLineOptionHelpPresenter helpPresenter;
@@ -74,7 +74,7 @@ public class CmdLineUtility {
parser = new StdCmdLineOptionParser();
optionStore = new SpringCmdLineOptionStoreFactory().createStore();
actionStore = new SpringCmdLineActionStoreFactory().createStore();
- optionHelpPrinter = new StdCmdLineOptionHelpPrinter();
+ optionHelpPrinter = new StdCmdLineOptionsHelpPrinter();
actionHelpPrinter = new StdCmdLineActionHelpPrinter();
helpPresenter = new StdCmdLineOptionHelpPresenter();
}
@@ -95,11 +95,11 @@ public class CmdLineUtility {
this.actionStore = actionStore;
}
- public CmdLineOptionHelpPrinter getOptionHelpPrinter() {
+ public CmdLineOptionsHelpPrinter getOptionHelpPrinter() {
return optionHelpPrinter;
}
- public void setOptionHelpPrinter(CmdLineOptionHelpPrinter optionHelpPrinter) {
+ public void setOptionHelpPrinter(CmdLineOptionsHelpPrinter optionHelpPrinter) {
this.optionHelpPrinter = optionHelpPrinter;
}
@@ -128,15 +128,22 @@ public class CmdLineUtility {
}
public void printOptionHelp(CmdLineArgs cmdLineArgs) {
- helpPresenter.presentOptionHelp(optionHelpPrinter.printHelp(cmdLineArgs));
+ helpPresenter.presentOptionHelp(optionHelpPrinter.printHelp(cmdLineArgs
+ .getSupportedOptions()));
}
public void printActionHelp(CmdLineArgs cmdLineArgs) {
- helpPresenter.presentActionHelp(actionHelpPrinter.printHelp(cmdLineArgs));
+ Validate.notEmpty(cmdLineArgs.getHelpOptionInst().getValues());
+
+ helpPresenter.presentActionHelp(actionHelpPrinter.printHelp(
+ CmdLineUtils.findAction(cmdLineArgs.getHelpOptionInst().getValues()
+ .get(0), cmdLineArgs.getSupportedActions()),
+ cmdLineArgs.getCustomSupportedOptions()));
}
public void printActionsHelp(CmdLineArgs cmdLineArgs) {
- helpPresenter.presentActionsHelp(actionsHelpPrinter.printHelp(cmdLineArgs));
+ helpPresenter.presentActionsHelp(actionsHelpPrinter.printHelp(cmdLineArgs
+ .getSupportedActions()));
}
/**
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java Sun Oct 30 23:32:42 2011
@@ -1,5 +1,27 @@
+/*
+ * 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.cl.action;
+/**
+ * Action which is specified and configurated via {@link CmdLineOption}s
+ * and then executed.
+ *
+ * @author bfoster (Brian Foster)
+ */
public abstract class CmdLineAction {
private String name;
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java Sun Oct 30 23:32:42 2011
@@ -14,17 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.oodt.cas.cl.help;
//JDK imports
import java.io.IOException;
/**
+ * Exception thrown to express that help {@link CmdLineOption} should be
+ * given to see help message.
*
- * @author bfoster
- * Exception thrown to express that -h should be given to see help
- *
+ * @author bfoster (Brian Foster)
*/
public class OptionHelpException extends IOException {
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java Sun Oct 30 23:32:42 2011
@@ -1,5 +1,26 @@
+/*
+ * 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.cl.help.presenter;
+/**
+ * Presenter to displaying help messages generated by help printers.
+ *
+ * @author bfoster (Brian Foster)
+ */
public interface CmdLineOptionHelpPresenter {
public void presentOptionHelp(String optionHelpMessage);
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java Sun Oct 30 23:32:42 2011
@@ -1,7 +1,29 @@
+/*
+ * 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.cl.help.presenter;
+//JDK imports
import java.io.PrintStream;
+/**
+ * Standard help presenter which sends help messages to {@link System.out}.
+ *
+ * @author bfoster (Brian Foster)
+ */
public class StdCmdLineOptionHelpPresenter implements CmdLineOptionHelpPresenter {
private PrintStream ps;
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java Sun Oct 30 23:32:42 2011
@@ -1,9 +1,44 @@
+/*
+ * 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.cl.help.printer;
-import org.apache.oodt.cas.cl.CmdLineArgs;
+//JDK imports
+import java.util.Set;
+//OODT imports
+import org.apache.oodt.cas.cl.action.CmdLineAction;
+import org.apache.oodt.cas.cl.option.CmdLineOption;
+
+/**
+ * Help printer responsible for generating help message for using
+ * a given {@link CmdLineAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
public interface CmdLineActionHelpPrinter {
- public String printHelp(CmdLineArgs cmdLineArgs);
+ /**
+ * Should generate help message for action specified by
+ * {@link #CmdLineArgs.getSpecifiedAction()}.
+ *
+ * @param action {@link CmdLineAction} for which help will be generate
+ * @param options Supported {@link CmdLineOption}s.
+ * @return Help message for specified action.
+ */
+ public String printHelp(CmdLineAction action, Set<CmdLineOption> options);
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java Sun Oct 30 23:32:42 2011
@@ -1,9 +1,41 @@
+/*
+ * 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.cl.help.printer;
-import org.apache.oodt.cas.cl.CmdLineArgs;
+//JDK imports
+import java.util.Set;
+//OODT imports
+import org.apache.oodt.cas.cl.action.CmdLineAction;
+
+/**
+ * Help printer responsible for generating print help message for
+ * supported {@link CmdLineAction}s.
+ *
+ * @author bfoster (Brian Foster)
+ */
public interface CmdLineActionsHelpPrinter {
- public String printHelp(CmdLineArgs cmdLineArgs);
+ /**
+ * Generates help messages given {@link CmdLineAction}s.
+ *
+ * @param actions {@link CmdLineAction}s to print help for
+ * @return Help message for given {@link CmdLineAction}s.
+ */
+ public String printHelp(Set<CmdLineAction> actions);
}
Copied: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java (from r1195126, oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionHelpPrinter.java)
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java?p2=oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java&p1=oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionHelpPrinter.java&r1=1195126&r2=1195279&rev=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java Sun Oct 30 23:32:42 2011
@@ -1,9 +1,42 @@
+/*
+ * 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.cl.help.printer;
-import org.apache.oodt.cas.cl.CmdLineArgs;
+//JDK imports
+import java.util.Set;
-public interface CmdLineOptionHelpPrinter {
+//OODT imports
+import org.apache.oodt.cas.cl.option.CmdLineOption;
- public String printHelp(CmdLineArgs cmdLineArgs);
+/**
+ * Help printer responsible for generating help message for given
+ * {@link CmdLineOption}s.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public interface CmdLineOptionsHelpPrinter {
+
+ /**
+ * Generates help message for given {@link CmdLineOption}s
+ *
+ * @param options {@link CmdLineOption}s for which help message will be
+ * generated
+ * @return Help message for given {@link CmdLineOption}s.
+ */
+ public String printHelp(Set<CmdLineOption> options);
}
Propchange: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java Sun Oct 30 23:32:42 2011
@@ -1,38 +1,64 @@
+/*
+ * 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.cl.help.printer;
+//OODT static imports
import static org.apache.oodt.cas.cl.util.CmdLineUtils.determineOptional;
import static org.apache.oodt.cas.cl.util.CmdLineUtils.determineRequired;
import static org.apache.oodt.cas.cl.util.CmdLineUtils.sortOptionsByRequiredStatus;
+//JDK imports
import java.util.List;
import java.util.Set;
-import org.apache.oodt.cas.cl.CmdLineArgs;
+//OODT imports
import org.apache.oodt.cas.cl.action.CmdLineAction;
import org.apache.oodt.cas.cl.option.CmdLineOption;
+/**
+ * Standard help printer for printing help for a {@link CmdLineAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
public class StdCmdLineActionHelpPrinter implements
CmdLineActionHelpPrinter {
- public String printHelp(CmdLineArgs cmdLineArgs) {
+ /**
+ * {@inheritDoc}
+ */
+ public String printHelp(CmdLineAction action, Set<CmdLineOption> options) {
StringBuffer sb = new StringBuffer("");
- sb.append(getHeader(cmdLineArgs.getSpecifiedAction())).append("\n");
+ sb.append(getHeader(action)).append("\n");
sb.append(getRequiredSubHeader()).append("\n");
- Set<CmdLineOption> requiredOptions = determineRequired(cmdLineArgs.getSpecifiedAction(), cmdLineArgs.getCustomSupportedOptions());
+ Set<CmdLineOption> requiredOptions = determineRequired(action, options);
List<CmdLineOption> sortedRequiredOptions = sortOptionsByRequiredStatus(requiredOptions);
for (CmdLineOption option : sortedRequiredOptions) {
sb.append(getRequiredOptionHelp(option)).append("\n");
}
sb.append(getOptionalSubHeader()).append("\n");
- Set<CmdLineOption> optionalOptions = determineOptional(cmdLineArgs.getSpecifiedAction(), cmdLineArgs.getCustomSupportedOptions());
+ Set<CmdLineOption> optionalOptions = determineOptional(action, options);
List<CmdLineOption> sortedOptionalOptions = sortOptionsByRequiredStatus(optionalOptions);
for (CmdLineOption option : sortedOptionalOptions) {
sb.append(getOptionalOptionHelp(option)).append("\n");
}
- sb.append(getFooter(cmdLineArgs.getSpecifiedAction())).append("\n");
+ sb.append(getFooter(action)).append("\n");
return sb.toString();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java Sun Oct 30 23:32:42 2011
@@ -1,16 +1,61 @@
+/*
+ * 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.cl.help.printer;
-import org.apache.oodt.cas.cl.CmdLineArgs;
+//JDK imports
+import java.util.Set;
+
+//OODT imports
import org.apache.oodt.cas.cl.action.CmdLineAction;
-public class StdCmdLineActionsHelpPrinter implements CmdLineActionsHelpPrinter {
+/**
+ * Standard help printer which prints supported actions help in the format of:
+ * <pre>
+ * Actions:
+ * Action:
+ * Name: ActionName
+ * Description: Action Description
+ *
+ * Action:
+ * Name: ActionName
+ * Description: Action Description
+ *
+ * ...
+ * ...
+ * ...
+ * </pre>
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class StdCmdLineActionsHelpPrinter
+ implements CmdLineActionsHelpPrinter {
- public String printHelp(CmdLineArgs cmdLineArgs) {
- CmdLineAction action = cmdLineArgs.getSpecifiedAction();
- return
- "Actions:\n" +
- " Action:\n Name: " + action.getName() + "\n" +
- " Description: " + action.getDescription() + "\n";
+ /**
+ * {@inheritDoc}
+ */
+ public String printHelp(Set<CmdLineAction> actions) {
+ StringBuffer sb = new StringBuffer("");
+ for (CmdLineAction action : actions) {
+ sb.append("Actions:").append("\n");
+ sb.append(" Action:").append("\n");
+ sb.append(" Name: ").append(action.getName()).append("\n");
+ sb.append(" Description: ").append(action.getDescription())
+ .append("\n").append("\n");
+ }
+ return sb.toString();
}
-
}
Copied: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java (from r1195126, oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionHelpPrinter.java)
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java?p2=oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java&p1=oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionHelpPrinter.java&r1=1195126&r2=1195279&rev=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java Sun Oct 30 23:32:42 2011
@@ -1,20 +1,49 @@
+/*
+ * 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.cl.help.printer;
+//OODT static imports
import static org.apache.oodt.cas.cl.util.CmdLineUtils.getFormattedString;
import static org.apache.oodt.cas.cl.util.CmdLineUtils.sortOptionsByRequiredStatus;
+//JDK imports
import java.util.List;
+import java.util.Set;
+//Apache imports
import org.apache.commons.lang.StringUtils;
-import org.apache.oodt.cas.cl.CmdLineArgs;
+
+//OODT imports
import org.apache.oodt.cas.cl.option.AdvancedCmdLineOption;
import org.apache.oodt.cas.cl.option.CmdLineOption;
-public class StdCmdLineOptionHelpPrinter implements CmdLineOptionHelpPrinter {
-
- public String printHelp(CmdLineArgs cmdLineArgs) {
+/**
+ * Standard help printer for {@link CmdLineOption}s.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class StdCmdLineOptionsHelpPrinter implements CmdLineOptionsHelpPrinter {
+
+ /**
+ * {@inheritDoc}
+ */
+ public String printHelp(Set<CmdLineOption> options) {
StringBuffer sb = new StringBuffer("");
- List<CmdLineOption> sortedOptions = sortOptionsByRequiredStatus(cmdLineArgs.getSupportedOptions());
+ List<CmdLineOption> sortedOptions = sortOptionsByRequiredStatus(options);
sb.append(getHeader()).append("\n");
for (CmdLineOption option : sortedOptions) {
sb.append(getOptionHelp(option)).append("\n");
Propchange: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java Sun Oct 30 23:32:42 2011
@@ -60,7 +60,7 @@ public class SimpleCmdLineOption impleme
required = false;
hasArgs = false;
performAndQuit = false;
- type = List.class;
+ type = String.class;
requirementRules = new ArrayList<RequirementRule>();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java Sun Oct 30 23:32:42 2011
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.oodt.cas.cl.option.handler;
//OODT imports
@@ -23,15 +22,13 @@ import org.apache.oodt.cas.cl.option.Cmd
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
/**
- * @author bfoster
- * @version $Revision$
+ * Handles a {@link CmdLineOption}'s values in relation to given
+ * {@link CmdLineAction}s.
+ *
+ * @author bfoster (Brian Foster)
*/
public interface CmdLineOptionHandler {
- /**
- *
- * @param optionInstance
- */
public abstract void handleOption(CmdLineAction selectedAction, CmdLineOptionInstance optionInstance);
/**
Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToAction.java?rev=1195279&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToAction.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToAction.java Sun Oct 30 23:32:42 2011
@@ -0,0 +1,42 @@
+/*
+ * 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.cl.option.handler;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link ApplyToAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestApplyToAction extends TestCase {
+
+ public void testVariableSetters() {
+ ApplyToAction applyToAction = new ApplyToAction();
+ assertNull(applyToAction.getActionName());
+ assertNull(applyToAction.getMethodName());
+
+ String actionName = "message";
+ applyToAction.setActionName(actionName);
+ assertEquals(actionName, applyToAction.getActionName());
+
+ String methodName = "setMessage";
+ applyToAction.setMethodName(methodName);
+ assertEquals(methodName, applyToAction.getMethodName());
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToActionHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToActionHandler.java?rev=1195279&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToActionHandler.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToActionHandler.java Sun Oct 30 23:32:42 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.cl.option.handler;
+
+//OODT static imports
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createAdvancedOption;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createApplyToActionHandler;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionInstance;
+
+//OODT imports
+import org.apache.oodt.cas.cl.action.PrintMessageAction;
+import org.apache.oodt.cas.cl.option.AdvancedCmdLineOption;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link ApplyToActionHandler}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestApplyToActionHandler extends TestCase {
+
+ public void testWithoutApplyToActionMappingSet() {
+ ApplyToActionHandler handler = new ApplyToActionHandler();
+ assertNull(handler.getApplyToActions());
+ PrintMessageAction action = new PrintMessageAction();
+ action.setName("PrintMessageAction");
+
+ assertNull(action.getMessage());
+
+ AdvancedCmdLineOption option = new AdvancedCmdLineOption();
+ option.setLongOption("message");
+ option.setHandler(handler);
+ option.getHandler().handleOption(action,
+ createOptionInstance(option, "Howdy"));
+
+ assertEquals("Howdy", action.getMessage());
+ }
+
+ public void testApplyToActionsMapping() {
+ PrintMessageAction action = new PrintMessageAction();
+ action.setName("PrintMessageAction");
+ AdvancedCmdLineOption option = createAdvancedOption("printMessage",
+ createApplyToActionHandler(action.getName(), "setMessage"));
+ option.getHandler().handleOption(action,
+ createOptionInstance(option, "Howdy"));
+
+ assertEquals("Howdy", action.getMessage());
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToActionHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java?rev=1195279&r1=1195278&r2=1195279&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java (original)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java Sun Oct 30 23:32:42 2011
@@ -27,6 +27,9 @@ import org.apache.oodt.cas.cl.option.Cmd
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
import org.apache.oodt.cas.cl.option.GroupCmdLineOption;
import org.apache.oodt.cas.cl.option.SimpleCmdLineOption;
+import org.apache.oodt.cas.cl.option.handler.ApplyToAction;
+import org.apache.oodt.cas.cl.option.handler.ApplyToActionHandler;
+import org.apache.oodt.cas.cl.option.handler.CmdLineOptionHandler;
import org.apache.oodt.cas.cl.option.require.ActionDependencyRule;
import org.apache.oodt.cas.cl.option.require.RequirementRule;
import org.apache.oodt.cas.cl.option.require.RequirementRule.Relation;
@@ -90,6 +93,20 @@ public class TestUtils {
return option;
}
+ public static AdvancedCmdLineOption createAdvancedOption(String longName,
+ CmdLineOptionHandler handler) {
+ return createAdvancedOption(longName, longName, handler);
+ }
+
+ public static AdvancedCmdLineOption createAdvancedOption(String shortName,
+ String longName, CmdLineOptionHandler handler) {
+ AdvancedCmdLineOption option = new AdvancedCmdLineOption();
+ option.setShortOption(shortName);
+ option.setLongOption(longName);
+ option.setHandler(handler);
+ return option;
+ }
+
public static AdvancedCmdLineOption createValidationOption(String longName, CmdLineOptionValidator... validators) {
AdvancedCmdLineOption option = new AdvancedCmdLineOption();
option.setLongOption(longName);
@@ -125,4 +142,12 @@ public class TestUtils {
rule.setRelation(Relation.OPTIONAL);
return rule;
}
+
+ public static ApplyToActionHandler createApplyToActionHandler(
+ String actionName, String methodName) {
+ ApplyToActionHandler handler = new ApplyToActionHandler();
+ handler.setApplyToActions(Lists.newArrayList(new ApplyToAction(actionName,
+ methodName)));
+ return handler;
+ }
}