From a973860091ebf543cb9aa9ab89f6b0d11ae75635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norbert=20Pl=F6tt?= Date: Tue, 12 Sep 2006 06:16:41 +0000 Subject: [PATCH] Fixing https:bug #156187 (PathEntry framework should handle cygwin style paths on Windows) --- .../plugin.xml | 165 +++++++++++++++++ .../tests/suite/AllManagedBuildTests.java | 2 + .../core/tests/PathConverterTest.java | 170 ++++++++++++++++++ .../core/tests/TestPathConverter1.java | 33 ++++ .../core/tests/TestPathConverter2.java | 16 ++ .../core/tests/TestPathConverter3.java | 16 ++ .../core/tests/TestPathConverter4.java | 37 ++++ .../schema/buildDefinitions.exsd | 22 +++ .../core/IOptionPathConverter.java | 31 ++++ .../cdt/managedbuilder/core/ITool.java | 9 +- .../cdt/managedbuilder/core/IToolChain.java | 8 +- .../internal/core/ManagedBuildInfo.java | 22 +++ .../managedbuilder/internal/core/Tool.java | 76 +++++++- .../internal/core/ToolChain.java | 60 ++++++- .../internal/core/ToolReference.java | 13 ++ .../ui/tests/util/TestToolchain.java | 11 ++ 16 files changed, 686 insertions(+), 5 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/PathConverterTest.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter1.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter2.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter3.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter4.java create mode 100644 build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionPathConverter.java diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml index eee8f087cbb..fc44c5086c8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/plugin.xml @@ -6308,4 +6308,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 8a33c4ba3ee..72cd5f1d282 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 @@ -29,6 +29,7 @@ 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.PathConverterTest; import org.eclipse.cdt.managedbuilder.core.tests.ResourceBuildCoreTests; /** @@ -63,6 +64,7 @@ public class AllManagedBuildTests { suite.addTest(OptionEnablementTests.suite()); suite.addTest(ManagedBuildDependencyCalculatorTests.suite()); suite.addTest(BuildDescriptionModelTests.suite()); + suite.addTest(PathConverterTest.suite()); //$JUnit-END$ return suite; } diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/PathConverterTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/PathConverterTest.java new file mode 100644 index 00000000000..a2ccf8cb0d9 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/PathConverterTest.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * Copyright (C) 2006 Siemens AG. + * 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 + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.core.tests; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.core.model.IncludeEntry; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter; +import org.eclipse.cdt.managedbuilder.core.IProjectType; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.IPath; + +/** + * This is a test for the pathConverter attribute + * which may be specified for a tool or toolchain + * The manifest has an extra buildDefinitions section + * with a dedicated project type "pathconvertertest.projecttype" + * to support these tests. + * @author pn3484 + * + */ +public class PathConverterTest extends TestCase { + + + public PathConverterTest(String name) { + super(name); + } + + + public static Test suite() { + TestSuite suite = new TestSuite(PathConverterTest.class.getName()); + suite.addTest(new PathConverterTest("testPathConversionInProject")); + suite.addTest(new PathConverterTest("testPathConverterConfigurations")); + return suite; + } + + + /** + * The expected converter can be determined from the configuration's id string. + * The id string has a toolchain part "tc<d><i>" and a tool part "to<d><i>".
+ *
+ * Where <d> stands for whether a converter is directly specified:
+ * 'n' : No converter specified
+ * 'y' : Converter of type TestPathConverter2 specified
+ *
+ * and <i> stands for whether a converter is inherited from the superclass.
+ * 'n' : Converter is not inherited
+ * 'y' : Converter is directly specified
+ *
+ * Inherited converters are always TestPathConverter1 type.
+ *
+ * The test setup in the manifest file tests the follwing precedence order:
+ * - A converter set directly on the tool overrides an inherited tool converter
+ * - An inherited converter overrides any toolchain converters
+ * - A converter set directly on the toolchain overrides an inherited toolchain converter
+ */ + protected Class getExpectedToolConverterClass(String configId) { + // Conservative defaults + boolean hasToolConverter = false ; + boolean hasToolInheritedConverter = false ; + // Analyze tool information + int toolInfoAt = configId.indexOf("to"); + String toolinfo = configId.substring(toolInfoAt+2, toolInfoAt+4); + hasToolConverter = (toolinfo.charAt(0)=='y'); + hasToolInheritedConverter = (toolinfo.charAt(1)=='y'); + // Assume no converter + Class toolConverterClass = getExpectedToolchainConverterClass(configId) ; + // Modify converter as appropriate + if (hasToolInheritedConverter) toolConverterClass = TestPathConverter2.class ; + if (hasToolConverter) toolConverterClass = TestPathConverter4.class ; + + return toolConverterClass ; + } + + /** + * @see getExpectedToolConverterClass() + */ + protected Class getExpectedToolchainConverterClass(String configId) { + // Conservative defaults + boolean hasToolchainConverter = false ; + boolean hasToolchainInheritedConverter = false ; + // Analyze toolchain information + int toolchainInfoAt = configId.indexOf("tc"); + String toolchaininfo = configId.substring(toolchainInfoAt+2, toolchainInfoAt+4); + hasToolchainConverter = (toolchaininfo.charAt(0)=='y'); + hasToolchainInheritedConverter = (toolchaininfo.charAt(1)=='y'); + // Assume no converter + Class toolConverterClass = null ; + // Modify converter as appropriate + if (hasToolchainInheritedConverter) toolConverterClass = TestPathConverter1.class ; + if (hasToolchainConverter) toolConverterClass = TestPathConverter3.class ; + + return toolConverterClass ; + } + + /** + * Check the converter settings for some key configurations + */ + public void testPathConverterConfigurations() { + IProjectType[] projTypes = ManagedBuildManager.getDefinedProjectTypes(); + assertNotNull("Project types were not loaded!", projTypes); + IProjectType projType = ManagedBuildManager.getProjectType("pathconvertertest.projecttype"); + assertNotNull("Projecttype should have been loaded!", projType); + + IConfiguration[] configurations = projType.getConfigurations(); + assertTrue("There should be some configurations!", configurations.length>0); + + // Check all configurations + for (int i = 0; i < configurations.length; i++) { + IConfiguration configuration = configurations[i]; + IToolChain toolchain = configuration.getToolChain(); + + Class expectedToolchainConverterClass = getExpectedToolchainConverterClass(configuration.getId()); + IOptionPathConverter toolchainPathConverter = toolchain.getOptionPathConverter(); + if (null==expectedToolchainConverterClass) { + assertNull("null pathConverter expected for toolchain!", toolchainPathConverter); + } else { + assertEquals("Unexpected pathConverter type for toolchain", expectedToolchainConverterClass, toolchainPathConverter.getClass()); + } + + + ITool tool = toolchain.getTools()[0]; // We have only one tool in the test setup + Class expectedToolConverterClass = getExpectedToolConverterClass(configuration.getId()); + IOptionPathConverter toolPathConverter = tool.getOptionPathConverter(); + if (null==expectedToolConverterClass) { + assertNull("null pathConverter expected for tool!", toolPathConverter); + } else { + assertEquals("Unexpected pathConverter type for tool", expectedToolConverterClass, toolPathConverter.getClass()); + } + } + } + + /** + * Check the path conversion in live project for a specific tool. + */ + public void testPathConversionInProject() throws Exception { + IProjectType type = ManagedBuildManager.getProjectType("pathconvertertest.projecttype"); + IWorkspaceRoot root = null ; + IProject project = ManagedBuildTestHelper.createProject("pathconverter01", type.getId()); + IManagedBuildInfo iinfo = ManagedBuildManager.getBuildInfo(project); + assertNotNull("build info could not be obtained", iinfo); + ManagedBuildInfo info = (ManagedBuildInfo) iinfo ; + boolean isConfigurationSet = info.setDefaultConfiguration("config toolchain-yy, tool-yy"); + assertTrue("Configuration could not be set", isConfigurationSet); + + IPathEntry[] pathEntries = info.getManagedBuildValues(); + assertEquals("Unexpected number of path entries", 1, pathEntries.length); + IncludeEntry entry = (IncludeEntry) pathEntries[0]; + IPath path = entry.getIncludePath(); + String pathText = path.toString() ; + assertEquals("Unexpected value for include path", "/usr/local/include", pathText); + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter1.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter1.java new file mode 100644 index 00000000000..e0887e540ae --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter1.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (C) 2006 Siemens AG. + * 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 + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.core.tests; + +import org.eclipse.cdt.managedbuilder.core.IOption; +import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +/** + * This minimalistic testing implementation does not actually change the path + * It just converts to an IPath object + * TestPathConverter1 is the converter which can be inherited from the toolchain + */ +public class TestPathConverter1 implements IOptionPathConverter { + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOptionPathConverter#convertToPlatformLocation(java.lang.String) + */ + public IPath convertToPlatformLocation(String toolSpecificPath, IOption option, ITool tool) { + Path path = new Path(toolSpecificPath); + return path ; + } + +} + diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter2.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter2.java new file mode 100644 index 00000000000..58b2fe6665a --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter2.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (C) 2006 Siemens AG. + * 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 + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.core.tests; + +/** + * TestpathConverter2 can be inherited from the pathconvertertest.convertingtool + */ +public class TestPathConverter2 extends TestPathConverter1 { + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter3.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter3.java new file mode 100644 index 00000000000..ef206315222 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter3.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (C) 2006 Siemens AG. + * 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 + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.core.tests; + +/** + * TestPathConverter3 is set on toolchains in several configurations + */ +public class TestPathConverter3 extends TestPathConverter1 { + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter4.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter4.java new file mode 100644 index 00000000000..3c4d16f60b9 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/TestPathConverter4.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (C) 2006 Siemens AG. + * 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 + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.core.tests; + +import org.eclipse.cdt.managedbuilder.core.IOption; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +/** + * This path converter will be used to test that a conversion actually takes place. + * It is referenced from the tool pathconvertertest.config.tcyy.toyy.toolchain.tool + * in the test projecttype.
+ * The tool pathconvertertest.config.tcyy.toyy.toolchain.tool inherits a path option + * from the pathconvertertest.convertingtool tool. The include path option has the + * intentionally strange value file:///usr/local/include. + * The "file://" part gets stripped away to satisfy the test. + */ +public class TestPathConverter4 extends TestPathConverter1 { + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.tests.TestPathConverter1#convertToPlatformLocation(java.lang.String) + */ + public IPath convertToPlatformLocation(String toolSpecificPath, IOption option, ITool tool) { + String convertedString = toolSpecificPath.substring("file://".length()); + IPath path = new Path(convertedString); + return path ; + } + + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd index 4b659291571..9a2e6c25398 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd +++ b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd @@ -423,6 +423,18 @@ + + + + Toolchains like Cygwin based Gnu tools can accept paths which are not valid for the OS platform. E.g. "/usr/include" is well difined for a Cygwin gcc compiler while it is not a meaningful path for a java.io.File. Therefore toolchains can specify a pathConverter which will be applied to include and library paths configured in the Managed Build System. + +The pathConverter of a toolchain applies for all tools of the toolchain except if a tool defines it's own pathConverter. In this case the pathConverter supplied by the toolchain is ignored. + + + + + + @@ -691,6 +703,16 @@ + + + + Tools like Cygwin based Gnu tools can accept paths which are not valid for the OS platform. E.g. "/usr/include" is well difined for a Cygwin gcc compiler while it is not a meaningful path for a java.io.File. Therefore tools can specify a pathConverter which will be applied to include and library paths configured in the Managed Build System. + + + + + + diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionPathConverter.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionPathConverter.java new file mode 100644 index 00000000000..8463616cab4 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOptionPathConverter.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (C) 2006 Siemens AG. + * 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 + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.core; + +import org.eclipse.core.runtime.IPath; + +/** + * An IOptionPathConverter converts between tool-specific paths + * and their platform locations + */ +public interface IOptionPathConverter { + + /** + * Convert from a tool specific path to a platform location, e.g. + * "/usr/include" for a Cygwin tool gets converted to + * "c:\\cygwin\\usr\\include" + * @param toolSpecificPath The string representation of the tool-specific path + * @param option TODO + * @param tool TODO + * @return A path which is a meaningful platform location + * or null, if the conversion fails. + */ + IPath convertToPlatformLocation(String toolSpecificPath, IOption option, ITool tool); + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java index aeb51258ebd..33590d6aba3 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java @@ -46,7 +46,8 @@ public interface ITool extends IBuildObject, IHoldsOptions { public static final String VERSIONS_SUPPORTED = "versionsSupported"; //$NON-NLS-1$ public static final String CONVERT_TO_ID = "convertToId"; //$NON-NLS-1$ - + public static final String OPTIONPATHCONVERTER = "optionPathConverter"; //$NON-NLS-1$ + public static final int FILTER_C = 0; public static final int FILTER_CC = 1; public static final int FILTER_BOTH = 2; @@ -723,4 +724,10 @@ public interface ITool extends IBuildObject, IHoldsOptions { * @return IEnvVarBuildPath[] */ public IEnvVarBuildPath[] getEnvVarBuildPaths(); + + /** + * Returns an IOptionPathConverter implementation for this tool + * or null, if no conversion is required + */ + public IOptionPathConverter getOptionPathConverter() ; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java index efe04cae754..519ceafccae 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 Intel Corporation and others. + * Copyright (c) 2004, 2005, 2006 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 @@ -376,4 +376,10 @@ public interface IToolChain extends IBuildObject, IHoldsOptions { * @return IConfigurationBuildMacroSupplier */ public IConfigurationBuildMacroSupplier getBuildMacroSupplier(); + + /** + * Returns an IOptionPathConverter implementation for this toolchain + * or null, if no conversion is required + */ + public IOptionPathConverter getOptionPathConverter() ; } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java index b7c65c826bb..e8d5a0216b9 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java @@ -32,12 +32,15 @@ import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IBuilder; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator; import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo; +import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; +import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITarget; import org.eclipse.cdt.managedbuilder.core.ITool; @@ -1143,6 +1146,17 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { String paths[] = ManagedBuildManager.getBuildMacroProvider().resolveStringListValue(path, EMPTY, " ", context, obj); //$NON-NLS-1$ if (paths != null) { for(int i = 0; i < paths.length; i++){ + // Check for registered path converter + if (obj instanceof OptionContextData) { + OptionContextData optionContext = (OptionContextData) obj; + IBuildObject buildObject = optionContext.getParent() ; + IOptionPathConverter optionPathConverter = getPathConverter(buildObject); + if (null!=optionPathConverter) { + IPath platformPath = optionPathConverter + .convertToPlatformLocation(paths[i], null, null); + paths[i] = platformPath.toOSString(); + } + } list.add(checkPath(paths[i])); } } @@ -1155,6 +1169,14 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo { return list; } + private IOptionPathConverter getPathConverter(IBuildObject buildObject) { + IOptionPathConverter converter = null ; + if (buildObject instanceof ITool) { + ITool tool = (ITool) buildObject; + converter = tool.getOptionPathConverter() ; + } + return converter ; + } private String checkPath(String p){ final String QUOTE = "\""; //$NON-NLS-1$ final String EMPTY = ""; //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java index 29be346b3e3..cfa10f1ae16 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java @@ -35,6 +35,7 @@ import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionApplicability; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IOutputType; +import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter; import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; @@ -122,7 +123,9 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { private IManagedCommandLineGenerator commandLineGenerator = null; private IConfigurationElement dependencyGeneratorElement = null; private IManagedDependencyGeneratorType dependencyGenerator = null; - private URL iconPathURL; + private URL iconPathURL; + private IConfigurationElement pathconverterElement = null ; + private IOptionPathConverter optionPathConverter = null ; // Miscellaneous private boolean isExtensionTool = false; private boolean isDirty = false; @@ -383,7 +386,9 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { commandLineGenerator = tool.commandLineGenerator; dependencyGeneratorElement = tool.dependencyGeneratorElement; dependencyGenerator = tool.dependencyGenerator; - + pathconverterElement = tool.pathconverterElement ; + optionPathConverter = tool.optionPathConverter ; + if(tool.envVarBuildPathList != null) envVarBuildPathList = new ArrayList(tool.envVarBuildPathList); @@ -559,6 +564,12 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { String icon = element.getAttribute(IOptionCategory.ICON); iconPathURL = ManagedBuildManager.getURLInBuildDefinitions( (DefaultManagedConfigElement)element, new Path(icon) ); } + + // optionPathConverter + String pathconverterTypeName = element.getAttribute(ITool.OPTIONPATHCONVERTER); + if (pathconverterTypeName != null && element instanceof DefaultManagedConfigElement) { + pathconverterElement = ((DefaultManagedConfigElement)element).getConfigurationElement(); + } } /* (non-Javadoc) @@ -718,6 +729,7 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { iconPathURL = null; } } + } /** @@ -882,6 +894,12 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { element.setAttribute(IOptionCategory.ICON, iconPathURL.toString()); } + // Note: optionPathConverter cannot be specified in a project file because + // an IConfigurationElement is needed to load it! + if (pathconverterElement != null) { + // TODO: issue warning? + } + saveRebuildState(); // I am clean now @@ -2347,7 +2365,61 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory { } return false; } + + + /** + * @return the pathconverterElement + */ + public IConfigurationElement getPathconverterElement() { + return pathconverterElement; + } + + public IOptionPathConverter getOptionPathConverter() { + // Use existing converter + if (optionPathConverter != null) { + return optionPathConverter ; + } + if (optionPathConverter==null) { + // If there is not yet a optionPathConverter try to construct from configuration element + IConfigurationElement element = getPathconverterElement(); + if (element != null) { + try { + if (element.getAttribute(ITool.OPTIONPATHCONVERTER) != null) { + optionPathConverter = (IOptionPathConverter) element + .createExecutableExtension(ITool.OPTIONPATHCONVERTER); + } + } catch (CoreException e) { + } + } + if (optionPathConverter==null) { + // If there is still no optionPathConverter, ask superclass of this tool whether it has a converter + if (getSuperClass() instanceof ITool) { + ITool superTool = (ITool) getSuperClass(); + optionPathConverter = superTool.getOptionPathConverter(); + } + } + // If there is still no converter, ask the toolchain for a + // global converter + if ((optionPathConverter==null)&&(getParent() instanceof IResourceConfiguration)) { + // The tool belongs to a resource configuration + IResourceConfiguration resourceConfiguration = (IResourceConfiguration) getParent(); + IConfiguration configuration = resourceConfiguration.getParent(); + if (null!=configuration) { + IToolChain toolchain = configuration.getToolChain(); + optionPathConverter = toolchain.getOptionPathConverter(); + } + } + if ((optionPathConverter==null)&&(getParent() instanceof IToolChain)) { + // The tool belongs to a toolchain + IToolChain toolchain = (IToolChain) getParent(); + optionPathConverter = toolchain.getOptionPathConverter(); + } + } + return optionPathConverter ; + } + + /* * O B J E C T S T A T E M A I N T E N A N C E */ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java index 83b6cb3a2f6..e3335f74ca7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java @@ -26,6 +26,7 @@ import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.eclipse.cdt.managedbuilder.core.IManagedIsToolChainSupported; import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.managedbuilder.core.IOutputType; +import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter; import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.ITargetPlatform; import org.eclipse.cdt.managedbuilder.core.ITool; @@ -83,6 +84,8 @@ public class ToolChain extends HoldsOptions implements IToolChain { private IConfigurationEnvironmentVariableSupplier environmentVariableSupplier = null; private IConfigurationElement buildMacroSupplierElement = null; private IConfigurationBuildMacroSupplier buildMacroSupplier = null; + private IConfigurationElement pathconverterElement = null ; + private IOptionPathConverter optionPathConverter = null ; // Miscellaneous private boolean isExtensionToolChain = false; @@ -309,6 +312,9 @@ public class ToolChain extends HoldsOptions implements IToolChain { buildMacroSupplierElement = toolChain.buildMacroSupplierElement; buildMacroSupplier = toolChain.buildMacroSupplier; + pathconverterElement = toolChain.pathconverterElement ; + optionPathConverter = toolChain.optionPathConverter ; + // Clone the children in superclass super.copyChildren(toolChain); // Clone the children @@ -466,6 +472,11 @@ public class ToolChain extends HoldsOptions implements IToolChain { buildMacroSupplierElement = ((DefaultManagedConfigElement)element).getConfigurationElement(); } + // optionPathConverter + String pathconverterTypeName = element.getAttribute(ITool.OPTIONPATHCONVERTER); + if (pathconverterTypeName != null && element instanceof DefaultManagedConfigElement) { + pathconverterElement = ((DefaultManagedConfigElement)element).getConfigurationElement(); + } } @@ -562,6 +573,14 @@ public class ToolChain extends HoldsOptions implements IToolChain { } } } + + // Note: optionPathConverter cannot be specified in a project file because + // an IConfigurationElement is needed to load it! + if (pathconverterElement != null) { + // TODO: issue warning? + } + + } /** @@ -689,6 +708,12 @@ public class ToolChain extends HoldsOptions implements IToolChain { userDefinedMacros.serialize(doc,macrosElement); } + // Note: optionPathConverter cannot be specified in a project file because + // an IConfigurationElement is needed to load it! + if (pathconverterElement != null) { + // TODO: issue warning? + } + if(userDefinedEnvironment != null) EnvironmentVariableProvider.fUserSupplier.storeEnvironment(getParent(),true); @@ -1240,7 +1265,40 @@ public class ToolChain extends HoldsOptions implements IToolChain { setDirty(true); } } - + + /** + * @return the pathconverterElement + */ + public IConfigurationElement getPathconverterElement() { + return pathconverterElement; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getPathConverter() + */ + public IOptionPathConverter getOptionPathConverter() { + if (optionPathConverter != null) { + return optionPathConverter ; + } + IConfigurationElement element = getPathconverterElement(); + if (element != null) { + try { + if (element.getAttribute(ITool.OPTIONPATHCONVERTER) != null) { + optionPathConverter = (IOptionPathConverter) element.createExecutableExtension(ITool.OPTIONPATHCONVERTER); + return optionPathConverter; + } + } catch (CoreException e) {} + } else { + if (getSuperClass() instanceof IToolChain) { + IToolChain superTool = (IToolChain) getSuperClass(); + return superTool.getOptionPathConverter() ; + } + } + return null ; + } + + + /* * O B J E C T S T A T E M A I N T E N A N C E */ 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 f3e9eaa2f7b..44c91b81adc 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 @@ -26,6 +26,7 @@ import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.eclipse.cdt.managedbuilder.core.IOption; import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IOutputType; +import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.IToolChain; @@ -1264,4 +1265,16 @@ public class ToolReference implements IToolReference { */ public void setRebuildState(boolean rebuild) { } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.ITool#getPathConverter() + */ + public IOptionPathConverter getOptionPathConverter() { + if (parent!=null) { + return parent.getOptionPathConverter(); + } + return null; + } + + } diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestToolchain.java b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestToolchain.java index 3573ed36e0a..ada012258cf 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestToolchain.java +++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestToolchain.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.managedbuilder.ui.tests.util; import org.eclipse.cdt.managedbuilder.core.IBuilder; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IOutputType; +import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter; import org.eclipse.cdt.managedbuilder.core.ITargetPlatform; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.IToolChain; @@ -263,5 +264,15 @@ public class TestToolchain extends HoldsOptions implements IToolChain { { this.id = id; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getPathConverter() + */ + public IOptionPathConverter getOptionPathConverter() { + // TODO Auto-generated method stub + return null; + } + + }