@Override
 public void handleEvent(CProjectDescriptionEvent event) {
   // we are only interested in about to apply
   if (event.getEventType() != CProjectDescriptionEvent.ABOUT_TO_APPLY) return;
   ICProjectDescription projDesc = event.getNewCProjectDescription();
   IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
   IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
   if (projDesc.getActiveConfiguration() != null) {
     IEnvironmentVariable var =
         contribEnv.getVariable(
             ArduinoConst.ENV_KEY_JANTJE_PLATFORM_FILE, projDesc.getActiveConfiguration());
     if (var != null) {
       IPath platformPath = new Path(var.getValue());
       ArduinoHelpers.setProjectPathVariables(
           projDesc.getProject(), platformPath.removeLastSegments(1));
       ArduinoHelpers.setTheEnvironmentVariables(
           projDesc.getProject(), projDesc.getActiveConfiguration(), false);
       try {
         ArduinoHelpers.addArduinoCodeToProject(
             projDesc.getProject(), projDesc.getActiveConfiguration());
       } catch (CoreException e1) {
         Common.log(
             new Status(
                 IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Error adding the arduino code", e1));
       }
       ArduinoLibraries.reAttachLibrariesToProject(projDesc.getActiveConfiguration());
     }
   }
 }
    @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;
    }
예제 #3
0
  /**
   * Gets the CDT environment from the CDT project's configuration referenced by the launch
   *
   * @since 3.0
   */
  public static String[] getLaunchEnvironment(ILaunchConfiguration config) throws CoreException {
    // Get the project
    String projectName =
        config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
    if (projectName == null) {
      return null;
    }
    projectName = projectName.trim();
    if (projectName.length() == 0) {
      return null;
    }
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (project == null || !project.isAccessible()) return null;

    ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project, false);

    // Not a CDT project?
    if (projDesc == null) return null;

    String buildConfigID =
        config.getAttribute(
            ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, ""); // $NON-NLS-1$
    ICConfigurationDescription cfg = null;
    if (buildConfigID.length() != 0) cfg = projDesc.getConfigurationById(buildConfigID);

    // if configuration is null fall-back to active
    if (cfg == null) cfg = projDesc.getActiveConfiguration();

    // Environment variables and inherited vars
    HashMap<String, String> envMap = new HashMap<String, String>();
    IEnvironmentVariable[] vars =
        CCorePlugin.getDefault().getBuildEnvironmentManager().getVariables(cfg, true);
    for (IEnvironmentVariable var : vars) envMap.put(var.getName(), var.getValue());

    // Add variables from build info
    ICdtVariable[] build_vars = CCorePlugin.getDefault().getCdtVariableManager().getVariables(cfg);
    for (ICdtVariable var : build_vars) {
      try {
        envMap.put(var.getName(), var.getStringValue());
      } catch (CdtVariableException e) {
        // Some Eclipse dynamic variables can't be resolved dynamically... we don't care.
      }
    }

    // Turn it into an envp format
    List<String> strings = new ArrayList<String>(envMap.size());
    for (Entry<String, String> entry : envMap.entrySet()) {
      StringBuffer buffer = new StringBuffer(entry.getKey());
      buffer.append('=').append(entry.getValue());
      strings.add(buffer.toString());
    }

    return strings.toArray(new String[strings.size()]);
  }
예제 #4
0
  /** Set the program name attributes on the working copy based on the ICElement */
  protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
    boolean renamed = false;

    if (!(cElement instanceof IBinary)) {
      cElement = cElement.getCProject();
    }

    if (cElement instanceof ICProject) {
      IProject project = cElement.getCProject().getProject();
      String name = project.getName();
      ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
      if (projDes != null) {
        String buildConfigName = projDes.getActiveConfiguration().getName();
        name = name + " " + buildConfigName; // $NON-NLS-1$
      }
      name = getLaunchConfigurationDialog().generateName(name);
      config.rename(name);
      renamed = true;
    }

    IBinary binary = null;
    if (cElement instanceof ICProject) {
      IBinary[] bins = getBinaryFiles((ICProject) cElement);
      if (bins != null && bins.length == 1) {
        binary = bins[0];
      }
    } else if (cElement instanceof IBinary) {
      binary = (IBinary) cElement;
    }

    if (binary != null) {
      String path;
      path = binary.getResource().getProjectRelativePath().toOSString();
      config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, path);
      if (!renamed) {
        String name = binary.getElementName();
        int index = name.lastIndexOf('.');
        if (index > 0) {
          name = name.substring(0, index);
        }
        name = getLaunchConfigurationDialog().generateName(name);
        config.rename(name);
        renamed = true;
      }
    }

    if (!renamed) {
      String name =
          getLaunchConfigurationDialog().generateName(cElement.getCProject().getElementName());
      config.rename(name);
    }
  }
예제 #5
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);
        }
      }
    }
  }
  /** @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;
  }
  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);
      }
    }
  }