Author: mostarda
Date: Tue Apr 10 22:21:51 2012
New Revision: 1312023
URL: http://svn.apache.org/viewvc?rev=1312023&view=rev
Log:
Added (dirty) solution for fixing support of --plugins-dir option. This commit is related
to issue #ANY23-73.
Modified:
incubator/any23/trunk/core/src/main/java/org/apache/any23/cli/ToolRunner.java
Modified: incubator/any23/trunk/core/src/main/java/org/apache/any23/cli/ToolRunner.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/main/java/org/apache/any23/cli/ToolRunner.java?rev=1312023&r1=1312022&r2=1312023&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/main/java/org/apache/any23/cli/ToolRunner.java (original)
+++ incubator/any23/trunk/core/src/main/java/org/apache/any23/cli/ToolRunner.java Tue Apr
10 22:21:51 2012
@@ -45,6 +45,8 @@ import static java.lang.System.exit;
*/
public final class ToolRunner {
+ public static final File DEFAULT_PLUGIN_DIR = new File(new File(System.getProperty("user.home")),
".any23/plugins");
+
private static final PrintStream infoStream = System.err;
@Parameter( names = { "-h", "--help" }, description = "Display help information." )
@@ -57,7 +59,7 @@ public final class ToolRunner {
private boolean verbose;
@Parameter( names = { "-p", "--plugins-dir" }, description = "The Any23 plugins directory.",
converter = FileConverter.class )
- private File pluginsDir = new File(new File(System.getProperty("user.home")), ".any23/plugins");
+ private File pluginsDir = DEFAULT_PLUGIN_DIR;
public static void main( String[] args ) throws Exception {
exit( new ToolRunner().execute( args ) );
@@ -67,6 +69,13 @@ public final class ToolRunner {
JCommander commander = new JCommander(this);
commander.setProgramName(System.getProperty("app.name"));
+ // TODO (low) : this dirty solution has been introduced because it is not possible
to
+ // parse arguments ( commander.parse() ) twice.
+ final File pluginsDirOption = parsePluginDirOption(args);
+ if(pluginsDirOption != null) {
+ pluginsDir = pluginsDirOption;
+ }
+
// add all plugins first
final Iterator<Tool> tools = getToolsInClasspath();
while (tools.hasNext()) {
@@ -220,4 +229,25 @@ public final class ToolRunner {
return "undefined";
}
+ private static File parsePluginDirOption(String[] args) {
+ int optionIndex = -1;
+ for(int i = 0; i < args.length; i++) {
+ if("-p".equals(args[i]) || "--plugins-dir".equals(args[i])) {
+ optionIndex = i;
+ }
+ }
+ if(optionIndex == -1) return null;
+
+ if(optionIndex == args.length - 1) {
+ System.err.println("Missing argument for --plugins-dir option.");
+ System.exit(1);
+ }
+ final File pluginsDir = new File( args[optionIndex + 1] );
+ if( ! pluginsDir.isDirectory() ) {
+ System.err.println("Expected a directory for --plugins-dir option value.");
+ System.exit(1);
+ }
+ return pluginsDir;
+ }
+
}
|