1
1
package com .semmle .js .extractor ;
2
2
3
+ import com .semmle .util .data .UnitParser ;
3
4
import com .semmle .util .exception .UserError ;
4
5
import com .semmle .util .process .Env ;
5
6
import com .semmle .util .process .Env .Var ;
6
7
7
8
public class EnvironmentVariables {
8
9
public static final String CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR =
9
10
"CODEQL_EXTRACTOR_JAVASCRIPT_ROOT" ;
10
-
11
+
11
12
public static final String CODEQL_EXTRACTOR_JAVASCRIPT_SCRATCH_DIR_ENV_VAR =
12
13
"CODEQL_EXTRACTOR_JAVASCRIPT_SCRATCH_DIR" ;
13
14
@@ -19,6 +20,36 @@ public class EnvironmentVariables {
19
20
20
21
public static final String CODEQL_DIST_ENV_VAR = "CODEQL_DIST" ;
21
22
23
+ /**
24
+ * Returns a number of megabytes by reading an environment variable with the given suffix,
25
+ * or the default value if not set.
26
+ * <p>
27
+ * The following prefixes are tried:
28
+ * <code>CODEQL_EXTRACTOR_JAVASCRIPT_</code>,
29
+ * <code>LGTM_</code>,
30
+ * <code>SEMMLE_</code>.
31
+ */
32
+ public static int getMegabyteCountFromPrefixedEnv (String suffix , int defaultValue ) {
33
+ String envVar = "CODEQL_EXTRACTOR_JAVASCRIPT_" + suffix ;
34
+ String value = Env .systemEnv ().get (envVar );
35
+ if (value == null || value .length () == 0 ) {
36
+ envVar = "LGTM_" + suffix ;
37
+ value = Env .systemEnv ().get (envVar );
38
+ }
39
+ if (value == null || value .length () == 0 ) {
40
+ envVar = "SEMMLE_" + suffix ;
41
+ value = Env .systemEnv ().get (envVar );
42
+ }
43
+ if (value == null || value .length () == 0 ) {
44
+ return defaultValue ;
45
+ }
46
+ Integer amount = UnitParser .parseOpt (value , UnitParser .MEGABYTES );
47
+ if (amount == null ) {
48
+ throw new UserError ("Invalid value for " + envVar + ": '" + value + "'" );
49
+ }
50
+ return amount ;
51
+ }
52
+
22
53
/**
23
54
* Gets the extractor root based on the <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
24
55
* SEMMLE_DIST</code> or environment variable, or <code>null</code> if neither is set.
0 commit comments