List of usage examples for org.apache.commons.cli CommandLine getArgList
public List getArgList()
From source file:org.drools.workbench.jcr2vfsmigration.config.MigrationConfig.java
public void parseArgs(String[] args) { Options options = new Options(); options.addOption("i", "inputJcrRepository", true, "The Guvnor 5 JCR repository"); options.addOption("o", "outputVfsRepository", true, "The Guvnor 6 VFS repository"); options.addOption("f", "forceOverwriteOutputVfsRepository", true, "Force overwriting the Guvnor 6 VFS repository"); CommandLine commandLine; try {/*from w w w .ja va 2 s . com*/ commandLine = new BasicParser().parse(options, args); } catch (ParseException e) { throw new IllegalArgumentException("The arguments (" + Arrays.toString(args) + ") could not be parsed.", e); } if (!commandLine.getArgList().isEmpty()) { throw new IllegalArgumentException("The arguments (" + Arrays.toString(args) + ") have unsupported arguments (" + commandLine.getArgList() + ")."); } parseArgInputJcrRepository(commandLine); parseArgOutputVfsRepository(commandLine); }
From source file:org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.java
public void run(String[] args) { Options options = getOptions();// w ww .j a va 2 s . c om final CommandLineParser parser = new PosixParser(); CommandLine line = null; try { line = parser.parse(options, args); if (line.getArgs().length == 0) throw new ParseException("No module name specified."); if (line.getArgs().length > 1) throw new ParseException("Only one module name expected. But " + line.getArgs().length + " were passed (" + line.getArgList() + ")"); String moduleName = line.getArgs()[0]; Map<String, String> params = new HashMap<String, String>(); String[] optionValues = line.getOptionValues(PARAM); if (optionValues != null) { for (String string : optionValues) { int index = string.indexOf('='); if (index == -1) { throw new ParseException( "Incorrect parameter syntax '" + string + "'. It should be 'name=value'"); } String name = string.substring(0, index); String value = string.substring(index + 1); if (params.put(name, value) != null) { throw new ParseException("Duplicate parameter '" + name + "'."); } } } // check OperationCanceledException is accessible OperationCanceledException.class.getName(); Injector injector = new Mwe2StandaloneSetup().createInjectorAndDoEMFRegistration(); Mwe2Runner mweRunner = injector.getInstance(Mwe2Runner.class); if (moduleName.contains("/")) { mweRunner.run(URI.createURI(moduleName), params); } else { mweRunner.run(moduleName, params); } } catch (NoClassDefFoundError e) { if ("org/eclipse/core/runtime/OperationCanceledException".equals(e.getMessage())) { System.err.println("Could not load class: org.eclipse.core.runtime.OperationCanceledException"); System.err.println("Add org.eclipse.equinox.common to the class path."); } else { throw e; } } catch (final ParseException exp) { final HelpFormatter formatter = new HelpFormatter(); System.err.println("Parsing arguments failed. Reason: " + exp.getMessage()); formatter.printHelp("java " + Mwe2Launcher.class.getName() + " some.mwe2.Module [options]\n", options); return; } }
From source file:org.eclipse.leshan.client.demo.LeshanClientDemo.java
public static void main(final String[] args) { // Define options for command line tools Options options = new Options(); options.addOption("h", "help", false, "Display help information."); options.addOption("n", true, String.format("Set the endpoint name of the Client.\nDefault: the local hostname or '%s' if any.", DEFAULT_ENDPOINT));/*from w w w .j a va2 s . c om*/ options.addOption("b", false, "If present use bootstrap."); options.addOption("lh", true, "Set the local CoAP address of the Client.\n Default: any local address."); options.addOption("lp", true, "Set the local CoAP port of the Client.\n Default: A valid port value is between 0 and 65535."); options.addOption("slh", true, "Set the secure local CoAP address of the Client.\nDefault: any local address."); options.addOption("slp", true, "Set the secure local CoAP port of the Client.\nDefault: A valid port value is between 0 and 65535."); options.addOption("u", true, "Set the LWM2M or Bootstrap server URL.\nDefault: localhost:5683."); options.addOption("i", true, "Set the LWM2M or Bootstrap server PSK identity in ascii.\nUse none secure mode if not set."); options.addOption("p", true, "Set the LWM2M or Bootstrap server Pre-Shared-Key in hexa.\nUse none secure mode if not set."); options.addOption("pos", true, "Set the initial location (latitude, longitude) of the device to be reported by the Location object. Format: lat_float:long_float"); options.addOption("sf", true, "Scale factor to apply when shifting position. Default is 1.0."); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(null); // Parse arguments CommandLine cl = null; try { cl = new DefaultParser().parse(options, args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); formatter.printHelp(USAGE, options); return; } // Print help if (cl.hasOption("help")) { formatter.printHelp(USAGE, options); return; } // Abort if unexpected options if (cl.getArgs().length > 0) { System.err.println("Unexpected option or arguments : " + cl.getArgList()); formatter.printHelp(USAGE, options); return; } // Abort if we have not identity and key for psk. if ((cl.hasOption("i") && !cl.hasOption("p")) || !cl.hasOption("i") && cl.hasOption("p")) { System.err.println("You should precise identity and Pre-Shared-Key if you want to connect in PSK"); formatter.printHelp(USAGE, options); return; } // Get endpoint name String endpoint; if (cl.hasOption("n")) { endpoint = cl.getOptionValue("n"); } else { try { endpoint = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { endpoint = DEFAULT_ENDPOINT; } } // Get server URI String serverURI; if (cl.hasOption("u")) { if (cl.hasOption("i")) serverURI = "coaps://" + cl.getOptionValue("u"); else serverURI = "coap://" + cl.getOptionValue("u"); } else { if (cl.hasOption("i")) serverURI = "coaps://localhost:5684"; else serverURI = "coap://leshan.eclipse.org:5683"; } // get security info byte[] pskIdentity = null; byte[] pskKey = null; if (cl.hasOption("i") && cl.hasOption("p")) { pskIdentity = cl.getOptionValue("i").getBytes(); pskKey = Hex.decodeHex(cl.getOptionValue("p").toCharArray()); } // get local address String localAddress = null; int localPort = 0; if (cl.hasOption("lh")) { localAddress = cl.getOptionValue("lh"); } if (cl.hasOption("lp")) { localPort = Integer.parseInt(cl.getOptionValue("lp")); } // get secure local address String secureLocalAddress = null; int secureLocalPort = 0; if (cl.hasOption("slh")) { secureLocalAddress = cl.getOptionValue("slh"); } if (cl.hasOption("slp")) { secureLocalPort = Integer.parseInt(cl.getOptionValue("slp")); } Float latitude = null; Float longitude = null; Float scaleFactor = 1.0f; // get initial Location if (cl.hasOption("pos")) { try { String pos = cl.getOptionValue("pos"); int colon = pos.indexOf(':'); if (colon == -1 || colon == 0 || colon == pos.length() - 1) { System.err.println( "Position must be a set of two floats separated by a colon, e.g. 48.131:11.459"); formatter.printHelp(USAGE, options); return; } latitude = Float.valueOf(pos.substring(0, colon)); longitude = Float.valueOf(pos.substring(colon + 1)); } catch (NumberFormatException e) { System.err.println("Position must be a set of two floats separated by a colon, e.g. 48.131:11.459"); formatter.printHelp(USAGE, options); return; } } if (cl.hasOption("sf")) { try { scaleFactor = Float.valueOf(cl.getOptionValue("sf")); } catch (NumberFormatException e) { System.err.println("Scale factor must be a float, e.g. 1.0 or 0.01"); formatter.printHelp(USAGE, options); return; } } createAndStartClient(endpoint, localAddress, localPort, secureLocalAddress, secureLocalPort, cl.hasOption("b"), serverURI, pskIdentity, pskKey, latitude, longitude, scaleFactor); }
From source file:org.eclipse.leshan.server.bootstrap.demo.LeshanBootstrapServerDemo.java
public static void main(String[] args) { // Define options for command line tools Options options = new Options(); options.addOption("h", "help", false, "Display help information."); options.addOption("lh", "coaphost", true, "Set the local CoAP address.\n Default: any local address."); options.addOption("lp", "coapport", true, "Set the local CoAP port.\n Default: 5683."); options.addOption("slh", "coapshost", true, "Set the secure local CoAP address.\nDefault: any local address."); options.addOption("slp", "coapsport", true, "Set the secure local CoAP port.\nDefault: 5684."); options.addOption("wp", "webport", true, "Set the HTTP port for web server.\nDefault: 8080."); options.addOption("cfg", "configfile", true, "Set the filename for the configuration.\nDefault: " + BootstrapStoreImpl.DEFAULT_FILE + "."); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(null); // Parse arguments CommandLine cl = null; try {/*from ww w .j av a2 s .c o m*/ cl = new DefaultParser().parse(options, args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); formatter.printHelp(USAGE, null, options, FOOTER); return; } // Print help if (cl.hasOption("help")) { formatter.printHelp(USAGE, null, options, FOOTER); return; } // Abort if unexpected options if (cl.getArgs().length > 0) { System.err.println("Unexpected option or arguments : " + cl.getArgList()); formatter.printHelp(USAGE, null, options, FOOTER); return; } // Get local address String localAddress = System.getenv("COAPHOST"); if (cl.hasOption("lh")) { localAddress = cl.getOptionValue("lh"); } if (localAddress == null) localAddress = "0.0.0.0"; String localPortOption = System.getenv("COAPPORT"); if (cl.hasOption("lp")) { localPortOption = cl.getOptionValue("lp"); } int localPort = LeshanServerBuilder.PORT; if (localPortOption != null) { localPort = Integer.parseInt(localPortOption); } // Get secure local address String secureLocalAddress = System.getenv("COAPSHOST"); if (cl.hasOption("slh")) { secureLocalAddress = cl.getOptionValue("slh"); } if (secureLocalAddress == null) secureLocalAddress = "0.0.0.0"; String secureLocalPortOption = System.getenv("COAPSPORT"); if (cl.hasOption("slp")) { secureLocalPortOption = cl.getOptionValue("slp"); } int secureLocalPort = LeshanServerBuilder.PORT_DTLS; if (secureLocalPortOption != null) { secureLocalPort = Integer.parseInt(secureLocalPortOption); } // Get http port String webPortOption = System.getenv("WEBPORT"); if (cl.hasOption("wp")) { webPortOption = cl.getOptionValue("wp"); } int webPort = 8080; if (webPortOption != null) { webPort = Integer.parseInt(webPortOption); } String configFilename = System.getenv("CONFIGFILE"); if (cl.hasOption("cfg")) { configFilename = cl.getOptionValue("cfg"); } if (configFilename == null) { configFilename = BootstrapStoreImpl.DEFAULT_FILE; } try { createAndStartServer(webPort, localAddress, localPort, secureLocalAddress, secureLocalPort, configFilename); } catch (BindException e) { System.err.println(String.format( "Web port %s is already in use, you can change it using the 'webport' option.", webPort)); formatter.printHelp(USAGE, null, options, FOOTER); } catch (Exception e) { LOG.error("Jetty stopped with unexcepted error ...", e); } }
From source file:org.eclipse.leshan.server.cluster.LeshanClusterServer.java
public static void main(String[] args) { // Define options for command line tools Options options = new Options(); options.addOption("h", "help", false, "Display help information."); options.addOption("n", "instanceID", true, "Sets the unique identifier of this instance in the cluster."); options.addOption("lh", "coaphost", true, "Sets the local CoAP address.\n Default: any local address."); options.addOption("lp", "coapport", true, "Sets the local CoAP port.\n Default: 5683."); options.addOption("slh", "coapshost", true, "Sets the local secure CoAP address.\nDefault: any local address."); options.addOption("slp", "coapsport", true, "Sets the local secure CoAP port.\nDefault: 5684."); options.addOption("r", "redis", true, "Sets the location of the Redis database. The URL is in the format of: 'redis://:password@hostname:port/db_number'\n\nDefault: 'redis://localhost:6379'."); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(null); // Parse arguments CommandLine cl = null; try {//from ww w .jav a 2 s. c om cl = new DefaultParser().parse(options, args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); formatter.printHelp(USAGE, null, options, FOOTER); return; } // Print help if (cl.hasOption("help")) { formatter.printHelp(USAGE, null, options, FOOTER); return; } // Abort if unexpected options if (cl.getArgs().length > 0) { System.err.println("Unexpected option or arguments : " + cl.getArgList()); formatter.printHelp(USAGE, null, options, FOOTER); return; } // get cluster instance Id String clusterInstanceId = System.getenv("INSTANCEID"); if (cl.hasOption("n")) { clusterInstanceId = cl.getOptionValue("n"); } if (clusterInstanceId == null) { System.err.println("InstanceId is mandatory !"); formatter.printHelp(USAGE, null, options, FOOTER); return; } // get local address String localAddress = System.getenv("COAPHOST"); if (cl.hasOption("lh")) { localAddress = cl.getOptionValue("lh"); } String localPortOption = System.getenv("COAPPORT"); if (cl.hasOption("lp")) { localPortOption = cl.getOptionValue("lp"); } int localPort = LeshanServerBuilder.PORT; if (localPortOption != null) { localPort = Integer.parseInt(localPortOption); } // get secure local address String secureLocalAddress = System.getenv("COAPSHOST"); if (cl.hasOption("slh")) { secureLocalAddress = cl.getOptionValue("slh"); } String secureLocalPortOption = System.getenv("COAPSPORT"); if (cl.hasOption("slp")) { secureLocalPortOption = cl.getOptionValue("slp"); } int secureLocalPort = LeshanServerBuilder.PORT_DTLS; if (secureLocalPortOption != null) { secureLocalPort = Integer.parseInt(secureLocalPortOption); } // get the Redis hostname:port String redisUrl = "redis://localhost:6379"; if (cl.hasOption("r")) { redisUrl = cl.getOptionValue("r"); } try { createAndStartServer(clusterInstanceId, localAddress, localPort, secureLocalAddress, secureLocalPort, redisUrl); } catch (Exception e) { LOG.error("Jetty stopped with unexcepted error ...", e); } }
From source file:org.eclipse.leshan.server.demo.LeshanServerDemo.java
public static void main(String[] args) { // Define options for command line tools Options options = new Options(); options.addOption("h", "help", false, "Display help information."); options.addOption("lh", "coaphost", true, "Set the local CoAP address.\n Default: any local address."); options.addOption("lp", "coapport", true, "Set the local CoAP port.\n Default: 5683."); options.addOption("slh", "coapshost", true, "Set the secure local CoAP address.\nDefault: any local address."); options.addOption("slp", "coapsport", true, "Set the secure local CoAP port.\nDefault: 5684."); options.addOption("wp", "webport", true, "Set the HTTP port for web server.\nDefault: 8080."); options.addOption("r", "redis", true, "Set the location of the Redis database for running in cluster mode. The URL is in the format of: 'redis://:password@hostname:port/db_number'\nExample without DB and password: 'redis://localhost:6379'\nDefault: none, no Redis connection."); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(null); // Parse arguments CommandLine cl = null; try {/*from w ww . ja v a 2s . com*/ cl = new DefaultParser().parse(options, args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); formatter.printHelp(USAGE, null, options, FOOTER); return; } // Print help if (cl.hasOption("help")) { formatter.printHelp(USAGE, null, options, FOOTER); return; } // Abort if unexpected options if (cl.getArgs().length > 0) { System.err.println("Unexpected option or arguments : " + cl.getArgList()); formatter.printHelp(USAGE, null, options, FOOTER); return; } // get local address String localAddress = System.getenv("COAPHOST"); if (cl.hasOption("lh")) { localAddress = cl.getOptionValue("lh"); } String localPortOption = System.getenv("COAPPORT"); if (cl.hasOption("lp")) { localPortOption = cl.getOptionValue("lp"); } int localPort = LeshanServerBuilder.PORT; if (localPortOption != null) { localPort = Integer.parseInt(localPortOption); } // get secure local address String secureLocalAddress = System.getenv("COAPSHOST"); if (cl.hasOption("slh")) { secureLocalAddress = cl.getOptionValue("slh"); } String secureLocalPortOption = System.getenv("COAPSPORT"); if (cl.hasOption("slp")) { secureLocalPortOption = cl.getOptionValue("slp"); } int secureLocalPort = LeshanServerBuilder.PORT_DTLS; if (secureLocalPortOption != null) { secureLocalPort = Integer.parseInt(secureLocalPortOption); } // get http port String webPortOption = System.getenv("WEBPORT"); if (cl.hasOption("wp")) { webPortOption = cl.getOptionValue("wp"); } int webPort = 8080; if (webPortOption != null) { webPort = Integer.parseInt(webPortOption); } // get the Redis hostname:port String redisUrl = null; if (cl.hasOption("r")) { redisUrl = cl.getOptionValue("r"); } try { createAndStartServer(webPort, localAddress, localPort, secureLocalAddress, secureLocalPort, redisUrl); } catch (BindException e) { System.err.println(String .format("Web port %s is alreay used, you could change it using 'webport' option.", webPort)); formatter.printHelp(USAGE, null, options, FOOTER); } catch (Exception e) { LOG.error("Jetty stopped with unexcepted error ...", e); } }
From source file:org.eclipselabs.garbagecat.Main.java
/** * @param args/*from w w w .j av a 2 s .com*/ * The argument list includes one or more scope options followed by the name of the gc log file to * inspect. */ public static void main(String[] args) { CommandLine cmd = null; try { cmd = parseOptions(args); } catch (ParseException pe) { System.out.println(pe.getMessage()); usage(options); } if (cmd != null) { if (cmd.hasOption(Constants.OPTION_HELP_LONG)) { usage(options); } else { // Determine JVM environment information. Date jvmStartDate = null; if (cmd.hasOption(Constants.OPTION_STARTDATETIME_LONG)) { jvmStartDate = GcUtil .parseStartDateTime(cmd.getOptionValue(Constants.OPTION_STARTDATETIME_SHORT)); } String jvmOptions = null; if (cmd.hasOption(Constants.OPTION_JVMOPTIONS_LONG)) { jvmOptions = cmd.getOptionValue(Constants.OPTION_JVMOPTIONS_SHORT); } String logFileName = (String) cmd.getArgList().get(cmd.getArgList().size() - 1); File logFile = new File(logFileName); GcManager gcManager = new GcManager(); // Do preprocessing if (cmd.hasOption(Constants.OPTION_PREPROCESS_LONG) || cmd.hasOption(Constants.OPTION_STARTDATETIME_LONG)) { /* * Requiring the JVM start date/time for preprocessing is a hack to handle datestamps. When * garbagecat was started there was no <code>-XX:+PrintGCDateStamps</code> option. When it was * introduced in JDK 1.6 update 4, the easiest thing to do to handle datestamps was to preprocess * the datestamps and convert them to timestamps. * * TODO: Handle datetimes separately from preprocessing so preprocessing doesn't require passing in * the JVM start date/time. */ logFile = gcManager.preprocess(logFile, jvmStartDate); } // Allow logging to be reordered? boolean reorder = false; if (cmd.hasOption(Constants.OPTION_REORDER_LONG)) { reorder = true; } // Store garbage collection logging in data store. gcManager.store(logFile, reorder); // Create report Jvm jvm = new Jvm(jvmOptions, jvmStartDate); // Determine report options int throughputThreshold = Constants.DEFAULT_BOTTLENECK_THROUGHPUT_THRESHOLD; if (cmd.hasOption(Constants.OPTION_THRESHOLD_LONG)) { throughputThreshold = Integer.parseInt(cmd.getOptionValue(Constants.OPTION_THRESHOLD_SHORT)); } JvmRun jvmRun = gcManager.getJvmRun(jvm, throughputThreshold); String outputFileName; if (cmd.hasOption(Constants.OPTION_OUTPUT_LONG)) { outputFileName = cmd.getOptionValue(Constants.OPTION_OUTPUT_SHORT); } else { outputFileName = Constants.OUTPUT_FILE_NAME; } boolean version = cmd.hasOption(Constants.OPTION_VERSION_LONG); boolean latestVersion = cmd.hasOption(Constants.OPTION_LATEST_VERSION_LONG); createReport(jvmRun, outputFileName, version, latestVersion); } } }
From source file:org.eclipselabs.garbagecat.Main.java
/** * Validate command line options./*from w ww . j a v a 2 s. co m*/ * * @param cmd * The command line options. * * @throws ParseException * Command line options not valid. */ public static void validateOptions(CommandLine cmd) throws ParseException { // Ensure log file specified. if (cmd.getArgList().size() == 0) { throw new ParseException("Missing log file"); } String logFileName = null; if (cmd.getArgList().size() > 0) { logFileName = (String) cmd.getArgList().get(cmd.getArgList().size() - 1); } // Ensure gc log file exists. if (logFileName == null) { throw new ParseException("Missing log file not"); } File logFile = new File(logFileName); if (!logFile.exists()) { throw new ParseException("Invalid log file: '" + logFileName + "'"); } // threshold if (cmd.hasOption(Constants.OPTION_THRESHOLD_LONG)) { String thresholdRegEx = "^\\d{1,3}$"; String thresholdOptionValue = cmd.getOptionValue(Constants.OPTION_THRESHOLD_SHORT); Pattern pattern = Pattern.compile(thresholdRegEx); Matcher matcher = pattern.matcher(thresholdOptionValue); if (!matcher.find()) { throw new ParseException("Invalid threshold: '" + thresholdOptionValue + "'"); } } // startdatetime if (cmd.hasOption(Constants.OPTION_STARTDATETIME_LONG)) { String startdatetimeOptionValue = cmd.getOptionValue(Constants.OPTION_STARTDATETIME_SHORT); Pattern pattern = Pattern.compile(GcUtil.START_DATE_TIME_REGEX); Matcher matcher = pattern.matcher(startdatetimeOptionValue); if (!matcher.find()) { throw new ParseException("Invalid startdatetime: '" + startdatetimeOptionValue + "'"); } } }
From source file:org.entando.edo.parser.CommandlineParser.java
/** * Setta le opzioni e pulisce args!//from w ww . j a v a 2 s . c om * @param cl * @param edoBean * @param args * @return * @throws IllegalArgumentException */ private String[] processCommandline(CommandLine cl, EdoBuilder edoBuilder, String[] args) throws IllegalArgumentException { if (cl.hasOption(OPTION_BASE_DIR)) { String baseDir = cl.getOptionValue(OPTION_BASE_DIR); if (StringUtils.isNotBlank(baseDir)) { if (baseDir.endsWith(File.separator)) { baseDir = StringUtils.removeEnd(baseDir, File.separator); } edoBuilder.setBaseDir(baseDir); } } _logger.debug("baseDir is: '{}'", edoBuilder.getBaseDir()); if (cl.hasOption(OPTION_PERMISSION)) { String perm = cl.getOptionValue(OPTION_PERMISSION); if (StringUtils.isNotBlank(perm)) { edoBuilder.setPermission(perm); } } _logger.debug("permission is: '{}'", edoBuilder.getPermission()); String packageName = null; if (cl.hasOption(OPTION_PACKAGE)) { String packageNameParam = cl.getOptionValue(OPTION_PACKAGE); if (StringUtils.isNotBlank(packageNameParam)) { if (PackageValidator.isValidPackageName(packageNameParam)) { packageName = packageNameParam; } else { _logger.error("invalid package name specified: {}", packageName); throw new IllegalArgumentException("invalid package name specified: " + packageName); } } } else { _logger.trace("auto generate packagename"); if (!cl.getArgList().isEmpty()) { packageName = "org.entando.entando.plugins.jp" + cl.getArgs()[0].toLowerCase(); } else { _logger.warn("Unable to generate the default package name. No enough args"); } } edoBuilder.setPackageName(packageName); _logger.debug("packagename: is '{}'", edoBuilder.getPackageName()); args = Arrays.copyOfRange(args, cl.getOptions().length, args.length); return args; }
From source file:org.exbin.deltahex.editor.DeltaHexEditor.java
/** * Main method launching the application. * * @param args arguments//from w w w . j a v a2s . co m */ public static void main(String[] args) { try { preferences = Preferences.userNodeForPackage(DeltaHexEditor.class); } catch (SecurityException ex) { preferences = null; } try { bundle = LanguageUtils.getResourceBundleByClass(DeltaHexEditor.class); // Parameters processing Options opt = new Options(); opt.addOption("h", "help", false, bundle.getString("cl_option_help")); opt.addOption("v", false, bundle.getString("cl_option_verbose")); opt.addOption("dev", false, bundle.getString("cl_option_dev")); BasicParser parser = new BasicParser(); CommandLine cl = parser.parse(opt, args); if (cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp(bundle.getString("cl_syntax"), opt); } else { verboseMode = cl.hasOption("v"); devMode = cl.hasOption("dev"); Logger logger = Logger.getLogger(""); try { logger.setLevel(Level.ALL); logger.addHandler(new XBHead.XBLogHandler(verboseMode)); } catch (java.security.AccessControlException ex) { // Ignore it in java webstart } XBBaseApplication app = new XBBaseApplication(); app.setAppPreferences(preferences); app.setAppBundle(bundle, LanguageUtils.getResourceBaseNameBundleByClass(DeltaHexEditor.class)); XBApplicationModuleRepository moduleRepository = app.getModuleRepository(); moduleRepository.addClassPathModules(); moduleRepository.addModulesFromManifest(DeltaHexEditor.class); moduleRepository.loadModulesFromPath(new File("plugins").toURI()); moduleRepository.initModules(); app.init(); GuiFrameModuleApi frameModule = moduleRepository.getModuleByInterface(GuiFrameModuleApi.class); GuiEditorModuleApi editorModule = moduleRepository.getModuleByInterface(GuiEditorModuleApi.class); GuiMenuModuleApi menuModule = moduleRepository.getModuleByInterface(GuiMenuModuleApi.class); GuiAboutModuleApi aboutModule = moduleRepository.getModuleByInterface(GuiAboutModuleApi.class); GuiUndoModuleApi undoModule = moduleRepository.getModuleByInterface(GuiUndoModuleApi.class); GuiFileModuleApi fileModule = moduleRepository.getModuleByInterface(GuiFileModuleApi.class); GuiOptionsModuleApi optionsModule = moduleRepository .getModuleByInterface(GuiOptionsModuleApi.class); GuiDockingModuleApi dockingModule = moduleRepository .getModuleByInterface(GuiDockingModuleApi.class); GuiUpdateModuleApi updateModule = moduleRepository.getModuleByInterface(GuiUpdateModuleApi.class); DeltaHexModule deltaHexModule = moduleRepository.getModuleByInterface(DeltaHexModule.class); frameModule.createMainMenu(); try { updateModule.setUpdateUrl(new URL(bundle.getString("update_url"))); updateModule.setUpdateDownloadUrl(new URL(bundle.getString("update_download_url"))); } catch (MalformedURLException ex) { Logger.getLogger(DeltaHexEditor.class.getName()).log(Level.SEVERE, null, ex); } updateModule.registerDefaultMenuItem(); aboutModule.registerDefaultMenuItem(); frameModule.registerExitAction(); frameModule.registerBarsVisibilityActions(); // Component dockingPanel = dockingModule.getDockingPanel(); // Register clipboard editing actions fileModule.registerMenuFileHandlingActions(); fileModule.registerToolBarFileHandlingActions(); fileModule.registerLastOpenedMenuActions(); fileModule.registerCloseListener(); undoModule.registerMainMenu(); undoModule.registerMainToolBar(); undoModule.registerUndoManagerInMainMenu(); // Register clipboard editing actions menuModule.registerMenuClipboardActions(); menuModule.registerToolBarClipboardActions(); optionsModule.registerMenuAction(); // HexEditorProvider editorProvider = deltaHexModule.getMultiEditorProvider(); HexEditorProvider editorProvider = deltaHexModule.getEditorProvider(); deltaHexModule.registerEditFindMenuActions(); deltaHexModule.registerEditFindToolBarActions(); deltaHexModule.registerViewNonprintablesMenuActions(); deltaHexModule.registerToolsOptionsMenuActions(); deltaHexModule.registerClipboardCodeActions(); deltaHexModule.registerOptionsMenuPanels(); deltaHexModule.registerGoToLine(); deltaHexModule.registerPropertiesMenu(); deltaHexModule.registerPrintMenu(); deltaHexModule.registerViewModeMenu(); deltaHexModule.registerCodeTypeMenu(); deltaHexModule.registerPositionCodeTypeMenu(); deltaHexModule.registerHexCharactersCaseHandlerMenu(); deltaHexModule.registerWordWrapping(); ApplicationFrameHandler frameHandler = frameModule.getFrameHandler(); editorModule.registerEditor("hex", editorProvider); // editorModule.registerMultiEditor("hex", (MultiEditorProvider) editorProvider); editorModule.registerUndoHandler(); undoModule.setUndoHandler(editorProvider.getHexUndoHandler()); deltaHexModule.registerStatusBar(); deltaHexModule.registerOptionsPanels(); deltaHexModule.getTextStatusPanel(); updateModule.registerOptionsPanels(); deltaHexModule.loadFromPreferences(preferences); // frameHandler.setMainPanel(dockingPanel); // Single editor only frameHandler.setMainPanel(editorModule.getEditorPanel()); frameHandler.setDefaultSize(new Dimension(600, 400)); frameHandler.show(); updateModule.checkOnStart(frameHandler.getFrame()); List fileArgs = cl.getArgList(); if (fileArgs.size() > 0) { fileModule.loadFromFile((String) fileArgs.get(0)); } } } catch (ParseException | RuntimeException ex) { Logger.getLogger(DeltaHexEditor.class.getName()).log(Level.SEVERE, null, ex); } }