From a641499411a8bf98740dfd2757237da23cec4b82 Mon Sep 17 00:00:00 2001 From: Tobias Hahnen Date: Tue, 20 Aug 2024 10:21:02 +0200 Subject: [PATCH] SLE-920: Move EP to the UI plug-in In order to not calculate SWT for all fragments (Sloop) of the CORE plug-in, we move it to the UI plug-in. This will fix an error with the build as the SWT dependency couldn't be found for our "no-arch" fragment that is literally "every other OS/ARCH" combination except for the ones we have Sloop packages for. --- .../META-INF/MANIFEST.MF | 1 + org.sonarlint.eclipse.cdt/plugin.xml | 2 +- .../CProjectConfiguratorExtension.java | 32 +++++++++++-------- .../META-INF/MANIFEST.MF | 5 +-- org.sonarlint.eclipse.core/plugin.xml | 3 -- .../extension/SonarLintExtensionTracker.java | 11 ++----- org.sonarlint.eclipse.jdt/plugin.xml | 2 +- .../JavaProjectConfiguratorExtension.java | 2 +- org.sonarlint.eclipse.pydev/plugin.xml | 2 +- .../PythonProjectConfiguratorExtension.java | 2 +- org.sonarlint.eclipse.ui/META-INF/MANIFEST.MF | 4 ++- org.sonarlint.eclipse.ui/plugin.xml | 3 ++ .../schema/syntaxHighlightingProvider.exsd | 6 ++-- .../SonarLintUiExtensionTracker.java | 8 ++++- .../eclipse/ui/internal/util/HTMLUtils.java | 4 +-- .../ui}/rule/ISyntaxHighlightingProvider.java | 4 +-- 16 files changed, 48 insertions(+), 43 deletions(-) rename {org.sonarlint.eclipse.core => org.sonarlint.eclipse.ui}/schema/syntaxHighlightingProvider.exsd (89%) rename {org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core => org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui}/rule/ISyntaxHighlightingProvider.java (95%) diff --git a/org.sonarlint.eclipse.cdt/META-INF/MANIFEST.MF b/org.sonarlint.eclipse.cdt/META-INF/MANIFEST.MF index 9dd3ebb93..0f4e82eea 100644 --- a/org.sonarlint.eclipse.cdt/META-INF/MANIFEST.MF +++ b/org.sonarlint.eclipse.cdt/META-INF/MANIFEST.MF @@ -12,6 +12,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.cdt.core;resolution:=optional, org.eclipse.cdt.ui;resolution:=optional, org.sonarlint.eclipse.core, + org.sonarlint.eclipse.ui, org.eclipse.core.filesystem, org.eclipse.jdt.annotation;resolution:=optional, org.eclipse.text, diff --git a/org.sonarlint.eclipse.cdt/plugin.xml b/org.sonarlint.eclipse.cdt/plugin.xml index 5810b2362..89fd1c19c 100644 --- a/org.sonarlint.eclipse.cdt/plugin.xml +++ b/org.sonarlint.eclipse.cdt/plugin.xml @@ -13,7 +13,7 @@ + point="org.sonarlint.eclipse.ui.syntaxHighlightingProvider"> diff --git a/org.sonarlint.eclipse.cdt/src/org/sonarlint/eclipse/cdt/internal/CProjectConfiguratorExtension.java b/org.sonarlint.eclipse.cdt/src/org/sonarlint/eclipse/cdt/internal/CProjectConfiguratorExtension.java index 2112dda31..9b210f922 100644 --- a/org.sonarlint.eclipse.cdt/src/org/sonarlint/eclipse/cdt/internal/CProjectConfiguratorExtension.java +++ b/org.sonarlint.eclipse.cdt/src/org/sonarlint/eclipse/cdt/internal/CProjectConfiguratorExtension.java @@ -42,7 +42,7 @@ import org.sonarlint.eclipse.core.analysis.SonarLintLanguage; import org.sonarlint.eclipse.core.resource.ISonarLintFile; import org.sonarlint.eclipse.core.resource.ISonarLintProject; -import org.sonarlint.eclipse.core.rule.ISyntaxHighlightingProvider; +import org.sonarlint.eclipse.ui.rule.ISyntaxHighlightingProvider; /** * Responsible for checking at runtime if CDT plugin is installed. @@ -113,28 +113,34 @@ public SonarLintLanguage language(ISonarLintFile file) { return null; } + /** + * We can only provide UI elements if the language matches C/C++ and the CDT UI plug-in is available as in some + * cases there might only be the core bundles present. This might be the case for thrid-party plug-ins that make + * use of the CDT core in order to work with C/C++ but provide their own "frontend". + */ + private static boolean canProvideUiElements(String ruleLanguage) { + return isCdtUiPresent() && (ruleLanguage.equals(C_LANGUAGE_KEY) || ruleLanguage.equals(CPP_LANGUAGE_KEY)); + } + @Override public Optional sourceViewerConfiguration(String ruleLanguage) { - if (isCdtUiPresent() && (ruleLanguage.equals(C_LANGUAGE_KEY) || ruleLanguage.equals(CPP_LANGUAGE_KEY))) { - return Optional.of(CdtUiUtils.sourceViewerConfiguration()); - } - return Optional.empty(); + return canProvideUiElements(ruleLanguage) + ? Optional.of(CdtUiUtils.sourceViewerConfiguration()) + : Optional.empty(); } @Override public Optional documentPartitioner(String ruleLanguage) { - if (isCdtUiPresent() && (ruleLanguage.equals(C_LANGUAGE_KEY) || ruleLanguage.equals(CPP_LANGUAGE_KEY))) { - return Optional.of(CdtUiUtils.documentPartitioner()); - } - return Optional.empty(); + return canProvideUiElements(ruleLanguage) + ? Optional.of(CdtUiUtils.documentPartitioner()) + : Optional.empty(); } @Nullable @Override public TextMergeViewer getTextMergeViewer(String ruleLanguage, Composite parent, CompareConfiguration mp) { - if (isCdtUiPresent() && (ruleLanguage.equals(C_LANGUAGE_KEY) || ruleLanguage.equals(CPP_LANGUAGE_KEY))) { - return CdtUiUtils.getTextMergeViewer(parent, mp); - } - return null; + return canProvideUiElements(ruleLanguage) + ? CdtUiUtils.getTextMergeViewer(parent, mp) + : null; } } diff --git a/org.sonarlint.eclipse.core/META-INF/MANIFEST.MF b/org.sonarlint.eclipse.core/META-INF/MANIFEST.MF index dd70493b5..0a7694fce 100644 --- a/org.sonarlint.eclipse.core/META-INF/MANIFEST.MF +++ b/org.sonarlint.eclipse.core/META-INF/MANIFEST.MF @@ -28,8 +28,7 @@ Export-Package: org.sonarlint.eclipse.core, org.sonarlint.eclipse.core.internal.utils;x-friends:="org.sonarlint.eclipse.cdt,org.sonarlint.eclipse.core.tests,org.sonarlint.eclipse.jdt,org.sonarlint.eclipse.m2e,org.sonarlint.eclipse.buildship,org.sonarlint.eclipse.ui", org.sonarlint.eclipse.core.internal.vcs;x-friends:="org.sonarlint.eclipse.ui", org.sonarlint.eclipse.core.listener, - org.sonarlint.eclipse.core.resource, - org.sonarlint.eclipse.core.rule + org.sonarlint.eclipse.core.resource Require-Bundle: org.eclipse.equinox.security, org.eclipse.core.runtime;bundle-version="3.14.0", org.eclipse.core.resources, @@ -39,13 +38,11 @@ Require-Bundle: org.eclipse.equinox.security, org.eclipse.core.net, org.eclipse.core.filesystem, org.eclipse.team.core, - org.eclipse.compare, org.eclipse.jdt.annotation;resolution:=optional, org.eclipse.jgit;resolution:=optional, org.eclipse.egit.core;resolution:=optional, org.eclipse.egit.ui;resolution:=optional, org.eclipse.text, - org.eclipse.swt, org.sonarsource.sonarlint.core.sonarlint-java-client-osgi;bundle-version="[10.4.0,10.5.0)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-11 diff --git a/org.sonarlint.eclipse.core/plugin.xml b/org.sonarlint.eclipse.core/plugin.xml index 2c8e03a3f..557b2d37d 100644 --- a/org.sonarlint.eclipse.core/plugin.xml +++ b/org.sonarlint.eclipse.core/plugin.xml @@ -8,9 +8,6 @@ - diff --git a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/extension/SonarLintExtensionTracker.java b/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/extension/SonarLintExtensionTracker.java index c9ed679c6..64e1e52e1 100644 --- a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/extension/SonarLintExtensionTracker.java +++ b/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/extension/SonarLintExtensionTracker.java @@ -25,11 +25,10 @@ import org.sonarlint.eclipse.core.analysis.IFileLanguageProvider; import org.sonarlint.eclipse.core.analysis.IFileTypeProvider; import org.sonarlint.eclipse.core.configurator.ProjectConfigurator; -import org.sonarlint.eclipse.core.resource.ISonarLintProjectHierarchyProvider; import org.sonarlint.eclipse.core.resource.ISonarLintFileAdapterParticipant; import org.sonarlint.eclipse.core.resource.ISonarLintProjectAdapterParticipant; +import org.sonarlint.eclipse.core.resource.ISonarLintProjectHierarchyProvider; import org.sonarlint.eclipse.core.resource.ISonarLintProjectsProvider; -import org.sonarlint.eclipse.core.rule.ISyntaxHighlightingProvider; public class SonarLintExtensionTracker extends AbstractSonarLintExtensionTracker { @@ -43,13 +42,11 @@ public class SonarLintExtensionTracker extends AbstractSonarLintExtensionTracker "org.sonarlint.eclipse.core.projectAdapterParticipant"); //$NON-NLS-1$ private final SonarLintEP languageEp = new SonarLintEP<>("org.sonarlint.eclipse.core.languageProvider"); //$NON-NLS-1$ private final SonarLintEP typeEp = new SonarLintEP<>("org.sonarlint.eclipse.core.typeProvider"); //$NON-NLS-1$ - private final SonarLintEP syntaxHighlightingProviderEP = new SonarLintEP<>( - "org.sonarlint.eclipse.core.syntaxHighlightingProvider"); //$NON-NLS-1$ private final SonarLintEP projectHierarchyProviderEP = new SonarLintEP<>( "org.sonarlint.eclipse.core.projectHierarchyProvider"); //$NON-NLS-1$ private final Collection> allEps = List.of(configuratorEp, analysisEp, projectsProviderEp, fileAdapterParticipantEp, projectAdapterParticipantEp, - languageEp, typeEp, syntaxHighlightingProviderEP, projectHierarchyProviderEP); + languageEp, typeEp, projectHierarchyProviderEP); private SonarLintExtensionTracker() { init(allEps); @@ -96,10 +93,6 @@ public Collection getTypeProviders() { return typeEp.getInstances(); } - public Collection getSyntaxHighlightingProvider() { - return syntaxHighlightingProviderEP.getInstances(); - } - public Collection getProjectHierarchyProviders() { return projectHierarchyProviderEP.getInstances(); } diff --git a/org.sonarlint.eclipse.jdt/plugin.xml b/org.sonarlint.eclipse.jdt/plugin.xml index 26e6f902d..8abec4529 100644 --- a/org.sonarlint.eclipse.jdt/plugin.xml +++ b/org.sonarlint.eclipse.jdt/plugin.xml @@ -25,7 +25,7 @@ + point="org.sonarlint.eclipse.ui.syntaxHighlightingProvider"> diff --git a/org.sonarlint.eclipse.jdt/src/org/sonarlint/eclipse/jdt/internal/JavaProjectConfiguratorExtension.java b/org.sonarlint.eclipse.jdt/src/org/sonarlint/eclipse/jdt/internal/JavaProjectConfiguratorExtension.java index 2bc3f5c3c..275117b68 100644 --- a/org.sonarlint.eclipse.jdt/src/org/sonarlint/eclipse/jdt/internal/JavaProjectConfiguratorExtension.java +++ b/org.sonarlint.eclipse.jdt/src/org/sonarlint/eclipse/jdt/internal/JavaProjectConfiguratorExtension.java @@ -40,9 +40,9 @@ import org.sonarlint.eclipse.core.resource.ISonarLintFile; import org.sonarlint.eclipse.core.resource.ISonarLintFileAdapterParticipant; import org.sonarlint.eclipse.core.resource.ISonarLintProject; -import org.sonarlint.eclipse.core.rule.ISyntaxHighlightingProvider; import org.sonarlint.eclipse.ui.quickfixes.IMarkerResolutionEnhancer; import org.sonarlint.eclipse.ui.quickfixes.ISonarLintMarkerResolver; +import org.sonarlint.eclipse.ui.rule.ISyntaxHighlightingProvider; public class JavaProjectConfiguratorExtension implements IAnalysisConfigurator, ISonarLintFileAdapterParticipant, IFileTypeProvider, IMarkerResolutionEnhancer, ISyntaxHighlightingProvider { diff --git a/org.sonarlint.eclipse.pydev/plugin.xml b/org.sonarlint.eclipse.pydev/plugin.xml index f7eefcbed..b26d241bc 100644 --- a/org.sonarlint.eclipse.pydev/plugin.xml +++ b/org.sonarlint.eclipse.pydev/plugin.xml @@ -1,7 +1,7 @@ + point="org.sonarlint.eclipse.ui.syntaxHighlightingProvider"> diff --git a/org.sonarlint.eclipse.pydev/src/org/sonarlint/eclipse/pydev/internal/PythonProjectConfiguratorExtension.java b/org.sonarlint.eclipse.pydev/src/org/sonarlint/eclipse/pydev/internal/PythonProjectConfiguratorExtension.java index 4efce7e41..7cfcce51c 100644 --- a/org.sonarlint.eclipse.pydev/src/org/sonarlint/eclipse/pydev/internal/PythonProjectConfiguratorExtension.java +++ b/org.sonarlint.eclipse.pydev/src/org/sonarlint/eclipse/pydev/internal/PythonProjectConfiguratorExtension.java @@ -22,7 +22,7 @@ import java.util.Optional; import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.sonarlint.eclipse.core.rule.ISyntaxHighlightingProvider; +import org.sonarlint.eclipse.ui.rule.ISyntaxHighlightingProvider; public class PythonProjectConfiguratorExtension implements ISyntaxHighlightingProvider { private static final String PYTHON_LANGUAGE_KEY = "py"; diff --git a/org.sonarlint.eclipse.ui/META-INF/MANIFEST.MF b/org.sonarlint.eclipse.ui/META-INF/MANIFEST.MF index 951745238..1e5edac45 100644 --- a/org.sonarlint.eclipse.ui/META-INF/MANIFEST.MF +++ b/org.sonarlint.eclipse.ui/META-INF/MANIFEST.MF @@ -26,6 +26,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.team.core, org.eclipse.jdt.annotation;resolution:=optional, org.eclipse.text, + org.eclipse.compare, org.eclipse.core.expressions, org.sonarsource.sonarlint.core.sonarlint-java-client-osgi;bundle-version="[10.4.0,10.5.0)" Export-Package: org.sonarlint.eclipse.ui.internal;x-friends:="org.sonarlint.eclipse.core.tests", @@ -35,7 +36,8 @@ Export-Package: org.sonarlint.eclipse.ui.internal;x-friends:="org.sonarlint.ecli org.sonarlint.eclipse.ui.internal.properties;x-friends:="org.sonarlint.eclipse.core.tests", org.sonarlint.eclipse.ui.internal.util;x-friends:="org.sonarlint.eclipse.core.tests", org.sonarlint.eclipse.ui.internal.views.issues;x-friends:="org.sonarlint.eclipse.its", - org.sonarlint.eclipse.ui.quickfixes;x-internal:=true + org.sonarlint.eclipse.ui.quickfixes;x-internal:=true, + org.sonarlint.eclipse.ui.rule Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-ActivationPolicy: lazy Bundle-Localization: OSGI-INF/l10n/bundle diff --git a/org.sonarlint.eclipse.ui/plugin.xml b/org.sonarlint.eclipse.ui/plugin.xml index 19d237cc6..e1d0261aa 100644 --- a/org.sonarlint.eclipse.ui/plugin.xml +++ b/org.sonarlint.eclipse.ui/plugin.xml @@ -2,6 +2,9 @@ + diff --git a/org.sonarlint.eclipse.core/schema/syntaxHighlightingProvider.exsd b/org.sonarlint.eclipse.ui/schema/syntaxHighlightingProvider.exsd similarity index 89% rename from org.sonarlint.eclipse.core/schema/syntaxHighlightingProvider.exsd rename to org.sonarlint.eclipse.ui/schema/syntaxHighlightingProvider.exsd index 395c31dc5..2ab6c1082 100644 --- a/org.sonarlint.eclipse.core/schema/syntaxHighlightingProvider.exsd +++ b/org.sonarlint.eclipse.ui/schema/syntaxHighlightingProvider.exsd @@ -1,9 +1,9 @@ - + - + Help rule descriptions to find the correct syntax highlighting configuration for code snippets based on the external plugin implementation @@ -55,7 +55,7 @@ - + diff --git a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/extension/SonarLintUiExtensionTracker.java b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/extension/SonarLintUiExtensionTracker.java index 5fb0d8db8..a8c6e385f 100644 --- a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/extension/SonarLintUiExtensionTracker.java +++ b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/extension/SonarLintUiExtensionTracker.java @@ -23,14 +23,17 @@ import java.util.List; import org.sonarlint.eclipse.core.internal.extension.AbstractSonarLintExtensionTracker; import org.sonarlint.eclipse.ui.quickfixes.IMarkerResolutionEnhancer; +import org.sonarlint.eclipse.ui.rule.ISyntaxHighlightingProvider; public class SonarLintUiExtensionTracker extends AbstractSonarLintExtensionTracker { private static SonarLintUiExtensionTracker singleInstance = null; private final SonarLintEP markerResolutionEnhancerEp = new SonarLintEP<>("org.sonarlint.eclipse.ui.markerResolutionEnhancer"); //$NON-NLS-1$ + private final SonarLintEP syntaxHighlightingProviderEP = new SonarLintEP<>( + "org.sonarlint.eclipse.ui.syntaxHighlightingProvider"); //$NON-NLS-1$ - private final Collection> allEps = List.of(markerResolutionEnhancerEp); + private final Collection> allEps = List.of(markerResolutionEnhancerEp, syntaxHighlightingProviderEP); private SonarLintUiExtensionTracker() { init(allEps); @@ -53,4 +56,7 @@ public Collection getMarkerResolutionEnhancers() { return markerResolutionEnhancerEp.getInstances(); } + public Collection getSyntaxHighlightingProvider() { + return syntaxHighlightingProviderEP.getInstances(); + } } diff --git a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/util/HTMLUtils.java b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/util/HTMLUtils.java index 749910ed8..f4e5770a7 100644 --- a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/util/HTMLUtils.java +++ b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/util/HTMLUtils.java @@ -27,8 +27,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; -import org.sonarlint.eclipse.core.internal.extension.SonarLintExtensionTracker; import org.sonarlint.eclipse.core.internal.utils.StringUtils; +import org.sonarlint.eclipse.ui.internal.extension.SonarLintUiExtensionTracker; /** Utility class used for parsing the HTML rule description into native elements */ public final class HTMLUtils { @@ -90,7 +90,7 @@ private static void createSourceViewer(String html, Composite parent, String lan // is provided by any plug-in via the extension mechanism. // INFO: Configuration must extend of org.eclipse.jface.text.source.SourceViewerConfiguration // INFO: Document partitioner must implement org.eclipse.jface.text.IDocumentPartitioner - var configurationProviders = SonarLintExtensionTracker.getInstance().getSyntaxHighlightingProvider(); + var configurationProviders = SonarLintUiExtensionTracker.getInstance().getSyntaxHighlightingProvider(); SourceViewerConfiguration sourceViewerConfigurationNullable = null; for (var configurationProvider : configurationProviders) { var sourceViewerConfigurationOptional = configurationProvider.sourceViewerConfiguration(languageKey); diff --git a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/rule/ISyntaxHighlightingProvider.java b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/rule/ISyntaxHighlightingProvider.java similarity index 95% rename from org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/rule/ISyntaxHighlightingProvider.java rename to org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/rule/ISyntaxHighlightingProvider.java index c55c83da5..f1eeff5b0 100644 --- a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/rule/ISyntaxHighlightingProvider.java +++ b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/rule/ISyntaxHighlightingProvider.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonarlint.eclipse.core.rule; +package org.sonarlint.eclipse.ui.rule; import java.util.Optional; import org.eclipse.compare.CompareConfiguration; @@ -57,7 +57,7 @@ public interface ISyntaxHighlightingProvider { * @param ruleLanguage to be used to check whether this plug-in can contribute a viewer for this language * @param parent the UI parent element which will embed the viewer * @param used for configuring the viewer by providing information on the left and right side, e.g. label - * @return + * @return the language/plug-in specific diff viewer or null if not applicable */ @Nullable default TextMergeViewer getTextMergeViewer(String ruleLanguage, Composite parent, CompareConfiguration mp) {