public ExpressionEvaluator(Project project, PropertyDictionary properties, Hashtable state, Stack visiting) { _project = project; _properties = properties; _state = state; _visiting = visiting; }
protected FunctionSetBase(Project project, PropertyDictionary properties) { _project = project; }
/// <summary> /// Inits stuff: /// <para>TypeFactory: Calls Initialize and AddProject </para> /// <para>Log.IndentSize set to 12</para> /// <para>Project properties are initialized ("ciscript.* stuff set")</para> /// <list type="ciscript.items"> /// <listheader>CIScript Props:</listheader> /// <item>ciscript.filename</item> /// <item>ciscript.version</item> /// <item>ciscript.location</item> /// <item>ciscript.project.name</item> /// <item>ciscript.project.buildfile (if doc has baseuri)</item> /// <item>ciscript.project.basedir</item> /// <item>ciscript.project.default = defaultTarget</item> /// <item>ciscript.tasks.[name] = true</item> /// <item>ciscript.tasks.[name].location = AssemblyFileName</item> /// </list> /// </summary> /// <param name="doc">An <see cref="XmlDocument" /> representing the project definition.</param> /// <param name="threshold">The project message threshold.</param> /// <param name="indentLevel">The project indentation level.</param> /// <exception cref="ArgumentNullException"><paramref name="doc" /> is <see langword="null" />.</exception> protected void CtorHelper(XmlDocument doc, Level threshold, int indentLevel) { if (doc == null) { throw new ArgumentNullException("doc"); } string newBaseDir = null; _properties = new PropertyDictionary(this); _frameworkNeutralProperties = new PropertyDictionary(this); // set the project definition _doc = doc; // set the indentation size of the build output _indentationSize = 12; // set the indentation level of the build output _indentationLevel = indentLevel; // set the project message threshold Threshold = threshold; // load project-level extensions assemblies TypeFactory.AddProject(this); // add default logger CreateDefaultLogger(); // configure platform properties ConfigurePlatformProperties(); // fill the namespace manager up, so we can make qualified xpath // expressions if (StringUtils.IsNullOrEmpty(doc.DocumentElement.NamespaceURI)) { string defURI; if (doc.DocumentElement.Attributes["xmlns", "ciscript"] == null) { defURI = @"http://none"; } else { defURI = doc.DocumentElement.Attributes["xmlns", "ciscript"].Value; } XmlAttribute attr = doc.CreateAttribute("xmlns"); attr.Value = defURI; doc.DocumentElement.Attributes.Append(attr); } NamespaceManager.AddNamespace("ciscript", doc.DocumentElement.NamespaceURI); // check to make sure that the root element in named correctly if (!doc.DocumentElement.LocalName.Equals(RootXml)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1059"), doc.BaseURI, RootXml)); } // get project attributes if (doc.DocumentElement.HasAttribute(ProjectNameAttribute)) { _projectName = doc.DocumentElement.GetAttribute(ProjectNameAttribute); } if (doc.DocumentElement.HasAttribute(ProjectBaseDirAttribute)) { newBaseDir = doc.DocumentElement.GetAttribute(ProjectBaseDirAttribute); } if (doc.DocumentElement.HasAttribute(ProjectDefaultAttribte)) { _defaultTargetName = doc.DocumentElement.GetAttribute(ProjectDefaultAttribte); } // give the project a meaningful base directory if (StringUtils.IsNullOrEmpty(newBaseDir)) { if (!StringUtils.IsNullOrEmpty(BuildFileLocalName)) { newBaseDir = Path.GetDirectoryName(BuildFileLocalName); } else { newBaseDir = Environment.CurrentDirectory; } } else { // if basedir attribute is set to a relative path, then resolve // it relative to the build file path if (!StringUtils.IsNullOrEmpty(BuildFileLocalName) && !Path.IsPathRooted(newBaseDir)) { newBaseDir = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(BuildFileLocalName), newBaseDir)); } } newBaseDir = Path.GetFullPath(newBaseDir); // base directory must be rooted. BaseDirectory = newBaseDir; // load settings out of settings file ProjectSettingsLoader psl = new ProjectSettingsLoader(this); psl.ProcessSettings(); // set here and in ciscript:Main Assembly ass = Assembly.GetExecutingAssembly(); // TO-DO: remove these built-in properties after CIScript 0.87 (?) // as these have been deprecated since CIScript 0.85 Properties.AddReadOnly(CIScriptPropertyFileName, ass.CodeBase); Properties.AddReadOnly(CIScriptPropertyVersion, ass.GetName().Version.ToString()); Properties.AddReadOnly(CIScriptPropertyLocation, AppDomain.CurrentDomain.BaseDirectory); Properties.AddReadOnly(CIScriptPropertyProjectName, ProjectName); if (BuildFileUri != null) { Properties.AddReadOnly(CIScriptPropertyProjectBuildFile, BuildFileUri.ToString()); } Properties.AddReadOnly(CIScriptPropertyProjectDefault, StringUtils.ConvertNullToEmpty(DefaultTargetName)); }
/// <summary> /// Initializes a new instance of the <see cref="AttributeConfigurator" /> /// class for the given <see cref="Element" />. /// </summary> /// <param name="element">The <see cref="Element" /> for which an <see cref="AttributeConfigurator" /> should be created.</param> /// <param name="elementNode">The <see cref="XmlNode" /> to initialize the <see cref="Element" /> with.</param> /// <param name="properties">The <see cref="PropertyDictionary" /> to use for property expansion.</param> /// <param name="targetFramework">The framework that the <see cref="Element" /> should target.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="element" /> is <see langword="null" />.</para> /// <para>-or-</para> /// <para><paramref name="elementNode" /> is <see langword="null" />.</para> /// <para>-or-</para> /// <para><paramref name="properties" /> is <see langword="null" />.</para> /// </exception> public AttributeConfigurator(Element element, XmlNode elementNode, PropertyDictionary properties) { if (element == null) { throw new ArgumentNullException("element"); } if (elementNode == null) { throw new ArgumentNullException("elementNode"); } if (properties == null) { throw new ArgumentNullException("properties"); } _element = element; _elementXml = elementNode; _properties = properties; // collect a list of attributes, we will check to see if we use them all. _unprocessedAttributes = new StringCollection(); foreach (XmlAttribute attribute in elementNode.Attributes) { _unprocessedAttributes.Add(attribute.Name); } // create collection of node names _unprocessedChildNodes = new StringCollection(); foreach (XmlNode childNode in elementNode) { // skip non-ciscript namespace elements and special elements like comments, pis, text, etc. if (!(childNode.NodeType == XmlNodeType.Element) || !childNode.NamespaceURI.Equals(NamespaceManager.LookupNamespace("ciscript"))) { continue; } // skip existing names as we only need unique names. if (_unprocessedChildNodes.Contains(childNode.Name)) { continue; } _unprocessedChildNodes.Add(childNode.Name); } }
/// <summary> /// Initializes all build attributes and child elements. /// </summary> protected virtual void InitializeXml(XmlNode elementNode, PropertyDictionary properties) { _xmlNode = elementNode; AttributeConfigurator configurator = new AttributeConfigurator( this, elementNode, properties); configurator.Initialize(); }
/// <summary> /// Performs initialization using the given set of properties. /// </summary> internal void Initialize(XmlNode elementNode, PropertyDictionary properties) { if (Project == null) { throw new InvalidOperationException("Element has invalid Project property."); } // save position in buildfile for reporting useful error messages. try { _location = Project.LocationMap.GetLocation(elementNode); } catch (ArgumentException ex) { logger.Warn("Location of Element node could be located.", ex); } InitializeXml(elementNode, properties); // allow inherited classes a chance to do some custom initialization InitializeElement(elementNode); }
/// <summary> /// Creates a child <see cref="Element" /> using property set/get methods. /// </summary> /// <param name="propInf">The <see cref="PropertyInfo" /> instance that represents the property of the current class.</param> /// <param name="xml">The <see cref="XmlNode" /> used to initialize the new <see cref="Element" /> instance.</param> /// <param name="properties">The collection of property values to use for macro expansion.</param> /// <param name="framework">The <see cref="FrameworkInfo" /> from which to obtain framework-specific information.</param> /// <returns>The <see cref="Element" /> child.</returns> private Element CreateChildBuildElement(PropertyInfo propInf, XmlNode xml, PropertyDictionary properties) { MethodInfo getter = null; MethodInfo setter = null; Element childElement = null; Type elementType = null; setter = propInf.GetSetMethod(true); getter = propInf.GetGetMethod(true); // if there is a getter, then get the current instance of the object, and use that if (getter != null) { try { childElement = (Element) propInf.GetValue(Element, null); } catch (InvalidCastException) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Property \"{0}\" for class \"{1}\" is backed by" + " \"{2}\" which does not derive from \"{3}\".", propInf.Name, Element.GetType().FullName, propInf.PropertyType.FullName, typeof(Element).FullName), Location); } if (childElement == null) { if (setter == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Property {0} cannot return null (if there is" + " no set method) for class {1}", propInf.Name, Element.GetType().FullName), Location); } else { // fake the getter as null so we process the rest like there is no getter getter = null; logger.Info(string.Format(CultureInfo.InvariantCulture,"{0}_get() returned null; will go the route of set method to populate.", propInf.Name)); } } else { elementType = childElement.GetType(); } } // create a new instance of the object if there is not a get method. (or the get object returned null... see above) if (getter == null && setter != null) { elementType = setter.GetParameters()[0].ParameterType; if (elementType.IsAbstract) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Abstract type: {0} for {2}.{1}", elementType.Name, propInf.Name, Name)); } childElement = (Element) Activator.CreateInstance(elementType, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, null , CultureInfo.InvariantCulture); } // initialize the child element childElement = Element.InitializeBuildElement(Element, xml, childElement, elementType); // check if we're dealing with a reference to a data type DataTypeBase dataType = childElement as DataTypeBase; if (dataType != null && xml.Attributes["refid"] != null) { // references to data type should be always be set if (setter == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "DataType child element '{0}' in class '{1}' must define a set method.", propInf.Name, Element.GetType().FullName), Location); } // re-set the getter (for force the setter to be used) getter = null; } // call the set method if we created the object if (setter != null && getter == null) { setter.Invoke(Element, new object[] {childElement}); } // return the new/used object return childElement; }
/// <summary> /// Inherits properties from an existing property dictionary Instance. /// </summary> /// <param name="source">Property list to inherit.</param> /// <param name="excludes">The list of properties to exclude during inheritance.</param> public virtual void Inherit(PropertyDictionary source, StringCollection excludes) { foreach (DictionaryEntry entry in source.Dictionary) { string propertyName = (string) entry.Key; if (excludes != null && excludes.Contains(propertyName)) { continue; } // do not overwrite an existing read-only property if (IsReadOnlyProperty(propertyName)) { continue; } // add property to dictionary ValidatePropertyName(propertyName, Location.UnknownLocation); Dictionary[propertyName] = entry.Value; // if property is readonly, add to collection of readonly properties if (source.IsReadOnlyProperty(propertyName)) { _readOnlyProperties.Add(propertyName); } // if property is dynamic, add to collection of dynamic properties // if it was not already in that collection if (source.IsDynamicProperty(propertyName) && !IsDynamicProperty(propertyName)) { _dynamicProperties.Add(propertyName); } } }