Examples of GetOpts


Examples of jimm.util.Getopts

* @param args command line array; each element is assumed to be a report
* file name.
*/
public static void main(String[] args) {

  Getopts g = new Getopts("a:c:d:e:f:g:h:i:l:np:qr:s:wx:E:R:o:", args);
  if (g.error()) {    // Any bad command line argument?
    usage(null);    // If so, whine and exit
  }

  // Get user's preferences, if any.
  Preferences prefs = Preferences.userRoot().node("/jimm/datavision");

  // Set look & feel.
  try {
    javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
  } catch (Exception e) {
    // Default L&F will be used if any problems occur, most probably,
    // ClassNotFound.
  }

    DataVision dv = new DataVision();

    // Language
    if (g.hasOption('g') || g.hasOption('i'))
  I18N.setLanguage(new Locale(g.option('g', "").toLowerCase(),
            g.option('i', "").toUpperCase()));

    dv.layoutEngineChoiceFromOptions(g);
    dv.dataSourceFromOptions(g);

    if (dv.hasLayoutEngine()) {
  if (dv.usesGUI())  // Can ask for password via GUI
      ErrorHandler.useGUI(true);
  else if (!g.hasOption('n') && !g.hasOption('p') && !g.hasOption('e'))
      usage(I18N.get("DataVision.n_or_p"));
    }

    dv.paramXMLFile = g.option('r', null); // Parameter XML file name or null
    dv.reportDir = g.option('R', null); // Report Directory or null
    dv.outputDir = g.option('o', null); // Output Directory or null

    // Store the report directory in the preferences for this package
    // These values are stored in the root package jimm.datavision
    if (dv.reportDir != null) {
        prefs.put("reportDir",dv.reportDir);
    }
    if (dv.outputDir != null) {
        prefs.put("outputDir",dv.outputDir);
    }

    if (g.argc() == 0) {
  if (startupDialog())  // Returns true if we should exit
      return;

  if (dv.hasLayoutEngine()) // Have layout engine but no file
      usage(I18N.get("DataVision.xml_req"));
  else {
      try {
    dv.designReport(g, null);
      }
      catch (Exception e) { // Global catch-all
    ErrorHandler.error(e);
      }
  }
    }
    else {      // Loop over input files
  dv.numReports = g.argc();
  for (int i = 0; i < g.argc(); ++i) {
            File f = new File(g.argv(i));
      try {
    if (dv.hasLayoutEngine())
        dv.runReport(g, f);
    else
        dv.designReport(g, f);
View Full Code Here

Examples of jimm.util.Getopts

* each is terminated with a newline. If it is not, no newline is output but
* they are separated by spaces if more than one of -v, -c, or -u was also
* specified.
*/
public static void main(String[] args) {
    Getopts g = new Getopts("vcun", args);
    boolean moreThanOne =
  ((g.hasOption('v') ? 1 : 0)
   + (g.hasOption('c') ? 1 : 0)
   + (g.hasOption('u') ? 1 : 0)) > 1;
    String separator = g.hasOption('n') ? "\n" : " ";

    if (g.hasOption('v')) System.out.print(Version);
    if (moreThanOne) System.out.print(separator);
    if (g.hasOption('c')) System.out.print(Copyright);
    if (moreThanOne) System.out.print(separator);
    if (g.hasOption('u')) System.out.print(URL);

    if (g.hasOption('n')) System.out.println();
}
View Full Code Here

Examples of jimm.util.Getopts

    super(name);
}

public void setUp() {
    args = DEFAULT_ARGS_LIST;
    g = new Getopts("abcd:e:f:gh:i", args);
}
View Full Code Here

Examples of jimm.util.Getopts

public void testSimpleOptions() {
    String[] args = {
  "-a", "-b", "-c", "-f", "farg", "-g", "-eearg",
  "non-option-arg one", "non-option-arg two",
    };
    Getopts g = new Getopts("abcd:e:f:gh:i", args);

    assertTrue(!g.error());

    assertTrue(g.hasOption('a'));
    assertTrue(g.hasOption('b'));
    assertTrue(g.hasOption('c'));
    assertTrue(!g.hasOption('d'));
    assertTrue(g.hasOption('e'));
    assertTrue(g.hasOption('f'));
    assertTrue(g.hasOption('g'));
    assertTrue(!g.hasOption('h'));
    assertTrue(!g.hasOption('i'));
}
View Full Code Here

Examples of jimm.util.Getopts

public void testIllegalArg() {
    // Add new illegal argument -z to front of list
    String[] argsWithIllegalValue = new String[args.length + 1];
    System.arraycopy(args, 0, argsWithIllegalValue, 1, args.length);
    argsWithIllegalValue[0] = "-z";
    g = new Getopts("abcd:e:f:gh:i", argsWithIllegalValue);

    assertTrue(g.error())// That -z doesn't belong
    assertTrue(!g.hasOption('z'));
}
View Full Code Here

Examples of jimm.util.Getopts

    assertEquals(args[args.length - 1], g.argv(1));
}

public void testSimpleCommandLine() {
    String[] args = { "-p", "password", "filename" };
    Getopts g = new Getopts("cdhlxnp:s:r:", args);

    assertTrue(!g.error());
    assertEquals("password", g.option('p'));
    assertEquals(1, g.argc());
    assertEquals("filename", g.argv(0));
}
View Full Code Here

Examples of jimm.util.Getopts

public void testDummy() {
    assertTrue(true);
}

public static void main(String[] args) {
    Getopts g = new Getopts("gjJ", args);
    if (g.error()) {
  System.err.println("usage: AllTests [-g] [-j] [-J]");
  System.err.println("  -g    Use GUI test runner (ignores -j and -J flags)");
  System.err.println("  -j    Run tests that rely upon JDBC and the database");
  System.err.println("  -J    Skip non-JDBC tests");
  System.exit(0);
    }

    if (g.hasOption('g'))
  junit.swingui.TestRunner.run(AllTests.class);
    else {
  junit.textui.TestRunner.run(suite(g.hasOption('j'), g.hasOption('J')));
  System.exit(0);    // For some reason, need this under OS X 10.3
    }
}
View Full Code Here

Examples of jimm.util.Getopts

"  -h           This help");
    System.exit(1);
}

public static void main(String[] args) {
    Getopts g = new Getopts("hvd:c:s:u:p:", args);
    if (g.error() || g.hasOption('h') || !g.hasOption('d') || !g.hasOption('c')
  || !g.hasOption('u'))
  usage();

    boolean verbose = g.hasOption('v');
    try {
  // Load the database JDBC driver
  if (verbose) System.out.println("loading driver");
  Driver d = (Driver)Class.forName(g.option('d')).newInstance();
  if (verbose) System.out.println("registering driver");
  DriverManager.registerDriver(d);

  // Connect to the database
  if (verbose) System.out.println("creating database connection");
  Connection conn = DriverManager.getConnection(g.option('c'),
                  g.option('u'),
                  g.option('p'));

  // If verbose, read table names and print them
  if (verbose) {
      DatabaseMetaData dbmd = conn.getMetaData();

      System.out.println("stores lower case identifiers = "
             + dbmd.storesLowerCaseIdentifiers());
      System.out.println("stores upper case identifiers = "
             + dbmd.storesUpperCaseIdentifiers());

      System.out.println("tables:");
      ResultSet rset = dbmd.getTables(null, g.option('s'), "%", null);
      while (rset.next())
    System.out.println("  " + rset.getString("TABLE_NAME"));
      rset.close();
  }
View Full Code Here

Examples of org.watermint.sourcecolon.org.opensolaris.opengrok.util.GetOpts

    private int nhits = 0;

    @SuppressWarnings({"PMD.SwitchStmtsShouldHaveDefault"})
    protected boolean parseCmdLine(String[] argv) {
        engine = new SearchEngine();
        GetOpts getOpts = new GetOpts(argv, "R:d:r:p:h:f:");
        try {
            getOpts.parse();
        } catch (Exception e) {
            System.err.println(e.getMessage());
            System.err.println(usage);
            return false;
        }

        int cmd;
        while ((cmd = getOpts.getOpt()) != -1) {
            switch (cmd) {
                case 'R':
                    try {
                        RuntimeEnvironment.getInstance().readConfiguration(new File(getOpts.getOptionArgument()));
                    } catch (Exception e) {
                        System.err.println("Failed to read config file: ");
                        System.err.println(e.getMessage());
                        return false;
                    }
                    break;
                case 'd':
                    engine.setDefinition(getOpts.getOptionArgument());
                    break;
                case 'r':
                    engine.setSymbol(getOpts.getOptionArgument());
                    break;
                case 'p':
                    engine.setFile(getOpts.getOptionArgument());
                    break;
                case 'h':
                    engine.setHistory(getOpts.getOptionArgument());
                    break;
                case 'f':
                    engine.setFreetext(getOpts.getOptionArgument());
                    break;
            }
        }

        return true;
View Full Code Here

Examples of org.watermint.sourcecolon.org.opensolaris.opengrok.util.GetOpts

        boolean listFiles = false;
        boolean createDict = false;
        int noThreads = 2 + (2 * Runtime.getRuntime().availableProcessors());

        // Parse command line options:
        GetOpts getOpts = new GetOpts(argv, cmdOptions.getCommandString());

        try {
            getOpts.parse();
        } catch (ParseException ex) {
            System.err.println("OpenGrok: " + ex.getMessage());
            System.err.println(cmdOptions.getUsage());
            System.exit(1);
        }

        try {
            Configuration cfg = null;
            int cmd;

            // We need to read the configuration file first, since we
            // will try to overwrite options..
            while ((cmd = getOpts.getOpt()) != -1) {
                if (cmd == 'R') {
                    cfg = Configuration.read(new File(getOpts.getOptionArgument()));
                    break;
                }
            }

            if (cfg == null) {
                cfg = new Configuration();
            }

            // Now we can handle all the other options..
            getOpts.reset();
            while ((cmd = getOpts.getOpt()) != -1) {
                switch (cmd) {
                    case 'x':
                        createDict = true;
                        runIndex = false;
                        break;

                    case 'e':
                        cfg.setGenerateHtml(false);
                        break;
                    case 'P':
                        addProjects = true;
                        break;
                    case 'p':
                        defaultProject = getOpts.getOptionArgument();
                        break;
                    case 'c':
                        cfg.setCtags(getOpts.getOptionArgument());
                        break;
                    case 'w': {
                        String webapp = getOpts.getOptionArgument();
                        if (webapp.charAt(0) != '/' && !webapp.startsWith("http")) {
                            webapp = "/" + webapp;
                        }
                        if (webapp.endsWith("/")) {
                            cfg.setUrlPrefix(webapp + "s?");
                        } else {
                            cfg.setUrlPrefix(webapp + "/s?");
                        }
                    }
                    break;
                    case 'W':
                        configFilename = getOpts.getOptionArgument();
                        break;
                    case 'N':
                        allowedSymlinks.add(getOpts.getOptionArgument());
                        break;
                    case 'n':
                        runIndex = false;
                        break;
                    case 'v':
                        cfg.setVerbose(true);
                        break;
                    case 'C':
                        cfg.setPrintProgress(true);
                        break;

                    case 's': {
                        File sourceRoot = new File(getOpts.getOptionArgument());
                        if (!sourceRoot.isDirectory()) {
                            System.err.println("ERROR: Source root must be a directory");
                            System.exit(1);
                        }
                        cfg.setSourceRoot(sourceRoot.getCanonicalPath());
                        break;
                    }
                    case 'd': {
                        File dataRoot = new File(getOpts.getOptionArgument());
                        if (!dataRoot.exists() && !dataRoot.mkdirs()) {
                            System.err.println("ERROR: Cannot create data root");
                            System.exit(1);
                        }
                        if (!dataRoot.isDirectory()) {
                            System.err.println("ERROR: Data root must be a directory");
                            System.exit(1);
                        }
                        cfg.setDataRoot(dataRoot.getCanonicalPath());
                        break;
                    }
                    case 'i':
                        cfg.getIgnoredNames().add(getOpts.getOptionArgument());
                        break;
                    case 'I':
                        cfg.getIncludedNames().add(getOpts.getOptionArgument());
                        break;
                    case 'Q':
                        if (getOpts.getOptionArgument().equalsIgnoreCase(ON)) {
                            cfg.setQuickContextScan(true);
                        } else if (getOpts.getOptionArgument().equalsIgnoreCase(OFF)) {
                            cfg.setQuickContextScan(false);
                        } else {
                            System.err.println("ERROR: You should pass either \"on\" or \"off\" as argument to -Q");
                            System.err.println("       Ex: \"-Q on\" will just scan a \"chunk\" of the file and insert \"[..all..]\"");
                            System.err.println("           \"-Q off\" will try to build a more accurate list by reading the complete file.");
                        }

                        break;
                    case 'm': {
                        try {
                            cfg.setIndexWordLimit(Integer.parseInt(getOpts.getOptionArgument()));
                        } catch (NumberFormatException exp) {
                            System.err.println("ERROR: Failed to parse argument to \"-m\": " + exp.getMessage());
                            System.exit(1);
                        }
                        break;
                    }
                    case 'a':
                        if (getOpts.getOptionArgument().equalsIgnoreCase(ON)) {
                            cfg.setAllowLeadingWildcard(true);
                        } else if (getOpts.getOptionArgument().equalsIgnoreCase(OFF)) {
                            cfg.setAllowLeadingWildcard(false);
                        } else {
                            System.err.println("ERROR: You should pass either \"on\" or \"off\" as argument to -a");
                            System.err.println("       Ex: \"-a on\" will allow a search to start with a wildcard");
                            System.err.println("           \"-a off\" will disallow a search to start with a wildcard");
                            System.exit(1);
                        }

                        break;

                    case 'A': {
                        String[] arg = getOpts.getOptionArgument().split(":");
                        if (arg.length != 2) {
                            System.err.println("ERROR: You must specify: -A extension:class");
                            System.err.println("       Ex: -A foo:org.watermint.sourcecolon.org.opensolaris.opengrok.analysis.c.CAnalyzer");
                            System.err.println("           will use the C analyzer for all files ending with .foo");
                            System.err.println("       Ex: -A c:-");
                            System.err.println("           will disable the c-analyzer for for all files ending with .c");
                            System.exit(1);
                        }

                        arg[0] = arg[0].substring(arg[0].lastIndexOf('.') + 1).toUpperCase();
                        if (arg[1].equals("-")) {
                            AnalyzerGuru.addExtension(arg[0], null);
                            break;
                        }

                        try {
                            AnalyzerGuru.addExtension(
                                    arg[0],
                                    AnalyzerGuru.findFactory(arg[1]));
                        } catch (Exception e) {
                            log.log(Level.SEVERE, "Unable to use {0} as a FileAnalyzerFactory", arg[1]);
                            log.log(Level.SEVERE, "Stack: ", e.fillInStackTrace());
                            System.exit(1);
                        }
                    }
                    break;
                    case 'T':
                        try {
                            noThreads = Integer.parseInt(getOpts.getOptionArgument());
                        } catch (NumberFormatException exp) {
                            System.err.println("ERROR: Failed to parse argument to \"-T\": " + exp.getMessage());
                            System.exit(1);
                        }
                        break;
                    case 'l':
                        if (getOpts.getOptionArgument().equalsIgnoreCase(ON)) {
                            cfg.setUsingLuceneLocking(true);
                        } else if (getOpts.getOptionArgument().equalsIgnoreCase(OFF)) {
                            cfg.setUsingLuceneLocking(false);
                        } else {
                            System.err.println("ERROR: You should pass either \"on\" or \"off\" as argument to -l");
                            System.err.println("       Ex: \"-l on\" will enable locks in Lucene");
                            System.err.println("           \"-l off\" will disable locks in Lucene");
                        }
                        break;
                    case 'V':
                        System.out.println(Info.getFullVersion());
                        System.exit(0);
                        break;
                    case '?':
                        System.err.println(cmdOptions.getUsage());
                        System.exit(0);
                        break;
                    case 't':
                        try {
                            int tmp = Integer.parseInt(getOpts.getOptionArgument());
                            cfg.setTabSize(tmp);
                        } catch (NumberFormatException exp) {
                            System.err.println("ERROR: Failed to parse argument to \"-t\": " + exp.getMessage());
                            System.exit(1);
                        }
                        break;
                    default:
                        System.err.println("Internal Error - Unimplemented cmdline option: " + (char) cmd);
                        System.exit(1);
                }
            }

            int optind = getOpts.getOptionIndex();
            if (optind != -1) {
                while (optind < argv.length) {
                    subFiles.add(argv[optind]);
                    ++optind;
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.