JS: Handle LGTM_WORKSPACE and fix emptiness check

This commit is contained in:
Asger Feldthaus 2020-01-30 12:31:25 +00:00
Родитель 141d4bfb70
Коммит 92dbfb2858
1 изменённых файлов: 16 добавлений и 9 удалений

Просмотреть файл

@ -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 <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
* SEMMLE_DIST</code> or environment variable, or <code>null</code> 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");
}
}