@Override
 public Map<String, String> getOptions() {
   if (null == _processorOptions) {
     // Java 5 processor options include items on the command line such as -s,
     // -classpath, etc., but Java 6 options only include the options specified
     // with -A, which will have been parsed into key/value pairs with no dash.
     Map<String, String> allOptions = AptConfig.getProcessorOptions(_javaProject);
     Map<String, String> procOptions = new HashMap<String, String>();
     for (Map.Entry<String, String> entry : allOptions.entrySet()) {
       if (!entry.getKey().startsWith("-")) { // $NON-NLS-1$
         procOptions.put(entry.getKey(), entry.getValue());
       }
     }
     procOptions.put("phase", getPhase().toString()); // $NON-NLS-1$
     _processorOptions = Collections.unmodifiableMap(procOptions);
   }
   return _processorOptions;
 }
Ejemplo n.º 2
0
  /**
   * Set the _options map based on the current project/workspace settings. There is a bug in Sun's
   * apt implementation: it parses the command line incorrectly, such that -Akey=value gets added to
   * the options map as key "-Akey=value" and value "". In order to support processors written to
   * run on Sun's apt as well as processors written without this bug in mind, we populate the map
   * with two copies of every option, one the expected way ("key" / "value") and the other the Sun
   * way ("-Akey=value" / ""). We make exceptions for the non-dash-A options that we set
   * automatically, such as -classpath, -target, and so forth; since these wouldn't have come from a
   * -A option we don't construct a -Akey=value variant.
   *
   * <p>Called from constructor. A new Env is constructed for each build pass, so this will always
   * be up to date with the latest settings.
   */
  private Map<String, String> initOptions(IJavaProject jproj) {
    Map<String, String> procOptions = AptConfig.getProcessorOptions(jproj);
    // options is large enough to include the translated -A options
    Map<String, String> options = new HashMap<String, String>(procOptions.size() * 2);

    // Add configured options
    for (Map.Entry<String, String> entry : procOptions.entrySet()) {
      String value = entry.getValue();
      String key = entry.getKey();
      options.put(key, value);
      if (!AptConfig.isAutomaticProcessorOption(key)) {
        String sunStyle;
        if (value != null) {
          sunStyle = "-A" + entry.getKey() + "=" + value; // $NON-NLS-1$ //$NON-NLS-2$
        } else {
          sunStyle = "-A" + entry.getKey(); // $NON-NLS-1$
        }
        options.put(sunStyle, ""); // $NON-NLS-1$
      }
    }
    return Collections.unmodifiableMap(options);
  }