@@ -144,6 +144,7 @@ private static <T> T createInstance(Class<? extends T> clazz) {
144
144
* If there is already a an instance, the call is ignored.
145
145
* @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise.
146
146
* @throws BundleException Throws exception in case the setup failed.
147
+ * @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead.
147
148
*/
148
149
public synchronized static boolean setup () throws BundleException {
149
150
return setup (plugins -> plugins .applyDefault ());
@@ -156,6 +157,7 @@ public synchronized static boolean setup() throws BundleException {
156
157
* @param plugins Eclipse plugins (which are also OSGi bundles) to start
157
158
* @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise.
158
159
* @throws BundleException Throws exception in case the setup failed.
160
+ * @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead.
159
161
*/
160
162
public synchronized static boolean setup (Consumer <SpotlessEclipsePluginConfig > plugins ) throws BundleException {
161
163
return setup (config -> config .applyDefault (), plugins );
@@ -168,6 +170,7 @@ public synchronized static boolean setup(Consumer<SpotlessEclipsePluginConfig> p
168
170
* @param plugins Eclipse plugins (which are also OSGi bundles) to start
169
171
* @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise.
170
172
* @throws BundleException Throws exception in case the setup failed.
173
+ * @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead.
171
174
*/
172
175
public synchronized static boolean setup (Consumer <SpotlessEclipseServiceConfig > config , Consumer <SpotlessEclipsePluginConfig > plugins ) throws BundleException {
173
176
return setup (core -> core .applyDefault (), config , plugins );
@@ -177,76 +180,98 @@ public synchronized static boolean setup(Consumer<SpotlessEclipseServiceConfig>
177
180
* Creates and configures a new {@link SpotlessEclipseFramework} if there is none.
178
181
* If there is already a an instance, the call is ignored.
179
182
* @param core Activators of core bundles
180
- * @param config Framework service configuration
183
+ * @param services Framework service configuration
181
184
* @param plugins Eclipse plugins to start
182
185
* @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise.
183
186
* @throws BundleException Throws exception in case the setup failed.
187
+ * @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead.
184
188
*/
185
- public synchronized static boolean setup (Consumer <SpotlessEclipseCoreConfig > core , Consumer <SpotlessEclipseServiceConfig > config , Consumer <SpotlessEclipsePluginConfig > plugins ) throws BundleException {
189
+ public synchronized static boolean setup (Consumer <SpotlessEclipseCoreConfig > core , Consumer <SpotlessEclipseServiceConfig > services , Consumer <SpotlessEclipsePluginConfig > plugins ) throws BundleException {
186
190
if (null != INSTANCE ) {
187
191
return false ;
188
192
}
193
+ setup (new SpotlessEclipseConfig () {
194
+ @ Override
195
+ public void registerBundles (SpotlessEclipseCoreConfig config ) {
196
+ core .accept (config );
197
+ }
198
+
199
+ @ Override
200
+ public void registerServices (SpotlessEclipseServiceConfig config ) {
201
+ services .accept (config );
202
+ }
189
203
190
- SpotlessEclipseCoreConfig coreConfig = new SpotlessEclipseCoreConfig ();
191
- core .accept (coreConfig );
204
+ @ Override
205
+ public void activatePlugins (SpotlessEclipsePluginConfig config ) {
206
+ plugins .accept (config );
207
+ }
208
+ });
209
+ return true ;
210
+ }
192
211
193
- INSTANCE = new SpotlessEclipseFramework (coreConfig );
194
- config .accept (INSTANCE .getServiceConfig ());
212
+ /**
213
+ * Creates and configures a new {@link SpotlessEclipseFramework} if there is none.
214
+ * If there is already a an instance, the call is ignored.
215
+ * @param config Configuration
216
+ * @throws BundleException Throws exception in case the setup failed.
217
+ */
218
+ public synchronized static void setup (SpotlessEclipseConfig config ) throws BundleException {
219
+ if (null == INSTANCE ) {
220
+ INSTANCE = new SpotlessEclipseFramework ();
221
+ config .registerServices (INSTANCE .getServiceConfig ());
222
+
223
+ SpotlessEclipseCoreConfig coreConfig = new SpotlessEclipseCoreConfig ();
224
+ config .registerBundles (coreConfig );
225
+ INSTANCE .startCoreBundles (coreConfig );
226
+
227
+ SpotlessEclipsePluginConfig pluginConfig = new SpotlessEclipsePluginConfig ();
228
+ config .activatePlugins (pluginConfig );
229
+ for (Class <?> extension : pluginConfig .getExtensions ()) {
230
+ INSTANCE .addExtension (extension );
231
+ }
232
+ for (BundleConfig .Entry plugin : pluginConfig .get ()) {
233
+ INSTANCE .addPlugin (plugin .state , plugin .activator );
234
+ }
195
235
196
- SpotlessEclipsePluginConfig pluginConfig = new SpotlessEclipsePluginConfig ();
197
- plugins .accept (pluginConfig );
198
- for (BundleConfig .Entry plugin : pluginConfig .get ()) {
199
- INSTANCE .addPlugin (plugin .state , plugin .activator );
236
+ config .customize ();
200
237
}
201
- return true ;
202
238
}
203
239
204
240
private final Function <Bundle , BundleException > registry ;
205
241
private final BundleController controller ;
206
- private final SpotlessEclipseCoreConfig coreConfig ;
207
- private boolean coreConfigStarted ;
208
242
209
- private SpotlessEclipseFramework (SpotlessEclipseCoreConfig coreConfig ) throws BundleException {
243
+ private SpotlessEclipseFramework () throws BundleException {
210
244
211
245
controller = new BundleController ();
212
246
registry = (pluginBundle ) -> {
213
247
return PluginRegistrar .register (pluginBundle );
214
248
};
215
-
216
- this .coreConfig = coreConfig ;
217
- coreConfigStarted = false ;
218
249
}
219
250
220
- /** Get framework service configuration */
221
251
private SpotlessEclipseServiceConfig getServiceConfig () {
222
252
return controller .getServices ();
223
253
}
224
254
225
- /** Add a plugin to the framework. */
255
+ private void addExtension (Class <?> clazzInBundleJar ) throws BundleException {
256
+ controller .addBundle (clazzInBundleJar , registry );
257
+ }
258
+
226
259
private void addPlugin (int state , BundleActivator plugin ) throws BundleException {
227
- if (!coreConfigStarted ) {
228
- //The SAXParserFactory.class is required for parsing the plugin XML files
229
- addMandatoryServiceIfMissing (SAXParserFactory .class , SAXParserFactory .newInstance ());
230
- /*
231
- * Since org.eclipse.core.runtime version 3.15.300, the Eclipse bundle look-up is accomplished
232
- * via the wiring framework, which requires a stat of the InternalPlatform.
233
- * The internal platform initialization is customized by the services
234
- * registered to the controller.
235
- */
236
- InternalPlatform .getDefault ().start (controller );
237
- startFrameworkBundles ();
238
- coreConfigStarted = true ;
239
- }
240
260
controller .addBundle (state , plugin , registry );
241
261
}
242
262
243
- private <S > void addMandatoryServiceIfMissing (Class <S > interfaceClass , S service ) {
244
- if (null == controller .getServiceReference (interfaceClass )) {
245
- controller .getServices ().add (interfaceClass , service );
246
- }
247
- }
263
+ private void startCoreBundles (SpotlessEclipseCoreConfig coreConfig ) throws BundleException {
264
+ //The SAXParserFactory.class is required for parsing the plugin XML files
265
+ addMandatoryServiceIfMissing (SAXParserFactory .class , SAXParserFactory .newInstance ());
266
+
267
+ /*
268
+ * Since org.eclipse.core.runtime version 3.15.300, the Eclipse bundle look-up is accomplished
269
+ * via the wiring framework, which requires starting the InternalPlatform.
270
+ * The internal platform initialization is customized by the services
271
+ * registered to the controller.
272
+ */
273
+ InternalPlatform .getDefault ().start (controller );
248
274
249
- private void startFrameworkBundles () throws BundleException {
250
275
for (BundleConfig .Entry coreBundle : coreConfig .get ()) {
251
276
try {
252
277
BundleContext context = controller .createContext (coreBundle .state );
@@ -257,4 +282,9 @@ private void startFrameworkBundles() throws BundleException {
257
282
}
258
283
}
259
284
285
+ private <S > void addMandatoryServiceIfMissing (Class <S > interfaceClass , S service ) {
286
+ if (null == controller .getServiceReference (interfaceClass )) {
287
+ controller .getServices ().add (interfaceClass , service );
288
+ }
289
+ }
260
290
}
0 commit comments