Example #1
0
  protected static Object[] extractMockArguments(Object[] args) {
    int i = 7;

    if (args.length > i) {
      Object[] mockArgs = new Object[args.length - i];
      System.arraycopy(args, i, mockArgs, 0, mockArgs.length);
      return mockArgs;
    }

    return EMPTY_ARGS;
  }
Example #2
0
 /** Parses command line arguments. */
 boolean parseArgs(String args[]) {
   /* Preprocess and expand @file arguments */
   try {
     args = CommandLine.parse(args);
   } catch (FileNotFoundException e) {
     fatalError(formatMsg("error.cant.open", e.getMessage()));
     return false;
   } catch (IOException e) {
     fatalError(e);
     return false;
   }
   /* parse flags */
   int count = 1;
   try {
     String flags = args[0];
     if (flags.startsWith("-")) {
       flags = flags.substring(1);
     }
     for (int i = 0; i < flags.length(); i++) {
       switch (flags.charAt(i)) {
         case 'c':
           if (xflag || tflag || uflag || iflag) {
             usageError();
             return false;
           }
           cflag = true;
           break;
         case 'u':
           if (cflag || xflag || tflag || iflag) {
             usageError();
             return false;
           }
           uflag = true;
           break;
         case 'x':
           if (cflag || uflag || tflag || iflag) {
             usageError();
             return false;
           }
           xflag = true;
           break;
         case 't':
           if (cflag || uflag || xflag || iflag) {
             usageError();
             return false;
           }
           tflag = true;
           break;
         case 'M':
           Mflag = true;
           break;
         case 'v':
           vflag = true;
           break;
         case 'f':
           fname = args[count++];
           break;
         case 'm':
           mname = args[count++];
           break;
         case '0':
           flag0 = true;
           break;
         case 'i':
           if (cflag || uflag || xflag || tflag) {
             usageError();
             return false;
           }
           // do not increase the counter, files will contain rootjar
           rootjar = args[count++];
           iflag = true;
           break;
         case 'e':
           ename = args[count++];
           break;
         case 'p':
           pname = args[count++];
           break;
         default:
           error(formatMsg("error.illegal.option", String.valueOf(flags.charAt(i))));
           usageError();
           return false;
       }
     }
   } catch (ArrayIndexOutOfBoundsException e) {
     usageError();
     return false;
   }
   if (!cflag && !tflag && !xflag && !uflag && !iflag) {
     error(getMsg("error.bad.option"));
     usageError();
     return false;
   }
   /* parse file arguments */
   int n = args.length - count;
   if (n > 0) {
     int k = 0;
     String[] nameBuf = new String[n];
     try {
       for (int i = count; i < args.length; i++) {
         if (args[i].equals("-C")) {
           /* change the directory */
           String dir = args[++i];
           dir = (dir.endsWith(File.separator) ? dir : (dir + File.separator));
           dir = dir.replace(File.separatorChar, '/');
           while (dir.indexOf("//") > -1) {
             dir = dir.replace("//", "/");
           }
           paths.add(dir.replace(File.separatorChar, '/'));
           nameBuf[k++] = dir + args[++i];
         } else {
           nameBuf[k++] = args[i];
         }
       }
     } catch (ArrayIndexOutOfBoundsException e) {
       usageError();
       return false;
     }
     files = new String[k];
     System.arraycopy(nameBuf, 0, files, 0, k);
   } else if (cflag && (mname == null)) {
     error(getMsg("error.bad.cflag"));
     usageError();
     return false;
   } else if (uflag) {
     if ((mname != null) || (ename != null) || (pname != null)) {
       /* just want to update the manifest */
       return true;
     } else {
       error(getMsg("error.bad.uflag"));
       usageError();
       return false;
     }
   }
   return true;
 }