コード例 #1
0
 /**
  * Adds text to the task, using the wrapper
  *
  * @param buf A character array of the text within the element. Will not be <code>null</code>.
  * @param start The start element in the array.
  * @param count The number of characters to read from the array.
  * @param context The current context.
  * @exception SAXParseException if the element doesn't support text
  * @see ProjectHelper#addText(Project,java.lang.Object,char[],int,int)
  */
 public void characters(char[] buf, int start, int count, AntXMLContext context)
     throws SAXParseException {
   RuntimeConfigurable wrapper = context.currentWrapper();
   wrapper.addText(buf, start, count);
 }
コード例 #2
0
ファイル: Groovyc.java プロジェクト: endSly/groovy
  private List<String> extractJointOptions(Path classpath) {
    List<String> jointOptions = new ArrayList<String>();
    if (!jointCompilation) return jointOptions;

    // extract joint options, some get pushed up...
    RuntimeConfigurable rc = javac.getRuntimeConfigurableWrapper();
    for (Object o1 : rc.getAttributeMap().entrySet()) {
      final Map.Entry e = (Map.Entry) o1;
      final String key = e.getKey().toString();
      final String value = getProject().replaceProperties(e.getValue().toString());
      if (key.contains("debug")) {
        String level = "";
        if (javac.getDebugLevel() != null) {
          level = ":" + javac.getDebugLevel();
        }
        jointOptions.add("-Fg" + level);
      } else if (key.contains("debugLevel")) {
        // ignore, taken care of in debug
      } else if ((key.contains("nowarn"))
          || (key.contains("verbose"))
          || (key.contains("deprecation"))) {
        // false is default, so something to do only in true case
        if ("on".equalsIgnoreCase(value)
            || "true".equalsIgnoreCase(value)
            || "yes".equalsIgnoreCase(value)) jointOptions.add("-F" + key);
      } else if (key.contains("classpath")) {
        classpath.add(javac.getClasspath());
      } else if ((key.contains("depend"))
          || (key.contains("extdirs"))
          || (key.contains("encoding"))
          || (key.contains("source"))
          || (key.contains("target"))
          || (key.contains("verbose"))) { // already handling verbose but pass on too
        jointOptions.add("-J" + key + "=" + value);
      } else {
        log.warn(
            "The option "
                + key
                + " cannot be set on the contained <javac> element. The option will be ignored");
      }
      // TODO includes? excludes?
    }

    // ant's <javac> supports nested <compilerarg value=""> elements (there can be multiple of them)
    // for additional options to be passed to javac.
    Enumeration children = rc.getChildren();
    while (children.hasMoreElements()) {
      RuntimeConfigurable childrc = (RuntimeConfigurable) children.nextElement();
      if (childrc.getElementTag().equals("compilerarg")) {
        for (Object o : childrc.getAttributeMap().entrySet()) {
          final Map.Entry e = (Map.Entry) o;
          final String key = e.getKey().toString();
          if (key.equals("value")) {
            final String value = getProject().replaceProperties(e.getValue().toString());
            StringTokenizer st = new StringTokenizer(value, " ");
            while (st.hasMoreTokens()) {
              String optionStr = st.nextToken();
              String replaced = optionStr.replace("-X", "-FX");
              if (optionStr.equals(replaced)) {
                replaced = optionStr.replace("-W", "-FW"); // GROOVY-5063
              }
              jointOptions.add(replaced);
            }
          }
        }
      }
    }

    return jointOptions;
  }
コード例 #3
0
    /**
     * Initialisation routine called after handler creation with the element name and attributes.
     * This configures the element with its attributes and sets it up with its parent container (if
     * any). Nested elements are then added later as the parser encounters them.
     *
     * @param uri The namespace URI for this element.
     * @param tag Name of the element which caused this handler to be created. Must not be <code>
     *     null</code>.
     * @param qname The qualified name for this element.
     * @param attrs Attributes of the element which caused this handler to be created. Must not be
     *     <code>null</code>.
     * @param context The current context.
     * @exception SAXParseException in case of error (not thrown in this implementation)
     */
    public void onStartElement(
        String uri, String tag, String qname, Attributes attrs, AntXMLContext context)
        throws SAXParseException {
      RuntimeConfigurable parentWrapper = context.currentWrapper();
      Object parent = null;

      if (parentWrapper != null) {
        parent = parentWrapper.getProxy();
      }

      /* UnknownElement is used for tasks and data types - with
      delayed eval */
      UnknownElement task = new UnknownElement(tag);
      task.setProject(context.getProject());
      task.setNamespace(uri);
      task.setQName(qname);
      task.setTaskType(ProjectHelper.genComponentName(task.getNamespace(), tag));
      task.setTaskName(qname);

      Location location =
          new Location(
              context.getLocator().getSystemId(),
              context.getLocator().getLineNumber(),
              context.getLocator().getColumnNumber());
      task.setLocation(location);
      task.setOwningTarget(context.getCurrentTarget());

      if (parent != null) {
        // Nested element
        ((UnknownElement) parent).addChild(task);
      } else {
        // Task included in a target ( including the default one ).
        context.getCurrentTarget().addTask(task);
      }

      context.configureId(task, attrs);

      // container.addTask(task);
      // This is a nop in UE: task.init();

      RuntimeConfigurable wrapper = new RuntimeConfigurable(task, task.getTaskName());

      for (int i = 0; i < attrs.getLength(); i++) {
        String name = attrs.getLocalName(i);
        String attrUri = attrs.getURI(i);
        if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {
          name = attrUri + ":" + attrs.getQName(i);
        }
        String value = attrs.getValue(i);
        // PR: Hack for ant-type value
        //  an ant-type is a component name which can
        // be namespaced, need to extract the name
        // and convert from qualified name to uri/name
        if (ANT_TYPE.equals(name)
            || (ANT_CORE_URI.equals(attrUri) && ANT_TYPE.equals(attrs.getLocalName(i)))) {
          name = ANT_TYPE;
          int index = value.indexOf(":");
          if (index >= 0) {
            String prefix = value.substring(0, index);
            String mappedUri = context.getPrefixMapping(prefix);
            if (mappedUri == null) {
              throw new BuildException("Unable to find XML NS prefix \"" + prefix + "\"");
            }
            value = ProjectHelper.genComponentName(mappedUri, value.substring(index + 1));
          }
        }
        wrapper.setAttribute(name, value);
      }
      if (parentWrapper != null) {
        parentWrapper.addChild(wrapper);
      }
      context.pushWrapper(wrapper);
    }