/// <summary>
        /// Executes the Categorization task
        /// The primary objective is to do the following:
        /// 1) Find supported/unsupported TargetFramework specified in the project file
        /// 2) Categorize if a project is a test project or not (currently we rely on references added to the project to decide if a project is Test or not)
        /// At the end of this task we get 6 outputs
        /// Each output array is a list of project categorized according to the TargetFramework the project is targeting.
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            List <string> sdkProjects    = new List <string>();
            List <string> testProjects   = new List <string>();
            List <string> allProjects    = new List <string>();
            List <string> ignorePathList = new List <string>();

            string[] ignoreTokens = IgnoreDirNameForSearchingProjects.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string igTkn in ignoreTokens)
            {
                ignorePathList.Add(igTkn);
            }

            if (!ignorePathList.Contains(KV_IGNOREDIRNAME))
            {
                ignorePathList.Add(KV_IGNOREDIRNAME);
            }
            ProjectSearchUtility ProjUtil = new ProjectSearchUtility(SourceRootDirPath, ignorePathList);

            if (BuildScope.Equals("All", StringComparison.OrdinalIgnoreCase))
            {
                sdkProjects  = ProjUtil.GetAllSDKProjects();
                testProjects = ProjUtil.GetFilteredTestProjects();
            }
            else //We set default scope to All if empty/null, so safe to evaluate to Else in this case
            {
                sdkProjects  = ProjUtil.GetScopedSDKProjects(BuildScope);
                testProjects = ProjUtil.GetScopedTestProjects(BuildScope);
            }

            allProjects.AddRange(sdkProjects);
            allProjects.AddRange(testProjects);

            ConcurrentBag <SdkProjectMetaData> projWithMetaData = new ConcurrentBag <SdkProjectMetaData>();

            var projTimeBefore = DateTime.Now;

            projWithMetaData = GetProjectData(allProjects, projWithMetaData);
            var projTimeAfter = DateTime.Now;

            Debug.WriteLine("Parsing Projects took {0}", (projTimeAfter - projTimeBefore).TotalSeconds.ToString());

            var net452SdkProjects     = from s in projWithMetaData where (s.IsTargetFxSupported == true && s.FxMoniker == TargetFrameworkMoniker.net452 && s.ProjectType == SdkProjctType.Sdk) select s.ProjectTaskItem;
            var netStd14SdkProjects   = from s in projWithMetaData where (s.IsTargetFxSupported == true && s.FxMoniker == TargetFrameworkMoniker.netstandard14 && s.ProjectType == SdkProjctType.Sdk) select s.ProjectTaskItem;
            var netCore11SdkProjects  = from s in projWithMetaData where (s.IsTargetFxSupported == true && s.FxMoniker == TargetFrameworkMoniker.netcoreapp11 && s.ProjectType == SdkProjctType.Sdk) select s.ProjectTaskItem;
            var testNetCore11Projects = from s in projWithMetaData where (s.IsTargetFxSupported == true && s.FxMoniker == TargetFrameworkMoniker.netcoreapp11 && s.ProjectType == SdkProjctType.Test) select s.ProjectTaskItem;
            var testNet452Projects    = from s in projWithMetaData where (s.IsTargetFxSupported == true && s.FxMoniker == TargetFrameworkMoniker.net452 && s.ProjectType == SdkProjctType.Test) select s.ProjectTaskItem;
            var unSupportedProjects   = from s in projWithMetaData where (s.IsTargetFxSupported == false) select s.ProjectTaskItem;

            net452SdkProjectsToBuild     = net452SdkProjects?.ToArray <ITaskItem>();
            netStd14SdkProjectsToBuild   = netStd14SdkProjects?.ToArray <ITaskItem>();
            netCore11SdkProjectsToBuild  = netCore11SdkProjects?.ToArray <ITaskItem>();
            netCore11TestProjectsToBuild = testNetCore11Projects?.ToArray <ITaskItem>();
            net452TestProjectsToBuild    = testNet452Projects?.ToArray <ITaskItem>();
            unSupportedProjectsToBuild   = unSupportedProjects?.ToArray <ITaskItem>();

            return(true);
        }
示例#2
0
        List <string> GetProjectsToBeSkiped()
        {
            string notSupportedErrorFormat = @"Unable to execute skipping tests on following directory '{0}'";

            List <string> ScopedProjects = new List <string>();

            // We will not skip broad build scope (e.g. sdk), the idea is to not to skip all the tests in a broader build scope.
            if (BuildScope.Equals("sdk", StringComparison.OrdinalIgnoreCase))
            {
                TaskLogger.LogException <NotSupportedException>(notSupportedErrorFormat, BuildScope);
            }
            else if (BuildScopes.Equals("sdk", StringComparison.OrdinalIgnoreCase))
            {
                TaskLogger.LogException <NotSupportedException>(notSupportedErrorFormat, BuildScope);
            }
            else
            {
                string sdkRootDirPath = Path.Combine(RepositoryRootDirPath, "sdk");

                CategorizeSDKProjectsTask catProj = new CategorizeSDKProjectsTask(RepositoryRootDirPath, BuildScope, null, ProjectType, ProjectCategory);
                catProj.BuildScopes = BuildScopes;
                catProj.Execute();

                if (catProj.MultipleScopes.Contains("sdk"))
                {
                    TaskLogger.LogException <NotSupportedException>(notSupportedErrorFormat, sdkRootDirPath);
                }
                else
                {
                    var sdkProj  = catProj.SDK_Projects.Select <SDKMSBTaskItem, string>((item) => item.ItemSpec);
                    var testProj = catProj.Test_Projects.Select <SDKMSBTaskItem, string>((item) => item.ItemSpec);

                    if (sdkProj.NotNullOrAny <string>())
                    {
                        ScopedProjects.AddRange(sdkProj.ToList <string>());
                    }

                    if (testProj.NotNullOrAny <string>())
                    {
                        ScopedProjects.AddRange(testProj.ToList <string>());
                    }
                }
            }

            return(ScopedProjects);
        }
        public override bool Execute()
        {
            base.Execute();
            if (WhatIf)
            {
                WhatIfAction();
            }
            else
            {
                List <string> ScopedProjects = new List <string>();

                // We will not skip broad build scope (e.g. sdk), the idea is to not to skip all the tests in a broader build scope.
                if (string.IsNullOrWhiteSpace(BuildScope))
                {
                    TaskLogger.LogWarning("BuildScope is required to skip tests.");
                }
                else if (BuildScope.Equals("sdk", StringComparison.OrdinalIgnoreCase))
                {
                    TaskLogger.LogWarning("'{0}' BuildScope is not supported", BuildScope);
                }
                else
                {
                    CategorizeSDKProjectsTask catProj = new CategorizeSDKProjectsTask(RepositoryRootDirPath, BuildScope, BuildScopes, ProjectType, ProjectCategory);
                    catProj.Execute();

                    var sdkProj  = catProj.SDK_Projects.Select <SDKMSBTaskItem, string>((item) => item.ItemSpec);
                    var testProj = catProj.Test_Projects.Select <SDKMSBTaskItem, string>((item) => item.ItemSpec);

                    if (sdkProj.NotNullOrAny <string>())
                    {
                        ScopedProjects.AddRange(sdkProj.ToList <string>());
                    }

                    if (testProj.NotNullOrAny <string>())
                    {
                        ScopedProjects.AddRange(testProj.ToList <string>());
                    }

                    UpdateProjects(ScopedProjects);
                    ScopedProjects.Clear();
                }
            }

            return(TaskLogger.TaskSucceededWithNoErrorsLogged);
        }