Beispiel #1
0
  /**
   * {@inheritDoc}
   *
   * <p>All necessary setup for the module. Populate the "processing" table in seqware_meta_db.
   * Create a temporary directory.
   */
  @Override
  public ReturnValue init() {

    ReturnValue ret = new ReturnValue();
    ret.setExitStatus(ReturnValue.SUCCESS);
    // fill in the [xxx] fields in the processing table
    ret.setAlgorithm("TrimAllReads");
    ret.setDescription("Trim all reads to a specific length.");
    ret.setVersion("0.7.0");

    try {
      OptionParser parser = getOptionParser();
      // The parameters object is actually an ArrayList of Strings created
      // by splitting the command line options by space. JOpt expects a String[]
      options = parser.parse(this.getParameters().toArray(new String[0]));
      // create a temp directory in current working directory
      // tempDir = FileTools.createTempDirectory(new File("."));
      // you can write to "stdout" or "stderr" which will be persisted back to the DB
      ret.setStdout(ret.getStdout() + "Output: " + (String) options.valueOf("outfastq") + "\n");
    } catch (OptionException e) {
      e.printStackTrace();
      ret.setStderr(e.getMessage());
      ret.setExitStatus(ReturnValue.INVALIDPARAMETERS);
    } // catch (IOException e) {
    //  e.printStackTrace();
    //  ret.setStderr(e.getMessage());
    //  ret.setExitStatus(ReturnValue.DIRECTORYNOTWRITABLE);
    // }

    return (ret);
  }
Beispiel #2
0
  private static OptionSet parseOptions(String[] argv) throws IOException {
    OptionSet args = null;
    OptionParser parser = new OptionParser();
    parser.acceptsAll(Arrays.asList("l", CMD_LIST), "list readers");
    parser.acceptsAll(Arrays.asList("p", OPT_PROVIDER), "specify provider").withRequiredArg();
    parser.acceptsAll(Arrays.asList("v", OPT_VERBOSE), "be verbose");
    parser.acceptsAll(Arrays.asList("e", OPT_ERROR), "fail if not 0x9000");
    parser.acceptsAll(Arrays.asList("h", OPT_HELP), "show help");
    parser.acceptsAll(Arrays.asList("r", OPT_READER), "use reader").withRequiredArg();
    parser.acceptsAll(Arrays.asList("a", CMD_APDU), "send APDU").withRequiredArg();
    parser.acceptsAll(Arrays.asList("w", OPT_WEB), "open ATR in web");
    parser.acceptsAll(Arrays.asList("V", OPT_VERSION), "show version information");
    parser.accepts(OPT_DUMP, "save dump to file").withRequiredArg().ofType(File.class);
    parser.accepts(OPT_REPLAY, "replay command from dump").withRequiredArg().ofType(File.class);

    parser.accepts(OPT_SUN, "load SunPCSC");
    parser.accepts(OPT_JNA, "load jnasmartcardio");
    parser.accepts(OPT_CONNECT, "connect to host:port or URL").withRequiredArg();
    parser.accepts(OPT_PINNED, "require certificate").withRequiredArg().ofType(File.class);

    parser.accepts(OPT_PROVIDERS, "list providers");
    parser.accepts(OPT_ALL, "process all readers");
    parser.accepts(OPT_WAIT, "wait for card insertion");
    parser.accepts(OPT_T0, "use T=0");
    parser.accepts(OPT_T1, "use T=1");
    parser.accepts(OPT_TEST_SERVER, "run a test server on port 10000").withRequiredArg();
    parser.accepts(OPT_NO_GET_RESPONSE, "don't use GET RESPONSE with SunPCSC");
    parser.accepts(OPT_LIB, "use specific PC/SC lib with SunPCSC").withRequiredArg();
    parser.accepts(OPT_PROVIDER_TYPE, "provider type if not PC/SC").withRequiredArg();

    // Parse arguments
    try {
      args = parser.parse(argv);
      // Try to fetch all values so that format is checked before usage
      for (String s : parser.recognizedOptions().keySet()) {
        args.valuesOf(s);
      }
    } catch (OptionException e) {
      if (e.getCause() != null) {
        System.err.println(e.getMessage() + ": " + e.getCause().getMessage());
      } else {
        System.err.println(e.getMessage());
      }
      System.err.println();
      help_and_exit(parser, System.err);
    }
    if (args.has(OPT_HELP)) {
      help_and_exit(parser, System.out);
    }
    return args;
  }
 private OptionSet parseOptions(OptionParser p, String[] args) throws IOException {
   OptionSet options = null;
   try {
     options = p.parse(args);
     if (options.has("?")
         || !options.has(maxwiOptName)
         || options.nonOptionArguments().size() < 2) {
       System.err.println("Usage:\nSimilarity <input_paths> <output_path> [options]");
       System.err.println("Please specify " + maxwiOptName + " option\n");
       p.printHelpOn(System.err);
       System.exit(0);
     }
   } catch (OptionException e) {
     System.err.println(e.getMessage());
     System.exit(1);
   }
   return options;
 }
 public static void main(final String[] args) throws IOException {
   final MappingTestServerOptionParser parser = new MappingTestServerOptionParser();
   try {
     final OptionSet options = parser.parse(args);
     if (options.has("help")) {
       parser.printHelpOn(System.out);
     } else {
       final String host = options.valueOf(parser.hostOption);
       final Integer port = options.valueOf(parser.portOption);
       final MappingTestServer server =
           new MappingTestServer(
               options.valueOf(parser.schemaOption),
               options.valueOf(parser.mappingOption),
               port,
               host);
       Runtime.getRuntime().addShutdownHook(new Thread(server::stopServer));
       log.info("Starting server on {}:{}...", host, port);
       server.runServer();
     }
   } catch (final OptionException e) {
     System.err.println(e.getLocalizedMessage());
     parser.printHelpOn(System.err);
   }
 }
Beispiel #5
0
  public static void main(String[] args) throws Exception {
    // We don't want to do the full argument parsing here as that might easily change in update
    // versions
    // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    parser
        .accepts(USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR))
        .withRequiredArg();
    parser
        .accepts(APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME))
        .withRequiredArg();

    OptionSet options;
    try {
      options = parser.parse(args);
    } catch (OptionException ex) {
      System.out.println("error: " + ex.getMessage());
      System.out.println();
      parser.printHelpOn(System.out);
      System.exit(EXIT_FAILURE);
      return;
    }
    BitsquareEnvironment bitsquareEnvironment = new BitsquareEnvironment(options);

    // need to call that before BitsquareAppMain().execute(args)
    initAppDir(bitsquareEnvironment.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY));

    // For some reason the JavaFX launch process results in us losing the thread context class
    // loader: reset it.
    // In order to work around a bug in JavaFX 8u25 and below, you must include the following code
    // as the first line of your realMain method:
    Thread.currentThread().setContextClassLoader(BitsquareAppMain.class.getClassLoader());

    new BitsquareAppMain().execute(args);
  }
  public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser("p:f:c:r:H:s:t:h");
    OptionSet options = null;
    try {
      options = parser.parse(args);
    } catch (OptionException ex) {
      System.err.println(ex.getMessage());
      System.exit(1);
    }

    if (options.has("h")) {
      printHelp(System.out);
      System.exit(0);
    }

    final int port;
    if (options.has("p")) {
      String portStr = options.valueOf("p").toString();
      try {
        port = Integer.parseInt(portStr);
      } catch (NumberFormatException ex) {
        throw new IllegalArgumentException("Invalid port number: " + portStr, ex);
      }
    } else {
      port = -1;
      System.err.println("Mandatory parameter port not given.");
      System.exit(1);
    }

    AnyUrlServlet servlet = new AnyUrlServlet();

    if (options.has("f")) {
      String fileStr = options.valueOf("f").toString();
      servlet.setFile(new File(fileStr));
    }

    if (options.has("c")) {
      servlet.setContentType(options.valueOf("c").toString());
    }

    if (options.has("r")) {
      servlet.setCharset(options.valueOf("r").toString());
    }

    if (options.has("H")) {
      MultiValueMap headers = new MultiValueMapLinkedHashSet();
      for (Object t : options.valuesOf("H")) {
        final String headerLine = t.toString().trim();
        final int sepIdx = headerLine.indexOf(':');
        if ((sepIdx > 0) && (sepIdx < headerLine.length())) {
          final String header = headerLine.substring(0, sepIdx).trim();
          final String value = headerLine.substring(sepIdx + 1).trim();
          // System.out.printf("\nHeader: Value => %s:%s\n", header, value);
          headers.put(header, value);
        }
      }
      servlet.setHeaders(headers);
    }

    if (options.has("s")) {
      try {
        int statusCode = Integer.parseInt(options.valueOf("s").toString());
        servlet.setStatusCode(statusCode);
      } catch (NumberFormatException ex) {
        throw new IllegalArgumentException("Param -s must be a valid status code.");
      }
    }

    if (options.has("t")) {
      try {
        long throttleMillis = Long.parseLong(options.valueOf("t").toString());
        if (throttleMillis > 1) {
          servlet.setThrottleMillis(throttleMillis);
        } else {
          throw new NumberFormatException();
        }
      } catch (NumberFormatException ex) {
        throw new IllegalArgumentException("Param -t must be a valid number.");
      }
    }

    Server server = new Server(port);
    server.setStopAtShutdown(true);

    // Attach the servlet:
    ServletContextHandler ctx = new ServletContextHandler();
    ctx.setContextPath("/");
    server.setHandler(ctx);
    ctx.addServlet(new ServletHolder(servlet), "/*");

    server.start();
  }
Beispiel #7
0
  public static void main(String[] args) {
    // Todo: Installation script
    OptionParser parser =
        new OptionParser() {
          {
            acceptsAll(asList("?", "help"), "Show the help");

            acceptsAll(asList("c", "config"), "Properties file to use")
                .withRequiredArg()
                .ofType(File.class)
                .defaultsTo(new File("server.properties"))
                .describedAs("Properties file");

            acceptsAll(asList("P", "plugins"), "Plugin directory to use")
                .withRequiredArg()
                .ofType(File.class)
                .defaultsTo(new File("plugins"))
                .describedAs("Plugin directory");

            acceptsAll(asList("h", "host", "server-ip"), "Host to listen on")
                .withRequiredArg()
                .ofType(String.class)
                .describedAs("Hostname or IP");

            acceptsAll(asList("W", "world-dir", "universe", "world-container"), "World container")
                .withRequiredArg()
                .ofType(File.class)
                .describedAs("Directory containing worlds");

            acceptsAll(asList("w", "world", "level-name"), "World name")
                .withRequiredArg()
                .ofType(String.class)
                .describedAs("World name");

            acceptsAll(asList("p", "port", "server-port"), "Port to listen on")
                .withRequiredArg()
                .ofType(Integer.class)
                .describedAs("Port");

            acceptsAll(asList("o", "online-mode"), "Whether to use online authentication")
                .withRequiredArg()
                .ofType(Boolean.class)
                .describedAs("Authentication");

            acceptsAll(asList("s", "size", "max-players"), "Maximum amount of players")
                .withRequiredArg()
                .ofType(Integer.class)
                .describedAs("Server size");

            acceptsAll(
                    asList("d", "date-format"),
                    "Format of the date to display in the console (for log entries)")
                .withRequiredArg()
                .ofType(SimpleDateFormat.class)
                .describedAs("Log date format");

            acceptsAll(asList("log-pattern"), "Specfies the log filename pattern")
                .withRequiredArg()
                .ofType(String.class)
                .defaultsTo("server.log")
                .describedAs("Log filename");

            acceptsAll(
                    asList("log-limit"), "Limits the maximum size of the log file (0 = unlimited)")
                .withRequiredArg()
                .ofType(Integer.class)
                .defaultsTo(0)
                .describedAs("Max log size");

            acceptsAll(asList("log-count"), "Specified how many log files to cycle through")
                .withRequiredArg()
                .ofType(Integer.class)
                .defaultsTo(1)
                .describedAs("Log count");

            acceptsAll(asList("log-append"), "Whether to append to the log file")
                .withRequiredArg()
                .ofType(Boolean.class)
                .defaultsTo(true)
                .describedAs("Log append");

            acceptsAll(asList("log-strip-color"), "Strips color codes from log file");

            acceptsAll(asList("b", "bukkit-settings"), "File for bukkit settings")
                .withRequiredArg()
                .ofType(File.class)
                .defaultsTo(new File("bukkit.yml"))
                .describedAs("Yml file");

            acceptsAll(asList("C", "commands-settings"), "File for command settings")
                .withRequiredArg()
                .ofType(File.class)
                .defaultsTo(new File("commands.yml"))
                .describedAs("Yml file");

            acceptsAll(asList("nojline"), "Disables jline and emulates the vanilla console");

            acceptsAll(asList("noconsole"), "Disables the console");

            acceptsAll(asList("v", "version"), "Show the CraftBukkit Version");

            acceptsAll(asList("demo"), "Demo mode");
          }
        };

    OptionSet options = null;

    try {
      options = parser.parse(args);
    } catch (joptsimple.OptionException ex) {
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage());
    }

    if ((options == null) || (options.has("?"))) {
      try {
        parser.printHelpOn(System.out);
      } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
      }
    } else if (options.has("v")) {
      System.out.println(CraftServer.class.getPackage().getImplementationVersion());
    } else {
      try {
        // This trick bypasses Maven Shade's clever rewriting of our getProperty call when using
        // String literals
        String jline_UnsupportedTerminal =
            new String(
                new char[] {
                  'j', 'l', 'i', 'n', 'e', '.', 'U', 'n', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e',
                  'd', 'T', 'e', 'r', 'm', 'i', 'n', 'a', 'l'
                });
        String jline_terminal =
            new String(
                new char[] {'j', 'l', 'i', 'n', 'e', '.', 't', 'e', 'r', 'm', 'i', 'n', 'a', 'l'});

        useJline = !(jline_UnsupportedTerminal).equals(System.getProperty(jline_terminal));

        if (options.has("nojline")) {
          System.setProperty("user.language", "en");
          useJline = false;
        }

        if (!useJline) {
          // This ensures the terminal literal will always match the jline implementation
          System.setProperty(
              jline.TerminalFactory.JLINE_TERMINAL, jline.UnsupportedTerminal.class.getName());
        }

        if (options.has("noconsole")) {
          useConsole = false;
        }

        // Spigot Start
        int maxPermGen = 0; // In kb
        for (String s :
            java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments()) {
          if (s.startsWith("-XX:MaxPermSize")) {
            maxPermGen = Integer.parseInt(s.replaceAll("[^\\d]", ""));
            maxPermGen <<= 10 * ("kmg".indexOf(Character.toLowerCase(s.charAt(s.length() - 1))));
          }
        }
        if (maxPermGen < (128 << 10)) // 128mb
        {
          System.out.println(
              "Warning, your max perm gen size is not set or less than 128mb. It is recommended you restart Java with the following argument: -XX:MaxPermSize=128M");
          System.out.println(
              "Please see http://www.spigotmc.org/wiki/changing-permgen-size/ for more details and more in-depth instructions.");
        }
        // Spigot End
        System.out.println("Loading libraries, please wait...");
        MinecraftServer.main(options);
      } catch (Throwable t) {
        t.printStackTrace();
      }
    }
  }