public void AddEntryIndented()
        {
            var data   = @"
    ### Generated by the tool
    ### End of generated by the tool
";
            var writer = new WorkspaceWriter();
            var entry  = new WorkspaceEntry()
            {
                PackageIdentity = new PackageIdentity("remotion.linq", new NuGetVersion(2, 2, 0))
            };

            var result = writer.AddEntry(data, entry, true);

            result = result.Replace("\r", "");

            var tocompare = @"
    ### Generated by the tool
    nuget_package(
        name = ""remotion.linq"",
        package = ""remotion.linq"",
        version = ""2.2.0"",
    )
    ### End of generated by the tool
".Replace("\r", "");

            Assert.Equal(tocompare, result);
        }
Beispiel #2
0
        private WorkspaceEntry ParseEntry()
        {
            while (!IsEof() && IsWhitespace())
            {
                ++_pos;
            }

            if (IsEof())
            {
                return(null);
            }

            var result = new WorkspaceEntry();

            RequireToken(Token.NUGET_PACKAGE);
            RequireToken(Token.LPAR);
            RequireAssignment(Token.NAME);
            var package = RequireAssignment(Token.PACKAGE);
            var version = RequireAssignment(Token.VERSION);

            result.PackageIdentity = new PackageIdentity(package, new NuGetVersion(version));
            result.Sha256          = RequireAssignment(Token.SHA256);
            result.CoreLib         = RequireAssignment(Token.CORE_LIB);
            result.NetLib          = RequireAssignment(Token.NET_LIB);
            result.MonoLib         = RequireAssignment(Token.MONO_LIB);
            result.Core_Deps       = RequireArray(Token.CORE_DEPS);
            result.Net_Deps        = RequireArray(Token.NET_DEPS);
            result.Mono_Deps       = RequireArray(Token.MONO_DEPS);
            result.Core_Files      = RequireArray(Token.CORE_FILES);
            result.Net_Files       = RequireArray(Token.NET_FILES);
            result.Mono_Files      = RequireArray(Token.MONO_FILES);
            RequireToken(Token.RPAR);
            return(result);
        }
        public override async Task <bool> InstallPackageAsync(
            PackageIdentity packageIdentity,
            DownloadResourceResult downloadResourceResult,
            INuGetProjectContext nuGetProjectContext,
            CancellationToken token)
        {
            var dependency = new PackageDependency(packageIdentity.Id, new VersionRange(packageIdentity.Version));

            var json = await GetJsonAsync();

            json.dependencies.Add(packageIdentity.Id, packageIdentity.Version.ToString());
            await SaveJsonAsync(json);

            var packageReader = downloadResourceResult.PackageReader
                                ?? new PackageArchiveReader(downloadResourceResult.PackageStream, leaveStreamOpen: true);
            IAsyncPackageContentReader packageContentReader = packageReader;
            IAsyncPackageCoreReader    packageCoreReader    = packageReader;

            var libItemGroups = await packageContentReader.GetLibItemsAsync(token);

            var referenceItemGroups = await packageContentReader.GetReferenceItemsAsync(token);

            var frameworkReferenceGroups = await packageContentReader.GetFrameworkItemsAsync(token);

            var contentFileGroups = await packageContentReader.GetContentItemsAsync(token);

            var buildFileGroups = await packageContentReader.GetBuildItemsAsync(token);

            var toolItemGroups = await packageContentReader.GetToolItemsAsync(token);

            var depsGroups = await packageContentReader.GetPackageDependenciesAsync(token);

            IEnumerable <FrameworkSpecificGroup> refItemGroups = null;

            if (packageReader is PackageArchiveReader reader)
            {
                refItemGroups = await reader.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }
            else if (packageReader is PackageFolderReader reader2)
            {
                refItemGroups = await reader2.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }

            var sha256 = "";

            if (!_skipSha256)
            {
                sha256 = GetSha(downloadResourceResult.PackageStream);
            }
            var entry = new WorkspaceEntry(packageIdentity, sha256,
                                           depsGroups, libItemGroups, toolItemGroups, refItemGroups, _mainFile, _variable);

            //if (!SdkList.Dlls.Contains(entry.PackageIdentity.Id.ToLower()))
            //{
            await AddEntry(entry);

            //}

            return(await base.InstallPackageAsync(packageIdentity, downloadResourceResult, nuGetProjectContext, token));
        }
        public override async Task <bool> InstallPackageAsync(
            PackageIdentity packageIdentity,
            DownloadResourceResult downloadResourceResult,
            INuGetProjectContext nuGetProjectContext,
            CancellationToken token)
        {
            var dependency = new PackageDependency(packageIdentity.Id, new VersionRange(packageIdentity.Version));

            var json = await GetJsonAsync();

            JsonConfigUtility.AddDependency(json, dependency);
            await SaveJsonAsync(json);

            var packageReader = downloadResourceResult.PackageReader
                                ?? new PackageArchiveReader(downloadResourceResult.PackageStream, leaveStreamOpen: true);
            IAsyncPackageContentReader packageContentReader = packageReader;
            IAsyncPackageCoreReader    packageCoreReader    = packageReader;

            var libItemGroups = await packageContentReader.GetLibItemsAsync(token);

            var referenceItemGroups = await packageContentReader.GetReferenceItemsAsync(token);

            var frameworkReferenceGroups = await packageContentReader.GetFrameworkItemsAsync(token);

            var contentFileGroups = await packageContentReader.GetContentItemsAsync(token);

            var buildFileGroups = await packageContentReader.GetBuildItemsAsync(token);

            var toolItemGroups = await packageContentReader.GetToolItemsAsync(token);

            var depsGroups = await packageContentReader.GetPackageDependenciesAsync(token);

            IEnumerable <FrameworkSpecificGroup> refItemGroups = null;

            if (packageReader is PackageArchiveReader reader)
            {
                refItemGroups = await reader.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }
            else if (packageReader is PackageFolderReader reader2)
            {
                refItemGroups = await reader2.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }

            var deps  = (PackageDependencyInfo)NuGetProjectActions.First(x => x.PackageIdentity.Equals(packageIdentity)).PackageIdentity;
            var entry = new WorkspaceEntry(packageIdentity, GetSha(downloadResourceResult.PackageStream),
                                           depsGroups, libItemGroups, toolItemGroups, refItemGroups, _mainFile);

            if (!SdkList.Dlls.Contains(entry.PackageIdentity.Id.ToLower()))
            {
                var workspace = await GetWorkspaceAsync();

                var updater = new WorkspaceWriter();
                var updated = updater.AddEntry(workspace, entry);
                await SaveWorkspaceAsync(updated);
            }

            return(await base.InstallPackageAsync(packageIdentity, downloadResourceResult, nuGetProjectContext, token));
        }
        public virtual async Task AddEntry(WorkspaceEntry entry)
        {
            var workspace = await GetWorkspaceAsync();

            var updater = new WorkspaceWriter();
            var updated = updater.AddEntry(workspace, entry, ProjectConfig.Indent);

            await SaveWorkspaceAsync(updated);
        }
Beispiel #6
0
        public string AddEntry(string currentWorkspace, WorkspaceEntry toadd)
        {
            var section = extractSection(currentWorkspace);
            var parser  = new WorkspaceParser(section);
            var parsed  = parser.Parse().Where(x => x.PackageIdentity.Id.ToLower() != toadd.PackageIdentity.Id.ToLower()).ToList();

            parsed.Add(toadd);

            var sb = new StringBuilder();

            foreach (var entry in parsed)
            {
                sb.Append(entry.Generate());
            }
            var newSection = sb.ToString();

            return(replaceSection(currentWorkspace, newSection));
        }
Beispiel #7
0
 public override Task AddEntry(WorkspaceEntry entry)
 {
     Entries.Add(entry);
     return(base.AddEntry(entry));
 }
        private WorkspaceEntry ParseEntry()
        {
            while (!IsEof() && IsWhitespace())
            {
                ++_pos;
            }

            if (IsEof())
            {
                return(null);
            }

            var result = new WorkspaceEntry();

            string package = null;
            string version = null;

            RequireToken(TokenCode.NUGET_PACKAGE);
            RequireToken(TokenCode.LPAR);

            var finished = false;

            while (!finished)
            {
                var(token, val) = PeekToken();
                switch (token)
                {
                case TokenCode.NAME:
                    RequireToken(TokenCode.NAME);
                    RequireToken(TokenCode.EQUAL);
                    try
                    {
                        RequireToken(TokenCode.STRING);
                    }
                    catch (UnexpectedToken ex)
                    {
                        result.Variable = ex.Literal;
                    }
                    break;

                case TokenCode.SOURCE:
                    RequireToken(TokenCode.SOURCE);
                    RequireToken(TokenCode.EQUAL);
                    RequireToken(TokenCode.SOURCE);
                    result.NugetSourceCustom = true;
                    break;

                case TokenCode.CORE_FILES:
                    result.Core_Files = RequireDictionaryList(TokenCode.CORE_FILES);
                    break;

                case TokenCode.CORE_LIB:
                    result.CoreLib = RequireDictionary(TokenCode.CORE_LIB);
                    break;

                case TokenCode.CORE_REF:
                    result.CoreRef = RequireDictionary(TokenCode.CORE_REF);
                    break;

                case TokenCode.MONO_DEPS:
                    result.Mono_Deps = RequireArray(TokenCode.MONO_DEPS);
                    break;

                case TokenCode.MONO_FILES:
                    result.Mono_Files = RequireArray(TokenCode.MONO_FILES);
                    break;

                case TokenCode.MONO_LIB:
                    result.MonoLib = RequireAssignment(TokenCode.MONO_LIB);
                    break;

                case TokenCode.MONO_REF:
                    result.MonoRef = RequireAssignment(TokenCode.MONO_REF);
                    break;

                case TokenCode.NET_DEPS:
                    result.Net_Deps = RequireDictionaryList(TokenCode.NET_DEPS);
                    break;

                case TokenCode.NET_FILES:
                    result.Net_Files = RequireDictionaryList(TokenCode.NET_FILES);
                    break;

                case TokenCode.NET_LIB:
                    result.NetLib = RequireDictionary(TokenCode.NET_LIB);
                    break;

                case TokenCode.NET_REF:
                    result.NetRef = RequireDictionary(TokenCode.NET_REF);
                    break;

                case TokenCode.PACKAGE:
                    package = RequireAssignment(TokenCode.PACKAGE);
                    break;

                case TokenCode.VERSION:
                    version = RequireAssignment(TokenCode.VERSION);
                    break;

                case TokenCode.SHA256:
                    result.Sha256 = RequireAssignment(TokenCode.SHA256);
                    break;

                case TokenCode.CORE_TOOL:
                    result.CoreTool = RequireDictionary(TokenCode.CORE_TOOL);
                    break;

                case TokenCode.NET_TOOL:
                    result.NetTool = RequireDictionary(TokenCode.NET_TOOL);
                    break;

                case TokenCode.MONO_TOOL:
                    result.MonoTool = RequireAssignment(TokenCode.MONO_TOOL);
                    break;

                case TokenCode.CORE_DEPS:
                    result.Core_Deps = RequireDictionaryList(TokenCode.CORE_DEPS);
                    break;

                case TokenCode.RPAR:
                    finished = true;
                    GetToken();
                    break;
                }
            }

            result.PackageIdentity = new PackageIdentity(package, new NuGetVersion(version));

            return(result);
        }
        public override async Task <bool> InstallPackageAsync(
            PackageIdentity packageIdentity,
            DownloadResourceResult downloadResourceResult,
            INuGetProjectContext nuGetProjectContext,
            CancellationToken token)
        {
            var dependency = new PackageDependency(packageIdentity.Id, new VersionRange(packageIdentity.Version));

            var json = await GetJsonAsync();

            json.dependencies.Add(packageIdentity.Id, packageIdentity.Version.ToString());
            await SaveJsonAsync(json);

            var packageReader = downloadResourceResult.PackageReader
                                ?? new PackageArchiveReader(downloadResourceResult.PackageStream, leaveStreamOpen: true);
            IAsyncPackageContentReader packageContentReader = packageReader;
            IAsyncPackageCoreReader    packageCoreReader    = packageReader;

            var libItemGroups = await packageContentReader.GetLibItemsAsync(token);

            var referenceItemGroups = await packageContentReader.GetReferenceItemsAsync(token);

            var frameworkReferenceGroups = await packageContentReader.GetFrameworkItemsAsync(token);

            var contentFileGroups = await packageContentReader.GetContentItemsAsync(token);

            var buildFileGroups = await packageContentReader.GetBuildItemsAsync(token);

            var toolItemGroups = await packageContentReader.GetToolItemsAsync(token);

            var depsGroups = await packageContentReader.GetPackageDependenciesAsync(token);

            // Very ugly hack to extract build folder and runtimes folder content
            // Unfortunately, the original implementation only returns .prop and .targets files.
            var readerBase         = (PackageReaderBase)packageContentReader;
            var dynMethod          = readerBase.GetType().BaseType.GetMethod("GetFileGroups", BindingFlags.NonPublic | BindingFlags.Instance);
            var allBuildFileGroups = (IEnumerable <FrameworkSpecificGroup>)dynMethod.Invoke(readerBase, new object?[] { "build" });
            var allRuntimes        = (IEnumerable <FrameworkSpecificGroup>)dynMethod.Invoke(readerBase, new object?[] { "runtimes" });

            IEnumerable <FrameworkSpecificGroup> refItemGroups = null;

            if (packageReader is PackageArchiveReader reader)
            {
                refItemGroups = await reader.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }
            else if (packageReader is PackageFolderReader reader2)
            {
                refItemGroups = await reader2.GetItemsAsync(PackagingConstants.Folders.Ref, token);
            }

            var sha256 = "";

            if (!_skipSha256)
            {
                sha256 = GetSha(downloadResourceResult.PackageStream);
            }
            var entry = new WorkspaceEntry(json.dependencies, packageIdentity, sha256,
                                           depsGroups, libItemGroups, toolItemGroups, refItemGroups, allBuildFileGroups, allRuntimes, _mainFile, _variable, _nugetSourceCustom);

            _entries.Add(packageIdentity, entry);
            await AddEntry(entry);

            return(await base.InstallPackageAsync(packageIdentity, downloadResourceResult, nuGetProjectContext, token));
        }