Skip to content

Commit

Permalink
SLE-920: Move EP to the UI plug-in
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thahnen committed Aug 20, 2024
1 parent 5b81288 commit a641499
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 43 deletions.
1 change: 1 addition & 0 deletions org.sonarlint.eclipse.cdt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion org.sonarlint.eclipse.cdt/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</provider>
</extension>
<extension
point="org.sonarlint.eclipse.core.syntaxHighlightingProvider">
point="org.sonarlint.eclipse.ui.syntaxHighlightingProvider">
<enhancer
class="org.sonarlint.eclipse.cdt.internal.CProjectConfiguratorExtension">
</enhancer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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> 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<IDocumentPartitioner> 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;
}
}
5 changes: 1 addition & 4 deletions org.sonarlint.eclipse.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
3 changes: 0 additions & 3 deletions org.sonarlint.eclipse.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
<extension-point id="analysisConfigurator" name="SonarLint Analysis Configurator" schema="schema/analysisConfigurator.exsd"/>
<extension-point id="languageProvider" name="SonarLint File Language Provider" schema="schema/languageProvider.exsd"/>
<extension-point id="typeProvider" name="SonarLint File Type Provider" schema="schema/typeProvider.exsd"/>
<extension-point id="syntaxHighlightingProvider"
name="SonarLint Syntax Highlighting Provider"
schema="schema/syntaxHighlightingProvider.exsd"/>
<extension-point id="projectHierarchyProvider"
name="SonarLint Project Hierarchy Provider"
schema="schema/projectHierarchyProvider.exsd" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -43,13 +42,11 @@ public class SonarLintExtensionTracker extends AbstractSonarLintExtensionTracker
"org.sonarlint.eclipse.core.projectAdapterParticipant"); //$NON-NLS-1$
private final SonarLintEP<IFileLanguageProvider> languageEp = new SonarLintEP<>("org.sonarlint.eclipse.core.languageProvider"); //$NON-NLS-1$
private final SonarLintEP<IFileTypeProvider> typeEp = new SonarLintEP<>("org.sonarlint.eclipse.core.typeProvider"); //$NON-NLS-1$
private final SonarLintEP<ISyntaxHighlightingProvider> syntaxHighlightingProviderEP = new SonarLintEP<>(
"org.sonarlint.eclipse.core.syntaxHighlightingProvider"); //$NON-NLS-1$
private final SonarLintEP<ISonarLintProjectHierarchyProvider> projectHierarchyProviderEP = new SonarLintEP<>(
"org.sonarlint.eclipse.core.projectHierarchyProvider"); //$NON-NLS-1$

private final Collection<SonarLintEP<?>> allEps = List.of(configuratorEp, analysisEp, projectsProviderEp, fileAdapterParticipantEp, projectAdapterParticipantEp,
languageEp, typeEp, syntaxHighlightingProviderEP, projectHierarchyProviderEP);
languageEp, typeEp, projectHierarchyProviderEP);

private SonarLintExtensionTracker() {
init(allEps);
Expand Down Expand Up @@ -96,10 +93,6 @@ public Collection<IFileTypeProvider> getTypeProviders() {
return typeEp.getInstances();
}

public Collection<ISyntaxHighlightingProvider> getSyntaxHighlightingProvider() {
return syntaxHighlightingProviderEP.getInstances();
}

public Collection<ISonarLintProjectHierarchyProvider> getProjectHierarchyProviders() {
return projectHierarchyProviderEP.getInstances();
}
Expand Down
2 changes: 1 addition & 1 deletion org.sonarlint.eclipse.jdt/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</enhancer>
</extension>
<extension
point="org.sonarlint.eclipse.core.syntaxHighlightingProvider">
point="org.sonarlint.eclipse.ui.syntaxHighlightingProvider">
<enhancer
class="org.sonarlint.eclipse.jdt.internal.JavaProjectConfiguratorExtension">
</enhancer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion org.sonarlint.eclipse.pydev/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<extension
point="org.sonarlint.eclipse.core.syntaxHighlightingProvider">
point="org.sonarlint.eclipse.ui.syntaxHighlightingProvider">
<enhancer
class="org.sonarlint.eclipse.pydev.internal.PythonProjectConfiguratorExtension">
</enhancer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion org.sonarlint.eclipse.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
3 changes: 3 additions & 0 deletions org.sonarlint.eclipse.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<?eclipse version="3.0"?>
<plugin>
<extension-point id="markerResolutionEnhancer" name="SonarLint Marker Resolution Enhancer" schema="schema/markerResolutionEnhancer.exsd"/>
<extension-point id="syntaxHighlightingProvider"
name="SonarLint Syntax Highlighting Provider"
schema="schema/syntaxHighlightingProvider.exsd"/>

<!-- Extensions -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.sonarlint.eclipse.core" xmlns="http://www.w3.org/2001/XMLSchema">
<schema targetNamespace="org.sonarlint.eclipse.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.sonarlint.eclipse.core" id="syntaxHighlightingProvider" name="SonarLint Syntax Highlighting Provider"/>
<meta.schema plugin="org.sonarlint.eclipse.ui" id="syntaxHighlightingProvider" name="SonarLint Syntax Highlighting Provider"/>
</appInfo>
<documentation>
Help rule descriptions to find the correct syntax highlighting configuration for code snippets based on the external plugin implementation
Expand Down Expand Up @@ -55,7 +55,7 @@

</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.sonarlint.eclipse.core.internal.rule.ISyntaxHighlightingProvider"/>
<meta.attribute kind="java" basedOn=":org.sonarlint.eclipse.ui.internal.rule.ISyntaxHighlightingProvider"/>
</appInfo>
</annotation>
</attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMarkerResolutionEnhancer> markerResolutionEnhancerEp = new SonarLintEP<>("org.sonarlint.eclipse.ui.markerResolutionEnhancer"); //$NON-NLS-1$
private final SonarLintEP<ISyntaxHighlightingProvider> syntaxHighlightingProviderEP = new SonarLintEP<>(
"org.sonarlint.eclipse.ui.syntaxHighlightingProvider"); //$NON-NLS-1$

private final Collection<SonarLintEP<?>> allEps = List.of(markerResolutionEnhancerEp);
private final Collection<SonarLintEP<?>> allEps = List.of(markerResolutionEnhancerEp, syntaxHighlightingProviderEP);

private SonarLintUiExtensionTracker() {
init(allEps);
Expand All @@ -53,4 +56,7 @@ public Collection<IMarkerResolutionEnhancer> getMarkerResolutionEnhancers() {
return markerResolutionEnhancerEp.getInstances();
}

public Collection<ISyntaxHighlightingProvider> getSyntaxHighlightingProvider() {
return syntaxHighlightingProviderEP.getInstances();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a641499

Please sign in to comment.