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/package-info.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java deleted file mode 100644 index 6cf6f0bfff..0000000000 --- a/_ext/eclipse-wtp/src/main/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/_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..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 @@ -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 { @@ -37,29 +39,55 @@ 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"; 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/"); + 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 + 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 +101,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/glue/wtp/EclipseCssFormatterStepImpl.java similarity index 63% 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/glue/wtp/EclipseCssFormatterStepImpl.java index fb0e1ffeac..e8ab624453 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/glue/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. @@ -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,15 +25,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(), 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/glue/wtp/EclipseHtmlFormatterStepImpl.java similarity index 61% 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/glue/wtp/EclipseHtmlFormatterStepImpl.java index 4b7f592c3c..dff38b8612 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/glue/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. @@ -13,19 +13,19 @@ * 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 com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; +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.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,22 +34,17 @@ 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; -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 { + 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/glue/wtp/EclipseJsFormatterStepImpl.java similarity index 68% 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/glue/wtp/EclipseJsFormatterStepImpl.java index c101b1a27a..9caccecc0a 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/glue/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. @@ -13,15 +13,13 @@ * 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 com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.DefaultBundles.*; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; +import com.diffplug.spotless.extra.glue.wtp.sse.PluginPreferences; 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 +47,12 @@ 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/glue/wtp/EclipseJsonFormatterStepImpl.java similarity index 75% 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/glue/wtp/EclipseJsonFormatterStepImpl.java index 91d8516b24..d2fad148c8 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/glue/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. @@ -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; @@ -22,21 +22,22 @@ 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; +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. * 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/glue/wtp/EclipseXmlFormatterStepImpl.java similarity index 50% 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/glue/wtp/EclipseXmlFormatterStepImpl.java index 57fce0d503..0db7a49ebe 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/glue/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. @@ -13,17 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -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.*; +package com.diffplug.spotless.extra.glue.wtp; 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 +34,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; +import com.diffplug.spotless.extra.glue.wtp.sse.PluginPreferences; /** 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 +80,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/glue/wtp/SolsticeSetup.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/SolsticeSetup.java new file mode 100644 index 0000000000..329eef580e --- /dev/null +++ b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/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.glue.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/glue/wtp/html/JsRegionProcessor.java similarity index 88% 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/glue/wtp/html/JsRegionProcessor.java index d856335c1b..7030d0adff 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/glue/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. @@ -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.html; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; +package com.diffplug.spotless.extra.glue.wtp.html; import java.util.function.BiFunction; @@ -27,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}: *
    @@ -42,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); } @@ -51,7 +47,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/glue/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/glue/wtp/html/StructuredDocumentProcessor.java index 6adc258c78..ac5efa0e9e 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/glue/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. @@ -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.html; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; +package com.diffplug.spotless.extra.glue.wtp.html; import java.util.ArrayList; import java.util.Arrays; @@ -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/sse/CleanupStep.java b/lib-extra/src/wtp/java/com/diffplug/spotless/extra/glue/wtp/sse/CleanupStep.java similarity index 55% 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/glue/wtp/sse/CleanupStep.java index 01be583bd8..43b860bba8 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/glue/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. @@ -13,18 +13,10 @@ * 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.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/glue/wtp/sse/PluginPreferences.java similarity index 98% 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/glue/wtp/sse/PluginPreferences.java index 81aa772617..c727d86ddc 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/glue/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. @@ -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/_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/glue/wtp/sse/PreventExternalURIResolverExtension.java similarity index 96% 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/glue/wtp/sse/PreventExternalURIResolverExtension.java index d0b95e5632..4938add7e5 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/glue/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. @@ -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; 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(