Skip to content

Commit

Permalink
Merge branch 'main' into feat-gjf-artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Sep 24, 2021
2 parents 04f44a9 + 85344bd commit b778a4b
Show file tree
Hide file tree
Showing 38 changed files with 456 additions and 451 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Added
* Added `groupArtifact` option for `google-java-format` ([#944](https://github.com/diffplug/spotless/pull/944))
### Changed
* Added support and bump Eclipse formatter default versions to `4.21` for `eclipse-cdt`, `eclipse-jdt`, `eclipse-wtp`. Change is only applied for JVM 11+.

## [2.16.1] - 2021-09-20
### Changed
* Added support and bump Eclipse formatter default versions for JVM 11+. For older JVMs the previous defaults remain.
* `eclipse-cdt` from `4.16` to `4.20`
* `eclipse-groovy` from `4.19` to `4.20`
* `eclipse-jdt` from `4.19` to `4.20`
* `eclipse-wtp` from `4.18` to `4.20`

## [2.16.0] - 2021-09-04
### Added
Expand Down
4 changes: 4 additions & 0 deletions _ext/eclipse-cdt/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

## [10.4.0] - 2021-09-23
### Added
* Switch to Eclipse CDT release 10.4 for Eclipse 4.21.

## [10.3.0] - 2021-06-27
### Added
* Switch to Eclipse CDT release 10.3 for Eclipse 4.20.
Expand Down
2 changes: 1 addition & 1 deletion _ext/eclipse-cdt/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description=Eclipse's CDT C/C++ formatter bundled for Spotless
VER_JAVA=11

# Compile dependencies
VER_ECLIPSE_CDT=10.3
VER_ECLIPSE_CDT=10.4
VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[
VER_ECLISPE_JFACE=[3.18.0,4.0.0[
VER_ECLISPE_EFS=[3.7.0,4.0.0[
Expand Down
4 changes: 4 additions & 0 deletions _ext/eclipse-wtp/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

## [3.23.0] - 2021-09-22
### Added
* Switch to Web Tools Platform release 3.23.0 for Eclipse 4.21.

## [3.22.0] - 2021-06-27
### Added
* Switch to Web Tools Platform release 3.22.0 for Eclipse 4.20.
Expand Down
2 changes: 1 addition & 1 deletion _ext/eclipse-wtp/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description=Eclipse's WTP formatters bundled for Spotless
VER_JAVA=11

# Compile
VER_ECLIPSE_WTP=2021-06
VER_ECLIPSE_WTP=2021-09
VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[
VER_IBM_ICU=[67.1,68[
VER_ECLISPE_EMF=[2.22.0,3.0.0[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +44,7 @@ public class EclipseBasedStepBuilder {
private final String formatterStepExt;
private final ThrowingEx.Function<State, FormatterFunc> stateToFormatter;
private final Provisioner jarProvisioner;
private String formatterVersion;

/**
* Resource location of Spotless Eclipse Formatter Maven coordinate lists.
Expand Down Expand Up @@ -73,6 +74,7 @@ public EclipseBasedStepBuilder(String formatterName, String formatterStepExt, Pr
this.formatterStepExt = Objects.requireNonNull(formatterStepExt, "formatterStepExt");
this.jarProvisioner = Objects.requireNonNull(jarProvisioner, "jarProvisioner");
this.stateToFormatter = Objects.requireNonNull(stateToFormatter, "stateToFormatter");
formatterVersion = "No version set"; //Will fail creation
}

/** Returns the FormatterStep (whose state will be calculated lazily). */
Expand All @@ -96,6 +98,7 @@ public void setVersion(String version) {
dependencies.add(line);
}
}
formatterVersion = version;
}

private static byte[] toByteArray(InputStream in) {
Expand Down Expand Up @@ -130,6 +133,7 @@ EclipseBasedStepBuilder.State get() throws IOException {
* Hence a lazy construction is not required.
*/
return new State(
formatterVersion,
formatterStepExt,
jarProvisioner,
dependencies,
Expand All @@ -145,16 +149,35 @@ public static class State implements Serializable {
private static final long serialVersionUID = 1L;

private final JarState jarState;
private final String semanticVersion;
//The formatterStepExt assures that different class loaders are used for different step types
@SuppressWarnings("unused")
private final String formatterStepExt;
private final FileSignature settingsFiles;

/** State constructor expects that all passed items are not modified afterwards */
protected State(String formatterStepExt, Provisioner jarProvisioner, List<String> dependencies, Iterable<File> settingsFiles) throws IOException {
protected State(String formatterVersion, String formatterStepExt, Provisioner jarProvisioner, List<String> dependencies, Iterable<File> settingsFiles) throws IOException {
this.jarState = JarState.withoutTransitives(dependencies, jarProvisioner);
this.settingsFiles = FileSignature.signAsList(settingsFiles);
this.formatterStepExt = formatterStepExt;
semanticVersion = convertEclipseVersion(formatterVersion);
}

private static String convertEclipseVersion(String version) {
String semanticVersion = version;
//Old Eclipse versions used a character at the end. For example '4.7.3a'.
if (1 < version.length()) {
char lastChar = version.charAt(version.length() - 1);
if ('.' != lastChar && 'a' <= lastChar) {
semanticVersion = version.substring(0, version.length() - 1);
semanticVersion += String.format(".%d", (int) lastChar);
}
}
return semanticVersion;
}

public String getSemanticVersion() {
return semanticVersion;
}

/** Get formatter preferences */
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.util.Properties;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.Jvm;
import com.diffplug.spotless.Provisioner;
import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
import com.diffplug.spotless.extra.EclipseBasedStepBuilder.State;
Expand All @@ -36,11 +37,11 @@ private EclipseCdtFormatterStep() {}

private static final String NAME = "eclipse cdt formatter";
private static final String FORMATTER_CLASS = "com.diffplug.spotless.extra.eclipse.cdt.EclipseCdtFormatterStepImpl";
private static final String DEFAULT_VERSION = "4.16.0";
private static final String FORMATTER_METHOD = "format";
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "4.16.0").add(11, "4.21.0");

public static String defaultVersion() {
return DEFAULT_VERSION;
return JVM_SUPPORT.getRecommendedFormatterVersion();
}

/** Provides default configuration */
Expand All @@ -49,10 +50,11 @@ public static EclipseBasedStepBuilder createBuilder(Provisioner provisioner) {
}

private static FormatterFunc apply(State state) throws Exception {
JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion());
Class<?> formatterClazz = state.loadClass(FORMATTER_CLASS);
Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences());
Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class);
return input -> (String) method.invoke(formatter, input);
return JVM_SUPPORT.suggestLaterVersionOnError(state.getSemanticVersion(), input -> (String) method.invoke(formatter, input));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Properties;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.Jvm;
import com.diffplug.spotless.Provisioner;
import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
import com.diffplug.spotless.extra.EclipseBasedStepBuilder.State;
Expand All @@ -33,11 +34,11 @@ private GrEclipseFormatterStep() {}
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.19.0";
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "4.19.0").add(11, "4.20.0");
private static final String FORMATTER_METHOD = "format";

public static String defaultVersion() {
return DEFAULT_VERSION;
return JVM_SUPPORT.getRecommendedFormatterVersion();
}

/** Provides default configuration */
Expand All @@ -46,18 +47,20 @@ public static EclipseBasedStepBuilder createBuilder(Provisioner provisioner) {
}

private static FormatterFunc apply(EclipseBasedStepBuilder.State state) throws Exception {
JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion());
Class<?> formatterClazz = getClass(state);
Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences());
Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class);
return input -> {
try {
return (String) method.invoke(formatter, input);
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
throw (null == exception) ? exceptionWrapper : exception;
}
};
return JVM_SUPPORT.suggestLaterVersionOnError(state.getSemanticVersion(),
input -> {
try {
return (String) method.invoke(formatter, input);
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
throw (null == exception) ? exceptionWrapper : exception;
}
});
}

private static Class<?> getClass(State state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Properties;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.Jvm;
import com.diffplug.spotless.Provisioner;
import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
import com.diffplug.spotless.extra.EclipseBasedStepBuilder.State;
Expand All @@ -32,11 +33,11 @@ private EclipseJdtFormatterStep() {}
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.19.0";
private static final String FORMATTER_METHOD = "format";
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "4.19.0").add(11, "4.21.0");

public static String defaultVersion() {
return DEFAULT_VERSION;
return JVM_SUPPORT.getRecommendedFormatterVersion();
}

/** Provides default configuration */
Expand All @@ -45,10 +46,11 @@ public static EclipseBasedStepBuilder createBuilder(Provisioner provisioner) {
}

private static FormatterFunc apply(State state) throws Exception {
JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion());
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);
return JVM_SUPPORT.suggestLaterVersionOnError(state.getSemanticVersion(), input -> (String) method.invoke(formatter, input));
}

private static Class<?> getClass(State state) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,11 +15,13 @@
*/
package com.diffplug.spotless.extra.wtp;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.Jvm;
import com.diffplug.spotless.Provisioner;
import com.diffplug.spotless.ThrowingEx;
import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
Expand All @@ -36,7 +38,7 @@ public enum EclipseWtpFormatterStep {

private static final String NAME = "eclipse wtp formatters";
private static final String FORMATTER_PACKAGE = "com.diffplug.spotless.extra.eclipse.wtp.";
private static final String DEFAULT_VERSION = "4.18.0";
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "4.18.0").add(11, "4.21.0");
private static final String FORMATTER_METHOD = "format";

private final String implementationClassName;
Expand All @@ -52,10 +54,11 @@ public EclipseBasedStepBuilder createBuilder(Provisioner provisioner) {
}

public static String defaultVersion() {
return DEFAULT_VERSION;
return JVM_SUPPORT.getRecommendedFormatterVersion();
}

private static FormatterFunc applyWithoutFile(String className, EclipseBasedStepBuilder.State state) throws Exception {
JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion());
Class<?> formatterClazz = state.loadClass(FORMATTER_PACKAGE + className);
Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences());
Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class);
Expand All @@ -70,18 +73,22 @@ private static FormatterFunc applyWithoutFile(String className, EclipseBasedStep
};
}

private static FormatterFunc.NeedsFile applyWithFile(String className, EclipseBasedStepBuilder.State state) throws Exception {
private static FormatterFunc applyWithFile(String className, EclipseBasedStepBuilder.State state) throws Exception {
JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion());
Class<?> formatterClazz = state.loadClass(FORMATTER_PACKAGE + className);
Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences());
Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class, String.class);
return (unixString, file) -> {
try {
return (String) method.invoke(formatter, unixString, file.getAbsolutePath());
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
throw (null == exception) ? exceptionWrapper : exception;
return JVM_SUPPORT.suggestLaterVersionOnError(state.getSemanticVersion(), new FormatterFunc.NeedsFile() {
@Override
public String applyWithFile(String unix, File file) throws Exception {
try {
return (String) method.invoke(formatter, unix, file.getAbsolutePath());
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
throw (null == exception) ? exceptionWrapper : exception;
}
}
};
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Spotless formatter based on CDT version 10.3 (see https://www.eclipse.org/cdt/)
com.diffplug.spotless:spotless-eclipse-cdt:10.3.0
com.diffplug.spotless:spotless-eclipse-base:3.5.0
com.github.spotbugs:spotbugs-annotations:4.0.2
com.google.code.findbugs:jsr305:3.0.2
com.ibm.icu:icu4j:67.1
net.jcip:jcip-annotations:1.0
org.eclipse.platform:org.eclipse.core.commands:3.10.0
org.eclipse.platform:org.eclipse.core.contenttype:3.7.1000
org.eclipse.platform:org.eclipse.core.filebuffers:3.7.0
org.eclipse.platform:org.eclipse.core.filesystem:1.9.0
org.eclipse.platform:org.eclipse.core.jobs:3.11.0
org.eclipse.platform:org.eclipse.core.resources:3.15.0
org.eclipse.platform:org.eclipse.core.runtime:3.22.0
org.eclipse.platform:org.eclipse.equinox.app:1.5.100
org.eclipse.platform:org.eclipse.equinox.common:3.15.0
org.eclipse.platform:org.eclipse.equinox.preferences:3.8.200
org.eclipse.platform:org.eclipse.equinox.registry:3.10.200
org.eclipse.platform:org.eclipse.jface.text:3.18.0
org.eclipse.platform:org.eclipse.jface:3.22.200
org.eclipse.platform:org.eclipse.osgi:3.16.300
org.eclipse.platform:org.eclipse.text:3.12.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Spotless formatter based on CDT version 10.4 (see https://www.eclipse.org/cdt/)
com.diffplug.spotless:spotless-eclipse-cdt:10.4.0
com.diffplug.spotless:spotless-eclipse-base:3.5.0
com.github.spotbugs:spotbugs-annotations:4.0.2
com.google.code.findbugs:jsr305:3.0.2
com.ibm.icu:icu4j:67.1
net.jcip:jcip-annotations:1.0
org.eclipse.platform:org.eclipse.core.commands:3.10.100
org.eclipse.platform:org.eclipse.core.contenttype:3.8.0
org.eclipse.platform:org.eclipse.core.filebuffers:3.7.0
org.eclipse.platform:org.eclipse.core.filesystem:1.9.100
org.eclipse.platform:org.eclipse.core.jobs:3.12.0
org.eclipse.platform:org.eclipse.core.resources:3.15.100
org.eclipse.platform:org.eclipse.core.runtime:3.23.0
org.eclipse.platform:org.eclipse.equinox.app:1.6.0
org.eclipse.platform:org.eclipse.equinox.common:3.15.0
org.eclipse.platform:org.eclipse.equinox.preferences:3.9.0
org.eclipse.platform:org.eclipse.equinox.registry:3.11.0
org.eclipse.platform:org.eclipse.jface.text:3.18.100
org.eclipse.platform:org.eclipse.jface:3.23.0
org.eclipse.platform:org.eclipse.osgi:3.17.0
org.eclipse.platform:org.eclipse.text:3.12.0
Loading

0 comments on commit b778a4b

Please sign in to comment.