/// <summary>
        /// Crete ClassFileInfo for a single Class
        /// </summary>
        /// <param name="inClass"></param>
        /// <returns></returns>
        public FileWriteInfo CreateClassFile(ClassContainer inClass)
        {
            if (!inClass.IsAnalyzed)
            {
                throw new Exception("Cannot create String from a Class that has not been typecleaned");
            }
            var tmpInfo = new FileWriteInfo()
            {
                FullName     = inClass.Type.Type.Name,
                RelativePath = inClass.Namespace?.Replace('.', Path.PathSeparator),
            };
            var tmpStringBuilder = new StringBuilder();

            tmpStringBuilder.AppendLine(CreateImports(inClass));
            tmpStringBuilder.AppendLine();

            //Namespace
            AddComment(tmpStringBuilder, inClass.NamespaceComment, 0, true);
            tmpStringBuilder.AppendLine($"namespace {inClass.Namespace}");
            tmpStringBuilder.AppendLine("{");

            var tmpIndentDepth = 1;

            AddClassContainerString(inClass, tmpStringBuilder, tmpIndentDepth);

            tmpStringBuilder.AppendLine("}");
            tmpInfo.Content = tmpStringBuilder.ToString();
            return(tmpInfo);
        }
Example #2
0
        public void InputItemThatCorrelatesWithMultipleTransformOutputItems()
        {
            string inputs  = "@(Items)";
            string outputs = "@(Items->'%(Filename).dll');@(Items->'%(Filename).xml')";

            FileWriteInfo[] filesToAnalyze = new FileWriteInfo[]
            {
                new FileWriteInfo("a.cs", yesterday),
                new FileWriteInfo("a.dll", today),
                new FileWriteInfo("a.xml", today),
                new FileWriteInfo("b.cs", yesterday),
                new FileWriteInfo("b.dll", twoDaysAgo),
                new FileWriteInfo("b.xml", today),
                new FileWriteInfo("c.cs", yesterday),
                new FileWriteInfo("c.dll", today),
                new FileWriteInfo("c.xml", today)
            };

            BuildItemGroup items = new BuildItemGroup();

            items.AddNewItem("Items", "a.cs");
            items.AddNewItem("Items", "b.cs");
            items.AddNewItem("Items", "c.cs");

            Hashtable itemsByName = new Hashtable(StringComparer.OrdinalIgnoreCase);

            itemsByName.Add("Items", items);

            DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs);

            Assertion.AssertEquals("Should only build partially.", DependencyAnalysisResult.IncrementalBuild, result);
        }
Example #3
0
        public void InputItemThatCorrelatesWithMultipleTransformOutputItems()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            string          inputs  = "@(Items)";
            string          outputs = "@(Items->'%(Filename).dll');@(Items->'%(Filename).xml')";

            FileWriteInfo[] filesToAnalyze = new FileWriteInfo[]
            {
                new FileWriteInfo("a.cs", _yesterday),
                new FileWriteInfo("a.dll", _today),
                new FileWriteInfo("a.xml", _today),
                new FileWriteInfo("b.cs", _yesterday),
                new FileWriteInfo("b.dll", _twoDaysAgo),
                new FileWriteInfo("b.xml", _today),
                new FileWriteInfo("c.cs", _yesterday),
                new FileWriteInfo("c.dll", _today),
                new FileWriteInfo("c.xml", _today)
            };

            List <ProjectItemInstance> items = new List <ProjectItemInstance>();

            items.Add(new ProjectItemInstance(project, "Items", "a.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "b.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "c.cs", project.FullPath));

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

            itemsByName.ImportItems(items);

            DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs);

            Assert.Equal(DependencyAnalysisResult.IncrementalBuild, result); // "Should only build partially."
        }
        public void Generate(VersionVariables variables, FileWriteInfo writeInfo)
        {
            var fileName  = writeInfo.FileName;
            var directory = writeInfo.WorkingDirectory;
            var filePath  = Path.Combine(directory, fileName);

            string originalFileContents = null;

            if (File.Exists(filePath))
            {
                originalFileContents = fileSystem.ReadAllText(filePath);
            }

            var fileExtension = Path.GetExtension(filePath);
            var template      = templateManager.GetTemplateFor(fileExtension);
            var addFormat     = templateManager.GetAddFormatFor(fileExtension);

            var members = string.Join(System.Environment.NewLine, variables.Select(v => string.Format("    " + addFormat, v.Key, v.Value)));

            var fileContents = string.Format(template, members);

            if (fileContents != originalFileContents)
            {
                fileSystem.WriteAllText(filePath, fileContents);
            }
        }
Example #5
0
 public void GenerateGitVersionInformation(VersionVariables variables, FileWriteInfo fileWriteInfo)
 {
     using (this.gitVersionInfoGenerator)
     {
         this.gitVersionInfoGenerator.Execute(variables, new GitVersionInfoContext(gitVersionOptions.WorkingDirectory, fileWriteInfo.FileName, fileWriteInfo.FileExtension));
     }
 }
Example #6
0
 private async void WriteFinished(FileWriteInfo info)
 {
     Log.Info("Downloader WriteFinished", $"File write finished to {info.FilePath}");
     Debug.WriteLine($"File write finished to {info.FilePath}");
     if (State != TransferStates.CANCELED)
     {
         await InsertInGallery(info.FilePath);
     }
 }
Example #7
0
        public void MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems()
        {
            Console.WriteLine("MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems");
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            string          inputs  = "@(Items);@(MoreItems)";
            string          outputs = "@(Items->'%(Filename).dll');@(MoreItems->'%(Filename).xml')";

            FileWriteInfo[] filesToAnalyze = new FileWriteInfo[]
            {
                new FileWriteInfo("a.cs", _yesterday),
                new FileWriteInfo("a.txt", _yesterday),
                new FileWriteInfo("a.dll", _today),
                new FileWriteInfo("a.xml", _today),
                new FileWriteInfo("b.cs", _yesterday),
                new FileWriteInfo("b.txt", _yesterday),
                new FileWriteInfo("b.dll", _twoDaysAgo),
                new FileWriteInfo("b.xml", _today),
                new FileWriteInfo("c.cs", _yesterday),
                new FileWriteInfo("c.txt", _yesterday),
                new FileWriteInfo("c.dll", _today),
                new FileWriteInfo("c.xml", _today)
            };

            List <ProjectItemInstance> items = new List <ProjectItemInstance>();

            items.Add(new ProjectItemInstance(project, "Items", "a.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "b.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "c.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "MoreItems", "a.txt", project.FullPath));
            items.Add(new ProjectItemInstance(project, "MoreItems", "b.txt", project.FullPath));
            items.Add(new ProjectItemInstance(project, "MoreItems", "c.txt", project.FullPath));

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

            itemsByName.ImportItems(items);

            ItemDictionary <ProjectItemInstance> changedTargetInputs  = new ItemDictionary <ProjectItemInstance>();
            ItemDictionary <ProjectItemInstance> upToDateTargetInputs = new ItemDictionary <ProjectItemInstance>();
            DependencyAnalysisResult             result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs, out changedTargetInputs, out upToDateTargetInputs);

            foreach (ProjectItemInstance itemInstance in changedTargetInputs)
            {
                Console.WriteLine("Changed: {0}:{1}", itemInstance.ItemType, itemInstance.EvaluatedInclude);
            }

            Assert.Equal(DependencyAnalysisResult.IncrementalBuild, result); // "Should only build partially."

            // Even though they were all up to date, we still expect to see an empty marker
            // so that lookups can correctly *not* find items of that type
            Assert.True(changedTargetInputs.HasEmptyMarker("MoreItems"));
        }
 public FileWriteFinishedEventArgs(FileWriteInfo fileWriteInfo)
 {
     FileWriteInfo = fileWriteInfo;
 }
        private DependencyAnalysisResult PerformDependencyAnalysisTestHelper
        (
            FileWriteInfo[] filesToAnalyze,
            ItemDictionary<ProjectItemInstance> itemsByName,
            string inputs,
            string outputs,
            out ItemDictionary<ProjectItemInstance> changedTargetInputs,
            out ItemDictionary<ProjectItemInstance> 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.SetCreationTime(path, filesToAnalyze[i].LastWriteTime);
                    File.SetLastWriteTime(path, filesToAnalyze[i].LastWriteTime);
                    filesToDelete.Add(path);
                }

                // Wait
                Thread.Sleep(50);

                // now create the project
                string unformattedProjectXml = ObjectModelHelpers.CleanupFileContents(
                    @"<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
	                      <Target Name='Build'
	                              Inputs=""{0}""
	                              Outputs=""{1}"">
	                      </Target>
	                  </Project>");

                string projectFile = Path.Combine(ObjectModelHelpers.TempProjectDir, "temp.proj");
                string formattedProjectXml = String.Format(unformattedProjectXml, inputs, outputs);
                File.WriteAllText(projectFile, formattedProjectXml);

                // Wait
                Thread.Sleep(50);

                filesToDelete.Add(projectFile);

                Project project = new Project(projectFile);
                ProjectInstance p = project.CreateProjectInstance();

                // now do the dependency analysis
                ItemBucket itemBucket = new ItemBucket(null, null, new Lookup(itemsByName, new PropertyDictionary<ProjectPropertyInstance>(), null), 0);
                TargetUpToDateChecker analyzer = new TargetUpToDateChecker(p, p.Targets["Build"], _mockHost, BuildEventContext.Invalid);

                return analyzer.PerformDependencyAnalysis(itemBucket, out changedTargetInputs, out upToDateTargetInputs);
            }
            finally
            {
                // finally clean up
                foreach (string path in filesToDelete)
                {
                    if (File.Exists(path)) File.Delete(path);
                }

                ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
            }
        }
 /// <summary>
 /// Helper method for tests of PerformDependencyAnalysis.
 /// The setup required here suggests that the TargetDependencyAnalyzer
 /// class should be refactored.
 /// </summary>
 private DependencyAnalysisResult PerformDependencyAnalysisTestHelper
 (
     FileWriteInfo[] filesToAnalyze,
     ItemDictionary<ProjectItemInstance> itemsByName,
     string inputs,
     string outputs
 )
 {
     ItemDictionary<ProjectItemInstance> h1 = new ItemDictionary<ProjectItemInstance>();
     ItemDictionary<ProjectItemInstance> h2 = new ItemDictionary<ProjectItemInstance>();
     return PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs, out h1, out h2);
 }
        public void MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems()
        {
            Console.WriteLine("MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems");
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            string inputs = "@(Items);@(MoreItems)";
            string outputs = "@(Items->'%(Filename).dll');@(MoreItems->'%(Filename).xml')";

            FileWriteInfo[] filesToAnalyze = new FileWriteInfo[]
                                             {
                                                 new FileWriteInfo("a.cs", _yesterday),
                                                 new FileWriteInfo("a.txt", _yesterday),
                                                 new FileWriteInfo("a.dll", _today),
                                                 new FileWriteInfo("a.xml", _today),
                                                 new FileWriteInfo("b.cs", _yesterday),
                                                 new FileWriteInfo("b.txt", _yesterday),
                                                 new FileWriteInfo("b.dll", _twoDaysAgo),
                                                 new FileWriteInfo("b.xml", _today),
                                                 new FileWriteInfo("c.cs", _yesterday),
                                                 new FileWriteInfo("c.txt", _yesterday),
                                                 new FileWriteInfo("c.dll", _today),
                                                 new FileWriteInfo("c.xml", _today)
                                             };

            List<ProjectItemInstance> items = new List<ProjectItemInstance>();
            items.Add(new ProjectItemInstance(project, "Items", "a.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "b.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "c.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "MoreItems", "a.txt", project.FullPath));
            items.Add(new ProjectItemInstance(project, "MoreItems", "b.txt", project.FullPath));
            items.Add(new ProjectItemInstance(project, "MoreItems", "c.txt", project.FullPath));

            ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();
            itemsByName.ImportItems(items);

            ItemDictionary<ProjectItemInstance> changedTargetInputs = new ItemDictionary<ProjectItemInstance>();
            ItemDictionary<ProjectItemInstance> upToDateTargetInputs = new ItemDictionary<ProjectItemInstance>();
            DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs, out changedTargetInputs, out upToDateTargetInputs);

            foreach (ProjectItemInstance itemInstance in changedTargetInputs)
            {
                Console.WriteLine("Changed: {0}:{1}", itemInstance.ItemType, itemInstance.EvaluatedInclude);
            }

            Assert.Equal(DependencyAnalysisResult.IncrementalBuild, result); // "Should only build partially."

            // Even though they were all up to date, we still expect to see an empty marker
            // so that lookups can correctly *not* find items of that type
            Assert.True(changedTargetInputs.HasEmptyMarker("MoreItems"));
        }
        public void InputItemThatCorrelatesWithMultipleTransformOutputItems()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            string inputs = "@(Items)";
            string outputs = "@(Items->'%(Filename).dll');@(Items->'%(Filename).xml')";

            FileWriteInfo[] filesToAnalyze = new FileWriteInfo[]
                                             {
                                                 new FileWriteInfo("a.cs", _yesterday),
                                                 new FileWriteInfo("a.dll", _today),
                                                 new FileWriteInfo("a.xml", _today),
                                                 new FileWriteInfo("b.cs", _yesterday),
                                                 new FileWriteInfo("b.dll", _twoDaysAgo),
                                                 new FileWriteInfo("b.xml", _today),
                                                 new FileWriteInfo("c.cs", _yesterday),
                                                 new FileWriteInfo("c.dll", _today),
                                                 new FileWriteInfo("c.xml", _today)
                                             };

            List<ProjectItemInstance> items = new List<ProjectItemInstance>();
            items.Add(new ProjectItemInstance(project, "Items", "a.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "b.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "c.cs", project.FullPath));

            ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();
            itemsByName.ImportItems(items);

            DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs);

            Assert.Equal(DependencyAnalysisResult.IncrementalBuild, result); // "Should only build partially."
        }
Example #13
0
 public FileWriteFinishedEventArgs(FileWriteInfo fileWriteInfo) : base(fileWriteInfo)
 {
 }
        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);
                }
            }
        }
 /// <summary>
 /// Helper method for tests of PerformDependencyAnalysis.
 /// The setup required here suggests that the TargetDependencyAnalyzer
 /// class should be refactored.
 /// </summary>
 private DependencyAnalysisResult PerformDependencyAnalysisTestHelper
 (
     FileWriteInfo[] filesToAnalyze,
     Hashtable itemsByName,
     string inputs,
     string outputs
 )
 {
     Hashtable h1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
     Hashtable h2 = new Hashtable(StringComparer.OrdinalIgnoreCase);
     return PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs, out h1, out h2);
 }
        public void InputItemThatCorrelatesWithMultipleTransformOutputItems()
        {
            string inputs = "@(Items)";
            string outputs = "@(Items->'%(Filename).dll');@(Items->'%(Filename).xml')";

            FileWriteInfo[] filesToAnalyze = new FileWriteInfo[] 
                                             { 
                                                 new FileWriteInfo("a.cs", yesterday),
                                                 new FileWriteInfo("a.dll", today),
                                                 new FileWriteInfo("a.xml", today),
                                                 new FileWriteInfo("b.cs", yesterday),
                                                 new FileWriteInfo("b.dll", twoDaysAgo),
                                                 new FileWriteInfo("b.xml", today),
                                                 new FileWriteInfo("c.cs", yesterday),
                                                 new FileWriteInfo("c.dll", today),
                                                 new FileWriteInfo("c.xml", today)
                                             };

            BuildItemGroup items = new BuildItemGroup();
            items.AddNewItem("Items", "a.cs");
            items.AddNewItem("Items", "b.cs");
            items.AddNewItem("Items", "c.cs");
            
            Hashtable itemsByName = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemsByName.Add("Items", items);

            DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs);

            Assertion.AssertEquals("Should only build partially.", DependencyAnalysisResult.IncrementalBuild, result);
        }