Example #1
0
  public void storeMappings(IProject project, ProjectLanguageConfiguration config)
      throws CoreException {
    ICProjectDescription descriptor = getProjectDescription(project, true);
    ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, true);
    // clear all children and settings
    rootElement.clear();

    ICStorageElement projectMappings = rootElement.createChild(PROJECT_MAPPINGS);

    addProjectContentTypeMappings(config.getContentTypeMappings(), projectMappings);
    addFileMappings(config.getFileMappings(), projectMappings);
    CCorePlugin.getDefault().setProjectDescription(project, descriptor);
  }
  /**
   * Store the value of an option.
   *
   * @param id a string uniquely identifying the option
   * @param value a string to be assigned as option value; if null, the empty string is assigned
   */
  public void setOption(String id, String value) {

    assert (id != null);
    assert (fStorage != null);

    ICStorageElement option = null;
    for (ICStorageElement child : fStorage.getChildrenByName("option")) {

      if (id.equals(child.getAttribute("id"))) {
        if (option == null) {
          // Remember first occurrence
          option = child;
        } else {
          // remove possible duplicates
          fStorage.removeChild(child);
        }
      }
    }

    if (option == null) {
      option = fStorage.createChild("option");
      option.setAttribute("id", id);
    }
    if (value == null) {
      value = "";
    } else {
      value = value.trim();
    }
    option.setAttribute("value", value);
  }
  /**
   * Retrieve the value of an option.
   *
   * @param id a string uniquely identifying the option
   * @return its value or null, if not found
   */
  public String getOption(String id) {

    assert (id != null);
    assert (fStorage != null);

    for (ICStorageElement child : fStorage.getChildrenByName("option")) {

      if (child.hasAttribute("id") && id.equals(child.getAttribute("id"))) {
        return child.getAttribute("value");
      }
    }

    return null;
  }
Example #4
0
  private void addFileMappings(
      Map<String, Map<String, String>> mappings, ICStorageElement rootElement) {
    for (Map.Entry<String, Map<String, String>> entry : mappings.entrySet()) {
      ICStorageElement mapping = rootElement.createChild(FILE_MAPPING);
      String path = entry.getKey();
      for (Entry<String, String> configurationEntry : entry.getValue().entrySet()) {
        String configuration = configurationEntry.getKey();
        String language = configurationEntry.getValue();

        mapping.setAttribute(ATTRIBUTE_PATH, path);
        mapping.setAttribute(ATTRIBUTE_CONFIGURATION, configuration);
        mapping.setAttribute(ATTRIBUTE_LANGUAGE, language);
      }
    }
  }
  /**
   * Retrieve a map with all properties.
   *
   * @return a map of strings.
   */
  public Map<String, String> getOptions() {

    assert (fStorage != null);

    Map<String, String> map = new HashMap<String, String>();

    for (ICStorageElement child : fStorage.getChildrenByName("option")) {

      if (child.hasAttribute("id")) {
        map.put(child.getAttribute("id"), child.getAttribute("value"));
      }
    }

    return map;
  }
Example #6
0
 public ProjectLanguageConfiguration decodeMappings(IProject project) throws CoreException {
   ProjectLanguageConfiguration config = new ProjectLanguageConfiguration();
   ICProjectDescription descriptor = getProjectDescription(project, false);
   if (descriptor != null) {
     ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, false);
     if (rootElement != null) {
       ICStorageElement[] mappingElements = rootElement.getChildrenByName(PROJECT_MAPPINGS);
       if (mappingElements.length > 0) {
         ICStorageElement element = mappingElements[0];
         config.setContentTypeMappings(decodeProjectContentTypeMappings(element));
         config.setFileMappings(decodeFileMappings(element));
       }
     }
   }
   return config;
 }
Example #7
0
  private Map<String, Map<String, String>> decodeProjectContentTypeMappings(
      ICStorageElement rootElement) {
    Map<String, Map<String, String>> decodedMappings = new TreeMap<String, Map<String, String>>();
    ICStorageElement[] mappingElements = rootElement.getChildrenByName(CONTENT_TYPE_MAPPING);
    for (int j = 0; j < mappingElements.length; j++) {
      ICStorageElement mapping = mappingElements[j];
      String configuration = mapping.getAttribute(ATTRIBUTE_CONFIGURATION);

      Map<String, String> contentTypeMappings = decodedMappings.get(configuration);
      if (contentTypeMappings == null) {
        contentTypeMappings = new TreeMap<String, String>();
        decodedMappings.put(configuration, contentTypeMappings);
      }
      String contentType = mapping.getAttribute(ATTRIBUTE_CONTENT_TYPE);
      String language = mapping.getAttribute(ATTRIBUTE_LANGUAGE);
      contentTypeMappings.put(contentType, language);
    }
    return decodedMappings;
  }
Example #8
0
  private Map<String, Map<String, String>> decodeFileMappings(ICStorageElement rootElement)
      throws CoreException {
    Map<String, Map<String, String>> decodedMappings = new TreeMap<String, Map<String, String>>();
    ICStorageElement[] mappingElements = rootElement.getChildrenByName(FILE_MAPPING);
    for (int j = 0; j < mappingElements.length; j++) {
      ICStorageElement mapping = mappingElements[j];
      String path = mapping.getAttribute(ATTRIBUTE_PATH);

      Map<String, String> configurationMappings = decodedMappings.get(path);
      if (configurationMappings == null) {
        configurationMappings = new TreeMap<String, String>();
        decodedMappings.put(path, configurationMappings);
      }
      String configuration = mapping.getAttribute(ATTRIBUTE_CONFIGURATION);
      String language = mapping.getAttribute(ATTRIBUTE_LANGUAGE);
      configurationMappings.put(configuration, language);
    }
    return decodedMappings;
  }
Example #9
0
  private void addProjectContentTypeMappings(
      Map<String, Map<String, String>> contentTypeMappings, ICStorageElement rootElement) {
    Iterator<Entry<String, Map<String, String>>> entries =
        contentTypeMappings.entrySet().iterator();
    while (entries.hasNext()) {
      Entry<String, Map<String, String>> entry = entries.next();

      String configuration = entry.getKey();
      Iterator<Entry<String, String>> contentTypeEntries = entry.getValue().entrySet().iterator();
      while (contentTypeEntries.hasNext()) {
        Entry<String, String> configurationEntry = contentTypeEntries.next();
        String contentType = configurationEntry.getKey();
        String language = configurationEntry.getValue();

        ICStorageElement mapping = rootElement.createChild(CONTENT_TYPE_MAPPING);
        mapping.setAttribute(ATTRIBUTE_CONTENT_TYPE, contentType);
        mapping.setAttribute(ATTRIBUTE_CONFIGURATION, configuration);
        mapping.setAttribute(ATTRIBUTE_LANGUAGE, language);
      }
    }
  }
Example #10
0
  /** Persist the resource configuration to the project file. */
  @Override
  public void serialize(ICStorageElement element) {
    super.serialize(element);
    if (toolsToInvoke != null) {
      element.setAttribute(IResourceConfiguration.TOOLS_TO_INVOKE, toolsToInvoke);
    }

    if (rcbsApplicability != null) {
      String str;
      switch (getRcbsApplicability()) {
        case KIND_APPLY_RCBS_TOOL_BEFORE:
          str = APPLY_RCBS_TOOL_BEFORE;
          break;
        case KIND_APPLY_RCBS_TOOL_AFTER:
          str = APPLY_RCBS_TOOL_AFTER;
          break;
        case KIND_APPLY_RCBS_TOOL_AS_OVERRIDE:
          str = APPLY_RCBS_TOOL_AS_OVERRIDE;
          break;
        case KIND_DISABLE_RCBS_TOOL:
          str = DISABLE_RCBS_TOOL;
          break;
        default:
          str = DISABLE_RCBS_TOOL;
          break;
      }
      element.setAttribute(IResourceConfiguration.RCBS_APPLICABILITY, str);
    }

    // Serialize my children
    List<ITool> toolElements = getToolList();
    for (ITool tool : toolElements) {
      ICStorageElement toolElement = element.createChild(ITool.TOOL_ELEMENT_NAME);
      ((Tool) tool).serialize(toolElement);
    }

    // I am clean now
    setDirty(false);
  }
Example #11
0
  /* (non-Javadoc)
   * Initialize the resource configuration information from the XML element
   * specified in the argument
   *
   * @param element An XML element containing the resource configuration information
   */
  protected void loadFromProject(ICStorageElement element) {
    // toolsToInvoke
    if (element.getAttribute(IResourceConfiguration.TOOLS_TO_INVOKE) != null) {
      toolsToInvoke =
          SafeStringInterner.safeIntern(
              element.getAttribute(IResourceConfiguration.TOOLS_TO_INVOKE));
    }

    // rcbsApplicability
    if (element.getAttribute(IResourceConfiguration.RCBS_APPLICABILITY) != null) {
      String rcbsApplicabilityStr = element.getAttribute(IResourceConfiguration.RCBS_APPLICABILITY);
      if (rcbsApplicabilityStr == null || rcbsApplicabilityStr.equals(DISABLE_RCBS_TOOL)) {
        rcbsApplicability = new Integer(KIND_DISABLE_RCBS_TOOL);
      } else if (rcbsApplicabilityStr.equals(APPLY_RCBS_TOOL_BEFORE)) {
        rcbsApplicability = new Integer(KIND_APPLY_RCBS_TOOL_BEFORE);
      } else if (rcbsApplicabilityStr.equals(APPLY_RCBS_TOOL_AFTER)) {
        rcbsApplicability = new Integer(KIND_APPLY_RCBS_TOOL_AFTER);
      } else if (rcbsApplicabilityStr.equals(APPLY_RCBS_TOOL_AS_OVERRIDE)) {
        rcbsApplicability = new Integer(KIND_APPLY_RCBS_TOOL_AS_OVERRIDE);
      }
    }
  }
Example #12
0
  /**
   * Create a <code>ResourceConfiguration</code> based on the specification stored in the project
   * file (.cdtbuild).
   *
   * @param parent The <code>IConfiguration</code> the resource configuration will be added to.
   * @param element The XML element that contains the resource configuration settings.
   */
  public ResourceConfiguration(
      IConfiguration parent, ICStorageElement element, String managedBuildRevision) {
    super(parent, element, true);
    isExtensionResourceConfig = false;
    setResourceData(new BuildFileData(this));

    setManagedBuildRevision(managedBuildRevision);
    // Initialize from the XML attributes
    loadFromProject(element);

    // Load children
    ICStorageElement configElements[] = element.getChildren();
    for (int i = 0; i < configElements.length; ++i) {
      ICStorageElement configElement = configElements[i];
      if (configElement.getName().equals(ITool.TOOL_ELEMENT_NAME)) {
        Tool tool = new Tool(this, configElement, getManagedBuildRevision());
        addTool(tool);
      }
    }

    String rebuild = PropertyManager.getInstance().getProperty(this, REBUILD_STATE);
    if (rebuild == null || Boolean.valueOf(rebuild).booleanValue()) setRebuildState(true);
    setDirty(false);
  }
  /**
   * Store the description of a memory section.
   *
   * @param section a string with the section name, using the CMSIS convention (like IRAM1, IROM1)
   * @param start a string with the hex value of the start address
   * @param size a string with the hex value of the size, in bytes
   * @param startup a string with 1 if the section will be used for startup (to host the vectors
   *     table)
   */
  public void setMemory(String section, String start, String size, String startup) {

    ICStorageElement memory = null;
    for (ICStorageElement child : fStorage.getChildrenByName("memory")) {

      if (section.equals(child.getAttribute("section"))) {
        if (memory == null) {
          // Remember first occurrence
          memory = child;
        } else {
          // remove possible duplicates
          fStorage.removeChild(child);
        }
      }
    }

    if (memory == null) {
      memory = fStorage.createChild("memory");
      memory.setAttribute("section", section);
    }
    memory.setAttribute("start", start);
    memory.setAttribute("size", size);
    memory.setAttribute("startup", startup);
  }
  public Map<String, String[]> getMemoryMap() {

    Map<String, String[]> map = new TreeMap<String, String[]>();

    for (ICStorageElement child : fStorage.getChildrenByName("memory")) {

      String section = child.getAttribute("section");
      String arr[] =
          new String[] {
            section,
            child.getAttribute("start"),
            child.getAttribute("size"),
            child.getAttribute("startup")
          };
      map.put(section, arr);
    }

    return map;
  }
 /** Clear all definitions inside this storage. */
 public void clear() {
   fStorage.clear();
 }