Package com.beust.jcommander

Examples of com.beust.jcommander.ParameterException


            uri = uri.trim();
            if (uri.toLowerCase().startsWith("http:") || uri.toLowerCase().startsWith("https:")) {
                try {
                    return new URL(uri).toString();
                } catch (MalformedURLException murle) {
                    throw new ParameterException(format("Invalid URI: '%s': %s", uri, murle.getMessage()));
                }
            }

            final File f = new File(uri);
            if (!f.exists()) {
                throw new ParameterException(format("No such file: [%s]", f.getAbsolutePath()));
            }
            if (f.isDirectory()) {
                throw new ParameterException(format("Found a directory: [%s]", f.getAbsolutePath()));
            }
            return f.toURI().toString();
        }
View Full Code Here


        public PrintStream convert( String value ) {
            final File file = new File(value);
            try {
                return new PrintStream(file);
            } catch (FileNotFoundException fnfe) {
                throw new ParameterException(format("Cannot open file '%s': %s", file, fnfe.getMessage()));
            }
        }
View Full Code Here

public class PortRangeValidator implements IValueValidator<Integer> {
  @Override
  public void validate(String name, Integer value) throws ParameterException {
    if (value > Character.MAX_VALUE && value < 0) {
      throw new ParameterException(name + "=" + value + " port is used. The port should be within 0 and " +
          Character.MAX_VALUE);
    }
  }
View Full Code Here

    if (value == null) {
      return;
    }
    super.validate(name, value);
    if (!checkExactPortAvailability(null, value)) {
      throw new ParameterException(name + "=" + value + " port is already occupied by the other system " +
          "or failed to bind. Please use the other port");
    }
  }
View Full Code Here

    List<String> methods = args.commandLineMethods;

    if (testClasses == null && slave == null && testJar == null
        && (testNgXml == null || testNgXml.isEmpty())
        && (methods == null || methods.isEmpty())) {
      throw new ParameterException("You need to specify at least one testng.xml, one class"
          + " or one method");
    }

    String groups = args.groups;
    String excludedGroups = args.excludedGroups;

    if (testJar == null &&
        (null != groups || null != excludedGroups) && testClasses == null
        && (testNgXml == null || testNgXml.isEmpty())) {
      throw new ParameterException("Groups option should be used with testclass option");
    }

    if (args.slave != null && args.master != null) {
     throw new ParameterException(CommandLineArgs.SLAVE + " can't be combined with "
         + CommandLineArgs.MASTER);
    }

    Boolean junit = args.junit;
    Boolean mixed = args.mixed;
    if (junit && mixed) {
     throw new ParameterException(CommandLineArgs.MIXED + " can't be combined with "
         + CommandLineArgs.JUNIT);
    }
  }
View Full Code Here

          method = console.getClass().getDeclaredMethod("readPassword", new Class<?>[0]);
          return (char[]) method.invoke(console, new Object[0]);
      }
    }
    catch (Exception e) {
      throw new ParameterException(e);
    }
  }
View Full Code Here

  public void validate(String name, String value)
      throws ParameterException {
    int n = Integer.parseInt(value);
    if (n < 0) {
      throw new ParameterException("Parameter " + name
          + " should be positive (found " + value +")");
    }
  }
View Full Code Here

      in.close();
      isr.close();
      return result.toCharArray();
    }
    catch (IOException e) {
      throw new ParameterException(e);
    }
  }
View Full Code Here

  public Date convert(String value) {
    try {
      return DATE_FORMAT.parse(value);
    } catch (ParseException pe) {
      throw new ParameterException(getErrorString(value, String.format("an ISO-8601 formatted date (%s)", DATE_FORMAT.toPattern())));
    }
  }
View Full Code Here

  public BigDecimal convert(String value) {
    try {
      return new BigDecimal(value);
    } catch (NumberFormatException nfe) {
      throw new ParameterException(getErrorString(value, "a BigDecimal"));
    }
  }
View Full Code Here

TOP

Related Classes of com.beust.jcommander.ParameterException

Copyright © 2018 www.massapicom. 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.