public void XElementAnnotationTestAnnotationWithoutChildrenModel() { XElement expectedAnnotation = new XElement("{http://foo}Annotation"); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "Annotation" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "ComplexType", Type = AnnotatableElementType.ComplexType } }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "DefaultNamespace", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.AnnotationWithoutChildrenCsdl(), expectedAnnotation, annotationInfo, annotationLocation, XElementAnnotationModelBuilder.AnnotationWithoutChildrenModel()); }
public FlangeOfChannel(ISteelMaterial Material, ISectionChannel s, ElementLocation location) :base(Material) { double bf=0; double tf=0; switch (location) { case ElementLocation.Top: bf = s.b_f; tf = s.t_f; break; case ElementLocation.Bottom: bf = s.b_f; tf = s.t_f; break; default: throw new Exception("Invalid location is specified for Channel flange"); } base.Overhang = bf; base.Thickness = tf; }
/// <summary> /// Abstract out the creation of the new AssemblyTaskFactory with default task, and /// with some basic validation. /// </summary> private void SetupTaskFactory(IDictionary <string, string> factoryParameters, bool explicitlyLaunchTaskHost) { _taskFactory = new AssemblyTaskFactory(); #if FEATURE_ASSEMBLY_LOCATION _loadInfo = AssemblyLoadInfo.Create(null, Assembly.GetAssembly(typeof(TaskToTestFactories)).Location); #else _loadInfo = AssemblyLoadInfo.Create(typeof(TaskToTestFactories).GetTypeInfo().Assembly.FullName, null); #endif _loadedType = _taskFactory.InitializeFactory(_loadInfo, "TaskToTestFactories", new Dictionary <string, TaskPropertyInfo>(), string.Empty, factoryParameters, explicitlyLaunchTaskHost, null, ElementLocation.Create("NONE"), String.Empty); Assert.True(_loadedType.Assembly.Equals(_loadInfo)); // "Expected the AssemblyLoadInfo to be equal" }
/// <inheritdoc cref="ISdkResolverService.ResolveSdk"/> public virtual SdkResult ResolveSdk(int submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath, bool interactive, bool isRunningInVisualStudio) { // Lazy initialize the SDK resolvers if (_resolvers == null) { Initialize(loggingContext, sdkReferenceLocation); } List <SdkResult> results = new List <SdkResult>(); // Loop through resolvers which have already been sorted by priority, returning the first result that was successful SdkLogger buildEngineLogger = new SdkLogger(loggingContext); loggingContext.LogComment(MessageImportance.Low, "SdkResolving", sdk.ToString()); foreach (SdkResolver sdkResolver in _resolvers) { SdkResolverContext context = new SdkResolverContext(buildEngineLogger, projectPath, solutionPath, ProjectCollection.Version, interactive, isRunningInVisualStudio) { State = GetResolverState(submissionId, sdkResolver) }; SdkResultFactory resultFactory = new SdkResultFactory(sdk); SdkResult result; try { result = (SdkResult)sdkResolver.Resolve(sdk, context, resultFactory); } catch (Exception e) when(e is FileNotFoundException || e is FileLoadException && sdkResolver.GetType().GetTypeInfo().Name.Equals("NuGetSdkResolver", StringComparison.Ordinal)) { // Since we explicitly add the NuGetSdkResolver, we special case this. The NuGetSdkResolver has special logic // to load NuGet assemblies at runtime which could fail if the user is not running installed MSBuild. Rather // than give them a generic error, we want to give a more specific message. This exception cannot be caught by // the resolver itself because it is usually thrown before the class is loaded // MSB4243: The NuGet-based SDK resolver failed to run because NuGet assemblies could not be located. Check your installation of MSBuild or set the environment variable "{0}" to the folder that contains the required NuGet assemblies. {1} loggingContext.LogWarning(null, new BuildEventFileInfo(sdkReferenceLocation), "CouldNotRunNuGetSdkResolver", MSBuildConstants.NuGetAssemblyPathEnvironmentVariableName, e.Message); continue; } catch (Exception e) { // MSB4242: The SDK resolver "{0}" failed to run. {1} loggingContext.LogWarning(null, new BuildEventFileInfo(sdkReferenceLocation), "CouldNotRunSdkResolver", sdkResolver.Name, e.Message); continue; } SetResolverState(submissionId, sdkResolver, context.State); if (result == null) { continue; } if (result.Success) { LogWarnings(loggingContext, sdkReferenceLocation, result); if (!IsReferenceSameVersion(sdk, result.Version)) { // MSB4241: The SDK reference "{0}" version "{1}" was resolved to version "{2}" instead. You could be using a different version than expected if you do not update the referenced version to match. loggingContext.LogWarning(null, new BuildEventFileInfo(sdkReferenceLocation), "SdkResultVersionDifferentThanReference", sdk.Name, sdk.Version, result.Version); } // Associate the element location of the resolved SDK reference result.ElementLocation = sdkReferenceLocation; return(result); } results.Add(result); } foreach (SdkResult result in results) { LogWarnings(loggingContext, sdkReferenceLocation, result); if (result.Errors != null) { foreach (string error in result.Errors) { loggingContext.LogErrorFromText(subcategoryResourceName: null, errorCode: null, helpKeyword: null, file: new BuildEventFileInfo(sdkReferenceLocation), message: error); } } } return(new SdkResult(sdk, null, null)); }
public void CreatableByTaskFactoryNotInAssembly() { Assert.False(_taskFactory.TaskNameCreatableByFactory("NotInAssembly", null, String.Empty, null, ElementLocation.Create(".", 1, 1))); }
public void CreatableByTaskFactoryMismatchedIdentity() { IDictionary <string, string> factoryIdentityParameters = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); factoryIdentityParameters.Add(XMakeAttributes.runtime, XMakeAttributes.MSBuildRuntimeValues.clr2); factoryIdentityParameters.Add(XMakeAttributes.architecture, XMakeAttributes.MSBuildArchitectureValues.currentArchitecture); SetupTaskFactory(factoryIdentityParameters, false /* don't want task host */); IDictionary <string, string> taskIdentityParameters = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); taskIdentityParameters.Add(XMakeAttributes.runtime, XMakeAttributes.MSBuildRuntimeValues.clr4); taskIdentityParameters.Add(XMakeAttributes.architecture, XMakeAttributes.MSBuildArchitectureValues.currentArchitecture); Assert.False(_taskFactory.TaskNameCreatableByFactory("TaskToTestFactories", taskIdentityParameters, String.Empty, null, ElementLocation.Create(".", 1, 1))); }
private void AnnotationRoundTripCsdlCheck(IEnumerable<XElement> csdls, XElement expectedAnnotation, AnnotationInfo annotationInfo, ElementLocation annotationLocation, IEdmModel model) { var errors = new EdmLibTestErrors(); this.VerifySemanticValidation(model, EdmVersion.Latest, errors); var isValid = this.ValidateAnnotation(model, expectedAnnotation, annotationInfo, annotationLocation); Assert.IsTrue(isValid, "Invalid XElement annotation."); IEnumerable<EdmError> serializationErrors; var serializedModelCsdls = this.GetSerializerResult(model, EdmVersion.Latest, out serializationErrors).Select(n => XElement.Parse(n)); Assert.AreEqual(0, serializationErrors.Count(), "Round trip test should not have serialization errors: " + Environment.NewLine + String.Join(Environment.NewLine, serializationErrors)); var csdlsWithLastestEdmVersion = ModelBuilderHelpers.ReplaceCsdlNamespacesForEdmVersion(csdls.ToArray(), EdmVersion.Latest).ToList(); new ConstructiveApiCsdlXElementComparer().Compare(csdlsWithLastestEdmVersion, serializedModelCsdls.ToList()); }
public void XElementAnnotationTestNestedXElementWithNoValueCsdl() { XElement expectedAnnotation = new XElement("{http://foo}Annotation", new XElement("{http://foo}Child", new XElement("{http://foo}GrandChild", new XElement("{http://foo}GreatGrandChild", new XElement("{http://foo}GreateGreatGrandChild") ) ) ) ); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "Annotation" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "SimpleType", Type = AnnotatableElementType.ComplexType }, new ElementInfo() { Name = "Id", Type = AnnotatableElementType.Property } }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "DefaultNamespace", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.NestedXElementWithNoValueCsdl(), expectedAnnotation, annotationInfo, annotationLocation); }
private void AnnotationRoundTripCsdlCheck(IEnumerable <XElement> csdls, XElement expectedAnnotation, AnnotationInfo annotationInfo, ElementLocation annotationLocation, IEdmModel model) { var errors = new EdmLibTestErrors(); this.VerifySemanticValidation(model, EdmVersion.Latest, errors); var isValid = this.ValidateAnnotation(model, expectedAnnotation, annotationInfo, annotationLocation); Assert.IsTrue(isValid, "Invalid XElement annotation."); IEnumerable <EdmError> serializationErrors; var serializedModelCsdls = this.GetSerializerResult(model, EdmVersion.Latest, out serializationErrors).Select(n => XElement.Parse(n)); Assert.AreEqual(0, serializationErrors.Count(), "Round trip test should not have serialization errors: " + Environment.NewLine + String.Join(Environment.NewLine, serializationErrors)); var csdlsWithLastestEdmVersion = ModelBuilderHelpers.ReplaceCsdlNamespacesForEdmVersion(csdls.ToArray(), EdmVersion.Latest).ToList(); new ConstructiveApiCsdlXElementComparer().Compare(csdlsWithLastestEdmVersion, serializedModelCsdls.ToList()); }
public void XElementAnnotationTestComplexNamespaceOverlappingModel() { XElement expectedAnnotation = new XElement("{http://foo}Annotation", new XElement("{http://foo}Child", new XElement("{http://foo1}GrandChild", new XElement("{http://foo}GreatGrandChild", "1" ) ) ), new XElement("{http://foo1}Child", new XElement("{http://foo}GrandChild", "1" ) ) ); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "Annotation" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "Container", Type = AnnotatableElementType.EntityContainer }, new ElementInfo() { Name = "SimpleFunction", Type = AnnotatableElementType.FunctionImport } }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "Default", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.ComplexNamespaceOverlappingCsdl(), expectedAnnotation, annotationInfo, annotationLocation, XElementAnnotationModelBuilder.ComplexNamespaceOverlappingModel()); }
/// <summary> /// Constructor called by the Evaluator. /// </summary> internal ProjectPropertyGroupTaskPropertyInstance(string name, string value, string condition, ElementLocation location, ElementLocation conditionLocation) { ErrorUtilities.VerifyThrowInternalNull(name, "name"); ErrorUtilities.VerifyThrowInternalNull(value, "value"); ErrorUtilities.VerifyThrowInternalNull(condition, "condition"); ErrorUtilities.VerifyThrowInternalNull(location, "location"); _name = name; _value = value; _condition = condition; _location = location; _conditionLocation = conditionLocation; }
private void AnnotationRoundTripCsdlCheck(IEnumerable <XElement> csdls, XElement expectedAnnotation, AnnotationInfo annotationInfo, ElementLocation annotationLocation) { var model = this.GetParserResult(csdls); this.AnnotationRoundTripCsdlCheck(csdls, expectedAnnotation, annotationInfo, annotationLocation, model); }
public Build.BackEnd.SdkResolution.SdkResult ResolveSdk(int submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath, bool interactive) { return(null); }
public override SdkResult ResolveSdk(int submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath, bool interactive, bool isRunningInVisualStudio) { ErrorUtilities.VerifyThrowInternalNull(sdk, nameof(sdk)); ErrorUtilities.VerifyThrowInternalNull(loggingContext, nameof(loggingContext)); ErrorUtilities.VerifyThrowInternalNull(sdkReferenceLocation, nameof(sdkReferenceLocation)); ErrorUtilities.VerifyThrowInternalLength(projectPath, nameof(projectPath)); return(_cachedSdkResolver.ResolveSdk(submissionId, sdk, loggingContext, sdkReferenceLocation, solutionPath, projectPath, interactive, isRunningInVisualStudio)); }
/// <summary> /// Constructor called by Evaluator /// </summary> internal ProjectTaskOutputPropertyInstance(string propertyName, string taskParameter, string condition, ElementLocation location, ElementLocation propertyNameLocation, ElementLocation taskParameterLocation, ElementLocation conditionLocation) { ErrorUtilities.VerifyThrowInternalLength(propertyName, "propertyName"); ErrorUtilities.VerifyThrowInternalLength(taskParameter, "taskParameter"); ErrorUtilities.VerifyThrowInternalNull(location, "location"); ErrorUtilities.VerifyThrowInternalNull(propertyNameLocation, "propertyNameLocation"); ErrorUtilities.VerifyThrowInternalNull(taskParameterLocation, "taskParameterLocation"); _propertyName = propertyName; _taskParameter = taskParameter; _condition = condition; _location = location; _propertyNameLocation = propertyNameLocation; _taskParameterLocation = taskParameterLocation; _conditionLocation = conditionLocation; }
public void XElementAnnotationTestAnnotationWithValueCsdl() { XElement expectedAnnotation = new XElement("{http://foo}Annotation", "Value 1.0" ); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "Annotation" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "SimpleFunction", Type = AnnotatableElementType.Function }, new ElementInfo() { Name = "Id", Type = AnnotatableElementType.Parameter } }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "DefaultNamespace", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.AnnotationWithValueCsdl(), expectedAnnotation, annotationInfo, annotationLocation); }
private bool ValidateAnnotation(IEdmModel model, XElement expectedAnnotation, AnnotationInfo annotationInfo, ElementLocation annotationLocation) { string annotationValue = this.GetElementAnnotationValue(model, annotationInfo, annotationLocation); if (string.IsNullOrEmpty(annotationValue)) { return(false); } var actualAnnotation = XElement.Parse(annotationValue); return(expectedAnnotation.ToString().Equals(actualAnnotation.ToString())); }
public void XElementAnnotationTestAnnotationWithEntitySetTagInEntityContainerModel() { XElement expectedAnnotation = new XElement("{http://foo}EntitySet", "1" ); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "EntitySet" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "Container", Type = AnnotatableElementType.EntityContainer } }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "DefaultNamespace", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.AnnotationWithEntitySetTagInEntityContainerCsdl(), expectedAnnotation, annotationInfo, annotationLocation, XElementAnnotationModelBuilder.AnnotationWithEntitySetTagInEntityContainerModel()); }
private string GetElementAnnotationValue(IEdmModel model, AnnotationInfo annotationInfo, ElementLocation annotationLocation) { IEdmElement element = GetElementByElementLocation(model, annotationLocation); if (null != element) { var annotation = model.GetAnnotationValue(element, annotationInfo.Namespace, annotationInfo.Name); if (null != annotation) { return(null != (annotation as EdmStringConstant) ? (annotation as EdmStringConstant).Value : string.Empty); } } return(string.Empty); }
/// <summary> /// Returns the URL of the file that contains the definition of the item at the current position /// </summary> /// <param name="filePath">Current file</param> /// <param name="sourceText">Text in the current file</param> /// <param name="position">Position of item that is to be resolved</param> /// <returns></returns> public List <Definition> ResolveDefinition(string filePath, string sourceText, int position) { Verify.NotDisposed(this); List <Definition> definitions = new List <Definition>(); if (_project != null) { XmlDocumentSyntax root = Parser.ParseText(sourceText); SyntaxNode syntaxNode = root.FindNode(position); // Resolves Definition for properties e.g. $(foo) if (syntaxNode.Kind == SyntaxKind.XmlTextLiteralToken && Utilities.IsProperty(sourceText.Substring(syntaxNode.Span.Start, syntaxNode.FullWidth), position - syntaxNode.Span.Start, out string propertyName)) { foreach (ProjectProperty property in _project.Properties) { if (property.Name == propertyName) { ProjectProperty currentProperty = property; while (currentProperty.Predecessor != null) { if (currentProperty.Xml?.Location != null) { ElementLocation location = currentProperty.Xml.Location; definitions.Add(new Definition(location.File, Path.GetFileNameWithoutExtension(_project.Xml.Location.File), currentProperty.Name + " Definitions", currentProperty.EvaluatedValue, location.Line, location.Column)); } currentProperty = currentProperty.Predecessor; } if (currentProperty.Xml?.Location != null) { ElementLocation lastLocation = currentProperty.Xml.Location; definitions.Add(new Definition(lastLocation.File, Path.GetFileNameWithoutExtension(_project.Xml.Location.File), currentProperty.Name + " Definitions", currentProperty.EvaluatedValue, lastLocation.Line, lastLocation.Column)); } break; } } } // Resolves Definition for regular imports else if (syntaxNode.ParentElement != null && syntaxNode.ParentElement.Name.Equals(SyntaxNames.Import)) { while (syntaxNode.Parent.ParentElement == syntaxNode.ParentElement) { syntaxNode = syntaxNode.Parent; } int nodeStart = syntaxNode.Parent.Span.Start; int col = nodeStart - Utilities.GetStartOfLine(sourceText, nodeStart) + 1; int line = Utilities.GetLine(sourceText, nodeStart) + 1; foreach (ResolvedImport import in _project.Imports) { ElementLocation location = import.ImportingElement.Location; if (location.File == filePath && col == location.Column && line == location.Line) { definitions.Add(new Definition(import.ImportedProject.FullPath, Path.GetFileNameWithoutExtension(_project.Xml.Location.File), "Imported Files", Path.GetFileName(import.ImportedProject.FullPath))); } } } // Resolves Definition for the project's sdk else if (syntaxNode.ParentElement != null && syntaxNode.ParentElement.Name.Equals(SyntaxNames.Project)) { bool foundSdk = false; for (int i = 0; i < 3; i++) { if (sourceText.Substring(syntaxNode.Start, 3).Equals(SyntaxNames.Sdk)) { foundSdk = true; break; } syntaxNode = syntaxNode.Parent; } if (foundSdk) { foreach (ResolvedImport import in _project.Imports) { ElementLocation location = import.ImportingElement.Location; if (location.File == filePath && 0 == location.Column && 0 == location.Line) { definitions.Add(new Definition(import.ImportedProject.FullPath, Path.GetFileNameWithoutExtension(_project.Xml.Location.File), "Sdk Imports", Path.GetFileName(import.ImportedProject.FullPath))); } } } } } return(definitions); }
/// <summary> /// Constructor called by the Evaluator. /// </summary> internal ProjectItemGroupTaskMetadataInstance(string name, string value, string condition, ElementLocation location, ElementLocation conditionLocation) { ErrorUtilities.VerifyThrowInternalNull(name, nameof(name)); ErrorUtilities.VerifyThrowInternalNull(value, nameof(value)); ErrorUtilities.VerifyThrowInternalNull(condition, nameof(condition)); ErrorUtilities.VerifyThrowInternalNull(location, nameof(location)); _name = name; _value = value; _condition = condition; _location = location; _conditionLocation = conditionLocation; }
private string GetElementAnnotationValue(IEdmModel model, AnnotationInfo annotationInfo, ElementLocation annotationLocation) { IEdmElement element = GetElementByElementLocation(model, annotationLocation); if (null != element) { var annotation = model.GetAnnotationValue(element, annotationInfo.Namespace, annotationInfo.Name); if (null != annotation) { return null != (annotation as EdmStringConstant) ? (annotation as EdmStringConstant).Value : string.Empty; } } return string.Empty; }
internal override IList <SdkResolver> LoadResolvers(LoggingContext loggingContext, ElementLocation location) { List <SdkResolver> resolvers = new List <SdkResolver> { new MockSdkResolver1(), new MockSdkResolver2(), new MockResolverReturnsNull(), new MockSdkResolverWithState() }; if (_includeErrorResolver) { resolvers.Add(new MockSdkResolverThrows()); } return(resolvers.OrderBy(i => i.Priority).ToList()); }
public string ResolveSdk(int submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath) { return(null); }
/// <summary> /// Resolves the specified SDK. This method uses concurrent dictionaries for locking per build submission and SDK name. This allows a build to be resolving multiple /// SDKs at once where the first request does the heavy lifting and blocked requests use the cached result. /// </summary> /// <param name="submissionId">The current build submission ID that is resolving an SDK.</param> /// <param name="sdk">The <see cref="SdkReference"/> containing information about the SDK to resolve.</param> /// <param name="loggingContext">The <see cref="LoggingContext"/> to use when logging messages during resolution.</param> /// <param name="sdkReferenceLocation">The <see cref="ElementLocation"/> of the element that referenced the SDK.</param> /// <param name="solutionPath">The full path to the solution, if any, that is being built.</param> /// <param name="projectPath">The full path to the project that referenced the SDK.</param> /// <returns>An <see cref="SdkResult"/> containing information about the SDK if one was resolved, otherwise <code>null</code>.</returns> private SdkResult GetSdkResultAndCache(int submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath) { ErrorUtilities.VerifyThrowInternalNull(sdk, nameof(sdk)); ErrorUtilities.VerifyThrowInternalNull(loggingContext, nameof(loggingContext)); ErrorUtilities.VerifyThrowInternalNull(sdkReferenceLocation, nameof(sdkReferenceLocation)); SdkResult result; if (Traits.Instance.EscapeHatches.DisableSdkResolutionCache) { result = GetSdkResult(submissionId, sdk, loggingContext, sdkReferenceLocation, solutionPath, projectPath); } else { // Get the dictionary for the specified submission if one is already added otherwise create a new dictionary for the submission. ConcurrentDictionary <string, SdkResult> cached = _cache.GetOrAdd(submissionId, new ConcurrentDictionary <string, SdkResult>(MSBuildNameIgnoreCaseComparer.Default)); /* * Get a cached result if available, otherwise resolve the SDK with the SdkResolverService.Instance. If multiple projects are attempting to resolve * the same SDK, they will all block while the first one resolves. Blocked requests will then get the cached result. This ensures that a single * build submission resolves each unique SDK only one time. */ result = cached.GetOrAdd( sdk.Name, key => GetSdkResult(submissionId, sdk, loggingContext, sdkReferenceLocation, solutionPath, projectPath)); } if (result != null && !SdkResolverService.IsReferenceSameVersion(sdk, result.Version)) { // MSB4240: Multiple versions of the same SDK "{0}" cannot be specified. The SDK version "{1}" already specified by "{2}" will be used and the version "{3}" will be ignored. loggingContext.LogWarning(null, new BuildEventFileInfo(sdkReferenceLocation), "ReferencingMultipleVersionsOfTheSameSdk", sdk.Name, result.Version, result.ElementLocation, sdk.Version); } return(result); }
public void CreatableByTaskFactoryNullTaskName() { Assert.Throws <InvalidProjectFileException>(() => { Assert.False(_taskFactory.TaskNameCreatableByFactory(null, null, String.Empty, null, ElementLocation.Create(".", 1, 1))); } ); }
/// <summary> /// Resolves the specified SDK without caching the result. /// </summary> /// <param name="submissionId">The current build submission ID that is resolving an SDK.</param> /// <param name="sdk">The <see cref="SdkReference"/> containing information about the SDK to resolve.</param> /// <param name="loggingContext">The <see cref="LoggingContext"/> to use when logging messages during resolution.</param> /// <param name="sdkReferenceLocation">The <see cref="ElementLocation"/> of the element that referenced the SDK.</param> /// <param name="solutionPath">The full path to the solution, if any, that is being built.</param> /// <param name="projectPath">The full path to the project that referenced the SDK.</param> /// <returns>An <see cref="SdkResult"/> containing information about the SDK if one was resolved, otherwise <code>null</code>.</returns> private SdkResult GetSdkResult(int submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath) { SdkResult sdkResult = SdkResolverService.Instance.GetSdkResult(submissionId, sdk, loggingContext, sdkReferenceLocation, solutionPath, projectPath); if (sdkResult != null) { if (!SdkResolverService.IsReferenceSameVersion(sdk, sdkResult.Version)) { // MSB4241: The SDK reference "{0}" version "{1}" was resolved to version "{2}" instead. You could be using a different version than expected if you do not update the referenced version to match. loggingContext.LogWarning(null, new BuildEventFileInfo(sdkReferenceLocation), "SdkResultVersionDifferentThanReference", sdk.Name, sdk.Version, sdkResult.Version); } // Associate the element location of the resolved SDK reference sdkResult.ElementLocation = sdkReferenceLocation; } return(sdkResult); }
public void NullLoadInfo() { Assert.Throws <ArgumentNullException>(() => { AssemblyTaskFactory taskFactory = new AssemblyTaskFactory(); taskFactory.InitializeFactory(null, "TaskToTestFactories", new Dictionary <string, TaskPropertyInfo>(), string.Empty, null, false, null, ElementLocation.Create("NONE"), String.Empty); } ); }
/// <inheritdoc cref="ISdkResolverService.ResolveSdk"/> public override string ResolveSdk(int submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath) { SdkResult result = GetSdkResultAndCache(submissionId, sdk, loggingContext, sdkReferenceLocation, solutionPath, projectPath); return(result?.Path); }
public void GoodTaskNameButNotInInfo() { Assert.Throws <InvalidProjectFileException>(() => { AssemblyTaskFactory taskFactory = new AssemblyTaskFactory(); taskFactory.InitializeFactory(_loadInfo, "RandomTask", new Dictionary <string, TaskPropertyInfo>(), string.Empty, null, false, null, ElementLocation.Create("NONE"), String.Empty); } ); }
/// <summary> /// Returns element location /// </summary> public Rectangle GetLocation(ElementLocation loc) { return SciterDomApi.GetElementLocation(this, loc); }
/// <summary> /// Create an instance of the wrapped ITask for a batch run of the task. /// </summary> public ITask CreateTaskInstance(ElementLocation taskLocation, TaskLoggingContext taskLoggingContext, AppDomainSetup appDomainSetup, bool isOutOfProc) { separateAppDomain = false; separateAppDomain = loadedType.HasLoadInSeparateAppDomainAttribute(); taskAppDomain = null; if (separateAppDomain) { if (!loadedType.Type.IsMarshalByRef) { taskLoggingContext.LogError ( new BuildEventFileInfo(taskLocation), "TaskNotMarshalByRef", taskName ); return null; } else { // Our task depend on this name to be precisely that, so if you change it make sure // you also change the checks in the tasks run in separate AppDomains. Better yet, just don't change it. // Make sure we copy the appdomain configuration and send it to the appdomain we create so that if the creator of the current appdomain // has done the binding redirection in code, that we will get those settings as well. AppDomainSetup appDomainInfo = new AppDomainSetup(); // Get the current app domain setup settings byte[] currentAppdomainBytes = appDomainSetup.GetConfigurationBytes(); // Apply the appdomain settings to the new appdomain before creating it appDomainInfo.SetConfigurationBytes(currentAppdomainBytes); taskAppDomain = AppDomain.CreateDomain(isOutOfProc ? "taskAppDomain (out-of-proc)" : "taskAppDomain (in-proc)", null, appDomainInfo); // Hook up last minute dumping of any exceptions taskAppDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandling.UnhandledExceptionHandler); } } // instantiate the task in given domain if (taskAppDomain == null || taskAppDomain == AppDomain.CurrentDomain) { // perf improvement for the same appdomain case - we already have the type object // and don't want to go through reflection to recreate it from the name. taskInstance = (ITask)Activator.CreateInstance(loadedType.Type); return taskInstance; } if (loadedType.Assembly.AssemblyFile != null) { taskInstance = (ITask)taskAppDomain.CreateInstanceFromAndUnwrap(loadedType.Assembly.AssemblyFile, loadedType.Type.FullName); // this will force evaluation of the task class type and try to load the task assembly Type taskType = taskInstance.GetType(); // If the types don't match, we have a problem. It means that our AppDomain was able to load // a task assembly using Load, and loaded a different one. I don't see any other choice than // to fail here. if (taskType != loadedType.Type) { taskLoggingContext.LogError ( new BuildEventFileInfo(taskLocation), "ConflictingTaskAssembly", loadedType.Assembly.AssemblyFile, loadedType.Type.Assembly.Location ); taskInstance = null; } } else { taskInstance = (ITask)taskAppDomain.CreateInstanceAndUnwrap(loadedType.Type.Assembly.FullName, loadedType.Type.FullName); } return taskInstance; }
/// <summary> /// Throw an invalid project exception indicating that the child is not valid beneath the element /// </summary> internal static void ThrowProjectInvalidChildElement(string name, string parentName, ElementLocation location) { ProjectErrorUtilities.ThrowInvalidProject(location, "UnrecognizedChildElement", name, parentName); }
public void XElementAnnotationTestAnnotationWithSchemaTagValueModel() { XElement expectedAnnotation = new XElement("{http://foo}Annotation", "</Schema>" ); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "Annotation" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "SimpleType", Type = AnnotatableElementType.EntityType } }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "DefaultNamespace", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.AnnotationWithSchemaTagValueCsdl(), expectedAnnotation, annotationInfo, annotationLocation, XElementAnnotationModelBuilder.AnnotationWithSchemaTagValueModel()); }
public void XElementAnnotationTestFunctionImportParameterWithAnnotationModel() { XElement expectedAnnotation = new XElement("{http://foo}Annotation", 1); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "Annotation" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "SimpleFunction", Type = AnnotatableElementType.Function }, new ElementInfo() { Name = "Name", Type = AnnotatableElementType.Parameter }, }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "Default", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.ActionImportParameterWithAnnotationCsdl(), expectedAnnotation, annotationInfo, annotationLocation, XElementAnnotationModelBuilder.OperationImportParameterWithAnnotationModel()); }
public void XElementAnnotationTestDifferentAnnotationNamespaceModel() { XElement expectedAnnotation = new XElement("{http://foo}Annotation", new XElement("{http://foo1}Child", new XElement("{http://foo2}GrandChild", "1" ) ) ); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "Annotation" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "Container", Type = AnnotatableElementType.EntityContainer }, new ElementInfo() { Name = "SimpleSet", Type = AnnotatableElementType.EntitySet } }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "DefaultNamespace", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.DifferentAnnotationNamespaceCsdl(), expectedAnnotation, annotationInfo, annotationLocation, XElementAnnotationModelBuilder.DifferentAnnotationNamespaceModel()); }
public void XElementAnnotationTestNavigationPropertyWithAnnotationModel() { XElement expectedAnnotation = new XElement("{http://foo}Annotation", 1); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "Annotation" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "Person", Type = AnnotatableElementType.EntityType }, new ElementInfo() { Name = "Friends", Type = AnnotatableElementType.NavigationProperty } }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "DefaultNamespace", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.NavigationPropertyWithAnnotationCsdl(), expectedAnnotation, annotationInfo, annotationLocation, XElementAnnotationModelBuilder.NavigationPropertyWithAnnotationModel()); }
public Defect_ProjectRefDuplicate(ElementLocation location, String targetProject) : base(location.File, location.Line, String.Format(SDefect.ProjectRefDuplicate, targetProject)) { }
string [] GetDefaultTargets(ProjectRootElement xml, bool fromAttribute, bool checkImports) { if (fromAttribute) { var ret = xml.DefaultTargets.Split(item_target_sep, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); if (checkImports && ret.Length == 0) { foreach (var imp in this.raw_imports) { ret = GetDefaultTargets(imp.ImportedProject, true, false); if (ret.Any()) { break; } } } return(ret); } else { if (xml.Targets.Any()) { return new String [] { xml.Targets.First().Name } } ; if (checkImports) { foreach (var imp in this.raw_imports) { var ret = GetDefaultTargets(imp.ImportedProject, false, false); if (ret.Any()) { return(ret); } } } return(new string [0]); } } void InitializeProperties(ProjectRootElement xml) { location = xml.Location; full_path = xml.FullPath; directory = string.IsNullOrWhiteSpace(xml.DirectoryPath) ? System.IO.Directory.GetCurrentDirectory() : xml.DirectoryPath; InitialTargets = xml.InitialTargets.Split(item_target_sep, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList(); raw_imports = new List <ResolvedImport> (); item_definitions = new Dictionary <string, ProjectItemDefinitionInstance> (); targets = new Dictionary <string, ProjectTargetInstance> (); raw_items = new List <ProjectItemInstance> (); properties = new Dictionary <string, ProjectPropertyInstance> (); foreach (DictionaryEntry p in Environment.GetEnvironmentVariables()) { // FIXME: this is kind of workaround for unavoidable issue that PLATFORM=* is actually given // on some platforms and that prevents setting default "PLATFORM=AnyCPU" property. if (!string.Equals("PLATFORM", (string)p.Key, StringComparison.OrdinalIgnoreCase)) { this.properties [(string)p.Key] = new ProjectPropertyInstance((string)p.Key, true, (string)p.Value); } } foreach (var p in global_properties) { this.properties [p.Key] = new ProjectPropertyInstance(p.Key, false, p.Value); } var tools = projects.GetToolset(tools_version) ?? projects.GetToolset(projects.DefaultToolsVersion); foreach (var p in projects.GetReservedProperties(tools, this, xml)) { this.properties [p.Name] = p; } foreach (var p in ProjectCollection.GetWellKnownProperties(this)) { this.properties [p.Name] = p; } ProcessXml(xml); DefaultTargets = GetDefaultTargets(xml).ToList(); }
public void XElementAnnotationTestEnumWithAnnotationCsdl() { XElement expectedAnnotation = new XElement("{http://foo}Annotation", 1); AnnotationInfo annotationInfo = new AnnotationInfo() { Namespace = "http://foo", Name = "Annotation" }; List<ElementInfo> annotationPath = new List<ElementInfo>() { new ElementInfo() { Name = "Spicy", Type = AnnotatableElementType.Enum } }; ElementLocation annotationLocation = new ElementLocation() { Namespace = "DefaultNamespace", ElementPath = annotationPath }; this.AnnotationRoundTripCsdlCheck(XElementAnnotationModelBuilder.EnumWithAnnotationCsdl(), expectedAnnotation, annotationInfo, annotationLocation); }
internal override IList <SdkResolver> LoadResolvers(ILoggingService logger, BuildEventContext bec, ElementLocation location) { return(_includeErrorResolver ? new List <SdkResolver> { new MockSdkResolverThrows(), new MockSdkResolver1(), new MockSdkResolver2() } : new List <SdkResolver> { new MockSdkResolver1(), new MockSdkResolver2() }); }
private void AnnotationRoundTripCsdlCheck(IEnumerable<XElement> csdls, XElement expectedAnnotation, AnnotationInfo annotationInfo, ElementLocation annotationLocation) { var model = this.GetParserResult(csdls); this.AnnotationRoundTripCsdlCheck(csdls, expectedAnnotation, annotationInfo, annotationLocation, model); }
private void Initialize(ILoggingService logger, BuildEventContext buildEventContext, ElementLocation location) { lock (_lockObject) { if (_resolvers != null) { return; } _resolvers = _sdkResolverLoader.LoadResolvers(logger, buildEventContext, location); } }
private bool ValidateAnnotation(IEdmModel model, XElement expectedAnnotation, AnnotationInfo annotationInfo, ElementLocation annotationLocation) { string annotationValue = this.GetElementAnnotationValue(model, annotationInfo, annotationLocation); if (string.IsNullOrEmpty(annotationValue)) { return false; } var actualAnnotation = XElement.Parse(annotationValue); return expectedAnnotation.ToString().Equals(actualAnnotation.ToString()); }
private static void LogWarnings(ILoggingService logger, BuildEventContext bec, ElementLocation location, SdkResultImpl result) { if (result.Warnings == null) { return; } foreach (var warning in result.Warnings) { logger.LogWarningFromText(bec, null, null, null, new BuildEventFileInfo(location), warning); } }
private IEdmElement GetElementByElementLocation(IEdmModel model, ElementLocation elementLocation) { IEdmElement elementWithAnnotation = model; foreach (ElementInfo elementInfo in elementLocation.ElementPath) { elementWithAnnotation = this.GetAnnotatableElement(elementLocation.Namespace, elementInfo.Name, elementInfo.Type, elementWithAnnotation); if (null == elementWithAnnotation) { break; } } return elementWithAnnotation; }
/// <summary> /// Get path on disk to the referenced SDK. /// </summary> /// <param name="sdk">SDK referenced by the Project.</param> /// <param name="logger">Logging service.</param> /// <param name="buildEventContext">Build event context for logging.</param> /// <param name="sdkReferenceLocation">Location of the element within the project which referenced the SDK.</param> /// <param name="solutionPath">Path to the solution if known.</param> /// <param name="projectPath">Path to the project being built.</param> /// <returns>Path to the root of the referenced SDK.</returns> internal string GetSdkPath(SdkReference sdk, ILoggingService logger, BuildEventContext buildEventContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath) { ErrorUtilities.VerifyThrowInternalNull(sdk, nameof(sdk)); ErrorUtilities.VerifyThrowInternalNull(logger, nameof(logger)); ErrorUtilities.VerifyThrowInternalNull(buildEventContext, nameof(buildEventContext)); ErrorUtilities.VerifyThrowInternalNull(sdkReferenceLocation, nameof(sdkReferenceLocation)); if (_resolvers == null) { Initialize(logger, buildEventContext, sdkReferenceLocation); } var results = new List <SdkResultImpl>(); try { var buildEngineLogger = new SdkLoggerImpl(logger, buildEventContext); foreach (var sdkResolver in _resolvers) { var context = new SdkResolverContextImpl(buildEngineLogger, projectPath, solutionPath, ProjectCollection.Version); var resultFactory = new SdkResultFactoryImpl(sdk); try { var result = (SdkResultImpl)sdkResolver.Resolve(sdk, context, resultFactory); if (result != null && result.Success) { LogWarnings(logger, buildEventContext, sdkReferenceLocation, result); return(result.Path); } results.Add(result); } catch (Exception e) { logger.LogFatalBuildError(buildEventContext, e, new BuildEventFileInfo(sdkReferenceLocation)); } } } catch (Exception e) { logger.LogFatalBuildError(buildEventContext, e, new BuildEventFileInfo(sdkReferenceLocation)); throw; } foreach (var result in results) { LogWarnings(logger, buildEventContext, sdkReferenceLocation, result); if (result.Errors != null) { foreach (var error in result.Errors) { logger.LogErrorFromText(buildEventContext, subcategoryResourceName: null, errorCode: null, helpKeyword: null, file: new BuildEventFileInfo(sdkReferenceLocation), message: error); } } } return(null); }
public void CreatableByTaskFactoryGoodName() { Assert.True(_taskFactory.TaskNameCreatableByFactory("TaskToTestFactories", null, String.Empty, null, ElementLocation.Create(".", 1, 1))); }
/// <summary> /// Gets element location /// </summary> public Rectangle GetElementLocation(Element he, ElementLocation areas) { Rectangle rect; CheckResult(SciterGetElementLocation(he.Handle, out rect, (ELEMENT_AREA)areas)); rect.Width -= rect.Left; rect.Height -= rect.Top; return rect; }