From 4cfbe34a8841d1e66f226719ff3e2a4da2f285b9 Mon Sep 17 00:00:00 2001 From: Alice Trifu Date: Sun, 10 Mar 2024 12:44:13 -0400 Subject: [PATCH] Created JSON Compilation Database Generator preference page and set file --- .../org.eclipse.pde.ds.annotations.prefs | 7 + .../META-INF/MANIFEST.MF | 7 + ...atabase.BuiltinPreferedOptionsDefaults.xml | 7 + ...database.PreferenceConfigurationAccess.xml | 10 + ...iondatabase.PreferenceMetadataDefaults.xml | 8 + .../build.properties | 3 +- .../plugin.xml | 4 +- .../BuiltinPreferedOptionsDefaults.java | 25 ++ .../CompilationDatabaseGeneratorBlock.java | 272 ++++++++++++++---- .../ui/compilationdatabase/Configuration.java | 45 +++ .../ConfigurationAccess.java | 43 +++ .../ConfigurationArea.java | 75 +++++ .../compilationdatabase/ExistingResource.java | 49 ++++ .../GenerateCDBEnable.java | 26 ++ .../JsonCdbGeneratorPreferencePage.java | 10 - .../JsonCdbGeneratorPropertyPage.java | 10 - .../ui/compilationdatabase/Messages.java | 2 + .../PreferenceConfigurationAccess.java | 80 ++++++ .../PreferenceConfigurationArea.java | 60 ++++ .../PreferenceMetadataDefaults.java | 33 +++ .../PreferenceOptions.java | 22 ++ .../PreferenceOptionsDefaults.java | 17 ++ .../PreferencePreferredOptions.java | 44 +++ .../PreferencesMetadata.java | 28 ++ .../compilationdatabase/PreferredOptions.java | 47 +++ .../ui/compilationdatabase/Qualifier.java | 12 + .../compilationdatabase/ResolveProject.java | 54 ++++ .../ResolveProjectScope.java | 35 +++ .../compilationdatabase/messages.properties | 4 +- .../releases/11.5/compositeArtifacts.xml | 12 + .../releases/11.5/compositeContent.xml | 12 + .../releases/latest/compositeArtifacts.xml | 4 +- .../releases/latest/compositeContent.xml | 4 +- releng/scripts/promote-files-to-download.sh | 1 + 34 files changed, 990 insertions(+), 82 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/.settings/org.eclipse.pde.ds.annotations.prefs create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.BuiltinPreferedOptionsDefaults.xml create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceConfigurationAccess.xml create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceMetadataDefaults.xml create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/BuiltinPreferedOptionsDefaults.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Configuration.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ConfigurationAccess.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ConfigurationArea.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ExistingResource.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/GenerateCDBEnable.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceConfigurationAccess.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceConfigurationArea.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceMetadataDefaults.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceOptions.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceOptionsDefaults.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferencePreferredOptions.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferencesMetadata.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferredOptions.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Qualifier.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ResolveProject.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ResolveProjectScope.java create mode 100644 releng/download/releases/11.5/compositeArtifacts.xml create mode 100644 releng/download/releases/11.5/compositeContent.xml diff --git a/build/org.eclipse.cdt.managedbuilder.ui/.settings/org.eclipse.pde.ds.annotations.prefs b/build/org.eclipse.cdt.managedbuilder.ui/.settings/org.eclipse.pde.ds.annotations.prefs new file mode 100644 index 00000000000..38f9eecff8e --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/.settings/org.eclipse.pde.ds.annotations.prefs @@ -0,0 +1,7 @@ +dsVersion=V1_3 +eclipse.preferences.version=1 +enabled=true +generateBundleActivationPolicyLazy=true +path=OSGI-INF +validationErrorLevel=error +validationErrorLevel.missingImplicitUnbindMethod=error diff --git a/build/org.eclipse.cdt.managedbuilder.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.ui/META-INF/MANIFEST.MF index bb8375e721b..196a54f8deb 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.ui/META-INF/MANIFEST.MF @@ -27,3 +27,10 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-17 Automatic-Module-Name: org.eclipse.cdt.managedbuilder.ui +Service-Component: OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.BuiltinEditorOptionsDefault.xml, + OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.DefaultConfigurationVisibility.xml, + OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.EditorConfigurationAccess.xml, + OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.EditorMetadataDefaults.xml, + OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.BuiltinPreferedOptionsDefaults.xml, + OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceConfigurationAccess.xml, + OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceMetadataDefaults.xml diff --git a/build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.BuiltinPreferedOptionsDefaults.xml b/build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.BuiltinPreferedOptionsDefaults.xml new file mode 100644 index 00000000000..ac26a7bcdae --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.BuiltinPreferedOptionsDefaults.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceConfigurationAccess.xml b/build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceConfigurationAccess.xml new file mode 100644 index 00000000000..45f61850759 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceConfigurationAccess.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceMetadataDefaults.xml b/build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceMetadataDefaults.xml new file mode 100644 index 00000000000..383524e4d1c --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/OSGI-INF/org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.PreferenceMetadataDefaults.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/build/org.eclipse.cdt.managedbuilder.ui/build.properties b/build/org.eclipse.cdt.managedbuilder.ui/build.properties index a22b5265eb1..dfd8c9af335 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/build.properties +++ b/build/org.eclipse.cdt.managedbuilder.ui/build.properties @@ -16,7 +16,8 @@ bin.includes = plugin.xml,\ about.html,\ icons/,\ .,\ - META-INF/ + META-INF/,\ + OSGI-INF/ src.includes = schema/,\ about.html source.. = src/ diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index d1e0a8459a8..204de3966ee 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -342,7 +342,7 @@ @@ -817,7 +817,7 @@ diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/BuiltinPreferedOptionsDefaults.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/BuiltinPreferedOptionsDefaults.java new file mode 100644 index 00000000000..439376d4c0e --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/BuiltinPreferedOptionsDefaults.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import org.osgi.service.component.annotations.Component; + +@Component +public class BuiltinPreferedOptionsDefaults implements PreferenceOptionsDefaults { + + @Override + public boolean generateCDB() { + return false; + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/CompilationDatabaseGeneratorBlock.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/CompilationDatabaseGeneratorBlock.java index 92921cf2041..bfc6e6d6102 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/CompilationDatabaseGeneratorBlock.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/CompilationDatabaseGeneratorBlock.java @@ -9,87 +9,251 @@ ********************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; -import org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder; -import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; -import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage; -import org.eclipse.cdt.ui.dialogs.ICOptionContainer; -import org.eclipse.cdt.ui.dialogs.ICOptionContainerExtension; -import org.eclipse.cdt.ui.dialogs.PreferenceScopeBlock; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.preference.IPreferenceStore; +import java.util.Optional; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.preference.IPreferencePageContainer; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.PreferencesUtil; +import org.eclipse.ui.dialogs.PropertyPage; +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; +import org.eclipse.ui.preferences.IWorkingCopyManager; +import org.eclipse.ui.preferences.WorkingCopyManager; +import org.osgi.service.prefs.BackingStoreException; /** * @noextend This class is not intended to be subclasses by clients. * @since 9.5 */ -public class CompilationDatabaseGeneratorBlock extends AbstractCOptionPage { +public class CompilationDatabaseGeneratorBlock extends PropertyPage implements IWorkbenchPreferencePage { + + private final String id = "org.eclipse.cdt.managedbuilder.ui.compilationdatabase.JsonCdbPreferencePage"; //$NON-NLS-1$ + + protected Configuration configuration; + protected IWorkspace workspace; + + protected IWorkingCopyManager manager; - private static final String PREF_PAGE_ID = "org.eclipse.cdt.managedbuilder.ui.compilationdatabase.JsonCdbPreferencePage"; //$NON-NLS-1$ - private final String ENABLE_FILE_GENERATION = CommonBuilder.COMPILATION_DATABASE_ENABLEMENT; - private Button generateFileCheckbox; - private IPreferenceStore preferenceStore; - private PreferenceScopeBlock fPrefScopeBlock; + private Link link; + private Button specific; + private Control control; + protected ConfigurationArea area; - public CompilationDatabaseGeneratorBlock() { - preferenceStore = ManagedBuilderUIPlugin.getDefault().getPreferenceStore(); + @Override + public void init(IWorkbench workbench) { + this.configuration = workbench.getService(Configuration.class); + this.workspace = workbench.getService(IWorkspace.class); } @Override - public void createControl(Composite parent) { - final Composite composite = new Composite(parent, SWT.NONE); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - composite.setLayout(new GridLayout(1, false)); - if (getProject() != null || getContainer() instanceof ICOptionContainerExtension) { - fPrefScopeBlock = new PreferenceScopeBlock(PREF_PAGE_ID) { - @Override - protected void onPreferenceScopeChange() { - generateFileCheckbox.setSelection(preferenceStore.getBoolean(ENABLE_FILE_GENERATION)); - } - }; - fPrefScopeBlock.createControl(composite); - fPrefScopeBlock.setInstanceScope(); + public void setContainer(IPreferencePageContainer container) { + super.setContainer(container); + if (manager == null) { + manager = Optional.ofNullable(container)// + .filter(IWorkbenchPreferenceContainer.class::isInstance)// + .map(IWorkbenchPreferenceContainer.class::cast)// + .map(IWorkbenchPreferenceContainer::getWorkingCopyManager)// + .orElseGet(WorkingCopyManager::new); + } + if (configuration == null) { + configuration = getConfiguration(); } - Group cdbGeneratorOptions = new Group(composite, SWT.NONE); - cdbGeneratorOptions.setLayout(new FillLayout(SWT.HORIZONTAL)); - cdbGeneratorOptions.setText(Messages.JsonCdbGeneratorPreferencePage_description); - cdbGeneratorOptions.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - generateFileCheckbox = new Button(cdbGeneratorOptions, SWT.CHECK); - generateFileCheckbox.setSelection(preferenceStore.getBoolean(ENABLE_FILE_GENERATION)); - generateFileCheckbox.setText(Messages.JsonCdbGeneratorPreferencePage_generateCompilationdatabase); + if (workspace == null) { + workspace = PlatformUI.getWorkbench().getService(IWorkspace.class); + } + } + + protected Configuration getConfiguration() { + return PlatformUI.getWorkbench().getService(Configuration.class); } @Override - public void performDefaults() { - preferenceStore.setToDefault(ENABLE_FILE_GENERATION); + protected Label createDescriptionLabel(Composite parent) { + if (projectScope().isPresent()) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create()); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + specific = new Button(composite, SWT.CHECK); + specific.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, false)); + specific.setText(Messages.JsonCdbGeneratorPropertyPage_enableProjectSpecific); + specific.setFont(JFaceResources.getDialogFont()); + specific.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> specificSelected())); + link = createLink(composite, Messages.JsonCdbGeneratorPropertyPage_configureWorkspace); + link.setLayoutData(new GridData(SWT.END, SWT.TOP, false, false)); + Label line = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); + line.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); + line.setFont(composite.getFont()); + } + return super.createDescriptionLabel(parent); + } + + private void specificSelected() { + enableProjectSpecificSettings(specific.getSelection()); + refreshWidgets(configuration.options(getElement())); + } + + private Link createLink(Composite composite, String text) { + Link link = new Link(composite, SWT.NONE); + link.setFont(composite.getFont()); + link.setText("" + text + ""); //$NON-NLS-1$ //$NON-NLS-2$ + link.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (PreferencesUtil.createPreferenceDialogOn(getShell(), getPreferenceId(), + new String[] { id, getPreferenceId() }, null).open() == Window.OK) { + refreshWidgets(configuration.options(getElement())); + } + } + }); + return link; + } + + protected String getPreferenceId() { + return id; } @Override - public void performApply(IProgressMonitor monitor) throws CoreException { - preferenceStore.setValue(ENABLE_FILE_GENERATION, generateFileCheckbox.getSelection()); + protected Control createContents(Composite parent) { + var isProjectScope = projectScope().isPresent(); + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).create()); + composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); + composite.setFont(parent.getFont()); + control = createPreferenceContent(composite, isProjectScope); + control.setLayoutData(new GridData(GridData.FILL_BOTH)); + if (isProjectScope) { + enableProjectSpecificSettings(hasProjectSpecificOptions()); + } + refreshWidgets(configuration.options(getElement())); + Dialog.applyDialogFont(composite); + return composite; } - private IProject getProject() { - ICOptionContainer container = getContainer(); - if (container != null) { - if (container instanceof ICOptionContainerExtension) { + protected ConfigurationArea getConfigurationArea(Composite composite, boolean isProjectScope) { + return new PreferenceConfigurationArea(composite, (PreferencesMetadata) configuration.metadata(), + isProjectScope); + } + + private Control createPreferenceContent(Composite parent, boolean isProjectScope) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(GridLayoutFactory.fillDefaults().create()); + composite.setFont(parent.getFont()); + area = getConfigurationArea(composite, isProjectScope); + return composite; + } + + protected void refreshWidgets(Object options) { + setErrorMessage(null); + area.load(options, useProjectSettings() || !projectScope().isPresent()); + + } + + protected Optional projectScope() { + return new ResolveProjectScope(workspace).apply(getElement()); + } + + @Override + protected void performDefaults() { + if (useProjectSettings()) { + enableProjectSpecificSettings(false); + } + IEclipsePreferences prefs = manager.getWorkingCopy(scope().getNode(configuration.qualifier())); + try { + for (String key : prefs.keys()) { + prefs.remove(key); + } + } catch (BackingStoreException e) { + Platform.getLog(getClass()).error("Unable to restore default values.", e); //$NON-NLS-1$ + } + refreshWidgets(configuration.defaults()); + super.performDefaults(); + } + + @Override + public boolean performOk() { + IEclipsePreferences prefs; + if (projectScope().isPresent()) { + prefs = manager.getWorkingCopy(projectScope().get().getNode(configuration.qualifier())); + if (!useProjectSettings()) { try { - return ((ICOptionContainerExtension) container).getProjectHandle(); - } catch (Exception e) { - ManagedBuilderUIPlugin.log(e); + for (String key : prefs.keys()) { + prefs.remove(key); + } + } catch (BackingStoreException e) { + Platform.getLog(getClass()).error("Unable to reset project preferences.", e); //$NON-NLS-1$ } + prefs = null; } - return container.getProject(); + } else { + prefs = manager.getWorkingCopy(InstanceScope.INSTANCE.getNode(configuration.qualifier())); } - return null; + if (prefs != null) { + area.store(prefs); + } + try { + manager.applyChanges(); + } catch (BackingStoreException e) { + Platform.getLog(getClass()).error("Unable to save preferences.", e); //$NON-NLS-1$ + return false; + } + return true; + } + + private IScopeContext scope() { + return projectScope().map(IScopeContext.class::cast).orElse(InstanceScope.INSTANCE); + } + + protected boolean hasProjectSpecificOptions() { + return projectScope()// + .map(p -> p.getNode(configuration.qualifier()))// + .map(n -> n.get(((PreferencesMetadata) configuration.metadata()).generateCDBFile().identifer(), null))// + .isPresent(); + } + + protected boolean useProjectSettings() { + return Optional.ofNullable(specific)// + .map(s -> s.getSelection())// + .orElse(Boolean.FALSE); + } + + protected void enableProjectSpecificSettings(boolean use) { + specific.setSelection(use); + updateLinkVisibility(); + } + + private void updateLinkVisibility() { + Optional.ofNullable(link)// + .filter(l -> !l.isDisposed())// + .ifPresent(l -> l.setEnabled(!useProjectSettings())); + } + + @Override + public void dispose() { + Optional.ofNullable(area).ifPresent(ConfigurationArea::dispose); + super.dispose(); } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Configuration.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Configuration.java new file mode 100644 index 00000000000..b5ecdb88fe2 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Configuration.java @@ -0,0 +1,45 @@ +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.net.URI; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.preferences.IPreferenceMetadataStore; + +public interface Configuration { + + /** + * Returns the defaults + * + * @return defaults + */ + Object defaults(); + + /** + * Returns the options for the given context like {@link IResource} or {@link URI}, must not return null + * @param context to be adapter to the proper scope + * + * @return options + */ + Object options(Object context); + + /** + * Returns the editor preference store for the given context like {@link IResource} or {@link URI}, must not return null + * @param context to be adapter to the proper scope + * + * @return preference store + */ + IPreferenceMetadataStore storage(Object context); + + /** + * Return the metadata for options, must not return null + * + * @return the option metadata + */ + Object metadata(); + + /** + * Default qualifier to use for preference storage + * @return preference qualifier + */ + String qualifier(); +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ConfigurationAccess.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ConfigurationAccess.java new file mode 100644 index 00000000000..a749a783ee2 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ConfigurationAccess.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.util.Optional; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.osgi.util.NLS; + +public abstract class ConfigurationAccess { + protected final String qualifier; + + public ConfigurationAccess(String qualifier) { + this.qualifier = qualifier; + } + + protected Optional projectScope(IWorkspace workspace, Object context) { + return new ResolveProjectScope(workspace).apply(context); + } + + protected IEclipsePreferences preferences(IScopeContext scope) { + return Optional.ofNullable(scope.getNode(qualifier))// + .filter(IEclipsePreferences.class::isInstance)// + .map(IEclipsePreferences.class::cast)// + .orElseThrow(() -> new IllegalStateException(// + NLS.bind("Unable to get preferences for node: {0}", // //$NON-NLS-1$ + qualifier))); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ConfigurationArea.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ConfigurationArea.java new file mode 100644 index 00000000000..37162b4b3e8 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ConfigurationArea.java @@ -0,0 +1,75 @@ +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; + +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.PreferenceMetadata; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.TypedEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; + +public abstract class ConfigurationArea { + protected final Map, Button> buttons; + protected final List> listeners; + protected final int columns; + + public ConfigurationArea(int columns) { + this.buttons = new HashMap<>(); + this.listeners = new ArrayList<>(); + this.columns = columns; + + } + + protected Group createGroup(Composite parent, String label, int numColumns) { + Group group = new Group(parent, SWT.NONE); + group.setFont(parent.getFont()); + group.setText(label); + GridLayout layout = new GridLayout(); + layout.numColumns = numColumns; + group.setLayout(layout); + group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + return group; + } + + protected Button createButton(PreferenceMetadata meta, Composite composite, int style, + int horizontalIndent) { + Button button = new Button(composite, style); + button.setLayoutData(GridDataFactory.fillDefaults().span(columns, 1).indent(horizontalIndent, 0).create()); + button.setData(meta); + button.setText(meta.name()); + button.setToolTipText(meta.description()); + buttons.put(meta, button); + return button; + } + + public void addChangeListener(Consumer listener) { + listeners.add(listener); + } + + public void removeChangeListener(Consumer listener) { + listeners.add(listener); + } + + public void changed(TypedEvent event) { + listeners.forEach(c -> c.accept(event)); + } + + public void dispose() { + listeners.clear(); + buttons.clear(); + } + + public abstract void load(Object options, boolean enable); + + public abstract void store(IEclipsePreferences prefs); + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ExistingResource.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ExistingResource.java new file mode 100644 index 00000000000..84b88d3caf0 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ExistingResource.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2023 ArSysOp and others. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Alexander Fedorov (ArSysOp) - initial API + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.net.URI; +import java.util.Arrays; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; + +public final class ExistingResource implements Function> { + + private final IWorkspace workspace; + + public ExistingResource(IWorkspace workspace) { + this.workspace = Objects.requireNonNull(workspace); + } + + @Override + public Optional apply(URI uri) { + return forContainer(uri).or(() -> forFile(uri)); + } + + private Optional forContainer(URI uri) { + return Arrays.stream(workspace.getRoot().findContainersForLocationURI(uri))// + .map(IResource.class::cast)// + .filter(c -> c.exists())// + .findFirst(); + } + + private Optional forFile(URI uri) { + return Arrays.stream(workspace.getRoot().findFilesForLocationURI(uri))// + .map(IResource.class::cast)// + .filter(c -> c.exists())// + .findFirst(); + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/GenerateCDBEnable.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/GenerateCDBEnable.java new file mode 100644 index 00000000000..d82b320c876 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/GenerateCDBEnable.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import org.eclipse.core.resources.IProject; + +public interface GenerateCDBEnable { + + /** + * Checks whether the generation of the compilation database file should be enabled for the given project. + * The enable can be linked with certain project properties (e.g. project natures). + * @param project + * @return true when the generation of compilation database file should be enabled for the given project + */ + public boolean isEnabledFor(IProject project); +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java index dc2361a25ce..6ca2209fa70 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java @@ -9,12 +9,8 @@ ********************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; -import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.ui.dialogs.ICOptionContainer; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -34,7 +30,6 @@ public class JsonCdbGeneratorPreferencePage extends PreferencePage public JsonCdbGeneratorPreferencePage() { fOptionBlock = new CompilationDatabaseGeneratorBlock(); - fOptionBlock.setContainer(this); } @Override @@ -71,11 +66,6 @@ public org.eclipse.core.runtime.Preferences getPreferences() { @Override public boolean performOk() { - try { - fOptionBlock.performApply(new NullProgressMonitor()); - } catch (CoreException e) { - ManagedBuilderUIPlugin.log(Status.error("Failed to save JSON Compilation Database Generator settings", e)); //$NON-NLS-1$ - } return true; } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPropertyPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPropertyPage.java index 9817495d591..a5833de00a5 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPropertyPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPropertyPage.java @@ -10,14 +10,10 @@ package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; -import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.ui.dialogs.ICOptionContainer; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.Status; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -34,7 +30,6 @@ public class JsonCdbGeneratorPropertyPage extends PropertyPage implements ICOpti public JsonCdbGeneratorPropertyPage() { super(); optionPage = new CompilationDatabaseGeneratorBlock(); - optionPage.setContainer(this); } @Override @@ -52,11 +47,6 @@ protected void performDefaults() { @Override public boolean performOk() { - try { - optionPage.performApply(new NullProgressMonitor()); - } catch (CoreException e) { - ManagedBuilderUIPlugin.log(Status.error("Failed to save JSON Compilation Database Generator settings", e)); //$NON-NLS-1$ - } return true; } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Messages.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Messages.java index 884a7e5f672..1836c7e3754 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Messages.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Messages.java @@ -16,6 +16,8 @@ class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.messages"; //$NON-NLS-1$ public static String JsonCdbGeneratorPreferencePage_description; public static String JsonCdbGeneratorPreferencePage_generateCompilationdatabase; + public static String JsonCdbGeneratorPropertyPage_configureWorkspace; + public static String JsonCdbGeneratorPropertyPage_enableProjectSpecific; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceConfigurationAccess.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceConfigurationAccess.java new file mode 100644 index 00000000000..23809fba545 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceConfigurationAccess.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.util.Optional; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.core.runtime.preferences.IPreferenceMetadataStore; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.core.runtime.preferences.OsgiPreferenceMetadataStore; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; + +@Component +public class PreferenceConfigurationAccess extends ConfigurationAccess implements Configuration { + + @Reference + private PreferencesMetadata metadata; + + @Reference + private IWorkspace workspace; + + @Reference(cardinality = ReferenceCardinality.OPTIONAL) + private GenerateCDBEnable enable; + + public PreferenceConfigurationAccess() { + super(new Qualifier().get()); + } + + @Override + public PreferenceOptions defaults() { + return new PreferencePreferredOptions(qualifier, new IScopeContext[] { DefaultScope.INSTANCE }, metadata, enable); + } + + @Override + public PreferenceOptions options(Object context) { + Optional project = projectScope(workspace, context); + IScopeContext[] scopes; + if (project.isPresent()) { + scopes = new IScopeContext[] { project.get(), InstanceScope.INSTANCE, DefaultScope.INSTANCE }; + } else { + scopes = new IScopeContext[] { InstanceScope.INSTANCE, DefaultScope.INSTANCE }; + } + return new PreferencePreferredOptions(qualifier, scopes, metadata, enable); + } + + @Override + public IPreferenceMetadataStore storage(Object context) { + return new OsgiPreferenceMetadataStore(// + preferences(// + projectScope(workspace, context)// + .map(IScopeContext.class::cast)// + .orElse(InstanceScope.INSTANCE))); + } + + @Override + public PreferencesMetadata metadata() { + return metadata; + } + + @Override + public String qualifier() { + return qualifier; + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceConfigurationArea.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceConfigurationArea.java new file mode 100644 index 00000000000..61dbccbfa9a --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceConfigurationArea.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2023 ArSysOp. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Alexander Fedorov (ArSysOp) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder; +import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.OsgiPreferenceMetadataStore; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +public final class PreferenceConfigurationArea extends ConfigurationArea { + + private final Button generateCDBFileButton; + private final String ENABLE_FILE_GENERATION = CommonBuilder.COMPILATION_DATABASE_ENABLEMENT; + private IPreferenceStore preferenceStore; + + public PreferenceConfigurationArea(Composite parent, PreferencesMetadata metadata, boolean isProjectScope) { + super(1); + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(columns).create()); + this.generateCDBFileButton = createButton(metadata.generateCDBFile(), composite, SWT.CHECK, 0); + preferenceStore = ManagedBuilderUIPlugin.getDefault().getPreferenceStore(); + } + + @Override + public void load(Object options, boolean enable) { + if (options instanceof PreferenceOptions editorOptions) { + if (generateCDBFileButton != null) { + generateCDBFileButton.setSelection(editorOptions.generateCDB()); + generateCDBFileButton.setEnabled(enable); + } + } + + } + + @Override + public void store(IEclipsePreferences prefs) { + OsgiPreferenceMetadataStore store = new OsgiPreferenceMetadataStore(prefs); + buttons.entrySet().forEach(e -> store.save(e.getValue().getSelection(), e.getKey())); + preferenceStore.setValue(ENABLE_FILE_GENERATION, generateCDBFileButton.getSelection()); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceMetadataDefaults.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceMetadataDefaults.java new file mode 100644 index 00000000000..52bde1e0054 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceMetadataDefaults.java @@ -0,0 +1,33 @@ +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +import org.eclipse.core.runtime.preferences.PreferenceMetadata; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +@Component +public class PreferenceMetadataDefaults implements PreferencesMetadata { + + @Reference + private PreferenceOptionsDefaults defaults; + + @Override + public PreferenceMetadata generateCDBFile() { + return new PreferenceMetadata<>(Boolean.class, // + "generateCDB", defaults.generateCDB(), // //$NON-NLS-1$ + Messages.JsonCdbGeneratorPreferencePage_generateCompilationdatabase, + Messages.JsonCdbGeneratorPreferencePage_description); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceOptions.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceOptions.java new file mode 100644 index 00000000000..e52f5cf430f --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceOptions.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +public interface PreferenceOptions { + + /** + * Compilation Database Generator needed + */ + boolean generateCDB(); + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceOptionsDefaults.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceOptionsDefaults.java new file mode 100644 index 00000000000..bcb8c3cda1a --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferenceOptionsDefaults.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +public interface PreferenceOptionsDefaults extends PreferenceOptions { + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferencePreferredOptions.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferencePreferredOptions.java new file mode 100644 index 00000000000..667c13cb68b --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferencePreferredOptions.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.util.Objects; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.preferences.IScopeContext; + +public class PreferencePreferredOptions extends PreferredOptions implements PreferenceOptions, GenerateCDBEnable { + private final PreferencesMetadata metadata; + private final GenerateCDBEnable enable; + + public PreferencePreferredOptions(String qualifier, IScopeContext[] scopes, PreferencesMetadata metadata, + GenerateCDBEnable enable) { + super(qualifier, scopes); + this.metadata = Objects.requireNonNull(metadata); + this.enable = enable; + } + + @Override + public boolean generateCDB() { + return booleanValue(metadata.generateCDBFile()); + } + + @Override + public boolean isEnabledFor(IProject project) { + if (enable != null) { + return enable.isEnabledFor(project); + } + return booleanValue(metadata.generateCDBFile()); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferencesMetadata.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferencesMetadata.java new file mode 100644 index 00000000000..13805c5ccea --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferencesMetadata.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import org.eclipse.core.runtime.preferences.PreferenceMetadata; + +public interface PreferencesMetadata { + + /** + * Returns the metadata for the "Generate compile_commands.json file" option, must not return null. + * + * @return the metadata for the "Generate compile_commands.json file" option + * + * @see PreferenceOptions#generateCDB() + */ + PreferenceMetadata generateCDBFile(); + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferredOptions.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferredOptions.java new file mode 100644 index 00000000000..a72dc8f758c --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/PreferredOptions.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.util.Objects; +import java.util.Optional; + +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.PreferenceMetadata; + +public abstract class PreferredOptions { + protected final String qualifier; + protected final IScopeContext[] scopes; + + public PreferredOptions(String qualifier, IScopeContext[] scopes) { + this.qualifier = Objects.requireNonNull(qualifier); + this.scopes = Objects.requireNonNull(scopes); + } + + protected String stringValue(PreferenceMetadata meta) { + String actual = String.valueOf(meta.defaultValue()); + for (int i = scopes.length - 1; i >= 0; i--) { + IScopeContext scope = scopes[i]; + String previous = actual; + actual = scope.getNode(qualifier).get(meta.identifer(), previous); + } + return actual; + } + + protected boolean booleanValue(PreferenceMetadata meta) { + return Optional.of(meta)// + .map(this::stringValue)// + .map(Boolean::valueOf)// + .orElseGet(meta::defaultValue); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Qualifier.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Qualifier.java new file mode 100644 index 00000000000..bf62f09fbb1 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/Qualifier.java @@ -0,0 +1,12 @@ +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.util.function.Supplier; + +public final class Qualifier implements Supplier { + + @Override + public String get() { + return "org.eclipse.cdt.managedbuilder.ui"; //$NON-NLS-1$ + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ResolveProject.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ResolveProject.java new file mode 100644 index 00000000000..0ebcf815568 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ResolveProject.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2023 ArSysOp. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Alexander Fedorov (ArSysOp) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.net.URI; +import java.util.Optional; +import java.util.function.Function; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.runtime.Adapters; + +public final class ResolveProject implements Function> { + + private final ExistingResource resolve; + + public ResolveProject(IWorkspace workspace) { + this.resolve = new ExistingResource(workspace); + } + + @Override + public Optional apply(Object context) { + return Optional.ofNullable(context)// + .flatMap(this::resource)// + .map(IResource::getProject); + } + + private Optional resource(Object object) { + return uri(object).or(() -> adapt(object)); + } + + private Optional uri(Object object) { + return Optional.ofNullable(object)// + .filter(URI.class::isInstance)// + .map(URI.class::cast)// + .flatMap(resolve); + } + + private Optional adapt(Object object) { + return Optional.ofNullable(Adapters.adapt(object, IResource.class)); + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ResolveProjectScope.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ResolveProjectScope.java new file mode 100644 index 00000000000..b190a9d60a4 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/ResolveProjectScope.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2023 ArSysOp. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Alexander Fedorov (ArSysOp) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; + +import java.util.Optional; +import java.util.function.Function; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ProjectScope; + +public final class ResolveProjectScope implements Function> { + + private final ResolveProject project; + + public ResolveProjectScope(IWorkspace workspace) { + this.project = new ResolveProject(workspace); + } + + @Override + public Optional apply(Object context) { + return project.apply(context).map(ProjectScope::new); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/messages.properties b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/messages.properties index e9d671ea720..ad0a26b0c7e 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/messages.properties +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/messages.properties @@ -8,4 +8,6 @@ # SPDX-License-Identifier: EPL-2.0 ############################################################################### JsonCdbGeneratorPreferencePage_description=Enables default generation of compile_commands.json file on build process -JsonCdbGeneratorPreferencePage_generateCompilationdatabase=Generate compile_commands.json file \ No newline at end of file +JsonCdbGeneratorPreferencePage_generateCompilationdatabase=Generate compile_commands.json file +JsonCdbGeneratorPropertyPage_configureWorkspace=Configure Workspace Settings... +JsonCdbGeneratorPropertyPage_enableProjectSpecific=Enable project-specific settings \ No newline at end of file diff --git a/releng/download/releases/11.5/compositeArtifacts.xml b/releng/download/releases/11.5/compositeArtifacts.xml new file mode 100644 index 00000000000..baccd2cfe9c --- /dev/null +++ b/releng/download/releases/11.5/compositeArtifacts.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/releng/download/releases/11.5/compositeContent.xml b/releng/download/releases/11.5/compositeContent.xml new file mode 100644 index 00000000000..657e86303e8 --- /dev/null +++ b/releng/download/releases/11.5/compositeContent.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/releng/download/releases/latest/compositeArtifacts.xml b/releng/download/releases/latest/compositeArtifacts.xml index b1472995862..6e3317bcbd6 100644 --- a/releng/download/releases/latest/compositeArtifacts.xml +++ b/releng/download/releases/latest/compositeArtifacts.xml @@ -4,9 +4,9 @@ type='org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository' version='1.0.0'> - + - + diff --git a/releng/download/releases/latest/compositeContent.xml b/releng/download/releases/latest/compositeContent.xml index b4982906d5c..3a7ec6bfef1 100644 --- a/releng/download/releases/latest/compositeContent.xml +++ b/releng/download/releases/latest/compositeContent.xml @@ -4,9 +4,9 @@ type='org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository' version='1.0.0'> - + - + diff --git a/releng/scripts/promote-files-to-download.sh b/releng/scripts/promote-files-to-download.sh index 760f4e59a20..da4055787bc 100755 --- a/releng/scripts/promote-files-to-download.sh +++ b/releng/scripts/promote-files-to-download.sh @@ -26,6 +26,7 @@ $ECHO $SCP ./releng/download/releases/11.1/* "${SSHUSER}:${DOWNLOAD}/releases/11 $ECHO $SCP ./releng/download/releases/11.2/* "${SSHUSER}:${DOWNLOAD}/releases/11.2/" $ECHO $SCP ./releng/download/releases/11.3/* "${SSHUSER}:${DOWNLOAD}/releases/11.3/" $ECHO $SCP ./releng/download/releases/11.4/* "${SSHUSER}:${DOWNLOAD}/releases/11.4/" +$ECHO $SCP ./releng/download/releases/11.5/* "${SSHUSER}:${DOWNLOAD}/releases/11.5/" $ECHO $SSH mkdir -p "${DOWNLOAD}/releases/cdt-lsp-latest/" $ECHO $SCP ./releng/download/releases/cdt-lsp-latest/* "${SSHUSER}:${DOWNLOAD}/releases/cdt-lsp-latest/"