Package org.kohsuke.args4j

Examples of org.kohsuke.args4j.CmdLineException


  }

  @Override
  protected Character parse(String argument) throws NumberFormatException, CmdLineException {
        if (argument.length() != 1)
            throw new CmdLineException(owner, Messages.ILLEGAL_CHAR.format(argument));
        return argument.charAt(0);
  }
View Full Code Here


    if (new File(name).isFile()) {
      final DirCache dirc;
      try {
        dirc = DirCache.read(new File(name), FS.DETECTED);
      } catch (IOException e) {
        throw new CmdLineException(MessageFormat.format(CLIText.get().notAnIndexFile, name), e);
      }
      setter.addValue(new DirCacheIterator(dirc));
      return 1;
    }

    final ObjectId id;
    try {
      id = clp.getRepository().resolve(name);
    } catch (IOException e) {
      throw new CmdLineException(e.getMessage());
    }
    if (id == null)
      throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));

    final CanonicalTreeParser p = new CanonicalTreeParser();
    final ObjectReader curs = clp.getRepository().newObjectReader();
    try {
      p.reset(curs, clp.getRevWalk().parseTree(id));
    } catch (MissingObjectException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
    } catch (IncorrectObjectTypeException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
    } catch (IOException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
    } finally {
      curs.release();
    }

    setter.addValue(p);
View Full Code Here

    }

    final int dot2 = name.indexOf(".."); //$NON-NLS-1$
    if (dot2 != -1) {
      if (!option.isMultiValued())
        throw new CmdLineException(MessageFormat.format(CLIText.get().onlyOneMetaVarExpectedIn
          , option.metaVar(), name));

      final String left = name.substring(0, dot2);
      final String right = name.substring(dot2 + 2);
      addOne(left, false);
View Full Code Here

      throws CmdLineException {
    final ObjectId id;
    try {
      id = clp.getRepository().resolve(name);
    } catch (IOException e) {
      throw new CmdLineException(e.getMessage());
    }
    if (id == null)
      throw new CmdLineException(MessageFormat.format(CLIText.get().notACommit, name));

    final RevCommit c;
    try {
      c = clp.getRevWalk().parseCommit(id);
    } catch (MissingObjectException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().notACommit, name));
    } catch (IncorrectObjectTypeException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().notACommit, name));
    } catch (IOException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
    }

    if (interesting)
      c.remove(RevFlag.UNINTERESTING);
    else
View Full Code Here

    final String name = params.getParameter(0);
    final ObjectId id;
    try {
      id = clp.getRepository().resolve(name);
    } catch (IOException e) {
      throw new CmdLineException(e.getMessage());
    }
    if (id != null) {
      setter.addValue(id);
      return 1;
    }

    throw new CmdLineException(MessageFormat.format(CLIText.get().notAnObject, name));
  }
View Full Code Here

  @Override
  public int parseArguments(final Parameters params) throws CmdLineException {
    final String name = params.getParameter(0);
    final CommandRef cr = CommandCatalog.get(name);
    if (cr == null)
      throw new CmdLineException(MessageFormat.format(
          CLIText.get().notAJgitCommand, name));

    // Force option parsing to stop. Everything after us should
    // be arguments known only to this command and must not be
    // recognized by the current parser.
View Full Code Here

    final String name = params.getParameter(0);
    final ObjectId id;
    try {
      id = clp.getRepository().resolve(name);
    } catch (IOException e) {
      throw new CmdLineException(e.getMessage());
    }
    if (id == null)
      throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));

    final RevTree c;
    try {
      c = clp.getRevWalk().parseTree(id);
    } catch (MissingObjectException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
    } catch (IncorrectObjectTypeException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
    } catch (IOException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
    }
    setter.addValue(c);
    return 1;
  }
View Full Code Here

    public static MetadataContainer<MetadataValue> getContainer(String node, String job, Integer build,
                                                                boolean createContainer)
            throws CmdLineException, NoItemException, NoMetadataException, IOException {

        if ((node == null || node.isEmpty()) && (job == null || job.isEmpty())) {
            throw new CmdLineException(null, "You must provide either a job or a node.");
        }
        if (build != null && (job == null || job.isEmpty())) {
            throw new CmdLineException(null, "You must provide a job for this build.");
        }
        MetadataContainer<MetadataValue> container = null;
        if (node != null && !node.isEmpty()) {
            Node theNode = Hudson.getInstance().getNode(node);
            if (theNode == null) {
View Full Code Here

     */
    @Test
    public void testDoGetNothing() throws Exception {
        String message = "You must provide either a job or a node.";
        PowerMockito.when(CliUtils.getContainer(null, null, null, false))
                .thenThrow(new CmdLineException(null, message));

        doAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                printed = (String)invocation.getArguments()[0];
View Full Code Here

    public int parseArguments(Parameters params) throws CmdLineException {
      try {
        setter.addValue(Long.parseLong(params.getParameter(0)));
        return 1;
      } catch (NumberFormatException e) {
        throw new CmdLineException(e);
      }
    }
View Full Code Here

TOP

Related Classes of org.kohsuke.args4j.CmdLineException

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.