mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-01-08 21:47:59 -05:00
GP-6193: Environment variables can now be set in launch.properties using ENVVARS= or ENVVARS_[PLATFORM]=
This commit is contained in:
@@ -44,6 +44,7 @@ public class LaunchSupport {
|
||||
* <li><b>-jdk_home_check: </b> Verify that the specified Java home directory contains a
|
||||
* supported version of java. No output is produced.</li>
|
||||
* <li><b>-vmargs: </b> Get JVM arguments and output on stdout (one per line).</li>
|
||||
* <li><b>-envvars: </b> Get environment variables and output on stdout (one per line).</li>
|
||||
* </ul>
|
||||
* Optional arguments supported by -java_home and -jdk_home:
|
||||
* <ul>
|
||||
@@ -114,6 +115,9 @@ public class LaunchSupport {
|
||||
case "-vmargs":
|
||||
exitCode = handleVmArgs(appConfig);
|
||||
break;
|
||||
case "-envvars":
|
||||
exitCode = handleEnvVars(appConfig);
|
||||
break;
|
||||
default:
|
||||
System.err.println("LaunchSupport received illegal argument: " + mode);
|
||||
break;
|
||||
@@ -351,4 +355,24 @@ public class LaunchSupport {
|
||||
appConfig.getLaunchProperties().getVmArgList().forEach(e -> System.out.print(e + "\r\n"));
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles getting the environment variables. If they are successfully determined, they are
|
||||
* printed to STDOUT as a new-line delimited string that can be parsed and added to the
|
||||
* environment, and an exit code that indicates success is returned.
|
||||
|
||||
* @param appConfig The appConfig configuration that defines what we support.
|
||||
* @return A suggested exit code based on whether or not the environment variables were
|
||||
* successfully gotten.
|
||||
*/
|
||||
private static int handleEnvVars(AppConfig appConfig) {
|
||||
if (appConfig.getLaunchProperties() == null) {
|
||||
System.err.println("Launch properties file was not specified!");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Force newline style to make cross-platform parsing consistent
|
||||
appConfig.getLaunchProperties().getEnvVarList().forEach(e -> System.out.print(e + "\r\n"));
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,16 @@ public class LaunchProperties {
|
||||
*/
|
||||
public static String VMARGS_PLATFORM = "VMARGS_" + JavaFinder.getCurrentPlatform();
|
||||
|
||||
/**
|
||||
* The environment variables to use to launch (all platforms).
|
||||
*/
|
||||
public static String ENVVARS = "ENVVARS";
|
||||
|
||||
/**
|
||||
* The environment variables to use to launch (current platform only).
|
||||
*/
|
||||
public static String ENVVARS_PLATFORM = "ENVVARS_" + JavaFinder.getCurrentPlatform();
|
||||
|
||||
private Map<String, List<String>> propertyMap;
|
||||
private File launchPropertiesFile;
|
||||
|
||||
@@ -132,6 +142,26 @@ public class LaunchProperties {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link List} of environment variables to use for the launch for the current
|
||||
* {@link Platform platform}.
|
||||
*
|
||||
* @return A {@link List} of environment variables to use for the launch for the current
|
||||
* {@link Platform}
|
||||
*/
|
||||
public List<String> getEnvVarList() {
|
||||
List<String> ret = new ArrayList<>();
|
||||
List<String> envVarList = propertyMap.get(ENVVARS);
|
||||
if (envVarList != null) {
|
||||
ret.addAll(envVarList);
|
||||
}
|
||||
List<String> envVarPlatformList = propertyMap.get(ENVVARS_PLATFORM);
|
||||
if (envVarPlatformList != null) {
|
||||
ret.addAll(envVarPlatformList);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and gets the launch properties from the given launch properties file.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user