Exemple #1
0
        public void TestSvnLinkParser()
        {
            string inputLinux    = "/path/to/src/oa-s160/linux-x86/src/folder/test.c:30";
            string expectedLinux = "branches/sprint_160/src/folder/test.c:30";

            Assert.Equal(expectedLinux, DynatraceSourceLink.GetRepoPathIfAvailable(inputLinux));

            string inputWindows    = @"c:\path\to\src\oa-s160\linux-x86\src\folder\test.c:30";
            string expectedWindows = @"branches/sprint_160/src\folder\test.c:30";

            Assert.Equal(expectedWindows, DynatraceSourceLink.GetRepoPathIfAvailable(inputWindows));

            string inputTrunk    = @"c:\path\to\src\trunk\src\folder\test.c:30";
            string expectedTrunk = @"trunk\src\folder\test.c:30";

            Assert.Equal(expectedTrunk, DynatraceSourceLink.GetRepoPathIfAvailable(inputTrunk));

            string inputSprint    = @"c:\path\to\src\sprint_160\src\folder\test.c:30";
            string expectedSprint = @"branches/sprint_160\src\folder\test.c:30";

            Assert.Equal(expectedSprint, DynatraceSourceLink.GetRepoPathIfAvailable(inputSprint));

            string inputInvalid = @"c:\path\to\src\folder\test.c:30";

            Assert.Null(DynatraceSourceLink.GetRepoPathIfAvailable(inputInvalid));
        }
        public void ProvideSourceFiles(string directory)
        {
            IList <Task>   tasks = new List <Task>();
            IList <string> files = new List <string>();

            if (result.ThreadInformation == null)
            {
                return;
            }

            string repoUrl  = Environment.GetEnvironmentVariable(EnvironmentName.REPOSITORY_URL.Name);
            string repoAuth = Environment.GetEnvironmentVariable(EnvironmentName.REPOSITORY_AUTHENTICATION.Name);

            if (string.IsNullOrEmpty(repoUrl))
            {
                return;
            }
            foreach (var thread in result.ThreadInformation)
            {
                if (thread.Value.StackTrace == null)
                {
                    continue;
                }
                foreach (var stackframe in thread.Value.StackTrace)
                {
                    string file = stackframe.SourceInfo?.File;
                    if (file == null)
                    {
                        // no source info
                        continue;
                    }
                    string repoPath = DynatraceSourceLink.GetRepoPathIfAvailable(file);
                    if (repoPath == null)
                    {
                        // source not available
                        continue;
                    }
                    string url = repoUrl + repoPath;

                    // GDB requires paths beginning with /src. Therefore, all source files must be merged into a common /src directory.
                    string shortPath = file.Substring(1);
                    if (shortPath.Contains("/src/"))
                    {
                        shortPath = shortPath.Substring(shortPath.IndexOf("/src/") + 1);
                    }
                    IFileInfo targetFile = filesystem.GetFile(Path.Combine(directory, shortPath));
                    if (files.Contains(targetFile.FullName))
                    {
                        continue;
                    }
                    files.Add(targetFile.FullName);
                    tasks.Add(requestHandler.DownloadFromUrlAsync(url, targetFile.FullName, repoAuth));
                }
            }
            foreach (Task t in tasks)
            {
                t.Wait();
            }
        }
Exemple #3
0
 public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
 {
     if (string.IsNullOrEmpty(SourceFile))
     {
         output.TagName = string.Empty;
         output.Attributes.Clear();
         output.Content.Clear();
     }
     else
     {
         if (IsDynatraceLinkAvailable())
         {
             output.TagName = "a";
             output.Attributes.Add("href", RepositoryUrl + DynatraceSourceLink.GetRepoPathIfAvailable(SourceFile));
             output.Attributes.Add("target", "_blank");
         }
         else
         {
             output.TagName = string.Empty;
             output.Attributes.Clear();
         }
     }
     return(base.ProcessAsync(context, output));
 }