Exemplo n.º 1
0
  // added for debug purposes....
  protected static String[] getSourceFiles(CompilerConfiguration config) {
    Set sources = new HashSet();

    // Set sourceFiles = null;
    // was:
    Set sourceFiles = config.getSourceFiles();

    if (sourceFiles != null && !sourceFiles.isEmpty()) {
      for (Iterator it = sourceFiles.iterator(); it.hasNext(); ) {
        Object o = it.next();

        File sourceFile = null;

        if (o instanceof String) {
          sourceFile = new File((String) o);
          System.out.println((String) o);
        } else if (o instanceof File) {
          sourceFile = (File) o;
        } else {
          break; // ignore it
        }

        sources.add(sourceFile.getAbsolutePath());
      }
    } else {
      for (Iterator it = config.getSourceLocations().iterator(); it.hasNext(); ) {
        String sourceLocation = (String) it.next();

        sources.addAll(getSourceFilesForSourceRoot(config, sourceLocation));
      }
    }

    String[] result;

    if (sources.isEmpty()) {
      result = new String[0];
    } else {
      result = (String[]) sources.toArray(new String[sources.size()]);
    }

    return result;
  }
Exemplo n.º 2
0
  public static String[] buildCompilerArguments(
      CompilerConfiguration config, String[] sourceFiles) {
    List args = new ArrayList();

    // ----------------------------------------------------------------------
    // Set output
    // ----------------------------------------------------------------------

    File destinationDir = new File(config.getOutputLocation());

    args.add("-d");

    args.add(destinationDir.getAbsolutePath());

    // ----------------------------------------------------------------------
    // Set the class and source paths
    // ----------------------------------------------------------------------

    List classpathEntries = config.getClasspathEntries();
    if (classpathEntries != null && !classpathEntries.isEmpty()) {
      args.add("-classpath");

      args.add(getPathString(classpathEntries));
    }

    List sourceLocations = config.getSourceLocations();
    if (sourceLocations != null && !sourceLocations.isEmpty()) {
      args.add("-sourcepath");

      args.add(getPathString(sourceLocations));
    }

    for (int i = 0; i < sourceFiles.length; i++) {
      args.add(sourceFiles[i]);
    }

    if (config.isOptimize()) {
      args.add("-O");
    }

    if (config.isDebug()) {
      args.add("-g");
    }

    if (config.isVerbose()) {
      args.add("-verbose");
    }

    if (config.isShowDeprecation()) {
      args.add("-deprecation");

      // This is required to actually display the deprecation messages
      config.setShowWarnings(true);
    }

    if (!config.isShowWarnings()) {
      args.add("-nowarn");
    }

    // TODO: this could be much improved
    if (StringUtils.isEmpty(config.getTargetVersion())) {
      // Required, or it defaults to the target of your JDK (eg 1.5)
      args.add("-target");
      args.add("1.1");
    } else {
      args.add("-target");
      args.add(config.getTargetVersion());
    }

    if (!suppressSource(config) && StringUtils.isEmpty(config.getSourceVersion())) {
      // If omitted, later JDKs complain about a 1.1 target
      args.add("-source");
      args.add("1.3");
    } else if (!suppressSource(config)) {
      args.add("-source");
      args.add(config.getSourceVersion());
    }

    if (!suppressEncoding(config) && !StringUtils.isEmpty(config.getSourceEncoding())) {
      args.add("-encoding");
      args.add(config.getSourceEncoding());
    }

    for (Iterator it = config.getCustomCompilerArguments().entrySet().iterator(); it.hasNext(); ) {
      Map.Entry entry = (Map.Entry) it.next();

      String key = (String) entry.getKey();

      if (StringUtils.isEmpty(key)) {
        continue;
      }

      args.add(key);

      String value = (String) entry.getValue();

      if (StringUtils.isEmpty(value)) {
        continue;
      }

      args.add(value);
    }

    return (String[]) args.toArray(new String[args.size()]);
  }