From 978eea5d4248e147637ab8a190085f2111dc0c43 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Thu, 23 Jan 2025 09:20:11 -0500 Subject: [PATCH] Allow the new API for CMakeBuildConfiguration to be extended (#1051) PR #1010 added the ability to extend CMakeBuildConfiguration and CMakeBuildConfigurationProvider by making the classes public API, they used to be internal API. This change makes it easier to reuse the code in the provider and configuration by allowing extenders to provide their own implementations of CMakeBuildConfiguration. This has been achieved by adding createCMakeBuildConfiguration methods to control which CMakeBuildConfiguration is constructed. Follow up to #1010 --- .../core/CMakeBuildConfigurationProvider.java | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationProvider.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationProvider.java index ab2b976a532..3db6183f7bf 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationProvider.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationProvider.java @@ -27,6 +27,13 @@ import org.eclipse.core.runtime.Platform; /** + * A ICBuildConfigurationProvider specialized for CMake + * + * Extenders can provide their own specialised CMakeConfiguration by extending this class and {@link CMakeBuildConfiguration}. + * Extenders need to override at least {@link #getId()}, and the various createCMakeBuildConfiguration methods. + * See the example project + * org.eclipse.cdt.cmake.example for a full example. + * * @since 1.6 */ public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProvider { @@ -41,6 +48,30 @@ public String getId() { return ID; } + /** + * Extenders should override this method to construct their specialized build configuration. + */ + protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name) + throws CoreException { + return new CMakeBuildConfiguration(config, name); + } + + /** + * Extenders should override this method to construct their specialized build configuration. + */ + protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name, + IToolChain toolChain) { + return new CMakeBuildConfiguration(config, name, toolChain); + } + + /** + * Extenders should override this method to construct their specialized build configuration. + */ + protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name, + IToolChain toolChain, ICMakeToolChainFile toolChainFile, String launchMode) { + return new CMakeBuildConfiguration(config, name, toolChain, toolChainFile, launchMode); + } + @Override public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name) throws CoreException { @@ -66,13 +97,13 @@ public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfigurat } if (toolChain != null) { - return new CMakeBuildConfiguration(config, name, toolChain); + return createCMakeBuildConfiguration(config, name, toolChain); } else { // No valid combinations return null; } } - CMakeBuildConfiguration cmakeConfig = new CMakeBuildConfiguration(config, name); + CMakeBuildConfiguration cmakeConfig = createCMakeBuildConfiguration(config, name); ICMakeToolChainFile tcFile = cmakeConfig.getToolChainFile(); IToolChain toolChain = cmakeConfig.getToolChain(); if (toolChain == null) { @@ -81,7 +112,7 @@ public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfigurat } if (tcFile != null && !toolChain.equals(tcFile.getToolChain())) { // toolchain changed - return new CMakeBuildConfiguration(config, name, tcFile.getToolChain(), tcFile, + return createCMakeBuildConfiguration(config, name, tcFile.getToolChain(), tcFile, cmakeConfig.getLaunchMode()); } else { return cmakeConfig; @@ -136,7 +167,7 @@ public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChai config = configManager.createBuildConfiguration(this, project, name, monitor); } - CMakeBuildConfiguration cmakeConfig = new CMakeBuildConfiguration(config, name, toolChain, file, launchMode); + CMakeBuildConfiguration cmakeConfig = createCMakeBuildConfiguration(config, name, toolChain, file, launchMode); configManager.addBuildConfiguration(config, cmakeConfig); return cmakeConfig; }