Author: bfoster
Date: Fri Dec 17 01:26:45 2010
New Revision: 1050261
URL: http://svn.apache.org/viewvc?rev=1050261&view=rev
Log:
- added a cas-commons command-line help for a given arguments
--------------------
OODT-91
Modified:
oodt/trunk/CHANGES.txt
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedActionsHandler.java
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedClientsHandler.java
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedServersHandler.java
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionBeanHandler.java
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionHandler.java
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/StdCmdLineOptionHandler.java
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/parser/CmdLineOptionParser.java
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/util/CmdLineOptionsUsagePrinter.java
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionCrawlerActionInfoHandler.java
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionJavaPropHandler.java
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionPreconditionInfoHandler.java
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionProductCrawlerInfoHandler.java
Modified: oodt/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Fri Dec 17 01:26:45 2010
@@ -4,6 +4,8 @@ Apache OODT Change Log
Release 0.2 (Current Development)
--------------------------------------------
+* OODT-91 cas-commons command-line help for a given arguments (bfoster)
+
* OODT-89 (cas-pushpull patch) Synchonize OODT-CAS components, which depend on
one another, on a particular Apache-Tika version (bfoster)
* OODT-88 mvn eclipse:eclipse fails to merge resources (bfoster)
Modified:
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedActionsHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedActionsHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedActionsHandler.java
(original)
+++
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedActionsHandler.java
Fri Dec 17 01:26:45 2010
@@ -66,9 +66,9 @@ public class PrintSupportedActionsHandle
this.beanRepo = beanRepo;
}
-// @Override
-// public boolean affectsOption(CmdLineOptionInstance arg0) {
-// return false;
-// }
+ @Override
+ public boolean affectsOption(CmdLineOptionInstance arg0) {
+ return false;
+ }
}
Modified:
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedClientsHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedClientsHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedClientsHandler.java
(original)
+++
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedClientsHandler.java
Fri Dec 17 01:26:45 2010
@@ -67,9 +67,9 @@ public class PrintSupportedClientsHandle
this.beanRepo = beanRepo;
}
-// @Override
-// public boolean affectsOption(CmdLineOptionInstance arg0) {
-// return false;
-// }
+ @Override
+ public boolean affectsOption(CmdLineOptionInstance arg0) {
+ return false;
+ }
}
Modified:
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedServersHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedServersHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedServersHandler.java
(original)
+++
oodt/trunk/catalog/src/main/java/org/apache/oodt/cas/catalog/server/option/PrintSupportedServersHandler.java
Fri Dec 17 01:26:45 2010
@@ -65,9 +65,9 @@ public class PrintSupportedServersHandle
this.beanRepo = beanRepo;
}
-// @Override
-// public boolean affectsOption(CmdLineOptionInstance arg0) {
-// return false;
-// }
+ @Override
+ public boolean affectsOption(CmdLineOptionInstance arg0) {
+ return false;
+ }
}
Modified:
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionBeanHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionBeanHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionBeanHandler.java
(original)
+++
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionBeanHandler.java
Fri Dec 17 01:26:45 2010
@@ -1,147 +1,157 @@
-/*
- * 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.commons.option.handler;
-
-//JDK imports
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-//OODT imports
-import org.apache.oodt.commons.option.CmdLineOption;
-import org.apache.oodt.commons.spring.SpringSetIdInjectionType;
-
-//Spring imports
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Required;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class CmdLineOptionBeanHandler extends CmdLineOptionHandler {
-
- private List<BeanInfo> applyToBeans;
-
- @Required
- public void setApplyToBeans(List<BeanInfo> applyToBeans) {
- this.applyToBeans = applyToBeans;
- }
-
- public void handleOption(CmdLineOption option, List<String> values) {
- try {
- for (BeanInfo applyToBean : this.applyToBeans) {
- Class type = (option.getType() != null) ? option.getType()
- : String.class;
- Object[] vals = null;
- if (values.size() != 0) {
- vals = this.convertToType(values, type);
- } else {
- vals = this.convertToType(Arrays
- .asList(new String[] { "true" }), type =
Boolean.TYPE);
- }
- try {
- if (applyToBean.getMethodName() != null) {
- applyToBean.getBean().getClass().getMethod(
- applyToBean.getMethodName(), type).invoke(
- applyToBean.getBean(), vals);
- } else {
- applyToBean.getBean().getClass().getMethod(
- "set" + StringUtils.capitalize(option.getId()),
- type).invoke(applyToBean.getBean(), vals);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public String getCustomOptionUsage(CmdLineOption option) {
- Set<String> affectedClasses = new HashSet<String>();
- for (BeanInfo beanInfo : applyToBeans) {
- if (beanInfo.getBean() instanceof SpringSetIdInjectionType)
- affectedClasses.add(((SpringSetIdInjectionType) beanInfo
- .getBean()).getId());
- else
- affectedClasses.add(beanInfo.getBean().getClass().getName());
- }
- return "Affects: " + affectedClasses.toString();
- }
-
- private Object[] convertToType(List<String> values, Class type)
- throws MalformedURLException, ClassNotFoundException {
- if (type.equals(File.class)) {
- List<Object> files = new LinkedList<Object>();
- for (String value : values)
- files.add(new File(value));
- return files.toArray(new Object[files.size()]);
- } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
- List<Object> booleans = new LinkedList<Object>();
- for (String value : values)
- booleans.add(value.toLowerCase().trim().equals("true"));
- return booleans.toArray(new Object[booleans.size()]);
- } else if (type.equals(URL.class)) {
- List<Object> urls = new LinkedList<Object>();
- for (String value : values)
- urls.add(new URL(value));
- return urls.toArray(new Object[urls.size()]);
- } else if (type.equals(Class.class)) {
- List<Object> classes = new LinkedList<Object>();
- for (String value : values)
- classes.add(Class.forName(value));
- return classes.toArray(new Object[classes.size()]);
- } else if (type.equals(List.class)) {
- return new Object[] { values };
- } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
- List<Object> ints = new LinkedList<Object>();
- for (String value : values)
- ints.add(new Integer(value));
- return ints.toArray(new Object[ints.size()]);
- } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
- List<Object> longs = new LinkedList<Object>();
- for (String value : values)
- longs.add(new Long(value));
- return longs.toArray(new Object[longs.size()]);
- } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
- List<Object> doubles = new LinkedList<Object>();
- for (String value : values)
- doubles.add(new Double(value));
- return doubles.toArray(new Object[doubles.size()]);
- } else if (type.equals(String.class)) {
- StringBuffer combinedString = new StringBuffer("");
- for (String value : values)
- combinedString.append(value + " ");
- return new String[] { combinedString.toString().trim() };
- } else {
- return values.toArray(new Object[values.size()]);
- }
- }
-
-}
+/*
+ * 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.commons.option.handler;
+
+//JDK imports
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+//OODT imports
+import org.apache.oodt.commons.option.CmdLineOption;
+import org.apache.oodt.commons.option.CmdLineOptionInstance;
+import org.apache.oodt.commons.spring.SpringSetIdInjectionType;
+
+//Spring imports
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Required;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class CmdLineOptionBeanHandler extends CmdLineOptionHandler {
+
+ private List<BeanInfo> applyToBeans;
+
+ @Required
+ public void setApplyToBeans(List<BeanInfo> applyToBeans) {
+ this.applyToBeans = applyToBeans;
+ }
+
+ public void handleOption(CmdLineOption option, List<String> values) {
+ try {
+ for (BeanInfo applyToBean : this.applyToBeans) {
+ Class type = (option.getType() != null) ? option.getType()
+ : String.class;
+ Object[] vals = null;
+ if (values.size() != 0) {
+ vals = this.convertToType(values, type);
+ } else {
+ vals = this.convertToType(Arrays
+ .asList(new String[] { "true" }), type =
Boolean.TYPE);
+ }
+ try {
+ if (applyToBean.getMethodName() != null) {
+ applyToBean.getBean().getClass().getMethod(
+ applyToBean.getMethodName(), type).invoke(
+ applyToBean.getBean(), vals);
+ } else {
+ applyToBean.getBean().getClass().getMethod(
+ "set" + StringUtils.capitalize(option.getId()),
+ type).invoke(applyToBean.getBean(), vals);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public String getCustomOptionUsage(CmdLineOption option) {
+ Set<String> affectedClasses = new HashSet<String>();
+ for (BeanInfo beanInfo : applyToBeans) {
+ if (beanInfo.getBean() instanceof SpringSetIdInjectionType)
+ affectedClasses.add(((SpringSetIdInjectionType) beanInfo
+ .getBean()).getId());
+ else
+ affectedClasses.add(beanInfo.getBean().getClass().getName());
+ }
+ return "Affects: " + affectedClasses.toString();
+ }
+
+ private Object[] convertToType(List<String> values, Class type)
+ throws MalformedURLException, ClassNotFoundException {
+ if (type.equals(File.class)) {
+ List<Object> files = new LinkedList<Object>();
+ for (String value : values)
+ files.add(new File(value));
+ return files.toArray(new Object[files.size()]);
+ } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
+ List<Object> booleans = new LinkedList<Object>();
+ for (String value : values)
+ booleans.add(value.toLowerCase().trim().equals("true"));
+ return booleans.toArray(new Object[booleans.size()]);
+ } else if (type.equals(URL.class)) {
+ List<Object> urls = new LinkedList<Object>();
+ for (String value : values)
+ urls.add(new URL(value));
+ return urls.toArray(new Object[urls.size()]);
+ } else if (type.equals(Class.class)) {
+ List<Object> classes = new LinkedList<Object>();
+ for (String value : values)
+ classes.add(Class.forName(value));
+ return classes.toArray(new Object[classes.size()]);
+ } else if (type.equals(List.class)) {
+ return new Object[] { values };
+ } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
+ List<Object> ints = new LinkedList<Object>();
+ for (String value : values)
+ ints.add(new Integer(value));
+ return ints.toArray(new Object[ints.size()]);
+ } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
+ List<Object> longs = new LinkedList<Object>();
+ for (String value : values)
+ longs.add(new Long(value));
+ return longs.toArray(new Object[longs.size()]);
+ } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
+ List<Object> doubles = new LinkedList<Object>();
+ for (String value : values)
+ doubles.add(new Double(value));
+ return doubles.toArray(new Object[doubles.size()]);
+ } else if (type.equals(String.class)) {
+ StringBuffer combinedString = new StringBuffer("");
+ for (String value : values)
+ combinedString.append(value + " ");
+ return new String[] { combinedString.toString().trim() };
+ } else {
+ return values.toArray(new Object[values.size()]);
+ }
+ }
+
+ @Override
+ public boolean affectsOption(CmdLineOptionInstance optionInstance) {
+ for (BeanInfo beanInfo : this.applyToBeans)
+ if (beanInfo.getBean() instanceof SpringSetIdInjectionType)
+ if (((SpringSetIdInjectionType)
beanInfo.getBean()).getId().equals(optionInstance.getValues().get(0)))
+ return true;
+ return false;
+ }
+
+}
Modified:
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionHandler.java
(original)
+++
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/CmdLineOptionHandler.java
Fri Dec 17 01:26:45 2010
@@ -1,57 +1,60 @@
-/*
- * 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.commons.option.handler;
-
-//JDK imports
-import java.util.List;
-
-//OODT imports
-import org.apache.oodt.commons.option.CmdLineOption;
-
-//Spring imports
-import org.apache.commons.lang.StringUtils;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public abstract class CmdLineOptionHandler {
-
- public String getOptionUsage(CmdLineOption option) {
- String argName = option.hasArgs() ? " <" + option.getOptionArgName()
- + ">" : "";
- String outputString = " -"
- + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--"
- + StringUtils.rightPad((option.getLongOption() + argName), 49)
- + option.getDescription();
- if (!option.isRequired())
- outputString = "[" + outputString.substring(1) + "]";
- else if (option.getRequiredOptions().size() > 0)
- outputString = "{" + outputString.substring(1) + "}";
- return outputString;
- }
-
- public abstract void handleOption(CmdLineOption option, List<String>
values);
-
- public abstract String getCustomOptionUsage(CmdLineOption option);
-
-}
+/*
+ * 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.commons.option.handler;
+
+//JDK imports
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.commons.option.CmdLineOption;
+import org.apache.oodt.commons.option.CmdLineOptionInstance;
+
+//Spring imports
+import org.apache.commons.lang.StringUtils;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public abstract class CmdLineOptionHandler {
+
+ public String getOptionUsage(CmdLineOption option) {
+ String argName = option.hasArgs() ? " <" + option.getOptionArgName()
+ + ">" : "";
+ String outputString = " -"
+ + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--"
+ + StringUtils.rightPad((option.getLongOption() + argName), 49)
+ + option.getDescription();
+ if (!option.isRequired())
+ outputString = "[" + outputString.substring(1) + "]";
+ else if (option.getRequiredOptions().size() > 0)
+ outputString = "{" + outputString.substring(1) + "}";
+ return outputString;
+ }
+
+ public abstract void handleOption(CmdLineOption option, List<String>
values);
+
+ public abstract String getCustomOptionUsage(CmdLineOption option);
+
+ public abstract boolean affectsOption(CmdLineOptionInstance
optionInstance);
+
+}
Modified:
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/StdCmdLineOptionHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/StdCmdLineOptionHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/StdCmdLineOptionHandler.java
(original)
+++
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/handler/StdCmdLineOptionHandler.java
Fri Dec 17 01:26:45 2010
@@ -1,45 +1,52 @@
-/*
- * 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.commons.option.handler;
-
-//JDK imports
-import java.util.List;
-
-import org.apache.oodt.commons.option.CmdLineOption;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class StdCmdLineOptionHandler extends CmdLineOptionHandler {
-
- @Override
- public String getCustomOptionUsage(CmdLineOption option) {
- return "";
- }
-
- @Override
- public void handleOption(CmdLineOption option, List<String> values) {
- // do nothing
- }
-
-}
+/*
+ * 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.commons.option.handler;
+
+//JDK imports
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.commons.option.CmdLineOption;
+import org.apache.oodt.commons.option.CmdLineOptionInstance;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class StdCmdLineOptionHandler extends CmdLineOptionHandler {
+
+ @Override
+ public String getCustomOptionUsage(CmdLineOption option) {
+ return "";
+ }
+
+ @Override
+ public void handleOption(CmdLineOption option, List<String> values) {
+ // do nothing
+ }
+
+ @Override
+ public boolean affectsOption(CmdLineOptionInstance optionInstance) {
+ return false;
+ }
+
+}
Modified:
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/parser/CmdLineOptionParser.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/parser/CmdLineOptionParser.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/parser/CmdLineOptionParser.java
(original)
+++
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/parser/CmdLineOptionParser.java
Fri Dec 17 01:26:45 2010
@@ -1,109 +1,117 @@
-/*
- * 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.commons.option.parser;
-
-//JDK imports
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.LinkedList;
-import java.util.List;
-
-//OODT imports
-import org.apache.oodt.commons.option.CmdLineOption;
-import org.apache.oodt.commons.option.CmdLineOptionInstance;
-import org.apache.oodt.commons.option.util.CmdLineOptionUtils;
-import org.apache.oodt.commons.option.util.CmdLineOptionsUsagePrinter;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class CmdLineOptionParser {
-
- private List<CmdLineOption> validOptions;
-
- public List<CmdLineOption> getValidOptions() {
- return validOptions;
- }
-
- public void setValidOptions(List<CmdLineOption> validOptions) {
- this.validOptions = validOptions;
- }
-
- public List<CmdLineOptionInstance> parse(String[] args) throws IOException
{
- List<CmdLineOptionInstance> optionInstances = new
LinkedList<CmdLineOptionInstance>();
- if (args.length < 1)
- throw new IOException(
- "Must specify options : type -h or --help for info");
-
- for (int j = 0; j < args.length; j++) {
- String curArg = args[j];
-
- // print usage and quit if -h or --help is given
- if (curArg.equals("-h") || curArg.equals("--help")) {
- CmdLineOptionsUsagePrinter.printUsage(new PrintStream(
- System.out), this.validOptions);
- System.exit(0);
- }
-
- if (curArg.startsWith("-")) {
- // check if long or short version was used
- if (curArg.startsWith("--"))
- curArg = curArg.substring(2);
- else
- curArg = curArg.substring(1);
-
- // check if option is a valid one
- CmdLineOption curOption = CmdLineOptionUtils.getOptionByName(
- curArg, validOptions);
- if (curOption == null)
- throw new IOException("Invalid option '" + curArg + "'");
-
- // check if option has arguments
- List<String> values = new LinkedList<String>();
- if (curOption.hasArgs()) {
- while (j + 1 < args.length && !args[j + 1].startsWith("-"))
- values.add(args[++j]);
- if (values.size() < 1)
- throw new IOException("Option " + curArg
- + " should have at least one argument");
- }
-
- //check if is a perform and quit option
- if (curOption.isPerformAndQuit()) {
- curOption.getHandler().handleOption(curOption, values);
- System.exit(0);
- }
-
- // add to list of option instances
- optionInstances
- .add(new CmdLineOptionInstance(curOption, values));
-
- } else {
- throw new IOException("Argument with no option flag '" + curArg
- + "'");
- }
- }
- return optionInstances;
- }
-
-}
+/*
+ * 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.commons.option.parser;
+
+//JDK imports
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.LinkedList;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.commons.option.CmdLineOption;
+import org.apache.oodt.commons.option.CmdLineOptionInstance;
+import org.apache.oodt.commons.option.util.CmdLineOptionUtils;
+import org.apache.oodt.commons.option.util.CmdLineOptionsUsagePrinter;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class CmdLineOptionParser {
+
+ private List<CmdLineOption> validOptions;
+
+ public List<CmdLineOption> getValidOptions() {
+ return validOptions;
+ }
+
+ public void setValidOptions(List<CmdLineOption> validOptions) {
+ this.validOptions = validOptions;
+ }
+
+ public List<CmdLineOptionInstance> parse(String[] args) throws IOException
{
+ List<CmdLineOptionInstance> optionInstances = new
LinkedList<CmdLineOptionInstance>();
+ if (args.length < 1)
+ throw new IOException(
+ "Must specify options : type -h or --help for info");
+
+ for (int j = 0; j < args.length; j++) {
+ String curArg = args[j];
+
+ // print usage and quit if -h or --help is given
+ if (curArg.equals("-h") || curArg.equals("--help")) {
+ if (args.length > j+1) {
+ String[] helpArgs = new String[args.length - j - 1];
+ System.arraycopy(args, j + 1, helpArgs, 0,
helpArgs.length);
+ CmdLineOptionsUsagePrinter.printUsage(new PrintStream(
+ System.out), this.validOptions,
this.parse(helpArgs).get(0));
+ }else {
+ CmdLineOptionsUsagePrinter.printUsage(new PrintStream(
+ System.out), this.validOptions);
+ }
+ System.exit(0);
+ }
+
+
+ if (curArg.startsWith("-")) {
+ // check if long or short version was used
+ if (curArg.startsWith("--"))
+ curArg = curArg.substring(2);
+ else
+ curArg = curArg.substring(1);
+
+ // check if option is a valid one
+ CmdLineOption curOption = CmdLineOptionUtils.getOptionByName(
+ curArg, validOptions);
+ if (curOption == null)
+ throw new IOException("Invalid option '" + curArg + "'");
+
+ // check if option has arguments
+ List<String> values = new LinkedList<String>();
+ if (curOption.hasArgs()) {
+ while (j + 1 < args.length && !args[j + 1].startsWith("-"))
+ values.add(args[++j]);
+ if (values.size() < 1)
+ throw new IOException("Option " + curArg
+ + " should have at least one argument");
+ }
+
+ //check if is a perform and quit option
+ if (curOption.isPerformAndQuit()) {
+ curOption.getHandler().handleOption(curOption, values);
+ System.exit(0);
+ }
+
+ // add to list of option instances
+ optionInstances
+ .add(new CmdLineOptionInstance(curOption, values));
+
+ } else {
+ throw new IOException("Argument with no option flag '" + curArg
+ + "'");
+ }
+ }
+ return optionInstances;
+ }
+
+}
Modified:
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/util/CmdLineOptionsUsagePrinter.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/util/CmdLineOptionsUsagePrinter.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/util/CmdLineOptionsUsagePrinter.java
(original)
+++
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/option/util/CmdLineOptionsUsagePrinter.java
Fri Dec 17 01:26:45 2010
@@ -1,95 +1,119 @@
-/*
- * 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.commons.option.util;
-
-//JDK imports
-import java.io.PrintStream;
-import java.util.Collections;
-import java.util.List;
-
-//OODT imports
-import org.apache.oodt.commons.option.CmdLineOption;
-
-//Spring imports
-import org.apache.commons.lang.StringUtils;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class CmdLineOptionsUsagePrinter {
-
- private CmdLineOptionsUsagePrinter() {
- }
-
- public static void printUsage(PrintStream ps, List<CmdLineOption> options)
{
- ps.println(createPrintableHeader(options));
- }
-
- private static String createPrintableHeader(List<CmdLineOption> options) {
- sortOptions(options);
- StringBuffer outputString = new StringBuffer(
-
"-----------------------------------------------------------------------------------------------------------------\n");
- outputString.append("|" + StringUtils.rightPad(" Short", 7) + "|"
- + StringUtils.rightPad(" Long", 50) + "| Description\n");
- outputString
-
.append("-----------------------------------------------------------------------------------------------------------------\n");
- for (CmdLineOption option : options) {
- outputString.append(option.getHandler().getOptionUsage(option)
- + "\n"
- + getFormattedString(option.getHandler()
- .getCustomOptionUsage(option), 62, 139));
- if (option.getRequiredOptions().size() > 0)
- outputString.append(getFormattedString("RequiredOptions: "
- + option.getRequiredOptions() + "\n", 62, 139));
- else
- outputString.append("\n");
- }
- outputString
-
.append("-----------------------------------------------------------------------------------------------------------------");
- return outputString.toString();
- }
-
- private static void sortOptions(List<CmdLineOption> options) {
- Collections.sort(options);
- }
-
- private static String getFormattedString(String string, int startIndex,
- int endIndex) {
- StringBuffer outputString = new StringBuffer("");
- String[] splitStrings = StringUtils.split(string, " ");
- StringBuffer curLine = null;
- for (int i = 0; i < splitStrings.length; i++) {
- curLine = new StringBuffer("");
- curLine.append(splitStrings[i] + " ");
-
- for (; i + 1 < splitStrings.length
- && curLine.length() + splitStrings[i + 1].length() <=
(endIndex - startIndex); i++)
- curLine.append(splitStrings[i + 1] + " ");
-
- outputString.append(StringUtils.repeat(" ", startIndex)
- + curLine.toString() + "\n");
- }
- return outputString.toString();
- }
-
-}
+/*
+ * 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.commons.option.util;
+
+//JDK imports
+import java.io.PrintStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Vector;
+
+//OODT imports
+import org.apache.oodt.commons.option.CmdLineOption;
+import org.apache.oodt.commons.option.CmdLineOptionInstance;
+import org.apache.oodt.commons.option.required.RequiredOption;
+
+//Spring imports
+import org.apache.commons.lang.StringUtils;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class CmdLineOptionsUsagePrinter {
+
+ private CmdLineOptionsUsagePrinter() {
+ }
+
+ public static void printUsage(PrintStream ps, List<CmdLineOption> options)
{
+ ps.println(createPrintableHeader(options));
+ }
+
+ public static void printUsage(PrintStream ps, List<CmdLineOption> options,
CmdLineOptionInstance optionHelp) {
+ ps.println("Option Help when option '--" +
optionHelp.getOption().getLongOption() + "' is specified with values " +
optionHelp.getValues());
+ ps.println(" - Required:");
+ Vector<CmdLineOption> required = new Vector<CmdLineOption>();
+ for (CmdLineOption option : options) {
+ for (RequiredOption reqOption : option.getRequiredOptions()) {
+ if
(reqOption.getOptionLongName().equals(optionHelp.getOption().getLongOption())
&& reqOption.getOptionValues().containsAll(optionHelp.getValues())) {
+ required.add(option);
+ ps.println(" -" + option.getShortOption() +
" [--" + option.getLongOption() + "] " + (option.hasArgs() ? "<" +
option.getOptionArgName() + ">" : ""));
+ break;
+ }
+ }
+ }
+ ps.println(" - Optional:");
+ for (CmdLineOption option : options) {
+ if (!required.contains(option) &&
option.getHandler().affectsOption(optionHelp))
+ ps.println(" -" + option.getShortOption() +
" [--" + option.getLongOption() + "] " + (option.hasArgs() ? "<" +
option.getOptionArgName() + ">" : ""));
+ }
+ }
+
+
+ private static String createPrintableHeader(List<CmdLineOption> options) {
+ sortOptions(options);
+ StringBuffer outputString = new StringBuffer(
+
"-----------------------------------------------------------------------------------------------------------------\n");
+ outputString.append("|" + StringUtils.rightPad(" Short", 7) + "|"
+ + StringUtils.rightPad(" Long", 50) + "| Description\n");
+ outputString
+
.append("-----------------------------------------------------------------------------------------------------------------\n");
+ for (CmdLineOption option : options) {
+ outputString.append(option.getHandler().getOptionUsage(option)
+ + "\n"
+ + getFormattedString(option.getHandler()
+ .getCustomOptionUsage(option), 62, 139));
+ if (option.getRequiredOptions().size() > 0)
+ outputString.append(getFormattedString("RequiredOptions: "
+ + option.getRequiredOptions() + "\n", 62, 139));
+ else
+ outputString.append("\n");
+ }
+ outputString
+
.append("-----------------------------------------------------------------------------------------------------------------");
+ return outputString.toString();
+ }
+
+ private static void sortOptions(List<CmdLineOption> options) {
+ Collections.sort(options);
+ }
+
+ private static String getFormattedString(String string, int startIndex,
+ int endIndex) {
+ StringBuffer outputString = new StringBuffer("");
+ String[] splitStrings = StringUtils.split(string, " ");
+ StringBuffer curLine = null;
+ for (int i = 0; i < splitStrings.length; i++) {
+ curLine = new StringBuffer("");
+ curLine.append(splitStrings[i] + " ");
+
+ for (; i + 1 < splitStrings.length
+ && curLine.length() + splitStrings[i + 1].length() <=
(endIndex - startIndex); i++)
+ curLine.append(splitStrings[i + 1] + " ");
+
+ outputString.append(StringUtils.repeat(" ", startIndex)
+ + curLine.toString() + "\n");
+ }
+ return outputString.toString();
+ }
+
+}
Modified:
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionCrawlerActionInfoHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionCrawlerActionInfoHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionCrawlerActionInfoHandler.java
(original)
+++
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionCrawlerActionInfoHandler.java
Fri Dec 17 01:26:45 2010
@@ -23,9 +23,10 @@ import java.io.PrintStream;
import java.util.List;
//OODT imports
-import org.apache.oodt.commons.option.CmdLineOption;
import org.apache.oodt.cas.crawl.action.CrawlerAction;
import org.apache.oodt.cas.crawl.action.MimeTypeCrawlerAction;
+import org.apache.oodt.commons.option.CmdLineOption;
+import org.apache.oodt.commons.option.CmdLineOptionInstance;
/**
*
@@ -63,4 +64,9 @@ public class CmdLineOptionCrawlerActionI
ps.close();
}
+ @Override
+ public boolean affectsOption(CmdLineOptionInstance arg0) {
+ return false;
+ }
+
}
Modified:
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionJavaPropHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionJavaPropHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionJavaPropHandler.java
(original)
+++
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionJavaPropHandler.java
Fri Dec 17 01:26:45 2010
@@ -21,7 +21,9 @@ package org.apache.oodt.cas.crawl.option
//JDK imports
import java.util.List;
+//OODT imports
import org.apache.oodt.commons.option.CmdLineOption;
+import org.apache.oodt.commons.option.CmdLineOptionInstance;
import org.apache.oodt.commons.option.handler.CmdLineOptionHandler;
//Spring imports
@@ -50,4 +52,9 @@ public class CmdLineOptionJavaPropHandle
+ option.getLongOption();
}
+ @Override
+ public boolean affectsOption(CmdLineOptionInstance arg0) {
+ return false;
+ }
+
}
Modified:
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionPreconditionInfoHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionPreconditionInfoHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionPreconditionInfoHandler.java
(original)
+++
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionPreconditionInfoHandler.java
Fri Dec 17 01:26:45 2010
@@ -24,6 +24,7 @@ import java.util.List;
//OODT imports
import org.apache.oodt.commons.option.CmdLineOption;
+import org.apache.oodt.commons.option.CmdLineOptionInstance;
import org.apache.oodt.cas.metadata.preconditions.PreConditionComparator;
/**
@@ -57,5 +58,10 @@ public class CmdLineOptionPreconditionIn
}
ps.close();
}
+
+ @Override
+ public boolean affectsOption(CmdLineOptionInstance arg0) {
+ return false;
+ }
}
Modified:
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionProductCrawlerInfoHandler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionProductCrawlerInfoHandler.java?rev=1050261&r1=1050260&r2=1050261&view=diff
==============================================================================
---
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionProductCrawlerInfoHandler.java
(original)
+++
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/option/CmdLineOptionProductCrawlerInfoHandler.java
Fri Dec 17 01:26:45 2010
@@ -24,6 +24,7 @@ import java.util.List;
//OODT imports
import org.apache.oodt.commons.option.CmdLineOption;
+import org.apache.oodt.commons.option.CmdLineOptionInstance;
import org.apache.oodt.cas.crawl.ProductCrawler;
/**
@@ -56,4 +57,9 @@ public class CmdLineOptionProductCrawler
ps.close();
}
+ @Override
+ public boolean affectsOption(CmdLineOptionInstance arg0) {
+ return false;
+ }
+
}