From 6f1df20a73ed03994933bf0251db58101d4b4a4c Mon Sep 17 00:00:00 2001 From: ashitsalesforce Date: Mon, 14 Oct 2024 13:16:59 -0700 Subject: [PATCH] generate csv of all configurable properties including command line options generate csv of all configurable properties including command line options if salesforce.loader.generatePropsCSV=true is specified as a command line option. --- .../dataloader/config/AppConfig.java | 11 +- .../config/ConfigPropertyMetadata.java | 109 ++++++++++++++---- .../dataloader/install/Installer.java | 7 ++ .../salesforce/dataloader/util/AppUtil.java | 1 + 4 files changed, 106 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/salesforce/dataloader/config/AppConfig.java b/src/main/java/com/salesforce/dataloader/config/AppConfig.java index 5bdeda8e1..7bde86467 100644 --- a/src/main/java/com/salesforce/dataloader/config/AppConfig.java +++ b/src/main/java/com/salesforce/dataloader/config/AppConfig.java @@ -513,6 +513,9 @@ public class AppConfig { // They are neither read from, nor written to config.properties file. private static final String[] INTERNAL_PROPERTY_NAMES = { PROP_OAUTH_CLIENTID, + PROP_SFDC_INTERNAL, + PROP_SFDC_INTERNAL_IS_SESSION_ID_LOGIN, + PROP_SFDC_INTERNAL_SESSION_ID, }; private static final String[] ENCRYPTED_PROPERTY_NAMES = { @@ -559,6 +562,9 @@ private AppConfig(String filename, Map cliOptionsMap) throws Con // Properties initialization completed. Configure OAuth environment next setOAuthEnvironment(getString(PROP_SELECTED_AUTH_ENVIRONMENT)); + if (getBoolean(AppUtil.CLI_OPTION_GENERATE_PROPERTIES_CSV)) { + ConfigPropertyMetadata.printCSV(this); + } } private String getLastRunPrefix() { @@ -1778,7 +1784,10 @@ private static boolean createDir(File dirPath) { * @throws IOException * @throws FactoryConfigurationError */ - public static synchronized AppConfig getInstance(Map argMap) throws ConfigInitializationException, FactoryConfigurationError, IOException { + public static synchronized AppConfig getInstance(Map argMap) throws ConfigInitializationException, FactoryConfigurationError, IOException { + if (argMap == null) { + argMap = new HashMap(); + } AppUtil.initializeAppConfig(AppUtil.convertCommandArgsMapToArgsArray(argMap)); logger = LogManager.getLogger(AppConfig.class); diff --git a/src/main/java/com/salesforce/dataloader/config/ConfigPropertyMetadata.java b/src/main/java/com/salesforce/dataloader/config/ConfigPropertyMetadata.java index a18aafa07..e5a985b9a 100644 --- a/src/main/java/com/salesforce/dataloader/config/ConfigPropertyMetadata.java +++ b/src/main/java/com/salesforce/dataloader/config/ConfigPropertyMetadata.java @@ -25,9 +25,16 @@ */ package com.salesforce.dataloader.config; +import java.io.File; +import java.io.IOException; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.HashMap; +import com.salesforce.dataloader.dao.csv.CSVFileWriter; +import com.salesforce.dataloader.exception.DataAccessObjectException; +import com.salesforce.dataloader.exception.DataAccessObjectInitializationException; +import com.salesforce.dataloader.model.Row; import com.salesforce.dataloader.ui.Labels; import com.salesforce.dataloader.util.AppUtil; @@ -43,13 +50,13 @@ public class ConfigPropertyMetadata { private boolean encrypted = false; private boolean internal = false; private boolean commandLineOption = false; - private final String uiLabelTemplate; - private final String uiTooltipTemplate; + private String uiLabelTemplate = ""; + private String uiTooltipTemplate = ""; static { Field[] appConfigFields = AppConfig.class.getDeclaredFields(); for (Field configField : appConfigFields) { - if (configField.getName().startsWith("PROP_") + if ((configField.getName().startsWith("PROP_") && !configField.getName().startsWith("PROP_SFDC_INTERNAL")) || configField.getName().startsWith("CLI_OPTION_")) { String propName; try { @@ -57,7 +64,7 @@ public class ConfigPropertyMetadata { } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { continue; } - ConfigPropertyMetadata configProp = new ConfigPropertyMetadata(configField.getName()); + ConfigPropertyMetadata configProp = new ConfigPropertyMetadata(propName); configProp.setEncrypted(AppConfig.isEncryptedProperty(propName)); configProp.setReadOnly(AppConfig.isReadOnlyProperty(propName)); configProp.setInternal(AppConfig.isInternalProperty(propName)); @@ -73,33 +80,27 @@ public class ConfigPropertyMetadata { } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { continue; } - ConfigPropertyMetadata configProp = new ConfigPropertyMetadata(configField.getName()); + ConfigPropertyMetadata configProp = new ConfigPropertyMetadata(propName); configProp.setReadOnly(true); propertiesMap.put(propName, configProp); } } } - public ConfigPropertyMetadata(String name) { - this.name = name; - this.uiLabelTemplate = Labels.getString("AdvancedSettingsDialog.uiLabel." + name); + public ConfigPropertyMetadata(String propName) { + this.name = propName; + this.uiLabelTemplate = Labels.getString("AdvancedSettingsDialog.uiLabel." + propName); + if (this.uiLabelTemplate == null + || (this.uiLabelTemplate.startsWith("!") && this.uiLabelTemplate.endsWith("!"))) { + this.uiLabelTemplate = ""; + } String tooltipText = null; - tooltipText = Labels.getString("AdvancedSettingsDialog.uiTooltip." + name); + tooltipText = Labels.getString("AdvancedSettingsDialog.uiTooltip." + propName); if (tooltipText != null && tooltipText.startsWith("!") && tooltipText.endsWith("!")) { tooltipText = null; } - String[] propArg = {this.name}; - try { - if (tooltipText == null) { - tooltipText = Labels.getFormattedString("AdvancedSettingsDialog.TooltipPropertyName", propArg); - } else { - tooltipText += "\n\n"; - tooltipText += Labels.getFormattedString("AdvancedSettingsDialog.TooltipPropertyName", propArg); - } - } catch (java.util.MissingResourceException e) { - // do nothing - } - if (tooltipText != null && tooltipText.startsWith("!") && tooltipText.endsWith("!")) { + if (tooltipText == null + || (tooltipText.startsWith("!") && tooltipText.endsWith("!"))) { tooltipText = null; } if (tooltipText == null) { @@ -150,4 +151,70 @@ public boolean isInternal() { public void setInternal(boolean internal) { this.internal = internal; } + + public String getName() { + return this.name; + } + + private static final String CSV_FILENAME = "properties.csv"; + + private static final String COL_PROPERTY_NAME = "property name"; + private static final String COL_DESCRIPTION = "Description"; + private static final String COL_DEFAULT_VAL = "Default value"; + private static final String COL_IS_READ_ONLY = "Settable through Settings dialog?"; + private static final String COL_IS_COMMAND_LINE_OPTION = "Command line option only?"; + private static final String COL_IS_ENCRYPTED = "encrypted?"; + + public static void printCSV(AppConfig appConfig) { + String propsFilename = appConfig.constructConfigFilePath(CSV_FILENAME); + File propsFile = new File(propsFilename); + if (propsFile.exists()) { + // delete existing file + propsFile.delete(); + } + try { + propsFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + CSVFileWriter csvWriter = new CSVFileWriter(propsFilename, appConfig, AppUtil.COMMA); + ArrayList colHeaders = new ArrayList(); + colHeaders.add(COL_PROPERTY_NAME); + colHeaders.add(COL_DESCRIPTION); + colHeaders.add(COL_DEFAULT_VAL); + colHeaders.add(COL_IS_READ_ONLY); + colHeaders.add(COL_IS_COMMAND_LINE_OPTION); + colHeaders.add(COL_IS_ENCRYPTED); + + try { + csvWriter.open(); + csvWriter.setColumnNames(colHeaders); + } catch (DataAccessObjectInitializationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return; + } + try { + for (ConfigPropertyMetadata propMD : propertiesMap.values()) { + if (propMD.isInternal()) { + continue; + } + Row row = new Row(); + row.put(COL_PROPERTY_NAME, propMD.getName()); + String description = propMD.getUiLabelTemplate() + propMD.getUiTooltip(); + row.put(COL_DESCRIPTION, description); + row.put(COL_DEFAULT_VAL, propMD.getDefaultValue()); + row.put(COL_IS_READ_ONLY, propMD.isReadOnly()); + row.put(COL_IS_COMMAND_LINE_OPTION, propMD.isCommandLineOption()); + row.put(COL_IS_ENCRYPTED, propMD.isEncrypted()); + try { + csvWriter.writeRow(row); + } catch (DataAccessObjectException e) { + e.printStackTrace(); + } + } + } finally { + csvWriter.close(); + } + } } \ No newline at end of file diff --git a/src/main/java/com/salesforce/dataloader/install/Installer.java b/src/main/java/com/salesforce/dataloader/install/Installer.java index a017059dd..e2206ff0f 100644 --- a/src/main/java/com/salesforce/dataloader/install/Installer.java +++ b/src/main/java/com/salesforce/dataloader/install/Installer.java @@ -43,7 +43,10 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.status.StatusLogger.Config; +import com.salesforce.dataloader.config.AppConfig; +import com.salesforce.dataloader.config.ConfigPropertyMetadata; import com.salesforce.dataloader.config.Messages; import com.salesforce.dataloader.util.AppUtil; @@ -132,6 +135,10 @@ public static void install(Map argsmap) { createAppsFolderShortcut(installationFolder, false); } } + /* comment out auto-generation of list of properties at installation time + AppConfig appConfig = AppConfig.getInstance(null); + ConfigPropertyMetadata.printCSV(appConfig); + */ } catch (Exception ex) { handleException(ex, Level.FATAL); exitCode = AppUtil.EXIT_CODE_CLIENT_ERROR; diff --git a/src/main/java/com/salesforce/dataloader/util/AppUtil.java b/src/main/java/com/salesforce/dataloader/util/AppUtil.java index 3b95978b2..b697f1349 100644 --- a/src/main/java/com/salesforce/dataloader/util/AppUtil.java +++ b/src/main/java/com/salesforce/dataloader/util/AppUtil.java @@ -108,6 +108,7 @@ public enum APP_RUN_MODE { public static final String CLI_OPTION_INSTALLATION_CREATE_MACOS_APPS_FOLDER_SHORTCUT_PROP = "salesforce.installation.shortcut.macos.appsfolder"; public static final String CLI_OPTION_SYSTEM_PROXY_HOST = "sfdc.system.proxyHost"; public static final String CLI_OPTION_SYSTEM_PROXY_PORT = "sfdc.system.proxyPort"; + public static final String CLI_OPTION_GENERATE_PROPERTIES_CSV = "salesforce.loader.generatePropsCSV"; public static final String CONFIG_DIR_DEFAULT_VALUE = "configs"; public static final String DATALOADER_DOWNLOAD_URL = "https://developer.salesforce.com/tools/data-loader"; public static final int EXIT_CODE_NO_ERRORS = 0;