Skip to content

Bumped to Groovy-Eclipse version 2.9.2 (corresponds to Eclipse 4.8.0). #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ You might be looking for:

### Version 1.14.0-SNAPSHOT - TBD (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/snapshot/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/snapshot/), [snapshot repo](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/))

* Updated default groovy-eclipse from 4.6.3 to 4.8.0 ([#244](https://github.com/diffplug/spotless/pull/244)). New version allows to ignore internal formatter errors/warnings.
* Updated default eclipse-jdt from 4.7.2 to 4.8.0 ([#239](https://github.com/diffplug/spotless/pull/239)). New version fixes a bug preventing Java code formatting within JavaDoc comments ([#191](https://github.com/diffplug/spotless/issues/191)).
* Eclipse formatter versions decoupled from Spotless formatter step implementations to allow independent updates of M2 based Eclipse dependencies. ([#253](https://github.com/diffplug/spotless/pull/253))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.Provisioner;
import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
import com.diffplug.spotless.extra.EclipseBasedStepBuilder.State;

/** Formatter step which calls out to the Groovy-Eclipse formatter. */
public final class GrEclipseFormatterStep {
// prevent direct instantiation
private GrEclipseFormatterStep() {}

private static final String NAME = "groovy eclipse formatter";
private static final String FORMATTER_CLASS = "com.diffplug.gradle.spotless.groovy.eclipse.GrEclipseFormatterStepImpl";
private static final String DEFAULT_VERSION = "4.6.3";
private static final String FORMATTER_CLASS = "com.diffplug.spotless.extra.eclipse.groovy.GrEclipseFormatterStepImpl";
private static final String FORMATTER_CLASS_OLD = "com.diffplug.gradle.spotless.groovy.eclipse.GrEclipseFormatterStepImpl";
private static final String MAVEN_GROUP_ARTIFACT = "com.diffplug.spotless:spotless-eclipse-groovy";
private static final String DEFAULT_VERSION = "4.8.0";
private static final String FORMATTER_METHOD = "format";

/** Creates a formatter step using the default version for the given settings file. */
Expand Down Expand Up @@ -60,7 +63,7 @@ public static EclipseBasedStepBuilder createBuilder(Provisioner provisioner) {
}

private static FormatterFunc apply(EclipseBasedStepBuilder.State state) throws Exception {
Class<?> formatterClazz = state.loadClass(FORMATTER_CLASS);
Class<?> formatterClazz = getClass(state);
Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences());
Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class);
return input -> {
Expand All @@ -74,4 +77,11 @@ private static FormatterFunc apply(EclipseBasedStepBuilder.State state) throws E
};
}

private static Class<?> getClass(State state) {
if (state.getMavenCoordinate(MAVEN_GROUP_ARTIFACT).isPresent()) {
return state.loadClass(FORMATTER_CLASS);
}
return state.loadClass(FORMATTER_CLASS_OLD);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Spotless formatter based on Groovy-Eclipse version 2.9.2 (see https://github.com/groovy/groovy-eclipse/releases)
com.diffplug.spotless:spotless-eclipse-groovy:2.9.2
com.diffplug.spotless:spotless-eclipse-base:3.0.0
com.google.code.findbugs:annotations:3.0.0
com.google.code.findbugs:jsr305:3.0.0
org.eclipse.platform:org.eclipse.core.commands:3.9.100
org.eclipse.platform:org.eclipse.core.contenttype:3.7.0
org.eclipse.platform:org.eclipse.core.jobs:3.10.0
org.eclipse.platform:org.eclipse.core.resources:3.13.0
org.eclipse.platform:org.eclipse.core.runtime:3.14.0
org.eclipse.platform:org.eclipse.equinox.app:1.3.500
org.eclipse.platform:org.eclipse.equinox.common:3.10.0
org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100
org.eclipse.platform:org.eclipse.equinox.registry:3.8.0
#Spotless currently loads all transitive dependencies.
#jface requires platform specific JARs (not used by formatter), which are not hosted via M2.
#org.eclipse.platform:org.eclipse.jface.text:3.13.0
#org.eclipse.platform:org.eclipse.jface:3.14.0
org.eclipse.platform:org.eclipse.osgi:3.13.0
org.eclipse.platform:org.eclipse.text:3.6.300
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class DeprecatedGrEclipseFormatterStepTest extends ResourceHarness {

private static final String RESOURCE_PATH = "groovy/greclipse/format/";
private static final String CONFIG_FILE = RESOURCE_PATH + "greclipse.properties";
private static final String DEPRECATED_VERSION = "4.6.3";

//String is hard-coded in the GrEclipseFormatter
private static final String FORMATTER_FILENAME_REPALCEMENT = "Hello.groovy";
Expand All @@ -44,14 +45,14 @@ private static Provisioner provisioner() {
@Test
public void nominal() throws Throwable {
List<File> config = createTestFiles(CONFIG_FILE);
StepHarness.forStep(GrEclipseFormatterStep.create(config, provisioner()))
StepHarness.forStep(GrEclipseFormatterStep.create(DEPRECATED_VERSION, config, provisioner()))
.testResource(RESOURCE_PATH + "unformatted.test", RESOURCE_PATH + "formatted.test");
}

@Test
public void formatterException() throws Throwable {
List<File> config = createTestFiles(CONFIG_FILE);
StepHarness.forStep(GrEclipseFormatterStep.create(config, provisioner()))
StepHarness.forStep(GrEclipseFormatterStep.create(DEPRECATED_VERSION, config, provisioner()))
.testException(RESOURCE_PATH + "exception.test", assertion -> {
assertion.isInstanceOf(IllegalArgumentException.class);
assertion.hasMessageContaining(FORMATTER_FILENAME_REPALCEMENT);
Expand All @@ -62,7 +63,7 @@ public void formatterException() throws Throwable {
public void configurationException() throws Throwable {
String configFileName = "greclipse.exception";
List<File> config = createTestFiles(RESOURCE_PATH + configFileName);
StepHarness.forStep(GrEclipseFormatterStep.create(config, provisioner()))
StepHarness.forStep(GrEclipseFormatterStep.create(DEPRECATED_VERSION, config, provisioner()))
.testException(RESOURCE_PATH + "unformatted.test", assertion -> {
assertion.isInstanceOf(IllegalArgumentException.class);
assertion.hasMessageContaining(configFileName);
Expand All @@ -81,7 +82,7 @@ protected void setupTest(API api) {

@Override
protected FormatterStep create() {
return GrEclipseFormatterStep.create(configFile, provisioner());
return GrEclipseFormatterStep.create(DEPRECATED_VERSION, configFile, provisioner());
}
}.testEquals();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class GrEclipseFormatterStepTest extends EclipseCommonTests {
@Override
protected String[] getSupportedVersions() {
return new String[]{"2.3.0", "4.6.3"};
return new String[]{"2.3.0", "4.6.3", "4.8.0"};
}

@Override
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Version 3.14.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-plugin-gradle/))

* Updated default groovy-eclipse from 4.6.3 to 4.8.0 ([#244](https://github.com/diffplug/spotless/pull/244)). New version allows to ignore internal formatter errors/warnings.
* Updated default eclipse-jdt from 4.7.2 to 4.7.3a ([#263](https://github.com/diffplug/spotless/issues/263)). New version fixes a bug preventing Java code formatting within JavaDoc comments ([#191](https://github.com/diffplug/spotless/issues/191)).
* Eclipse formatter versions decoupled from Spotless formatter step implementations to allow independent updates of M2 based Eclipse dependencies. ([#253](https://github.com/diffplug/spotless/pull/253))

Expand Down
6 changes: 5 additions & 1 deletion plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ spotless {
}
```

The [Groovy-Eclipse](https://github.com/groovy/groovy-eclipse) formatter is based on the Eclipse Java formatter as used by `eclipseFormatFile`. It uses the same configuration parameters plus a few additional ones. These parameters can be configured within a single file, like the Java properties file [greclipse.properties](../lib-extra/src/test/resources/groovy/greclipse/format/greclipse.properties) in the previous example. The formatter step can also load the [exported Eclipse properties](../ECLIPSE_SCREENSHOTS.md) and augment it with the `org.codehaus.groovy.eclipse.ui.prefs` from the Eclipse workspace as shown below.
The [Groovy-Eclipse](https://github.com/groovy/groovy-eclipse) formatter is based on the Eclipse Java formatter as used by `eclipseFormatFile`. It uses the same configuration parameters plus a few additional ones. These parameters can be configured within a single file, like the Java properties file [greclipse.properties](../lib-extra/src/test/resources/groovy/greclipse/format/greclipse.properties) in the previous example. The formatter step can also load the [exported Eclipse properties](../ECLIPSE_SCREENSHOTS.md) and augment it with the `org.codehaus.groovy.eclipse.ui.prefs` from the Eclipse workspace as shown below.

[Groovy-Eclipse](https://github.com/groovy/groovy-eclipse) formatter errors/warnings lead
per default to a build failure. This behavior can be changed by adding the property/key value: `ignoreFormatterProblems=true` to the configuration. In this scenario, files
causing problems, will not be modified by this formatter step.

```gradle
spotless {
Expand Down