Skip to main content
summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorTorbjörn Svensson2018-10-06 17:09:56 -0400
committerWilliam Riley2018-10-09 05:47:15 -0400
commitaef0eaee8c5cf28b441ec0cfe535acd30418e98d (patch)
tree38b88a101c188ae18a275ae190057d1d4c48db5e /build
parentae78fde323f048080c240d0494eb723537eba7da (diff)
downloadorg.eclipse.cdt-aef0eaee8c5cf28b441ec0cfe535acd30418e98d.tar.gz
org.eclipse.cdt-aef0eaee8c5cf28b441ec0cfe535acd30418e98d.tar.xz
org.eclipse.cdt-aef0eaee8c5cf28b441ec0cfe535acd30418e98d.zip
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>
Diffstat (limited to 'build')
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui.tests/META-INF/MANIFEST.MF3
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui.tests/plugin.xml62
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/properties/HideEmptyOptionCategoryApplicabilityCalculator.java34
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/properties/ToolListContentProviderTests.java92
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/suite/AutomatedIntegrationSuite.java2
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListContentProvider.java2
6 files changed, 193 insertions, 2 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.ui.tests/META-INF/MANIFEST.MF
index 07e2a24ad8..c4114bca42 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui.tests/META-INF/MANIFEST.MF
+++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/META-INF/MANIFEST.MF
@@ -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,
diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui.tests/plugin.xml
index cb7d425743..d344a2f272 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui.tests/plugin.xml
+++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/plugin.xml
@@ -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>
diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/properties/HideEmptyOptionCategoryApplicabilityCalculator.java b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/properties/HideEmptyOptionCategoryApplicabilityCalculator.java
new file mode 100644
index 0000000000..f24d9bd4e2
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/properties/HideEmptyOptionCategoryApplicabilityCalculator.java
@@ -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));
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/properties/ToolListContentProviderTests.java b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/properties/ToolListContentProviderTests.java
new file mode 100644
index 0000000000..81bca2aba9
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/properties/ToolListContentProviderTests.java
@@ -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;
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/suite/AutomatedIntegrationSuite.java b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/suite/AutomatedIntegrationSuite.java
index fc7b8a16de..6f11646356 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/suite/AutomatedIntegrationSuite.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/suite/AutomatedIntegrationSuite.java
@@ -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;
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListContentProvider.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListContentProvider.java
index f8a3962deb..947caeaf6d 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListContentProvider.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolListContentProvider.java
@@ -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);
}

Back to the top