Example #1
0
        private DependencyAnalysisResult PerformDependencyAnalysisTestHelper
        (
            FileWriteInfo [] filesToAnalyze,
            Hashtable itemsByName,
            string inputs,
            string outputs,
            out Hashtable changedTargetInputs,
            out Hashtable upToDateTargetInputs
        )
        {
            List <string> filesToDelete = new List <string>();

            try
            {
                // first set the disk up
                for (int i = 0; i < filesToAnalyze.Length; ++i)
                {
                    string path = ObjectModelHelpers.CreateFileInTempProjectDirectory(filesToAnalyze[i].Path, "");
                    File.SetLastWriteTime(path, filesToAnalyze[i].LastWriteTime);
                    filesToDelete.Add(path);
                }

                // now create the project
                string unformattedProjectXml =
                    @"
                        <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>
	                        <Target Name=`Build`
	                                Inputs=`{0}`
	                                Outputs=`{1}`>
	                        </Target>
	                    </Project>
                    ";
                Project p = ObjectModelHelpers.CreateInMemoryProject(String.Format(unformattedProjectXml, inputs, outputs));

                // now do the dependency analysis
                ItemBucket itemBucket             = new ItemBucket(null, null, LookupHelpers.CreateLookup(itemsByName), 0);
                TargetDependencyAnalyzer analyzer = new TargetDependencyAnalyzer(ObjectModelHelpers.TempProjectDir, p.Targets["Build"], p.ParentEngine.LoggingServices, (BuildEventContext)null);

                return(analyzer.PerformDependencyAnalysis(itemBucket, out changedTargetInputs, out upToDateTargetInputs));
            }
            finally
            {
                // finally clean up
                foreach (string path in filesToDelete)
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Helper method for tests of IsAnyOutOfDate.
        /// The setup required here suggests that the TargetDependencyAnalyzer
        /// class should be refactored.
        /// </summary>
        /// <param name="input1Time"></param>
        /// <param name="input2Time"></param>
        /// <param name="output1Time"></param>
        /// <param name="output2Time"></param>
        /// <param name="isUpToDate"></param>
        private void IsAnyOutOfDateTestHelper
        (
            DateTime?input1Time,
            DateTime?input2Time,
            DateTime?output1Time,
            DateTime?output2Time,
            bool expectedAnyOutOfDate,
            bool includeInput1,
            bool includeInput2,
            bool includeOutput1,
            bool includeOutput2
        )
        {
            ArrayList inputs  = new ArrayList();
            ArrayList outputs = new ArrayList();

            string input1  = "NONEXISTENT_FILE";
            string input2  = "NONEXISTENT_FILE";
            string output1 = "NONEXISTENT_FILE";
            string output2 = "NONEXISTENT_FILE";

            try
            {
                if (input1Time != null)
                {
                    input1 = Path.GetTempFileName();
                    File.WriteAllText(input1, String.Empty);
                    File.SetLastWriteTime(input1, (DateTime)input1Time);
                }

                if (input2Time != null)
                {
                    input2 = Path.GetTempFileName();
                    File.WriteAllText(input2, String.Empty);
                    File.SetLastWriteTime(input2, (DateTime)input2Time);
                }

                if (output1Time != null)
                {
                    output1 = Path.GetTempFileName();
                    File.WriteAllText(output1, String.Empty);
                    File.SetLastWriteTime(output1, (DateTime)output1Time);
                }

                if (output2Time != null)
                {
                    output2 = Path.GetTempFileName();
                    File.WriteAllText(output2, String.Empty);
                    File.SetLastWriteTime(output2, (DateTime)output2Time);
                }

                if (includeInput1)
                {
                    inputs.Add(input1);
                }
                if (includeInput2)
                {
                    inputs.Add(input2);
                }
                if (includeOutput1)
                {
                    outputs.Add(output1);
                }
                if (includeOutput2)
                {
                    outputs.Add(output2);
                }

                DependencyAnalysisLogDetail detail;
                Assertion.AssertEquals(expectedAnyOutOfDate, TargetDependencyAnalyzer.IsAnyOutOfDate(out detail, Directory.GetCurrentDirectory(), inputs, outputs));
            }
            finally
            {
                if (File.Exists(input1))
                {
                    File.Delete(input1);
                }
                if (File.Exists(input2))
                {
                    File.Delete(input2);
                }
                if (File.Exists(output1))
                {
                    File.Delete(output1);
                }
                if (File.Exists(output2))
                {
                    File.Delete(output2);
                }
            }
        }