From 093af21476912ae1806639c58be6a9c64c05a43f Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sat, 14 Jul 2018 20:01:11 +0200 Subject: [PATCH 1/6] Extension of lib/lib-extra allowing access to Maven coordinate information. --- .../diffplug/spotless/extra/EclipseBasedStepBuilder.java | 7 +++++++ lib/src/main/java/com/diffplug/spotless/JarState.java | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EclipseBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EclipseBasedStepBuilder.java index ebb4cf460c..18d4843995 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EclipseBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EclipseBasedStepBuilder.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.Properties; import com.diffplug.common.base.Errors; @@ -151,6 +152,12 @@ public Properties getPreferences() { return preferences.getProperties(); } + /** Returns first coordinate from sorted set that starts with a given prefix.*/ + public Optional getMavenCoordinate(String prefix) { + return jarState.getMavenCoordinates().stream() + .filter(coordinate -> coordinate.startsWith(prefix)).findFirst(); + } + /** Load class based on the given configuration of JAR provider and Maven coordinates. */ public Class loadClass(String name) { try { diff --git a/lib/src/main/java/com/diffplug/spotless/JarState.java b/lib/src/main/java/com/diffplug/spotless/JarState.java index ce1740c38d..6682d9b038 100644 --- a/lib/src/main/java/com/diffplug/spotless/JarState.java +++ b/lib/src/main/java/com/diffplug/spotless/JarState.java @@ -42,8 +42,7 @@ public final class JarState implements Serializable { private static final long serialVersionUID = 1L; - @SuppressWarnings("unused") - private final Set mavenCoordinates; + private final TreeSet mavenCoordinates; @SuppressWarnings("unused") private final FileSignature fileSignature; @@ -92,4 +91,9 @@ URL[] jarUrls() { public ClassLoader getClassLoader() { return SpotlessCache.instance().classloader(this); } + + /** Returns unmodifiable view on sorted Maven coordinates */ + public Set getMavenCoordinates() { + return Collections.unmodifiableSet(mavenCoordinates); + } } From 2fd0b20d75e5ad168f09e4f547094ec1e46039ca Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sat, 14 Jul 2018 20:03:49 +0200 Subject: [PATCH 2/6] Integration of Spotless Eclipse JDT formatter implementation version 4.8.0. --- .../extra/java/EclipseJdtFormatterStep.java | 14 +++++++++++--- .../extra/eclipse_jdt_formatter/v4.8.0.lockfile | 17 +++++++++++++++++ .../extra/java/EclipseJdtFormatterStepTest.java | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.8.0.lockfile diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java index 0aab33402e..51f693ee35 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java @@ -29,8 +29,10 @@ public final class EclipseJdtFormatterStep { private EclipseJdtFormatterStep() {} private static final String NAME = "eclipse jdt formatter"; - private static final String FORMATTER_CLASS = "com.diffplug.gradle.spotless.java.eclipse.EclipseFormatterStepImpl"; - private static final String DEFAULT_VERSION = "4.7.2"; + private static final String FORMATTER_CLASS_OLD = "com.diffplug.gradle.spotless.java.eclipse.EclipseFormatterStepImpl"; + private static final String FORMATTER_CLASS = "com.diffplug.spotless.extra.eclipse.java.EclipseJdtFormatterStepImpl"; + private static final String MAVEN_GROUP_ARTIFACT = "com.diffplug.spotless:spotless-eclipse-jdt"; + private static final String DEFAULT_VERSION = "4.8.0"; private static final String FORMATTER_METHOD = "format"; public static String defaultVersion() { @@ -43,9 +45,15 @@ public static EclipseBasedStepBuilder createBuilder(Provisioner provisioner) { } private static FormatterFunc apply(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 -> (String) method.invoke(formatter, input); } + + private static Class getClass(State state) { + if (state.getMavenCoordinate(MAVEN_GROUP_ARTIFACT).isPresent()) + return state.loadClass(FORMATTER_CLASS); + return state.loadClass(FORMATTER_CLASS_OLD); + } } diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.8.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.8.0.lockfile new file mode 100644 index 0000000000..46d635cad1 --- /dev/null +++ b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.8.0.lockfile @@ -0,0 +1,17 @@ +# Spotless formatter based on JDT version 4.8.0 (see https://projects.eclipse.org/projects/eclipse.jdt) +com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 +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.jdt:org.eclipse.jdt.core:3.14.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 +org.eclipse.platform:org.eclipse.osgi:3.13.0 +org.eclipse.platform:org.eclipse.text:3.6.300 \ No newline at end of file diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java index 04b0bda575..a8a5ce8532 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java @@ -24,7 +24,7 @@ public class EclipseJdtFormatterStepTest extends EclipseCommonTests { @Override protected String[] getSupportedVersions() { - return new String[]{"4.6.1", "4.6.3", "4.7.0", "4.7.1", "4.7.2"}; + return new String[]{"4.6.1", "4.6.3", "4.7.0", "4.7.1", "4.7.2", "4.8.0"}; } @Override From 8ce3295dcdd73bb8ee02a6487e3367e9ef936807 Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sat, 14 Jul 2018 20:04:38 +0200 Subject: [PATCH 3/6] Eclipse JDT formatter 4.8.0 applied on Spotless code. --- lib/src/main/java/com/diffplug/spotless/PaddedCell.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java b/lib/src/main/java/com/diffplug/spotless/PaddedCell.java index d8fd282051..5925f2a7d1 100644 --- a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java +++ b/lib/src/main/java/com/diffplug/spotless/PaddedCell.java @@ -35,7 +35,7 @@ public final class PaddedCell { /** The kind of result. */ public enum Type { - CONVERGE, CYCLE, DIVERGE; + CONVERGE, CYCLE, DIVERGE; /** Creates a PaddedCell with the given file and steps. */ PaddedCell create(File file, List steps) { From 64ffa3155c9da25d2e9efd70407c7f54d48b8efc Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Thu, 19 Jul 2018 20:26:10 +0200 Subject: [PATCH 4/6] Updated CHANGES.md --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 65365b4832..de59500e54 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 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)) ### Version 1.13.0 - June 1st 2018 (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/1.11.0/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/1.13.0/), artifact [lib]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib), [lib-extra]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib-extra))) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 6443edced7..89dabd1956 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -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 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)) ### Version 3.13.0 - June 1st 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.13.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.13.0)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index dd68758ee3..cc3833a847 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -2,6 +2,7 @@ ### Version 1.14.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-maven-plugin/)) +* 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)). * Require 3.1.0+ version of Maven ([#259](https://github.com/diffplug/spotless/pull/259)). * 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)) From 307b6ca3f5c963d84c492c906b0d4273a6988c1a Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Thu, 19 Jul 2018 21:09:18 +0200 Subject: [PATCH 5/6] Implemented changes as requested by reviewer. --- .../diffplug/spotless/extra/java/EclipseJdtFormatterStep.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java index 51f693ee35..7807ecae3b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java @@ -52,8 +52,9 @@ private static FormatterFunc apply(State state) throws Exception { } private static Class getClass(State state) { - if (state.getMavenCoordinate(MAVEN_GROUP_ARTIFACT).isPresent()) + if (state.getMavenCoordinate(MAVEN_GROUP_ARTIFACT).isPresent()) { return state.loadClass(FORMATTER_CLASS); + } return state.loadClass(FORMATTER_CLASS_OLD); } } From 44cebb0e26a862bbfc1670a45a9addb5e556ddb2 Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Thu, 19 Jul 2018 22:14:24 +0200 Subject: [PATCH 6/6] Implemented review requests. --- lib/src/main/java/com/diffplug/spotless/JarState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/JarState.java b/lib/src/main/java/com/diffplug/spotless/JarState.java index 6682d9b038..fb2da50efb 100644 --- a/lib/src/main/java/com/diffplug/spotless/JarState.java +++ b/lib/src/main/java/com/diffplug/spotless/JarState.java @@ -42,7 +42,7 @@ public final class JarState implements Serializable { private static final long serialVersionUID = 1L; - private final TreeSet mavenCoordinates; + private final Set mavenCoordinates; @SuppressWarnings("unused") private final FileSignature fileSignature;