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
|
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
namespace Cli.FunctionalTests
{
public class NuGetPackageSource
{
public static NuGetPackageSource None { get; } = new NuGetPackageSource
{
Name = nameof(None),
SourceArgumentLazy = new Lazy<string>(string.Empty),
};
public static NuGetPackageSource NuGetOrg { get; } = new NuGetPackageSource
{
Name = nameof(NuGetOrg),
SourceArgumentLazy = new Lazy<string>("--source https://api.nuget.org/v3/index.json"),
};
public static NuGetPackageSource DotNetCore { get; } = new NuGetPackageSource
{
Name = nameof(DotNetCore),
SourceArgumentLazy = new Lazy<string>("--source https://dotnetmygetlegacy.blob.core.windows.net/dotnet-core/index.json"),
};
public static NuGetPackageSource EnvironmentVariable { get; } = new NuGetPackageSource
{
Name = nameof(EnvironmentVariable),
SourceArgumentLazy = new Lazy<string>(() => GetSourceArgumentFromEnvironment()),
};
public static NuGetPackageSource EnvironmentVariableAndNuGetOrg { get; } = new NuGetPackageSource
{
Name = nameof(EnvironmentVariableAndNuGetOrg),
SourceArgumentLazy = new Lazy<string>(() => string.Join(" ", EnvironmentVariable.SourceArgument, NuGetOrg.SourceArgument)),
};
private NuGetPackageSource() { }
public string Name { get; private set; }
public string SourceArgument => SourceArgumentLazy.Value;
private Lazy<string> SourceArgumentLazy { get; set; }
public override string ToString() => Name;
private static string GetSourceArgumentFromEnvironment()
{
var sourceString = Environment.GetEnvironmentVariable("NUGET_PACKAGE_SOURCE") ??
throw new InvalidOperationException("Environment variable NUGET_PACKAGE_SOURCE is required but not set");
// Split on pipe and remove blank entries
var sources = sourceString.Split('|').Where(s => !string.IsNullOrWhiteSpace(s));
return string.Join(" ", sources.Select(s => $"--source {s}"));
}
}
}
|