From 512462b0939d8ad4460a59fe914ad549e020cee1 Mon Sep 17 00:00:00 2001 From: Mikhail Sennikovsky Date: Mon, 12 Dec 2005 18:10:39 +0000 Subject: [PATCH] Additional option enablement functionality and tests Additional value handler functionality --- .../plugin.xml | 968 ++++++++++++++++++ .../testplugin/ManagedBuildTestHelper.java | 37 +- .../tests/suite/AllManagedBuildTests.java | 2 + .../core/tests/OptionEnablementTests.java | 544 ++++++++++ .../schema/buildDefinitions.exsd | 51 +- .../managedbuilder/core/IHoldsOptions.java | 15 + .../core/IManagedOptionValueHandler.java | 4 + .../core/ManagedBuildManager.java | 62 +- ...leanExpressionApplicabilityCalculator.java | 10 + .../internal/core/Configuration.java | 69 +- .../internal/core/HoldsOptions.java | 59 +- .../managedbuilder/internal/core/Option.java | 72 +- .../internal/core/ResourceConfiguration.java | 86 +- .../internal/core/ToolReference.java | 4 + .../enablement/CheckHolderExpression.java | 52 + .../enablement/CompositeExpression.java | 2 + .../OptionEnablementExpression.java | 73 +- .../BuildToolSettingsPreferenceStore.java | 14 +- 18 files changed, 1936 insertions(+), 188 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/OptionEnablementTests.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/CheckHolderExpression.java diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml index b156b2d02b6..1f1398da8cf 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml @@ -4942,6 +4942,974 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java index 073bf7389f6..85b6f75fac0 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.managedbuilder.testplugin; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileReader; import java.io.FileWriter; @@ -18,6 +19,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.zip.ZipFile; import junit.framework.Assert; +import junit.framework.TestCase; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; @@ -28,7 +30,7 @@ import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; -import org.eclipse.cdt.make.core.MakeCorePlugin; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; @@ -38,11 +40,11 @@ import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.ui.dialogs.IOverwriteQuery; import org.eclipse.ui.wizards.datatransfer.ImportOperation; import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider; @@ -79,7 +81,7 @@ public class ManagedBuildTestHelper { workspace.setDescription(workspaceDesc); IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); //description.setLocation(root.getLocation()); - project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), MakeCorePlugin.MAKE_PROJECT_ID); + project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID); } } else { IWorkspace workspace = ResourcesPlugin.getWorkspace(); @@ -102,6 +104,33 @@ public class ManagedBuildTestHelper { return project; } + static public IProject createProject( + final String name, + final String projectTypeId) { + try { + return createProject(name, + null, + ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID, + projectTypeId); + } catch (CoreException e) { + TestCase.fail(e.getLocalizedMessage()); + } + return null; + } + + static public IFile createFile(IProject project, String name){ + IFile file = project.getFile(name); + if( file.exists() ){ + try { +// file.create( new ByteArrayInputStream( "#include \n extern void bar(); \n int main() { \nprintf(\"Hello, World!!\"); \n bar();\n return 0; }".getBytes() ), false, null ); + file.create( new ByteArrayInputStream( new byte[0] ), false, null ); + } catch (CoreException e) { + TestCase.fail(e.getLocalizedMessage()); + } + } + return file; + } + /** * Remove the IProject with the name specified in the argument from the * receiver's workspace. diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java index 72d6cb77390..df36c031221 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.managedbuilder.core.tests.ManagedProject21MakefileTests; import org.eclipse.cdt.managedbuilder.core.tests.ManagedProject30MakefileTests; import org.eclipse.cdt.managedbuilder.core.tests.ManagedProjectUpdateTests; import org.eclipse.cdt.managedbuilder.core.tests.MultiVersionSupportTests; +import org.eclipse.cdt.managedbuilder.core.tests.OptionEnablementTests; import org.eclipse.cdt.managedbuilder.core.tests.ResourceBuildCoreTests; /** @@ -57,6 +58,7 @@ public class AllManagedBuildTests { suite.addTest(ManagedBuildMacrosTests.suite()); suite.addTest(ManagedBuildTCSupportedTest.suite()); suite.addTest(MultiVersionSupportTests.suite()); + suite.addTest(OptionEnablementTests.suite()); //$JUnit-END$ return suite; } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/OptionEnablementTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/OptionEnablementTests.java new file mode 100644 index 00000000000..b98e32484ef --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/OptionEnablementTests.java @@ -0,0 +1,544 @@ +/******************************************************************************* + * Copyright (c) 2005 Intel Corporation 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: + * Intel Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.core.tests; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IBuildObject; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler; +import org.eclipse.cdt.managedbuilder.core.IOption; +import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; +import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; + +public class OptionEnablementTests extends TestCase + implements IManagedOptionValueHandler, + IOptionApplicability{ + private static boolean fEnUiVisible; + private static boolean fEnUiEnabled; + private static boolean fEnCmdUsed; + + private static boolean fHandleValueCalled; + + private static final String thisEnumIds[] = new String[]{"testgnu.enablement.c.optimization.level.optimize", "testgnu.enablement.c.optimization.level.more"}; + private static final String thisStrings[] = new String[]{ +// "", +// "test a b c", +// "some buggy string", + "start 1.2.3 stop"}; + + + public boolean handleValue(IBuildObject configuration, IHoldsOptions holder, IOption option, String extraArgument, int event) { + // TODO Auto-generated method stub + return false; + } + + public boolean isDefaultValue(IBuildObject configuration, IHoldsOptions holder, IOption option, String extraArgument) { + // TODO Auto-generated method stub + return false; + } + + public boolean isEnumValueAppropriate(IBuildObject configuration, IHoldsOptions holder, IOption option, String extraArgument, String enumValue) { + // TODO Auto-generated method stub + return false; + } + + public boolean isOptionUsedInCommandLine(IBuildObject configuration, IHoldsOptions holder, IOption option) { + return fEnCmdUsed; + } + + public boolean isOptionVisible(IBuildObject configuration, IHoldsOptions holder, IOption option) { + return fEnUiVisible; + } + + public boolean isOptionEnabled(IBuildObject configuration, IHoldsOptions holder, IOption option) { + return fEnUiEnabled; + } + + public static Test suite() { + return new TestSuite(OptionEnablementTests.class); + } + + private void resetValueHandler(){ + fHandleValueCalled = false; + } + + private void setEnablement(boolean cmdUs, boolean uiVis, boolean uiEn){ + fEnUiVisible = uiVis; + fEnUiEnabled = uiEn; + fEnCmdUsed = cmdUs; + } + + 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"); + } + + private void doEnumAllValues(IBuildObject cfgBo){ + ITool thisTool = getTool(cfgBo,"enablement.this.child_1.2.3"); + ITool otherTool = getTool(cfgBo,"enablement.other"); + + IBuildObject thisCfg = thisTool.getParent(); + IBuildObject otherCfg = otherTool.getParent(); + + for(int i = 0; i < thisStrings.length; i++){ + String strVal = thisStrings[i]; + setOption(cfgBo, thisTool, "this.string", strVal); + doTestEnablement(cfgBo); + } +/* + for(int i = 0; i < thisEnumIds.length; i++){ + String strVal = thisEnumIds[i]; + setOption(cfgBo, thisTool, "this.enum", strVal); + doTestEnablement(cfgBo); + } +*/ + setOption(cfgBo, thisTool, "this.boolean", false); + doTestEnablement(cfgBo); + + setOption(cfgBo, thisTool, "this.boolean", true); + doTestEnablement(cfgBo); + } + + private ITool getTool(IBuildObject cfgBo, String id){ + IResourceConfiguration rcCfg = null; + IConfiguration cfg = null; + ITool tool = null; + if(cfgBo instanceof IResourceConfiguration){ + rcCfg = (IResourceConfiguration)rcCfg; + cfg = rcCfg.getParent(); + ITool tools[] = rcCfg.getTools(); + for(int i = 0; i < tools.length; i++){ + for(ITool tmp = tools[i]; tmp != null; tmp=tmp.getSuperClass()){ + if(tmp.getId().equals(id)){ + tool = tools[i]; + break; + } + } + } + } else if(cfgBo instanceof IConfiguration){ + cfg = (IConfiguration)cfgBo; + tool = cfg.getToolsBySuperClassId(id)[0]; + } else + fail("wrong argument"); + return tool; + } + + private IOption setOption(IBuildObject cfg, IHoldsOptions holder, String id, boolean value){ + return setOption(cfg, holder, holder.getOptionBySuperClassId(id), value); + } + + private IOption setOption(IBuildObject cfg, IHoldsOptions holder, IOption option, boolean value){ + try{ + if(cfg instanceof IConfiguration) + return ((IConfiguration)cfg).setOption(holder, option, value); + else if(cfg instanceof IResourceConfiguration) + return ((IResourceConfiguration)cfg).setOption(holder, option, value); + } catch(BuildException e){ + fail(e.getLocalizedMessage()); + } + fail("wrong arg"); + return null; + } + + private IOption setOption(IBuildObject cfg, IHoldsOptions holder, String id, String value){ + return setOption(cfg, holder, holder.getOptionBySuperClassId(id), value); + } + + private IOption setOption(IBuildObject cfg, IHoldsOptions holder, IOption option, String value){ + try{ + if(cfg instanceof IConfiguration) + return ((IConfiguration)cfg).setOption(holder, option, value); + else if(cfg instanceof IResourceConfiguration) + return ((IResourceConfiguration)cfg).setOption(holder, option, value); + } catch(BuildException e){ + fail(e.getLocalizedMessage()); + } + fail("wrong arg"); + return null; + } + + private IOption setOption(IBuildObject cfg, IHoldsOptions holder, String id, String value[]){ + return setOption(cfg, holder, holder.getOptionBySuperClassId(id), value); + } + + private IOption setOption(IBuildObject cfg, IHoldsOptions holder, IOption option, String value[]){ + try{ + if(cfg instanceof IConfiguration) + return ((IConfiguration)cfg).setOption(holder, option, value); + else if(cfg instanceof IResourceConfiguration) + return ((IResourceConfiguration)cfg).setOption(holder, option, value); + } catch(BuildException e){ + fail(e.getLocalizedMessage()); + } + fail("wrong arg"); + return null; + } + + private void doTestEnablement(IBuildObject cfg){ + ITool tool = getTool(cfg, "enablement.this.child_1.2.3"); + ITool otherTool = getTool(cfg, "enablement.other"); + ITool tool2 = getTool(cfg, "enablement.this.child.2_1.2.3"); + +// IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + + IOption thisBoolean = tool.getOptionBySuperClassId("this.boolean"); + IOption thisString = tool.getOptionBySuperClassId("this.string"); + IOption thisEnum = tool.getOptionBySuperClassId("this.enum"); + + IOption otherString = otherTool.getOptionBySuperClassId("other.string"); + IOption otherBoolean = otherTool.getOptionBySuperClassId("other.boolean"); + + + + + try{ + + IOption option = tool.getOptionBySuperClassId("enablement.command.c1"); + + assertEquals(option.getCommand(), "c1"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.command.c2"); + assertEquals(option.getCommand(), "c2"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.commandFalse.c1"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "c1"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.commandFalse.c2"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "c2"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.command.c1.commandFalse.cF1"); + assertEquals(option.getCommand(), "c1"); + assertEquals(option.getCommandFalse(), "cF1"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.command.cmd.commandFalse.cmdF"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.command.c1.commandFalse.cmdF"); + assertEquals(option.getCommand(), "c1"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.command.cmd.commandFalse.cF1"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cF1"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.ui.en"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cF1"); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.ui.vis"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cF1"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.cmd.us"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.cmdUs.or.uiVis"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cF1"); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.uiEn.or.uiVis"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cF1"); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.all"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cF1"); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.all.ac.vh"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cF1"); + + setEnablement(false, false, false); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + setEnablement(false, true, false); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + setEnablement(false, false, true); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + setEnablement(true, false, false); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + setEnablement(false, false, false); + option = tool.getOptionBySuperClassId("enablement.all.cF1.ac.vh"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cF1"); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + + setEnablement(true, false, true); + + option = tool.getOptionBySuperClassId("enablement.all.cF.cmdF"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.all.cF.cF1"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cF1"); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("this.boolean"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOpt.all.Q.this.boolean.True"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertEquals(thisBoolean.getBooleanValue() == true, + option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertEquals(thisBoolean.getBooleanValue() == true, + option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertEquals(thisBoolean.getBooleanValue() == true, + option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOpt.all.Q.this.boolean.False"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertEquals(thisBoolean.getBooleanValue() == false, + option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertEquals(thisBoolean.getBooleanValue() == false, + option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertEquals(thisBoolean.getBooleanValue() == false, + option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOpt.all.Q.this.string.Q.empty"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertEquals(thisString.getStringValue().equals(""), + option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals(""), + option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals(""), + option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOpt.all.Q.this.string.Q.test a b c"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertEquals(thisString.getStringValue().equals("test a b c"), + option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals("test a b c"), + option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals("test a b c"), + option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOpt.all.Q.this.enum.Q.testgnu.enablement.c.optimization.level.optimize"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + String id = thisEnum.getEnumeratedId(thisEnum.getStringValue()); + if(id == null) + id = ""; + assertEquals(id.equals("testgnu.enablement.c.optimization.level.optimize"), + option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertEquals(id.equals("testgnu.enablement.c.optimization.level.optimize"), + option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertEquals(id.equals("testgnu.enablement.c.optimization.level.optimize"), + option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOpt.all.Q.this.Q.true"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertEquals(option.getBooleanValue() == true, + option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertEquals(option.getBooleanValue()== true, + option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertEquals(option.getBooleanValue() == true, + option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOpt.all.Q.this.string.Q.start ${ParentVersion} stop"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertEquals(thisString.getStringValue().equals("start 1.2.3 stop"), + option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals("start 1.2.3 stop"), + option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals("start 1.2.3 stop"), + option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOpt.all.Q.this.string.Q.other.string"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertEquals(thisString.getStringValue().equals(otherString.getStringValue()), + option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals(otherString.getStringValue()), + option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals(otherString.getStringValue()), + option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOpt.all.Q.this.string.Q.other.string"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertEquals(thisString.getStringValue().equals(otherString.getStringValue()), + option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals(otherString.getStringValue()), + option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertEquals(thisString.getStringValue().equals(otherString.getStringValue()), + option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkString"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkString.2"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkString.3"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkFalse.false"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkNot.false"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkOr.true"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkAnd.false"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool.getOptionBySuperClassId("enablement.checkHolder.true.1.false.2"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertTrue(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionVisible(cfg, tool, option)); + assertTrue(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool, option)); + + option = tool2.getOptionBySuperClassId("enablement.checkHolder.true.1.false.2"); + assertEquals(option.getCommand(), "cmd"); + assertEquals(option.getCommandFalse(), "cmdF"); + assertFalse(option.getApplicabilityCalculator().isOptionUsedInCommandLine(cfg, tool2, option)); + assertFalse(option.getApplicabilityCalculator().isOptionVisible(cfg, tool2, option)); + assertFalse(option.getApplicabilityCalculator().isOptionEnabled(cfg, tool2, option)); + + }catch (BuildException e){ + fail(e.getLocalizedMessage()); + } + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd index c2ce83c5cb0..ca68baedba5 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd +++ b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd @@ -1626,6 +1626,7 @@ If the "buildPathResolver" attribute is specified, the "pathDelim + @@ -1635,11 +1636,35 @@ Can contain the following values: UI_VISIBILITY – the given enablement expression specifies whether the option is to be visible in UI, UI_ENABLEMENT – the given enablement expression specifies the enable state of the controls that represent the option in UI, CMD_USAGE – the given enablement expression specifies whether the option is to be used in command line +CONTAINER_ATTRIBUTE - the given enablement expressions specifies thecontainer attribute value ALL – this value means the combination of all the above values. Several types could be specified simultaneously using the "|" as a delimiter, e.g.: type="UI_VISIBILITY|CMD_USAGE" - + + + + + + + This attribute should be used only for the CONTAINER_ATTRIBUTE enablement to specify the name of the attribute for which this enablement applies. Currently the following option attributes are supported: +"command" +"commandFalse" + + + + + + + + + + + + + + + This attribute should be used only for the CONTAINER_ATTRIBUTE enablement to specify the value of the attribute specified in the "attribute" for which this enablement applies @@ -1659,6 +1684,7 @@ type="UI_VISIBILITY|CMD_USAGE" + @@ -1676,6 +1702,7 @@ type="UI_VISIBILITY|CMD_USAGE" + @@ -1693,6 +1720,7 @@ type="UI_VISIBILITY|CMD_USAGE" + @@ -1723,7 +1751,6 @@ type="UI_VISIBILITY|CMD_USAGE" Specifies the expected value. If the current option value matches the value specified in this attribute, the checkOption element is treated as true, otherwise – as false. The expected value could be specified either as a string that may contain build macros or as a regular expression. During the comparison, the build macros are resolved and the option value is checked to match the resulting string or regular expression. The way the expected value is specified and treated depends on the value of the isRegex attribute - @@ -1761,7 +1788,7 @@ The expected value could be specified either as a string that may contain build - Represents the string to be checked. The string will typically contain the build macros. + Represents the string to be checked. The string will typically contain the build macros. @@ -1771,7 +1798,6 @@ The expected value could be specified either as a string that may contain build Specifies the expected value. If the current string specified in the “string” attribute matches the value specified in this attribute, the checkString element is treated as true, otherwise – as false. The expected value could be specified either as a string that might contain the build macros or as a regular expression. The way the value is specified and treated depends on the value of the isRegex attribute. - @@ -1793,6 +1819,23 @@ The way the value is specified and treated depends on the value of the isRegex a + + + + Performs the holder check. + + + + + + + Specifies the holder id to be checked. The checkHolder is treated as true if the id specified in this attribute matches with the option's holder id or the id of some holder's super-class. Otherwise the checkHolder is treated as false. + + + + + + diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java index 1a4963ef8a1..6a33dadb796 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IHoldsOptions.java @@ -141,4 +141,19 @@ public interface IHoldsOptions extends IBuildObject { */ public void createOptions(IHoldsOptions superClass); + /** + + * This method should be called in order to obtain the option whose value and attributes could be directly changed/adjusted + * + * @param id the option to be modified + * @param adjustExtension if false, modifications are to be made for the non-extension element + * (only for some particular configuration associated with some eclipse project) + * This is the most common use of this method. + * + * True is allowed only while while handling the LOAD value handler event. + * In this case modifications are to be made for the extension element. + * This could be used for adjusting extension options + * Note: changing this option will affect all non-extension configurations using this option! + */ + IOption getOptionToSet(IOption option, boolean adjustExtension) throws BuildException; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedOptionValueHandler.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedOptionValueHandler.java index c66f9d44c08..4bde86408b8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedOptionValueHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedOptionValueHandler.java @@ -38,6 +38,10 @@ public interface IManagedOptionValueHandler{ * button (or the OK button). The valueHandler can * transfer the value of the option to its own * back-end. */ + public final int EVENT_LOAD = 5; /** Posted when the managed build extensions (defined in the manifext files)extension option isThe option has been set by pressing the Apply + * are loadded. + * The handler is allowed to adjust the extension elements + */ /** * Handles transfer between values between UI element and diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index b0cd9d32852..c9547375f4f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -16,6 +16,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -26,7 +27,6 @@ import java.util.Map; import java.util.Random; import java.util.SortedMap; import java.util.TreeMap; -import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -49,6 +49,7 @@ import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentBuildPathsChangeListener; import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider; +import org.eclipse.cdt.managedbuilder.internal.core.BooleanExpressionApplicabilityCalculator; import org.eclipse.cdt.managedbuilder.internal.core.Builder; import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.core.DefaultManagedConfigElement; @@ -76,21 +77,18 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.resources.ResourceAttributes; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.PluginVersionIdentifier; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.IJobManager; -import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchWindow; @@ -2028,7 +2026,61 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI } } } + + performAdjustments(); } + + private static void performAdjustments(){ + IProjectType types[] = getDefinedProjectTypes(); + for(int i = 0; i < types.length; i++){ + IConfiguration cfgs[] = types[i].getConfigurations(); + for(int j = 0; j < cfgs.length; j++){ + adjustConfig(cfgs[j]); + } + } + + for(int i = 0; i < types.length; i++){ + IConfiguration cfgs[] = types[i].getConfigurations(); + for(int j = 0; j < cfgs.length; j++){ + performValueHandlerEvent(cfgs[j], IManagedOptionValueHandler.EVENT_LOAD); + } + } + + } + + private static void adjustConfig(IConfiguration cfg){ + IToolChain tc = cfg.getToolChain(); + adjustHolder(cfg, tc); + + ITool tools[] = cfg.getTools(); + for(int i = 0; i < tools.length; i++){ + adjustHolder(cfg, tools[i]); + } + + IResourceConfiguration rcCfgs[] = cfg.getResourceConfigurations(); + + for(int i = 0; i 0) + booleanExpressionCalculator = new BooleanExpressionApplicabilityCalculator(enablements); + // get the applicability calculator, if any String applicabilityCalculatorStr = element.getAttribute(APPLICABILITY_CALCULATOR); if (applicabilityCalculatorStr != null && element instanceof DefaultManagedConfigElement) { applicabilityCalculatorElement = ((DefaultManagedConfigElement)element).getConfigurationElement(); } else { - IManagedConfigElement enablements[] = element.getChildren(OptionEnablementExpression.NAME); - if(enablements.length > 0) - applicabilityCalculator = new BooleanExpressionApplicabilityCalculator(enablements); - + applicabilityCalculator = booleanExpressionCalculator; } // valueHandler @@ -1329,7 +1337,8 @@ public class Option extends BuildObject implements IOption { */ public void setDefaultValue(Object v) { defaultValue = v; - setDirty(true); + if(!isExtensionElement()) + setDirty(true); } /* (non-Javadoc) @@ -1343,7 +1352,8 @@ public class Option extends BuildObject implements IOption { } else { categoryId = null; } - setDirty(true); + if(!isExtensionElement()) + setDirty(true); } } @@ -1354,7 +1364,8 @@ public class Option extends BuildObject implements IOption { if (cmd == null && command == null) return; if (cmd == null || command == null || !cmd.equals(command)) { command = cmd; - isDirty = true; + if(!isExtensionElement()) + isDirty = true; } } @@ -1365,7 +1376,8 @@ public class Option extends BuildObject implements IOption { if (cmd == null && commandFalse == null) return; if (cmd == null || commandFalse == null || !cmd.equals(commandFalse)) { commandFalse = cmd; - isDirty = true; + if(!isExtensionElement()) + isDirty = true; } } @@ -1376,7 +1388,8 @@ public class Option extends BuildObject implements IOption { if (tooltip == null && tip == null) return; if (tooltip == null || tip == null || !tooltip.equals(tip)) { tip = tooltip; - isDirty = true; + if(!isExtensionElement()) + isDirty = true; } } @@ -1386,7 +1399,8 @@ public class Option extends BuildObject implements IOption { public void setResourceFilter(int filter) { if (resourceFilter == null || !(filter == resourceFilter.intValue())) { resourceFilter = new Integer(filter); - isDirty = true; + if(!isExtensionElement()) + isDirty = true; } } @@ -1396,7 +1410,8 @@ public class Option extends BuildObject implements IOption { public void setBrowseType(int type) { if (browseType == null || !(type == browseType.intValue())) { browseType = new Integer(type); - isDirty = true; + if(!isExtensionElement()) + isDirty = true; } } @@ -1409,7 +1424,8 @@ public class Option extends BuildObject implements IOption { } else { throw new BuildException(ManagedMakeMessages.getResourceString("Option.error.bad_value_type")); //$NON-NLS-1$ } - setDirty(true); + if(!isExtensionElement()) + setDirty(true); } @@ -1423,7 +1439,8 @@ public class Option extends BuildObject implements IOption { } else { throw new BuildException(ManagedMakeMessages.getResourceString("Option.error.bad_value_type")); //$NON-NLS-1$ } - setDirty(true); + if(!isExtensionElement()) + setDirty(true); } @@ -1446,7 +1463,8 @@ public class Option extends BuildObject implements IOption { else { throw new BuildException(ManagedMakeMessages.getResourceString("Option.error.bad_value_type")); //$NON-NLS-1$ } - setDirty(true); + if(!isExtensionElement()) + setDirty(true); } /* (non-Javadoc) @@ -1454,7 +1472,8 @@ public class Option extends BuildObject implements IOption { */ public void setValue(Object v) { value = v; - setDirty(true); + if(!isExtensionElement()) + setDirty(true); } /* (non-Javadoc) @@ -1464,7 +1483,8 @@ public class Option extends BuildObject implements IOption { // TODO: Verify that this is a valid type if (valueType == null || valueType.intValue() != type) { valueType = new Integer(type); - setDirty(true); + if(!isExtensionElement()) + setDirty(true); } } @@ -1485,7 +1505,8 @@ public class Option extends BuildObject implements IOption { */ public void setValueHandlerElement(IConfigurationElement element) { valueHandlerElement = element; - setDirty(true); + if(!isExtensionElement()) + setDirty(true); } /* (non-Javadoc) @@ -1536,7 +1557,8 @@ public class Option extends BuildObject implements IOption { valueHandlerExtraArgument == null || !extraArgument.equals(valueHandlerExtraArgument)) { valueHandlerExtraArgument = extraArgument; - isDirty = true; + if(!isExtensionElement()) + isDirty = true; } } @@ -1815,5 +1837,17 @@ public class Option extends BuildObject implements IOption { public void setVersion(PluginVersionIdentifier version) { // Do nothing } + + public BooleanExpressionApplicabilityCalculator getBooleanExpressionCalculator(){ + return booleanExpressionCalculator; + } + + public boolean isAdjustedExtension(){ + return isUdjusted; + } + + public void setAdjusted(boolean adjusted) { + isUdjusted = adjusted; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java index d93e33424a1..02f52f76fbc 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java @@ -766,32 +766,8 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi if (option.getBooleanValue() != value) { // If this resource config does not already override this option, then we need to // create a new option - if (getHoldersParent(option) != this) { - IOption newSuperClass = option; - if (!newSuperClass.isExtensionElement()) { - newSuperClass = newSuperClass.getSuperClass(); - } - if (newSuperClass.isExtensionElement()) { - // If the extension element was created from an MBS 2.0 model OptionReference element, hook the - // new option up to its superclass directly. This is to avoid references to oddly id'ed - // elements that are automatically generated from V2.0 model optionReferences. If these - // end up in the project file, then the project could have a problem when the integration - // provider switches to providing the new model. - if (((Option)newSuperClass).wasOptRef()) { - newSuperClass = newSuperClass.getSuperClass(); - } - } - // Create an Option element for the managed build project file (.CDTBUILD) - String subId; - int nnn = ManagedBuildManager.getRandomNumber(); - subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$ - retOpt = holder.createOption(newSuperClass, subId, null, false); - retOpt.setValueType(option.getValueType()); - retOpt.setValue(value); - setDirty(true); - } else { - option.setValue(value); - } + retOpt = holder.getOptionToSet(option, false); + retOpt.setValue(value); // TODO: This causes the entire project to be rebuilt. Is there a way to only have this // file rebuilt? "Clean" its output? Change its modification date? parent.setRebuildState(true); @@ -806,32 +782,8 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi if (oldValue != null && !oldValue.equals(value)) { // If this resource config does not already override this option, then we need to // create a new option - if (getHoldersParent(option) != this) { - IOption newSuperClass = option; - if (!newSuperClass.isExtensionElement()) { - newSuperClass = newSuperClass.getSuperClass(); - } - if (newSuperClass.isExtensionElement()) { - // If the extension element was created from an MBS 2.0 model OptionReference element, hook the - // new option up to its superclass directly. This is to avoid references to oddly id'ed - // elements that are automatically generated from V2.0 model optionReferences. If these - // end up in the project file, then the project could have a problem when the integration - // provider switches to providing the new model. - if (((Option)newSuperClass).wasOptRef()) { - newSuperClass = newSuperClass.getSuperClass(); - } - } - // Create an Option element for the managed build project file (.CDTBUILD) - String subId; - int nnn = ManagedBuildManager.getRandomNumber(); - subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$ - retOpt = holder.createOption(newSuperClass, subId, null, false); - retOpt.setValueType(option.getValueType()); - retOpt.setValue(value); - setDirty(true); - } else { - option.setValue(value); - } + retOpt = holder.getOptionToSet(option, false); + retOpt.setValue(value); // TODO: This causes the entire project to be rebuilt. Is there a way to only have this // file rebuilt? "Clean" its output? Change its modification date? parent.setRebuildState(true); @@ -867,34 +819,8 @@ public class ResourceConfiguration extends BuildObject implements IResourceConfi break; } if(!Arrays.equals(value, oldValue)) { - // If this resource config does not already override this option, then we need to - // create a new option - if (getHoldersParent(option) != this) { - IOption newSuperClass = option; - if (!newSuperClass.isExtensionElement()) { - newSuperClass = newSuperClass.getSuperClass(); - } - if (newSuperClass.isExtensionElement()) { - // If the extension element was created from an MBS 2.0 model OptionReference element, hook the - // new option up to its superclass directly. This is to avoid references to oddly id'ed - // elements that are automatically generated from V2.0 model optionReferences. If these - // end up in the project file, then the project could have a problem when the integration - // provider switches to providing the new model. - if (((Option)newSuperClass).wasOptRef()) { - newSuperClass = newSuperClass.getSuperClass(); - } - } - // Create an Option element for the managed build project file (.CDTBUILD) - String subId; - int nnn = ManagedBuildManager.getRandomNumber(); - subId = newSuperClass.getId() + "." + nnn; //$NON-NLS-1$ - retOpt = holder.createOption(newSuperClass, subId, null, false); - retOpt.setValueType(option.getValueType()); - retOpt.setValue(value); - setDirty(true); - } else { - option.setValue(value); - } + retOpt = holder.getOptionToSet(option, false); + retOpt.setValue(value); // TODO: This causes the entire project to be rebuilt. Is there a way to only have this // file rebuilt? "Clean" its output? Change its modification date? parent.setRebuildState(true); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java index 9125449199e..d5df38aa97d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java @@ -1244,4 +1244,8 @@ public class ToolReference implements IToolReference { public String getManagedBuildRevision() { return null; } + + public IOption getOptionToSet(IOption option, boolean adjustExtension){ + return null; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/CheckHolderExpression.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/CheckHolderExpression.java new file mode 100644 index 00000000000..5bf316b81fe --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/CheckHolderExpression.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2005 Intel Corporation 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: + * Intel Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.enablement; + +import org.eclipse.cdt.managedbuilder.core.IBuildObject; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; +import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; +import org.eclipse.cdt.managedbuilder.core.IOption; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; + +public class CheckHolderExpression implements IBooleanExpression { + public static final String NAME = "checkHolder"; //$NON-NLS-1$ + + public static final String HOLDER_ID = "holderId"; //$NON-NLS-1$ + + private String fHolderId; + + public CheckHolderExpression(IManagedConfigElement element){ + fHolderId = element.getAttribute(HOLDER_ID); + } + + + public boolean evaluate(IBuildObject configuration, IHoldsOptions holder, + IOption option) { + if(fHolderId != null){ + for(; holder != null; holder = getHolderSuperClass(holder)){ + if(fHolderId.equals(holder.getId())) + return true; + } + return false; + } + return true; + } + + private IHoldsOptions getHolderSuperClass(IHoldsOptions holder){ + if(holder instanceof ITool) + return ((ITool)holder).getSuperClass(); + else if(holder instanceof IToolChain) + return ((IToolChain)holder).getSuperClass(); + return null; + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/CompositeExpression.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/CompositeExpression.java index 4f04ded55d0..a327a94b198 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/CompositeExpression.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/CompositeExpression.java @@ -46,6 +46,8 @@ public abstract class CompositeExpression implements IBooleanExpression { return new CheckStringExpression(element); else if(FalseExpression.NAME.equals(name)) return new FalseExpression(element); + else if(CheckHolderExpression.NAME.equals(name)) + return new CheckHolderExpression(element); return null; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/OptionEnablementExpression.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/OptionEnablementExpression.java index d7f5582762f..0e10a7708ef 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/OptionEnablementExpression.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/enablement/OptionEnablementExpression.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.managedbuilder.internal.enablement; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; @@ -25,21 +26,55 @@ public class OptionEnablementExpression extends AndExpression{ public static final String TYPE_UI_VISIBILITY = "UI_VISIBILITY"; //$NON-NLS-1$ public static final String TYPE_UI_ENABLEMENT = "UI_ENABLEMENT"; //$NON-NLS-1$ public static final String TYPE_CMD_USAGE = "CMD_USAGE"; //$NON-NLS-1$ + public static final String TYPE_CONTAINER_ATTRIBUTE = "CONTAINER_ATTRIBUTE"; //$NON-NLS-1$ public static final String TYPE_ALL = "ALL"; //$NON-NLS-1$ public static final String FLAG_DELIMITER = "|"; //$NON-NLS-1$ + public static final String ATTRIBUTE = "attribute"; //$NON-NLS-1$ + public static final String VALUE = "value"; //$NON-NLS-1$ + + private static final String fSupportedAttributes[] = { + IOption.COMMAND, + IOption.COMMAND_FALSE, + }; + public static final int FLAG_UI_VISIBILITY = 0x01; public static final int FLAG_UI_ENABLEMENT = 0x02; public static final int FLAG_CMD_USAGE = 0x04; + public static final int FLAG_CONTAINER_ATTRIBUTE = 0x08; public static final int FLAG_ALL = ~0; private int fEnablementFlags; + private String fAttribute; + private String fValue; public OptionEnablementExpression(IManagedConfigElement element) { super(element); fEnablementFlags = calculateFlags(element.getAttribute(TYPE)); + + fAttribute = element.getAttribute(ATTRIBUTE); + fValue = element.getAttribute(VALUE); + adjustAttributeSupport(); + } + + private void adjustAttributeSupport(){ + boolean cleanAttrFlag = true; + if(fAttribute != null && fValue != null){ + for(int i = 0; i < fSupportedAttributes.length; i++){ + if(fAttribute.equals(fSupportedAttributes[i])){ + cleanAttrFlag = false; + break; + } + } + } + + if(cleanAttrFlag){ + fEnablementFlags &= ~FLAG_CONTAINER_ATTRIBUTE; + fAttribute = null; + fValue = null; + } } public String[] convertToList(String value, String delimiter){ @@ -80,6 +115,8 @@ public class OptionEnablementExpression extends AndExpression{ flags |= FLAG_UI_ENABLEMENT; else if(TYPE_CMD_USAGE.equals(str)) flags |= FLAG_CMD_USAGE; + else if(TYPE_CONTAINER_ATTRIBUTE.equals(str)) + flags |= FLAG_CONTAINER_ATTRIBUTE; else if(TYPE_ALL.equals(str)) flags |= FLAG_ALL; } @@ -94,11 +131,18 @@ public class OptionEnablementExpression extends AndExpression{ IHoldsOptions holder, IOption option, int flags){ - if(!checkFlags(flags) || evaluate(configuration, holder, option)) - return true; - return false; + return evaluate(configuration, holder, option, flags, (FLAG_CONTAINER_ATTRIBUTE & flags) == 0); } - + + public boolean evaluate(IBuildObject configuration, + IHoldsOptions holder, + IOption option, + int flags, + boolean bDefault){ + return checkFlags(flags) ? evaluate(configuration, holder, option) + : bDefault; + } + /* public boolean evaluate(IBuildObject configuration, IHoldsOptions holder, IOption option) { @@ -114,4 +158,25 @@ public class OptionEnablementExpression extends AndExpression{ public int getFlags(){ return fEnablementFlags; } + + public boolean performAdjustment(IBuildObject configuration, + IHoldsOptions holder, + IOption option){ + if(evaluate(configuration,holder,option,FLAG_CONTAINER_ATTRIBUTE)){ + try{ + if(IOption.COMMAND.equals(fAttribute)){ + IOption setOption = holder.getOptionToSet(option, true); + setOption.setCommand(fValue); + }else if(IOption.COMMAND_FALSE.equals(fAttribute)){ + IOption setOption = holder.getOptionToSet(option, true); + setOption.setCommandFalse(fValue); + }else + return false; + }catch (BuildException e){ + return false; + } + return true; + } + return false; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolSettingsPreferenceStore.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolSettingsPreferenceStore.java index 87c2d9c13b9..ae95b4f1ad1 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolSettingsPreferenceStore.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildToolSettingsPreferenceStore.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; +import org.eclipse.cdt.managedbuilder.internal.core.Option; import org.eclipse.cdt.managedbuilder.internal.core.Tool; import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacroProvider; import org.eclipse.cdt.managedbuilder.internal.macros.DefaultMacroSubstitutor; @@ -120,11 +121,12 @@ public class BuildToolSettingsPreferenceStore implements IPreferenceStore { } private static IOption getExtensionOption(IOption option){ - do { - if(option.isExtensionElement()) - return option; - } while ((option = option.getSuperClass()) != null); - return null; + for(;option != null && (!option.isExtensionElement() + || ((Option)option).isAdjustedExtension() + || ((Option)option).wasOptRef()); + option = option.getSuperClass()){} + + return option; } public void addPropertyChangeListener(IPropertyChangeListener listener) { @@ -269,7 +271,7 @@ public class BuildToolSettingsPreferenceStore implements IPreferenceStore { IOption option = (IOption)options[i][1]; if(option.getId().equals(name) - || (!option.isExtensionElement() + || ((!option.isExtensionElement() || ((Option)option).isAdjustedExtension() || ((Option)option).wasOptRef()) && option.getSuperClass() != null && option.getSuperClass().getId().equals(name))) return options[i];