-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathDefaultPlatformsInformationProvider.cs
More file actions
101 lines (87 loc) · 4.12 KB
/
DefaultPlatformsInformationProvider.cs
File metadata and controls
101 lines (87 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// --------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// --------------------------------------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Options;
namespace Microsoft.Oryx.BuildScriptGenerator
{
/// <summary>
/// Detects platforms in the provided source directory.
/// </summary>
public class DefaultPlatformsInformationProvider
{
private readonly IEnumerable<IProgrammingPlatform> platforms;
private readonly IStandardOutputWriter outputWriter;
private readonly BuildScriptGeneratorOptions commonOptions;
public DefaultPlatformsInformationProvider(
IEnumerable<IProgrammingPlatform> platforms,
IStandardOutputWriter outputWriter,
IOptions<BuildScriptGeneratorOptions> commonOptions)
{
this.platforms = platforms;
this.outputWriter = outputWriter;
this.commonOptions = commonOptions.Value;
}
/// <summary>
/// Detects platforms in the provided source directory.
/// </summary>
/// <param name="context">The <see cref="RepositoryContext"/>.</param>
/// <returns>A list of detected platform results.</returns>
public IEnumerable<PlatformInfo> GetPlatformsInfo(RepositoryContext context)
{
var platformInfos = new List<PlatformInfo>();
this.outputWriter.WriteLine($"Primary SDK Storage URL: {this.commonOptions.OryxSdkStorageBaseUrl}");
this.outputWriter.WriteLine($"Backup SDK Storage URL: {this.commonOptions.OryxSdkStorageBackupBaseUrl}");
// Try detecting ALL platforms since in some scenarios this is required.
// For example, in case of a multi-platform app like ASP.NET Core + NodeJs, we might need to dynamically
// install both these platforms' sdks before actually using any of their commands. So even though a user
// of Oryx might explicitly supply the platform of the app as .NET Core, we still need to make sure the
// build environment is setup with detected platforms' sdks.
this.outputWriter.WriteLine("Detecting platforms...");
if (this.commonOptions.EnableExternalSdkProvider)
{
this.outputWriter.WriteLine("External SDK provider is enabled.");
}
if (this.commonOptions.EnableMcrSdkProvider)
{
this.outputWriter.WriteLine("MCR SDK provider is enabled.");
}
foreach (var platform in this.platforms)
{
// Check if a platform is enabled or not
if (!platform.IsEnabled(context))
{
this.outputWriter.WriteLine(
$"Platform '{platform.Name}' has been disabled, so skipping detection for it.");
continue;
}
var detectionResult = platform.Detect(context);
if (detectionResult != null)
{
var toolsInPath = platform.GetToolsToBeSetInPath(context, detectionResult);
platformInfos.Add(new PlatformInfo
{
DetectorResult = detectionResult,
RequiredToolsInPath = toolsInPath,
});
}
}
if (platformInfos.Any())
{
this.outputWriter.WriteLine("Detected following platforms:");
foreach (var platformInfo in platformInfos)
{
var detectorResult = platformInfo.DetectorResult;
this.outputWriter.WriteLine($" {detectorResult.Platform}: {detectorResult.PlatformVersion}");
}
}
else
{
this.outputWriter.WriteLine("Could not detect any platform in the source directory.");
}
return platformInfos;
}
}
}