From 63698819b8c40d98b104f6acae0b79baf6081b53 Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sat, 15 Dec 2018 12:14:42 +0100 Subject: [PATCH 1/7] Provided common WTP formatter step. Fixed Maven artifact lookup without transitives. Added test step to verify Maven artifact lookup without transitives. --- .../extra/wtp/EclipseWtpFormatterStep.java | 51 ++++++++++++++++--- .../gradle/spotless/FormatExtension.java | 34 +++++++++++++ .../spotless/maven/ArtifactResolver.java | 35 ++++++++----- .../spotless/maven/FormatterFactory.java | 4 ++ .../spotless/maven/generic/EclipseWtp.java | 49 ++++++++++++++++++ .../maven/generic/EclipseWtpTest.java | 41 +++++++++++++++ spotlessSelf.gradle | 14 ++--- 7 files changed, 201 insertions(+), 27 deletions(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/EclipseWtpTest.java diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java index d1e1078537..a82b71e3e2 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java @@ -15,25 +15,62 @@ */ package com.diffplug.spotless.extra.wtp; +import static java.util.Arrays.stream; +import static java.util.stream.Collectors.joining; + import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Locale; +import java.util.Objects; import java.util.Properties; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.ThrowingEx; import com.diffplug.spotless.extra.EclipseBasedStepBuilder; /** Formatter step which calls out to the Groovy-Eclipse formatter. */ -public final class EclipseWtpFormatterStep { - // prevent direct instantiation - private EclipseWtpFormatterStep() {} +public enum EclipseWtpFormatterStep { + // @formatter:off + CSS ("EclipseCssFormatterStepImpl", EclipseWtpFormatterStep::applyWithoutFile), + HTML("EclipseHtmlFormatterStepImpl", EclipseWtpFormatterStep::applyWithoutFile), + JS ("EclipseJsFormatterStepImpl", EclipseWtpFormatterStep::applyWithoutFile), + JSON("EclipseJsonFormatterStepImpl", EclipseWtpFormatterStep::applyWithoutFile), + XML ("EclipseXmlFormatterStepImpl", EclipseWtpFormatterStep::applyWithFile); + // @formatter:on 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.7.3a"; private static final String FORMATTER_METHOD = "format"; + private final String implementationClassName; + private final ThrowingEx.BiFunction formatterCall; + + EclipseWtpFormatterStep(String implementationClassName, ThrowingEx.BiFunction formatterCall) { + this.implementationClassName = implementationClassName; + this.formatterCall = formatterCall; + } + + /** Similar to {@link #valueOf(Class, String)}, ignores whitespace, case and adds helpful exception messages. */ + public static EclipseWtpFormatterStep valueFrom(String name) { + Objects.requireNonNull(name); + name = name.trim().toUpperCase(Locale.ENGLISH); + try { + return valueOf(name); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(e.getMessage() + + " (allowed values: " + + stream(values()).map(enumType -> enumType.toString()).collect(joining("; ")) + + ")"); + } + } + + public EclipseBasedStepBuilder createBuilder(Provisioner provisioner) { + return new EclipseBasedStepBuilder(NAME, " - " + toString(), provisioner, state -> formatterCall.apply(implementationClassName, state)); + } + public static String defaultVersion() { return DEFAULT_VERSION; } @@ -45,22 +82,22 @@ public static EclipseBasedStepBuilder createCssBuilder(Provisioner provisioner) /** Provides default configuration for HTML formatter */ public static EclipseBasedStepBuilder createHtmlBuilder(Provisioner provisioner) { - return new EclipseBasedStepBuilder(NAME, " - html", provisioner, state -> applyWithoutFile("EclipseHtmlFormatterStepImpl", state)); + return HTML.createBuilder(provisioner); } /** Provides default configuration for Java Script formatter */ public static EclipseBasedStepBuilder createJsBuilder(Provisioner provisioner) { - return new EclipseBasedStepBuilder(NAME, " - js", provisioner, state -> applyWithoutFile("EclipseJsFormatterStepImpl", state)); + return JS.createBuilder(provisioner); } /** Provides default configuration for JSON formatter */ public static EclipseBasedStepBuilder createJsonBuilder(Provisioner provisioner) { - return new EclipseBasedStepBuilder(NAME, " - json", provisioner, state -> applyWithoutFile("EclipseJsonFormatterStepImpl", state)); + return JSON.createBuilder(provisioner); } /** Provides default configuration for XML formatter */ public static EclipseBasedStepBuilder createXmlBuilder(Provisioner provisioner) { - return new EclipseBasedStepBuilder(NAME, " - xml", provisioner, state -> applyWithFile("EclipseXmlFormatterStepImpl", state)); + return XML.createBuilder(provisioner); } private static FormatterFunc applyWithoutFile(String className, EclipseBasedStepBuilder.State state) throws Exception { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index e19e88e356..0c908965af 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -35,6 +35,8 @@ import com.diffplug.spotless.LazyForwardingEquality; import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.ThrowingEx; +import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; import com.diffplug.spotless.generic.EndWithNewlineStep; import com.diffplug.spotless.generic.IndentStep; import com.diffplug.spotless.generic.LicenseHeaderStep; @@ -483,6 +485,38 @@ public PrettierConfig prettier() { return prettierConfig; } + public class EclipseWtpConfig { + private final EclipseBasedStepBuilder builder; + + EclipseWtpConfig(EclipseWtpFormatterStep type) { + this(type, EclipseWtpFormatterStep.defaultVersion()); + } + + EclipseWtpConfig(EclipseWtpFormatterStep type, String version) { + builder = type.createBuilder(GradleProvisioner.fromProject(getProject())); + builder.setVersion(EclipseWtpFormatterStep.defaultVersion()); + addStep(builder.build()); + } + + public void configFile(Object... configFiles) { + requireElementsNonNull(configFiles); + Project project = getProject(); + builder.setPreferences(project.files(configFiles).getFiles()); + replaceStep(builder.build()); + } + + } + + public EclipseWtpConfig eclipseWtp(String type) { + return new EclipseWtpConfig(EclipseWtpFormatterStep.valueFrom(type)); + } + + public EclipseWtpConfig eclipseWtp(String type, String version) { + return new EclipseWtpConfig( + EclipseWtpFormatterStep.valueFrom(type), + version); + } + /** Sets up a format task according to the values in this extension. */ protected void setupTask(SpotlessTask task) { task.setPaddedCell(paddedCell); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java index 379bf25cff..97fe0da001 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java @@ -31,9 +31,10 @@ import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.graph.DefaultDependencyNode; import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.graph.DependencyFilter; import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResult; import org.eclipse.aether.resolution.DependencyRequest; import org.eclipse.aether.resolution.DependencyResolutionException; @@ -41,9 +42,6 @@ public class ArtifactResolver { - private static final DependencyFilter ACCEPT_ALL = (node, parents) -> true; - private static final DependencyFilter FILTER_TRANSITIVES = (node, parents) -> parents.size() <= 1; - private final RepositorySystem repositorySystem; private final RepositorySystemSession session; private final List repositories; @@ -73,31 +71,42 @@ public Set resolve(boolean withTransitives, Collection mavenCoordi .map(artifact -> new Dependency(artifact, null)) .collect(toList()); CollectRequest collectRequest = new CollectRequest(dependencies, null, repositories); - DependencyRequest dependencyRequest; + List artifactResults; if (withTransitives) { - dependencyRequest = new DependencyRequest(collectRequest, ACCEPT_ALL); + DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null); + artifactResults = resolveArtifacts(dependencyRequest); } else { - dependencyRequest = new DependencyRequest(collectRequest, FILTER_TRANSITIVES); + List artifactRequests = dependencies.stream() + .map(dependency -> new DefaultDependencyNode(dependency)) + .map(dependencyNode -> new ArtifactRequest(dependencyNode)) + .collect(toList()); + artifactResults = resolveArtifacts(artifactRequests); } - DependencyResult dependencyResult = resolveDependencies(dependencyRequest); - - return dependencyResult.getArtifactResults() - .stream() + return artifactResults.stream() .peek(this::logResolved) .map(ArtifactResult::getArtifact) .map(Artifact::getFile) .collect(toSet()); } - private DependencyResult resolveDependencies(DependencyRequest dependencyRequest) { + private List resolveArtifacts(DependencyRequest dependencyRequest) { try { - return repositorySystem.resolveDependencies(session, dependencyRequest); + DependencyResult dependencyResult = repositorySystem.resolveDependencies(session, dependencyRequest); + return dependencyResult.getArtifactResults(); } catch (DependencyResolutionException e) { throw new ArtifactResolutionException("Unable to resolve dependencies", e); } } + private List resolveArtifacts(List artifactRequests) { + try { + return repositorySystem.resolveArtifacts(session, artifactRequests); + } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) { + throw new ArtifactResolutionException("Unable to resolve dependencies", e); + } + } + private void logResolved(ArtifactResult artifactResult) { if (log.isDebugEnabled()) { log.debug("Resolved artifact: " + artifactResult); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java index dd0cbd4959..0b96f07fb0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java @@ -107,6 +107,10 @@ public final void addReplaceRegex(ReplaceRegex replaceRegex) { addStepFactory(replaceRegex); } + public final void addEclipseWtp(EclipseWtp eclipseWtp) { + addStepFactory(eclipseWtp); + } + protected final void addStepFactory(FormatterStepFactory stepFactory) { Objects.requireNonNull(stepFactory); stepFactories.add(stepFactory); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java new file mode 100644 index 0000000000..adff349dcb --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java @@ -0,0 +1,49 @@ +/* + * Copyright 2016 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.generic; + +import static java.util.Arrays.stream; +import static java.util.stream.Collectors.toList; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class EclipseWtp implements FormatterStepFactory { + @Parameter + private String type; + + @Parameter + private String version; + + @Parameter + private String[] files; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + EclipseBasedStepBuilder eclipseConfig = EclipseWtpFormatterStep.valueFrom(type).createBuilder(stepConfig.getProvisioner()); + eclipseConfig.setVersion(version == null ? EclipseWtpFormatterStep.defaultVersion() : version); + if (null != files) { + eclipseConfig.setPreferences( + stream(files).map(file -> stepConfig.getFileLocator().locateFile(file)).collect(toList())); + } + return eclipseConfig.build(); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/EclipseWtpTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/EclipseWtpTest.java new file mode 100644 index 0000000000..92a103bb8f --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/EclipseWtpTest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.generic; + +import org.junit.Test; + +import com.diffplug.spotless.maven.MavenIntegrationTest; + +public class EclipseWtpTest extends MavenIntegrationTest { + + @Test + public void testType() throws Exception { + writePomWithFormatSteps( + "", + "XML", + ""); + runTest(); + } + + private void runTest() throws Exception { + String notFormatted = " c"; + String formatted = "\n\t c\n"; + //writePomWithFormatSteps includes java. WTP does not care about file extensions. + setFile("src/main/java/test.java").toContent(notFormatted); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("src/main/java/test.java").hasContent(formatted); + } +} diff --git a/spotlessSelf.gradle b/spotlessSelf.gradle index f06c5addbe..b579a6bc01 100644 --- a/spotlessSelf.gradle +++ b/spotlessSelf.gradle @@ -43,13 +43,6 @@ spotless { bumpThisNumberIfACustomStepChanges(3) greclipse().configFile('spotless.eclipseformat.xml', 'spotless.groovyformat.prefs') } - xml { - target fileTree('.') { - include com.diffplug.spotless.xml.XmlDefaults.FILE_FILTER - exclude '**/build/**' - } - eclipse().configFile 'spotless.xmlformat.prefs' - } freshmark { target '**/*.md' propertiesFile('gradle.properties') @@ -64,4 +57,11 @@ spotless { trimTrailingWhitespace() endWithNewline() } + format 'xml', { + target fileTree('.') { + include '**/*.xml', '**/*.xsd' + exclude '**/build/**' + } + eclipseWtp('xml').configFile 'spotless.xmlformat.prefs' + } } From 11147a96e8155a18ece5e03d41484dfbc07d8a22 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 18 Dec 2018 10:53:53 -0800 Subject: [PATCH 2/7] Change to using the EclipseWtpFormatterStep enum as the argument. --- .../extra/wtp/EclipseWtpFormatterStep.java | 19 ------------------- .../gradle/spotless/FormatExtension.java | 17 +++++------------ .../spotless/maven/generic/EclipseWtp.java | 4 ++-- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java index a82b71e3e2..b9306e8e5c 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java @@ -15,14 +15,9 @@ */ package com.diffplug.spotless.extra.wtp; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.joining; - import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Locale; -import java.util.Objects; import java.util.Properties; import com.diffplug.spotless.FormatterFunc; @@ -53,20 +48,6 @@ public enum EclipseWtpFormatterStep { this.formatterCall = formatterCall; } - /** Similar to {@link #valueOf(Class, String)}, ignores whitespace, case and adds helpful exception messages. */ - public static EclipseWtpFormatterStep valueFrom(String name) { - Objects.requireNonNull(name); - name = name.trim().toUpperCase(Locale.ENGLISH); - try { - return valueOf(name); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException(e.getMessage() + - " (allowed values: " + - stream(values()).map(enumType -> enumType.toString()).collect(joining("; ")) + - ")"); - } - } - public EclipseBasedStepBuilder createBuilder(Provisioner provisioner) { return new EclipseBasedStepBuilder(NAME, " - " + toString(), provisioner, state -> formatterCall.apply(implementationClassName, state)); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 0c908965af..9c54dc107a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -488,13 +488,9 @@ public PrettierConfig prettier() { public class EclipseWtpConfig { private final EclipseBasedStepBuilder builder; - EclipseWtpConfig(EclipseWtpFormatterStep type) { - this(type, EclipseWtpFormatterStep.defaultVersion()); - } - EclipseWtpConfig(EclipseWtpFormatterStep type, String version) { builder = type.createBuilder(GradleProvisioner.fromProject(getProject())); - builder.setVersion(EclipseWtpFormatterStep.defaultVersion()); + builder.setVersion(version); addStep(builder.build()); } @@ -504,17 +500,14 @@ public void configFile(Object... configFiles) { builder.setPreferences(project.files(configFiles).getFiles()); replaceStep(builder.build()); } - } - public EclipseWtpConfig eclipseWtp(String type) { - return new EclipseWtpConfig(EclipseWtpFormatterStep.valueFrom(type)); + public EclipseWtpConfig eclipseWtp(EclipseWtpFormatterStep type) { + return eclipseWtp(type, EclipseWtpFormatterStep.defaultVersion()); } - public EclipseWtpConfig eclipseWtp(String type, String version) { - return new EclipseWtpConfig( - EclipseWtpFormatterStep.valueFrom(type), - version); + public EclipseWtpConfig eclipseWtp(EclipseWtpFormatterStep type, String version) { + return new EclipseWtpConfig(type, version); } /** Sets up a format task according to the values in this extension. */ diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java index adff349dcb..e7e3d0e386 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java @@ -28,7 +28,7 @@ public class EclipseWtp implements FormatterStepFactory { @Parameter - private String type; + private EclipseWtpFormatterStep type; @Parameter private String version; @@ -38,7 +38,7 @@ public class EclipseWtp implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - EclipseBasedStepBuilder eclipseConfig = EclipseWtpFormatterStep.valueFrom(type).createBuilder(stepConfig.getProvisioner()); + EclipseBasedStepBuilder eclipseConfig = type.createBuilder(stepConfig.getProvisioner()); eclipseConfig.setVersion(version == null ? EclipseWtpFormatterStep.defaultVersion() : version); if (null != files) { eclipseConfig.setPreferences( From 96372fc81b707610278135ba936ceb7772a27977 Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sat, 22 Dec 2018 09:37:34 +0100 Subject: [PATCH 3/7] Fixed Maven artifact resolver for dependencies without transitives. --- .../spotless/maven/ArtifactResolver.java | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java index 97fe0da001..1e2dd817b5 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java @@ -19,6 +19,7 @@ import static java.util.stream.Collectors.toSet; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -31,10 +32,9 @@ import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.collection.CollectRequest; -import org.eclipse.aether.graph.DefaultDependencyNode; import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.graph.Exclusion; import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResult; import org.eclipse.aether.resolution.DependencyRequest; import org.eclipse.aether.resolution.DependencyResolutionException; @@ -42,6 +42,8 @@ public class ArtifactResolver { + private final static Exclusion EXCLUDE_ALL_TRANSITIVES = new Exclusion("*", "*", "*", "*"); + private final RepositorySystem repositorySystem; private final RepositorySystemSession session; private final List repositories; @@ -66,47 +68,34 @@ public Set resolve(String mavenCoordinate) { * of the specified coordinates and optionally their transitive dependencies. */ public Set resolve(boolean withTransitives, Collection mavenCoordinates) { + Collection excludeTransitive = new ArrayList(1); + if (!withTransitives) { + excludeTransitive.add(EXCLUDE_ALL_TRANSITIVES); + } List dependencies = mavenCoordinates.stream() .map(coordinateString -> new DefaultArtifact(coordinateString)) - .map(artifact -> new Dependency(artifact, null)) + .map(artifact -> new Dependency(artifact, null, null, excludeTransitive)) .collect(toList()); CollectRequest collectRequest = new CollectRequest(dependencies, null, repositories); - List artifactResults; - if (withTransitives) { - DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null); - artifactResults = resolveArtifacts(dependencyRequest); - } else { - List artifactRequests = dependencies.stream() - .map(dependency -> new DefaultDependencyNode(dependency)) - .map(dependencyNode -> new ArtifactRequest(dependencyNode)) - .collect(toList()); - artifactResults = resolveArtifacts(artifactRequests); - } + DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null); + DependencyResult dependencyResult = resolveDependencies(dependencyRequest); - return artifactResults.stream() + return dependencyResult.getArtifactResults() + .stream() .peek(this::logResolved) .map(ArtifactResult::getArtifact) .map(Artifact::getFile) .collect(toSet()); } - private List resolveArtifacts(DependencyRequest dependencyRequest) { + private DependencyResult resolveDependencies(DependencyRequest dependencyRequest) { try { - DependencyResult dependencyResult = repositorySystem.resolveDependencies(session, dependencyRequest); - return dependencyResult.getArtifactResults(); + return repositorySystem.resolveDependencies(session, dependencyRequest); } catch (DependencyResolutionException e) { throw new ArtifactResolutionException("Unable to resolve dependencies", e); } } - private List resolveArtifacts(List artifactRequests) { - try { - return repositorySystem.resolveArtifacts(session, artifactRequests); - } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) { - throw new ArtifactResolutionException("Unable to resolve dependencies", e); - } - } - private void logResolved(ArtifactResult artifactResult) { if (log.isDebugEnabled()) { log.debug("Resolved artifact: " + artifactResult); From d873c36a40c5284e12cbd0443d028a32a8527de6 Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sat, 22 Dec 2018 09:40:02 +0100 Subject: [PATCH 4/7] Refactored existing WTP testing and marked CSS & XML extensions as deprecated. --- .../extra/wtp/EclipseWtpFormatterStep.java | 6 +++- .../wtp/EclipseWtpFormatterStepTest.java | 30 ++++++++----------- .../diffplug/spotless/css/CssDefaults.java | 7 ++++- .../diffplug/spotless/xml/XmlDefaults.java | 7 ++++- .../gradle/spotless/CssExtension.java | 8 +++++ .../gradle/spotless/SpotlessExtension.java | 16 ++++++++-- .../gradle/spotless/XmlExtension.java | 4 +++ .../spotless/maven/AbstractSpotlessMojo.java | 10 ++++--- .../com/diffplug/spotless/maven/css/Css.java | 5 +++- .../diffplug/spotless/maven/css/Eclipse.java | 3 ++ .../diffplug/spotless/maven/xml/Eclipse.java | 3 ++ .../com/diffplug/spotless/maven/xml/Xml.java | 7 +++-- .../spotless/maven/MavenIntegrationTest.java | 4 +++ .../maven/generic/LicenseHeaderTest.java | 4 +++ .../spotless/css/CssDefaultsTest.java | 2 ++ .../spotless/xml/XmlDefaultsTest.java | 2 ++ 16 files changed, 89 insertions(+), 29 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java index b9306e8e5c..65ce7e8a75 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java @@ -56,7 +56,11 @@ public static String defaultVersion() { return DEFAULT_VERSION; } - /** Provides default configuration for CSSformatter */ + /** + * Provides default configuration for CSSformatter. + * Method is deprecated. Use {@link EclipseWtpFormatterStep#createBuilder(Provisioner)} instead. + */ + @Deprecated public static EclipseBasedStepBuilder createCssBuilder(Provisioner provisioner) { return new EclipseBasedStepBuilder(NAME, " - css", provisioner, state -> applyWithoutFile("EclipseCssFormatterStepImpl", state)); } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java index fb136fa8f5..55d96fb028 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.Properties; import java.util.function.Consumer; -import java.util.function.Function; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,7 +32,6 @@ import org.junit.runners.Parameterized.Parameters; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.extra.EclipseBasedStepBuilder; import com.diffplug.spotless.extra.eclipse.EclipseCommonTests; @@ -44,29 +42,27 @@ public class EclipseWtpFormatterStepTest extends EclipseCommonTests { private enum WTP { // @formatter:off CSS( "body {\na: v; b: \nv;\n} \n", - "body {\n\ta: v;\n\tb: v;\n}", - EclipseWtpFormatterStep::createCssBuilder), + "body {\n\ta: v;\n\tb: v;\n}"), HTML( " \t \n ", - "\n\n\n\n\n\n", - EclipseWtpFormatterStep::createHtmlBuilder), + "\n\n\n\n\n\n"), JS( "function f( ) {\na.b(1,\n2);}", - "function f() {\n a.b(1, 2);\n}", - EclipseWtpFormatterStep::createJsBuilder), + "function f() {\n a.b(1, 2);\n}"), JSON( "{\"a\": \"b\", \"c\": { \"d\": \"e\",\"f\": \"g\"}}", - "{\n\t\"a\": \"b\",\n\t\"c\": {\n\t\t\"d\": \"e\",\n\t\t\"f\": \"g\"\n\t}\n}", - EclipseWtpFormatterStep::createJsonBuilder), - XML( " c", "\n\t c\n", - EclipseWtpFormatterStep::createXmlBuilder); + "{\n\t\"a\": \"b\",\n\t\"c\": {\n\t\t\"d\": \"e\",\n\t\t\"f\": \"g\"\n\t}\n}"), + XML( " c", "\n\t c\n"); // @formatter:on public final String input; public final String expectation; - public final Function builderMethod; - private WTP(String input, final String expectation, Function builderMethod) { + private WTP(String input, final String expectation) { this.input = input; this.expectation = expectation; - this.builderMethod = builderMethod; + } + + public EclipseBasedStepBuilder createBuilder() { + EclipseWtpFormatterStep stepType = EclipseWtpFormatterStep.valueOf(this.toString()); + return stepType.createBuilder(TestProvisioner.mavenCentral()); } } @@ -95,7 +91,7 @@ protected String getTestExpectation(String version) { @Override protected FormatterStep createStep(String version) { - EclipseBasedStepBuilder builder = wtp.builderMethod.apply(TestProvisioner.mavenCentral()); + EclipseBasedStepBuilder builder = wtp.createBuilder(); builder.setVersion(version); return builder.build(); } @@ -131,7 +127,7 @@ private FormatterStep createStepForDefaultVersion(Consumer config) t File tempFile = File.createTempFile("EclipseWtpFormatterStepTest-", ".properties"); OutputStream tempOut = new FileOutputStream(tempFile); configProps.store(tempOut, "test properties"); - EclipseBasedStepBuilder builder = wtp.builderMethod.apply(TestProvisioner.mavenCentral()); + EclipseBasedStepBuilder builder = wtp.createBuilder(); builder.setVersion(EclipseWtpFormatterStep.defaultVersion()); builder.setPreferences(Arrays.asList(tempFile)); return builder.build(); diff --git a/lib/src/main/java/com/diffplug/spotless/css/CssDefaults.java b/lib/src/main/java/com/diffplug/spotless/css/CssDefaults.java index 1550d39401..e0b42dba74 100644 --- a/lib/src/main/java/com/diffplug/spotless/css/CssDefaults.java +++ b/lib/src/main/java/com/diffplug/spotless/css/CssDefaults.java @@ -19,7 +19,12 @@ import java.util.Collections; import java.util.List; -/** Common utilities for CSS */ +/** + * Common utilities for CSS + *
+ * The CSS extension is discontinued. + */ +@Deprecated public class CssDefaults { //Prevent instantiation private CssDefaults() {}; diff --git a/lib/src/main/java/com/diffplug/spotless/xml/XmlDefaults.java b/lib/src/main/java/com/diffplug/spotless/xml/XmlDefaults.java index 249eacc8f1..d041d349c4 100644 --- a/lib/src/main/java/com/diffplug/spotless/xml/XmlDefaults.java +++ b/lib/src/main/java/com/diffplug/spotless/xml/XmlDefaults.java @@ -20,7 +20,12 @@ import java.util.List; import java.util.stream.Collectors; -/** Common utilities for XML */ +/** + * Common utilities for XML + *
+ * The XML extension is discontinued. + */ +@Deprecated public class XmlDefaults { //Prevent instantiation private XmlDefaults() {}; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CssExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CssExtension.java index 5c8ff77e6b..0152b738d7 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CssExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CssExtension.java @@ -23,6 +23,10 @@ import com.diffplug.spotless.extra.EclipseBasedStepBuilder; import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; +/** + * The CSS extension is deprecated. Use the generic {@link FormatExtension} instead. + */ +@Deprecated public class CssExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { static final String NAME = "css"; @@ -38,6 +42,10 @@ public EclipseConfig eclipse(String version) { return new EclipseConfig(version); } + /** + * The CSS Eclipse configuration is deprecated. Use the {@link FormatExtension.EclipseWtpConfig} instead. + */ + @Deprecated public class EclipseConfig { private final EclipseBasedStepBuilder builder; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index 9fa1d073d1..a9b7e82eb1 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java @@ -118,12 +118,24 @@ public void sql(Action closure) { configure(SqlExtension.NAME, SqlExtension.class, closure); } - /** Configures the special css-specific extension for CSS files. */ + /** + * Configures the special css-specific extension for CSS files. + *
+ * The CSS extension is discontinued. CSS formatters are now part of + * the generic {@link FormatExtension}. + */ + @Deprecated public void css(Action closure) { configure(CssExtension.NAME, CssExtension.class, closure); } - /** Configures the special xml-specific extension for XML/XSL/... files (XHTML is excluded). */ + /** + * Configures the special xml-specific extension for XML/XSL/... files (XHTML is excluded). + *
+ * The XML extension is discontinued. XML formatters are now part of + * the generic {@link FormatExtension}. + */ + @Deprecated public void xml(Action closure) { configure(XmlExtension.NAME, XmlExtension.class, closure); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/XmlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/XmlExtension.java index 233d514e6f..49672771c3 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/XmlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/XmlExtension.java @@ -23,6 +23,10 @@ import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; import com.diffplug.spotless.xml.XmlDefaults; +/** + * The XML extension is deprecated. Use the generic {@link FormatExtension} instead. + */ +@Deprecated public class XmlExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { static final String NAME = "xml"; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index c4047403df..0d2753ca94 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -37,13 +37,11 @@ import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.maven.cpp.Cpp; -import com.diffplug.spotless.maven.css.Css; import com.diffplug.spotless.maven.generic.Format; import com.diffplug.spotless.maven.generic.LicenseHeader; import com.diffplug.spotless.maven.java.Java; import com.diffplug.spotless.maven.kotlin.Kotlin; import com.diffplug.spotless.maven.scala.Scala; -import com.diffplug.spotless.maven.xml.Xml; public abstract class AbstractSpotlessMojo extends AbstractMojo { @@ -89,14 +87,18 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Kotlin kotlin; + /** The XML extension is discontinued. */ @Parameter - private Xml xml; + @Deprecated + private com.diffplug.spotless.maven.xml.Xml xml; @Parameter private Cpp cpp; + /** The CSS extension is discontinued. */ @Parameter - private Css css; + @Deprecated + private com.diffplug.spotless.maven.css.Css css; protected abstract void process(List files, Formatter formatter) throws MojoExecutionException; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/css/Css.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/css/Css.java index 6f43c2c42a..5307ab3447 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/css/Css.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/css/Css.java @@ -24,10 +24,13 @@ /** * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. - *

+ *
* It defines a formatter for CSS source files that can execute both language agnostic (e.g. {@link LicenseHeader}) * and css-specific (e.g. {@link Eclipse}) steps. + *
+ * The CSS extension is discontinued. CSS formatters are now part of the generic {@link FormatterFactory}. */ +@Deprecated public class Css extends FormatterFactory { private static final Set DEFAULT_INCLUDES = CssDefaults.FILE_FILTER diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/css/Eclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/css/Eclipse.java index 34fe14d76f..32865bef96 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/css/Eclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/css/Eclipse.java @@ -25,7 +25,10 @@ import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.maven.generic.EclipseWtp; +/** CSS Eclipse is deprecated. Use {@link EclipseWtp} instead.*/ +@Deprecated public class Eclipse implements FormatterStepFactory { @Parameter diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Eclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Eclipse.java index 9b18b3a56a..6e1071fb57 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Eclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Eclipse.java @@ -25,7 +25,10 @@ import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.maven.generic.EclipseWtp; +/** XML Eclipse is deprecated. Use {@link EclipseWtp} instead.*/ +@Deprecated public class Eclipse implements FormatterStepFactory { @Parameter diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Xml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Xml.java index a5a690326c..915a5331a8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Xml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/xml/Xml.java @@ -24,10 +24,13 @@ /** * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. - *

+ *
* It defines a formatter for XML/XSL/... source files that can execute both language agnostic (e.g. {@link LicenseHeader}) * and xml-specific (e.g. {@link Eclipse}) steps. - */ + *
+ * The XML extension is discontinued. XML formatters are now part of the generic {@link FormatterFactory}. + */ +@Deprecated public class Xml extends FormatterFactory { private static final Set DEFAULT_INCLUDES = XmlDefaults.FILE_FILTER diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationTest.java index 8f0b5b2171..8036b1899e 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationTest.java @@ -102,6 +102,8 @@ protected void writePomWithKotlinSteps(String... steps) throws IOException { writePom(groupWithSteps("kotlin", steps)); } + /** The XML extension is discontinued. */ + @Deprecated protected void writePomWithXmlSteps(String... steps) throws IOException { writePom(groupWithSteps("xml", steps)); } @@ -110,6 +112,8 @@ protected void writePomWithCppSteps(String... steps) throws IOException { writePom(groupWithSteps("cpp", steps)); } + /** The CSS extension is discontinued. */ + @Deprecated protected void writePomWithCssSteps(String... steps) throws IOException { writePom(groupWithSteps("css", steps)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java index 8f05932530..7897752502 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java @@ -50,7 +50,9 @@ public void fromContentCpp() throws Exception { assertFile(path).hasContent(cppLicense + '\n' + cppContent); } + /** The CSS extension is discontinued. */ @Test + @Deprecated public void fromContentCss() throws Exception { String license = "/* my license */"; writePomWithCssSteps( @@ -131,7 +133,9 @@ public void fromContentKotlin() throws Exception { assertFile(path).hasContent(KOTLIN_LICENSE_HEADER + '\n' + noLicenseHeader); } + /** XML extension is discontinued. */ @Test + @Deprecated public void fromContentXml() throws Exception { String license = " Licensed under Apache-2.0 "; writePomWithXmlSteps( diff --git a/testlib/src/test/java/com/diffplug/spotless/css/CssDefaultsTest.java b/testlib/src/test/java/com/diffplug/spotless/css/CssDefaultsTest.java index e5bc9beb61..21cf735fa0 100644 --- a/testlib/src/test/java/com/diffplug/spotless/css/CssDefaultsTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/css/CssDefaultsTest.java @@ -26,6 +26,8 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.generic.LicenseHeaderStep; +/** The CSS extension is discontinued. */ +@Deprecated public class CssDefaultsTest extends ResourceHarness { @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/xml/XmlDefaultsTest.java b/testlib/src/test/java/com/diffplug/spotless/xml/XmlDefaultsTest.java index 54d8098da7..cbdf86e445 100644 --- a/testlib/src/test/java/com/diffplug/spotless/xml/XmlDefaultsTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/xml/XmlDefaultsTest.java @@ -26,6 +26,8 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.generic.LicenseHeaderStep; +/** The XML extension is discontinued. */ +@Deprecated public class XmlDefaultsTest extends ResourceHarness { @Test From a44230b4e3cbc31bce858245eb407f62a8a0634d Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sat, 22 Dec 2018 12:13:39 +0100 Subject: [PATCH 5/7] Updated gradle/maven README.md --- plugin-gradle/README.md | 87 +++++++++++++++++------------------------ plugin-maven/README.md | 76 ++++++++++++++++++++++------------- 2 files changed, 85 insertions(+), 78 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c7626d075f..c01362bd91 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -79,8 +79,7 @@ Spotless can check and apply formatting to any plain-text file, using simple rul * Eclipse's [CDT](#eclipse-cdt) C/C++ code formatter * Eclipse's java code formatter (including style and import ordering) -* Eclipse's [WTP-CSS](#eclipse-wtp-css) CSS code formatter -* Eclipse's [WTP-XML](#eclipse-wtp-xml) XML code formatter +* Eclipse's [WTP](#eclipse-wtp) WTP code formatters * Google's [google-java-format](https://github.com/google/google-java-format) * [Groovy Eclipse](#groovy-eclipse)'s groovy code formatter * [FreshMark](https://github.com/diffplug/freshmark) (markdown with variables) @@ -321,55 +320,6 @@ spotless { Use the Eclipse to define the *Code Style preferences* (see [Eclipse documentation](https://www.eclipse.org/documentation/)). Within the preferences *Edit...* dialog, you can export your configuration as XML file, which can be used as a `configFile`. If no `configFile` is provided, the CDT default configuration is used. - - -## Applying to CSS sources - -```gradle -spotless { - css { - target '**/*.css' '**/*.css2'// Change file filter. By default files with 'css' extension are supported - eclipse().configFile './css-formatter.prefs' // Properties file of the Eclipse WTP formatter - // Use for example eclipse('4.7.3a') to specify a specific version of Eclipse, - // available versions are: https://github.com/diffplug/spotless/tree/master/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatters - // also supports license headers - licenseHeader '' // License header - licenseHeaderFile './license.txt' // License header file - } -} -``` - - - -### Eclipse [WTP](https://www.eclipse.org/webtools/) CSS formatter -Use Eclipse to define the *CSS Files* editor preferences (see [Eclipse documentation](http://help.eclipse.org/photon/topic/org.eclipse.wst.sse.doc.user/topics/tsrcedt025.html)) and the *Cleanup* preferences available in the *Source* menu (when editing a CSS file). The preferences are stored below your Eclipse workspace directory in `.metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.css.core.prefs`. Note that only the differences to the default configuration are stored within the file. Omit the 'configFile' entirely to use the default Eclipse configuration. - - - -## Applying to XML sources - -```gradle -spotless { - xml { - target '**/*.xml' // Change file filter. By default files with 'xml', 'xsl', 'xslt', 'wsdl', 'xsd', 'exsd' and 'xmi' extension are supported - eclipse().configFile './xml-formatter.prefs' // Properties file of the Eclipse WTP formatter - // Use for example eclipse('4.7.3a') to specify a specific version of Eclipse, - // available versions are: https://github.com/diffplug/spotless/tree/master/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatters - // also supports license headers - licenseHeader '' // License header - licenseHeaderFile './license.txt' // License header file - } -} -``` - - - -### Eclipse [WTP](https://www.eclipse.org/webtools/) XML formatter -Use Eclipse to define the *XML editor preferences* (see [Eclipse documentation](https://www.eclipse.org/documentation/)). The preferences are stored below your Eclipse workspace directory in `.metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.xml.core.prefs`. Note that only the differences to the default configuration are stored within the file. Omit the 'configFile' entirely to use the default Eclipse configuration. - -The Eclipse WTP formatter supports DTD/XSD restrictions on white spaces. For XSD/DTD lookup, relative and absolute XSD/DTD URIs are supported. Furthermore a user catalog can be configured using the `userCatalog` property key. Add the property to the preference file or add an additional preference or properties files as an additional argument to the `configFile`. - - ## Applying to Typescript source @@ -510,6 +460,41 @@ spotless { Spotless uses npm to install necessary packages locally. It runs prettier using [J2V8](https://github.com/eclipsesource/J2V8) internally after that. + + +## Applying [Eclipse WTP](https://www.eclipse.org/webtools/) to css | html | etc. + +The Eclipse [WTP](https://www.eclipse.org/webtools/) formatter can be applied as follows: + +```gradle +spotless { + format 'xml', { + target fileTree('.') { + include '**/*.xml', '**/*.xsd' + exclude '**/build/**' + } + // Use for example eclipseWtp('xml', '4.7.3a') to specify a specific version of Eclipse, + // available versions are: https://github.com/diffplug/spotless/tree/master/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatters + eclipseWtp('xml').configFile 'spotless.xml.prefs' 'spotless.common.properties' + } +} +``` +The WTP formatter accept multiple configuration files. All Eclipse configuration file formats are accepted as well as simple Java property files. Omit the `configFile` entirely to use the default Eclipse configuration. The following formatters and configurations are supported: + +| Type | Configuration | File location +| ---- | ------------------- | ------------- +| CSS | editor preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.css.core.prefs +| | cleanup preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.css.core.prefs +| HTML | editor preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.html.core.prefs +| | cleanup preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.html.core.prefs +| | embedded CSS | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.css.core.prefs +| | embedded JS | Use the export in the Eclipse editor configuration dialog +| JS | editor preferences | Use the export in the Eclipse editor configuration dialog +| JSON | editor preferences | .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.json.core.prefs +| XML | editor preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.xml.core.prefs + +Note that `HTML` should be used for `X-HTML` sources instead of `XML`. + ## License header options diff --git a/plugin-maven/README.md b/plugin-maven/README.md index fccaa93e45..8a2b40bb38 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -74,7 +74,7 @@ Spotless supports the following powerful formatters: * Eclipse's java code formatter (including style and import ordering) * Eclipse's [CDT](https://www.eclipse.org/cdt/) C/C++ code formatter -* Eclipse's [WTP](https://www.eclipse.org/webtools/) CSS and XML code formatter +* Eclipse's [WTP](https://www.eclipse.org/webtools/) Web-Tools code formatters * Google's [google-java-format](https://github.com/google/google-java-format) * User-defined license enforcement, regex replacement, etc. @@ -214,32 +214,6 @@ By default, all files matching `src/**/*.css` Ant style pattern will be formatte ``` Use Eclipse to define the *CSS Files* editor preferences (see [Eclipse documentation](http://help.eclipse.org/photon/topic/org.eclipse.wst.sse.doc.user/topics/tsrcedt025.html)) and the *Cleanup* preferences available in the *Source* menu (when editing a CSS file). The preferences are stored below your Eclipse workspace directory in `.metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.css.core.prefs`. Note that only the differences to the default configuration are stored within the file. If no `` is provided, the WTP default configuration is used. - - -## Applying to XML source - -By default, all files matching `src/**/*.` Ant style pattern will be formatted, whereas the file extensions `xml`, `xsl`, `xslt`, `wsdl`, `xsd`, `exsd`, `xmi` are supported. Each element under `` is a step, and they will be applied in the order specified. Every step is optional, and they will be applied in the order specified. - -```xml - - - - - <!-- Licensed under Apache-2.0 --> - ${basedir}/license-header - - - ${basedir}/eclipse-fmt.pref - - 4.7.3a - - - -``` -Use Eclipse to define the *XML editor preferences* (see [Eclipse documentation](https://www.eclipse.org/documentation/)). The preferences are stored below your Eclipse workspace directory in `.metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.xml.core.prefs`. Note that only the differences to the default configuration are stored within the file. If no `` is provided, the WTP default configuration is used. - -The Eclipse WTP formatter supports DTD/XSD restrictions on white spaces. For XSD/DTD lookup, relative and absolute XSD/DTD URIs are supported. Furthermore a user catalog can be configured using the `userCatalog` property key. Add the property to the preference ``. - ## Applying to custom sources @@ -301,6 +275,54 @@ By default, no Ant-Style include patterns are defined. Each element under ` ``` + + + +## Applying [Eclipse WTP](https://www.eclipse.org/webtools/) to css | html | etc. + +The Eclipse [WTP](https://www.eclipse.org/webtools/) formatter can be applied as follows: + +```xml + + + + + + src/**/resources/**/*.xml + src/**/resources/**/*.xsd + + + + + XML + + + ${basedir}/xml.prefs + ${basedir}/additional.properties + + + 4.7.3a + + + + +``` +The WTP formatter accept multiple configuration files. All Eclipse configuration file formats are accepted as well as simple Java property files. Omit the `` entirely to use the default Eclipse configuration. The following formatters and configurations are supported: + +| Type | Configuration | File location +| ---- | ------------------- | ------------- +| CSS | editor preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.css.core.prefs +| | cleanup preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.css.core.prefs +| HTML | editor preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.html.core.prefs +| | cleanup preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.html.core.prefs +| | embedded CSS | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.css.core.prefs +| | embedded JS | Use the export in the Eclipse editor configuration dialog +| JS | editor preferences | Use the export in the Eclipse editor configuration dialog +| JSON | editor preferences | .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.json.core.prefs +| XML | editor preferences | .metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.xml.core.prefs + +Note that `HTML` should be used for `X-HTML` sources instead of `XML`. + ## Line endings and encodings (invisible stuff) From df9ea152255e592a442753505b11db8e9405a70d Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sat, 22 Dec 2018 12:37:48 +0100 Subject: [PATCH 6/7] Finalized README changes (including the changes from master). Added PR to CHANGES. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 6 +++--- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 24 ------------------------ 5 files changed, 9 insertions(+), 27 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4de2ac7769..d85c455ffc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ You might be looking for: ### Version 1.18.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/)) +* CSS and XML extensions are discontinued ([#325](https://github.com/diffplug/spotless/pull/325)). + ### Version 1.17.0 - October 30th 2018 (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/1.17.0/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/1.17.0/), artifact [lib]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib), [lib-extra]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib-extra))) * Updated default eclipse-jdt from 4.7.3a to 4.9.0 ([#316](https://github.com/diffplug/spotless/pull/316)). New version addresses enum-tab formatting bug in 4.8 ([#314](https://github.com/diffplug/spotless/issues/314)). diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 8084f4da8e..ecb78ceeb1 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -2,6 +2,8 @@ ### Version 3.18.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/)) +* Provided eclipse-wtp formatters in generic formatter extension. ([#325](https://github.com/diffplug/spotless/pull/325)). This change obsoletes the CSS and XML extensions. + ### Version 3.17.0 - December 13th 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.17.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.17.0)) * Updated default eclipse-jdt from 4.7.3a to 4.9.0 ([#316](https://github.com/diffplug/spotless/pull/316)). New version addresses enum-tab formatting bug in 4.8 ([#314](https://github.com/diffplug/spotless/issues/314)). diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6adeac223a..e4c912b2c7 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -79,7 +79,7 @@ Spotless can check and apply formatting to any plain-text file, using simple rul * Eclipse's [CDT](#eclipse-cdt) C/C++ code formatter * Eclipse's java code formatter (including style and import ordering) -* Eclipse's [WTP](#eclipse-wtp) WTP code formatters +* Eclipse's [WTP](#eclipse-wtp) HTML, XML, ... code formatters * Google's [google-java-format](https://github.com/google/google-java-format) * [Groovy Eclipse](#groovy-eclipse)'s groovy code formatter * [FreshMark](https://github.com/diffplug/freshmark) (markdown with variables) @@ -472,9 +472,9 @@ spotless { target fileTree('.') { include '**/*.xml', '**/*.xsd' exclude '**/build/**' - } + } // Use for example eclipseWtp('xml', '4.7.3a') to specify a specific version of Eclipse, - // available versions are: https://github.com/diffplug/spotless/tree/master/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatters + // available versions are: https://github.com/diffplug/spotless/tree/master/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatters eclipseWtp('xml').configFile 'spotless.xml.prefs' 'spotless.common.properties' } } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6e1e263727..ea2f63b67c 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -2,6 +2,8 @@ ### Version 1.18.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/)) +* Provided eclipse-wtp formatters as part of custom source format element. ([#325](https://github.com/diffplug/spotless/pull/325)). This change obsoletes the CSS and XML source elements. + ### Version 1.17.0 - December 13th 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/1.17.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-maven-plugin/1.17.0)) * Updated default eclipse-jdt from 4.7.3a to 4.9.0 ([#316](https://github.com/diffplug/spotless/pull/316)). New version addresses enum-tab formatting bug in 4.8 ([#314](https://github.com/diffplug/spotless/issues/314)). diff --git a/plugin-maven/README.md b/plugin-maven/README.md index eaadd1e274..265c424fce 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -190,30 +190,6 @@ By default, all files matching `src/main/cpp/**/*.` and `src/test/cpp/**/*. ``` Use the Eclipse to define the *Code Style preferences* (see [Eclipse documentation](https://www.eclipse.org/documentation/)). Within the preferences *Edit...* dialog, you can export your configuration as XML file, which can be used as a configuration ``. If no `` is provided, the CDT default configuration is used. - - -## Applying to CSS source - -By default, all files matching `src/**/*.css` Ant style pattern will be formatted. Each element under `` is a step, and they will be applied in the order specified. Every step is optional, and they will be applied in the order specified. - -```xml - - - - - /* Licensed under Apache-2.0 */ - ${basedir}/license-header - - - ${basedir}/eclipse-fmt.pref - - 4.7.3a - - - -``` -Use Eclipse to define the *CSS Files* editor preferences (see [Eclipse documentation](http://help.eclipse.org/photon/topic/org.eclipse.wst.sse.doc.user/topics/tsrcedt025.html)) and the *Cleanup* preferences available in the *Source* menu (when editing a CSS file). The preferences are stored below your Eclipse workspace directory in `.metadata/.plugins/org.eclipse.core.runtime/org.eclipse.wst.css.core.prefs`. Note that only the differences to the default configuration are stored within the file. If no `` is provided, the WTP default configuration is used. - ## Applying to custom sources From 5133fe118334db9a023f6fa721a6dd5f17e408c1 Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sun, 23 Dec 2018 14:48:44 +0100 Subject: [PATCH 7/7] Add missing @Deprecated statements. --- .../extra/wtp/EclipseWtpFormatterStep.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java index 65ce7e8a75..12f05abb81 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java @@ -65,22 +65,38 @@ public static EclipseBasedStepBuilder createCssBuilder(Provisioner provisioner) return new EclipseBasedStepBuilder(NAME, " - css", provisioner, state -> applyWithoutFile("EclipseCssFormatterStepImpl", state)); } - /** Provides default configuration for HTML formatter */ + /** + * Provides default configuration for HTML formatter. + * Method is deprecated. Use {@link EclipseWtpFormatterStep#createBuilder(Provisioner)} instead. + */ + @Deprecated public static EclipseBasedStepBuilder createHtmlBuilder(Provisioner provisioner) { return HTML.createBuilder(provisioner); } - /** Provides default configuration for Java Script formatter */ + /** + * Provides default configuration for Java Script formatter. + * Method is deprecated. Use {@link EclipseWtpFormatterStep#createBuilder(Provisioner)} instead. + */ + @Deprecated public static EclipseBasedStepBuilder createJsBuilder(Provisioner provisioner) { return JS.createBuilder(provisioner); } - /** Provides default configuration for JSON formatter */ + /** + * Provides default configuration for JSON formatter. + * Method is deprecated. Use {@link EclipseWtpFormatterStep#createBuilder(Provisioner)} instead. + */ + @Deprecated public static EclipseBasedStepBuilder createJsonBuilder(Provisioner provisioner) { return JSON.createBuilder(provisioner); } - /** Provides default configuration for XML formatter */ + /** + * Provides default configuration for XML formatter. + * Method is deprecated. Use {@link EclipseWtpFormatterStep#createBuilder(Provisioner)} instead. + */ + @Deprecated public static EclipseBasedStepBuilder createXmlBuilder(Provisioner provisioner) { return XML.createBuilder(provisioner); }