コード例 #1
0
  private int verifyVersionEx() {
    String min = getMinVersion();
    String max = getMaxVersion();
    int retval = OK;
    // No min and max, version always ok.
    if (min == null && max == null) return (OK);

    if (!pathIsValid()) return (BAD_REAL_PATH);
    // No get the version ...
    // We cannot look to the version of this vm because we should
    // test the given JDK VM.
    String[] params = {
      pathSelectionPanel.getPath() + File.separator + "bin" + File.separator + "java", "-version"
    };
    String[] output = new String[2];
    FileExecutor fe = new FileExecutor();
    fe.executeCommand(params, output);
    // "My" VM writes the version on stderr :-(
    String vs = (output[0].length() > 0) ? output[0] : output[1];
    if (min != null) {
      if (!compareVersions(vs, min, true, 4, 4, "__NO_NOT_IDENTIFIER_")) retval = BAD_VERSION;
    }
    if (max != null)
      if (!compareVersions(vs, max, false, 4, 4, "__NO_NOT_IDENTIFIER_")) retval = BAD_VERSION;
    if (retval == OK
        && badRegEntries != null
        && badRegEntries.size() > 0) { // Test for bad registry entry.
      if (badRegEntries.contains(getDetectedVersion())) retval = BAD_REG_PATH;
    }
    return (retval);
  }
コード例 #2
0
    /**
     * Internal helper method.
     *
     * @param executor The executor, only used when using external compiler.
     * @param output The output from the compiler ([0] = stdout, [1] = stderr)
     * @return The result of the compilation.
     */
    private int runCompiler(FileExecutor executor, String[] output, List<String> cmdline) {
      if (cmdline.get(0).equals(ECLIPSE_COMPILER_NAME)) {
        return runEclipseCompiler(output, cmdline);
      }

      return executor.executeCommand(cmdline.toArray(new String[cmdline.size()]), output);
    }
コード例 #3
0
    /**
     * Check whether the given compiler works.
     *
     * <p>This performs two steps:
     *
     * <ol>
     *   <li>check whether we can successfully call "compiler -help"
     *   <li>check whether we can successfully call "compiler -help arguments" (not all compilers
     *       return an error here)
     * </ol>
     *
     * On failure, the method CompileHandler#errorCompile is called with a descriptive error
     * message.
     *
     * @param compiler the compiler to use
     * @param arguments additional arguments to pass to the compiler
     * @return false on error
     */
    public CompileResult checkCompiler(String compiler, ArrayList arguments) {
      int retval = 0;
      FileExecutor executor = new FileExecutor();
      String[] output = new String[2];

      Debug.trace("checking whether \"" + compiler + " -help\" works");

      {
        String[] args = {compiler, "-help"};

        retval = executor.executeCommand(args, output);

        if (retval != 0) {
          CompileResult result =
              new CompileResult(
                  this.langpack.getString("CompilePanel.error.compilernotfound"),
                  args,
                  output[0],
                  output[1]);
          this.listener.handleCompileError(result);
          if (!result.isContinue()) return result;
        }
      }

      Debug.trace("checking whether \"" + compiler + " -help +arguments\" works");

      // used to collect the arguments for executing the compiler
      LinkedList args = new LinkedList(arguments);

      // add -help argument to prevent the compiler from doing anything
      args.add(0, "-help");

      // add compiler in front of arguments
      args.add(0, compiler);

      // construct classpath argument for compiler
      // - collect all classpaths
      StringBuffer classpath_sb = new StringBuffer();
      Iterator cp_it = this.classpath.iterator();
      while (cp_it.hasNext()) {
        String cp = (String) cp_it.next();
        if (classpath_sb.length() > 0) classpath_sb.append(File.pathSeparatorChar);
        classpath_sb.append(new File(cp).getAbsolutePath());
      }

      String classpath_str = classpath_sb.toString();

      // - add classpath argument to command line
      if (classpath_str.length() > 0) {
        args.add("-classpath");
        args.add(classpath_str);
      }

      String[] args_arr = (String[]) args.toArray(output);

      retval = executor.executeCommand(args_arr, output);

      if (retval != 0) {
        CompileResult result =
            new CompileResult(
                this.langpack.getString("CompilePanel.error.invalidarguments"),
                args_arr,
                output[0],
                output[1]);
        this.listener.handleCompileError(result);
        if (!result.isContinue()) return result;
      }

      return new CompileResult();
    }
コード例 #4
0
    public CompileResult perform(String compiler, ArrayList arguments) {
      Debug.trace("starting job " + this.name);
      // we have some maximum command line length - need to count
      int cmdline_len = 0;

      // used to collect the arguments for executing the compiler
      LinkedList args = new LinkedList(arguments);

      {
        Iterator arg_it = args.iterator();
        while (arg_it.hasNext()) cmdline_len += ((String) arg_it.next()).length() + 1;
      }

      // add compiler in front of arguments
      args.add(0, compiler);
      cmdline_len += compiler.length() + 1;

      // construct classpath argument for compiler
      // - collect all classpaths
      StringBuffer classpath_sb = new StringBuffer();
      Iterator cp_it = this.classpath.iterator();
      while (cp_it.hasNext()) {
        String cp = (String) cp_it.next();
        if (classpath_sb.length() > 0) classpath_sb.append(File.pathSeparatorChar);
        classpath_sb.append(new File(cp).getAbsolutePath());
      }

      String classpath_str = classpath_sb.toString();

      // - add classpath argument to command line
      if (classpath_str.length() > 0) {
        args.add("-classpath");
        cmdline_len = cmdline_len + 11;
        args.add(classpath_str);
        cmdline_len += classpath_str.length() + 1;
      }

      // remember how many arguments we have which don't change for the
      // job
      int common_args_no = args.size();
      // remember how long the common command line is
      int common_args_len = cmdline_len;

      // used for execution
      FileExecutor executor = new FileExecutor();
      String output[] = new String[2];

      // used for displaying the progress bar
      String jobfiles = "";
      int fileno = 0;
      int last_fileno = 0;

      // now iterate over all files of this job
      Iterator file_it = this.files.iterator();

      while (file_it.hasNext()) {
        File f = (File) file_it.next();

        String fpath = f.getAbsolutePath();

        Debug.trace("processing " + fpath);

        // we add the file _first_ to the arguments to have a better
        // chance to get something done if the command line is almost
        // MAX_CMDLINE_SIZE or even above
        fileno++;
        jobfiles += f.getName() + " ";
        args.add(fpath);
        cmdline_len += fpath.length();

        // start compilation if maximum command line length reached
        if (cmdline_len >= MAX_CMDLINE_SIZE) {
          Debug.trace("compiling " + jobfiles);

          // display useful progress bar (avoid showing 100% while
          // still
          // compiling a lot)
          this.listener.progress(last_fileno, jobfiles);
          last_fileno = fileno;

          String[] full_cmdline = (String[]) args.toArray(output);

          int retval = executor.executeCommand(full_cmdline, output);

          // update progress bar: compilation of fileno files done
          this.listener.progress(fileno, jobfiles);

          if (retval != 0) {
            CompileResult result =
                new CompileResult(
                    this.langpack.getString("CompilePanel.error"),
                    full_cmdline,
                    output[0],
                    output[1]);
            this.listener.handleCompileError(result);
            if (!result.isContinue()) return result;
          } else {
            // verify that all files have been compiled successfully
            // I found that sometimes, no error code is returned
            // although
            // compilation failed.
            Iterator arg_it = args.listIterator(common_args_no);
            while (arg_it.hasNext()) {
              File java_file = new File((String) arg_it.next());

              String basename = java_file.getName();
              int dotpos = basename.lastIndexOf('.');
              basename = basename.substring(0, dotpos) + ".class";
              File class_file = new File(java_file.getParentFile(), basename);

              if (!class_file.exists()) {
                CompileResult result =
                    new CompileResult(
                        this.langpack.getString("CompilePanel.error.noclassfile")
                            + java_file.getAbsolutePath(),
                        full_cmdline,
                        output[0],
                        output[1]);
                this.listener.handleCompileError(result);
                if (!result.isContinue()) return result;
                // don't continue any further
                break;
              }
            }
          }

          // clean command line: remove files we just compiled
          for (int i = args.size() - 1; i >= common_args_no; i--) {
            args.removeLast();
          }

          cmdline_len = common_args_len;
          jobfiles = "";
        }
      }

      if (cmdline_len > common_args_len) {
        this.listener.progress(last_fileno, jobfiles);

        String[] full_cmdline = (String[]) args.toArray(output);

        int retval = executor.executeCommand(full_cmdline, output);

        this.listener.progress(fileno, jobfiles);

        if (retval != 0) {
          CompileResult result =
              new CompileResult(
                  this.langpack.getString("CompilePanel.error"),
                  full_cmdline,
                  output[0],
                  output[1]);
          this.listener.handleCompileError(result);
          if (!result.isContinue()) return result;
        }
      }

      Debug.trace("job " + this.name + " done (" + fileno + " files compiled)");

      return new CompileResult();
    }