From 52a8218fe099b172d98d306b3d8ca8a40a64066d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 00:56:56 -0700 Subject: [PATCH 1/4] Get EclipseWTP to build under Equo. --- .../extra/eclipse/wtp/html/package-info.java | 20 -- .../eclipse/wtp/sse/ContentTypeManager.java | 235 ------------------ .../extra/eclipse/wtp/sse/package-info.java | 20 -- lib-extra/build.gradle | 24 +- .../extra/wtp/EclipseWtpFormatterStep.java | 47 +++- .../wtp/EclipseWtpFormatterStepTest.java | 6 +- .../wtp/EclipseCssFormatterStepImpl.java | 32 +-- .../wtp/EclipseHtmlFormatterStepImpl.java | 60 +---- .../wtp/EclipseJsFormatterStepImpl.java | 72 +----- .../wtp/EclipseJsonFormatterStepImpl.java | 29 +-- .../wtp/EclipseXmlFormatterStepImpl.java | 83 ++----- .../extra/eclipse/wtp/SolsticeSetup.java | 55 ++++ .../eclipse/wtp/html/JsRegionProcessor.java | 6 +- .../wtp/html/StructuredDocumentProcessor.java | 12 +- .../extra/eclipse/wtp/package-info.java | 0 .../extra/eclipse/wtp/sse/CleanupStep.java | 56 +---- .../eclipse/wtp/sse/PluginPreferences.java | 2 +- .../PreventExternalURIResolverExtension.java | 2 +- .../gradle/spotless/FormatExtension.java | 4 +- .../spotless/maven/generic/EclipseWtp.java | 6 +- 20 files changed, 172 insertions(+), 599 deletions(-) delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/package-info.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/ContentTypeManager.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/package-info.java rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java (70%) rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java (66%) rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java (70%) rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java (79%) rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java (53%) create mode 100644 lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/SolsticeSetup.java rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java (94%) rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java (95%) rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java (100%) rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java (56%) rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java (99%) rename {_ext/eclipse-wtp/src/main => lib-extra/src/wtp}/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java (98%) diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/package-info.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/package-info.java deleted file mode 100644 index 770e126a1b..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ -/** Eclipse WTP HTML formatter helper */ -@ParametersAreNonnullByDefault -package com.diffplug.spotless.extra.eclipse.wtp.html; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/ContentTypeManager.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/ContentTypeManager.java deleted file mode 100644 index 499a147ae9..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/ContentTypeManager.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * 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.extra.eclipse.wtp.sse; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeSettings; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS; -import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML; -import org.eclipse.wst.json.core.contenttype.ContentTypeIdForJSON; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; - -import com.diffplug.spotless.extra.eclipse.base.service.NoContentTypeSpecificHandling; - -/** - - * WTP ModelHandlerRegistry uses the content type mamanger clean-up formatters - * to provide association of content to content type related functionality. - *

- * Preference lookup per content type is accomplished via the - * Eclipse PreferencesService, which must be provided in combination with - * this service. - *

- * The input byte steam encoding detection is accomplished by the - * content type manager. Normally the encoding is bount do a document/file. - * Spotless applies the formatting on strings already decoded. - * The WTP AbstractStructuredCleanupProcessor provides for non-documents - * a clean-up function converting the decoded string into an UTF-8 encoded byte stream. - * WTP AbstractDocumentLoader uses content type mamanger to determine the encoding - * of the input stream. - * Only the steps are affected that are using the - * AbstractStructuredCleanupProcessor. All other steps creating an empty document - * (e.g. via WTP AbstractDocumentLoader) and setting the textual content of the new document. - * - * @see org.eclipse.core.internal.preferences.PreferencesService - * @see org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor - * @see org.eclipse.wst.sse.core.internal.document.AbstractDocumentLoader - * @see org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry - */ -class ContentTypeManager extends NoContentTypeSpecificHandling { - private final Map id2Object; - private final IContentType processorStepType; - private final IContentDescription processorStepDescription; - - /** - * Content type manager as required for cleanup steps. - * @param formatterContentTypeID The content type of the formatter step - */ - ContentTypeManager(String formatterContentTypeID) { - id2Object = new HashMap(); - Arrays.asList( - ContentTypeIdForCSS.ContentTypeID_CSS, - ContentTypeIdForXML.ContentTypeID_XML, - ContentTypeIdForHTML.ContentTypeID_HTML, - ContentTypeIdForJSON.ContentTypeID_JSON) - .stream().forEach(id -> id2Object.put(id, new ContentTypeId(id))); - processorStepType = id2Object.get(formatterContentTypeID); - if (null == processorStepType) { - throw new IllegalArgumentException("The manager does not support content type " + formatterContentTypeID); - } - processorStepDescription = new StringDescription(processorStepType); - } - - @Override - public IContentType getContentType(String contentTypeIdentifier) { - /* - * It is OK to return null here since the manager is only used as an additional - * helper to alter default behavior. - */ - return id2Object.get(contentTypeIdentifier); - } - - @Override - public IContentType findContentTypeFor(InputStream contents, String fileName) throws IOException { - //We only format things here with the given processor, so this answer is always correct. - return processorStepType; - } - - @Override - public IContentDescription getDescriptionFor(InputStream contents, String fileName, QualifiedName[] options) throws IOException { - return processorStepDescription; - } - - private static class StringDescription implements IContentDescription { - - private final IContentType type; - - public StringDescription(IContentType type) { - this.type = type; - } - - @Override - public boolean isRequested(QualifiedName key) { - return false; //Don't use set Property - } - - @Override - public String getCharset() { - //Called by AbstractDocumentLoader.readInputStream - return "UTF-8"; //UTF-8 encoded by AbstractStructuredCleanupProcessor.cleanupContent - } - - @Override - public IContentType getContentType() { - return type; - } - - @Override - public Object getProperty(QualifiedName key) { - return null; //Assume that the property map is empty - } - - @Override - public void setProperty(QualifiedName key, Object value) { - throw new IllegalArgumentException("Content description key cannot be set: " + key); - } - } - - /** - * The WTP uses the manager mainly for ID mapping, so most of the methods are not used. - * Actually it has a hand stitched way for transforming the content type ID - * {@code org.eclipse.wst...source} to the plugin ID {@code org.eclipse.wst...core}. - * @see org.eclipse.wst.sse.core.internal.encoding.ContentBasedPreferenceGateway - */ - private static class ContentTypeId implements IContentType { - - private final String id; - - ContentTypeId(String id) { - this.id = id; - } - - @Override - public void addFileSpec(String fileSpec, int type) throws CoreException {} - - @Override - public void removeFileSpec(String fileSpec, int type) throws CoreException {} - - @Override - public void setDefaultCharset(String userCharset) throws CoreException {} - - @Override - public boolean isUserDefined() { - return false; - } - - @Override - public IContentType getBaseType() { - return null; - } - - @Override - public IContentDescription getDefaultDescription() { - return null; - } - - @Override - public IContentDescription getDescriptionFor(InputStream contents, QualifiedName[] options) throws IOException { - return null; - } - - @Override - public IContentDescription getDescriptionFor(Reader contents, QualifiedName[] options) throws IOException { - return null; - } - - @Override - public String getDefaultCharset() { - return null; - } - - @Override - public String[] getFileSpecs(int type) { - return null; - } - - @Override - public String getId() { - return id; - } - - @Override - public String getName() { - return id; - } - - @Override - public boolean isAssociatedWith(String fileName) { - return false; - } - - @Override - public boolean isAssociatedWith(String fileName, IScopeContext context) { - return false; - } - - @Override - public boolean isKindOf(IContentType another) { - if (null == another) { - return false; - } - return this.id.equals(another.getId()); - } - - @Override - public IContentTypeSettings getSettings(IScopeContext context) throws CoreException { - return null; - } - - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/package-info.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/package-info.java deleted file mode 100644 index 931b7e085e..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ -/** Eclipse WTP Structured Source Editing (SEE) formatter helper */ -@ParametersAreNonnullByDefault -package com.diffplug.spotless.extra.eclipse.wtp.sse; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index d2d6542a52..6a4d5a915b 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -42,7 +42,8 @@ tasks.withType(Test).configureEach { def NEEDS_P2_DEPS = [ 'jdt', 'groovy', - 'cdt' + 'cdt', + 'wtp' ] for (needsP2 in NEEDS_P2_DEPS) { sourceSets.register(needsP2) { @@ -85,6 +86,27 @@ p2deps { p2repo 'https://download.eclipse.org/tools/cdt/releases/10.7/' install 'org.eclipse.cdt.core' } + into 'wtpCompileOnly', { + p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' + p2repo 'https://download.eclipse.org/webtools/repository/2022-12/' + // XML/HTML Formatter - Dependencies + install 'org.eclipse.wst.xml.core' // DefaultXMLPartitionFormatter and XMLAssociationProvider + install 'org.eclipse.wst.sse.core' // Structure models + install 'org.eclipse.wst.common.uriresolver' // URI resolver for model queries + install 'org.eclipse.wst.dtd.core' // Support DTD extensions + // XML Formatter - Dependencies + install 'org.eclipse.wst.xsd.core' // Support XSD extensions + // JS Formatter - Dependencies + install 'org.eclipse.wst.jsdt.core' // DefaultCodeFormatter and related + install 'org.eclipse.wst.jsdt.ui' // Functionality to format comments + // JSON Formatter - Dependencies + install 'org.eclipse.wst.json.core' // FormatProcessorJSON and related + install 'org.eclipse.json' // Provides JSON node interfaces + // CSS Formatter - Dependencies + install 'org.eclipse.wst.css.core' // FormatProcessorCSS and related + // HTML Formatter - Dependencies + install 'org.eclipse.wst.html.core' // HTMLFormatProcessorImpl and related + } } // we'll hold the core lib to a high standard 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 441e6df878..8680c68bb4 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,9 @@ import com.diffplug.spotless.Jvm; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.ThrowingEx; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; + +import dev.equo.solstice.p2.P2Model; /** Formatter step which calls out to the Groovy-Eclipse formatter. */ public enum EclipseWtpFormatterStep { @@ -42,24 +44,49 @@ public enum EclipseWtpFormatterStep { private static final String FORMATTER_METHOD = "format"; private final String implementationClassName; - private final ThrowingEx.BiFunction formatterCall; + private final ThrowingEx.BiFunction formatterCall; - EclipseWtpFormatterStep(String implementationClassName, ThrowingEx.BiFunction formatterCall) { + EclipseWtpFormatterStep(String implementationClassName, ThrowingEx.BiFunction formatterCall) { this.implementationClassName = implementationClassName; this.formatterCall = formatterCall; } - public EclipseBasedStepBuilder createBuilder(Provisioner provisioner) { - return new EclipseBasedStepBuilder(NAME, " - " + toString(), provisioner, state -> formatterCall.apply(implementationClassName, state)); + public EquoBasedStepBuilder createBuilder(Provisioner provisioner) { + return new EquoBasedStepBuilder(NAME + " - " + name(), provisioner, state -> formatterCall.apply(implementationClassName, state)) { + @Override + protected P2Model model(String version) { + var model = new P2Model(); + addPlatformRepo(model, "4.26"); + model.addP2Repo("https://download.eclipse.org/webtools/repository/2022-12/"); + // XML/HTML Formatter - Dependencies + model.getInstall().add("org.eclipse.wst.xml.core"); // DefaultXMLPartitionFormatter and XMLAssociationProvider + model.getInstall().add("org.eclipse.wst.sse.core"); // Structure models + model.getInstall().add("org.eclipse.wst.common.uriresolver"); // URI resolver for model queries + model.getInstall().add("org.eclipse.wst.dtd.core"); // Support DTD extensions + // XML Formatter - Dependencies + model.getInstall().add("org.eclipse.wst.xsd.core"); // Support XSD extensions + // JS Formatter - Dependencies + model.getInstall().add("org.eclipse.wst.jsdt.core"); // DefaultCodeFormatter and related + model.getInstall().add("org.eclipse.wst.jsdt.ui"); // Functionality to format comments + // JSON Formatter - Dependencies + model.getInstall().add("org.eclipse.wst.json.core"); // FormatProcessorJSON and related + model.getInstall().add("org.eclipse.json"); // Provides JSON node interfaces + // CSS Formatter - Dependencies + model.getInstall().add("org.eclipse.wst.css.core"); // FormatProcessorCSS and related + // HTML Formatter - Dependencies + model.getInstall().add("org.eclipse.wst.html.core"); // HTMLFormatProcessorImpl and related + return model; + } + }; } public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); } - private static FormatterFunc applyWithoutFile(String className, EclipseBasedStepBuilder.State state) throws Exception { + private static FormatterFunc applyWithoutFile(String className, EquoBasedStepBuilder.State state) throws Exception { JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion()); - Class formatterClazz = state.loadClass(FORMATTER_PACKAGE + className); + Class formatterClazz = state.getJarState().getClassLoader().loadClass(FORMATTER_PACKAGE + className); Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences()); Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class); return input -> { @@ -73,9 +100,9 @@ private static FormatterFunc applyWithoutFile(String className, EclipseBasedStep }; } - private static FormatterFunc applyWithFile(String className, EclipseBasedStepBuilder.State state) throws Exception { + private static FormatterFunc applyWithFile(String className, EquoBasedStepBuilder.State state) throws Exception { JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion()); - Class formatterClazz = state.loadClass(FORMATTER_PACKAGE + className); + Class formatterClazz = state.getJarState().getClassLoader().loadClass(FORMATTER_PACKAGE + className); Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences()); Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class, String.class); return JVM_SUPPORT.suggestLaterVersionOnError(state.getSemanticVersion(), new FormatterFunc.NeedsFile() { 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 9517c24121..ae3d4c258a 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,12 +32,12 @@ import com.diffplug.spotless.Jvm; import com.diffplug.spotless.TestProvisioner; -import com.diffplug.spotless.extra.eclipse.EclipseResourceHarness; +import com.diffplug.spotless.extra.eclipse.EquoResourceHarness; public class EclipseWtpFormatterStepTest { private final static Jvm.Support JVM_SUPPORT = Jvm. support("Oldest Version").add(8, "4.8.0"); - private static class NestedTests extends EclipseResourceHarness { + private static class NestedTests extends EquoResourceHarness { public NestedTests(String unformatted, String formatted, EclipseWtpFormatterStep kind) { super(kind.createBuilder(TestProvisioner.mavenCentral()), unformatted, formatted); } diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java similarity index 70% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java index fb0e1ffeac..476528cdcc 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,15 +22,18 @@ import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceInitializer; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; /** Formatter step which calls out to the Eclipse CSS cleanup and formatter. */ public class EclipseCssFormatterStepImpl extends CleanupStep { + static { + SolsticeSetup.init(); + } public EclipseCssFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor(), new FrameworkConfig(properties)); + super(new CleanupProcessor()); + PluginPreferences.configure(CSSCorePlugin.getDefault(), new CSSCorePreferenceInitializer(), properties); PluginPreferences.assertNoChanges(CSSCorePlugin.getDefault(), properties); } @@ -54,27 +57,4 @@ public AbstractStructuredCleanupProcessor get() { return this; } } - - static class FrameworkConfig extends CleanupStep.FrameworkConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - this.properties = properties; - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - super.activatePlugins(config); - activateCssPlugins(config); - } - - static void activateCssPlugins(SpotlessEclipsePluginConfig config) { - config.add(new CSSCorePlugin()); - } - - @Override - public void customize() { - PluginPreferences.configure(CSSCorePlugin.getDefault(), new CSSCorePreferenceInitializer(), properties); - } - } } diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java similarity index 66% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java index 4b7f592c3c..93d5ed8330 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,17 +15,12 @@ */ package com.diffplug.spotless.extra.eclipse.wtp; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - -import java.util.Arrays; -import java.util.List; import java.util.Properties; import org.eclipse.wst.html.core.internal.HTMLCorePlugin; import org.eclipse.wst.html.core.internal.cleanup.HTMLCleanupProcessorImpl; import org.eclipse.wst.html.core.internal.encoding.HTMLDocumentLoader; import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl; -import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceInitializer; import org.eclipse.wst.html.core.text.IHTMLPartitions; import org.eclipse.wst.jsdt.core.JavaScriptCore; import org.eclipse.wst.jsdt.core.ToolFactory; @@ -34,9 +29,6 @@ import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseCoreConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; import com.diffplug.spotless.extra.eclipse.wtp.html.JsRegionProcessor; import com.diffplug.spotless.extra.eclipse.wtp.html.StructuredDocumentProcessor; import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; @@ -44,12 +36,15 @@ /** Formatter step which calls out to the Eclipse HTML cleanup and formatter. */ public class EclipseHtmlFormatterStepImpl extends CleanupStep { + static { + SolsticeSetup.init(); + } private final String htmlFormatterIndent; private final CodeFormatter jsFormatter; public EclipseHtmlFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor(), new FrameworkConfig(properties)); + super(new CleanupProcessor()); PluginPreferences.assertNoChanges(HTMLCorePlugin.getDefault(), properties); htmlFormatterIndent = ((CleanupProcessor) processorAccessor).getIndent(); jsFormatter = ToolFactory.createCodeFormatter(JavaScriptCore.getOptions(), ToolFactory.M_FORMAT_EXISTING); @@ -61,7 +56,7 @@ public String format(String raw) throws Exception { // Not sure how Eclipse binds the JS formatter to HTML. The formatting is accomplished manually instead. IStructuredDocument document = (IStructuredDocument) new HTMLDocumentLoader().createNewStructuredDocument(); - document.setPreferredLineDelimiter(LINE_DELIMITER); + document.setPreferredLineDelimiter("\n"); document.set(raw); StructuredDocumentProcessor jsProcessor = new StructuredDocumentProcessor( document, IHTMLPartitions.SCRIPT, JsRegionProcessor.createFactory(htmlFormatterIndent)); @@ -112,48 +107,5 @@ protected IStructuredFormatProcessor getFormatProcessor() { String getIndent() { return processor.getFormatPreferences().getIndent(); } - - } - - private static class FrameworkConfig extends CleanupStep.FrameworkConfig { - private final List dependentConfigs; - private final Properties properties; - - public FrameworkConfig(Properties properties) { - dependentConfigs = Arrays.asList( - new EclipseCssFormatterStepImpl.FrameworkConfig(properties), - new EclipseJsFormatterStepImpl.FrameworkConfig(properties), - new EclipseXmlFormatterStepImpl.FrameworkConfig(properties)); - this.properties = properties; - } - - @Override - public void registerBundles(SpotlessEclipseCoreConfig config) { - EclipseJsFormatterStepImpl.FrameworkConfig.registerNonHeadlessBundles(config); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - super.activatePlugins(config); - EclipseCssFormatterStepImpl.FrameworkConfig.activateCssPlugins(config); - EclipseJsFormatterStepImpl.FrameworkConfig.activateJsPlugins(config); - /* - * The HTML formatter only uses the DOCTYPE/SCHEMA for content model selection. - * Hence no external URIs are required. - */ - boolean allowExternalURI = false; - EclipseXmlFormatterStepImpl.FrameworkConfig.activateXmlPlugins(config, allowExternalURI); - config.add(new HTMLCorePlugin()); - } - - @Override - public void customize() { - dependentConfigs.stream().forEach(c -> { - c.customize(); - }); - PluginPreferences.configure(HTMLCorePlugin.getDefault(), new HTMLCorePreferenceInitializer(), properties); - } - } - } diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java similarity index 70% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java index c101b1a27a..f60379c226 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,9 @@ */ package com.diffplug.spotless.extra.eclipse.wtp; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.DefaultBundles.*; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - import java.util.AbstractMap.SimpleEntry; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.Properties; @@ -49,17 +45,14 @@ import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingContext; import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingStrategy; import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions; -import org.osgi.framework.Bundle; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseCoreConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; /** Formatter step which calls out to the Eclipse JS formatter. */ public class EclipseJsFormatterStepImpl { + static { + SolsticeSetup.init(); + } private final static String[] COMMENT_TYPES = { IJavaScriptPartitions.JAVA_DOC, @@ -79,9 +72,8 @@ public class EclipseJsFormatterStepImpl { private final Set commentTypesToBeFormatted; public EclipseJsFormatterStepImpl(Properties properties) throws Exception { - SpotlessEclipseFramework.setup(new FrameworkConfig(properties)); - PluginPreferences.assertNoChanges(JavaScriptCore.getPlugin(), properties); - options = JavaScriptCore.getOptions(); + PluginPreferences.store(JavaScriptCore.getPlugin(), properties); + options = JavaScriptCore.getDefaultOptions(); commentTypesToBeFormatted = OPTION_2_COMMENT_TYPE.entrySet().stream().filter(x -> DefaultCodeFormatterConstants.TRUE.equals(options.get(x.getKey()))).map(x -> x.getValue()).collect(Collectors.toSet()); formatter = ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_EXISTING); } @@ -91,7 +83,7 @@ public String format(String raw) throws Exception { raw = formatComments(raw); // The comment formatter messed up the code a little bit (adding some line breaks). Now we format the code. IDocument doc = new Document(raw); - TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, raw, 0, raw.length(), 0, LINE_DELIMITER); + TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, raw, 0, raw.length(), 0, "\n"); if (edit == null) { throw new IllegalArgumentException("Invalid JavaScript syntax for formatting."); } else { @@ -134,54 +126,4 @@ private String formatComments(String raw) { return raw; } } - - static class FrameworkConfig implements SpotlessEclipseConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - this.properties = properties; - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(this.getClass().getPackage().getName()); - } - - @Override - public void registerBundles(SpotlessEclipseCoreConfig config) { - registerNonHeadlessBundles(config); - } - - static void registerNonHeadlessBundles(SpotlessEclipseCoreConfig config) { - //The JS model requires the JDT indexer, hence a headless Eclipse cannot be used. - config.add(PLATFORM, Bundle.ACTIVE); - config.add(REGISTRY, PREFERENCES, COMMON); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - activateJsPlugins(config); - } - - static void activateJsPlugins(SpotlessEclipsePluginConfig config) { - // The JS core uses EFS for determination of temporary storage location - config.add(org.eclipse.core.filesystem.EFS.class); - // The JS core provides the JSDT formatter - config.add(new org.eclipse.wst.jsdt.core.JavaScriptCore()); - } - - @Override - @SuppressWarnings("unchecked") - public void customize() { - PluginPreferences.store(JavaScriptCore.getPlugin(), properties); - Hashtable options = JavaScriptCore.getDefaultOptions(); - options.putAll(DefaultCodeFormatterConstants.getJSLintConventionsSettings()); - options.putAll(new HashMap(properties)); - JavaScriptCore.setOptions(options); - } - - } - } diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java similarity index 79% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java index 91d8516b24..52c07b66b4 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,8 @@ import org.eclipse.wst.json.core.JSONCorePlugin; import org.eclipse.wst.json.core.cleanup.CleanupProcessorJSON; import org.eclipse.wst.json.core.format.FormatProcessorJSON; -import org.eclipse.wst.json.core.internal.preferences.JSONCorePreferenceInitializer; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; @@ -34,9 +32,12 @@ * Note that the cleanup is escaped, since it has known bugs and is currently not used by Eclipse. */ public class EclipseJsonFormatterStepImpl extends CleanupStep { + static { + SolsticeSetup.init(); + } public EclipseJsonFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor(), new FrameworkConfig(properties)); + super(new CleanupProcessor()); PluginPreferences.assertNoChanges(JSONCorePlugin.getDefault(), properties); } @@ -90,24 +91,4 @@ public String cleanupContent(String input) throws IOException, CoreException { return formatter.formatContent(input); } } - - private static class FrameworkConfig extends CleanupStep.FrameworkConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - this.properties = properties; - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - super.activatePlugins(config); - config.add(new JSONCorePlugin()); - } - - @Override - public void customize() { - PluginPreferences.configure(JSONCorePlugin.getDefault(), new JSONCorePreferenceInitializer(), properties); - } - } - } diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java similarity index 53% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java index 57fce0d503..f3578a9ed6 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,12 @@ */ package com.diffplug.spotless.extra.eclipse.wtp; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.*; import java.util.Properties; import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.text.edits.TextEdit; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.dtd.core.internal.DTDCorePlugin; import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument; @@ -39,89 +36,38 @@ import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser; import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceInitializer; import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML; -import org.eclipse.wst.xsd.core.internal.XSDCorePlugin; -import org.eclipse.xsd.util.XSDSchemaBuildingTools; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PreventExternalURIResolverExtension; /** Formatter step which calls out to the Eclipse XML formatter. */ public class EclipseXmlFormatterStepImpl { + static { + SolsticeSetup.init(); + } + private final DefaultXMLPartitionFormatter formatter; private final XMLFormattingPreferences preferences; private final INodeAdapterFactory xmlAdapterFactory; - public EclipseXmlFormatterStepImpl(Properties properties) throws Exception { - SpotlessEclipseFramework.setup(new FrameworkConfig(properties)); + public EclipseXmlFormatterStepImpl(Properties properties) { + SolsticeSetup.init(); PluginPreferences.assertNoChanges(XMLCorePlugin.getDefault(), properties); preferences = new XMLFormattingPreferences(); formatter = new DefaultXMLPartitionFormatter(); //The adapter factory maintains the common CMDocumentCache xmlAdapterFactory = new ModelQueryAdapterFactoryForXML(); - } - - static class FrameworkConfig implements SpotlessEclipseConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - /* - * The cache is only used for system catalogs, but not for user catalogs. - * It requires the SSECorePLugin, which has either a big performance overhead, - * or needs a dirty mocking (we don't really require its functions but it needs to be there). - * So we disable the cache for now. - * This might cause a performance drop in case for example XSDs are formatted. - * But these standard/system restriction files contain anyway no formatting rules. - * So in case of performance inconveniences, we could add a Spotless property to disable the - * XSD/DTD parsing entirely (for example by adding an own URI resolver). - */ - properties.setProperty(CMDOCUMENT_GLOBAL_CACHE_ENABLED, Boolean.toString(false)); - this.properties = properties; - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(EclipseXmlFormatterStepImpl.class.getPackage().getName()); - } - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - activateXmlPlugins(config, PluginPreferences.isExternalUriAllowed(properties)); - } - - static void activateXmlPlugins(SpotlessEclipsePluginConfig config, boolean allowExternalURI) { - //The WST XML formatter - config.add(new XMLCorePlugin()); - //XSDs/DTDs must be resolved by URI - config.add(new URIResolverPlugin()); - //Support formatting based on DTD restrictions - config.add(new DTDCorePlugin()); - //Support formatting based on XSD restrictions - config.add(new XSDCorePlugin()); - if (!allowExternalURI) { - config.add(new PreventExternalURIResolverExtension()); - } - } - - @Override - public void customize() { - //Register required EMF factories - XSDSchemaBuildingTools.getXSDFactory(); - PluginPreferences.configure(XMLCorePlugin.getDefault(), new XMLCorePreferenceInitializer(), properties); - PluginPreferences.configureCatalog(properties, (Catalog) XMLCorePlugin.getDefault().getDefaultXMLCatalog()); - } - - }; + PluginPreferences.configure(XMLCorePlugin.getDefault(), new XMLCorePreferenceInitializer(), properties); + PluginPreferences.configureCatalog(properties, (Catalog) XMLCorePlugin.getDefault().getDefaultXMLCatalog()); + // if (!allowExternalURI) { + // config.add(new PreventExternalURIResolverExtension()); + // } + } /** Formatting XML string resolving URIs according its base location */ public String format(String raw, String baseLocation) throws Exception { IStructuredDocument document = new BasicStructuredDocument(new XMLSourceParser()); - document.setPreferredLineDelimiter(LINE_DELIMITER); + document.setPreferredLineDelimiter("\n"); IDocumentPartitioner partitioner = new StructuredTextPartitionerForXML(); document.setDocumentPartitioner(new StructuredTextPartitionerForXML()); partitioner.connect(document); @@ -136,5 +82,4 @@ public String format(String raw, String baseLocation) throws Exception { formatterChanges.apply(document); return document.get(); } - } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/SolsticeSetup.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/SolsticeSetup.java new file mode 100644 index 0000000000..a5e8d4237b --- /dev/null +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/SolsticeSetup.java @@ -0,0 +1,55 @@ +/* + * Copyright 2023 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.extra.eclipse.wtp; + +import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.CMDOCUMENT_GLOBAL_CACHE_ENABLED; + +import java.io.IOException; +import java.nio.file.Files; +import java.util.Map; + +import org.eclipse.osgi.internal.location.EquinoxLocations; +import org.osgi.framework.Constants; + +import dev.equo.solstice.NestedJars; +import dev.equo.solstice.ShimIdeBootstrapServices; +import dev.equo.solstice.Solstice; +import dev.equo.solstice.p2.CacheLocations; + +public class SolsticeSetup { + static { + NestedJars.setToWarnOnly(); + NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.nestedJars()); + try { + var solstice = Solstice.findBundlesOnClasspath(); + solstice.warnAndModifyManifestsToFix(); + Map props = Map.of("osgi.nl", "en_US", + Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT, + EquinoxLocations.PROP_INSTANCE_AREA, Files.createTempDirectory("spotless-wtp").toAbsolutePath().toString(), + CMDOCUMENT_GLOBAL_CACHE_ENABLED, Boolean.toString(false)); + solstice.openShim(props); + ShimIdeBootstrapServices.apply(props, solstice.getContext()); + solstice.start("org.apache.felix.scr"); + solstice.startAllWithLazy(false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + static void init() { + + } +} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java similarity index 94% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java index d856335c1b..b77c627f74 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.extra.eclipse.wtp.html; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - import java.util.function.BiFunction; import org.eclipse.jface.text.BadLocationException; @@ -51,7 +49,7 @@ public JsRegionProcessor(IStructuredDocument document, ITypedRegion scriptRegion protected void applyFirst(CodeFormatter formatter) throws MalformedTreeException, BadLocationException { MultiTextEdit modifications = new MultiTextEdit(); String jsSource = document.get(region.getOffset(), region.getLength()); - TextEdit jsEdit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, jsSource, 0, jsSource.length(), indentationLevel + 1, LINE_DELIMITER); + TextEdit jsEdit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, jsSource, 0, jsSource.length(), indentationLevel + 1, "\n"); if (null != jsEdit) { jsEdit.moveTree(region.getOffset()); modifications.addChild(jsEdit); diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java similarity index 95% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java index 6adc258c78..0ac3d47abc 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.extra.eclipse.wtp.html; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -158,14 +156,14 @@ private static int computeIndent(IStructuredDocument document, ITypedRegion regi /** Add delimiter at or after given offset, if there is none at the offset position. Returns the number of characters inserted. */ protected int fixDelimiter(MultiTextEdit modifications, int offset, boolean addAfter) throws BadLocationException { - int delimiterLength = LINE_DELIMITER.length(); + int delimiterLength = "\n".length(); String delimiter = document.get(offset, delimiterLength); - if (!LINE_DELIMITER.equals(delimiter)) { + if (!"\n".equals(delimiter)) { if (addAfter) { offset += 1; } - modifications.addChild(new InsertEdit(offset, LINE_DELIMITER)); - return LINE_DELIMITER.length(); + modifications.addChild(new InsertEdit(offset, "\n")); + return "\n".length(); } return 0; } diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java similarity index 100% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java similarity index 56% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java index 01be583bd8..06415e5de8 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,8 @@ */ package com.diffplug.spotless.extra.eclipse.wtp.sse; -import org.eclipse.core.internal.preferences.PreferencesService; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; - /** * Common base class for step implementations based on an SSE cleanup processor. *

@@ -60,52 +52,9 @@ public interface ProcessorAccessor { String getTypeId(); } - /** Framework configuration public to all formatters using the Cleanup step */ - public static abstract class FrameworkConfig implements SpotlessEclipseConfig { - - private String processorContentTypeID; - - protected FrameworkConfig() { - processorContentTypeID = "none"; - } - - void setProcessorTypeID(String contentTypeID) { - processorContentTypeID = contentTypeID; - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.disableDebugging(); - config.hideEnvironment(); - config.useTemporaryLocations(); - config.changeSystemLineSeparator(); - config.useSlf4J(this.getClass().getPackage().getName() + "-" + processorContentTypeID); - - //Assure that all file content processed by this formatter step are associated to this cleanup-step - config.add(IContentTypeManager.class, new ContentTypeManager(processorContentTypeID)); - - //The preference lookup via the ContentTypeManager, requires a preference service - config.add(IPreferencesService.class, PreferencesService.getDefault()); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - /* - * The core preferences require do lookup the resources "config/override.properties" - * from the plugin ID. - * The values are never used, nor do we require the complete SSE core plugin to be started. - * Hence we just provide the internal plugin. - */ - config.add(new org.eclipse.wst.sse.core.internal.encoding.util.CodedResourcePlugin()); - } - } - protected final ProcessorAccessor processorAccessor; - protected CleanupStep(ProcessorAccessor processorAccessor, FrameworkConfig config) throws Exception { - config.setProcessorTypeID(processorAccessor.getTypeId()); - SpotlessEclipseFramework.setup(config); + protected CleanupStep(ProcessorAccessor processorAccessor) throws Exception { this.processorAccessor = processorAccessor; this.processorAccessor.refreshPreferences(); /* @@ -124,5 +73,4 @@ protected CleanupStep(ProcessorAccessor processorAccessor, FrameworkConfig confi public String format(String raw) throws Exception { return processorAccessor.get().cleanupContent(raw); } - } diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java similarity index 99% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java index 81aa772617..186b03afac 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java similarity index 98% rename from _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java index d0b95e5632..e86a0d760b 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 fd613e82e1..dfb42f7396 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 @@ -50,7 +50,7 @@ import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.cpp.ClangFormatStep; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; import com.diffplug.spotless.generic.EndWithNewlineStep; import com.diffplug.spotless.generic.IndentStep; @@ -703,7 +703,7 @@ private FormatterStep createStep() { } public class EclipseWtpConfig { - private final EclipseBasedStepBuilder builder; + private final EquoBasedStepBuilder builder; EclipseWtpConfig(EclipseWtpFormatterStep type, String version) { builder = type.createBuilder(provisioner()); 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 e7e3d0e386..e12d2c9506 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -38,7 +38,7 @@ public class EclipseWtp implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - EclipseBasedStepBuilder eclipseConfig = type.createBuilder(stepConfig.getProvisioner()); + EquoBasedStepBuilder eclipseConfig = type.createBuilder(stepConfig.getProvisioner()); eclipseConfig.setVersion(version == null ? EclipseWtpFormatterStep.defaultVersion() : version); if (null != files) { eclipseConfig.setPreferences( From 5a64f0c91c78ddcc4c18374ad2d58dea81ec15e5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 01:01:32 -0700 Subject: [PATCH 2/4] Go back to the original WTP implementation for comparison. --- .../wtp/EclipseCssFormatterStepImpl.java | 30 +++++-- .../wtp/EclipseHtmlFormatterStepImpl.java | 58 +++++++++++-- .../wtp/EclipseJsFormatterStepImpl.java | 70 ++++++++++++++-- .../wtp/EclipseJsonFormatterStepImpl.java | 27 ++++++- .../wtp/EclipseXmlFormatterStepImpl.java | 81 ++++++++++++++++--- .../eclipse/wtp/html/JsRegionProcessor.java | 4 +- .../wtp/html/StructuredDocumentProcessor.java | 10 ++- .../extra/eclipse/wtp/sse/CleanupStep.java | 54 ++++++++++++- 8 files changed, 295 insertions(+), 39 deletions(-) diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java index 476528cdcc..2017e674ba 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java @@ -22,18 +22,15 @@ import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceInitializer; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; /** Formatter step which calls out to the Eclipse CSS cleanup and formatter. */ public class EclipseCssFormatterStepImpl extends CleanupStep { - static { - SolsticeSetup.init(); - } public EclipseCssFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor()); - PluginPreferences.configure(CSSCorePlugin.getDefault(), new CSSCorePreferenceInitializer(), properties); + super(new CleanupProcessor(), new FrameworkConfig(properties)); PluginPreferences.assertNoChanges(CSSCorePlugin.getDefault(), properties); } @@ -57,4 +54,27 @@ public AbstractStructuredCleanupProcessor get() { return this; } } + + static class FrameworkConfig extends CleanupStep.FrameworkConfig { + private final Properties properties; + + FrameworkConfig(Properties properties) { + this.properties = properties; + } + + @Override + public void activatePlugins(SpotlessEclipsePluginConfig config) { + super.activatePlugins(config); + activateCssPlugins(config); + } + + static void activateCssPlugins(SpotlessEclipsePluginConfig config) { + config.add(new CSSCorePlugin()); + } + + @Override + public void customize() { + PluginPreferences.configure(CSSCorePlugin.getDefault(), new CSSCorePreferenceInitializer(), properties); + } + } } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java index 93d5ed8330..822275768b 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java @@ -15,12 +15,17 @@ */ package com.diffplug.spotless.extra.eclipse.wtp; +import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; + +import java.util.Arrays; +import java.util.List; import java.util.Properties; import org.eclipse.wst.html.core.internal.HTMLCorePlugin; import org.eclipse.wst.html.core.internal.cleanup.HTMLCleanupProcessorImpl; import org.eclipse.wst.html.core.internal.encoding.HTMLDocumentLoader; import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl; +import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceInitializer; import org.eclipse.wst.html.core.text.IHTMLPartitions; import org.eclipse.wst.jsdt.core.JavaScriptCore; import org.eclipse.wst.jsdt.core.ToolFactory; @@ -29,6 +34,9 @@ import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseCoreConfig; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; import com.diffplug.spotless.extra.eclipse.wtp.html.JsRegionProcessor; import com.diffplug.spotless.extra.eclipse.wtp.html.StructuredDocumentProcessor; import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; @@ -36,15 +44,12 @@ /** Formatter step which calls out to the Eclipse HTML cleanup and formatter. */ public class EclipseHtmlFormatterStepImpl extends CleanupStep { - static { - SolsticeSetup.init(); - } private final String htmlFormatterIndent; private final CodeFormatter jsFormatter; public EclipseHtmlFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor()); + super(new CleanupProcessor(), new FrameworkConfig(properties)); PluginPreferences.assertNoChanges(HTMLCorePlugin.getDefault(), properties); htmlFormatterIndent = ((CleanupProcessor) processorAccessor).getIndent(); jsFormatter = ToolFactory.createCodeFormatter(JavaScriptCore.getOptions(), ToolFactory.M_FORMAT_EXISTING); @@ -56,7 +61,7 @@ public String format(String raw) throws Exception { // Not sure how Eclipse binds the JS formatter to HTML. The formatting is accomplished manually instead. IStructuredDocument document = (IStructuredDocument) new HTMLDocumentLoader().createNewStructuredDocument(); - document.setPreferredLineDelimiter("\n"); + document.setPreferredLineDelimiter(LINE_DELIMITER); document.set(raw); StructuredDocumentProcessor jsProcessor = new StructuredDocumentProcessor( document, IHTMLPartitions.SCRIPT, JsRegionProcessor.createFactory(htmlFormatterIndent)); @@ -107,5 +112,48 @@ protected IStructuredFormatProcessor getFormatProcessor() { String getIndent() { return processor.getFormatPreferences().getIndent(); } + + } + + private static class FrameworkConfig extends CleanupStep.FrameworkConfig { + private final List dependentConfigs; + private final Properties properties; + + public FrameworkConfig(Properties properties) { + dependentConfigs = Arrays.asList( + new EclipseCssFormatterStepImpl.FrameworkConfig(properties), + new EclipseJsFormatterStepImpl.FrameworkConfig(properties), + new EclipseXmlFormatterStepImpl.FrameworkConfig(properties)); + this.properties = properties; + } + + @Override + public void registerBundles(SpotlessEclipseCoreConfig config) { + EclipseJsFormatterStepImpl.FrameworkConfig.registerNonHeadlessBundles(config); + } + + @Override + public void activatePlugins(SpotlessEclipsePluginConfig config) { + super.activatePlugins(config); + EclipseCssFormatterStepImpl.FrameworkConfig.activateCssPlugins(config); + EclipseJsFormatterStepImpl.FrameworkConfig.activateJsPlugins(config); + /* + * The HTML formatter only uses the DOCTYPE/SCHEMA for content model selection. + * Hence no external URIs are required. + */ + boolean allowExternalURI = false; + EclipseXmlFormatterStepImpl.FrameworkConfig.activateXmlPlugins(config, allowExternalURI); + config.add(new HTMLCorePlugin()); + } + + @Override + public void customize() { + dependentConfigs.stream().forEach(c -> { + c.customize(); + }); + PluginPreferences.configure(HTMLCorePlugin.getDefault(), new HTMLCorePreferenceInitializer(), properties); + } + } + } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java index f60379c226..d55d5f8512 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java @@ -15,9 +15,13 @@ */ package com.diffplug.spotless.extra.eclipse.wtp; +import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.DefaultBundles.*; +import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; + import java.util.AbstractMap.SimpleEntry; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.Properties; @@ -45,14 +49,17 @@ import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingContext; import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingStrategy; import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions; +import org.osgi.framework.Bundle; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseCoreConfig; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; /** Formatter step which calls out to the Eclipse JS formatter. */ public class EclipseJsFormatterStepImpl { - static { - SolsticeSetup.init(); - } private final static String[] COMMENT_TYPES = { IJavaScriptPartitions.JAVA_DOC, @@ -72,8 +79,9 @@ public class EclipseJsFormatterStepImpl { private final Set commentTypesToBeFormatted; public EclipseJsFormatterStepImpl(Properties properties) throws Exception { - PluginPreferences.store(JavaScriptCore.getPlugin(), properties); - options = JavaScriptCore.getDefaultOptions(); + SpotlessEclipseFramework.setup(new FrameworkConfig(properties)); + PluginPreferences.assertNoChanges(JavaScriptCore.getPlugin(), properties); + options = JavaScriptCore.getOptions(); commentTypesToBeFormatted = OPTION_2_COMMENT_TYPE.entrySet().stream().filter(x -> DefaultCodeFormatterConstants.TRUE.equals(options.get(x.getKey()))).map(x -> x.getValue()).collect(Collectors.toSet()); formatter = ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_EXISTING); } @@ -83,7 +91,7 @@ public String format(String raw) throws Exception { raw = formatComments(raw); // The comment formatter messed up the code a little bit (adding some line breaks). Now we format the code. IDocument doc = new Document(raw); - TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, raw, 0, raw.length(), 0, "\n"); + TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, raw, 0, raw.length(), 0, LINE_DELIMITER); if (edit == null) { throw new IllegalArgumentException("Invalid JavaScript syntax for formatting."); } else { @@ -126,4 +134,54 @@ private String formatComments(String raw) { return raw; } } + + static class FrameworkConfig implements SpotlessEclipseConfig { + private final Properties properties; + + FrameworkConfig(Properties properties) { + this.properties = properties; + } + + @Override + public void registerServices(SpotlessEclipseServiceConfig config) { + config.applyDefault(); + config.useSlf4J(this.getClass().getPackage().getName()); + } + + @Override + public void registerBundles(SpotlessEclipseCoreConfig config) { + registerNonHeadlessBundles(config); + } + + static void registerNonHeadlessBundles(SpotlessEclipseCoreConfig config) { + //The JS model requires the JDT indexer, hence a headless Eclipse cannot be used. + config.add(PLATFORM, Bundle.ACTIVE); + config.add(REGISTRY, PREFERENCES, COMMON); + } + + @Override + public void activatePlugins(SpotlessEclipsePluginConfig config) { + config.applyDefault(); + activateJsPlugins(config); + } + + static void activateJsPlugins(SpotlessEclipsePluginConfig config) { + // The JS core uses EFS for determination of temporary storage location + config.add(org.eclipse.core.filesystem.EFS.class); + // The JS core provides the JSDT formatter + config.add(new org.eclipse.wst.jsdt.core.JavaScriptCore()); + } + + @Override + @SuppressWarnings("unchecked") + public void customize() { + PluginPreferences.store(JavaScriptCore.getPlugin(), properties); + Hashtable options = JavaScriptCore.getDefaultOptions(); + options.putAll(DefaultCodeFormatterConstants.getJSLintConventionsSettings()); + options.putAll(new HashMap(properties)); + JavaScriptCore.setOptions(options); + } + + } + } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java index 52c07b66b4..23eb194031 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java @@ -22,8 +22,10 @@ import org.eclipse.wst.json.core.JSONCorePlugin; import org.eclipse.wst.json.core.cleanup.CleanupProcessorJSON; import org.eclipse.wst.json.core.format.FormatProcessorJSON; +import org.eclipse.wst.json.core.internal.preferences.JSONCorePreferenceInitializer; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; @@ -32,12 +34,9 @@ * Note that the cleanup is escaped, since it has known bugs and is currently not used by Eclipse. */ public class EclipseJsonFormatterStepImpl extends CleanupStep { - static { - SolsticeSetup.init(); - } public EclipseJsonFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor()); + super(new CleanupProcessor(), new FrameworkConfig(properties)); PluginPreferences.assertNoChanges(JSONCorePlugin.getDefault(), properties); } @@ -91,4 +90,24 @@ public String cleanupContent(String input) throws IOException, CoreException { return formatter.formatContent(input); } } + + private static class FrameworkConfig extends CleanupStep.FrameworkConfig { + private final Properties properties; + + FrameworkConfig(Properties properties) { + this.properties = properties; + } + + @Override + public void activatePlugins(SpotlessEclipsePluginConfig config) { + super.activatePlugins(config); + config.add(new JSONCorePlugin()); + } + + @Override + public void customize() { + PluginPreferences.configure(JSONCorePlugin.getDefault(), new JSONCorePreferenceInitializer(), properties); + } + } + } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java index f3578a9ed6..fa5d5fd52b 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java @@ -15,12 +15,15 @@ */ package com.diffplug.spotless.extra.eclipse.wtp; +import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.*; import java.util.Properties; import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.text.edits.TextEdit; +import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; +import org.eclipse.wst.dtd.core.internal.DTDCorePlugin; import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument; @@ -36,38 +39,89 @@ import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser; import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceInitializer; import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML; +import org.eclipse.wst.xsd.core.internal.XSDCorePlugin; +import org.eclipse.xsd.util.XSDSchemaBuildingTools; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; +import com.diffplug.spotless.extra.eclipse.wtp.sse.PreventExternalURIResolverExtension; /** Formatter step which calls out to the Eclipse XML formatter. */ public class EclipseXmlFormatterStepImpl { - static { - SolsticeSetup.init(); - } - private final DefaultXMLPartitionFormatter formatter; private final XMLFormattingPreferences preferences; private final INodeAdapterFactory xmlAdapterFactory; - public EclipseXmlFormatterStepImpl(Properties properties) { - SolsticeSetup.init(); + public EclipseXmlFormatterStepImpl(Properties properties) throws Exception { + SpotlessEclipseFramework.setup(new FrameworkConfig(properties)); PluginPreferences.assertNoChanges(XMLCorePlugin.getDefault(), properties); preferences = new XMLFormattingPreferences(); formatter = new DefaultXMLPartitionFormatter(); //The adapter factory maintains the common CMDocumentCache xmlAdapterFactory = new ModelQueryAdapterFactoryForXML(); - - PluginPreferences.configure(XMLCorePlugin.getDefault(), new XMLCorePreferenceInitializer(), properties); - PluginPreferences.configureCatalog(properties, (Catalog) XMLCorePlugin.getDefault().getDefaultXMLCatalog()); - // if (!allowExternalURI) { - // config.add(new PreventExternalURIResolverExtension()); - // } } + static class FrameworkConfig implements SpotlessEclipseConfig { + private final Properties properties; + + FrameworkConfig(Properties properties) { + /* + * The cache is only used for system catalogs, but not for user catalogs. + * It requires the SSECorePLugin, which has either a big performance overhead, + * or needs a dirty mocking (we don't really require its functions but it needs to be there). + * So we disable the cache for now. + * This might cause a performance drop in case for example XSDs are formatted. + * But these standard/system restriction files contain anyway no formatting rules. + * So in case of performance inconveniences, we could add a Spotless property to disable the + * XSD/DTD parsing entirely (for example by adding an own URI resolver). + */ + properties.setProperty(CMDOCUMENT_GLOBAL_CACHE_ENABLED, Boolean.toString(false)); + this.properties = properties; + } + + @Override + public void registerServices(SpotlessEclipseServiceConfig config) { + config.applyDefault(); + config.useSlf4J(EclipseXmlFormatterStepImpl.class.getPackage().getName()); + } + + @Override + public void activatePlugins(SpotlessEclipsePluginConfig config) { + config.applyDefault(); + activateXmlPlugins(config, PluginPreferences.isExternalUriAllowed(properties)); + } + + static void activateXmlPlugins(SpotlessEclipsePluginConfig config, boolean allowExternalURI) { + //The WST XML formatter + config.add(new XMLCorePlugin()); + //XSDs/DTDs must be resolved by URI + config.add(new URIResolverPlugin()); + //Support formatting based on DTD restrictions + config.add(new DTDCorePlugin()); + //Support formatting based on XSD restrictions + config.add(new XSDCorePlugin()); + if (!allowExternalURI) { + config.add(new PreventExternalURIResolverExtension()); + } + } + + @Override + public void customize() { + //Register required EMF factories + XSDSchemaBuildingTools.getXSDFactory(); + PluginPreferences.configure(XMLCorePlugin.getDefault(), new XMLCorePreferenceInitializer(), properties); + PluginPreferences.configureCatalog(properties, (Catalog) XMLCorePlugin.getDefault().getDefaultXMLCatalog()); + } + + }; + /** Formatting XML string resolving URIs according its base location */ public String format(String raw, String baseLocation) throws Exception { IStructuredDocument document = new BasicStructuredDocument(new XMLSourceParser()); - document.setPreferredLineDelimiter("\n"); + document.setPreferredLineDelimiter(LINE_DELIMITER); IDocumentPartitioner partitioner = new StructuredTextPartitionerForXML(); document.setDocumentPartitioner(new StructuredTextPartitionerForXML()); partitioner.connect(document); @@ -82,4 +136,5 @@ public String format(String raw, String baseLocation) throws Exception { formatterChanges.apply(document); return document.get(); } + } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java index b77c627f74..a419d82ed1 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.extra.eclipse.wtp.html; +import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; + import java.util.function.BiFunction; import org.eclipse.jface.text.BadLocationException; @@ -49,7 +51,7 @@ public JsRegionProcessor(IStructuredDocument document, ITypedRegion scriptRegion protected void applyFirst(CodeFormatter formatter) throws MalformedTreeException, BadLocationException { MultiTextEdit modifications = new MultiTextEdit(); String jsSource = document.get(region.getOffset(), region.getLength()); - TextEdit jsEdit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, jsSource, 0, jsSource.length(), indentationLevel + 1, "\n"); + TextEdit jsEdit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, jsSource, 0, jsSource.length(), indentationLevel + 1, LINE_DELIMITER); if (null != jsEdit) { jsEdit.moveTree(region.getOffset()); modifications.addChild(jsEdit); diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java index 0ac3d47abc..61642d8979 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.extra.eclipse.wtp.html; +import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -156,14 +158,14 @@ private static int computeIndent(IStructuredDocument document, ITypedRegion regi /** Add delimiter at or after given offset, if there is none at the offset position. Returns the number of characters inserted. */ protected int fixDelimiter(MultiTextEdit modifications, int offset, boolean addAfter) throws BadLocationException { - int delimiterLength = "\n".length(); + int delimiterLength = LINE_DELIMITER.length(); String delimiter = document.get(offset, delimiterLength); - if (!"\n".equals(delimiter)) { + if (!LINE_DELIMITER.equals(delimiter)) { if (addAfter) { offset += 1; } - modifications.addChild(new InsertEdit(offset, "\n")); - return "\n".length(); + modifications.addChild(new InsertEdit(offset, LINE_DELIMITER)); + return LINE_DELIMITER.length(); } return 0; } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java index 06415e5de8..b9d2f67c2f 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java @@ -15,8 +15,16 @@ */ package com.diffplug.spotless.extra.eclipse.wtp.sse; +import org.eclipse.core.internal.preferences.PreferencesService; +import org.eclipse.core.runtime.content.IContentTypeManager; +import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; +import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; + /** * Common base class for step implementations based on an SSE cleanup processor. *

@@ -52,9 +60,52 @@ public interface ProcessorAccessor { String getTypeId(); } + /** Framework configuration public to all formatters using the Cleanup step */ + public static abstract class FrameworkConfig implements SpotlessEclipseConfig { + + private String processorContentTypeID; + + protected FrameworkConfig() { + processorContentTypeID = "none"; + } + + void setProcessorTypeID(String contentTypeID) { + processorContentTypeID = contentTypeID; + } + + @Override + public void registerServices(SpotlessEclipseServiceConfig config) { + config.disableDebugging(); + config.hideEnvironment(); + config.useTemporaryLocations(); + config.changeSystemLineSeparator(); + config.useSlf4J(this.getClass().getPackage().getName() + "-" + processorContentTypeID); + + //Assure that all file content processed by this formatter step are associated to this cleanup-step + config.add(IContentTypeManager.class, new ContentTypeManager(processorContentTypeID)); + + //The preference lookup via the ContentTypeManager, requires a preference service + config.add(IPreferencesService.class, PreferencesService.getDefault()); + } + + @Override + public void activatePlugins(SpotlessEclipsePluginConfig config) { + config.applyDefault(); + /* + * The core preferences require do lookup the resources "config/override.properties" + * from the plugin ID. + * The values are never used, nor do we require the complete SSE core plugin to be started. + * Hence we just provide the internal plugin. + */ + config.add(new org.eclipse.wst.sse.core.internal.encoding.util.CodedResourcePlugin()); + } + } + protected final ProcessorAccessor processorAccessor; - protected CleanupStep(ProcessorAccessor processorAccessor) throws Exception { + protected CleanupStep(ProcessorAccessor processorAccessor, FrameworkConfig config) throws Exception { + config.setProcessorTypeID(processorAccessor.getTypeId()); + SpotlessEclipseFramework.setup(config); this.processorAccessor = processorAccessor; this.processorAccessor.refreshPreferences(); /* @@ -73,4 +124,5 @@ protected CleanupStep(ProcessorAccessor processorAccessor) throws Exception { public String format(String raw) throws Exception { return processorAccessor.get().cleanupContent(raw); } + } From 746df7a97378f4aac96418da96ab0d667825e2d0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 01:01:39 -0700 Subject: [PATCH 3/4] Revert "Go back to the original WTP implementation for comparison." This reverts commit 3f8a5dafaccab3912bac7e6954544200722e0c5d. --- .../wtp/EclipseCssFormatterStepImpl.java | 30 ++----- .../wtp/EclipseHtmlFormatterStepImpl.java | 58 ++----------- .../wtp/EclipseJsFormatterStepImpl.java | 70 ++-------------- .../wtp/EclipseJsonFormatterStepImpl.java | 27 +------ .../wtp/EclipseXmlFormatterStepImpl.java | 81 +++---------------- .../eclipse/wtp/html/JsRegionProcessor.java | 4 +- .../wtp/html/StructuredDocumentProcessor.java | 10 +-- .../extra/eclipse/wtp/sse/CleanupStep.java | 54 +------------ 8 files changed, 39 insertions(+), 295 deletions(-) diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java index 2017e674ba..476528cdcc 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java @@ -22,15 +22,18 @@ import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceInitializer; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; /** Formatter step which calls out to the Eclipse CSS cleanup and formatter. */ public class EclipseCssFormatterStepImpl extends CleanupStep { + static { + SolsticeSetup.init(); + } public EclipseCssFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor(), new FrameworkConfig(properties)); + super(new CleanupProcessor()); + PluginPreferences.configure(CSSCorePlugin.getDefault(), new CSSCorePreferenceInitializer(), properties); PluginPreferences.assertNoChanges(CSSCorePlugin.getDefault(), properties); } @@ -54,27 +57,4 @@ public AbstractStructuredCleanupProcessor get() { return this; } } - - static class FrameworkConfig extends CleanupStep.FrameworkConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - this.properties = properties; - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - super.activatePlugins(config); - activateCssPlugins(config); - } - - static void activateCssPlugins(SpotlessEclipsePluginConfig config) { - config.add(new CSSCorePlugin()); - } - - @Override - public void customize() { - PluginPreferences.configure(CSSCorePlugin.getDefault(), new CSSCorePreferenceInitializer(), properties); - } - } } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java index 822275768b..93d5ed8330 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java @@ -15,17 +15,12 @@ */ package com.diffplug.spotless.extra.eclipse.wtp; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - -import java.util.Arrays; -import java.util.List; import java.util.Properties; import org.eclipse.wst.html.core.internal.HTMLCorePlugin; import org.eclipse.wst.html.core.internal.cleanup.HTMLCleanupProcessorImpl; import org.eclipse.wst.html.core.internal.encoding.HTMLDocumentLoader; import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl; -import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceInitializer; import org.eclipse.wst.html.core.text.IHTMLPartitions; import org.eclipse.wst.jsdt.core.JavaScriptCore; import org.eclipse.wst.jsdt.core.ToolFactory; @@ -34,9 +29,6 @@ import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseCoreConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; import com.diffplug.spotless.extra.eclipse.wtp.html.JsRegionProcessor; import com.diffplug.spotless.extra.eclipse.wtp.html.StructuredDocumentProcessor; import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; @@ -44,12 +36,15 @@ /** Formatter step which calls out to the Eclipse HTML cleanup and formatter. */ public class EclipseHtmlFormatterStepImpl extends CleanupStep { + static { + SolsticeSetup.init(); + } private final String htmlFormatterIndent; private final CodeFormatter jsFormatter; public EclipseHtmlFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor(), new FrameworkConfig(properties)); + super(new CleanupProcessor()); PluginPreferences.assertNoChanges(HTMLCorePlugin.getDefault(), properties); htmlFormatterIndent = ((CleanupProcessor) processorAccessor).getIndent(); jsFormatter = ToolFactory.createCodeFormatter(JavaScriptCore.getOptions(), ToolFactory.M_FORMAT_EXISTING); @@ -61,7 +56,7 @@ public String format(String raw) throws Exception { // Not sure how Eclipse binds the JS formatter to HTML. The formatting is accomplished manually instead. IStructuredDocument document = (IStructuredDocument) new HTMLDocumentLoader().createNewStructuredDocument(); - document.setPreferredLineDelimiter(LINE_DELIMITER); + document.setPreferredLineDelimiter("\n"); document.set(raw); StructuredDocumentProcessor jsProcessor = new StructuredDocumentProcessor( document, IHTMLPartitions.SCRIPT, JsRegionProcessor.createFactory(htmlFormatterIndent)); @@ -112,48 +107,5 @@ protected IStructuredFormatProcessor getFormatProcessor() { String getIndent() { return processor.getFormatPreferences().getIndent(); } - - } - - private static class FrameworkConfig extends CleanupStep.FrameworkConfig { - private final List dependentConfigs; - private final Properties properties; - - public FrameworkConfig(Properties properties) { - dependentConfigs = Arrays.asList( - new EclipseCssFormatterStepImpl.FrameworkConfig(properties), - new EclipseJsFormatterStepImpl.FrameworkConfig(properties), - new EclipseXmlFormatterStepImpl.FrameworkConfig(properties)); - this.properties = properties; - } - - @Override - public void registerBundles(SpotlessEclipseCoreConfig config) { - EclipseJsFormatterStepImpl.FrameworkConfig.registerNonHeadlessBundles(config); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - super.activatePlugins(config); - EclipseCssFormatterStepImpl.FrameworkConfig.activateCssPlugins(config); - EclipseJsFormatterStepImpl.FrameworkConfig.activateJsPlugins(config); - /* - * The HTML formatter only uses the DOCTYPE/SCHEMA for content model selection. - * Hence no external URIs are required. - */ - boolean allowExternalURI = false; - EclipseXmlFormatterStepImpl.FrameworkConfig.activateXmlPlugins(config, allowExternalURI); - config.add(new HTMLCorePlugin()); - } - - @Override - public void customize() { - dependentConfigs.stream().forEach(c -> { - c.customize(); - }); - PluginPreferences.configure(HTMLCorePlugin.getDefault(), new HTMLCorePreferenceInitializer(), properties); - } - } - } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java index d55d5f8512..f60379c226 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java @@ -15,13 +15,9 @@ */ package com.diffplug.spotless.extra.eclipse.wtp; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.DefaultBundles.*; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - import java.util.AbstractMap.SimpleEntry; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.Properties; @@ -49,17 +45,14 @@ import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingContext; import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingStrategy; import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions; -import org.osgi.framework.Bundle; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseCoreConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; /** Formatter step which calls out to the Eclipse JS formatter. */ public class EclipseJsFormatterStepImpl { + static { + SolsticeSetup.init(); + } private final static String[] COMMENT_TYPES = { IJavaScriptPartitions.JAVA_DOC, @@ -79,9 +72,8 @@ public class EclipseJsFormatterStepImpl { private final Set commentTypesToBeFormatted; public EclipseJsFormatterStepImpl(Properties properties) throws Exception { - SpotlessEclipseFramework.setup(new FrameworkConfig(properties)); - PluginPreferences.assertNoChanges(JavaScriptCore.getPlugin(), properties); - options = JavaScriptCore.getOptions(); + PluginPreferences.store(JavaScriptCore.getPlugin(), properties); + options = JavaScriptCore.getDefaultOptions(); commentTypesToBeFormatted = OPTION_2_COMMENT_TYPE.entrySet().stream().filter(x -> DefaultCodeFormatterConstants.TRUE.equals(options.get(x.getKey()))).map(x -> x.getValue()).collect(Collectors.toSet()); formatter = ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_EXISTING); } @@ -91,7 +83,7 @@ public String format(String raw) throws Exception { raw = formatComments(raw); // The comment formatter messed up the code a little bit (adding some line breaks). Now we format the code. IDocument doc = new Document(raw); - TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, raw, 0, raw.length(), 0, LINE_DELIMITER); + TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, raw, 0, raw.length(), 0, "\n"); if (edit == null) { throw new IllegalArgumentException("Invalid JavaScript syntax for formatting."); } else { @@ -134,54 +126,4 @@ private String formatComments(String raw) { return raw; } } - - static class FrameworkConfig implements SpotlessEclipseConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - this.properties = properties; - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(this.getClass().getPackage().getName()); - } - - @Override - public void registerBundles(SpotlessEclipseCoreConfig config) { - registerNonHeadlessBundles(config); - } - - static void registerNonHeadlessBundles(SpotlessEclipseCoreConfig config) { - //The JS model requires the JDT indexer, hence a headless Eclipse cannot be used. - config.add(PLATFORM, Bundle.ACTIVE); - config.add(REGISTRY, PREFERENCES, COMMON); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - activateJsPlugins(config); - } - - static void activateJsPlugins(SpotlessEclipsePluginConfig config) { - // The JS core uses EFS for determination of temporary storage location - config.add(org.eclipse.core.filesystem.EFS.class); - // The JS core provides the JSDT formatter - config.add(new org.eclipse.wst.jsdt.core.JavaScriptCore()); - } - - @Override - @SuppressWarnings("unchecked") - public void customize() { - PluginPreferences.store(JavaScriptCore.getPlugin(), properties); - Hashtable options = JavaScriptCore.getDefaultOptions(); - options.putAll(DefaultCodeFormatterConstants.getJSLintConventionsSettings()); - options.putAll(new HashMap(properties)); - JavaScriptCore.setOptions(options); - } - - } - } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java index 23eb194031..52c07b66b4 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java @@ -22,10 +22,8 @@ import org.eclipse.wst.json.core.JSONCorePlugin; import org.eclipse.wst.json.core.cleanup.CleanupProcessorJSON; import org.eclipse.wst.json.core.format.FormatProcessorJSON; -import org.eclipse.wst.json.core.internal.preferences.JSONCorePreferenceInitializer; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; @@ -34,9 +32,12 @@ * Note that the cleanup is escaped, since it has known bugs and is currently not used by Eclipse. */ public class EclipseJsonFormatterStepImpl extends CleanupStep { + static { + SolsticeSetup.init(); + } public EclipseJsonFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor(), new FrameworkConfig(properties)); + super(new CleanupProcessor()); PluginPreferences.assertNoChanges(JSONCorePlugin.getDefault(), properties); } @@ -90,24 +91,4 @@ public String cleanupContent(String input) throws IOException, CoreException { return formatter.formatContent(input); } } - - private static class FrameworkConfig extends CleanupStep.FrameworkConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - this.properties = properties; - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - super.activatePlugins(config); - config.add(new JSONCorePlugin()); - } - - @Override - public void customize() { - PluginPreferences.configure(JSONCorePlugin.getDefault(), new JSONCorePreferenceInitializer(), properties); - } - } - } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java index fa5d5fd52b..f3578a9ed6 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java @@ -15,15 +15,12 @@ */ package com.diffplug.spotless.extra.eclipse.wtp; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.*; import java.util.Properties; import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.text.edits.TextEdit; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.dtd.core.internal.DTDCorePlugin; import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument; @@ -39,89 +36,38 @@ import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser; import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceInitializer; import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML; -import org.eclipse.wst.xsd.core.internal.XSDCorePlugin; -import org.eclipse.xsd.util.XSDSchemaBuildingTools; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PreventExternalURIResolverExtension; /** Formatter step which calls out to the Eclipse XML formatter. */ public class EclipseXmlFormatterStepImpl { + static { + SolsticeSetup.init(); + } + private final DefaultXMLPartitionFormatter formatter; private final XMLFormattingPreferences preferences; private final INodeAdapterFactory xmlAdapterFactory; - public EclipseXmlFormatterStepImpl(Properties properties) throws Exception { - SpotlessEclipseFramework.setup(new FrameworkConfig(properties)); + public EclipseXmlFormatterStepImpl(Properties properties) { + SolsticeSetup.init(); PluginPreferences.assertNoChanges(XMLCorePlugin.getDefault(), properties); preferences = new XMLFormattingPreferences(); formatter = new DefaultXMLPartitionFormatter(); //The adapter factory maintains the common CMDocumentCache xmlAdapterFactory = new ModelQueryAdapterFactoryForXML(); - } - - static class FrameworkConfig implements SpotlessEclipseConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - /* - * The cache is only used for system catalogs, but not for user catalogs. - * It requires the SSECorePLugin, which has either a big performance overhead, - * or needs a dirty mocking (we don't really require its functions but it needs to be there). - * So we disable the cache for now. - * This might cause a performance drop in case for example XSDs are formatted. - * But these standard/system restriction files contain anyway no formatting rules. - * So in case of performance inconveniences, we could add a Spotless property to disable the - * XSD/DTD parsing entirely (for example by adding an own URI resolver). - */ - properties.setProperty(CMDOCUMENT_GLOBAL_CACHE_ENABLED, Boolean.toString(false)); - this.properties = properties; - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(EclipseXmlFormatterStepImpl.class.getPackage().getName()); - } - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - activateXmlPlugins(config, PluginPreferences.isExternalUriAllowed(properties)); - } - - static void activateXmlPlugins(SpotlessEclipsePluginConfig config, boolean allowExternalURI) { - //The WST XML formatter - config.add(new XMLCorePlugin()); - //XSDs/DTDs must be resolved by URI - config.add(new URIResolverPlugin()); - //Support formatting based on DTD restrictions - config.add(new DTDCorePlugin()); - //Support formatting based on XSD restrictions - config.add(new XSDCorePlugin()); - if (!allowExternalURI) { - config.add(new PreventExternalURIResolverExtension()); - } - } - - @Override - public void customize() { - //Register required EMF factories - XSDSchemaBuildingTools.getXSDFactory(); - PluginPreferences.configure(XMLCorePlugin.getDefault(), new XMLCorePreferenceInitializer(), properties); - PluginPreferences.configureCatalog(properties, (Catalog) XMLCorePlugin.getDefault().getDefaultXMLCatalog()); - } - - }; + PluginPreferences.configure(XMLCorePlugin.getDefault(), new XMLCorePreferenceInitializer(), properties); + PluginPreferences.configureCatalog(properties, (Catalog) XMLCorePlugin.getDefault().getDefaultXMLCatalog()); + // if (!allowExternalURI) { + // config.add(new PreventExternalURIResolverExtension()); + // } + } /** Formatting XML string resolving URIs according its base location */ public String format(String raw, String baseLocation) throws Exception { IStructuredDocument document = new BasicStructuredDocument(new XMLSourceParser()); - document.setPreferredLineDelimiter(LINE_DELIMITER); + document.setPreferredLineDelimiter("\n"); IDocumentPartitioner partitioner = new StructuredTextPartitionerForXML(); document.setDocumentPartitioner(new StructuredTextPartitionerForXML()); partitioner.connect(document); @@ -136,5 +82,4 @@ public String format(String raw, String baseLocation) throws Exception { formatterChanges.apply(document); return document.get(); } - } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java index a419d82ed1..b77c627f74 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.extra.eclipse.wtp.html; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - import java.util.function.BiFunction; import org.eclipse.jface.text.BadLocationException; @@ -51,7 +49,7 @@ public JsRegionProcessor(IStructuredDocument document, ITypedRegion scriptRegion protected void applyFirst(CodeFormatter formatter) throws MalformedTreeException, BadLocationException { MultiTextEdit modifications = new MultiTextEdit(); String jsSource = document.get(region.getOffset(), region.getLength()); - TextEdit jsEdit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, jsSource, 0, jsSource.length(), indentationLevel + 1, LINE_DELIMITER); + TextEdit jsEdit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, jsSource, 0, jsSource.length(), indentationLevel + 1, "\n"); if (null != jsEdit) { jsEdit.moveTree(region.getOffset()); modifications.addChild(jsEdit); diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java index 61642d8979..0ac3d47abc 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.extra.eclipse.wtp.html; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -158,14 +156,14 @@ private static int computeIndent(IStructuredDocument document, ITypedRegion regi /** Add delimiter at or after given offset, if there is none at the offset position. Returns the number of characters inserted. */ protected int fixDelimiter(MultiTextEdit modifications, int offset, boolean addAfter) throws BadLocationException { - int delimiterLength = LINE_DELIMITER.length(); + int delimiterLength = "\n".length(); String delimiter = document.get(offset, delimiterLength); - if (!LINE_DELIMITER.equals(delimiter)) { + if (!"\n".equals(delimiter)) { if (addAfter) { offset += 1; } - modifications.addChild(new InsertEdit(offset, LINE_DELIMITER)); - return LINE_DELIMITER.length(); + modifications.addChild(new InsertEdit(offset, "\n")); + return "\n".length(); } return 0; } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java index b9d2f67c2f..06415e5de8 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java @@ -15,16 +15,8 @@ */ package com.diffplug.spotless.extra.eclipse.wtp.sse; -import org.eclipse.core.internal.preferences.PreferencesService; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; - /** * Common base class for step implementations based on an SSE cleanup processor. *

@@ -60,52 +52,9 @@ public interface ProcessorAccessor { String getTypeId(); } - /** Framework configuration public to all formatters using the Cleanup step */ - public static abstract class FrameworkConfig implements SpotlessEclipseConfig { - - private String processorContentTypeID; - - protected FrameworkConfig() { - processorContentTypeID = "none"; - } - - void setProcessorTypeID(String contentTypeID) { - processorContentTypeID = contentTypeID; - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.disableDebugging(); - config.hideEnvironment(); - config.useTemporaryLocations(); - config.changeSystemLineSeparator(); - config.useSlf4J(this.getClass().getPackage().getName() + "-" + processorContentTypeID); - - //Assure that all file content processed by this formatter step are associated to this cleanup-step - config.add(IContentTypeManager.class, new ContentTypeManager(processorContentTypeID)); - - //The preference lookup via the ContentTypeManager, requires a preference service - config.add(IPreferencesService.class, PreferencesService.getDefault()); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - /* - * The core preferences require do lookup the resources "config/override.properties" - * from the plugin ID. - * The values are never used, nor do we require the complete SSE core plugin to be started. - * Hence we just provide the internal plugin. - */ - config.add(new org.eclipse.wst.sse.core.internal.encoding.util.CodedResourcePlugin()); - } - } - protected final ProcessorAccessor processorAccessor; - protected CleanupStep(ProcessorAccessor processorAccessor, FrameworkConfig config) throws Exception { - config.setProcessorTypeID(processorAccessor.getTypeId()); - SpotlessEclipseFramework.setup(config); + protected CleanupStep(ProcessorAccessor processorAccessor) throws Exception { this.processorAccessor = processorAccessor; this.processorAccessor.refreshPreferences(); /* @@ -124,5 +73,4 @@ protected CleanupStep(ProcessorAccessor processorAccessor, FrameworkConfig confi public String format(String raw) throws Exception { return processorAccessor.get().cleanupContent(raw); } - } From 5485b9f45f41424f9e2fa6b1868ca965f4411019 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 01:21:44 -0700 Subject: [PATCH 4/4] Move WTP into the packages where it is supposed to be. --- .../extra/wtp/EclipseWtpFormatterStep.java | 3 ++- .../extra/eclipse/wtp/package-info.java | 20 ------------------- .../wtp/EclipseCssFormatterStepImpl.java | 8 ++++---- .../wtp/EclipseHtmlFormatterStepImpl.java | 12 +++++------ .../wtp/EclipseJsFormatterStepImpl.java | 6 +++--- .../wtp/EclipseJsonFormatterStepImpl.java | 6 +++--- .../wtp/EclipseXmlFormatterStepImpl.java | 6 ++---- .../{eclipse => glue}/wtp/SolsticeSetup.java | 2 +- .../wtp/html/JsRegionProcessor.java | 6 ++---- .../wtp/html/StructuredDocumentProcessor.java | 2 +- .../wtp/sse/CleanupStep.java | 2 +- .../wtp/sse/PluginPreferences.java | 2 +- .../PreventExternalURIResolverExtension.java | 2 +- 13 files changed, 27 insertions(+), 50 deletions(-) delete mode 100644 lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/EclipseCssFormatterStepImpl.java (91%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/EclipseHtmlFormatterStepImpl.java (92%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/EclipseJsFormatterStepImpl.java (98%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/EclipseJsonFormatterStepImpl.java (94%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/EclipseXmlFormatterStepImpl.java (94%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/SolsticeSetup.java (97%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/html/JsRegionProcessor.java (93%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/html/StructuredDocumentProcessor.java (99%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/sse/CleanupStep.java (98%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/sse/PluginPreferences.java (98%) rename lib-extra/src/wtp/java/com/diffplug/spotless/extra/{eclipse => glue}/wtp/sse/PreventExternalURIResolverExtension.java (97%) 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 8680c68bb4..a266bef1be 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 @@ -39,7 +39,7 @@ public enum EclipseWtpFormatterStep { // @formatter:on private static final String NAME = "eclipse wtp formatter"; - private static final String FORMATTER_PACKAGE = "com.diffplug.spotless.extra.eclipse.wtp."; + private static final String FORMATTER_PACKAGE = "com.diffplug.spotless.extra.glue.wtp."; private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "4.18.0").add(11, "4.21.0"); private static final String FORMATTER_METHOD = "format"; @@ -58,6 +58,7 @@ protected P2Model model(String version) { var model = new P2Model(); addPlatformRepo(model, "4.26"); model.addP2Repo("https://download.eclipse.org/webtools/repository/2022-12/"); + model.addP2Repo("https://download.eclipse.org/tools/orbit/downloads/drops/R20230302014618/repository/"); // XML/HTML Formatter - Dependencies model.getInstall().add("org.eclipse.wst.xml.core"); // DefaultXMLPartitionFormatter and XMLAssociationProvider model.getInstall().add("org.eclipse.wst.sse.core"); // Structure models diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java deleted file mode 100644 index 6cf6f0bfff..0000000000 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ -/** Eclipse WTP based Spotless formatters */ -@ParametersAreNonnullByDefault -package com.diffplug.spotless.extra.eclipse.wtp; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseCssFormatterStepImpl.java similarity index 91% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseCssFormatterStepImpl.java index 476528cdcc..e8ab624453 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseCssFormatterStepImpl.java @@ -13,7 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp; +package com.diffplug.spotless.extra.glue.wtp; + +import com.diffplug.spotless.extra.glue.wtp.sse.CleanupStep; +import com.diffplug.spotless.extra.glue.wtp.sse.PluginPreferences; import java.util.Properties; @@ -22,9 +25,6 @@ import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceInitializer; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; -import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; - /** Formatter step which calls out to the Eclipse CSS cleanup and formatter. */ public class EclipseCssFormatterStepImpl extends CleanupStep { static { diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseHtmlFormatterStepImpl.java similarity index 92% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseHtmlFormatterStepImpl.java index 93d5ed8330..dff38b8612 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseHtmlFormatterStepImpl.java @@ -13,7 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp; +package com.diffplug.spotless.extra.glue.wtp; + +import com.diffplug.spotless.extra.glue.wtp.html.JsRegionProcessor; +import com.diffplug.spotless.extra.glue.wtp.html.StructuredDocumentProcessor; +import com.diffplug.spotless.extra.glue.wtp.sse.CleanupStep; +import com.diffplug.spotless.extra.glue.wtp.sse.PluginPreferences; import java.util.Properties; @@ -29,11 +34,6 @@ import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import com.diffplug.spotless.extra.eclipse.wtp.html.JsRegionProcessor; -import com.diffplug.spotless.extra.eclipse.wtp.html.StructuredDocumentProcessor; -import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; - /** Formatter step which calls out to the Eclipse HTML cleanup and formatter. */ public class EclipseHtmlFormatterStepImpl extends CleanupStep { static { diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseJsFormatterStepImpl.java similarity index 98% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseJsFormatterStepImpl.java index f60379c226..9caccecc0a 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseJsFormatterStepImpl.java @@ -13,7 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp; +package com.diffplug.spotless.extra.glue.wtp; + +import com.diffplug.spotless.extra.glue.wtp.sse.PluginPreferences; import java.util.AbstractMap.SimpleEntry; import java.util.Arrays; @@ -46,8 +48,6 @@ import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingStrategy; import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; - /** Formatter step which calls out to the Eclipse JS formatter. */ public class EclipseJsFormatterStepImpl { static { diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseJsonFormatterStepImpl.java similarity index 94% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseJsonFormatterStepImpl.java index 52c07b66b4..d2fad148c8 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseJsonFormatterStepImpl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp; +package com.diffplug.spotless.extra.glue.wtp; import java.io.IOException; import java.util.Properties; @@ -24,8 +24,8 @@ import org.eclipse.wst.json.core.format.FormatProcessorJSON; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; -import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; +import com.diffplug.spotless.extra.glue.wtp.sse.CleanupStep; +import com.diffplug.spotless.extra.glue.wtp.sse.PluginPreferences; /** * Formatter step which calls out to the Eclipse JSON cleanup processor and formatter. diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseXmlFormatterStepImpl.java similarity index 94% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseXmlFormatterStepImpl.java index f3578a9ed6..0db7a49ebe 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/EclipseXmlFormatterStepImpl.java @@ -13,9 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp; - -import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.*; +package com.diffplug.spotless.extra.glue.wtp; import java.util.Properties; @@ -37,7 +35,7 @@ import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceInitializer; import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; +import com.diffplug.spotless.extra.glue.wtp.sse.PluginPreferences; /** Formatter step which calls out to the Eclipse XML formatter. */ public class EclipseXmlFormatterStepImpl { diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/SolsticeSetup.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/SolsticeSetup.java similarity index 97% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/SolsticeSetup.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/SolsticeSetup.java index a5e8d4237b..329eef580e 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/SolsticeSetup.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/SolsticeSetup.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp; +package com.diffplug.spotless.extra.glue.wtp; import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.CMDOCUMENT_GLOBAL_CACHE_ENABLED; diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/html/JsRegionProcessor.java similarity index 93% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/html/JsRegionProcessor.java index b77c627f74..7030d0adff 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/html/JsRegionProcessor.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp.html; +package com.diffplug.spotless.extra.glue.wtp.html; import java.util.function.BiFunction; @@ -25,8 +25,6 @@ import org.eclipse.wst.jsdt.core.formatter.CodeFormatter; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import com.diffplug.spotless.extra.eclipse.wtp.html.StructuredDocumentProcessor.RegionProcessor; - /** * Provides additional formating to the plain JS {@link CodeFormatter}: *

    @@ -40,7 +38,7 @@ * to the one of Eclipse. *

    */ -public class JsRegionProcessor extends RegionProcessor { +public class JsRegionProcessor extends StructuredDocumentProcessor.RegionProcessor { public JsRegionProcessor(IStructuredDocument document, ITypedRegion scriptRegion, String htmlIndent) { super(document, scriptRegion, htmlIndent); } diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/html/StructuredDocumentProcessor.java similarity index 99% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/html/StructuredDocumentProcessor.java index 0ac3d47abc..ac5efa0e9e 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/html/StructuredDocumentProcessor.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp.html; +package com.diffplug.spotless.extra.glue.wtp.html; import java.util.ArrayList; import java.util.Arrays; diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/CleanupStep.java similarity index 98% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/CleanupStep.java index 06415e5de8..43b860bba8 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/CleanupStep.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp.sse; +package com.diffplug.spotless.extra.glue.wtp.sse; import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/PluginPreferences.java similarity index 98% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/PluginPreferences.java index 186b03afac..c727d86ddc 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/PluginPreferences.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp.sse; +package com.diffplug.spotless.extra.glue.wtp.sse; import java.io.File; import java.io.FileInputStream; diff --git a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/PreventExternalURIResolverExtension.java similarity index 97% rename from lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java rename to lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/PreventExternalURIResolverExtension.java index e86a0d760b..4938add7e5 100644 --- a/lib-extra/src/wtp/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/PreventExternalURIResolverExtension.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.wtp.sse; +package com.diffplug.spotless.extra.glue.wtp.sse; import org.eclipse.core.resources.IFile; import org.eclipse.emf.common.util.URI;