From b976ad7fbff682308b2d929027441505c4836a9c Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 19 Oct 2023 12:40:24 +0200 Subject: [PATCH] Allow customization of project names --- ...ProjectPerPackageProvisioningStrategy.java | 22 ++++++++++++++++++- .../projectview/BazelProjectFileReader.java | 13 +++++++++++ .../core/projectview/BazelProjectView.java | 2 ++ docs/common/projectviews.md | 6 +++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerPackageProvisioningStrategy.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerPackageProvisioningStrategy.java index 7c5a9fe9..63ba559b 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerPackageProvisioningStrategy.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerPackageProvisioningStrategy.java @@ -54,6 +54,8 @@ */ public class ProjectPerPackageProvisioningStrategy extends BaseProvisioningStrategy { + private static final String PROJECT_NAME_SEPARATOR_CHAR = "project_name_separator_char"; + public static final String STRATEGY_NAME = "project-per-package"; private static Logger LOG = LoggerFactory.getLogger(ProjectPerPackageProvisioningStrategy.class); @@ -262,6 +264,23 @@ protected List doProvisionProjects(Collection targets return result; } + private char getProjectNameSeparatorChar(BazelPackage bazelPackage) throws CoreException { + var separatorChar = bazelPackage.getBazelWorkspace() + .getBazelProjectView() + .targetProvisioningSettings() + .get(PROJECT_NAME_SEPARATOR_CHAR); + if (separatorChar == null) { + return '.'; + } + + separatorChar = separatorChar.trim(); + if (separatorChar.length() != 1) { + throw new CoreException(Status.error("Invalid 'project_name_separator_char' setting in project view!")); + } + + return separatorChar.charAt(0); + } + private boolean isSupported(BazelTarget bazeltarget) { String ruleName; try { @@ -287,7 +306,8 @@ protected BazelProject provisionPackageProject(BazelPackage bazelPackage, List importingFiles = new LinkedHashSet<>(); IPath bazelBinary; + final LinkedHashMap targetProvisioningSettings = new LinkedHashMap<>(); final LinkedHashMap projectMappings = new LinkedHashMap<>(); final LinkedHashSet importPreferences = new LinkedHashSet<>(); final LinkedHashSet projectSettings = new LinkedHashSet<>(); @@ -131,6 +132,7 @@ public BazelProjectView build() throws IllegalStateException { bazelBinary, targetDiscoveryStrategy, targetProvisioningStrategy, + targetProvisioningSettings, projectMappings, preferencesToImport, projectSettingsToSync, @@ -334,6 +336,17 @@ private void parseProjectFile(Path bazelProjectFile, BazelProjectViewBuilder bui } break; } + case "target_provisioning_settings": { + parseSectionBodyIntoList(rawSection).forEach(s -> { + var separator = s.indexOf('='); + if (separator != -1) { + var key = s.substring(0, separator).trim(); + var value = s.substring(separator + 1).trim(); + builder.targetProvisioningSettings.put(key, value); + } + }); + break; + } case "import_preferences": { parseSectionBodyIntoList(rawSection).forEach(builder.importPreferences::add); break; diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/projectview/BazelProjectView.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/projectview/BazelProjectView.java index db089e3b..e3952a02 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/projectview/BazelProjectView.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/projectview/BazelProjectView.java @@ -38,6 +38,7 @@ public record BazelProjectView( IPath bazelBinary, String targetDiscoveryStrategy, String targetProvisioningStrategy, + Map targetProvisioningSettings, Map projectMappings, Collection importPreferences, Collection projectSettings, @@ -52,6 +53,7 @@ public record BazelProjectView( targets = Collections.unmodifiableCollection(targets); additionalLanguages = Collections.unmodifiableCollection(additionalLanguages); tsConfigRules = Collections.unmodifiableCollection(tsConfigRules); + targetProvisioningSettings = Collections.unmodifiableMap(targetProvisioningSettings); projectMappings = Collections.unmodifiableMap(projectMappings); importPreferences = Collections.unmodifiableCollection(importPreferences); projectSettings = Collections.unmodifiableCollection(projectSettings); diff --git a/docs/common/projectviews.md b/docs/common/projectviews.md index d9ed421f..9ea0ff75 100644 --- a/docs/common/projectviews.md +++ b/docs/common/projectviews.md @@ -144,6 +144,12 @@ For details please read the JavaDoc (and Java code) of [ProjectPerPackageProvisi * It requires running `bazel build` to detect classpath configuration. * Is not fully implemented and required help/work/contributions. +### `target_provisioning_settings` + +A list of settings to further tweak the `target_provisioning_strategy`. +The syntax of each entry is `key = value`, where `key` and `value` are expected string values (without any whitespace characters). + + ### `project_mappings` A list of mappings from targets (typically from external repositories) to projects in the IDE.