Example #1
0
  private Iterable<String> _createOptions(
      List<? extends File> classPath,
      List<? extends File> sourcePath,
      File destination,
      List<? extends File> bootClassPath,
      String sourceVersion,
      boolean showWarnings) {
    if (bootClassPath == null) {
      bootClassPath = _defaultBootClassPath;
    }

    LinkedList<String> options = new LinkedList<String>();
    for (Map.Entry<String, String> e : CompilerOptions.getOptions(showWarnings).entrySet()) {
      options.add(e.getKey());
      if (e.getValue().length() > 0) options.add(e.getValue());
    }
    options.add("-g");

    if (classPath != null) {
      options.add("-classpath");
      options.add(IOUtil.pathToString(classPath));
    }
    if (sourcePath != null) {
      options.add("-sourcepath");
      options.add(IOUtil.pathToString(sourcePath));
    }
    if (destination != null) {
      options.add("-d");
      options.add(destination.getPath());
    }
    if (bootClassPath != null) {
      options.add("-bootclasspath");
      options.add(IOUtil.pathToString(bootClassPath));
    }
    if (sourceVersion != null) {
      options.add("-source");
      options.add(sourceVersion);
    }
    if (!showWarnings) {
      options.add("-nowarn");
    }

    // Bug fix: if "-target" is not present, Iterables in for-each loops cause compiler errors
    if (sourceVersion != null) {
      options.add("-target");
      options.add(sourceVersion);
    }
    /* The following line is commented out because it does not work for Java 8. */
    //    else { options.add("-target"); options.add("1.7"); }

    return options;
  }