File tree Expand file tree Collapse file tree 3 files changed +39
-6
lines changed
Expand file tree Collapse file tree 3 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -205,7 +205,7 @@ public class AutoBuild {
205205
206206 public AutoBuild () {
207207 this .LGTM_SRC = toRealPath (getPathFromEnvVar ("LGTM_SRC" ));
208- this .SEMMLE_DIST = getPathFromEnvVar ( Env . Var . SEMMLE_DIST . toString ());
208+ this .SEMMLE_DIST = Paths . get ( EnvironmentVariables . getExtractorRoot ());
209209 this .outputConfig = new ExtractorOutputConfig (LegacyLanguage .JAVASCRIPT );
210210 this .trapCache = mkTrapCache ();
211211 this .typeScriptMode =
Original file line number Diff line number Diff line change 1+ package com .semmle .js .extractor ;
2+
3+ import com .semmle .util .exception .UserError ;
4+ import com .semmle .util .process .Env ;
5+ import com .semmle .util .process .Env .Var ;
6+
7+ public class EnvironmentVariables {
8+ public static final String CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR =
9+ "CODEQL_EXTRACTOR_JAVASCRIPT_ROOT" ;
10+
11+ /**
12+ * Gets the extractor root based on the <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
13+ * SEMMLE_DIST</code> or environment variable, or <code>null</code> if neither is set.
14+ */
15+ public static String tryGetExtractorRoot () {
16+ String env = Env .systemEnv ().get (CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR );
17+ if (env != null && !env .isEmpty ()) return env ;
18+ env = Env .systemEnv ().get (Var .SEMMLE_DIST );
19+ if (env != null && !env .isEmpty ()) return env ;
20+ return null ;
21+ }
22+
23+ /**
24+ * Gets the extractor root based on the <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
25+ * SEMMLE_DIST</code> or environment variable, or throws a UserError if neither is set.
26+ */
27+ public static String getExtractorRoot () {
28+ String env = tryGetExtractorRoot ();
29+ if (env == null ) {
30+ throw new UserError ("SEMMLE_DIST or CODEQL_EXTRACTOR_JAVASCRIPT_ROOT must be set" );
31+ }
32+ return env ;
33+ }
34+ }
Original file line number Diff line number Diff line change 77import com .google .gson .JsonParseException ;
88import com .google .gson .JsonParser ;
99import com .google .gson .JsonPrimitive ;
10+ import com .semmle .js .extractor .EnvironmentVariables ;
1011import com .semmle .js .extractor .ExtractionMetrics ;
1112import com .semmle .js .parser .JSParser .Result ;
1213import com .semmle .ts .extractor .TypeTable ;
@@ -290,14 +291,12 @@ private File getParserWrapper() {
290291 File parserWrapper ;
291292 LogbackUtils .getLogger (AbstractProcessBuilder .class ).setLevel (Level .INFO );
292293 String explicitPath = Env .systemEnv ().get (PARSER_WRAPPER_PATH_ENV_VAR );
293- String semmleDistVar = Env .systemEnv ().get (Env .Var .SEMMLE_DIST .name ());
294294 if (explicitPath != null ) {
295295 parserWrapper = new File (explicitPath );
296- } else if (semmleDistVar != null && !semmleDistVar .isEmpty ()) {
297- parserWrapper = new File (semmleDistVar , "tools/typescript-parser-wrapper/main.js" );
298296 } else {
299- throw new CatastrophicError (
300- "Could not find TypeScript parser: " + Env .Var .SEMMLE_DIST .name () + " is not set." );
297+ parserWrapper =
298+ new File (
299+ EnvironmentVariables .getExtractorRoot (), "tools/typescript-parser-wrapper/main.js" );
301300 }
302301 if (!parserWrapper .isFile ())
303302 throw new ResourceError (
You can’t perform that action at this time.
0 commit comments