Ejemplo n.º 1
0
  @Override
  public ICResourceDescription getResDesc(ICConfigurationDescription cf) {
    IAdaptable ad = getElement();

    if (isForProject()) return cf.getRootFolderDescription();
    ICResourceDescription out = null;
    IResource res = (IResource) ad;
    IPath p = res.getProjectRelativePath();
    if (isForFolder() || isForFile()) {
      if (cf instanceof ICMultiItemsHolder) {
        out = cf.getResourceDescription(p, isForFolder()); // sic !
      } else {
        out = cf.getResourceDescription(p, false);
        if (!p.equals(out.getPath())) {
          try {
            if (isForFolder()) out = cf.createFolderDescription(p, (ICFolderDescription) out);
            else out = cf.createFileDescription(p, out);
          } catch (CoreException e) {
            System.out.println(
                Messages.AbstractPage_10
                    + p.toOSString()
                    + "\n"
                    + e.getLocalizedMessage()); // $NON-NLS-1$
          }
        }
      }
    }
    return out;
  }
    @Override
    public CExternalSetting[] getExternalSettings() {
      IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(fProjName);
      if (project.isAccessible()) {
        ICProjectDescription des =
            CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
        if (des != null) {
          ICConfigurationDescription cfg =
              fCfgId.length() != 0
                  ? des.getConfigurationById(fCfgId)
                  : des.getActiveConfiguration();

          if (cfg != null) {
            CExternalSetting[] es;
            ICExternalSetting[] ies = cfg.getExternalSettings();
            if (ies instanceof CExternalSetting[]) es = (CExternalSetting[]) ies;
            else {
              es = new CExternalSetting[ies.length];
              System.arraycopy(ies, 0, es, 0, es.length);
            }
            // Update the cache with the real settings this configuration is exporting
            cachedSettings.put(fId, es);
            return es;
          }
        }
      }
      // If project not yet accessible, just return the previous settings
      // for the moment. We'll update again when the referenced project reappears
      if (!cachedSettings.containsKey(fId) && prevSettings.length > 0)
        cachedSettings.putIfAbsent(fId, prevSettings);
      if (prevSettings.length == 0 && cachedSettings.containsKey(fId))
        return cachedSettings.get(fId);
      return prevSettings;
    }
 /**
  * Clone a configuration and put it on the tmp list if it is not already a saved configuration and
  * not already on the tmp list.
  *
  * @param p project
  * @param oldId the id of the old configuration to clone
  * @param cfgd the configuration descriptor for the clone
  * @return true if the configuration is already saved, false otherwise
  */
 public synchronized boolean cloneCfg(IProject p, String oldId, ICConfigurationDescription cfgd) {
   if (isConfigurationAlreadySaved(p, cfgd)) return true;
   Map<String, IAConfiguration> tmpList = getTmpConfigs(p);
   String newId = cfgd.getId();
   // Don't bother if the new configuration is already on the tmp list
   IAConfiguration cfg = tmpList.get(newId);
   if (cfg != null) return false;
   // Otherwise, try and find the old id to copy the configuration from
   // or punt if not found
   IAConfiguration oldCfg = null;
   Map<String, IAConfiguration> savedList = getSavedConfigs(p);
   if (savedList != null) oldCfg = savedList.get(oldId);
   if (oldCfg != null) {
     IAConfiguration newCfg = oldCfg.copy(cfgd.getId());
     tmpList.put(cfgd.getId(), newCfg);
     // Check to see if the new configuration is already stored as part of the project description.
     // If yes, it should already be saved.  This can occur if the configuration was added as part
     // of
     // another CDT Property page and the Autotools Property page was never opened.
     if (CoreModel.getDefault().getProjectDescription(p).getConfigurationById(newId) != null) {
       addConfiguration(p, newCfg);
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 4
0
 @Override
 public ICConfigurationDescription getConfigurationByName(String name) {
   for (Iterator<ICConfigurationDescription> iter = fCfgMap.values().iterator();
       iter.hasNext(); ) {
     ICConfigurationDescription cfg = iter.next();
     if (name.equals(cfg.getName())) return cfg;
   }
   return null;
 }
Ejemplo n.º 5
0
  /** @see IncrementalProjectBuilder#build */
  @Override
  protected IProject[] build(
      int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor)
      throws CoreException {
    if (DEBUG_EVENTS) {
      @SuppressWarnings("unchecked")
      Map<String, String> argsMap = args;
      printEvent(kind, argsMap);
    }

    // If auto discovery is disabled, do nothing
    //		boolean autodiscoveryEnabled;
    //		boolean autodiscoveryEnabled2;
    //		IScannerConfigBuilderInfo2 buildInfo2 = null;
    //		IConfiguration cfg = ScannerConfigUtil.getActiveConfiguration(getProject());
    IManagedBuildInfo bInfo = ManagedBuildManager.getBuildInfo(getProject());
    if (bInfo != null) {
      IConfiguration cfgs[] = bInfo.getManagedProject().getConfigurations();
      if (cfgs.length != 0) {
        if (!needAllConfigBuild()) {
          ICProjectDescription des =
              CoreModel.getDefault().getProjectDescription(getProject(), false);
          IConfiguration cfg = null;
          if (des != null) {
            ICConfigurationDescription settingCfgDes = des.getDefaultSettingConfiguration();
            if (settingCfgDes != null) {
              for (int i = 0; i < cfgs.length; i++) {
                if (settingCfgDes.getId().equals(cfgs[i].getId())) {
                  cfg = cfgs[i];
                  break;
                }
              }
            }
          }
          if (cfg != null) {
            cfgs = new IConfiguration[] {cfg};
          } else {
            cfgs = new IConfiguration[0];
          }
        }
        int numWork = cfgs.length;
        if (numWork > 0) {
          monitor.beginTask(
              MakeMessages.getString("ScannerConfigBuilder.Invoking_Builder"),
              numWork); //$NON-NLS-1$
          for (int i = 0; i < cfgs.length; i++) {
            build(cfgs[i], 0, new SubProgressMonitor(monitor, 1));
          }
        }
      }

      CfgDiscoveredPathManager.getInstance().updateCoreSettings(getProject(), cfgs);
    }

    return getProject().getReferencedProjects();
  }
Ejemplo n.º 6
0
    public void configurationRemoved(ICConfigurationDescription cfg) {
      if (cfg.getProjectDescription() != CProjectDescription.this)
        throw new IllegalArgumentException();

      if (!cfg.getId().equals(getId())) return;

      fIsCfgModified = true;
      fCfg = null;
      getConfiguration();
    }
 public synchronized IAConfiguration getTmpConfiguration(
     IProject p, ICConfigurationDescription cfgd) {
   Map<String, IAConfiguration> list = getTmpConfigs(p);
   IAConfiguration acfg = list.get(cfgd.getId());
   if (acfg != null) {
     return acfg;
   }
   IAConfiguration oldCfg = getConfiguration(p, cfgd.getId(), false);
   list.put(cfgd.getId(), oldCfg);
   return oldCfg;
 }
Ejemplo n.º 8
0
    public void setConfiguration(ICConfigurationDescription cfg) {
      if (cfg.getProjectDescription() != CProjectDescription.this)
        throw new IllegalArgumentException();

      if (cfg.getId().equals(getId())) return;

      fCfg = cfg;
      fId = cfg.getId();
      fIsCfgModified = true;
      fNeedsPersistance = true;
    }
Ejemplo n.º 9
0
  /**
   * Create a new custom storage for packs related config options. The new storage is specific for
   * each build configuration, so it is created inside the "cconfiguration" element.
   *
   * @param config a Configuration object (like Debug/Release).
   * @throws CoreException
   */
  public CProjectPacksStorage(IConfiguration config) throws CoreException {

    if (config instanceof Configuration) {
      fConfig = (Configuration) config;
      ICConfigurationDescription configDesc = fConfig.getConfigurationDescription();
      fStorage = configDesc.getStorage(STORAGE_NAME, true);
    } else {
      throw new CoreException(
          new Status(Status.ERROR, Activator.PLUGIN_ID, "ConfigStorage() requires Configuration"));
    }
  }
Ejemplo n.º 10
0
  /** Get source entries for default setting configuration (i.e. configuration shown in UI). */
  private static ICSourceEntry[] getSourceEntries(IProject project) {
    ICProjectDescriptionManager mgr = CCorePlugin.getDefault().getProjectDescriptionManager();
    ICProjectDescription prjDescription = mgr.getProjectDescription(project, false);
    if (prjDescription != null) {
      ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
      if (cfgDescription != null) {
        ICSourceEntry[] srcEntries = cfgDescription.getResolvedSourceEntries();
        return srcEntries;
      }
    }

    return new ICSourceEntry[0];
  }
Ejemplo n.º 11
0
  boolean needsDescriptionPersistence() {
    if (fIsModified) return true;

    if (fPrefs.isModified()) return true;

    if (fStorage.isModified()) return true;

    for (ICConfigurationDescription cfgDes : fCfgMap.values()) {
      if (cfgDes.isModified()) return true;
    }

    return false;
  }
Ejemplo n.º 12
0
 @Override
 protected void performOK() {
   ICConfigurationDescription[] cfgs = page.getCfgsEditable();
   AutotoolsConfigurePropertyPage ap = (AutotoolsConfigurePropertyPage) page;
   Map<String, IAConfiguration> cfgList = new HashMap<>();
   for (int i = 0; i < cfgs.length; ++i) {
     ICConfigurationDescription cd = cfgs[i];
     IAConfiguration acfg = ap.getConfiguration(cd);
     cfgList.put(cd.getId(), acfg);
   }
   IProject project = page.getProject();
   AutotoolsConfigurationManager.getInstance()
       .replaceProjectConfigurations(project, cfgList, cfgs);
   AutotoolsConfigurationManager.getInstance().clearTmpConfigurations(project);
 }
Ejemplo n.º 13
0
  protected void cfgChanged(ICConfigurationDescription _cfgd) {

    CConfigurationStatus st = _cfgd.getConfigurationStatus();
    if (errPane != null && errMessage != null) {
      if (st.isOK()) {
        errPane.setVisible(false);
      } else {
        errMessage.setText(st.getMessage());
        errPane.setVisible(true);
      }
    }

    resd = getResDesc(_cfgd);

    if (excludeFromBuildCheck != null) {
      excludeFromBuildCheck.setEnabled(resd.canExclude(!resd.isExcluded()));
      excludeFromBuildCheck.setSelection(resd.isExcluded());
    }
    int x = CDTPropertyManager.getPagesCount();
    for (int i = 0; i < x; i++) {
      Object p = CDTPropertyManager.getPage(i);
      if (p == null || !(p instanceof AbstractPage)) continue;
      AbstractPage ap = (AbstractPage) p;
      if (ap.displayedConfig) ap.forEach(ICPropertyTab.UPDATE, getResDesc());
    }
  }
  /**
   * Notify the ExternalSettingManager that there's been a change in the configuration which may
   * require referencing configs to update their cache of the external settings
   */
  public void handleEvent(CProjectDescriptionEvent event) {
    switch (event.getEventType()) {
      case CProjectDescriptionEvent.LOADED:
        {
          // Bug 312575 on Project load, event.getProjectDelta() == null => report all configs as
          // potentially changed
          // Referencing projects should be reconciled and potentially updated.
          String projName = event.getProject().getName();
          ICConfigurationDescription[] descs =
              event.getNewCProjectDescription().getConfigurations();
          CExternalSettingsContainerChangeInfo[] changeInfos =
              new CExternalSettingsContainerChangeInfo[descs.length + 1];
          int i = 0;
          for (ICConfigurationDescription desc :
              event.getNewCProjectDescription().getConfigurations())
            changeInfos[i++] =
                new CExternalSettingsContainerChangeInfo(
                    CExternalSettingsContainerChangeInfo.CONTAINER_CONTENTS,
                    new CContainerRef(FACTORY_ID, createId(projName, desc.getId())),
                    null);
          // Active configuration too
          changeInfos[i] =
              new CExternalSettingsContainerChangeInfo(
                  CExternalSettingsContainerChangeInfo.CONTAINER_CONTENTS,
                  new CContainerRef(FACTORY_ID, createId(projName, ACTIVE_CONFIG_ID)),
                  null);
          notifySettingsChange(null, null, changeInfos);
          break;
        }
      case CProjectDescriptionEvent.APPLIED:
        String[] ids = getContainerIds(event.getProjectDelta());
        if (ids.length != 0) {
          CExternalSettingsContainerChangeInfo[] changeInfos =
              new CExternalSettingsContainerChangeInfo[ids.length];

          for (int i = 0; i < changeInfos.length; i++) {
            changeInfos[i] =
                new CExternalSettingsContainerChangeInfo(
                    CExternalSettingsContainerChangeInfo.CONTAINER_CONTENTS,
                    new CContainerRef(FACTORY_ID, ids[i]),
                    null);
          }
          notifySettingsChange(null, null, changeInfos);
        }
    }
  }
Ejemplo n.º 15
0
  /**
   * Check if all configuration descriptions are present in the internal array of configuration
   * descriptions.
   *
   * @param cfgs
   * @return true if all present, false otherwise
   */
  private static boolean areCfgsStillThere(ICConfigurationDescription[] cfgs) {
    if (cfgs == null || cfgDescs == null) return false;

    for (ICConfigurationDescription multiCfg : cfgs) {
      boolean foundOne = false;
      for (ICConfigurationDescription cfgDesc : cfgDescs) {
        if (multiCfg.getId().equals(cfgDesc.getId())) {
          foundOne = true;
          break;
        }
      }
      if (!foundOne) {
        return false;
      }
    }
    return true;
  }
Ejemplo n.º 16
0
  @Override
  public IStatus build(IProgressMonitor monitor) {
    IStatus result = Status.OK_STATUS;

    ICConfigurationDescription config = resolveSelectedConfiguration();

    if (config == null) {
      result =
          new Status(
              IStatus.WARNING,
              CUIPlugin.PLUGIN_ID,
              NLS.bind(WorkingSetMessages.WSProjConfig_noConfig, getProjectName()));
    } else {
      if (!isActive()) {
        activate();
        result =
            new Status(
                IStatus.WARNING,
                CUIPlugin.PLUGIN_ID,
                NLS.bind(
                    WorkingSetMessages.WSProjConfig_activatedWarning,
                    config.getName(),
                    getProjectName()));
      }

      monitor = SubMonitor.convert(monitor);

      try {
        resolveProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
      } catch (CoreException e) {
        if (result.isOK()) {
          result = e.getStatus();
        } else {
          result =
              new MultiStatus(
                  CUIPlugin.PLUGIN_ID,
                  0,
                  new IStatus[] {result, e.getStatus()},
                  NLS.bind(WorkingSetMessages.WSProjConfig_buildProblem, getProjectName()),
                  null);
        }
      }
    }

    return result;
  }
Ejemplo n.º 17
0
  @Override
  public void activate() {
    ICConfigurationDescription config = resolveSelectedConfiguration();

    if (config != null) {
      ICProjectDescription desc = config.getProjectDescription();

      if (desc.getActiveConfiguration() != config) {
        try {
          IProject project = desc.getProject();
          desc.setActiveConfiguration(config);
          CoreModel.getDefault().setProjectDescription(project, desc);
        } catch (CoreException e) {
          CUIPlugin.log(e);
        }
      }
    }
  }
  private void doOK() {
    ICConfigurationDescription confdesc = getConfdesc();
    if (confdesc != null) {
      saveAllSelections(confdesc);
      IProject project = confdesc.getProjectDescription().getProject();

      Helpers.setTheEnvironmentVariables(project, confdesc, false);

      try {
        Helpers.addArduinoCodeToProject(project, confdesc);
      } catch (CoreException e1) {
        Common.log(
            new Status(
                IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.error_adding_arduino_code, e1));
      }
      Helpers.removeInvalidIncludeFolders(confdesc);
      Helpers.setDirtyFlag(project, confdesc);
    }
  }
  /** @deprecated Not intended to be public - do not use */
  @Deprecated
  public String getDefaultDebugger(final ILaunchConfiguration config) throws CoreException {
    // Mostly from CDebbuggerTab
    String defaultDebugger = null;

    String projectName =
        config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
    if (projectName.length() > 0) {
      IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
      ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project);
      if (projDesc != null) {
        ICConfigurationDescription configDesc = projDesc.getActiveConfiguration();
        String configId = configDesc.getId();
        ICDebugConfiguration[] debugConfigs =
            CDebugCorePlugin.getDefault().getActiveDebugConfigurations();
        outer:
        for (int i = 0; i < debugConfigs.length; ++i) {
          ICDebugConfiguration debugConfig = debugConfigs[i];
          String[] patterns = debugConfig.getSupportedBuildConfigPatterns();
          if (patterns != null) {
            for (int j = 0; j < patterns.length; ++j) {
              if (configId.matches(patterns[j])) {
                defaultDebugger = debugConfig.getID();
                break outer;
              }
            }
          }
        }
      }
    }

    if (defaultDebugger == null) {
      ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration();
      if (dc != null) {
        defaultDebugger = dc.getID();
      }
    }

    return defaultDebugger;
  }
  @Override
  public void handleEvent(ILanguageSettingsChangeEvent event) {
    IWorkspaceRoot wspRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = wspRoot.getProject(event.getProjectName());

    if (project != null) {
      ICProjectDescription prjDescription =
          CCorePlugin.getDefault().getProjectDescription(project, false);
      if (prjDescription != null) {
        // cfgDescription being indexed
        ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
        String indexedId = cfgDescription.getId();

        for (String id : event.getConfigurationDescriptionIds()) {
          if (id.equals(indexedId)) {
            reindex(id, event);
            return;
          }
        }
      }
    }
  }
  @Override
  protected ISerializeInfo getSerializeInfo(Object context) {
    ISerializeInfo serializeInfo = null;

    if (context instanceof ICConfigurationDescription) {
      final ICConfigurationDescription cfg = (ICConfigurationDescription) context;
      final String name = cfg.getId();
      if (name != null)
        serializeInfo =
            new ISerializeInfo() {
              @Override
              public Preferences getNode() {
                return getConfigurationNode(cfg.getProjectDescription());
              }

              @Override
              public String getPrefName() {
                return name;
              }
            };
    } else if (context == null || context instanceof IWorkspace) {
      final Preferences prefs = getWorkspaceNode();
      final String name = PREFNAME_WORKSPACE;
      if (prefs != null)
        serializeInfo =
            new ISerializeInfo() {
              @Override
              public Preferences getNode() {
                return prefs;
              }

              @Override
              public String getPrefName() {
                return name;
              }
            };
    }
    return serializeInfo;
  }
Ejemplo n.º 22
0
 /**
  * Find index of configuration description in the internal array of configuration descriptions.
  *
  * @param cfgd
  * @return index of found configuration description or index of active configuration.
  */
 private static int getCfgIndex(ICConfigurationDescription cfgd) {
   int index = 0;
   for (int i = 0; i < cfgDescs.length; ++i) {
     if (cfgd != null) {
       if (cfgd.getId().equals(cfgDescs[i].getId())) {
         return i;
       }
     } else if (cfgDescs[i].isActive()) {
       index = i;
     }
   }
   return index;
 }
Ejemplo n.º 23
0
 /**
  * Searches in the prj for the config description with the same ID as for given cfg. If there's no
  * such cfgd, it will be created.
  *
  * @param prj - project description where we'll search (or create) config description
  * @param cfg - config description belonging to another project description, it is a sample for
  *     search and base for possile creation of resulting configuration description.
  * @return the configuration description (found or created) or null in case of error
  */
 private ICConfigurationDescription findCfg(
     ICProjectDescription prj, ICConfigurationDescription cfg) {
   String id = cfg.getId();
   // find config with the same ID as original one
   ICConfigurationDescription c = prj.getConfigurationById(id);
   // if there's no cfg found, try to create it
   if (c == null) {
     try {
       c = prj.createConfiguration(id, cfg.getName(), cfg);
       c.setDescription(cfg.getDescription());
     } catch (CoreException e) {
       /* do nothing: c is already null */
     }
   }
   // if creation failed, report an error and return null
   if (c == null) {
     MessageBox mb = new MessageBox(getShell());
     mb.setMessage(Messages.AbstractPage_3);
     mb.open();
   }
   return c;
 }
  private void initLanguageSettings(IProject project) throws CoreException {
    ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);

    if (prjDesc == null) throw new IllegalArgumentException("No valid CDT project given!");

    ICConfigurationDescription activeConfig = prjDesc.getActiveConfiguration();

    if (activeConfig == null)
      throw new IllegalArgumentException("No valid active configuration found!");

    String[] extensionsToInclude = getExtensionsToInclude(project);
    ICFolderDescription folderDesc = activeConfig.getRootFolderDescription();

    for (ICLanguageSetting ls : folderDesc.getLanguageSettings()) {
      String[] extensions = ls.getSourceExtensions();
      Arrays.sort(extensions);

      if (Arrays.equals(extensionsToInclude, extensions)) {
        languageSettings.add(ls);
      }
    }
  }
Ejemplo n.º 25
0
  /*
   * Event Handlers
   */
  private void handleConfigSelection() {
    // If there is nothing in config selection widget just bail
    if (configSelector.getItemCount() == 0) return;
    int selectionIndex = configSelector.getSelectionIndex();
    if (selectionIndex == -1) return;
    if (cfgDescs == null || cfgDescs.length == 0) return;

    // Check if the user has selected the "all / multiple" configuration
    if (selectionIndex >= cfgDescs.length) {
      if (selectionIndex == cfgDescs.length) { // all
        multiCfgs = cfgDescs;
      } else { // multiple
        // Check previous state of variables figuring out if need to pop up selection dialog
        // areCfgsStillThere() covers deletions by a user in Manage Configurations dialog
        boolean enterMultiCfgsDialog =
            (multiCfgs == null) || (multiCfgs == cfgDescs) || !areCfgsStillThere(multiCfgs);
        if (enterMultiCfgsDialog) {
          ICConfigurationDescription[] mcfgs =
              ConfigMultiSelectionDialog.select(cfgDescs, parentComposite.getShell());
          if (mcfgs == null || mcfgs.length == 0) {
            // return back to previous selection
            int cfgIndex = -1;
            if (multiCfgs == cfgDescs) { // return to choice "All"
              cfgIndex = cfgDescs.length;
            } else {
              cfgIndex = getCfgIndex(lastSelectedCfg);
            }
            configSelector.select(cfgIndex);
            return;
          }
          multiCfgs = mcfgs;
        }
      }
      lastSelectedCfg = null;

      cfgChanged(MultiItemsHolder.createCDescription(multiCfgs));
      return;
    }
    multiCfgs = null;

    String id1 = getResDesc() == null ? null : getResDesc().getId();
    lastSelectedCfg = cfgDescs[selectionIndex];
    String id2 = lastSelectedCfg.getId();
    if (id2 != null && !id2.equals(id1)) {
      cfgChanged(lastSelectedCfg);
    }
  }
Ejemplo n.º 26
0
  private void setValues() {
    /*
     *  This method updates the context of the build property pages
     *   - Which configuration/resource configuration is selected
     *   - Which tool/option category is selected
     *
     *  It is called:
     *   - When a property page becomes visible
     *   - When the user changes the configuration selection
     *   - When the user changes the "exclude" setting for a resource
     */

    IConfiguration icfg = getCfg(icfgd.getConfiguration());
    if (icfg instanceof IMultiConfiguration) {
      fTree.setInput(null);
      fTree.getControl().setEnabled(false);
      currentSettingsPage.setVisible(false);
      return;
    }

    IAConfiguration currCfg = getAutotoolsCfg();

    //  Create the Tree Viewer content provider if first time
    if (listprovider == null) {
      listprovider = new ToolListContentProvider();
      fTree.setContentProvider(listprovider);
    }

    //  Update the selected configuration and the Tree Viewer
    ToolListElement[] newElements;

    fTree.setInput(currCfg);
    fTree.getControl().setEnabled(true);
    newElements = (ToolListElement[]) listprovider.getElements(currCfg);
    fTree.expandAll();

    selectedElement = newElements[0];
    fTree.setSelection(new StructuredSelection(selectedElement), true);
  }
 private void syncNameField(ICConfigurationDescription cfgd) {
   IConfiguration icfg = ManagedBuildManager.getConfigurationForDescription(cfgd);
   String id = cfgd.getId();
   if (icfg != null) {
     IToolChain toolchain = icfg.getToolChain();
     ITool[] tools = toolchain.getTools();
     for (int j = 0; j < tools.length; ++j) {
       ITool tool = tools[j];
       if (tool.getName().equals("configure")) { // $NON-NLS-1$
         IOption option =
             tool.getOptionBySuperClassId(
                 "org.eclipse.linuxtools.cdt.autotools.core.option.configure.name"); // $NON-NLS-1$
         IHoldsOptions h = tool;
         try {
           IOption optionToSet = h.getOptionToSet(option, false);
           optionToSet.setValue(id);
         } catch (BuildException e) {
         }
       }
     }
   }
 }
Ejemplo n.º 28
0
  @Override
  public boolean isActive() {
    ICConfigurationDescription desc = resolveSelectedConfiguration();

    return (desc != null) && desc.isActive();
  }
  // Perform apply of configuration changes.  This rewrites out the current known list of
  // configurations
  // with any changes currently that have been made to them.  If a configuration has been renamed,
  // but this
  // has not yet been confirmed by the end-user, then only the changes to the configuration are
  // made.  The
  // name currently remains the same in the output file.
  public synchronized void applyConfigs(String projectName, ICConfigurationDescription[] cfgds) {
    try {
      IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
      IResource res = root.findMember(projectName, false);
      if (res == null || res.getType() != IResource.PROJECT) {
        AutotoolsPlugin.logErrorMessage(
            ConfigureMessages.getFormattedString(CFG_CANT_SAVE, new String[] {projectName}));
        return;
      }
      IProject project = (IProject) res;
      IPath output = project.getLocation().append(CFG_FILE_NAME);
      File f = output.toFile();
      if (!f.exists()) f.createNewFile();
      if (f.exists()) {
        try (PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(f)))) {
          Map<String, IAConfiguration> cfgs = getSavedConfigs(project);
          if (cfgs == null) return;
          p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); // $NON-NLS-1$
          p.println("<configurations>"); // $NON-NLS-1$
          Option[] optionList = AutotoolsConfiguration.getOptionList();
          HashSet<String> savedIds = new HashSet<>();
          setSyncing(true);
          for (int x = 0; x < cfgds.length; ++x) {
            ICConfigurationDescription cfgd = cfgds[x];
            @SuppressWarnings("unused")
            CConfigurationData data = cfgd.getConfigurationData();
            String id = cfgd.getId();
            savedIds.add(id);
            IAConfiguration cfg = getTmpConfiguration(project, cfgd);
            cfgs.put(
                id,
                cfg); // add to list in case we have a new configuration not yet added to Project
                      // Description
            p.println("<configuration id=\"" + id + "\">"); // $NON-NLS-1$ //$NON-NLS-2$
            for (int j = 0; j < optionList.length; ++j) {
              Option option = optionList[j];
              IConfigureOption opt = cfg.getOption(option.getName());
              if (!opt.isCategory())
                p.println(
                    "<option id=\""
                        + option.getName()
                        + "\" value=\""
                        + opt.getValue()
                        + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ // $NON-NLS-3$
            }
            p.println("</configuration>"); // $NON-NLS-1$
            syncNameField(cfgd);
          }
          setSyncing(false);

          // Put all the remaining configurations already saved back into the file.
          // These represent deleted configurations, but confirmation has not occurred.
          for (Entry<String, IAConfiguration> i : cfgs.entrySet()) {
            String id = i.getKey();
            // A remaining id won't appear in our savedIds list.
            if (!savedIds.contains(id)) {
              IAConfiguration cfg = i.getValue();
              p.println("<configuration id=\"" + id + "\">"); // $NON-NLS-1$ //$NON-NLS-2$
              for (int j = 0; j < optionList.length; ++j) {
                Option option = optionList[j];
                IConfigureOption opt = cfg.getOption(option.getName());
                if (!opt.isCategory())
                  p.println(
                      "<option id=\""
                          + option.getName()
                          + "\" value=\""
                          + opt.getValue()
                          + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ // $NON-NLS-3$
              }
              p.println("</configuration>"); // $NON-NLS-1$
            }
          }
          p.println("</configurations>");
        }
      }
    } catch (IOException e) {
      AutotoolsPlugin.log(e);
    }
  }
 private void saveConfigs(IProject project, ICConfigurationDescription[] cfgds) {
   try {
     String projectName = project.getName();
     IPath output = project.getLocation().append(CFG_FILE_NAME);
     File f = output.toFile();
     if (!f.exists()) f.createNewFile();
     if (f.exists()) {
       try (PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(f)))) {
         Map<String, IAConfiguration> cfgs = configs.get(projectName);
         p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); // $NON-NLS-1$
         p.println("<configurations>"); // $NON-NLS-1$
         Option[] optionList = AutotoolsConfiguration.getOptionList();
         // Before saving, force any cloning to occur via the option
         // value handler.
         setSyncing(true);
         for (int i = 0; i < cfgds.length; ++i) {
           @SuppressWarnings("unused")
           CConfigurationData data = cfgds[i].getConfigurationData();
         }
         setSyncing(false);
         for (int i = 0; i < cfgds.length; ++i) {
           ICConfigurationDescription cfgd = cfgds[i];
           String id = cfgd.getId();
           IAConfiguration cfg = cfgs.get(id);
           if (cfg == null) {
             cfg = createDefaultConfiguration(id);
           }
           p.println("<configuration id=\"" + cfg.getId() + "\">"); // $NON-NLS-1$ //$NON-NLS-2$
           for (int j = 0; j < optionList.length; ++j) {
             Option option = optionList[j];
             IConfigureOption opt = cfg.getOption(option.getName());
             if (opt.isFlag()) {
               p.println(
                   "<flag id=\""
                       + option.getName()
                       + "\" value=\"" //$NON-NLS-1$ //$NON-NLS-2$
                       + xmlEscape(option.getDefaultValue())
                       + "\">"); //$NON-NLS-1$
               FlagConfigureOption fco = (FlagConfigureOption) opt;
               List<String> children = fco.getChildren();
               for (int k = 0; k < children.size(); ++k) {
                 String childName = children.get(k);
                 IConfigureOption childopt = cfg.getOption(childName);
                 p.println(
                     "<flagvalue id=\""
                         + childopt.getName()
                         + "\" value=\"" //$NON-NLS-1$ //$NON-NLS-2$
                         + xmlEscape(childopt.getValue())
                         + "\"/>"); // $NON-NLS-3$
               }
               p.println("</flag>"); // $NON-NLS-1$
             } else if (!opt.isCategory() && !opt.isFlagValue())
               p.println(
                   "<option id=\""
                       + option.getName()
                       + "\" value=\""
                       + xmlEscape(opt.getValue()) // $NON-NLS-1$ //$NON-NLS-2$
                       + "\"/>"); // $NON-NLS-3$
           }
           p.println("</configuration>"); // $NON-NLS-1$
           // Sync name field as this configuration is now
           // officially saved
           syncNameField(cfgd);
         }
         p.println("</configurations>");
       }
     }
   } catch (IOException e) {
     AutotoolsPlugin.log(e);
   }
 }