Beispiel #1
0
        public async Task GivenOnePathToOneExistingProjectFile_WhenThisProjectDoesHaveOneProjectAssetsFileProperty_ThenNoException_ShouldBeThrown()
        {
            var mockFileSystem = new MockFileSystem();

            mockFileSystem.AddFile(@"c:\foo\bar\xyz.csproj", new MockFileData(@"<Project Sdk=""Microsoft.NET.Sdk"">
  <PropertyGroup>
    <TargetFrameworks>netstandard1.6;net462;net452</TargetFrameworks>
    <AssemblyName>Lokad.AzureEventStore</AssemblyName>
    <RuntimeIdentifiers>win</RuntimeIdentifiers>
    <OutputType>Library</OutputType>
    <Company>Lokad</Company>
    <Copyright>Copyright © Lokad 2019</Copyright>
    <AssemblyVersion>2.1.0.0</AssemblyVersion>
    <FileVersion>2.1.0.0</FileVersion>
    <PackageId>Lokad.AzureEventStore</PackageId>
    <PackageVersion>2.1.0.0</PackageVersion>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Authors>Lokad</Authors>
    <Description>Simple, low-maintenance event sourcing backed by Azure Blob Storage.</Description>
    <PackageLicenseUrl>https://github.com/Lokad/AzureEventStore/blob/master/LICENSE.txt</PackageLicenseUrl>
    <PackageProjectUrl>https://github.com/Lokad/AzureEventStore</PackageProjectUrl>
    <PackageIconUrl>https://raw.githubusercontent.com/Lokad/AzureEventStore/master/lokad.png</PackageIconUrl>
    <Version>2.1.0</Version>
<ProjectAssetsFile Condition="" '$(ProjectAssetsFile)' == '' "">c:\foo\bar\obj\project.assets.json</ProjectAssetsFile>
  </PropertyGroup>
  <ItemGroup Condition=""'$(TargetFramework)'=='netstandard1.6'"">
    <PackageReference Include=""System.Diagnostics.Contracts"" Version=""4.3.0"" />
    <PackageReference Include=""System.Diagnostics.TraceSource"" Version=""4.3.0"" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include=""Microsoft.Azure.Storage.Blob"" Version=""9.4.1"" />
    <PackageReference Include=""Newtonsoft.Json"" Version=""12.0.1"" />
  </ItemGroup>
</Project>"));

            var entryPoint = new EntryPoint(mockFileSystem.FileInfo.FromFileName(@"c:\foo\bar\xyz.csproj"), EntryPointType.Project);
            var cut        = new ProjectDependencyResolver(mockFileSystem, Mock.Of <IEnvironment>());

            mockFileSystem.AddFile(@"c:\foo\bar\obj\project.assets.json", new MockFileData(""));

            Func <Task> action = async() => await cut.ResolveDependenciesAsync(entryPoint);

            await action.Should().NotThrowAsync();
        }
Beispiel #2
0
        // ReSharper disable UnusedMember.Local
#pragma warning disable IDE0051 // Remove unused private members
        private async Task <int> OnExecuteAsync(CancellationToken cancellationToken)
#pragma warning restore IDE0051 // Remove unused private members
        // ReSharper restore UnusedMember.Local
        {
            if (OutputPath is null)
            {
                SkipDownloadOfLicenses = true;
            }

            IFileInfo?outputFile;

            if (OutputPath != null)
            {
                outputFile = _fileSystem.FileInfo.FromFileName(OutputPath);
                if (outputFile.Exists)
                {
                    _reporter.Error("The file to write the output to already exists. Specify another output path or delete the file");
                    return(1);
                }
            }
            else
            {
                outputFile = null;
            }

            var instances = MSBuildLocator.QueryVisualStudioInstances().ToList();

            MSBuildLocator.RegisterMSBuildPath(instances.First().MSBuildPath);

            var entryPoint = _entryPointLocator.GetEntryPoint(PathToProjectOrSolution);

            var dependencies = await _projectDependencyResolver.ResolveDependenciesAsync(entryPoint);

            _reporter.OutputInvariant($"Resolving dependencies of {entryPoint.File.FullName}");
            _reporter.OutputInvariant($"\tcount {dependencies.Count}");

            _reporter.Output("Extracting licensing information");
            var packageSpec = _packageLocator.Provide(dependencies);

            _reporter.Output("Correcting license locations");
            var existingLicenses = packageSpec.Values
                                   .Where(v => v.LicenseLocation != null)
                                   .Select(v => v.LicenseLocation !)
                                   .Distinct(EqualityComparer <Uri> .Default);
            var correctedLicenseLocations = _uriCorrector.Correct(existingLicenses);

            _reporter.OutputInvariant($"Downloading licenses (total {correctedLicenseLocations.Count})");
            IImmutableDictionary <Uri, string> licenses;

            if (SkipDownloadOfLicenses)
            {
                _reporter.Output("\tSkipping download");
                licenses = ImmutableDictionary <Uri, string> .Empty;
            }
            else
            {
                licenses = await _downloader.DownloadAsync(correctedLicenseLocations.Values.Select(v => v.corrected), cancellationToken);
            }

            var licenseDependencyInformation = new List <LicenseDependencyInformation>();

            foreach (var(package, (location, licenseExpression, authors)) in packageSpec)
            {
                Uri?   correctedUrl;
                string licenseContent;
                if (!(location is null))
                {
                    correctedUrl   = correctedLicenseLocations[location].corrected;
                    licenseContent = licenses.FirstOrDefault(l => l.Key == correctedUrl).Value ?? "";
                }