Skip to content

Commit 9a5e806

Browse files
committed
C#: Address review comments.
1 parent 69041bc commit 9a5e806

File tree

3 files changed

+26
-47
lines changed

3 files changed

+26
-47
lines changed

csharp/autobuilder/Semmle.Autobuild/AutobuildOptions.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,8 @@ public static string[] AsListWithExpandedEnvVars(this string? value, IBuildActio
107107

108108
static readonly Regex linuxEnvRegEx = new Regex(@"\$([a-zA-Z_][a-zA-Z_0-9]*)", RegexOptions.Compiled);
109109

110-
public static string? AsStringWithExpandedEnvVarsMaybeNull(this string? value, IBuildActions actions)
111-
{
112-
if (string.IsNullOrEmpty(value))
113-
return value;
114-
115-
return value.AsStringWithExpandedEnvVars(actions);
116-
}
110+
public static string? AsStringWithExpandedEnvVarsMaybeNull(this string? value, IBuildActions actions) =>
111+
value?.AsStringWithExpandedEnvVars(actions);
117112

118113
public static string AsStringWithExpandedEnvVars(this string value, IBuildActions actions)
119114
{

csharp/autobuilder/Semmle.Autobuild/Autobuilder.cs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -185,34 +185,28 @@ public Autobuilder(IBuildActions actions, AutobuildOptions options)
185185
});
186186

187187
CodeQLExtractorCSharpRoot = Actions.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_ROOT");
188-
189188
SemmleDist = Actions.GetEnvironmentVariable("SEMMLE_DIST");
190-
191-
CodeQLJavaHome = Actions.GetEnvironmentVariable("CODEQL_JAVA_HOME");
192-
193-
SemmleJavaHome = Actions.GetEnvironmentVariable("SEMMLE_JAVA_HOME");
194-
195-
if(CodeQLJavaHome is null && SemmleJavaHome is null)
196-
throw new InvalidEnvironmentException("The environment variables CODEQL_JAVA_HOME and SEMMLE_JAVA_HOME have not been set.");
197-
198189
SemmlePlatformTools = Actions.GetEnvironmentVariable("SEMMLE_PLATFORM_TOOLS");
199190

200-
if (CodeQLExtractorCSharpRoot is null && SemmleDist is null)
201-
throw new InvalidEnvironmentException("The environment variables CODEQL_EXTRACTOR_CSHARP_ROOT and SEMMLE_DIST have not been set.");
202-
203-
var trapDir = Actions.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_TRAP_DIR") ?? Actions.GetEnvironmentVariable("TRAP_FOLDER");
204-
205-
if (trapDir is null)
206-
throw new InvalidEnvironmentException("The environment variables CODEQL_EXTRACTOR_CSHARP_TRAP_DIR and TRAP_FOLDER have not been set.");
207-
208-
TrapDir = trapDir;
209-
210-
var sourceArchiveDir = Actions.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR") ?? Actions.GetEnvironmentVariable("SOURCE_ARCHIVE");
211-
212-
if(sourceArchiveDir is null)
213-
throw new InvalidEnvironmentException("The environment variables CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR and SOURCE_ARCHIVE have not been set.");
214-
215-
SourceArchiveDir = sourceArchiveDir;
191+
JavaHome =
192+
Actions.GetEnvironmentVariable("CODEQL_JAVA_HOME") ??
193+
Actions.GetEnvironmentVariable("SEMMLE_JAVA_HOME") ??
194+
throw new InvalidEnvironmentException("The environment variable CODEQL_JAVA_HOME or SEMMLE_JAVA_HOME has not been set.");
195+
196+
Distribution =
197+
CodeQLExtractorCSharpRoot ??
198+
SemmleDist ??
199+
throw new InvalidEnvironmentException("The environment variable CODEQL_EXTRACTOR_CSHARP_ROOT or SEMMLE_DIST has not been set.");
200+
201+
TrapDir =
202+
Actions.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_TRAP_DIR") ??
203+
Actions.GetEnvironmentVariable("TRAP_FOLDER") ??
204+
throw new InvalidEnvironmentException("The environment variable CODEQL_EXTRACTOR_CSHARP_TRAP_DIR or TRAP_FOLDER has not been set.");
205+
206+
SourceArchiveDir =
207+
Actions.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR") ??
208+
Actions.GetEnvironmentVariable("SOURCE_ARCHIVE") ??
209+
throw new InvalidEnvironmentException("The environment variable CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR or SOURCE_ARCHIVE has not been set.");
216210
}
217211

218212
private string TrapDir { get; }
@@ -407,29 +401,19 @@ BuildScript AutobuildFailure() =>
407401
/// </summary>
408402
private string? CodeQLExtractorCSharpRoot { get; }
409403

410-
/// <summary>
411-
/// Value of CODEQL_JAVA_HOME environment variable.
412-
/// </summary>
413-
private string? CodeQLJavaHome { get; }
414-
415404
/// <summary>
416405
/// Value of SEMMLE_DIST environment variable.
417406
/// </summary>
418407
private string? SemmleDist { get; }
419408

420-
public string Distribution => CodeQLExtractorCSharpRoot ?? SemmleDist!;
421-
422-
public string JavaHome => CodeQLJavaHome ?? SemmleJavaHome!;
409+
public string Distribution { get; }
423410

424-
/// <summary>
425-
/// Value of SEMMLE_JAVA_HOME environment variable.
426-
/// </summary>
427-
public string? SemmleJavaHome { get; private set; }
411+
public string JavaHome { get; }
428412

429413
/// <summary>
430414
/// Value of SEMMLE_PLATFORM_TOOLS environment variable.
431415
/// </summary>
432-
public string? SemmlePlatformTools { get; private set; }
416+
public string? SemmlePlatformTools { get; }
433417

434418
/// <summary>
435419
/// The absolute path of the odasa executable.

csharp/extractor/Semmle.Util/CanonicalPathCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public override string GetCanonicalPath(string path, IPathCache cache)
127127

128128
if (parent != null)
129129
{
130-
string? name = Path.GetFileName(path);
131-
string? parentPath = cache.GetCanonicalPath(parent.FullName);
130+
var name = Path.GetFileName(path);
131+
var parentPath = cache.GetCanonicalPath(parent.FullName);
132132
try
133133
{
134134
string[] entries = Directory.GetFileSystemEntries(parentPath, name);

0 commit comments

Comments
 (0)