Beispiel #1
0
        private void RunBuild(FileInfo buildFile)
        {
            Log(Level.Info, "{0} {1}", buildFile.FullName, DefaultTarget);

            // create new project with same threshold as current project and
            // increased indentation level, and initialize it using the same
            // configuration node
            Project project = new Project(buildFile.FullName, Project);

            // have the new project inherit properties from the current project
            if (InheritAll)
            {
                StringCollection excludes = new StringCollection();
                excludes.Add(Project.NAntPropertyFileName);
                excludes.Add(Project.NAntPropertyLocation);
                excludes.Add(Project.NAntPropertyOnSuccess);
                excludes.Add(Project.NAntPropertyOnFailure);
                excludes.Add(Project.NAntPropertyProjectBaseDir);
                excludes.Add(Project.NAntPropertyProjectBuildFile);
                excludes.Add(Project.NAntPropertyProjectDefault);
                excludes.Add(Project.NAntPropertyProjectName);
                excludes.Add(Project.NAntPropertyVersion);
                this.PropertyAccessor.MergeInto(project, excludes);
            }

            // add/overwrite properties
            foreach (PropertyTask property in OverrideProperties)
            {
                // expand properties in context of current project for non-dynamic
                // properties
                if (!property.Dynamic)
                {
                    property.Value = this.PropertyAccessor.ExpandProperties(property.Value, Location);
                }
                property.Project   = project;
                property.CallStack = this.CallStack;
                property.Execute();
            }

            if (InheritRefs)
            {
                // pass datatypes thru to the child project
                project.DataTypeReferences.Inherit(Project.DataTypeReferences);
            }

            // handle multiple targets
            if (DefaultTarget != null)
            {
                foreach (string t in DefaultTarget.Split(' '))
                {
                    string target = t.Trim();
                    if (target.Length > 0)
                    {
                        project.BuildTargets.Add(target);
                    }
                }
            }

            Project.ProjectRunResult result;
            if (this.InheritAll)
            {
                result = project.Run(this.CallStack.Clone() as TargetCallStack);
            }
            else
            {
                result = project.Run(project.RootTargetCallStack);
            }

            // run the given build
            if (!result.Success)
            {
                throw new BuildException(string.Concat("Nested build failed: ", result.Exception.Message), result.Exception);
            }
        }
Beispiel #2
0
        private void RunBuild(FileInfo buildFile)
        {
            Log(Level.Info, "{0} {1}", buildFile.FullName, DefaultTarget);

            // create new project with same threshold as current project and
            // increased indentation level, and initialize it using the same
            // configuration node
            Project project = new Project(buildFile.FullName, Project.Threshold,
                                          Project.IndentationLevel + 1, Project.ConfigurationNode);

            // add listeners of current project to new project
            project.AttachBuildListeners(Project.BuildListeners);

            // have the new project inherit the runtime framework from the
            // current project
            if (Project.RuntimeFramework != null && project.Frameworks.Contains(Project.RuntimeFramework.Name))
            {
                project.RuntimeFramework = project.Frameworks[Project.RuntimeFramework.Name];
            }

            // have the new project inherit the current framework from the
            // current project
            if (Project.TargetFramework != null && project.Frameworks.Contains(Project.TargetFramework.Name))
            {
                project.TargetFramework = project.Frameworks[Project.TargetFramework.Name];
            }

            // have the new project inherit properties from the current project
            if (InheritAll)
            {
                StringCollection excludes = new StringCollection();
                excludes.Add(Project.NAntPropertyFileName);
                excludes.Add(Project.NAntPropertyLocation);
                excludes.Add(Project.NAntPropertyOnSuccess);
                excludes.Add(Project.NAntPropertyOnFailure);
                excludes.Add(Project.NAntPropertyProjectBaseDir);
                excludes.Add(Project.NAntPropertyProjectBuildFile);
                excludes.Add(Project.NAntPropertyProjectDefault);
                excludes.Add(Project.NAntPropertyProjectName);
                excludes.Add(Project.NAntPropertyVersion);
                project.Properties.Inherit(Properties, excludes);
            }

            // add/overwrite properties
            foreach (PropertyTask property in OverrideProperties)
            {
                // expand properties in context of current project for non-dynamic
                // properties
                if (!property.Dynamic)
                {
                    property.Value = Project.ExpandProperties(property.Value, Location);
                }
                property.Project = project;
                property.Execute();
            }

            if (InheritRefs)
            {
                // pass datatypes thru to the child project
                project.DataTypeReferences.Inherit(Project.DataTypeReferences);
            }

            // handle multiple targets
            if (DefaultTarget != null)
            {
                foreach (string t in DefaultTarget.Split(' '))
                {
                    string target = t.Trim();
                    if (target.Length > 0)
                    {
                        project.BuildTargets.Add(target);
                    }
                }
            }

            // run the given build
            if (!project.Run())
            {
                throw new BuildException("Nested build failed.  Refer to build log for exact reason.");
            }
        }