Merge pull request #1918 from dotnet/pakrym/deps-nulls
Remove DependencyModel csv reader, add lots of null checks everywhere
This commit is contained in:
commit
f5330cdd1f
18 changed files with 163 additions and 310 deletions
|
@ -19,6 +19,10 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
bool serviceable)
|
||||
: base(type, name, version, hash, dependencies, serviceable)
|
||||
{
|
||||
if (assemblies == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assemblies));
|
||||
}
|
||||
Assemblies = assemblies.ToArray();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -8,7 +9,7 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
{
|
||||
public class CompilationOptions
|
||||
{
|
||||
public IEnumerable<string> Defines { get; }
|
||||
public IReadOnlyList<string> Defines { get; }
|
||||
|
||||
public string LanguageVersion { get; }
|
||||
|
||||
|
@ -26,7 +27,7 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
|
||||
public bool? PublicSign { get; }
|
||||
|
||||
public string DebugType { get; }
|
||||
public string DebugType { get; }
|
||||
|
||||
public bool? EmitEntryPoint { get; }
|
||||
|
||||
|
@ -59,7 +60,11 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
bool? emitEntryPoint,
|
||||
bool? generateXmlDocumentation)
|
||||
{
|
||||
Defines = defines;
|
||||
if (defines == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(defines));
|
||||
}
|
||||
Defines = defines.ToArray();
|
||||
LanguageVersion = languageVersion;
|
||||
Platform = platform;
|
||||
AllowUnsafe = allowUnsafe;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyModel
|
||||
|
@ -9,6 +10,14 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
{
|
||||
public Dependency(string name, string version)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new ArgumentException(nameof(name));
|
||||
}
|
||||
if (string.IsNullOrEmpty(version))
|
||||
{
|
||||
throw new ArgumentException(nameof(version));
|
||||
}
|
||||
Name = name;
|
||||
Version = version;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,9 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
IEnumerable<RuntimeLibrary> runtimeLibraries,
|
||||
IEnumerable<RuntimeFallbacks> runtimeGraph)
|
||||
{
|
||||
if (targetFramework == null)
|
||||
if (string.IsNullOrEmpty(targetFramework))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(targetFramework));
|
||||
}
|
||||
if (runtime == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(runtime));
|
||||
throw new ArgumentException(nameof(targetFramework));
|
||||
}
|
||||
if (compilationOptions == null)
|
||||
{
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyModel
|
||||
{
|
||||
public class DependencyContextCsvReader: IDependencyContextReader
|
||||
{
|
||||
public DependencyContext Read(Stream stream)
|
||||
{
|
||||
var lines = new List<DepsFileLine>();
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
var line = new DepsFileLine();
|
||||
line.LibraryType = ReadValue(reader);
|
||||
line.PackageName = ReadValue(reader);
|
||||
line.PackageVersion = ReadValue(reader);
|
||||
line.PackageHash = ReadValue(reader);
|
||||
line.AssetType = ReadValue(reader);
|
||||
line.AssetName = ReadValue(reader);
|
||||
line.AssetPath = ReadValue(reader);
|
||||
|
||||
if (line.AssetType == "runtime" &&
|
||||
!line.AssetPath.EndsWith(".ni.dll"))
|
||||
{
|
||||
lines.Add(line);
|
||||
}
|
||||
SkipWhitespace(reader);
|
||||
}
|
||||
}
|
||||
|
||||
var runtimeLibraries = new List<RuntimeLibrary>();
|
||||
var packageGroups = lines.GroupBy(PackageIdentity);
|
||||
foreach (var packageGroup in packageGroups)
|
||||
{
|
||||
var identity = packageGroup.Key;
|
||||
runtimeLibraries.Add(new RuntimeLibrary(
|
||||
type: identity.Item1,
|
||||
name: identity.Item2,
|
||||
version: identity.Item3,
|
||||
hash: identity.Item4,
|
||||
assemblies: packageGroup.Select(l => RuntimeAssembly.Create(l.AssetPath)),
|
||||
nativeLibraries: Enumerable.Empty<string>(),
|
||||
resourceAssemblies: Enumerable.Empty<ResourceAssembly>(),
|
||||
subTargets: Enumerable.Empty<RuntimeTarget>(),
|
||||
dependencies: Enumerable.Empty<Dependency>(),
|
||||
serviceable: false
|
||||
));
|
||||
}
|
||||
|
||||
return new DependencyContext(
|
||||
targetFramework: string.Empty,
|
||||
runtime: string.Empty,
|
||||
isPortable: false,
|
||||
compilationOptions: CompilationOptions.Default,
|
||||
compileLibraries: Enumerable.Empty<CompilationLibrary>(),
|
||||
runtimeLibraries: runtimeLibraries.ToArray(),
|
||||
runtimeGraph: Enumerable.Empty<RuntimeFallbacks>());
|
||||
}
|
||||
|
||||
private Tuple<string, string, string, string> PackageIdentity(DepsFileLine line)
|
||||
{
|
||||
return Tuple.Create(line.LibraryType, line.PackageName, line.PackageVersion, line.PackageHash);
|
||||
}
|
||||
|
||||
private void SkipWhitespace(StreamReader reader)
|
||||
{
|
||||
// skip all whitespace
|
||||
while (!reader.EndOfStream && char.IsWhiteSpace((char)reader.Peek()))
|
||||
{
|
||||
reader.Read();
|
||||
}
|
||||
}
|
||||
|
||||
private string ReadValue(StreamReader reader)
|
||||
{
|
||||
SkipWhitespace(reader);
|
||||
|
||||
var c = ReadSucceed(reader.Read());
|
||||
if (c != '"')
|
||||
{
|
||||
throw new FormatException("Deps file value should start with '\"'");
|
||||
}
|
||||
|
||||
var value = new StringBuilder();
|
||||
while (ReadSucceed(reader.Peek()) != '"')
|
||||
{
|
||||
c = ReadSucceed(reader.Read());
|
||||
if (c == '\\')
|
||||
{
|
||||
value.Append(ReadSucceed(reader.Read()));
|
||||
}
|
||||
else
|
||||
{
|
||||
value.Append(c);
|
||||
}
|
||||
}
|
||||
// Read last "
|
||||
ReadSucceed(reader.Read());
|
||||
// Read comment
|
||||
if (reader.Peek() == ',')
|
||||
{
|
||||
reader.Read();
|
||||
}
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
private char ReadSucceed(int c)
|
||||
{
|
||||
if (c == -1)
|
||||
{
|
||||
throw new FormatException("Unexpected end of file");
|
||||
}
|
||||
return (char) c;
|
||||
}
|
||||
|
||||
private struct DepsFileLine
|
||||
{
|
||||
public string LibraryType;
|
||||
public string PackageName;
|
||||
public string PackageVersion;
|
||||
public string PackageHash;
|
||||
public string AssetType;
|
||||
public string AssetName;
|
||||
public string AssetPath;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,6 +14,10 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
{
|
||||
public DependencyContext Read(Stream stream)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
}
|
||||
using (var streamReader = new StreamReader(stream))
|
||||
{
|
||||
using (var reader = new JsonTextReader(streamReader))
|
||||
|
@ -39,35 +43,60 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
|
||||
JObject runtimeTarget = null;
|
||||
JObject compileTarget = null;
|
||||
if (targetsObject != null)
|
||||
|
||||
if (targetsObject == null)
|
||||
{
|
||||
var compileTargetProperty = targetsObject.Properties()
|
||||
.FirstOrDefault(p => !IsRuntimeTarget(p.Name));
|
||||
throw new FormatException("Dependency file does not have 'targets' section");
|
||||
}
|
||||
|
||||
compileTarget = (JObject)compileTargetProperty.Value;
|
||||
target = compileTargetProperty.Name;
|
||||
|
||||
if (!string.IsNullOrEmpty(runtimeTargetName))
|
||||
if (!string.IsNullOrEmpty(runtimeTargetName))
|
||||
{
|
||||
runtimeTarget = (JObject) targetsObject[runtimeTargetName];
|
||||
if (runtimeTarget == null)
|
||||
{
|
||||
runtimeTarget = (JObject) targetsObject[runtimeTargetName];
|
||||
if (runtimeTarget == null)
|
||||
{
|
||||
throw new FormatException($"Target with name {runtimeTargetName} not found");
|
||||
}
|
||||
throw new FormatException($"Target with name {runtimeTargetName} not found");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var runtimeTargetProperty = targetsObject.Properties()
|
||||
.FirstOrDefault(p => IsRuntimeTarget(p.Name));
|
||||
|
||||
var seperatorIndex = runtimeTargetName.IndexOf(DependencyContextStrings.VersionSeperator);
|
||||
if (seperatorIndex > -1 && seperatorIndex < runtimeTargetName.Length)
|
||||
{
|
||||
runtime = runtimeTargetName.Substring(seperatorIndex + 1);
|
||||
isPortable = false;
|
||||
}
|
||||
runtimeTarget = (JObject)runtimeTargetProperty?.Value;
|
||||
runtimeTargetName = runtimeTargetProperty?.Name;
|
||||
}
|
||||
|
||||
if (runtimeTargetName != null)
|
||||
{
|
||||
var seperatorIndex = runtimeTargetName.IndexOf(DependencyContextStrings.VersionSeperator);
|
||||
if (seperatorIndex > -1 && seperatorIndex < runtimeTargetName.Length)
|
||||
{
|
||||
runtime = runtimeTargetName.Substring(seperatorIndex + 1);
|
||||
target = runtimeTargetName.Substring(0, seperatorIndex);
|
||||
isPortable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
runtimeTarget = compileTarget;
|
||||
target = runtimeTargetName;
|
||||
}
|
||||
}
|
||||
|
||||
var ridlessTargetProperty = targetsObject.Properties().FirstOrDefault(p => !IsRuntimeTarget(p.Name));
|
||||
if (ridlessTargetProperty != null)
|
||||
{
|
||||
compileTarget = (JObject)ridlessTargetProperty.Value;
|
||||
if (runtimeTarget == null)
|
||||
{
|
||||
runtimeTarget = compileTarget;
|
||||
target = ridlessTargetProperty.Name;
|
||||
}
|
||||
}
|
||||
|
||||
if (runtimeTarget == null)
|
||||
{
|
||||
throw new FormatException("No runtime target found");
|
||||
}
|
||||
|
||||
return new DependencyContext(
|
||||
target,
|
||||
runtime,
|
||||
|
@ -100,7 +129,7 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
}
|
||||
|
||||
return new CompilationOptions(
|
||||
compilationOptionsObject[DependencyContextStrings.DefinesPropertyName]?.Values<string>(),
|
||||
compilationOptionsObject[DependencyContextStrings.DefinesPropertyName]?.Values<string>() ?? Enumerable.Empty<string>(),
|
||||
compilationOptionsObject[DependencyContextStrings.LanguageVersionPropertyName]?.Value<string>(),
|
||||
compilationOptionsObject[DependencyContextStrings.PlatformPropertyName]?.Value<string>(),
|
||||
compilationOptionsObject[DependencyContextStrings.AllowUnsafePropertyName]?.Value<bool>(),
|
||||
|
|
|
@ -14,20 +14,17 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
private static Lazy<string[]> _depsFiles = new Lazy<string[]>(GetHostDepsList);
|
||||
|
||||
private const string DepsJsonExtension = ".deps.json";
|
||||
private const string DepsExtension = ".deps";
|
||||
|
||||
private readonly string _entryPointDepsLocation;
|
||||
private readonly string _runtimeDepsLocation;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IDependencyContextReader _jsonReader;
|
||||
private readonly IDependencyContextReader _csvReader;
|
||||
|
||||
public DependencyContextLoader() : this(
|
||||
GetDefaultEntrypointDepsLocation(),
|
||||
GetDefaultRuntimeDepsLocation(),
|
||||
FileSystemWrapper.Default,
|
||||
new DependencyContextJsonReader(),
|
||||
new DependencyContextCsvReader())
|
||||
new DependencyContextJsonReader())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -35,21 +32,19 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
string entryPointDepsLocation,
|
||||
string runtimeDepsLocation,
|
||||
IFileSystem fileSystem,
|
||||
IDependencyContextReader jsonReader,
|
||||
IDependencyContextReader csvReader)
|
||||
IDependencyContextReader jsonReader)
|
||||
{
|
||||
_entryPointDepsLocation = entryPointDepsLocation;
|
||||
_runtimeDepsLocation = runtimeDepsLocation;
|
||||
_fileSystem = fileSystem;
|
||||
_jsonReader = jsonReader;
|
||||
_csvReader = csvReader;
|
||||
}
|
||||
|
||||
public static DependencyContextLoader Default { get; } = new DependencyContextLoader();
|
||||
|
||||
internal virtual bool IsEntryAssembly(Assembly assembly)
|
||||
{
|
||||
return assembly.GetName() == Assembly.GetEntryAssembly().GetName();
|
||||
return assembly.GetName() == Assembly.GetEntryAssembly()?.GetName();
|
||||
}
|
||||
|
||||
internal virtual Stream GetResourceStream(Assembly assembly, string name)
|
||||
|
@ -132,15 +127,6 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
}
|
||||
}
|
||||
|
||||
var depsFile = Path.ChangeExtension(assembly.Location, DepsExtension);
|
||||
if (_fileSystem.File.Exists(depsFile))
|
||||
{
|
||||
using (var stream = _fileSystem.File.OpenRead(depsFile))
|
||||
{
|
||||
return _csvReader.Read(stream);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -166,7 +152,7 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
|
||||
private static string[] GetHostDepsList()
|
||||
{
|
||||
// TODO: Were going to replace this with AppContext.GetData
|
||||
// TODO: We're going to replace this with AppContext.GetData
|
||||
var appDomainType = typeof(object).GetTypeInfo().Assembly?.GetType("System.AppDomain");
|
||||
var currentDomain = appDomainType?.GetProperty("CurrentDomain")?.GetValue(null);
|
||||
var deps = appDomainType?.GetMethod("GetData")?.Invoke(currentDomain, new[] { "APP_CONTEXT_DEPS_FILES" });
|
||||
|
|
|
@ -16,6 +16,14 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
{
|
||||
public void Write(DependencyContext context, Stream stream)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
}
|
||||
using (var writer = new StreamWriter(stream))
|
||||
{
|
||||
using (var jsonWriter = new JsonTextWriter(writer) { Formatting = Formatting.Indented })
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -10,6 +11,22 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
{
|
||||
public Library(string type, string name, string version, string hash, IEnumerable<Dependency> dependencies, bool serviceable)
|
||||
{
|
||||
if (string.IsNullOrEmpty(type))
|
||||
{
|
||||
throw new ArgumentException(nameof(type));
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new ArgumentException(nameof(name));
|
||||
}
|
||||
if (string.IsNullOrEmpty(version))
|
||||
{
|
||||
throw new ArgumentException(nameof(version));
|
||||
}
|
||||
if (dependencies == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(dependencies));
|
||||
}
|
||||
Type = type;
|
||||
Name = name;
|
||||
Version = version;
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyModel
|
||||
{
|
||||
public class ResourceAssembly
|
||||
{
|
||||
public ResourceAssembly(string path, string locale)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentException(nameof(path));
|
||||
}
|
||||
if (string.IsNullOrEmpty(locale))
|
||||
{
|
||||
throw new ArgumentException(nameof(locale));
|
||||
}
|
||||
Locale = locale;
|
||||
Path = path;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,14 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
|
||||
public RuntimeAssembly(string assemblyName, string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(assemblyName))
|
||||
{
|
||||
throw new ArgumentException(nameof(assemblyName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentException(nameof(path));
|
||||
}
|
||||
_assemblyName = assemblyName;
|
||||
Path = path;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
|
||||
public RuntimeFallbacks(string runtime, IEnumerable<string> fallbacks)
|
||||
{
|
||||
if (runtime == null)
|
||||
if (string.IsNullOrEmpty(runtime))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(runtime));
|
||||
throw new ArgumentException(nameof(runtime));
|
||||
}
|
||||
if (fallbacks == null)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -21,6 +22,22 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
bool serviceable)
|
||||
: base(type, name, version, hash, dependencies, serviceable)
|
||||
{
|
||||
if (assemblies == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assemblies));
|
||||
}
|
||||
if (nativeLibraries == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nativeLibraries));
|
||||
}
|
||||
if (resourceAssemblies == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(resourceAssemblies));
|
||||
}
|
||||
if (subTargets == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(subTargets));
|
||||
}
|
||||
Assemblies = assemblies.ToArray();
|
||||
ResourceAssemblies = resourceAssemblies.ToArray();
|
||||
RuntimeTargets = subTargets.ToArray();
|
||||
|
@ -28,8 +45,8 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
}
|
||||
|
||||
public IReadOnlyList<RuntimeAssembly> Assemblies { get; }
|
||||
|
||||
public IReadOnlyList<string> NativeLibraries { get; }
|
||||
|
||||
public IReadOnlyList<string> NativeLibraries { get; }
|
||||
|
||||
public IReadOnlyList<ResourceAssembly> ResourceAssemblies { get; }
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -7,6 +8,18 @@ namespace Microsoft.Extensions.DependencyModel
|
|||
{
|
||||
public RuntimeTarget(string runtime, IEnumerable<RuntimeAssembly> assemblies, IEnumerable<string> nativeLibraries)
|
||||
{
|
||||
if (string.IsNullOrEmpty(runtime))
|
||||
{
|
||||
throw new ArgumentException(nameof(runtime));
|
||||
}
|
||||
if (assemblies == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assemblies));
|
||||
}
|
||||
if (nativeLibraries == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nativeLibraries));
|
||||
}
|
||||
Runtime = runtime;
|
||||
Assemblies = assemblies.ToArray();
|
||||
NativeLibraries = nativeLibraries.ToArray();
|
||||
|
|
|
@ -10,7 +10,7 @@ using Moq;
|
|||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace StreamForwarderTests
|
||||
namespace Microsoft.Extensions.DependencyModel.Tests
|
||||
{
|
||||
public class CompositeResolverTests
|
||||
{
|
||||
|
@ -55,14 +55,7 @@ namespace StreamForwarderTests
|
|||
failTwo.Object
|
||||
};
|
||||
|
||||
var library = new CompilationLibrary(
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
Enumerable.Empty<string>(),
|
||||
Enumerable.Empty<Dependency>(),
|
||||
false);
|
||||
var library = TestLibraryFactory.Create();
|
||||
|
||||
var resolver = new CompositeCompilationAssemblyResolver(resolvers);
|
||||
var result = resolver.TryResolveAssemblyPaths(library, null);
|
||||
|
@ -90,14 +83,7 @@ namespace StreamForwarderTests
|
|||
};
|
||||
|
||||
var assemblies = new List<string>();
|
||||
var library = new CompilationLibrary(
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
Enumerable.Empty<string>(),
|
||||
Enumerable.Empty<Dependency>(),
|
||||
false);
|
||||
var library = TestLibraryFactory.Create();
|
||||
|
||||
var resolver = new CompositeCompilationAssemblyResolver(resolvers);
|
||||
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyModel.Tests
|
||||
{
|
||||
public class DependencyContextCsvReaderTests
|
||||
{
|
||||
private DependencyContext Read(string text)
|
||||
{
|
||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(text)))
|
||||
{
|
||||
return new DependencyContextCsvReader().Read(stream);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GroupsAssetsCorrectlyIntoLibraries()
|
||||
{
|
||||
var context = Read(@"
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.Runtime.dll""
|
||||
");
|
||||
context.RuntimeLibraries.Should().HaveCount(1);
|
||||
var library = context.RuntimeLibraries.Single();
|
||||
library.Type.Should().Be("Package");
|
||||
library.Name.Should().Be("runtime.any.System.AppContext");
|
||||
library.Version.Should().Be("4.1.0-rc2-23811");
|
||||
library.Hash.Should().Be("sha512-1");
|
||||
library.Assemblies.Should().HaveCount(2).And
|
||||
.Contain(a => a.Path == "lib\\dnxcore50\\System.AppContext.dll").And
|
||||
.Contain(a => a.Path == "lib\\dnxcore50\\System.Runtime.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IgnoresAllButRuntimeAssets()
|
||||
{
|
||||
var context = Read(@"
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""native"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext2.so""
|
||||
");
|
||||
context.RuntimeLibraries.Should().HaveCount(1);
|
||||
var library = context.RuntimeLibraries.Single();
|
||||
library.Assemblies.Should().HaveCount(1).And
|
||||
.Contain(a => a.Path == "lib\\dnxcore50\\System.AppContext.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IgnoresNiDllAssemblies()
|
||||
{
|
||||
var context = Read(@"
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.ni.dll""
|
||||
");
|
||||
context.RuntimeLibraries.Should().HaveCount(1);
|
||||
var library = context.RuntimeLibraries.Single();
|
||||
library.Assemblies.Should().HaveCount(1).And
|
||||
.Contain(a => a.Path == "lib\\dnxcore50\\System.AppContext.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsesTypeNameVersionAndHashToGroup()
|
||||
{
|
||||
var context = Read(@"
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23812"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-2"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext2"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Project"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
");
|
||||
context.RuntimeLibraries.Should().HaveCount(5);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("text")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("\"")]
|
||||
[InlineData(@""",""")]
|
||||
[InlineData(@"\\")]
|
||||
public void ThrowsFormatException(string intput)
|
||||
{
|
||||
Assert.Throws<FormatException>(() => Read(intput));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,7 +26,6 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
@"{
|
||||
""runtimeTarget"": "".NETStandardApp,Version=v1.5/osx.10.10-x64"",
|
||||
""targets"": {
|
||||
"".NETStandardApp,Version=v1.5"": {},
|
||||
"".NETStandardApp,Version=v1.5/osx.10.10-x64"": {},
|
||||
}
|
||||
}");
|
||||
|
@ -35,21 +34,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
context.Runtime.Should().Be("osx.10.10-x64");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultsToPortable()
|
||||
{
|
||||
var context = Read(
|
||||
@"{
|
||||
}");
|
||||
context.IsPortable.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetsPortableIfRuntimeTargetHasNoRid()
|
||||
{
|
||||
var context = Read(
|
||||
@"{
|
||||
""runtimeTarget"": "".NETStandardApp,Version=v1.5"",
|
||||
""targets"": {
|
||||
"".NETStandardApp,Version=v1.5"": {}
|
||||
}
|
||||
|
@ -64,7 +53,6 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
@"{
|
||||
""runtimeTarget"": "".NETStandardApp,Version=v1.5/osx.10.10-x64"",
|
||||
""targets"": {
|
||||
"".NETStandardApp,Version=v1.5"": {},
|
||||
"".NETStandardApp,Version=v1.5/osx.10.10-x64"": {}
|
||||
}
|
||||
}");
|
||||
|
@ -88,6 +76,9 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
{
|
||||
var context = Read(
|
||||
@"{
|
||||
""targets"": {
|
||||
"".NETStandardApp,Version=v1.5/osx.10.10-x64"": {},
|
||||
},
|
||||
""runtimes"": {
|
||||
""osx.10.10-x64"": [ ],
|
||||
""osx.10.11-x64"": [ ""osx"" ],
|
||||
|
@ -237,6 +228,9 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
""publicSign"": true,
|
||||
""warningsAsErrors"": true,
|
||||
""optimize"": true
|
||||
},
|
||||
""targets"": {
|
||||
"".NETStandardApp,Version=v1.5/osx.10.10-x64"": {},
|
||||
}
|
||||
}");
|
||||
context.CompilationOptions.AllowUnsafe.Should().Be(true);
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
|||
IReadOnlyList<RuntimeFallbacks> runtimeGraph = null)
|
||||
{
|
||||
return new DependencyContext(
|
||||
target ?? string.Empty,
|
||||
target ?? "DefaultTarget",
|
||||
runtime ?? string.Empty,
|
||||
isPortable ?? false,
|
||||
compilationOptions ?? CompilationOptions.Default,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue