Ejemplo n.º 1
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            var    error = (Error)task;
            string text  = _expressionEngine.EvaluateExpression(error.Text, environment);

            logger.WriteError("  {0}", text);
        }
Ejemplo n.º 2
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            var resolve    = (ResolveAssemblyReference)task;
            var assemblies = _expressionEngine.EvaluateItemList(resolve.Assemblies, environment);

            var rootPath = environment.Properties[Properties.MSBuildProjectDirectory];
            var builder  = new StringBuilder();

            for (int i = 0; i < assemblies.Length; ++i)
            {
                var fileName = ResolveReference(assemblies[i], rootPath);
                if (fileName != null)
                {
                    builder.Append(fileName);
                    builder.Append(Tokenizer.ItemListSeparator);
                }
            }

            if (builder.Length > 0)
            {
                builder.Remove(builder.Length - 1, 1);
            }

            environment.Output["ResolvedFiles"] = builder.ToString();
        }
Ejemplo n.º 3
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            var copy = (Copy)task;

            ProjectItem[] sourceFiles      = _expressionEngine.EvaluateItemList(copy.SourceFiles, environment);
            ProjectItem[] destinationFiles = _expressionEngine.EvaluateItemList(copy.DestinationFiles, environment);

            if (sourceFiles.Length != destinationFiles.Length)
            {
                throw new BuildException(
                          string.Format("SourceFiles and DestinationFiles must be of the same length, but \"{0}\" and \"{1}\" are not",
                                        sourceFiles.Length,
                                        destinationFiles.Length));
            }

            string directory = environment.Properties[Properties.MSBuildProjectDirectory];
            var    copied    = new ProjectItem[sourceFiles.Length];

            for (int i = 0; i < sourceFiles.Length; ++i)
            {
                ProjectItem source      = sourceFiles[i];
                ProjectItem destination = destinationFiles[i];

                if (Copy(directory, source, destination, logger))
                {
                    copied[i] = destination;
                }
            }
        }
Ejemplo n.º 4
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            var t          = (ResolveProjectReference)task;
            var items      = _expressionEngine.EvaluateItemList(t.ProjectReferences, environment);
            var fileNames  = ResolveFileNames(items, environment);
            var projects   = graph.TryGetAll(fileNames);
            var assemblies = ResolveOutputAssemblies(projects);
            var builder    = new StringBuilder();

            for (int i = 0; i < assemblies.Length; ++i)
            {
                var name = assemblies[i];
                if (name != null)
                {
                    builder.Append(name);
                    builder.Append(Tokenizer.ItemListSeparator);
                }
            }

            if (builder.Length != 0)
            {
                builder.Remove(builder.Length - 1, 1);
            }

            environment.Output["ResolvedFiles"] = builder.ToString();
        }
Ejemplo n.º 5
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("environment");
            }
            var warning = (Warning)task;
            var text    = _expressionEngine.EvaluateExpression(warning.Text, environment);

            logger.WriteWarning("  {0}", text);
        }
Ejemplo n.º 6
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("environment");
            }

            var       message   = (Message)task;
            Verbosity verbosity = ImportanceToVerbosity(message.Importance);
            //var text = _expressionEngine.EvaluateExpression(message.Text, environment);
            var text = _expressionEngine.EvaluateConcatenation(message.Text, environment);

            logger.WriteLine(verbosity, "  {0}", text);
        }
        private static IEnumerable <ProjectId> GetProjectsThatThisProjectTransitivelyDependsOn(
            IProjectDependencyGraph graph,
            ProjectId projectId,
            HashSet <ProjectId> result)
        {
            if (result.Add(projectId))
            {
                foreach (var id in graph.GetProjectsThatThisProjectDirectlyDependsOn(projectId))
                {
                    GetProjectsThatThisProjectTransitivelyDependsOn(graph, id, result);
                }
            }

            return(result);
        }
        private static IEnumerable<ProjectId> GetProjectsThatThisProjectTransitivelyDependsOn(
            IProjectDependencyGraph graph,
            ProjectId projectId,
            HashSet<ProjectId> result)
        {
            if (result.Add(projectId))
            {
                foreach (var id in graph.GetProjectsThatThisProjectDirectlyDependsOn(projectId))
                {
                    GetProjectsThatThisProjectTransitivelyDependsOn(graph, id, result);
                }
            }

            return result;
        }
Ejemplo n.º 9
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            var output = (Output)task;

            var taskParameter = _expressionEngine.EvaluateExpression(output.TaskParameter, environment);
            var propertyName  = _expressionEngine.EvaluateExpression(output.PropertyName, environment);

            string value;

            if (!environment.Output.TryGetValue(taskParameter, out value))
            {
                logger.WriteError("TaskParameter \"{0}\" not found", taskParameter);
            }
            else
            {
                environment.Properties[propertyName] = value;
            }
        }
Ejemplo n.º 10
0
        private void Run(BuildEnvironment environment,
                         Node task,
                         IProjectDependencyGraph graph,
                         ILogger logger)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("environment");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            var condition = task.Condition;

            if (condition != null)
            {
                if (!_expressionEngine.EvaluateCondition(condition, environment))
                {
                    logger.WriteLine(Verbosity.Diagnostic, "  Skipping task \"{0}\" because {1} does not evaluate to true",
                                     task.GetType().Name,
                                     condition);
                    return;
                }
            }

            ITaskRunner taskRunner;

            if (!_taskRunners.TryGetValue(task.GetType(), out taskRunner))
            {
                throw new BuildException(string.Format("Unknown task: {0}", task.GetType()));
            }

            taskRunner.Run(environment, task, graph, logger);
        }
Ejemplo n.º 11
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            var delete = (Delete)task;

            ProjectItem[] files = _expressionEngine.EvaluateItemList(delete.Files, environment);

            string directory = environment.Properties[Properties.MSBuildProjectDirectory];
            var    deleted   = new ProjectItem[files.Length];

            for (int i = 0; i < files.Length; ++i)
            {
                ProjectItem file = files[i];

                if (Delete(directory, file, logger))
                {
                    deleted[i] = file;
                }
            }
        }
Ejemplo n.º 12
0
        private void Run(BuildEnvironment environment,
                         Target target,
                         IProjectDependencyGraph graph,
                         ILogger logger)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (target.Condition != null)
            {
                if (!_expressionEngine.EvaluateCondition(target.Condition, environment))
                {
                    logger.WriteLine(Verbosity.Normal, "  Skipping target \"{0}\" because {1} does not evaluate to true",
                                     target.Name,
                                     target.Condition);
                    return;
                }
            }

            target.Inputs = _expressionEngine.EvaluateConcatenation(target.Inputs, environment);
            target.Output = _expressionEngine.EvaluateConcatenation(target.Output, environment);
            if (IsUpToDate(environment, target))
            {
                logger.WriteLine(Verbosity.Normal,
                                 "  Skipping target \"{0}\" because it's inputs are up-to-date with respect to its outputs",
                                 target.Name);
            }

            logger.WriteLine(Verbosity.Normal, "{0}:", target.Name);

            foreach (var node in target.Children)
            {
                Run(environment, node, graph, logger);

                if (logger.HasErrors)
                {
                    break;
                }
            }
        }
Ejemplo n.º 13
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            var csc       = (Csc)task;
            var arguments = new ArgumentBuilder();

            BuildCommandLineArguments(environment, csc, arguments);

            logger.WriteLine(Verbosity.Normal, "  {0} {1}", CompilerPath, arguments);

            CreateDirectories(environment, csc);

            var    rootPath = environment.Properties[Properties.MSBuildProjectDirectory];
            string output;
            var    exitCode = ProcessEx.Run(CompilerPath, rootPath, arguments, out output);

            logger.WriteMultiLine(Verbosity.Minimal, output, interpretLines: true);

            if (exitCode != 0)
            {
                throw new BuildException(string.Format("csc returned {0}", exitCode));
            }
        }
Ejemplo n.º 14
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            var csc         = (Csc)task;
            var compilation = Compile(environment, csc);

            var outputAssembly       = GetOutputAssembly(environment, csc);
            var rootPath             = environment.Properties[Properties.MSBuildProjectDirectory];
            var fullAssemblyFileName = Path.MakeAbsolute(rootPath, outputAssembly);
            var pdbName         = string.Format("{0}.pdb", Path.GetFilenameWithoutExtension(outputAssembly));
            var outputPdb       = Path.Combine(Path.GetDirectory(outputAssembly), pdbName);
            var fullPdbFileName = Path.MakeAbsolute(rootPath, outputPdb);

            var manifestResources = GetManifestResources(environment, csc);

            var directory = Path.GetDirectory(fullAssemblyFileName);

            _fileSystem.CreateDirectory(directory);

            using (var assemblyStream = new MemoryStream())
                using (var pdbStream = new MemoryStream())
                {
                    var result = compilation.Emit(assemblyStream, pdbStream, manifestResources: manifestResources);
                    if (!result.Success)
                    {
                        foreach (var diagnostic in result.Diagnostics)
                        {
                            logger.WriteMultiLine(Verbosity.Minimal, diagnostic.ToString(), true);
                        }

                        throw new BuildException("csc returned: -1");
                    }

                    assemblyStream.Position = 0;
                    _fileSystem.WriteAllStream(fullAssemblyFileName, assemblyStream);
                    pdbStream.Position = 0;
                    _fileSystem.WriteAllStream(fullPdbFileName, pdbStream);
                }
        }
 /// <summary>
 /// Gets the list of projects that this project transitively depends on.
 /// </summary>
 public static IEnumerable <ProjectId> GetProjectsThatThisProjectTransitivelyDependsOn(
     this IProjectDependencyGraph graph,
     ProjectId projectId)
 {
     return(GetProjectsThatThisProjectTransitivelyDependsOn(graph, projectId, new HashSet <ProjectId>()));
 }
Ejemplo n.º 16
0
        public void Run(Project project,
                        string target,
                        BuildEnvironment environment,
                        IProjectDependencyGraph graph,
                        ILogger logger)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (environment == null)
            {
                throw new ArgumentNullException("environment");
            }
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            logger.WriteLine(Verbosity.Quiet, "------ {0} started: Project: {1}, Configuration: {2} {3} ------",
                             target,
                             environment.Properties[Properties.MSBuildProjectName],
                             environment.Properties[Properties.Configuration],
                             environment.Properties[Properties.PlatformTarget]
                             );

            var started = DateTime.Now;

            logger.WriteLine(Verbosity.Normal, "Build started {0}.", started);


            var availableTargets = new Dictionary <string, Target>(project.Targets.Count);

            foreach (var t in project.Targets)
            {
                availableTargets.Add(t.Name, t);
            }

            var executedTargets = new HashSet <Target>();
            var pendingTargets  = new TargetStack();
            var targets         = TryFindTargets(environment, logger, availableTargets, target);

            targets.Reverse();
            foreach (var pendingTarget in targets)
            {
                if (pendingTarget != null)
                {
                    pendingTargets.Push(pendingTarget);
                }
            }

            while (pendingTargets.Count > 0)
            {
                var targetToBeExecuted = pendingTargets.Peek();
                var dependingTargets   = TryFindTargets(environment, logger, availableTargets,
                                                        targetToBeExecuted.DependsOnTargets);
                var requirementsSatisfied = true;
                foreach (var dependency in dependingTargets)
                {
                    if (!executedTargets.Contains(dependency))
                    {
                        pendingTargets.TryPush(dependency);
                        requirementsSatisfied = false;
                        break;
                    }
                }

                if (requirementsSatisfied)
                {
                    pendingTargets.Pop();

                    Run(environment, targetToBeExecuted, graph, logger);
                    if (logger.HasErrors)
                    {
                        break;
                    }

                    executedTargets.Add(targetToBeExecuted);
                }
            }


            logger.WriteLine(Verbosity.Normal, "{0} succeeded.", target);
            var elapsed = DateTime.Now - started;

            logger.WriteLine(Verbosity.Minimal, "Time Elapsed {0}", elapsed);
        }
Ejemplo n.º 17
0
 public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
 {
     var exec = (Exec)task;
 }
Ejemplo n.º 18
0
        public void Run(BuildEnvironment environment, Node task, IProjectDependencyGraph graph, ILogger logger)
        {
            var group = (PropertyGroup)task;

            _expressionEngine.Evaluate(group, environment);
        }