diff --git a/javascript/extractor/src/com/semmle/js/extractor/EnvironmentVariables.java b/javascript/extractor/src/com/semmle/js/extractor/EnvironmentVariables.java index 7c5bac5a9f5..6f8e7124b3c 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/EnvironmentVariables.java +++ b/javascript/extractor/src/com/semmle/js/extractor/EnvironmentVariables.java @@ -11,15 +11,18 @@ public class EnvironmentVariables { public static final String CODEQL_EXTRACTOR_JAVASCRIPT_SCRATCH_DIR_ENV_VAR = "CODEQL_EXTRACTOR_JAVASCRIPT_SCRATCH_DIR"; + public static final String LGTM_WORKSPACE_ENV_VAR = + "LGTM_WORKSPACE"; + /** * Gets the extractor root based on the CODEQL_EXTRACTOR_JAVASCRIPT_ROOT or * SEMMLE_DIST or environment variable, or null if neither is set. */ public static String tryGetExtractorRoot() { - String env = Env.systemEnv().get(CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR); - if (env != null && !env.isEmpty()) return env; - env = Env.systemEnv().get(Var.SEMMLE_DIST); - if (env != null && !env.isEmpty()) return env; + String env = Env.systemEnv().getNonEmpty(CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR); + if (env != null) return env; + env = Env.systemEnv().getNonEmpty(Var.SEMMLE_DIST); + if (env != null) return env; return null; } @@ -35,11 +38,15 @@ public class EnvironmentVariables { return env; } + /** + * Gets the scratch directory from the appropriate environment variable. + */ public static String getScratchDir() { - String env = Env.systemEnv().get(CODEQL_EXTRACTOR_JAVASCRIPT_SCRATCH_DIR_ENV_VAR); - if (env == null) { - throw new UserError(CODEQL_EXTRACTOR_JAVASCRIPT_SCRATCH_DIR_ENV_VAR + " must be set"); - } - return env; + String env = Env.systemEnv().getNonEmpty(CODEQL_EXTRACTOR_JAVASCRIPT_SCRATCH_DIR_ENV_VAR); + if (env != null) return env; + env = Env.systemEnv().getNonEmpty(LGTM_WORKSPACE_ENV_VAR); + if (env != null) return env; + + throw new UserError(CODEQL_EXTRACTOR_JAVASCRIPT_SCRATCH_DIR_ENV_VAR + " or " + LGTM_WORKSPACE_ENV_VAR + " must be set"); } }