private static HashSet<string> AddReferencesFromClassPath(DependencyGraphBuilder builder, object proj, XDocument xclasspath, string basePath, string classpathFile) { var referencedProjects = new HashSet<string>(); if (xclasspath != null) { foreach (var xcpe in xclasspath.Descendants("classpathentry")) { var kind = xcpe.Attribute("kind") .Value; var path = xcpe.Attribute("path") .Value; if (string.IsNullOrWhiteSpace(kind) || string.IsNullOrWhiteSpace(path)) continue; if (kind == "lib") { var targetPath = PathUtils.ToAbsolute(basePath, path); var targetName = GuessLibraryName(targetPath); var language = GuessLanguage(targetPath); builder.AddLibraryReference(proj, null, targetName, null, targetPath, ToLocation(classpathFile, xcpe), language.AsList()); } else if (kind == "src" && path.StartsWith("/")) { var targetProjectName = path.Substring(1); builder.AddProjectReference(proj, targetProjectName, null, null, null, ToLocation(classpathFile, xcpe), null); referencedProjects.Add(targetProjectName); } } } return referencedProjects; }
public void BuildGraphForMethod_MethodCallAndTokenLoad_ReturnsCorrectDependencies() { var subject = new DependencyGraphBuilder(Disassembler, new ModuleReferenceComparer()); var result = subject.BuildGraphForMethod(ReflectionUtility.GetLambdaMethod(() => { Console.WriteLine(typeof(DependencyGraphBuilderTests)); })); Assert.AreEqual(2, result.Nodes.Count); }
private static void AddReferencesFromProject(DependencyGraphBuilder builder, object proj, XDocument xproject, string projectFile, HashSet<string> referencedProjects) { foreach (var xtarget in xproject.XPathSelectElements("/projectDescription/projects/project")) { var targetProjectName = xtarget.Value; if (!referencedProjects.Contains(targetProjectName)) builder.AddProjectReference(proj, targetProjectName, null, null, null, ToLocation(projectFile, xtarget), null); } }
public void BuildGraphForMethod_MethodCallAndTokenLoad_ReturnsCorrectDependencies() { var subject = new DependencyGraphBuilder(new MethodDisassembler(), new ModuleReferenceComparer()); var result = subject.BuildGraphForMethod(ReflectionUtility.GetLambdaMethod(() => { Console.WriteLine(typeof(DependencyGraphBuilderTests)); })); Assert.AreEqual(2, result.Nodes.Count); }
public void LoadProjects(List<string> paths, DependencyGraphBuilder builder, List<OutputEntry> warnings) { var projectFiles = new HashSet<string>(paths.SelectMany(folder => Directory.GetFiles(folder, ".project", SearchOption.AllDirectories)) .Select(Path.GetFullPath)); foreach (var projectFile in projectFiles) { // ReSharper disable once AssignNullToNotNullAttribute var classpathFile = Path.Combine(Path.GetDirectoryName(projectFile), ".classpath"); LoadProject(builder, projectFile, classpathFile); } }
public virtual void TestBuildingDependencyGraph() { var a = new A(); var b = new B(); var c = new C(); var d = new D(); var nodes = new object[] { a, b, c, d }; var edges = new DependencyGraphBuilder <object>(_dependencyExplorer) .BuildDependencyGraph(nodes).ToArray(); edges.Should().Contain(e => e.From == a && e.To == b); edges.Should().Contain(e => e.From == c && e.To == a); edges.Should().Contain(e => e.From == c && e.To == b); edges.Should().Contain(e => e.From == d && e.To == a); edges.Should().Contain(e => e.From == d && e.To == b); edges.Should().Contain(e => e.From == d && e.To == c); }
public AssemblyCallGraph Run() { var callGraph = RunJitCompiler(CreateUnorderedController()); if (_recordEventDetails) { UnorderedCallGraph = callGraph; } if (_targetScope != null && _targetScope.ScopeType == ScopeType.Method) { return(callGraph); } var dependencyGraph = DependencyGraphBuilder.BuildFromCallGraph(callGraph); DependencyResolver resolver = new DependencyResolver(dependencyGraph); var methodList = resolver.GetOrderedMethodList(); if (methodList.Methods.Count == 0) { return(callGraph); } string methodListFile = SerializeMethodList(methodList); try { var orderedCallGraph = RunJitCompiler(CreateOrderedController(methodListFile)); return(orderedCallGraph); } finally { if (File.Exists(methodListFile)) { File.Delete(methodListFile); } } }
private static void LoadProjects(List<string> paths, DependencyGraphBuilder builder, List<OutputEntry> warnings, string filenamePattern, params string[] defaultLanguage) { var csprojsFiles = new HashSet<string>(paths.SelectMany(folder => Directory.GetFiles(folder, filenamePattern, SearchOption.AllDirectories)) .Select(Path.GetFullPath)); List<VSProjReader> csprojs = csprojsFiles.Select(f => new VSProjReader(f)) .OrderBy(n => n.Filename, StringComparer.CurrentCultureIgnoreCase) .ToList(); foreach (VSProjReader csproj in csprojs) { object proj = builder.AddProject(csproj.Name, csproj.AssemblyName, csproj.ProjectGuid, csproj.Filename, defaultLanguage); foreach (VSProjReader.ProjectReference csref in csproj.ProjectReferences) builder.AddProjectReference(proj, csref.Name, null, csref.ProjectGuid, csref.Include, new Location(csproj.Filename, csref.LineNumber), defaultLanguage); foreach (VSProjReader.Reference csref in csproj.References) { IEnumerable<string> language; if (csref.HintPath == null && csref.Include.GetPublicKey() == null) // A system lib language = defaultLanguage; else language = null; builder.AddLibraryReference(proj, null, csref.Include.Name, null, csref.HintPath, new Location(csproj.Filename, csref.LineNumber), language); } foreach (VSProjReader.COMReference csref in csproj.COMReferences) builder.AddLibraryReference(proj, null, csref.Include, csref.Guid, null, new Location(csproj.Filename, csref.LineNumber), null); } var externalCsprojFiles = csprojs.SelectMany(p => p.ProjectReferences) .Select(r => r.Include) .Distinct() .Where(f => !csprojsFiles.Contains(f)) .OrderBy(n => n, StringComparer.CurrentCultureIgnoreCase); foreach (string externalCsprojFile in externalCsprojFiles) { if (paths.Any(p => externalCsprojFile.StartsWith(p + Path.DirectorySeparatorChar))) { OutputMessage msg = new OutputMessage().Append("Failed to load a referenced project: ") .Append(externalCsprojFile); warnings.Add(new LoadingOutputEntry("Referenced project not found", msg)); continue; } try { var csproj = new VSProjReader(externalCsprojFile); builder.AddProject(csproj.Name, csproj.AssemblyName, csproj.ProjectGuid, csproj.Filename, defaultLanguage); } catch (IOException) { OutputMessage msg = new OutputMessage().Append("Failed to load a project outside of input folders: ") .Append(externalCsprojFile); warnings.Add(new LoadingOutputEntry("External project not found", msg)); } } }
public void LoadProjects(List<string> paths, DependencyGraphBuilder builder, List<OutputEntry> warnings) { LoadProjects(paths, builder, warnings, "*.csproj", "C#"); LoadProjects(paths, builder, warnings, "*.vbproj", "Visual Basic"); LoadProjects(paths, builder, warnings, "*.fsproj", "F#"); }
public void SetUp() { _testAssembly = GetType().Assembly; _graphBuilder = new DependencyGraphBuilder(); }
private void LoadProject(DependencyGraphBuilder builder, string projectFile, string classpathFile) { var xproject = XDocument.Load(projectFile, LoadOptions.SetLineInfo); if (xproject.Root == null || xproject.Root.Name != "projectDescription") throw new IOException("Invalid .project file: " + projectFile); XDocument xclasspath = null; if (File.Exists(classpathFile)) { xclasspath = XDocument.Load(classpathFile, LoadOptions.SetLineInfo); if (xclasspath.Root == null || xclasspath.Root.Name != "classpath") throw new IOException("Invalid .classpath file: " + classpathFile); } var name = xproject.XPathSelectElement("/projectDescription/name") .Value; var basePath = Path.GetDirectoryName(classpathFile); var languages = FindLanguages(xproject); var proj = builder.AddProject(name, name, null, projectFile, languages); var referencedProjects = AddReferencesFromClassPath(builder, proj, xclasspath, basePath, classpathFile); AddReferencesFromProject(builder, proj, xproject, projectFile, referencedProjects); }