List of usage examples for org.apache.commons.cli Option UNLIMITED_VALUES
int UNLIMITED_VALUES
To view the source code for org.apache.commons.cli Option UNLIMITED_VALUES.
Click Source Link
From source file:org.diqube.tool.merge.Merge.java
private Options createCliOptions() { Options res = new Options(); res.addOption(Option.builder(OPT_INPUT).longOpt("input").numberOfArgs(Option.UNLIMITED_VALUES) .argName("file> <file> <...") .desc("The input file(s) to read from (.diqube format, at least one required).").required() .build());//from w ww. j a v a 2 s.co m res.addOption(Option.builder(OPT_OUTPUT).longOpt("output").numberOfArgs(1).argName("file") .desc("Output file name (required).").required().build()); res.addOption(Option.builder(OPT_COMMENT).longOpt("comment").numberOfArgs(1).argName("string") .desc("Comment to write into the output file.").build()); res.addOption(Option.builder(OPT_HELP).longOpt("help").desc("Show this help.").build()); return res; }
From source file:org.dspace.app.mediafilter.MediaFilterCLITool.java
public static void main(String[] argv) throws Exception { // set headless for non-gui workstations System.setProperty("java.awt.headless", "true"); // create an options object and populate it CommandLineParser parser = new PosixParser(); int status = 0; Options options = new Options(); options.addOption("v", "verbose", false, "print all extracted text and other details to STDOUT"); options.addOption("q", "quiet", false, "do not print anything except in the event of errors."); options.addOption("f", "force", false, "force all bitstreams to be processed"); options.addOption("i", "identifier", true, "ONLY process bitstreams belonging to identifier"); options.addOption("m", "maximum", true, "process no more than maximum items"); options.addOption("h", "help", false, "help"); //create a "plugin" option (to specify specific MediaFilter plugins to run) OptionBuilder.withLongOpt("plugins"); OptionBuilder.withValueSeparator(','); OptionBuilder.withDescription("ONLY run the specified Media Filter plugin(s)\n" + "listed from '" + MEDIA_FILTER_PLUGINS_KEY + "' in dspace.cfg.\n" + "Separate multiple with a comma (,)\n" + "(e.g. MediaFilterManager -p \n\"Word Text Extractor\",\"PDF Text Extractor\")"); Option pluginOption = OptionBuilder.create('p'); pluginOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args options.addOption(pluginOption);/* w ww .ja v a 2s . c om*/ //create a "skip" option (to specify communities/collections/items to skip) OptionBuilder.withLongOpt("skip"); OptionBuilder.withValueSeparator(','); OptionBuilder.withDescription( "SKIP the bitstreams belonging to identifier\n" + "Separate multiple identifiers with a comma (,)\n" + "(e.g. MediaFilterManager -s \n 123456789/34,123456789/323)"); Option skipOption = OptionBuilder.create('s'); skipOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args options.addOption(skipOption); boolean isVerbose = false; boolean isQuiet = false; boolean isForce = false; // default to not forced String identifier = null; // object scope limiter int max2Process = Integer.MAX_VALUE; Map<String, List<String>> filterFormats = new HashMap<>(); CommandLine line = null; try { line = parser.parse(options, argv); } catch (MissingArgumentException e) { System.out.println("ERROR: " + e.getMessage()); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(1); } if (line.hasOption('h')) { HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(0); } if (line.hasOption('v')) { isVerbose = true; } isQuiet = line.hasOption('q'); if (line.hasOption('f')) { isForce = true; } if (line.hasOption('i')) { identifier = line.getOptionValue('i'); } if (line.hasOption('m')) { max2Process = Integer.parseInt(line.getOptionValue('m')); if (max2Process <= 1) { System.out.println("Invalid maximum value '" + line.getOptionValue('m') + "' - ignoring"); max2Process = Integer.MAX_VALUE; } } String filterNames[] = null; if (line.hasOption('p')) { //specified which media filter plugins we are using filterNames = line.getOptionValues('p'); if (filterNames == null || filterNames.length == 0) { //display error, since no plugins specified System.err.println("\nERROR: -p (-plugin) option requires at least one plugin to be specified.\n" + "(e.g. MediaFilterManager -p \"Word Text Extractor\",\"PDF Text Extractor\")\n"); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(1); } } else { //retrieve list of all enabled media filter plugins! filterNames = DSpaceServicesFactory.getInstance().getConfigurationService() .getArrayProperty(MEDIA_FILTER_PLUGINS_KEY); } MediaFilterService mediaFilterService = MediaFilterServiceFactory.getInstance().getMediaFilterService(); mediaFilterService.setForce(isForce); mediaFilterService.setQuiet(isQuiet); mediaFilterService.setVerbose(isVerbose); mediaFilterService.setMax2Process(max2Process); //initialize an array of our enabled filters List<FormatFilter> filterList = new ArrayList<FormatFilter>(); //set up each filter for (int i = 0; i < filterNames.length; i++) { //get filter of this name & add to list of filters FormatFilter filter = (FormatFilter) CoreServiceFactory.getInstance().getPluginService() .getNamedPlugin(FormatFilter.class, filterNames[i]); if (filter == null) { System.err.println( "\nERROR: Unknown MediaFilter specified (either from command-line or in dspace.cfg): '" + filterNames[i] + "'"); System.exit(1); } else { filterList.add(filter); String filterClassName = filter.getClass().getName(); String pluginName = null; //If this filter is a SelfNamedPlugin, //then the input formats it accepts may differ for //each "named" plugin that it defines. //So, we have to look for every key that fits the //following format: filter.<class-name>.<plugin-name>.inputFormats if (SelfNamedPlugin.class.isAssignableFrom(filter.getClass())) { //Get the plugin instance name for this class pluginName = ((SelfNamedPlugin) filter).getPluginInstanceName(); } //Retrieve our list of supported formats from dspace.cfg //For SelfNamedPlugins, format of key is: // filter.<class-name>.<plugin-name>.inputFormats //For other MediaFilters, format of key is: // filter.<class-name>.inputFormats String[] formats = DSpaceServicesFactory.getInstance().getConfigurationService() .getArrayProperty(FILTER_PREFIX + "." + filterClassName + (pluginName != null ? "." + pluginName : "") + "." + INPUT_FORMATS_SUFFIX); //add to internal map of filters to supported formats if (ArrayUtils.isNotEmpty(formats)) { //For SelfNamedPlugins, map key is: // <class-name><separator><plugin-name> //For other MediaFilters, map key is just: // <class-name> filterFormats.put(filterClassName + (pluginName != null ? MediaFilterService.FILTER_PLUGIN_SEPARATOR + pluginName : ""), Arrays.asList(formats)); } } //end if filter!=null } //end for //If verbose, print out loaded mediafilter info if (isVerbose) { System.out.println("The following MediaFilters are enabled: "); Iterator<String> i = filterFormats.keySet().iterator(); while (i.hasNext()) { String filterName = i.next(); System.out.println("Full Filter Name: " + filterName); String pluginName = null; if (filterName.contains(MediaFilterService.FILTER_PLUGIN_SEPARATOR)) { String[] fields = filterName.split(MediaFilterService.FILTER_PLUGIN_SEPARATOR); filterName = fields[0]; pluginName = fields[1]; } System.out.println(filterName + (pluginName != null ? " (Plugin: " + pluginName + ")" : "")); } } mediaFilterService.setFilterFormats(filterFormats); //store our filter list into an internal array mediaFilterService.setFilterClasses(filterList); //Retrieve list of identifiers to skip (if any) String skipIds[] = null; if (line.hasOption('s')) { //specified which identifiers to skip when processing skipIds = line.getOptionValues('s'); if (skipIds == null || skipIds.length == 0) { //display error, since no identifiers specified to skip System.err.println("\nERROR: -s (-skip) option requires at least one identifier to SKIP.\n" + "Make sure to separate multiple identifiers with a comma!\n" + "(e.g. MediaFilterManager -s 123456789/34,123456789/323)\n"); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(0); } //save to a global skip list mediaFilterService.setSkipList(Arrays.asList(skipIds)); } Context c = null; try { c = new Context(); // have to be super-user to do the filtering c.turnOffAuthorisationSystem(); // now apply the filters if (identifier == null) { mediaFilterService.applyFiltersAllItems(c); } else // restrict application scope to identifier { DSpaceObject dso = HandleServiceFactory.getInstance().getHandleService().resolveToObject(c, identifier); if (dso == null) { throw new IllegalArgumentException("Cannot resolve " + identifier + " to a DSpace object"); } switch (dso.getType()) { case Constants.COMMUNITY: mediaFilterService.applyFiltersCommunity(c, (Community) dso); break; case Constants.COLLECTION: mediaFilterService.applyFiltersCollection(c, (Collection) dso); break; case Constants.ITEM: mediaFilterService.applyFiltersItem(c, (Item) dso); break; } } c.complete(); c = null; } catch (Exception e) { status = 1; } finally { if (c != null) { c.abort(); } } System.exit(status); }
From source file:org.dspace.app.mediafilter.MediaFilterManager.java
public static void main(String[] argv) throws Exception { // set headless for non-gui workstations System.setProperty("java.awt.headless", "true"); // create an options object and populate it CommandLineParser parser = new PosixParser(); int status = 0; Options options = new Options(); options.addOption("v", "verbose", false, "print all extracted text and other details to STDOUT"); options.addOption("q", "quiet", false, "do not print anything except in the event of errors."); options.addOption("f", "force", false, "force all bitstreams to be processed"); options.addOption("n", "noindex", false, "do NOT update the search index after filtering bitstreams"); options.addOption("i", "identifier", true, "ONLY process bitstreams belonging to identifier"); options.addOption("m", "maximum", true, "process no more than maximum items"); options.addOption("h", "help", false, "help"); //create a "plugin" option (to specify specific MediaFilter plugins to run) OptionBuilder.withLongOpt("plugins"); OptionBuilder.withValueSeparator(','); OptionBuilder.withDescription("ONLY run the specified Media Filter plugin(s)\n" + "listed from '" + MEDIA_FILTER_PLUGINS_KEY + "' in dspace.cfg.\n" + "Separate multiple with a comma (,)\n" + "(e.g. MediaFilterManager -p \n\"Word Text Extractor\",\"PDF Text Extractor\")"); Option pluginOption = OptionBuilder.create('p'); pluginOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args options.addOption(pluginOption);//w ww . j av a2s. co m //create a "skip" option (to specify communities/collections/items to skip) OptionBuilder.withLongOpt("skip"); OptionBuilder.withValueSeparator(','); OptionBuilder.withDescription( "SKIP the bitstreams belonging to identifier\n" + "Separate multiple identifiers with a comma (,)\n" + "(e.g. MediaFilterManager -s \n 123456789/34,123456789/323)"); Option skipOption = OptionBuilder.create('s'); skipOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args options.addOption(skipOption); CommandLine line = null; try { line = parser.parse(options, argv); } catch (MissingArgumentException e) { System.out.println("ERROR: " + e.getMessage()); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(1); } if (line.hasOption('h')) { HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(0); } if (line.hasOption('v')) { isVerbose = true; } isQuiet = line.hasOption('q'); if (line.hasOption('n')) { updateIndex = false; } if (line.hasOption('f')) { isForce = true; } if (line.hasOption('i')) { identifier = line.getOptionValue('i'); } if (line.hasOption('m')) { max2Process = Integer.parseInt(line.getOptionValue('m')); if (max2Process <= 1) { System.out.println("Invalid maximum value '" + line.getOptionValue('m') + "' - ignoring"); max2Process = Integer.MAX_VALUE; } } String filterNames[] = null; if (line.hasOption('p')) { //specified which media filter plugins we are using filterNames = line.getOptionValues('p'); if (filterNames == null || filterNames.length == 0) { //display error, since no plugins specified System.err.println("\nERROR: -p (-plugin) option requires at least one plugin to be specified.\n" + "(e.g. MediaFilterManager -p \"Word Text Extractor\",\"PDF Text Extractor\")\n"); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(1); } } else { //retrieve list of all enabled media filter plugins! String enabledPlugins = ConfigurationManager.getProperty(MEDIA_FILTER_PLUGINS_KEY); filterNames = enabledPlugins.split(",\\s*"); } //initialize an array of our enabled filters List<FormatFilter> filterList = new ArrayList<FormatFilter>(); //set up each filter for (int i = 0; i < filterNames.length; i++) { //get filter of this name & add to list of filters FormatFilter filter = (FormatFilter) PluginManager.getNamedPlugin(FormatFilter.class, filterNames[i]); if (filter == null) { System.err.println( "\nERROR: Unknown MediaFilter specified (either from command-line or in dspace.cfg): '" + filterNames[i] + "'"); System.exit(1); } else { filterList.add(filter); String filterClassName = filter.getClass().getName(); String pluginName = null; //If this filter is a SelfNamedPlugin, //then the input formats it accepts may differ for //each "named" plugin that it defines. //So, we have to look for every key that fits the //following format: filter.<class-name>.<plugin-name>.inputFormats if (SelfNamedPlugin.class.isAssignableFrom(filter.getClass())) { //Get the plugin instance name for this class pluginName = ((SelfNamedPlugin) filter).getPluginInstanceName(); } //Retrieve our list of supported formats from dspace.cfg //For SelfNamedPlugins, format of key is: // filter.<class-name>.<plugin-name>.inputFormats //For other MediaFilters, format of key is: // filter.<class-name>.inputFormats String formats = ConfigurationManager.getProperty(FILTER_PREFIX + "." + filterClassName + (pluginName != null ? "." + pluginName : "") + "." + INPUT_FORMATS_SUFFIX); //add to internal map of filters to supported formats if (formats != null) { //For SelfNamedPlugins, map key is: // <class-name><separator><plugin-name> //For other MediaFilters, map key is just: // <class-name> filterFormats.put( filterClassName + (pluginName != null ? FILTER_PLUGIN_SEPARATOR + pluginName : ""), Arrays.asList(formats.split(",[\\s]*"))); } } //end if filter!=null } //end for //If verbose, print out loaded mediafilter info if (isVerbose) { System.out.println("The following MediaFilters are enabled: "); Iterator<String> i = filterFormats.keySet().iterator(); while (i.hasNext()) { String filterName = i.next(); System.out.println("Full Filter Name: " + filterName); String pluginName = null; if (filterName.contains(FILTER_PLUGIN_SEPARATOR)) { String[] fields = filterName.split(FILTER_PLUGIN_SEPARATOR); filterName = fields[0]; pluginName = fields[1]; } System.out.println(filterName + (pluginName != null ? " (Plugin: " + pluginName + ")" : "")); } } //store our filter list into an internal array filterClasses = (FormatFilter[]) filterList.toArray(new FormatFilter[filterList.size()]); //Retrieve list of identifiers to skip (if any) String skipIds[] = null; if (line.hasOption('s')) { //specified which identifiers to skip when processing skipIds = line.getOptionValues('s'); if (skipIds == null || skipIds.length == 0) { //display error, since no identifiers specified to skip System.err.println("\nERROR: -s (-skip) option requires at least one identifier to SKIP.\n" + "Make sure to separate multiple identifiers with a comma!\n" + "(e.g. MediaFilterManager -s 123456789/34,123456789/323)\n"); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(0); } //save to a global skip list skipList = Arrays.asList(skipIds); } Context c = null; try { c = new Context(); // have to be super-user to do the filtering c.turnOffAuthorisationSystem(); // now apply the filters if (identifier == null) { applyFiltersAllItems(c); } else // restrict application scope to identifier { DSpaceObject dso = HandleManager.resolveToObject(c, identifier); if (dso == null) { throw new IllegalArgumentException("Cannot resolve " + identifier + " to a DSpace object"); } switch (dso.getType()) { case Constants.COMMUNITY: applyFiltersCommunity(c, (Community) dso); break; case Constants.COLLECTION: applyFiltersCollection(c, (Collection) dso); break; case Constants.ITEM: applyFiltersItem(c, (Item) dso); break; } } // update search index? if (updateIndex) { if (!isQuiet) { System.out.println("Updating search index:"); } DSIndexer.setBatchProcessingMode(true); try { DSIndexer.updateIndex(c); } finally { DSIndexer.setBatchProcessingMode(false); } } c.complete(); c = null; } catch (Exception e) { status = 1; } finally { if (c != null) { c.abort(); } } System.exit(status); }
From source file:org.dspace.papaya.mediafilter.PapayaMediaFilterManager.java
public static void main(String[] argv) throws Exception { // set headless for non-gui workstations System.setProperty("java.awt.headless", "true"); // create an options object and populate it CommandLineParser parser = new PosixParser(); int status = 0; Options options = new Options(); options.addOption("v", "verbose", false, "print all extracted text and other details to STDOUT"); options.addOption("q", "quiet", false, "do not print anything except in the event of errors."); options.addOption("f", "force", false, "force all bitstreams to be processed"); options.addOption("i", "identifier", true, "ONLY process bitstreams belonging to identifier"); options.addOption("m", "maximum", true, "process no more than maximum items"); options.addOption("h", "help", false, "help"); //create a "plugin" option (to specify specific MediaFilter plugins to run) OptionBuilder.withLongOpt("plugins"); OptionBuilder.withValueSeparator(','); OptionBuilder.withDescription("ONLY run the specified Media Filter plugin(s)\n" + "listed from '" + MEDIA_FILTER_PLUGINS_KEY + "' in dspace.cfg.\n" + "Separate multiple with a comma (,)\n" + "(e.g. MediaFilterManager -p \n\"Word Text Extractor\",\"PDF Text Extractor\")"); Option pluginOption = OptionBuilder.create('p'); pluginOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args options.addOption(pluginOption);/* ww w . java 2s .co m*/ //create a "skip" option (to specify communities/collections/items to skip) OptionBuilder.withLongOpt("skip"); OptionBuilder.withValueSeparator(','); OptionBuilder.withDescription( "SKIP the bitstreams belonging to identifier\n" + "Separate multiple identifiers with a comma (,)\n" + "(e.g. MediaFilterManager -s \n 123456789/34,123456789/323)"); Option skipOption = OptionBuilder.create('s'); skipOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args options.addOption(skipOption); CommandLine line = null; try { line = parser.parse(options, argv); } catch (MissingArgumentException e) { System.out.println("ERROR: " + e.getMessage()); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(1); } if (line.hasOption('h')) { HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(0); } if (line.hasOption('v')) { isVerbose = true; } isQuiet = line.hasOption('q'); if (line.hasOption('f')) { isForce = true; } if (line.hasOption('i')) { identifier = line.getOptionValue('i'); } if (line.hasOption('m')) { max2Process = Integer.parseInt(line.getOptionValue('m')); if (max2Process <= 1) { System.out.println("Invalid maximum value '" + line.getOptionValue('m') + "' - ignoring"); max2Process = Integer.MAX_VALUE; } } String filterNames[] = null; if (line.hasOption('p')) { //specified which media filter plugins we are using filterNames = line.getOptionValues('p'); if (filterNames == null || filterNames.length == 0) { //display error, since no plugins specified System.err.println("\nERROR: -p (-plugin) option requires at least one plugin to be specified.\n" + "(e.g. MediaFilterManager -p \"Word Text Extractor\",\"PDF Text Extractor\")\n"); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(1); } } else { //retrieve list of all enabled media filter plugins! String enabledPlugins = ConfigurationManager.getProperty(MEDIA_FILTER_PLUGINS_KEY); filterNames = enabledPlugins.split(",\\s*"); } //initialize an array of our enabled filters List<FormatFilter> filterList = new ArrayList<FormatFilter>(); //set up each filter for (int i = 0; i < filterNames.length; i++) { //get filter of this name & add to list of filters FormatFilter filter = (FormatFilter) PluginManager.getNamedPlugin(FormatFilter.class, filterNames[i]); if (filter == null) { System.err.println( "\nERROR: Unknown MediaFilter specified (either from command-line or in dspace.cfg): '" + filterNames[i] + "'"); System.exit(1); } else { filterList.add(filter); String filterClassName = filter.getClass().getName(); String pluginName = null; //If this filter is a SelfNamedPlugin, //then the input formats it accepts may differ for //each "named" plugin that it defines. //So, we have to look for every key that fits the //following format: filter.<class-name>.<plugin-name>.inputFormats if (SelfNamedPlugin.class.isAssignableFrom(filter.getClass())) { //Get the plugin instance name for this class pluginName = ((SelfNamedPlugin) filter).getPluginInstanceName(); } //Retrieve our list of supported formats from dspace.cfg //For SelfNamedPlugins, format of key is: // filter.<class-name>.<plugin-name>.inputFormats //For other MediaFilters, format of key is: // filter.<class-name>.inputFormats String formats = ConfigurationManager.getProperty(FILTER_PREFIX + "." + filterClassName + (pluginName != null ? "." + pluginName : "") + "." + INPUT_FORMATS_SUFFIX); //add to internal map of filters to supported formats if (formats != null) { //For SelfNamedPlugins, map key is: // <class-name><separator><plugin-name> //For other MediaFilters, map key is just: // <class-name> filterFormats.put( filterClassName + (pluginName != null ? FILTER_PLUGIN_SEPARATOR + pluginName : ""), Arrays.asList(formats.split(",[\\s]*"))); } } //end if filter!=null } //end for //If verbose, print out loaded mediafilter info if (isVerbose) { System.out.println("The following MediaFilters are enabled: "); Iterator<String> i = filterFormats.keySet().iterator(); while (i.hasNext()) { String filterName = i.next(); System.out.println("Full Filter Name: " + filterName); String pluginName = null; if (filterName.contains(FILTER_PLUGIN_SEPARATOR)) { String[] fields = filterName.split(FILTER_PLUGIN_SEPARATOR); filterName = fields[0]; pluginName = fields[1]; } System.out.println(filterName + (pluginName != null ? " (Plugin: " + pluginName + ")" : "")); } } //store our filter list into an internal array filterClasses = (FormatFilter[]) filterList.toArray(new FormatFilter[filterList.size()]); //Retrieve list of identifiers to skip (if any) String skipIds[] = null; if (line.hasOption('s')) { //specified which identifiers to skip when processing skipIds = line.getOptionValues('s'); if (skipIds == null || skipIds.length == 0) { //display error, since no identifiers specified to skip System.err.println("\nERROR: -s (-skip) option requires at least one identifier to SKIP.\n" + "Make sure to separate multiple identifiers with a comma!\n" + "(e.g. MediaFilterManager -s 123456789/34,123456789/323)\n"); HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("MediaFilterManager\n", options); System.exit(0); } //save to a global skip list skipList = Arrays.asList(skipIds); } Context c = null; try { c = new Context(); // have to be super-user to do the filtering c.turnOffAuthorisationSystem(); // now apply the filters if (identifier == null) { applyFiltersAllItems(c); } else // restrict application scope to identifier { DSpaceObject dso = HandleManager.resolveToObject(c, identifier); if (dso == null) { throw new IllegalArgumentException("Cannot resolve " + identifier + " to a DSpace object"); } switch (dso.getType()) { case Constants.COMMUNITY: applyFiltersCommunity(c, (Community) dso); break; case Constants.COLLECTION: applyFiltersCollection(c, (Collection) dso); break; case Constants.ITEM: applyFiltersItem(c, (Item) dso); break; } } c.complete(); c = null; } catch (Exception e) { status = 1; } finally { if (c != null) { c.abort(); } } System.exit(status); }
From source file:org.duracloud.retrieval.config.RetrievalToolConfigParser.java
/** * Creates a parser for command line configuration options. *///from w w w . ja v a 2s. c o m public RetrievalToolConfigParser() { cmdLineUtil = new CommandLineToolUtil(); // Command Line Options cmdOptions = new Options(); Option hostOption = new Option("h", "host", true, "the host address of the DuraCloud " + "DuraStore application"); hostOption.setRequired(true); cmdOptions.addOption(hostOption); Option portOption = new Option("r", "port", true, "the port of the DuraCloud DuraStore application " + "(optional, default value is " + DEFAULT_PORT + ")"); portOption.setRequired(false); cmdOptions.addOption(portOption); Option usernameOption = new Option("u", "username", true, "the username necessary to perform writes to DuraStore"); usernameOption.setRequired(true); cmdOptions.addOption(usernameOption); Option passwordOption = new Option("p", "password", true, "the password necessary to perform writes to DuraStore; NOTICE: " + "if no password is specified in the command line the retrieval tool will " + "look for an environment variable named " + CommandLineToolUtil.PASSWORD_ENV_VARIABLE_NAME + " containing the password. Finally, if this environment variable " + "does not exist the user will be prompted for the password."); passwordOption.setRequired(false); cmdOptions.addOption(passwordOption); Option storeIdOption = new Option("i", "store-id", true, "the Store ID for the DuraCloud storage provider"); storeIdOption.setRequired(false); cmdOptions.addOption(storeIdOption); Option spaces = new Option("s", "spaces", true, "the space or spaces from which content will be " + "retrieved"); spaces.setRequired(false); spaces.setArgs(Option.UNLIMITED_VALUES); cmdOptions.addOption(spaces); Option allSpaces = new Option("a", "all-spaces", false, "indicates that all spaces should be retrieved; if " + "this option is included the -s option is ignored " + "(optional, not set by default)"); allSpaces.setRequired(false); cmdOptions.addOption(allSpaces); Option contentDirOption = new Option("c", "content-dir", true, "retrieved content is stored in this local directory"); contentDirOption.setRequired(true); cmdOptions.addOption(contentDirOption); Option workDirOption = new Option("w", "work-dir", true, "logs and output files will be stored in the work " + "directory (optional, set to duracloud-retrieval-work " + "directory in user's home directory by default)"); workDirOption.setRequired(false); cmdOptions.addOption(workDirOption); Option overwrite = new Option("o", "overwrite", false, "indicates that existing local files which differ " + "from files in DuraCloud under the same path and name " + "sould be overwritten rather than copied " + "(optional, not set by default)"); overwrite.setRequired(false); cmdOptions.addOption(overwrite); Option numThreads = new Option("t", "threads", true, "the number of threads in the pool used to manage " + "file transfers (optional, default value is " + DEFAULT_NUM_THREADS + ")"); numThreads.setRequired(false); cmdOptions.addOption(numThreads); Option disableTimestamps = new Option("d", "disable-timestamps", false, "indicates that timestamp information found as content " + "item properties in DuraCloud should not be applied to " + "local files as they are retrieved (optional, not set " + "by default)"); disableTimestamps.setRequired(false); cmdOptions.addOption(disableTimestamps); Option listOnly = new Option("l", "list-only", false, "indicates that the retrieval tool should create a file " + "listing the contents of the specified space rather than " + "downloading the actual content files. The list file " + "will be placed in the specified content directory. " + "One list file will be created for each specified space." + "(optional, not set by default)"); listOnly.setRequired(false); cmdOptions.addOption(listOnly); Option listFile = new Option("f", "list-file", true, "retrieve specific contents using content IDs in the " + "specified file. The specified file should contain " + "one content ID per line. This option can only " + "operate on one space at a time."); listFile.setRequired(false); cmdOptions.addOption(listFile); }
From source file:org.duracloud.sync.config.SyncToolConfigParser.java
/** * Creates a parser for command line configuration options. *///from w w w . j a va 2 s .c o m public SyncToolConfigParser() { cmdLineUtil = new CommandLineToolUtil(); // Command Line Options cmdOptions = new Options(); Option hostOption = new Option("h", "host", true, "the host address of the DuraCloud " + "DuraStore application"); hostOption.setRequired(true); cmdOptions.addOption(hostOption); Option portOption = new Option("r", "port", true, "the port of the DuraCloud DuraStore application " + "(optional, default value is " + DEFAULT_PORT + ")"); portOption.setRequired(false); cmdOptions.addOption(portOption); Option usernameOption = new Option("u", "username", true, "the username necessary to perform writes to DuraStore"); usernameOption.setRequired(true); cmdOptions.addOption(usernameOption); Option passwordOption = new Option("p", "password", true, "the password necessary to perform writes to DuraStore; NOTICE: " + "if no password is specified in the command line the sync tool will " + "look for an environment variable named " + CommandLineToolUtil.PASSWORD_ENV_VARIABLE_NAME + " containing the password. Finally, if this environment variable " + "does not exist the user will be prompted for the password."); passwordOption.setRequired(false); cmdOptions.addOption(passwordOption); Option storeIdOption = new Option("i", "store-id", true, "the Store ID for the DuraCloud storage provider"); storeIdOption.setRequired(false); cmdOptions.addOption(storeIdOption); Option spaceId = new Option("s", "space-id", true, "the ID of the DuraCloud space where content " + "will be stored"); spaceId.setRequired(true); cmdOptions.addOption(spaceId); Option workDirOption = new Option("w", "work-dir", true, "the state of the sync tool is persisted to " + "this directory (optional, default value is " + "duracloud-sync-work directory in user home)"); workDirOption.setRequired(false); cmdOptions.addOption(workDirOption); Option contentDirs = new Option("c", "content-dirs", true, "the directory paths to monitor and sync with DuraCloud"); contentDirs.setRequired(true); contentDirs.setArgs(Option.UNLIMITED_VALUES); cmdOptions.addOption(contentDirs); Option pollFrequency = new Option("f", "poll-frequency", true, "the time (in ms) to wait between each poll of the " + "sync-dirs (optional, default value is " + DEFAULT_POLL_FREQUENCY + ")"); pollFrequency.setRequired(false); cmdOptions.addOption(pollFrequency); Option numThreads = new Option("t", "threads", true, "the number of threads in the pool used to manage " + "file transfers (optional, default value is " + DEFAULT_NUM_THREADS + ")"); numThreads.setRequired(false); cmdOptions.addOption(numThreads); Option maxFileSize = new Option("m", "max-file-size", true, "the maximum size of a stored file in GB (value must " + "be between 1 and 5), larger files will be split into " + "pieces (optional, default value is " + DEFAULT_MAX_FILE_SIZE + ")"); maxFileSize.setRequired(false); cmdOptions.addOption(maxFileSize); Option renameUpdates = new Option("n", "rename-updates", true, "indicates that updates should be synced to the cloud and renamed. " + "Specify an optional suffix to override default " + "( \"" + SyncToolConfig.DEFAULT_UPDATE_SUFFIX + "\"); " + "To prevent updates altogether, see option -o. " + "(optional, not set by default)"); renameUpdates.setRequired(false); renameUpdates.setArgName("suffix"); renameUpdates.setOptionalArg(true); cmdOptions.addOption(renameUpdates); Option syncUpdates = new Option("o", "no-update", false, "indicates that changed files should not be updated; " + "to perform updates without overwriting, see option -n. " + "(optional, not set by default)"); syncUpdates.setRequired(false); cmdOptions.addOption(syncUpdates); Option syncDeletes = new Option("d", "sync-deletes", false, "indicates that deletes performed on files within the " + "sync directories should also be performed on those " + "files in DuraCloud; if this option is not included " + "all deletes are ignored (optional, not set by default)"); syncDeletes.setRequired(false); cmdOptions.addOption(syncDeletes); Option cleanStart = new Option("l", "clean-start", false, "indicates that the sync tool should perform a clean " + "start, ensuring that all files in all content " + "directories are checked against DuraCloud, even if " + "those files have not changed locally since the last " + "run of the sync tool. (optional, not set by default)"); cleanStart.setRequired(false); cmdOptions.addOption(cleanStart); Option jumpStart = new Option("j", "jump-start", false, "indicates that the sync tool should not attempt to " + "check if content to be synchronized is already in " + "DuraCloud, but should instead transfer all content. " + "This option is best used for new data sets. " + "(optional, not set by default)"); jumpStart.setRequired(false); cmdOptions.addOption(jumpStart); Option exitOnCompletion = new Option("x", "exit-on-completion", false, "indicates that the sync tool should exit once it has " + "completed a scan of the content directories and synced " + "all files; if this option is included, the sync tool " + "will not continue to monitor the sync dirs " + "(optional, not set by default)"); exitOnCompletion.setRequired(false); cmdOptions.addOption(exitOnCompletion); Option excludeOption = new Option("e", "exclude", true, "file which provides a list of files and/or " + "directories to exclude from the sync (one file or " + "directory name rule per line)"); excludeOption.setRequired(false); cmdOptions.addOption(excludeOption); Option prefixOption = new Option("a", "prefix", true, "a prefix that is added to the beginning of the ID of " + "each content item that is stored in DuraCloud. For " + "example, a prefix value of 'a/b/c/' with a content " + "item whose path is 'dir1/file.txt' would result in " + "the file stored in DuraCloud as 'a/b/c/dir1/file.txt " + "(optional)"); prefixOption.setRequired(false); cmdOptions.addOption(prefixOption); // Options to use Backup Config configFileOptions = new Options(); Option configFileOption = new Option("g", "config-file", true, "read configuration from this file (a file containing " + "the most recently used configuration can be found in " + "the work-dir, named " + BACKUP_FILE_NAME + ")"); configFileOption.setRequired(true); configFileOptions.addOption(configFileOption); }
From source file:org.duracloud.syncoptimize.config.SyncOptimizeConfigParser.java
/** * Creates a parser for command line configuration options. *//*from w w w. ja v a 2s . c o m*/ public SyncOptimizeConfigParser() { cmdLineUtil = new CommandLineToolUtil(); // Command Line Options cmdOptions = new Options(); Option hostOption = new Option("h", "host", true, "the host address of the DuraCloud " + "DuraStore application"); hostOption.setRequired(true); cmdOptions.addOption(hostOption); Option portOption = new Option("r", "port", true, "the port of the DuraCloud DuraStore application " + "(optional, default value is " + DEFAULT_PORT + ")"); portOption.setRequired(false); cmdOptions.addOption(portOption); Option usernameOption = new Option("u", "username", true, "the username necessary to perform writes to DuraStore"); usernameOption.setRequired(true); cmdOptions.addOption(usernameOption); Option passwordOption = new Option("p", "password", true, "the password necessary to perform writes to DuraStore; NOTICE: " + "if no password is specified in the command line the retrieval tool will " + "look for an environment variable named " + CommandLineToolUtil.PASSWORD_ENV_VARIABLE_NAME + " containing the password. Finally, if this environment variable " + "does not exist the user will be prompted for the password."); passwordOption.setRequired(false); cmdOptions.addOption(passwordOption); Option spaceIdOption = new Option("s", "space", true, "the space in which test content will be placed"); spaceIdOption.setRequired(true); spaceIdOption.setArgs(Option.UNLIMITED_VALUES); cmdOptions.addOption(spaceIdOption); Option numFilesOption = new Option("n", "num-files", true, "the number of files to transfer on each test run"); numFilesOption.setRequired(false); cmdOptions.addOption(numFilesOption); Option sizeFilesOption = new Option("m", "size-files", true, "the size of files to transfer on each test run, in MB"); sizeFilesOption.setRequired(false); cmdOptions.addOption(sizeFilesOption); }
From source file:org.eclipse.emf.search.examples.ecore.grep.EcoreGrep.java
private Options initOptions() { Option patternOpt = new Option(PATTERN_OPT_ID, true, "pattern kind for Ecore query among 'REGEX', 'NORMAL', 'CASE' (Regular Expresion, Normal *,? Compliant Pattern, Case Sensitive) "); patternOpt.addValue("REGEX"); patternOpt.addValue("NORMAL"); patternOpt.addValue("CASE"); patternOpt.setArgs(1);//from w ww . j av a 2s .com Option exprOpt = new Option(EXPR_OPT_ID, true, "expression"); exprOpt.setArgs(1); exprOpt.setRequired(true); Option dirOpt = new Option(DIR_OPT_ID, true, "directory list"); dirOpt.setArgs(Option.UNLIMITED_VALUES); dirOpt.setRequired(true); Option participantOpt = new Option(PARTICIPANT_OPT_ID, true, "meta-element participant list"); participantOpt.setArgs(Option.UNLIMITED_VALUES); Options options = new Options(); options.addOption(dirOpt); options.addOption(exprOpt); options.addOption(patternOpt); options.addOption(participantOpt); return options; }
From source file:org.jboss.jbossset.CommandLineParser.java
private void addUsernameOptions() { options.addOption(Option.builder("u").argName("usernames").longOpt("usernames") .desc("Pass the JIRA usernames to be searched as command line options.").required(false) .numberOfArgs(Option.UNLIMITED_VALUES).valueSeparator(' ').build()); options.addOption(Option.builder("uf").argName("userFile").longOpt("userFile") .desc("Read JIRA usernames from the specified file.").required(false).numberOfArgs(1).build()); }
From source file:org.jruyi.launcher.Main.java
private static boolean processCommandLines(String[] args) throws Exception { Options options = new Options(); options.addOption("?", "help", false, null); options.addOption("v", "version", false, null); Option o = new Option("D", true, null); o.setArgs(Option.UNLIMITED_VALUES); options.addOption(o);//from w w w .ja va 2 s . c o m options.addOption("r", "run", true, null); CommandLine line = new PosixParser().parse(options, args); Option[] opts = line.getOptions(); for (Option option : opts) { String opt = option.getOpt(); if (opt.equals("?")) { printHelp(); return false; } else if (opt.equals("v")) { MainHolder.INST.printVersion(); return false; } else if (opt.equals("D")) { handleSystemProps(option.getValues()); } else if (opt.equals("r")) { System.setProperty(JRUYI_INST_NAME, option.getValue().trim()); } else throw new Exception("Unknown option: " + option); } return true; }