<commit_before>// <copyright file="ProductModule.cs" company="<NAME>">
//  Opus package
// </copyright>
// <summary>Publisher package</summary>
// <author><NAME></author>
namespace VSSolutionBuilder
{
    public sealed partial class VSSolutionBuilder
    {
        private static void CopyNodes(IProject toProject, Opus.Core.DependencyNode toCopy)
        {
            var configCollection = toProject.Configurations;
            // TODO: this should be done from the base target!
            var configurationName = configCollection.GetConfigurationNameForTarget(toCopy.Target); // TODO: not accurate
            var configuration = configCollection[configurationName];

            var toolName = "VCPostBuildEventTool";
            var vcPostBuildEventTool = configuration.GetTool(toolName);
            if (null == vcPostBuildEventTool)
            {
                vcPostBuildEventTool = new ProjectTool(toolName);
                configuration.AddToolIfMissing(vcPostBuildEventTool);
            }

            var sourceLoc = toCopy.Module.Locations[C.Application.OutputFile];
            var sourcePath = sourceLoc.GetSingleRawPath();
            var destinationDir = configuration.OutputDirectory;

            var commandLine = new System.Text.StringBuilder();
            commandLine.AppendFormat("IF NOT EXIST \"{0}\" MKDIR \"{0}\"{1}", destinationDir, System.Environment.NewLine);
            commandLine.AppendFormat("cmd.exe /c COPY \"{0}\" \"{1}\"{2}", sourcePath, destinationDir, System.Environment.NewLine);

            {
                string attributeName = null;
                if (VisualStudioProcessor.EVisualStudioTarget.VCPROJ == toProject.VSTarget)
                {
                    attributeName = "CommandLine";
                }
                else if (VisualStudioProcessor.EVisualStudioTarget.MSBUILD == toProject.VSTarget)
                {
                    attributeName = "Command";
                }

                lock (vcPostBuildEventTool)
                {
                    if (vcPostBuildEventTool.HasAttribute(attributeName))
                    {
                        var currentValue = vcPostBuildEventTool[attributeName];
                        currentValue += commandLine.ToString();
                        vcPostBuildEventTool[attributeName] = currentValue;
                    }
                    else
                    {
                        vcPostBuildEventTool.AddAttribute(attributeName, commandLine.ToString());
                    }
                }
            }
        }

        public object Build(Publisher.ProductModule moduleToBuild, out bool success)
        {
            var primaryNode = Publisher.ProductModuleUtilities.GetPrimaryNode(moduleToBuild);
            var projectData = primaryNode.Data as IProject;
            CopyNodes(projectData, primaryNode);

            success = true;
            return null;
        }
    }
}<commit_msg>[trunk] VSSolution support for publishing. Dependencies are copied next to the primary module<commit_after>// <copyright file="ProductModule.cs" company="<NAME>">
//  Opus package
// </copyright>
// <summary>Publisher package</summary>
// <author><NAME></author>
namespace VSSolutionBuilder
{
    public sealed partial class VSSolutionBuilder
    {
        private static void
        CopyNodes(
            Publisher.ProductModule moduleToBuild,
            IProject toProject,
            Opus.Core.DependencyNode toCopy)
        {
            var configCollection = toProject.Configurations;
            // TODO: this should be done from the base target!
            var configurationName = configCollection.GetConfigurationNameForTarget(toCopy.Target); // TODO: not accurate
            var configuration = configCollection[configurationName];

            var toolName = "VCPostBuildEventTool";
            var vcPostBuildEventTool = configuration.GetTool(toolName);
            if (null == vcPostBuildEventTool)
            {
                vcPostBuildEventTool = new ProjectTool(toolName);
                configuration.AddToolIfMissing(vcPostBuildEventTool);
            }

            // TODO: the key needs to be on an options interface or similiar
            var sourceLoc = toCopy.Module.Locations[C.Application.OutputFile];
            var sourcePath = sourceLoc.GetSingleRawPath();

            var destinationDir = configuration.OutputDirectory;
            var destinationDirPath = destinationDir.GetSingleRawPath();

            var newKeyName = Publisher.ProductModuleUtilities.GetPublishedKeyName(toCopy.Module, toCopy.Module, C.Application.OutputFile);
            var primaryKey = new Opus.Core.LocationKey(newKeyName, Opus.Core.ScaffoldLocation.ETypeHint.File);
            var destPath = Publisher.ProductModuleUtilities.GenerateDestinationPath(sourcePath, destinationDirPath, moduleToBuild, primaryKey);

            var commandLine = new System.Text.StringBuilder();
            commandLine.AppendFormat("cmd.exe /c COPY \"{0}\" \"{1}\"{2}", sourcePath, destPath, System.Environment.NewLine);

            {
                string attributeName = null;
                if (VisualStudioProcessor.EVisualStudioTarget.VCPROJ == toProject.VSTarget)
                {
                    attributeName = "CommandLine";
                }
                else if (VisualStudioProcessor.EVisualStudioTarget.MSBUILD == toProject.VSTarget)
                {
                    attributeName = "Command";
                }

                lock (vcPostBuildEventTool)
                {
                    if (vcPostBuildEventTool.HasAttribute(attributeName))
                    {
                        var currentValue = vcPostBuildEventTool[attributeName];
                        currentValue += commandLine.ToString();
                        vcPostBuildEventTool[attributeName] = currentValue;
                    }
                    else
                    {
                        vcPostBuildEventTool.AddAttribute(attributeName, commandLine.ToString());
                    }
                }
            }
        }

        public object
        Build(
            Publisher.ProductModule moduleToBuild,
            out bool success)
        {
            var primaryNode = Publisher.ProductModuleUtilities.GetPrimaryNode(moduleToBuild);
            var projectData = primaryNode.Data as IProject;

            foreach (var dependency in primaryNode.ExternalDependents)
            {
                var module = dependency.Module;
                var moduleType = module.GetType();
                var flags = System.Reflection.BindingFlags.Instance |
                            System.Reflection.BindingFlags.NonPublic;
                var fields = moduleType.GetFields(flags);
                foreach (var field in fields)
                {
                    var candidates = field.GetCustomAttributes(typeof(Publisher.PublishModuleDependencyAttribute), false);
                    if (0 == candidates.Length)
                    {
                        continue;
                    }
                    if (candidates.Length > 1)
                    {
                        throw new Opus.Core.Exception("More than one publish module dependency found");
                    }
                    var candidateData = field.GetValue(module) as Opus.Core.Array<Opus.Core.LocationKey>;
                    foreach (var key in candidateData)
                    {
                        CopyNodes(moduleToBuild, projectData, module.OwningNode);
                    }
                }
            }

            success = true;
            return null;
        }
    }
}
{'fraction_non_alphanumeric': 0.07904363731382284, 'fraction_numerical': 0.0014371570420695062, 'mean_word_length': 1.7427445360085991, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 21, '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': '1886713', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1709, 'n_words': 365}