Skip to content

Commit 1f77549

Browse files
authored
Released eclipse-base 3.3.0 and eclipse-wtp 3.15.2 (#533)
Added support of plugin extensions without activator to eclipse-base. Added configuration via single interface implementation (functional configuration is marked deprecated). Racing conditions in eclipse-wtp fixed. New approach disallows multiple instantiations with different configurations.
1 parent 45d2122 commit 1f77549

File tree

67 files changed

+1185
-1084
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1185
-1084
lines changed

_ext/eclipse-base/CHANGES.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
# spotless-eclipse-base
22

3-
### Version 3.2.1 - September 3rd 2019 ([artifact]([jcenter](https://bintray.com/diffplug/opensource/spotless-eclipse-base)))
3+
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.2.1`).
44

5-
* Fixed deletion of temporary workspace. ([#447](https://github.com/diffplug/spotless/issues/447))
5+
## [Unreleased]
66

7-
### Version 3.2.0 - June 30th 2019 ([artifact]([jcenter](https://bintray.com/diffplug/opensource/spotless-eclipse-base)))
7+
## [3.3.0] - 2020-03-04
8+
### Added
9+
* Added support of plugin extensions without activator ([#533](https://github.com/diffplug/spotless/issues/533)). Required since `org.eclipse.core.filesystem` version `1.7.600` (see
10+
[Bug 550548](https://bugs.eclipse.org/bugs/show_bug.cgi?id=550548))
11+
* Updated configuration via single interface implementation. Functional based configuration still supported.
812

9-
* Added support of Eclipse 4.12 framework wiring. ([#413](https://github.com/diffplug/spotless/issues/413))
13+
## [3.2.1] - 2019-09-03
14+
* Fixed deletion of temporary workspace. ([#447](https://github.com/diffplug/spotless/issues/447))
1015

11-
### Version 3.1.1 - June 4th 2019 ([artifact]([jcenter](https://bintray.com/diffplug/opensource/spotless-eclipse-base)))
16+
## [3.2.0] - 2019-06-30
17+
* Added support of Eclipse 4.12 framework wiring. ([#413](https://github.com/diffplug/spotless/issues/413))
1218

19+
## [3.1.1] - 2019-06-04
1320
* Fixed problem handling URL escaped characters in JAR file location. ([#401](https://github.com/diffplug/spotless/issues/401))
1421

15-
### Version 3.1.0 - February 10th 2019 ([artifact]([jcenter](https://bintray.com/diffplug/opensource/spotless-eclipse-base)))
16-
22+
## [3.1.0] - 2019-02-10
1723
* Added logging service based on SLF4J. ([#236](https://github.com/diffplug/spotless/issues/236))
1824
* Updated internal interfaces to support `org.eclipse.osgi` version 3.13.
1925
* Corrected documentation of version number usage in `gradle.properties`.
2026

21-
### Version 3.0.0 - July 18th 2018 ([artifact]([jcenter](https://bintray.com/diffplug/opensource/spotless-eclipse-base)))
22-
27+
## [3.0.0] - 2018-06-18
2328
* Initial release!

_ext/eclipse-base/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public EclipseFormatterStepImpl(Properties settings) throws Exception {
3232
```
3333

3434
The framework also supports fat JARs, providing multiple plugins.
35-
In this cases the resources required by plugins, especially the `META-INF` and plugin information, must be located in locations unique
36-
to the plugin.
35+
In this cases the resources required by plugins, especially the `META-INF` and plugin information, must be located in locations unique to the plugin.
3736
For this purpose the framework expects that these resources are stored in a sub-directory
3837
which has the name of the package containing the plugin. For example in case the JDT plugin
3938
is included in your formatter fat JAR, the directory structure should be:

_ext/eclipse-base/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apply from: rootProject.file('_ext/gradle/java-setup.gradle')
2-
apply from: rootProject.file('_ext/gradle/java-publish.gradle')
2+
apply from: rootProject.file('gradle/java-publish.gradle')
33

44
ext {
55
developers = [

_ext/eclipse-base/gradle.properties

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Mayor versions correspond to the supported Eclipse core version.
22
# Minor version is incremented for features or incompatible changes (including changes to supported dependency versions).
33
# Patch version is incremented for backward compatible patches of this library.
4-
version=3.2.1
54
artifactId=spotless-eclipse-base
65
description=Eclipse bundle controller and services for Spotless
76

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2016 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.extra.eclipse.base;
17+
18+
/**
19+
* Obtain configuration for Eclipse framework setup
20+
* <p>
21+
* The setup consitst of 4 phases:
22+
* <ol>
23+
* <li>Registration of framework bundles</li>
24+
* <li>Registration of servicves</li>
25+
* <li>Resitration of extension points, activation of bundles/plugins</li>
26+
* <li>Customize bundle/plugin configuration</li>
27+
* </ol>
28+
*/
29+
public interface SpotlessEclipseConfig {
30+
default public void registerBundles(SpotlessEclipseCoreConfig config) {
31+
config.applyDefault();
32+
}
33+
34+
default public void registerServices(SpotlessEclipseServiceConfig config) {
35+
config.applyDefault();
36+
}
37+
38+
default public void activatePlugins(SpotlessEclipsePluginConfig config) {
39+
config.applyDefault();
40+
}
41+
42+
default public void customize() {}
43+
}

_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseCoreConfig.java

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
*/
3333
public class SpotlessEclipseCoreConfig extends BundleConfig<SpotlessEclipseFramework.DefaultBundles> {
3434

35+
/**
36+
* Don't instantiate and call {@link SpotlessEclipseConfig} directly.
37+
* Registered bundles should only be instantiated once, since
38+
* older bundles still abusing singletons for access.
39+
*/
3540
SpotlessEclipseCoreConfig() {}
3641

3742
@Override

_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFramework.java

+68-38
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ private static <T> T createInstance(Class<? extends T> clazz) {
144144
* If there is already a an instance, the call is ignored.
145145
* @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise.
146146
* @throws BundleException Throws exception in case the setup failed.
147+
* @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead.
147148
*/
148149
public synchronized static boolean setup() throws BundleException {
149150
return setup(plugins -> plugins.applyDefault());
@@ -156,6 +157,7 @@ public synchronized static boolean setup() throws BundleException {
156157
* @param plugins Eclipse plugins (which are also OSGi bundles) to start
157158
* @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise.
158159
* @throws BundleException Throws exception in case the setup failed.
160+
* @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead.
159161
*/
160162
public synchronized static boolean setup(Consumer<SpotlessEclipsePluginConfig> plugins) throws BundleException {
161163
return setup(config -> config.applyDefault(), plugins);
@@ -168,6 +170,7 @@ public synchronized static boolean setup(Consumer<SpotlessEclipsePluginConfig> p
168170
* @param plugins Eclipse plugins (which are also OSGi bundles) to start
169171
* @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise.
170172
* @throws BundleException Throws exception in case the setup failed.
173+
* @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead.
171174
*/
172175
public synchronized static boolean setup(Consumer<SpotlessEclipseServiceConfig> config, Consumer<SpotlessEclipsePluginConfig> plugins) throws BundleException {
173176
return setup(core -> core.applyDefault(), config, plugins);
@@ -177,76 +180,98 @@ public synchronized static boolean setup(Consumer<SpotlessEclipseServiceConfig>
177180
* Creates and configures a new {@link SpotlessEclipseFramework} if there is none.
178181
* If there is already a an instance, the call is ignored.
179182
* @param core Activators of core bundles
180-
* @param config Framework service configuration
183+
* @param services Framework service configuration
181184
* @param plugins Eclipse plugins to start
182185
* @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise.
183186
* @throws BundleException Throws exception in case the setup failed.
187+
* @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead.
184188
*/
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 {
186190
if (null != INSTANCE) {
187191
return false;
188192
}
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+
}
189203

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+
}
192211

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+
}
195235

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();
200237
}
201-
return true;
202238
}
203239

204240
private final Function<Bundle, BundleException> registry;
205241
private final BundleController controller;
206-
private final SpotlessEclipseCoreConfig coreConfig;
207-
private boolean coreConfigStarted;
208242

209-
private SpotlessEclipseFramework(SpotlessEclipseCoreConfig coreConfig) throws BundleException {
243+
private SpotlessEclipseFramework() throws BundleException {
210244

211245
controller = new BundleController();
212246
registry = (pluginBundle) -> {
213247
return PluginRegistrar.register(pluginBundle);
214248
};
215-
216-
this.coreConfig = coreConfig;
217-
coreConfigStarted = false;
218249
}
219250

220-
/** Get framework service configuration */
221251
private SpotlessEclipseServiceConfig getServiceConfig() {
222252
return controller.getServices();
223253
}
224254

225-
/** Add a plugin to the framework. */
255+
private void addExtension(Class<?> clazzInBundleJar) throws BundleException {
256+
controller.addBundle(clazzInBundleJar, registry);
257+
}
258+
226259
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-
}
240260
controller.addBundle(state, plugin, registry);
241261
}
242262

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);
248274

249-
private void startFrameworkBundles() throws BundleException {
250275
for (BundleConfig.Entry coreBundle : coreConfig.get()) {
251276
try {
252277
BundleContext context = controller.createContext(coreBundle.state);
@@ -257,4 +282,9 @@ private void startFrameworkBundles() throws BundleException {
257282
}
258283
}
259284

285+
private <S> void addMandatoryServiceIfMissing(Class<S> interfaceClass, S service) {
286+
if (null == controller.getServiceReference(interfaceClass)) {
287+
controller.getServices().add(interfaceClass, service);
288+
}
289+
}
260290
}

_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipsePluginConfig.java

+38
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
package com.diffplug.spotless.extra.eclipse.base;
1717

18+
import java.util.ArrayList;
19+
import java.util.Arrays;
20+
import java.util.List;
21+
import java.util.Objects;
22+
1823
import org.osgi.framework.Bundle;
1924
import org.osgi.framework.BundleActivator;
2025

@@ -30,9 +35,42 @@
3035
* Note that a plugin does not necessarily derive from the
3136
* Eclipse {@link org.eclipse.core.runtime.Plugin} class.
3237
* </p>
38+
* <p>
39+
* Some plugins are pure extensions without any activator.
40+
* For resource and plugin information lookup, a class can be
41+
* specified which is in the JAR containing the resources and
42+
* plugin information. This lookup procedure also supports
43+
* fat JAR lookups as described in the ReadMe.md.
44+
* </p>
3345
* @see org.eclipse.core.runtime.RegistryFactory
3446
*/
3547
public class SpotlessEclipsePluginConfig extends BundleConfig<SpotlessEclipseFramework.DefaultPlugins> {
48+
private final List<Class<?>> extensions;
49+
50+
/**
51+
* Don't instantiate and call {@link SpotlessEclipseConfig} directly.
52+
* Registered plugins and extensions should only be instantiated once, since
53+
* some still abusing singletons for access.
54+
*/
55+
SpotlessEclipsePluginConfig() {
56+
extensions = new ArrayList<>();
57+
}
58+
59+
/** Add an extension plugin, identified by a class of the plugin. */
60+
public void add(Class<?> extensionClass) {
61+
Objects.requireNonNull(extensionClass, "Plugin extension class must nor be null");
62+
extensions.add(extensionClass);
63+
}
64+
65+
/** Add a set of default bundles with their default states */
66+
public void add(Class<?>... extensionClasses) {
67+
Arrays.asList(extensionClasses).forEach(extensionClass -> add(extensionClass));
68+
}
69+
70+
/** Returns the current configuration */
71+
public List<Class<?>> getExtensions() {
72+
return extensions;
73+
}
3674

3775
@Override
3876
public void applyDefault() {

0 commit comments

Comments
 (0)