Exemplo n.º 1
0
        private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLoggingContext targetLoggingContext, IElementLocation includeLocation, bool excludeFileSpecIsEmpty, bool disableExcludeDriveEnumerationWarning, string fileSpec)
        {
            // Both condition lines are necessary to skip for the first GetFileListEscaped call
            // and reach for the GetFileListUnescaped call when the wildcarded Exclude attribute results
            // in a drive enumeration. Since we only want to check for the Exclude
            // attribute here, we want to ensure that includeLocation is null - otherwise,
            // Include wildcard attributes for the GetFileListEscaped calls would falsely appear
            // with the Exclude attribute in the logged warning.
            if (((!excludeFileSpecIsEmpty) && (!disableExcludeDriveEnumerationWarning)) ||
                (includeLocation == null))
            {
                targetLoggingContext.LogWarning(
                    DriveEnumeratingWildcardMessageResourceName,
                    fileSpec,
                    XMakeAttributes.exclude,
                    XMakeElements.itemGroup);
            }

            // Both conditions are necessary to reach for both GetFileListEscaped calls
            // and skip for the GetFileListUnescaped call when the wildcarded Include attribute
            // results in drive enumeration.
            else if (excludeFileSpecIsEmpty && (includeLocation != null))
            {
                targetLoggingContext.LogWarning(
                    DriveEnumeratingWildcardMessageResourceName,
                    fileSpec,
                    XMakeAttributes.include,
                    XMakeElements.itemGroup);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Factory for intrinsic tasks.
 /// </summary>
 /// <param name="taskInstance">The task instance object.</param>
 /// <param name="loggingContext">The logging context.</param>
 /// <param name="projectInstance">The project instance.</param>
 /// <returns>An instantiated intrinsic task.</returns>
 internal static IntrinsicTask InstantiateTask(ProjectTargetInstanceChild taskInstance, TargetLoggingContext loggingContext, ProjectInstance projectInstance, bool logTaskInputs)
 {
     if (taskInstance is ProjectPropertyGroupTaskInstance)
     {
         return new PropertyGroupIntrinsicTask(taskInstance as ProjectPropertyGroupTaskInstance, loggingContext, projectInstance, logTaskInputs);
     }
     else if (taskInstance is ProjectItemGroupTaskInstance)
     {
         return new ItemGroupIntrinsicTask(taskInstance as ProjectItemGroupTaskInstance, loggingContext, projectInstance, logTaskInputs);
     }
     else
     {
         ErrorUtilities.ThrowInternalError("Unhandled intrinsic task type {0}", taskInstance.GetType().BaseType);
         return null;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs a task logging context from a parent target context and a task node.
        /// </summary>
        internal TaskLoggingContext(TargetLoggingContext targetLoggingContext, string projectFullPath, ProjectTargetInstanceChild task)
            : base(targetLoggingContext)
        {
            _targetLoggingContext = targetLoggingContext;
            _task = task;

            ProjectTaskInstance taskInstance = task as ProjectTaskInstance;
            if (taskInstance != null)
            {
                _taskName = taskInstance.Name;
            }
            else
            {
                ProjectPropertyGroupTaskInstance propertyGroupInstance = task as ProjectPropertyGroupTaskInstance;
                if (propertyGroupInstance != null)
                {
                    _taskName = "PropertyGroup";
                }
                else
                {
                    ProjectItemGroupTaskInstance itemGroupInstance = task as ProjectItemGroupTaskInstance;
                    if (itemGroupInstance != null)
                    {
                        _taskName = "ItemGroup";
                    }
                    else
                    {
                        _taskName = "Unknown";
                    }
                }
            }

            this.BuildEventContext = LoggingService.LogTaskStarted2
                (
                targetLoggingContext.BuildEventContext,
                _taskName,
                projectFullPath,
                task.Location.File
                );
            this.IsValid = true;
        }
Exemplo n.º 4
0
 internal static IntrinsicTask InstantiateTask(ProjectTargetInstanceChild taskInstance, TargetLoggingContext loggingContext, ProjectInstance projectInstance, bool logTaskInputs)
 {
     if (taskInstance is ProjectPropertyGroupTaskInstance propertyGroupTaskInstance)
     {
         return(new PropertyGroupIntrinsicTask(propertyGroupTaskInstance, loggingContext, projectInstance, logTaskInputs));
     }
     else if (taskInstance is ProjectItemGroupTaskInstance itemGroupTaskInstance)
     {
         return(new ItemGroupIntrinsicTask(itemGroupTaskInstance, loggingContext, projectInstance, logTaskInputs));
     }
     else
     {
         ErrorUtilities.ThrowInternalError("Unhandled intrinsic task type {0}", taskInstance.GetType().GetTypeInfo().BaseType);
         return(null);
     }
 }
Exemplo n.º 5
0
 protected IntrinsicTask(TargetLoggingContext loggingContext, ProjectInstance projectInstance, bool logTaskInputs)
 {
     this.LoggingContext = loggingContext;
     this.Project        = projectInstance;
     this.LogTaskInputs  = logTaskInputs;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initialize to run a specific task.
 /// </summary>
 void ITaskExecutionHost.InitializeForTask(IBuildEngine2 buildEngine, TargetLoggingContext loggingContext, ProjectInstance projectInstance, string taskName, ElementLocation taskLocation, ITaskHost taskHost, bool continueOnError, AppDomainSetup appDomainSetup, bool isOutOfProc, CancellationToken cancellationToken)
 {
     _buildEngine = buildEngine;
     _projectInstance = projectInstance;
     _targetLoggingContext = loggingContext;
     _taskName = taskName;
     _taskLocation = taskLocation;
     _cancellationTokenRegistration = cancellationToken.Register(this.Cancel);
     _taskHost = taskHost;
     _continueOnError = continueOnError;
     _taskExecutionIdle.Set();
     this.AppDomainSetup = appDomainSetup;
     this.IsOutOfProc = isOutOfProc;
 }
Exemplo n.º 7
0
        public void TestTaskResolutionFailureWithUsingTask()
        {
            Assert.Throws<InvalidProjectFileException>(() =>
            {
                _loggingService = new MockLoggingService();
                Dispose();
                _host = new TaskExecutionHost();
                TargetLoggingContext tlc = new TargetLoggingContext(_loggingService, new BuildEventContext(1, 1, BuildEventContext.InvalidProjectContextId, 1));

                ProjectInstance project = CreateTestProject();
                _host.InitializeForTask
                    (
                    this,
                    tlc,
                    project,
                    "TaskWithMissingAssembly",
                    ElementLocation.Create("none", 1, 1),
                    this,
                    false,
                    null,
                    false,
                    CancellationToken.None
                    );
                _host.FindTask(null);
                _host.InitializeForBatch(new TaskLoggingContext(_loggingService, tlc.BuildEventContext), _bucket, null);
            }
           );
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initialize the host object
        /// </summary>
        /// <param name="throwOnExecute">Should the task throw when executed</param>
        private void InitializeHost(bool throwOnExecute)
        {
            _loggingService = LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1) as ILoggingService;
            _logger = new MockLogger();
            _loggingService.RegisterLogger(_logger);
            _host = new TaskExecutionHost();
            TargetLoggingContext tlc = new TargetLoggingContext(_loggingService, new BuildEventContext(1, 1, BuildEventContext.InvalidProjectContextId, 1));

            // Set up a temporary project and add some items to it.
            ProjectInstance project = CreateTestProject();

            TypeLoader typeLoader = new TypeLoader(new TypeFilter(IsTaskFactoryClass));
            AssemblyLoadInfo loadInfo = AssemblyLoadInfo.Create(Assembly.GetAssembly(typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory)).FullName, null);
            LoadedType loadedType = new LoadedType(typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory), loadInfo);

            TaskBuilderTestTask.TaskBuilderTestTaskFactory taskFactory = new TaskBuilderTestTask.TaskBuilderTestTaskFactory();
            taskFactory.ThrowOnExecute = throwOnExecute;
            string taskName = "TaskBuilderTestTask";
            (_host as TaskExecutionHost)._UNITTESTONLY_TaskFactoryWrapper = new TaskFactoryWrapper(taskFactory, loadedType, taskName, null);
            _host.InitializeForTask
                (
                this,
                tlc,
                project,
                taskName,
                ElementLocation.Create("none", 1, 1),
                this,
                false,
                null,
                false,
                CancellationToken.None
                );

            ProjectTaskInstance taskInstance = project.Targets["foo"].Tasks.First();
            TaskLoggingContext talc = tlc.LogTaskBatchStarted(".", taskInstance);

            ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();

            ProjectItemInstance item = new ProjectItemInstance(project, "ItemListContainingOneItem", "a.cs", ".");
            item.SetMetadata("Culture", "fr-fr");
            itemsByName.Add(item);
            _oneItem = new ITaskItem[] { new TaskItem(item) };

            item = new ProjectItemInstance(project, "ItemListContainingTwoItems", "b.cs", ".");
            ProjectItemInstance item2 = new ProjectItemInstance(project, "ItemListContainingTwoItems", "c.cs", ".");
            item.SetMetadata("HintPath", "c:\\foo");
            item2.SetMetadata("HintPath", "c:\\bar");
            itemsByName.Add(item);
            itemsByName.Add(item2);
            _twoItems = new ITaskItem[] { new TaskItem(item), new TaskItem(item2) };

            _bucket = new ItemBucket(new string[0], new Dictionary<string, string>(), new Lookup(itemsByName, new PropertyDictionary<ProjectPropertyInstance>(), null), 0);
            _host.FindTask(null);
            _host.InitializeForBatch(talc, _bucket, null);
            _parametersSetOnTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            _outputsReadFromTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
        }
Exemplo n.º 9
0
        public void TestTaskResolutionFailureWithNoUsingTask()
        {
            Dispose();
            _host = new TaskExecutionHost();
            TargetLoggingContext tlc = new TargetLoggingContext(_loggingService, new BuildEventContext(1, 1, BuildEventContext.InvalidProjectContextId, 1));

            ProjectInstance project = CreateTestProject();
            _host.InitializeForTask
                (
                this,
                tlc,
                project,
                "TaskWithNoUsingTask",
                ElementLocation.Create("none", 1, 1),
                this,
                false,
                null,
                false,
                CancellationToken.None
                );

            _host.FindTask(null);
            _host.InitializeForBatch(new TaskLoggingContext(_loggingService, tlc.BuildEventContext), _bucket, null);
            _logger.AssertLogContains("MSB4036");
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes this base class.
 /// </summary>
 /// <param name="loggingContext">The logging context</param>
 /// <param name="projectInstance">The project instance</param>
 /// <param name="logTaskInputs">Flag to determine whether or not to log task inputs.</param>
 protected IntrinsicTask(TargetLoggingContext loggingContext, ProjectInstance projectInstance, bool logTaskInputs)
 {
     this.LoggingContext = loggingContext;
     this.Project = projectInstance;
     this.LogTaskInputs = logTaskInputs;
 }