Skip to content

Commit

Permalink
Merge pull request #1351 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
move CLI option declarations to AppConfig.java
  • Loading branch information
ashitsalesforce authored Oct 21, 2024
2 parents 8d7abb4 + 22845ab commit cd7724a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 56 deletions.
51 changes: 32 additions & 19 deletions src/main/java/com/salesforce/dataloader/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,23 @@ public class AppConfig {
* The Constants for the current Loader Keys
*/
//
// salesforce constants

//
// Configurable properties that can be specified only as CLI options
//
public static final String CLI_OPTION_SYSTEM_PROXY_PORT = "sfdc.system.proxyPort";
public static final String CLI_OPTION_SYSTEM_PROXY_HOST = "sfdc.system.proxyHost";
public static final String CLI_OPTION_INSTALLATION_CREATE_MACOS_APPS_FOLDER_SHORTCUT_PROP = "salesforce.installation.shortcut.macos.appsfolder";
public static final String CLI_OPTION_INSTALLATION_CREATE_WINDOWS_START_MENU_SHORTCUT_PROP = "salesforce.installation.shortcut.windows.startmenu";
public static final String CLI_OPTION_INSTALLATION_CREATE_DESKTOP_SHORTCUT_PROP = "salesforce.installation.shortcut.desktop";
public static final String CLI_OPTION_INSTALLATION_FOLDER_PROP = "salesforce.installation.dir";
public static final String CLI_OPTION_SAVE_ALL_PROPS = "salesforce.saveAllSettings";
public static final String CLI_OPTION_CONFIG_DIR_PROP = "salesforce.config.dir";
public static final String CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH = "swt.nativelib.inpath";
public static final String CLI_OPTION_GMT_FOR_DATE_FIELD_VALUE = "datefield.usegmt";

// =======================
// Property name constants (Settings specified in config.properties file or as command line options)
// Configurable properties specified in config.properties file
// =======================
// Loader Preferences
public static final String PROP_HIDE_WELCOME_SCREEN = "loader.hideWelcome";
Expand Down Expand Up @@ -527,16 +540,16 @@ public class AppConfig {
PROP_MIN_RETRY_SLEEP_SECS,
PROP_REUSE_CLIENT_CONNECTION,
CLI_OPTION_RUN_MODE,
AppUtil.CLI_OPTION_CONFIG_DIR_PROP,
AppUtil.CLI_OPTION_GMT_FOR_DATE_FIELD_VALUE,
AppUtil.CLI_OPTION_INSTALLATION_CREATE_DESKTOP_SHORTCUT_PROP,
AppUtil.CLI_OPTION_INSTALLATION_CREATE_MACOS_APPS_FOLDER_SHORTCUT_PROP,
AppUtil.CLI_OPTION_INSTALLATION_CREATE_WINDOWS_START_MENU_SHORTCUT_PROP,
AppUtil.CLI_OPTION_INSTALLATION_FOLDER_PROP,
AppUtil.CLI_OPTION_SAVE_ALL_PROPS,
AppUtil.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH,
AppUtil.CLI_OPTION_SYSTEM_PROXY_HOST,
AppUtil.CLI_OPTION_SYSTEM_PROXY_PORT,
AppConfig.CLI_OPTION_CONFIG_DIR_PROP,
AppConfig.CLI_OPTION_GMT_FOR_DATE_FIELD_VALUE,
AppConfig.CLI_OPTION_INSTALLATION_CREATE_DESKTOP_SHORTCUT_PROP,
AppConfig.CLI_OPTION_INSTALLATION_CREATE_MACOS_APPS_FOLDER_SHORTCUT_PROP,
AppConfig.CLI_OPTION_INSTALLATION_CREATE_WINDOWS_START_MENU_SHORTCUT_PROP,
AppConfig.CLI_OPTION_INSTALLATION_FOLDER_PROP,
AppConfig.CLI_OPTION_SAVE_ALL_PROPS,
AppConfig.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH,
AppConfig.CLI_OPTION_SYSTEM_PROXY_HOST,
AppConfig.CLI_OPTION_SYSTEM_PROXY_PORT,
};

// Properties that are not published as their are either not saved or are read-only
Expand All @@ -554,10 +567,10 @@ public class AppConfig {
PROP_SERVER_ENVIRONMENTS,
PROP_SELECTED_SERVER_ENVIRONMENT,
PROP_DAO_SKIP_TOTAL_COUNT,
AppUtil.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH,
AppUtil.CLI_OPTION_INSTALLATION_FOLDER_PROP,
AppUtil.CLI_OPTION_SYSTEM_PROXY_HOST,
AppUtil.CLI_OPTION_SYSTEM_PROXY_PORT,
AppConfig.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH,
AppConfig.CLI_OPTION_INSTALLATION_FOLDER_PROP,
AppConfig.CLI_OPTION_SYSTEM_PROXY_HOST,
AppConfig.CLI_OPTION_SYSTEM_PROXY_PORT,
};

private static final String[] ENCRYPTED_PROPERTY_NAMES = {
Expand Down Expand Up @@ -598,7 +611,7 @@ private AppConfig(String filename, Map<String, String> cliOptionsMap) throws Con
// 1. process-conf.properties for CLI mode
// 2. command line options for both CLI and UI modes
this.loadParameterOverrides(cliOptionsMap);
saveAllProps = getBoolean(AppUtil.CLI_OPTION_SAVE_ALL_PROPS);
saveAllProps = getBoolean(AppConfig.CLI_OPTION_SAVE_ALL_PROPS);

// last run gets initialized after loading config and overrides
// since config params are needed for initializing last run.
Expand Down Expand Up @@ -749,8 +762,8 @@ private void setDefaults(Map<String, String> cliOptionsMap) {
setDefaultValue(PROP_PROCESS_EXIT_WITH_ERROR_ON_FAILED_ROWS_BATCH_MODE, false);
setDefaultValue(PROP_INCLUDE_RICH_TEXT_FIELD_DATA_IN_QUERY_RESULTS, false);
setDefaultValue(PROP_OAUTH_INSTANCE_URL, false);
String systemProxyHost = cliOptionsMap.get(AppUtil.CLI_OPTION_SYSTEM_PROXY_HOST);
String systemProxyPort = cliOptionsMap.get(AppUtil.CLI_OPTION_SYSTEM_PROXY_PORT);
String systemProxyHost = cliOptionsMap.get(AppConfig.CLI_OPTION_SYSTEM_PROXY_HOST);
String systemProxyPort = cliOptionsMap.get(AppConfig.CLI_OPTION_SYSTEM_PROXY_PORT);
if (systemProxyHost != null && !systemProxyHost.isBlank()) {
setDefaultValue(PROP_PROXY_HOST, systemProxyHost);
setDefaultValue(PROP_PROXY_PORT, systemProxyPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void install(Map<String, String> argsmap) {
logger.debug("going to show banner");
AppUtil.showBanner();
}
String installationFolderFromCommandLine = argsmap.get(AppUtil.CLI_OPTION_INSTALLATION_FOLDER_PROP);
String installationFolderFromCommandLine = argsmap.get(AppConfig.CLI_OPTION_INSTALLATION_FOLDER_PROP);
boolean promptUserToDeleteExistingInstallationFolder = false;
if (installationFolderFromCommandLine == null || installationFolderFromCommandLine.isBlank()) {
skipCopyArtifacts = promptCurrentInstallationFolder();
Expand All @@ -102,7 +102,7 @@ public static void install(Map<String, String> argsmap) {
}
extractInstallationArtifactsFromJar(installationFolder);

String createDesktopShortcutStr = argsmap.get(AppUtil.CLI_OPTION_INSTALLATION_CREATE_DESKTOP_SHORTCUT_PROP);
String createDesktopShortcutStr = argsmap.get(AppConfig.CLI_OPTION_INSTALLATION_CREATE_DESKTOP_SHORTCUT_PROP);
logger.debug("going to create desktop shortcut");
if (interactiveMode) {
createDesktopShortcut(installationFolder, true);
Expand All @@ -112,7 +112,7 @@ public static void install(Map<String, String> argsmap) {
createDesktopShortcut(installationFolder, false);
}

String createWindowsStartMenuShortcutStr = argsmap.get(AppUtil.CLI_OPTION_INSTALLATION_CREATE_WINDOWS_START_MENU_SHORTCUT_PROP);
String createWindowsStartMenuShortcutStr = argsmap.get(AppConfig.CLI_OPTION_INSTALLATION_CREATE_WINDOWS_START_MENU_SHORTCUT_PROP);
logger.debug("going to create start menu shortcut");
if (AppUtil.isRunningOnWindows()) {
if (interactiveMode) {
Expand All @@ -124,7 +124,7 @@ public static void install(Map<String, String> argsmap) {
}
}

String createMacOSAppsFolderShortcutStr = argsmap.get(AppUtil.CLI_OPTION_INSTALLATION_CREATE_MACOS_APPS_FOLDER_SHORTCUT_PROP);
String createMacOSAppsFolderShortcutStr = argsmap.get(AppConfig.CLI_OPTION_INSTALLATION_CREATE_MACOS_APPS_FOLDER_SHORTCUT_PROP);
logger.debug("going to create start menu shortcut");
if (AppUtil.isRunningOnMacOS()) {
if (interactiveMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import com.salesforce.dataloader.action.progress.ILoaderProgress;
import com.salesforce.dataloader.client.HttpClientTransport;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.controller.Controller;

public class DataLoaderRunner extends Thread {
Expand Down Expand Up @@ -100,8 +101,8 @@ public static IProcess runApp(String[] args, ILoaderProgress monitor) {
/* Run in the UI mode, get the controller instance with batchMode == false */
logger = LogManager.getLogger(DataLoaderRunner.class);
Installer.install(argsMap);
if (argsMap.containsKey(AppUtil.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH)
&& "true".equalsIgnoreCase(argsMap.get(AppUtil.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH))){
if (argsMap.containsKey(AppConfig.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH)
&& "true".equalsIgnoreCase(argsMap.get(AppConfig.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH))){
try {
String defaultBrowser = System.getProperty("org.eclipse.swt.browser.DefaultType");
if (defaultBrowser == null) {
Expand Down Expand Up @@ -188,8 +189,8 @@ private static void rerunWithSWTNativeLib(String[] args) {
}

// add the argument to indicate that JAVA_LIB_PATH has the folder containing SWT native libraries
jvmArgs.add(AppUtil.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH + "=true");
logger.debug(" " + AppUtil.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH + "=true");
jvmArgs.add(AppConfig.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH + "=true");
logger.debug(" " + AppConfig.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH + "=true");

// set System proxy info as proxy server defaults
String proxyHost = null;
Expand All @@ -201,8 +202,8 @@ private static void rerunWithSWTNativeLib(String[] args) {
if (addr != null) {
proxyHost = addr.getHostName();
proxyPort = addr.getPort();
jvmArgs.add(AppUtil.CLI_OPTION_SYSTEM_PROXY_HOST + "=" + proxyHost);
jvmArgs.add(AppUtil.CLI_OPTION_SYSTEM_PROXY_PORT + "=" + proxyPort);
jvmArgs.add(AppConfig.CLI_OPTION_SYSTEM_PROXY_HOST + "=" + proxyHost);
jvmArgs.add(AppConfig.CLI_OPTION_SYSTEM_PROXY_PORT + "=" + proxyPort);
}
}
AppUtil.exec(jvmArgs, null);
Expand Down
32 changes: 11 additions & 21 deletions src/main/java/com/salesforce/dataloader/util/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ public enum APP_RUN_MODE {
public static final String DATALOADER_VERSION;
public static final String DATALOADER_SHORT_VERSION;
public static final String MIN_JAVA_VERSION;
public static final String CLI_OPTION_GMT_FOR_DATE_FIELD_VALUE = "datefield.usegmt";
public static final String CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH = "swt.nativelib.inpath";
public static final String CLI_OPTION_CONFIG_DIR_PROP = "salesforce.config.dir";
public static final String CLI_OPTION_SAVE_ALL_PROPS = "salesforce.saveAllSettings";
public static final String CLI_OPTION_INSTALLATION_FOLDER_PROP = "salesforce.installation.dir";
public static final String CLI_OPTION_INSTALLATION_CREATE_DESKTOP_SHORTCUT_PROP = "salesforce.installation.shortcut.desktop";
public static final String CLI_OPTION_INSTALLATION_CREATE_WINDOWS_START_MENU_SHORTCUT_PROP = "salesforce.installation.shortcut.windows.startmenu";
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 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 Expand Up @@ -262,8 +252,8 @@ public static APP_RUN_MODE getAppRunMode() {
}

private static void setUseGMTForDateFieldValue(Map<String, String> argMap) {
if (argMap.containsKey(AppUtil.CLI_OPTION_GMT_FOR_DATE_FIELD_VALUE)) {
if ("true".equalsIgnoreCase(argMap.get(AppUtil.CLI_OPTION_GMT_FOR_DATE_FIELD_VALUE))) {
if (argMap.containsKey(AppConfig.CLI_OPTION_GMT_FOR_DATE_FIELD_VALUE)) {
if ("true".equalsIgnoreCase(argMap.get(AppConfig.CLI_OPTION_GMT_FOR_DATE_FIELD_VALUE))) {
useGMTForDateFieldValue = true;
}
}
Expand All @@ -290,13 +280,13 @@ public static synchronized String getConfigurationsDir() {
}

private static synchronized void setConfigurationsDir(Map<String, String> argsMap) {
if (argsMap != null && argsMap.containsKey(CLI_OPTION_CONFIG_DIR_PROP)) {
configurationsDir = argsMap.get(CLI_OPTION_CONFIG_DIR_PROP);
if (argsMap != null && argsMap.containsKey(AppConfig.CLI_OPTION_CONFIG_DIR_PROP)) {
configurationsDir = argsMap.get(AppConfig.CLI_OPTION_CONFIG_DIR_PROP);
} else if (configurationsDir != null && !configurationsDir.isEmpty()) {
return;
} else {
// first time invocation and configurationsDir is not set through argsMap
configurationsDir = System.getProperty(CLI_OPTION_CONFIG_DIR_PROP);
configurationsDir = System.getProperty(AppConfig.CLI_OPTION_CONFIG_DIR_PROP);
if (configurationsDir == null || configurationsDir.isBlank()) {
configurationsDir = getDefaultConfigDir();
}
Expand All @@ -308,7 +298,7 @@ private static synchronized void setConfigurationsDir(Map<String, String> argsMa
System.err.println("Unable to find configuration folder " + configurationsDir);
configurationsDir = configDirFile.getAbsolutePath();
}
System.setProperty(CLI_OPTION_CONFIG_DIR_PROP, configurationsDir);
System.setProperty(AppConfig.CLI_OPTION_CONFIG_DIR_PROP, configurationsDir);
}

private static String getDefaultConfigDir() {
Expand Down Expand Up @@ -354,7 +344,7 @@ public synchronized static Map<String, String> convertCommandArgsArrayToArgMap(S


private static void processArgsForBatchMode(String[] args, Map<String,String> argsMap) {
if (!argsMap.containsKey(AppUtil.CLI_OPTION_CONFIG_DIR_PROP) && args.length < 2) {
if (!argsMap.containsKey(AppConfig.CLI_OPTION_CONFIG_DIR_PROP) && args.length < 2) {
// config folder must be specified in the first argument
System.err.println(
"Usage: process <configuration folder> [batch process bean id]\n"
Expand All @@ -374,8 +364,8 @@ private static void processArgsForBatchMode(String[] args, Map<String,String> ar
+ " process ../myconfigdir");
System.exit(EXIT_CODE_CLIENT_ERROR);
}
if (!argsMap.containsKey(AppUtil.CLI_OPTION_CONFIG_DIR_PROP)) {
argsMap.put(AppUtil.CLI_OPTION_CONFIG_DIR_PROP, args[0]);
if (!argsMap.containsKey(AppConfig.CLI_OPTION_CONFIG_DIR_PROP)) {
argsMap.put(AppConfig.CLI_OPTION_CONFIG_DIR_PROP, args[0]);
}
if (!argsMap.containsKey(AppConfig.PROP_PROCESS_NAME)
&& args.length > 2
Expand Down Expand Up @@ -506,8 +496,8 @@ public static Proxy getSystemHttpsProxy(String[] args) {
Map<String, String> argsMap = convertCommandArgsArrayToArgMap(args);
if (getAppRunMode() == APP_RUN_MODE.BATCH
|| getAppRunMode() == APP_RUN_MODE.ENCRYPT
|| (argsMap.containsKey(AppUtil.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH)
&& "true".equalsIgnoreCase(argsMap.get(AppUtil.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH)))) {
|| (argsMap.containsKey(AppConfig.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH)
&& "true".equalsIgnoreCase(argsMap.get(AppConfig.CLI_OPTION_SWT_NATIVE_LIB_IN_JAVA_LIB_PATH)))) {
// do not check for system proxy settings
// if run mode is batch or encrypt
// or if on the 2nd iteration of the UI mode
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/salesforce/dataloader/ConfigTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package com.salesforce.dataloader;

import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.util.AppUtil;

import org.junit.Before;

Expand Down Expand Up @@ -73,7 +72,7 @@ protected Map<String, String> getTestConfig() {
for (TestProperties prop : getDefaultTestPropertiesSet()) {
prop.putConfigSetting(configBase);
}
configBase.put(AppUtil.CLI_OPTION_CONFIG_DIR_PROP, TEST_CONF_DIR);
configBase.put(AppConfig.CLI_OPTION_CONFIG_DIR_PROP, TEST_CONF_DIR);
String proxyUsername = System.getProperty(AppConfig.PROP_PROXY_USERNAME);
String proxyPassword = System.getProperty(AppConfig.PROP_PROXY_PASSWORD);
if (proxyUsername != null && proxyPassword != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/salesforce/dataloader/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ abstract class TestBase {
TEST_PROPS = loadTestProperties();
TEST_FILES_DIR = getProperty("testfiles.dir");
TEST_CONF_DIR = TEST_FILES_DIR + File.separator + "conf";
TEST_PROPS.put(AppUtil.CLI_OPTION_CONFIG_DIR_PROP, TEST_CONF_DIR);
TEST_PROPS.put(AppConfig.CLI_OPTION_CONFIG_DIR_PROP, TEST_CONF_DIR);
TEST_DATA_DIR = TEST_FILES_DIR + File.separator + "data";
TEST_STATUS_DIR = TEST_FILES_DIR + File.separator + "status";
DEFAULT_ACCOUNT_EXT_ID_FIELD = getProperty("test.account.extid");

Map<String, String> argsMap = new HashMap<String, String>();
argsMap.put(AppUtil.CLI_OPTION_CONFIG_DIR_PROP, getTestConfDir());
argsMap.put(AppConfig.CLI_OPTION_CONFIG_DIR_PROP, getTestConfDir());
try {
AppUtil.initializeAppConfig(AppUtil.convertCommandArgsMapToArgsArray(argsMap));
} catch (FactoryConfigurationError e) {
Expand Down Expand Up @@ -196,8 +196,8 @@ private void setupTestName() {
protected void setupController(Map<String, String> configOverrideMap) {
// configure the Controller to point to our testing config
configOverrideMap.put(AppConfig.PROP_READ_ONLY_CONFIG_PROPERTIES, Boolean.TRUE.toString());
if (!System.getProperties().contains(AppUtil.CLI_OPTION_CONFIG_DIR_PROP))
System.setProperty(AppUtil.CLI_OPTION_CONFIG_DIR_PROP, getTestConfDir());
if (!System.getProperties().contains(AppConfig.CLI_OPTION_CONFIG_DIR_PROP))
System.setProperty(AppConfig.CLI_OPTION_CONFIG_DIR_PROP, getTestConfDir());

try {
controller = Controller.getInstance(configOverrideMap);
Expand Down

0 comments on commit cd7724a

Please sign in to comment.