Пример #1
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();
  }
Пример #2
0
  private IProjectType getProjectType() {
    IProjectType projectType = null;

    // Get the projectType from project.
    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(getProject());
    if (info != null) {
      IManagedProject managedProject = info.getManagedProject();
      if (managedProject != null) {
        projectType = managedProject.getProjectType();
      }
    }
    return projectType;
  }
Пример #3
0
  private List<IBuildObject> getProjectToolchains() {
    List<IBuildObject> projectToolchains = new ArrayList<>();

    // Get the projectType from project.
    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(getProject());
    if (info != null) {
      IConfiguration[] configs = info.getManagedProject().getConfigurations();
      for (IConfiguration config : configs) {
        IToolChain toolchain = config.getToolChain();
        if (toolchain != null) {
          projectToolchains.add(toolchain);
        }
      }
    }
    return projectToolchains;
  }
Пример #4
0
  public void testEnablement() {
    resetValueHandler();

    IProject project =
        ManagedBuildTestHelper.createProject("en", "cdt.managedbuild.target.enablement.exe");
    IFile aFile = ManagedBuildTestHelper.createFile(project, "a.c");
    IFile bFile = ManagedBuildTestHelper.createFile(project, "b.c");

    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
    IConfiguration cfg = info.getManagedProject().getConfigurations()[0];
    assertFalse(fHandleValueCalled);

    doTestEnablement(cfg);

    doEnumAllValues(cfg);

    ManagedBuildTestHelper.removeProject("en");
  }
Пример #5
0
  @Override
  protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
      handleConverterSelection();
      IConvertManagedBuildObject convertBuildObject = null;
      try {
        convertBuildObject =
            (IConvertManagedBuildObject)
                getSelectedConversionElement().createExecutableExtension("class"); // $NON-NLS-1$
      } catch (CoreException e) {
        ManagedBuilderUIPlugin.log(e);
      }
      if (convertBuildObject != null) {
        String fromId = getSelectedConversionElement().getAttribute("fromId"); // $NON-NLS-1$
        String toId = getSelectedConversionElement().getAttribute("toId"); // $NON-NLS-1$

        IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(getProject());
        if (info != null) {
          IManagedProject managedProject = info.getManagedProject();
          if (managedProject != null) {
            if (convertBuildObject.convert(managedProject, fromId, toId, true) == null) {
              setConversionSuccessful(false);
            } else {
              setConversionSuccessful(true);
            }
          } else {
            setConversionSuccessful(false);
          }
        } else {
          setConversionSuccessful(false);
        }
      } else {
        setConversionSuccessful(false);
      }
    }
    super.buttonPressed(buttonId);
  }
Пример #6
0
  public void testEnablement_Bug250686() throws Exception {
    final String testName = getName();
    IProject project = ManagedBuildTestHelper.createProject(testName, PROJECT_TYPE);
    assertNotNull(project);

    IFolder folder = ManagedBuildTestHelper.createFolder(project, "Folder");
    assertNotNull(folder);

    IFile file = ManagedBuildTestHelper.createFile(project, "Folder/file.c");
    assertNotNull(file);

    ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project);
    prjDescription.getConfigurationByName(CFG_NAME);

    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
    IConfiguration cfg = info.getManagedProject().getConfigurations()[0];
    assertNotNull(cfg);
    assertEquals(CFG_NAME, cfg.getName());

    {
      // Round 1. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 1. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 1. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFolderInfo);

      // Option is taken from root folder here
      IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 2. Override the value of the option for the root folder
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      ITool[] tools = rootFolderInfo.getToolsBySuperClassId(TOOL_ID);
      assertEquals(1, tools.length);
      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      rootFolderInfo.setOption(tools[0], option, OPTION_VALUE_ROOT);
    }

    {
      // Round 2. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 2. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 2. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFolderInfo);

      // Option is taken from root folder here
      IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 3. Override the value of the option for the subfolder
      IFolderInfo folderInfo = cfg.createFolderInfo(folder.getFullPath());
      assertNotNull(folderInfo);

      ITool[] tools = folderInfo.getToolsBySuperClassId(TOOL_ID);
      assertEquals(1, tools.length);

      IOption option = getOptionForFolder(folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());

      folderInfo.setOption(tools[0], option, OPTION_VALUE_FOLDER);
    }

    {
      // Round 3. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 3. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 3. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFolderInfo);

      // Option is taken from parent folder here
      IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 4. Override the value of the option for the file
      IFileInfo fileInfo = cfg.createFileInfo(file.getFullPath());
      assertNotNull(fileInfo);

      ITool[] tools = fileInfo.getTools();
      assertEquals(1, tools.length);
      ITool tool = tools[0];
      assertNotNull(tool);

      IOption option = getOptionForFile(fileInfo, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());

      fileInfo.setOption(tool, option, OPTION_VALUE_FILE);
    }

    {
      // Round 4. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 4. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 4. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFileInfo);

      IOption option = getOptionForFile((IFileInfo) fileInfo, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FILE, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    ManagedBuildTestHelper.removeProject(testName);
  }
 private IConfiguration getDefaultConfig() {
   return ManagedBuildManager.getBuildInfo(project).getDefaultConfiguration();
 }
Пример #8
0
  @Override
  public void process(
      TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor)
      throws ProcessFailureException {
    String projectName = args[0].getSimpleValue();
    String prefix = args[1].getSimpleValue();
    String path = args[2].getSimpleValue();

    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (!project.exists()) return;

    IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
    if (buildInfo == null) return;

    IConfiguration[] configs = buildInfo.getManagedProject().getConfigurations();
    for (IConfiguration config : configs) {
      IToolChain toolchain = config.getToolChain();
      IOption option =
          toolchain.getOptionBySuperClassId("cdt.managedbuild.option.gnu.cross.prefix");
      ManagedBuildManager.setOption(config, toolchain, option, prefix);
      option = toolchain.getOptionBySuperClassId("cdt.managedbuild.option.gnu.cross.path");
      ManagedBuildManager.setOption(config, toolchain, option, path);

      ICfgScannerConfigBuilderInfo2Set cbi =
          CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(config);
      Map<CfgInfoContext, IScannerConfigBuilderInfo2> map = cbi.getInfoMap();
      for (CfgInfoContext cfgInfoContext : map.keySet()) {
        IScannerConfigBuilderInfo2 bi = map.get(cfgInfoContext);
        String providerId = "specsFile";
        String runCommand = bi.getProviderRunCommand(providerId);
        bi.setProviderRunCommand(providerId, prefix + runCommand);
        try {
          bi.save();
        } catch (CoreException e) {
          throw new ProcessFailureException(e);
        }

        // Clear the path info that was captured at project creation time
        // TODO we need an API to do this to avoid the discouraged access warnings.

        DiscoveredPathInfo pathInfo = new DiscoveredPathInfo(project);
        InfoContext infoContext = cfgInfoContext.toInfoContext();

        // 1. Remove scanner info from .metadata/.plugins/org.eclipse.cdt.make.core/Project.sc
        DiscoveredScannerInfoStore dsiStore = DiscoveredScannerInfoStore.getInstance();
        try {
          dsiStore.saveDiscoveredScannerInfoToState(project, infoContext, pathInfo);
        } catch (CoreException e) {
          e.printStackTrace();
        }

        // 2. Remove scanner info from CfgDiscoveredPathManager cache and from the Tool
        CfgDiscoveredPathManager cdpManager = CfgDiscoveredPathManager.getInstance();
        cdpManager.removeDiscoveredInfo(project, cfgInfoContext);

        // 3. Remove scanner info from SI collector
        IScannerConfigBuilderInfo2 buildInfo2 = map.get(cfgInfoContext);
        if (buildInfo2 != null) {
          ScannerConfigProfileManager scpManager = ScannerConfigProfileManager.getInstance();
          String selectedProfileId = buildInfo2.getSelectedProfileId();
          SCProfileInstance profileInstance =
              scpManager.getSCProfileInstance(project, infoContext, selectedProfileId);

          IScannerInfoCollector collector = profileInstance.getScannerInfoCollector();
          if (collector instanceof IScannerInfoCollectorCleaner) {
            ((IScannerInfoCollectorCleaner) collector).deleteAll(project);
          }
          buildInfo2 = null;
        }
      }
    }

    ManagedBuildManager.saveBuildInfo(project, true);
  }