<commit_before>using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.DotNet.Cli.Build;

using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

namespace Microsoft.DotNet.Host.Build
{
    public class StubPackageBuilder
    {
        private DotNetCli _dotnet;
        private string _intermediateDirectory;
        private string _outputDirectory;

        private bool _stubBitsBuilt = false;

        public StubPackageBuilder(DotNetCli dotnet, string intermediateDirectory, string outputDirectory)
        {
            _dotnet = dotnet;
            _intermediateDirectory = intermediateDirectory;
            _outputDirectory = outputDirectory;
        }

        public void GeneratePackage(string packageId, string version)
        {
            if (! _stubBitsBuilt)
            {
                BuildStubBits(_dotnet, _intermediateDirectory);
            }

            CreateStubPackage(_dotnet, packageId, version, _intermediateDirectory, _outputDirectory);
        }

        private void BuildStubBits(DotNetCli dotnet, string intermediateDirectory)
        {
            var projectJson = new StringBuilder();
            projectJson.Append("{");
            projectJson.Append("  \"dependencies\": { \"System.Console\": \"4.0.0-*\" },");
            projectJson.Append("  \"frameworks\": { \"netcoreapp1.0\": { } },");
            projectJson.Append("}");

            var programCs = "using System; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { Console.WriteLine(\"Hello World!\"); } } }";

            var tempPjDirectory = Path.Combine(intermediateDirectory, "dummyNuGetPackageIntermediate");
            FS.Rmdir(tempPjDirectory);

            Directory.CreateDirectory(tempPjDirectory);

            var tempPjFile = Path.Combine(tempPjDirectory, "project.json");
            var tempSourceFile = Path.Combine(tempPjDirectory, "Program.cs");

            File.WriteAllText(tempPjFile, projectJson.ToString());
            File.WriteAllText(tempSourceFile, programCs.ToString());

            dotnet.Restore("--verbosity", "verbose", "--disable-parallel")
                .WorkingDirectory(tempPjDirectory)
                .Execute()
                .EnsureSuccessful();
            dotnet.Build(tempPjFile, "--runtime", "win7-x64")
                .WorkingDirectory(tempPjDirectory)
                .Execute()
                .EnsureSuccessful();

            _stubBitsBuilt = true;
        }

        private static void CreateStubPackage(DotNetCli dotnet, 
            string packageId, 
            string version,
            string intermediateDirectory, 
            string outputDirectory)
        {
            var projectJson = new StringBuilder();
            projectJson.Append("{");
            projectJson.Append($"  \"version\": \"{version}\",");
            projectJson.Append($"  \"name\": \"{packageId}\",");
            projectJson.Append("  \"dependencies\": { \"System.Console\": \"4.0.0-*\" },");
            projectJson.Append("  \"frameworks\": { \"netcoreapp1.0\": { } },");
            projectJson.Append("}");

            var tempPjDirectory = Path.Combine(intermediateDirectory, "dummyNuGetPackageIntermediate");
            var tempPjFile = Path.Combine(tempPjDirectory, "project.json");

            File.WriteAllText(tempPjFile, projectJson.ToString());

            dotnet.Pack(
                tempPjFile, "--no-build",
                "--output", outputDirectory)
                .WorkingDirectory(tempPjDirectory)
                .Execute()
                .EnsureSuccessful();
        }
    }
}
<commit_msg>Change stub packages to no longer contain any dependencies.  Instead they just contain a dummy.txt file.<commit_after>using System.IO;
using System.Text;
using Microsoft.DotNet.Cli.Build;

namespace Microsoft.DotNet.Host.Build
{
    public class StubPackageBuilder
    {
        private DotNetCli _dotnet;
        private string _intermediateDirectory;
        private string _outputDirectory;

        private bool _dummyFileCreated;

        public StubPackageBuilder(DotNetCli dotnet, string intermediateDirectory, string outputDirectory)
        {
            _dotnet = dotnet;
            _intermediateDirectory = intermediateDirectory;
            _outputDirectory = outputDirectory;
        }

        public void GeneratePackage(string packageId, string version)
        {
            if (!_dummyFileCreated)
            {
                CreateDummyFile(_dotnet, _intermediateDirectory);
            }

            CreateStubPackage(_dotnet, packageId, version, _intermediateDirectory, _outputDirectory);
        }

        private void CreateDummyFile(DotNetCli dotnet, string intermediateDirectory)
        {
            var dummyTxt = "dummy text";

            var tempPjDirectory = Path.Combine(intermediateDirectory, "dummyNuGetPackageIntermediate");
            FS.Rmdir(tempPjDirectory);

            Directory.CreateDirectory(tempPjDirectory);

            var dummyTextFile = Path.Combine(tempPjDirectory, "dummy.txt");

            File.WriteAllText(dummyTextFile, dummyTxt);

            _dummyFileCreated = true;
        }

        private static void CreateStubPackage(DotNetCli dotnet, 
            string packageId, 
            string version,
            string intermediateDirectory, 
            string outputDirectory)
        {
            var projectJson = new StringBuilder();
            projectJson.Append("{");
            projectJson.Append($"  \"version\": \"{version}\",");
            projectJson.Append($"  \"name\": \"{packageId}\",");
            projectJson.Append("  \"packOptions\": { \"files\": { \"include\": \"dummy.txt\" } },");
            projectJson.Append("  \"frameworks\": { \"netcoreapp1.0\": { } },");
            projectJson.Append("}");

            var tempPjDirectory = Path.Combine(intermediateDirectory, "dummyNuGetPackageIntermediate");
            var tempPjFile = Path.Combine(tempPjDirectory, "project.json");

            File.WriteAllText(tempPjFile, projectJson.ToString());

            dotnet.Pack(
                tempPjFile, "--no-build",
                "--output", outputDirectory)
                .WorkingDirectory(tempPjDirectory)
                .Execute()
                .EnsureSuccessful();
        }
    }
}

{'fraction_non_alphanumeric': 0.10877891833920637, 'fraction_numerical': 0.0022981461620959092, 'mean_word_length': 2.2542372881355934, 'pattern_counts': {'":': 17, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3829898', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1629, 'n_words': 327}