Skip to content

Commit 978eea5

Browse files
authored
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
1 parent 9c4ace1 commit 978eea5

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationProvider.java

+35-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
import org.eclipse.core.runtime.Platform;
2828

2929
/**
30+
* A ICBuildConfigurationProvider specialized for CMake
31+
*
32+
* Extenders can provide their own specialised CMakeConfiguration by extending this class and {@link CMakeBuildConfiguration}.
33+
* Extenders need to override at least {@link #getId()}, and the various createCMakeBuildConfiguration methods.
34+
* See the example project <a href="https://github.com/eclipse-cdt/cdt/tree/main/cmake/org.eclipse.cdt.cmake.example">
35+
* org.eclipse.cdt.cmake.example</a> for a full example.
36+
*
3037
* @since 1.6
3138
*/
3239
public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProvider {
@@ -41,6 +48,30 @@ public String getId() {
4148
return ID;
4249
}
4350

51+
/**
52+
* Extenders should override this method to construct their specialized build configuration.
53+
*/
54+
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name)
55+
throws CoreException {
56+
return new CMakeBuildConfiguration(config, name);
57+
}
58+
59+
/**
60+
* Extenders should override this method to construct their specialized build configuration.
61+
*/
62+
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
63+
IToolChain toolChain) {
64+
return new CMakeBuildConfiguration(config, name, toolChain);
65+
}
66+
67+
/**
68+
* Extenders should override this method to construct their specialized build configuration.
69+
*/
70+
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
71+
IToolChain toolChain, ICMakeToolChainFile toolChainFile, String launchMode) {
72+
return new CMakeBuildConfiguration(config, name, toolChain, toolChainFile, launchMode);
73+
}
74+
4475
@Override
4576
public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name)
4677
throws CoreException {
@@ -66,13 +97,13 @@ public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfigurat
6697
}
6798

6899
if (toolChain != null) {
69-
return new CMakeBuildConfiguration(config, name, toolChain);
100+
return createCMakeBuildConfiguration(config, name, toolChain);
70101
} else {
71102
// No valid combinations
72103
return null;
73104
}
74105
}
75-
CMakeBuildConfiguration cmakeConfig = new CMakeBuildConfiguration(config, name);
106+
CMakeBuildConfiguration cmakeConfig = createCMakeBuildConfiguration(config, name);
76107
ICMakeToolChainFile tcFile = cmakeConfig.getToolChainFile();
77108
IToolChain toolChain = cmakeConfig.getToolChain();
78109
if (toolChain == null) {
@@ -81,7 +112,7 @@ public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfigurat
81112
}
82113
if (tcFile != null && !toolChain.equals(tcFile.getToolChain())) {
83114
// toolchain changed
84-
return new CMakeBuildConfiguration(config, name, tcFile.getToolChain(), tcFile,
115+
return createCMakeBuildConfiguration(config, name, tcFile.getToolChain(), tcFile,
85116
cmakeConfig.getLaunchMode());
86117
} else {
87118
return cmakeConfig;
@@ -136,7 +167,7 @@ public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChai
136167
config = configManager.createBuildConfiguration(this, project, name, monitor);
137168
}
138169

139-
CMakeBuildConfiguration cmakeConfig = new CMakeBuildConfiguration(config, name, toolChain, file, launchMode);
170+
CMakeBuildConfiguration cmakeConfig = createCMakeBuildConfiguration(config, name, toolChain, file, launchMode);
140171
configManager.addBuildConfiguration(config, cmakeConfig);
141172
return cmakeConfig;
142173
}

0 commit comments

Comments
 (0)