Skip to content

Commit

Permalink
Merge pull request #1338 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
generate csv of all configurable properties including command line op…
  • Loading branch information
ashitsalesforce authored Oct 14, 2024
2 parents e9369a6 + 6f1df20 commit 507c1e8
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 22 deletions.
11 changes: 10 additions & 1 deletion src/main/java/com/salesforce/dataloader/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -559,6 +562,9 @@ private AppConfig(String filename, Map<String, String> 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() {
Expand Down Expand Up @@ -1778,7 +1784,10 @@ private static boolean createDir(File dirPath) {
* @throws IOException
* @throws FactoryConfigurationError
*/
public static synchronized AppConfig getInstance(Map<String, String> argMap) throws ConfigInitializationException, FactoryConfigurationError, IOException {
public static synchronized AppConfig getInstance(Map<String, String> argMap) throws ConfigInitializationException, FactoryConfigurationError, IOException {
if (argMap == null) {
argMap = new HashMap<String, String>();
}
AppUtil.initializeAppConfig(AppUtil.convertCommandArgsMapToArgsArray(argMap));
logger = LogManager.getLogger(AppConfig.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -43,21 +50,21 @@ 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 {
propName = configField.get(null).toString();
} 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));
Expand All @@ -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) {
Expand Down Expand Up @@ -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<String> colHeaders = new ArrayList<String>();
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -132,6 +135,10 @@ public static void install(Map<String, String> 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;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/salesforce/dataloader/util/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 507c1e8

Please sign in to comment.