mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Bug 539882: Applicability calculator should be called with option category
In some situations, it's convenient to create option categories on the abstract tool and use an option applicability calculator to hide the option category if no option is added to the category in an extending instance of the tool. To make the decision, the calculator needs to know what category is to be checked. Change-Id: Id4a269ee583f1f3dee88dee797ba89a0e92d1a42 Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com>
This commit is contained in:
parent
ae78fde323
commit
aef0eaee8c
6 changed files with 193 additions and 2 deletions
|
@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.ui,
|
|||
org.junit,
|
||||
org.eclipse.cdt.managedbuilder.core,
|
||||
org.eclipse.cdt.core,
|
||||
org.eclipse.core.resources
|
||||
org.eclipse.core.resources,
|
||||
org.eclipse.cdt.managedbuilder.core.tests
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Export-Package: org.eclipse.cdt.managedbuilder.ui.tests,
|
||||
|
|
|
@ -46,6 +46,68 @@
|
|||
<toolchain toolchainID="F"/>
|
||||
</wizardPage>
|
||||
</extension>
|
||||
<extension
|
||||
id="cdt.test.ToolListContentProvider.toolchain"
|
||||
point="org.eclipse.cdt.managedbuilder.core.buildDefinitions">
|
||||
<projectType
|
||||
id="cdt.managedbuild.target.ToolListContentProvider.exe"
|
||||
isAbstract="false"
|
||||
isTest="true">
|
||||
<configuration
|
||||
id="cdt.managedbuild.config.ToolListContentProvider.exe.debug"
|
||||
name="ToolListContentProvider">
|
||||
<toolChain
|
||||
id="cdt.managedbuild.toolchain.ToolListContentProvider.exe.debug"
|
||||
isSystem="true">
|
||||
<targetPlatform
|
||||
id="cdt.managedbuild.target.ToolListContentProvider.platform.exe.debug">
|
||||
</targetPlatform>
|
||||
<builder
|
||||
id="cdt.managedbuild.target.ToolListContentProvider.builder.exe.debug">
|
||||
</builder>
|
||||
<optionCategory
|
||||
applicabilityCalculator="org.eclipse.cdt.managedbuilder.ui.tests.properties.HideEmptyOptionCategoryApplicabilityCalculator"
|
||||
id="ToolListContentProvider.toolchain.empty.category1"
|
||||
name="ToolListContentProvider.toolchain.empty.category1">
|
||||
</optionCategory>
|
||||
<option
|
||||
category="ToolListContentProvider.toolchain.empty.category1"
|
||||
id="ToolListContentProvider.toolchain.empty.option1"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="string">
|
||||
</option>
|
||||
<optionCategory
|
||||
applicabilityCalculator="org.eclipse.cdt.managedbuilder.ui.tests.properties.HideEmptyOptionCategoryApplicabilityCalculator"
|
||||
id="ToolListContentProvider.toolchain.empty.category2"
|
||||
name="ToolListContentProvider.toolchain.empty.category2">
|
||||
</optionCategory>
|
||||
<tool
|
||||
id="ToolListContentProvider.tool.empty1"
|
||||
isAbstract="false"
|
||||
superClass=" ">
|
||||
<optionCategory
|
||||
applicabilityCalculator="org.eclipse.cdt.managedbuilder.ui.tests.properties.HideEmptyOptionCategoryApplicabilityCalculator"
|
||||
id="ToolListContentProvider.tool.empty.category1"
|
||||
name="ToolListContentProvider.tool.empty.category1">
|
||||
</optionCategory>
|
||||
<option
|
||||
category="ToolListContentProvider.tool.empty.category1"
|
||||
id="ToolListContentProvider.tool.empty.option1"
|
||||
isAbstract="false"
|
||||
resourceFilter="all"
|
||||
valueType="string">
|
||||
</option>
|
||||
<optionCategory
|
||||
applicabilityCalculator="org.eclipse.cdt.managedbuilder.ui.tests.properties.HideEmptyOptionCategoryApplicabilityCalculator"
|
||||
id="ToolListContentProvider.tool.empty.category2"
|
||||
name="ToolListContentProvider.tool.empty.category2">
|
||||
</optionCategory>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</configuration>
|
||||
</projectType>
|
||||
</extension>
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2018 STMicroelectronics and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* STMicroelectronics
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.ui.tests.properties;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
|
||||
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOptionCategoryApplicability;
|
||||
|
||||
public class HideEmptyOptionCategoryApplicabilityCalculator implements IOptionCategoryApplicability {
|
||||
|
||||
public HideEmptyOptionCategoryApplicabilityCalculator() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptionCategoryVisible(IBuildObject configuration, IHoldsOptions optHolder,
|
||||
IOptionCategory category) {
|
||||
// Check that the category contains at least one option
|
||||
return Arrays.asList(optHolder.getOptions())
|
||||
.stream()
|
||||
.map((opt) -> opt.getCategory())
|
||||
.anyMatch((cat) -> cat != null && cat.equals(category));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2018 STMicroelectronics and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* STMicroelectronics
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.ui.tests.properties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITool;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
|
||||
import org.eclipse.cdt.managedbuilder.ui.properties.ToolListContentProvider;
|
||||
import org.eclipse.cdt.managedbuilder.ui.properties.ToolListElement;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
public class ToolListContentProviderTests extends TestCase {
|
||||
|
||||
private static final String testName = "ToolListContentProvider"; //$NON-NLS-1$
|
||||
private static boolean fHandleValueCalled;
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(ToolListContentProviderTests.class);
|
||||
}
|
||||
|
||||
private void resetValueHandler(){
|
||||
fHandleValueCalled = false;
|
||||
}
|
||||
|
||||
public void testToolListContentProvider(){
|
||||
resetValueHandler();
|
||||
|
||||
IProject project = ManagedBuildTestHelper.createProject(testName,
|
||||
"cdt.managedbuild.target.ToolListContentProvider.exe"); //$NON-NLS-1$
|
||||
|
||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
||||
IConfiguration cfg = info.getManagedProject().getConfigurations()[0];
|
||||
assertFalse(fHandleValueCalled);
|
||||
|
||||
doTestToolListContentProvider(cfg);
|
||||
|
||||
ManagedBuildTestHelper.removeProject(testName);
|
||||
}
|
||||
|
||||
private void doTestToolListContentProvider(IConfiguration cfg){
|
||||
ToolListContentProvider provider = new ToolListContentProvider(ToolListContentProvider.PROJECT);
|
||||
provider.inputChanged(null, null, cfg.getRootFolderInfo());
|
||||
|
||||
ToolListElement[] elements = (ToolListElement[])provider.getChildren(cfg);
|
||||
|
||||
// Toolchain level
|
||||
List<String> toolchainOptCats = getOptionCategories(elements);
|
||||
assertTrue(toolchainOptCats.contains("ToolListContentProvider.toolchain.empty.category1"));
|
||||
assertFalse(toolchainOptCats.contains("ToolListContentProvider.toolchain.empty.category2"));
|
||||
|
||||
// Tool level
|
||||
for (ToolListElement element : elements) {
|
||||
ITool tool = element.getTool();
|
||||
if (tool != null && tool.getBaseId().equals("ToolListContentProvider.tool.empty1")) {
|
||||
List<String> toolOptCats = getOptionCategories(element.getChildElements());
|
||||
assertTrue(toolOptCats.contains("ToolListContentProvider.tool.empty.category1"));
|
||||
assertFalse(toolOptCats.contains("ToolListContentProvider.tool.empty.category2"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getOptionCategories(ToolListElement[] elements) {
|
||||
List<String> res = new ArrayList<>();
|
||||
for (ToolListElement element : elements) {
|
||||
IOptionCategory cat = element.getOptionCategory();
|
||||
if (cat != null) { // Only list nodes with option category
|
||||
String id = cat.getBaseId();
|
||||
assertNotNull(id);
|
||||
res.add(id);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import junit.framework.TestSuite;
|
|||
|
||||
import org.eclipse.cdt.managedbuilder.ui.tests.TestCProjectPlatformPage;
|
||||
import org.eclipse.cdt.managedbuilder.ui.tests.TestCustomPageManager;
|
||||
import org.eclipse.cdt.managedbuilder.ui.tests.properties.ToolListContentProviderTests;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -30,6 +31,7 @@ public class AutomatedIntegrationSuite {
|
|||
// TODO uncoment this
|
||||
suite.addTest(TestCustomPageManager.suite());
|
||||
suite.addTestSuite(TestCProjectPlatformPage.class);
|
||||
suite.addTest(ToolListContentProviderTests.suite());
|
||||
|
||||
//$JUnit-END$
|
||||
return suite;
|
||||
|
|
|
@ -120,7 +120,7 @@ public class ToolListContentProvider implements ITreeContentProvider{
|
|||
for (int i=0; i<cats.length; i++) {
|
||||
ToolListElement e = new ToolListElement(parentElement, optHolder, cats[i]);
|
||||
applicabilityCalculator = e.getOptionCategory().getApplicabilityCalculator();
|
||||
if (applicabilityCalculator == null || applicabilityCalculator.isOptionCategoryVisible(config, optHolder, parent)) {
|
||||
if (applicabilityCalculator == null || applicabilityCalculator.isOptionCategoryVisible(config, e.getHoldOptions(), e.getOptionCategory())) {
|
||||
parentElement.addChildElement(e);
|
||||
createChildElements(e,config);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue