Ejemplo n.º 1
0
  /** This method assumes that folder has only one qualified tool. */
  private IOption getOptionForFolder(IFolderInfo rcInfo, String toolId, String optionId) {
    ITool[] tools = null;
    tools = rcInfo.getToolsBySuperClassId(toolId);
    assertNotNull(tools);
    assertEquals(1, tools.length);
    ITool tool = tools[0];
    assertNotNull(tool);

    IOption option = tool.getOptionBySuperClassId(optionId);
    return option;
  }
Ejemplo n.º 2
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);
  }