Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code readability changes #1362

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/main/java/com/salesforce/dataloader/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public class AppConfig {
private final boolean saveAllProps;
private Map<String,ConfigPropertyMetadata> configPropsMetadataMap = ConfigPropertyMetadata.getPropertiesMap();

private Map<String, String> parameterOverridesMap;
private Map<String, String> commandLineOptionsMap;

/**
* The default-default value for the respective types.
Expand Down Expand Up @@ -597,7 +597,7 @@ public class AppConfig {
* @see #load()
* @see #save()
*/
private AppConfig(String filename, Map<String, String> cliOptionsMap) throws ConfigInitializationException, IOException {
private AppConfig(String filename, Map<String, String> commandLineOptionsMap) throws ConfigInitializationException, IOException {
loadedProperties = new LinkedProperties();
this.filename = filename;

Expand All @@ -606,7 +606,7 @@ private AppConfig(String filename, Map<String, String> cliOptionsMap) throws Con

// initialize with defaults
//
this.setDefaults(cliOptionsMap);
this.setDefaults(commandLineOptionsMap);
this.defaultProperties = new LinkedProperties();
this.defaultProperties.putAll(this.loadedProperties);

Expand All @@ -617,7 +617,7 @@ private AppConfig(String filename, Map<String, String> cliOptionsMap) throws Con
// parameter overrides are from two places:
// 1. process-conf.properties for CLI mode
// 2. command line options for both CLI and UI modes
this.loadParameterOverrides(cliOptionsMap);
this.loadCommandLineOptions(commandLineOptionsMap);
saveAllProps = getBoolean(AppConfig.PROP_SAVE_ALL_PROPS);

// last run gets initialized after loading config and overrides
Expand Down Expand Up @@ -1192,14 +1192,14 @@ private void decryptAndCacheProperty(Map<?, ?> values, String propertyName) thro
* Load config parameter override values. The main use case is loading of overrides from
* external config file
*/
public void loadParameterOverrides(Map<String, String> configOverrideMap) throws ParameterLoadException,
public void loadCommandLineOptions(Map<String, String> commandLineOptionsMap) throws ParameterLoadException,
ConfigInitializationException {
this.parameterOverridesMap = configOverrideMap;
this.commandLineOptionsMap = commandLineOptionsMap;
// make sure to post-process the args to be loaded
postLoad(configOverrideMap, false);
postLoad(commandLineOptionsMap, false);

// replace values in the Config
putValue(configOverrideMap);
putValue(commandLineOptionsMap);
}

/**
Expand Down Expand Up @@ -1433,8 +1433,8 @@ private void encryptPropertiesBeforeSave() {
}

private void removeCommandLineOptionsBeforeSave() {
if (this.parameterOverridesMap != null) {
for (String propertyName : this.parameterOverridesMap.keySet()) {
if (this.commandLineOptionsMap != null) {
for (String propertyName : this.commandLineOptionsMap.keySet()) {
this.loadedProperties.remove(propertyName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public void run() {
HttpClientTransport.closeHttpClient();
}

public static void main(String[] args) {
public static void main(String[] commandLineOptions) {
try {
runApp(args, null);
runApp(commandLineOptions, null);
System.exit(exitCode);
} catch (ExitException ex) {
System.exit(ex.getExitCode());
Expand All @@ -84,21 +84,21 @@ public static void main(String[] args) {
System.exit(exitCode);
}

public static IProcess runApp(String[] args, ILoaderProgress monitor) {
public static IProcess runApp(String[] commandLineOptions, ILoaderProgress monitor) {
Controller controller = null;
Runtime.getRuntime().addShutdownHook(new DataLoaderRunner());
try {
controller = Controller.getInstance(AppUtil.convertCommandArgsArrayToArgMap(args));
controller = Controller.getInstance(AppUtil.convertCommandArgsArrayToArgMap(commandLineOptions));
} catch (FactoryConfigurationError | Exception ex) {
ex.printStackTrace();
System.exit(AppUtil.EXIT_CODE_CLIENT_ERROR);
}
if (AppUtil.getAppRunMode() == AppUtil.APP_RUN_MODE.BATCH) {
return ProcessRunner.runBatchMode(AppUtil.convertCommandArgsArrayToArgMap(args), monitor);
return ProcessRunner.runBatchMode(AppUtil.convertCommandArgsArrayToArgMap(commandLineOptions), monitor);
} else if (AppUtil.getAppRunMode() == AppUtil.APP_RUN_MODE.ENCRYPT) {
EncryptionUtil.main(args);
EncryptionUtil.main(commandLineOptions);
} else {
Map<String, String> argsMap = AppUtil.convertCommandArgsArrayToArgMap(args);
Map<String, String> argsMap = AppUtil.convertCommandArgsArrayToArgMap(commandLineOptions);
/* Run in the UI mode, get the controller instance with batchMode == false */
logger = DLLogManager.getLogger(DataLoaderRunner.class);
Installer.install(argsMap);
Expand All @@ -117,7 +117,7 @@ public static IProcess runApp(String[] args, ILoaderProgress monitor) {
}
} else { // SWT_NATIVE_LIB_IN_JAVA_LIB_PATH not set
AppUtil.showBanner();
rerunWithSWTNativeLib(args);
rerunWithSWTNativeLib(commandLineOptions);
}
}
return null;
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/salesforce/dataloader/process/ProcessRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ public static void logErrorAndExitProcess(String message, Throwable throwable, i
throw new ExitException(throwable, exitCode);
}

public static ProcessRunner runBatchMode(Map<String, String>argMap, ILoaderProgress progressMonitor) throws UnsupportedOperationException {
public static ProcessRunner runBatchMode(Map<String, String>commandLineOptionsMap, ILoaderProgress progressMonitor) throws UnsupportedOperationException {
ProcessRunner runner = null;
try {
// create the process
runner = ProcessRunner.getInstance(argMap);
runner = ProcessRunner.getInstance(commandLineOptionsMap);
if (runner == null) {
logErrorAndExitProcess("Process runner is null",
new NullPointerException(), AppUtil.EXIT_CODE_CLIENT_ERROR);
Expand Down Expand Up @@ -290,22 +290,22 @@ public static ProcessRunner runBatchMode(Map<String, String>argMap, ILoaderProgr
*/

/**
* @param argMap
* @param commandLineOptionsMap
* @return instance of ProcessRunner
* @throws ProcessInitializationException
*/
private static synchronized ProcessRunner getInstance(Map<String, String> argMap) throws ProcessInitializationException {
private static synchronized ProcessRunner getInstance(Map<String, String> commandLineOptionsMap) throws ProcessInitializationException {
logger.info(Messages.getString("Process.initializingEngine")); //$NON-NLS-1$
String dynaBeanID = argMap.get(AppConfig.PROP_PROCESS_NAME);
String dynaBeanID = commandLineOptionsMap.get(AppConfig.PROP_PROCESS_NAME);
ProcessRunner runner;
if (dynaBeanID == null || dynaBeanID.isEmpty()) {
// operation and other process params are specified in config.properties
logger.info(AppConfig.PROP_PROCESS_NAME
+ "is not specified in the command line. Loading the process properties from config.properties.");
runner = new ProcessRunner();

if (argMap.containsKey(AppConfig.PROP_PROCESS_THREAD_NAME)) {
runner.setName(argMap.get(AppConfig.PROP_PROCESS_THREAD_NAME));
if (commandLineOptionsMap.containsKey(AppConfig.PROP_PROCESS_THREAD_NAME)) {
runner.setName(commandLineOptionsMap.get(AppConfig.PROP_PROCESS_THREAD_NAME));
}
} else {
// process name specified in the command line arg.
Expand All @@ -317,7 +317,10 @@ private static synchronized ProcessRunner getInstance(Map<String, String> argMap
+ AppConfig.getConfigurationsDir());
runner = ProcessConfig.getProcessInstance(dynaBeanID);
}
runner.getConfigOverrideMap().putAll(argMap);

// Override properties set in config.properties and process-conf.xml
// by properties specified as command line options
runner.getConfigOverrideMap().putAll(commandLineOptionsMap);
return runner;
}

Expand Down
Loading