ExpandProperties() public method

Expands a string from known properties.
public ExpandProperties ( string input, Location location ) : string
input string The with replacement tokens.
location Location The location in the build file. Used to throw more accurate exceptions.
return string
コード例 #1
0
ファイル: ProjectTest.cs プロジェクト: RoastBoy/nant
        public void Test_Initialization_FSBuildFile() {
            // create the build file in the temp folder
            TempFile.CreateWithContents(FormatBuildFile("", ""), _buildFileName);

            Project p = new Project(_buildFileName, Level.Error, 0);

            Assert.IsNotNull(p.Properties["nant.version"], "Property ('nant.version') not defined.");
            Assert.IsNotNull(p.Properties["nant.location"], "Property ('nant.location') not defined.");

            Assert.AreEqual(new Uri(_buildFileName), p.Properties["nant.project.buildfile"]);
            Assert.AreEqual(TempDirName, p.Properties["nant.project.basedir"]);
            Assert.AreEqual("test", p.Properties["nant.project.default"]);

            CheckCommon(p);

            Assert.AreEqual("The value is " + Boolean.TrueString + ".", p.ExpandProperties("The value is ${task::exists('fail')}.", null));
        }
コード例 #2
0
 private static void TryExpandingProperty(Project project, IBuildProperty property)
 {
     try
     {
         property.DefaultExpandedValue =
             property.ExpandedValue =
             project.ExpandProperties(property.Value, new Location("Buildfile"));
     }
     catch (BuildException)
     {
         // TODO: Do something with the error message
     }
 }
コード例 #3
0
        private void FollowIncludes(Project project, XmlDocument doc)
        {
            foreach (XmlElement element in doc.GetElementsByTagName("include"))
            {
                string buildFile = element.GetAttribute("buildfile");
                string filename = project.ExpandProperties(buildFile, new Location("Buildfile"));

                ParseIncludeFile(project, filename);
            }
        }
コード例 #4
0
        /// <summary>
        /// Processes the framework nodes of the given platform node.
        /// </summary>
        /// <param name="platformNode">An <see cref="XmlNode" /> representing the platform on which NAnt is running.</param>
        private void ProcessFrameworks(XmlNode platformNode)
        {
            // determine the framework family name
            string frameworkFamily = PlatformHelper.IsMono ? "mono" : "net";
            // determine the version of the current runtime framework
            string frameworkClrVersion = Environment.Version.ToString(3);
            // determine default targetframework
            string defaultTargetFramework = GetXmlAttributeValue(platformNode, "default");

            // deals with xml info from the config file, not build document.
            foreach (XmlNode frameworkNode in platformNode.SelectNodes("nant:framework", NamespaceManager)) {
                // skip special elements like comments, pis, text, etc.
                if (!(frameworkNode.NodeType == XmlNodeType.Element)) {
                    continue;
                }

                string name = null;
                bool isRuntimeFramework = false;

                try {
                    // get framework attributes
                    name = GetXmlAttributeValue(frameworkNode, "name");

                    string family = GetXmlAttributeValue(frameworkNode, "family");
                    string clrVersion = GetXmlAttributeValue(frameworkNode, "clrversion");

                    // check if we're processing the current runtime framework
                    if (family == frameworkFamily && clrVersion == frameworkClrVersion) {
                        isRuntimeFramework = true;
                    }

                    // get framework-specific project node
                    XmlNode projectNode = frameworkNode.SelectSingleNode("nant:project",
                        NamespaceManager);

                    if (projectNode == null) {
                        throw new BuildException("<project> node has not been defined.");
                    }

                    string tempBuildFile = Path.GetTempFileName();
                    XmlTextWriter writer = null;
                    Project frameworkProject = null;

                    try {
                        // write project to file
                        writer = new XmlTextWriter(tempBuildFile, Encoding.UTF8);
                        writer.WriteStartDocument(true);
                        writer.WriteRaw(projectNode.OuterXml);
                        writer.Flush();
                        writer.Close();

                        // use StreamReader to load build file from to avoid
                        // having location information as part of the error
                        // messages
                        using (StreamReader sr = new StreamReader(new FileStream(tempBuildFile, FileMode.Open, FileAccess.Read, FileShare.Write), Encoding.UTF8)) {
                            XmlDocument projectDoc = new XmlDocument();
                            projectDoc.Load(sr);

                            // create and execute project
                            frameworkProject = new Project(projectDoc, Level.None, 0, (XmlNode) null);
                            frameworkProject.BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
                            frameworkProject.Execute();
                        }
                    } finally {
                        if (writer != null) {
                            writer.Close();
                        }

                        if (File.Exists(tempBuildFile)) {
                            File.Delete(tempBuildFile);
                        }
                    }

                    string description = frameworkProject.ExpandProperties(
                        GetXmlAttributeValue(frameworkNode, "description"),
                        Location.UnknownLocation);
                    string version = frameworkProject.ExpandProperties(
                        GetXmlAttributeValue(frameworkNode, "version"),
                        Location.UnknownLocation);
                    string runtimeEngine = frameworkProject.ExpandProperties(
                        GetXmlAttributeValue(frameworkNode, "runtimeengine"),
                        Location.UnknownLocation);
                    string frameworkDir = frameworkProject.ExpandProperties(
                        GetXmlAttributeValue(frameworkNode, "frameworkdirectory"),
                        Location.UnknownLocation);
                    string frameworkAssemblyDir = frameworkProject.ExpandProperties(
                        GetXmlAttributeValue(frameworkNode, "frameworkassemblydirectory"),
                        Location.UnknownLocation);
                    string sdkDir = GetXmlAttributeValue(frameworkNode, "sdkdirectory");

                    try {
                        sdkDir = frameworkProject.ExpandProperties(sdkDir,
                            Location.UnknownLocation);
                    } catch (BuildException) {
                        // do nothing with this exception as a framework is still
                        // considered valid if the sdk directory is not available
                        // or not configured correctly
                    }

                    // create new FrameworkInfo instance, this will throw an
                    // an exception if the framework is not valid
                    FrameworkInfo info = new FrameworkInfo(name,
                        family,
                        description,
                        new Version(version),
                        new Version(clrVersion),
                        frameworkDir,
                        sdkDir,
                        frameworkAssemblyDir,
                        runtimeEngine,
                        frameworkProject);

                    // get framework-specific environment nodes
                    XmlNodeList environmentNodes = frameworkNode.SelectNodes("nant:environment/nant:env",
                        NamespaceManager);

                    // process framework environment nodes
                    info.EnvironmentVariables = ProcessFrameworkEnvironmentVariables(
                        environmentNodes, info);

                    // process framework task assemblies
                    info.TaskAssemblies.Project = frameworkProject;
                    info.TaskAssemblies.NamespaceManager = NamespaceManager;
                    info.TaskAssemblies.Parent = frameworkProject; // avoid warnings by setting the parent of the fileset
                    info.TaskAssemblies.ID = "internal-task-assemblies"; // avoid warnings by assigning an id
                    XmlNode taskAssembliesNode = frameworkNode.SelectSingleNode(
                        "nant:task-assemblies", NamespaceManager);
                    if (taskAssembliesNode != null) {
                        info.TaskAssemblies.Initialize(taskAssembliesNode,
                            frameworkProject.Properties, info);
                    }

                    // framework is valid, so add it to framework dictionary
                    Project.Frameworks.Add(info.Name, info);

                    if (isRuntimeFramework) {
                        // framework matches current runtime, so set it as
                        // current target framework
                        Project.RuntimeFramework = Project.TargetFramework = info;
                    }
                } catch (Exception ex) {
                    if (isRuntimeFramework) {
                        // current runtime framework is not correctly configured
                        // in NAnt configuration file
                        throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                            ResourceUtils.GetString("NA1063"),
                            name), ex);
                    } else {
                        if (name != null && name == defaultTargetFramework) {
                            Project.Log(Level.Warning, ResourceUtils.GetString("NA1181"), name, ex.Message);
                            Project.Log(Level.Debug, ex.ToString());
                            Project.Log(Level.Warning, "");
                        } else {
                            Project.Log(Level.Verbose, ResourceUtils.GetString("NA1182"), name, ex.Message);
                            Project.Log(Level.Debug, ex.ToString());
                            Project.Log(Level.Verbose, "");
                        }
                    }
                }
            }

            if (Project.RuntimeFramework == null) {
                // information about the current runtime framework should
                // be added to the NAnt configuration file
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    ResourceUtils.GetString("NA1062"), frameworkFamily, frameworkClrVersion));
            }

            if (defaultTargetFramework != null && defaultTargetFramework != "auto") {
                if (Project.Frameworks.ContainsKey(defaultTargetFramework)) {
                    Project.TargetFramework = Project.Frameworks[defaultTargetFramework];
                } else {
                    Project.Log(Level.Warning, ResourceUtils.GetString("NA1178"), defaultTargetFramework, Project.RuntimeFramework.Name);
                    Project.Log(Level.Warning, "");
                }
            }
        }
コード例 #5
0
ファイル: FrameworkInfo.cs プロジェクト: mwbowers/nant
        private void PerformInit()
        {
            // get framework-specific project node
            XmlNode projectNode = _frameworkNode.SelectSingleNode("nant:project",
                NamespaceManager);

            if (projectNode == null)
                throw new ArgumentException("No <project> node is defined.");

            // create XmlDocument from project node
            XmlDocument projectDoc = new XmlDocument();
            projectDoc.LoadXml(projectNode.OuterXml);

            // create and execute project
            Project frameworkProject = new Project(projectDoc);
            frameworkProject.BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            frameworkProject.Execute();

            XmlNode runtimeNode = _frameworkNode.SelectSingleNode ("runtime",
                NamespaceManager);
            if (runtimeNode != null) {
                _runtime = new Runtime ();
                _runtime.Parent = _runtime.Project = frameworkProject;
                _runtime.NamespaceManager = NamespaceManager;
                _runtime.Initialize(runtimeNode, frameworkProject.Properties, this);
            }

            string sdkDir = GetXmlAttributeValue(_frameworkNode, "sdkdirectory");
            try {
                sdkDir = frameworkProject.ExpandProperties(sdkDir,
                    Location.UnknownLocation);
            } catch (BuildException) {
                // do nothing with this exception as a framework is still
                // considered valid if the sdk directory is not available
                // or not configured correctly
            }

            // the sdk directory does not actually have to exist for a
            // framework to be considered valid
            if (sdkDir != null && Directory.Exists(sdkDir))
                _sdkDirectory = new DirectoryInfo(sdkDir);

            _project = frameworkProject;
            _status = InitStatus.Initialized;
        }
コード例 #6
0
ファイル: ProjectTest.cs プロジェクト: RoastBoy/nant
        public void Test_Initialization_DOMBuildFile() {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(FormatBuildFile("", ""));
            Project p = new Project(doc, Level.Error, 0);

            Assert.IsNotNull(p.Properties["nant.version"], "Property not defined.");
            Assert.IsNull(p.Properties["nant.project.buildfile"], "location of buildfile should not exist!");
            Assert.IsNotNull(p.Properties["nant.project.basedir"], "nant.project.basedir should not be null");
            Assert.AreEqual(TempDirName, p.Properties["nant.project.basedir"]);
            Assert.AreEqual("test", p.Properties["nant.project.default"]);

            CheckCommon(p);

            Assert.AreEqual("The value is " + Boolean.TrueString + ".", p.ExpandProperties("The value is ${task::exists('fail')}.", null));
        }
コード例 #7
0
ファイル: ProjectTest.cs プロジェクト: RoastBoy/nant
 private bool TaskExists (Project p, string taskName) {
     string val = p.ExpandProperties("${task::exists('" + taskName + "')}", 
         Location.UnknownLocation);
     return val == Boolean.TrueString;
 }
コード例 #8
0
        /// START: TO BE REMOVED
        void GatherModuleDpdFromCustmizedSlnMaker(Project proj, string config, string group, XmlNode xmlNode, ref string needRunCrossConfig)
        {
            string projName = proj.Properties["package.name"];
            XmlAttribute pathAttribute, nameAttribute, modulesAttribute, groupAttribute;
            XmlNodeList nodeList = xmlNode.SelectNodes("./project");
            for (int i = 0; i < nodeList.Count; i++)
            {
                if (!GetConditionAttribute(nodeList.Item(i), "project")) continue;

                pathAttribute = nodeList.Item(i).Attributes["path"];
                nameAttribute = nodeList.Item(i).Attributes["name"];
                modulesAttribute = nodeList.Item(i).Attributes["modules"];
                groupAttribute = nodeList.Item(i).Attributes["group"];
                if (groupAttribute == null && pathAttribute == null)
                {
                    if (modulesAttribute != null)
                    {
                        string bm = "";
                        if (nameAttribute == null || (nameAttribute != null && nameAttribute.InnerText == projName))
                        {
                            bm = proj.ExpandProperties(modulesAttribute.InnerText);
                        }
                        if (bm != "")
                        {
                            XmlAttribute pathDepAttribute, nameDepAttribute, modulesDepAttribute;
                            XmlNodeList oNodeListDep = nodeList.Item(i).SelectNodes("./depends");
                            // we assume all dependent modules belong to the group ${group}
                            string crossmoduledependentlist = "";
                            string nativemoduledependentlist = "";
                            for (int j = 0; j < oNodeListDep.Count; j++)
                            {
                                pathDepAttribute = oNodeListDep.Item(j).Attributes["path"];
                                nameDepAttribute = oNodeListDep.Item(j).Attributes["name"];
                                modulesDepAttribute = oNodeListDep.Item(j).Attributes["modules"];
                                if (pathDepAttribute == null && nameDepAttribute == null && modulesDepAttribute != null)
                                {
                                    foreach (string dpm in NantToVSTools.TrimAndSplit(proj.ExpandProperties(modulesDepAttribute.InnerText)))
                                    {
                                        if (dpm == string.Empty) continue;
                                        if (dpm.StartsWith("cross-")) // if found a cross dependent module
                                            crossmoduledependentlist = crossmoduledependentlist + " " + dpm;
                                        else
                                            nativemoduledependentlist = nativemoduledependentlist + " " + dpm;
                                    }
                                }
                            }
                            if (crossmoduledependentlist != "")
                            {
                                needRunCrossConfig = "true";
                                foreach (string item in NantToVSTools.TrimAndSplit(bm))
                                {
                                    if (item == string.Empty) continue;
                                    string crossConfig = proj.Properties["config-cross"] + "-" + proj.Properties["config-name"];
                                    if (item.StartsWith("cross"))
                                    {
                                        string constrainProperty = projName + "." + group + ".buildmodules";
                                        if (_properties.Contains(constrainProperty + "." + config))
                                        {
                                            string existingModules = (string)_properties[constrainProperty + "." + config];
                                            if (existingModules != "") // if it's empty, then it means it depends on everything
                                            {
                                                _properties[constrainProperty + "." + config] = CombineStrings(existingModules, crossmoduledependentlist);
                                            }
                                        }
                                        else
                                        {
                                            _properties[constrainProperty + "." + config] = crossmoduledependentlist;
                                        }
                                    }
                                    else
                                    {
                                        // we assume in customized slnmaker only [example|tool|test] modules dependencies, no inter-group module dependenices except depending on 'runtime'
                                        if (_native2crossmoduledependencies.Contains(projName + "." + group + ".buildmodules." + config + ".md." + item))
                                        {
                                            _native2crossmoduledependencies[projName + "." + group + ".buildmodules." + config + ".md." + item] =
                                                ((string)_native2crossmoduledependencies[projName + "." + group + ".buildmodules." + config + ".md." + item]) + " " + crossmoduledependentlist;
                                        }
                                        else
                                            _native2crossmoduledependencies.Add(projName + "." + group + ".buildmodules." + config + ".md." + item, crossConfig + "." + group + "." + crossmoduledependentlist);
                                    }
                                }
                            }
                            if (nativemoduledependentlist != "") // this is only true when we have native [example|test|tool] module dependencies in customized slnmaker
                            {
                                if (config.IndexOf("cross") != -1)
                                    Console.WriteLine("WARNING: Cross2Native module dependency found! " + bm + " depend(s) on " + nativemoduledependentlist);
                                string constrainProperty = projName + "." + group + ".buildmodules";
                                if (_properties.Contains(constrainProperty + "." + config))
                                {
                                    string existingModules = (string)_properties[constrainProperty + "." + config];
                                    if (existingModules != "") // if it's empty, then it means it depends on everything
                                    {
                                        _properties[constrainProperty + "." + config] = CombineStrings(existingModules, nativemoduledependentlist);
                                    }
                                }
                                else
                                {
                                    _properties[constrainProperty + "." + config] = nativemoduledependentlist;
                                }
                            }
                        }
                    }
                }
            }
        }