Exemplo n.º 1
0
        public void ClassProxyGeneratorForNestedClasses()
        {
            var nestedClassDescription = new ClassDescription(
                "NestedClass",
                null,
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription>(),
                new List <string>(),
                new List <ClassDescription>(),
                isNested: true);

            var mainClassDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription>(),
                new List <string>(),
                new List <ClassDescription> {
                nestedClassDescription
            },
                isNested: false);

            var libraryDescripton = new LibraryDescription("MyLibrary", new Dictionary <string, ClassDescription>());

            libraryDescripton.AddClassDescription(mainClassDescription,
                                                  "packageName.MyClass");

            libraryDescripton.AddClassDescription(nestedClassDescription, "packageName.MyClass$NestedClass");

            var classProxyGenerator = new MockClassProxyGenerator();

            new LibraryProxyGenerator(classProxyGenerator).Generate(libraryDescripton);
        }
Exemplo n.º 2
0
        public void CallClassProxyGeneratorForDependencies()
        {
            var dependenciesClasses   = new List <ClassDescription>();
            var dependenciesFullNames = new List <string>
            {
                "packageName.DependenceClass0",
                "packageName.DependenceClass1",
                "packageName.DependenceClass2"
            };

            for (int i = 0; i < 3; i++)
            {
                var dependence = new ClassDescription(
                    $"DependenceClass{i}",
                    "packageName",
                    new List <ModifierDescription>(),
                    new List <FieldDescription>(),
                    new List <MethodDescription>(),
                    new List <string>(),
                    new List <ClassDescription>(),
                    isNested: false);

                dependenciesClasses.Add(dependence);
            }

            var mainClassDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription>(),
                dependenciesFullNames,
                new List <ClassDescription>(),
                isNested: false);

            var libraryDescripton = new LibraryDescription("MyLibrary", new Dictionary <string, ClassDescription>());

            libraryDescripton.AddClassDescription(mainClassDescription,
                                                  "packageName.MyClass");
            for (int i = 0; i < 3; i++)
            {
                libraryDescripton.AddClassDescription(dependenciesClasses[i], dependenciesFullNames[i]);
            }

            var classProxyGenerator = new MockClassProxyGenerator();

            new LibraryProxyGenerator(classProxyGenerator).Generate(libraryDescripton);

            Assert.AreEqual(4, classProxyGenerator.CallsArguments.Count, "A lot of classes was proxy");
            Assert.AreEqual(
                "packageName.MyClass",
                libraryDescripton.GetFullName(classProxyGenerator.CallsArguments[0]),
                "ClassProxyGenerator call order incorrect");

            for (int i = 1; i < 4; i++)
            {
                var name = libraryDescripton.GetFullName(classProxyGenerator.CallsArguments[i]);
                Assert.AreEqual(dependenciesFullNames[i - 1], name, "ClassProxyGenerator call order incorrect");
            }
        }
Exemplo n.º 3
0
        private void AddDiagnostics(List <DiagnosticMessage> messages,
                                    LibraryDescription library,
                                    string message,
                                    DiagnosticMessageSeverity severity,
                                    string errorCode)
        {
            // A (in project.json) -> B (unresolved) (not in project.json)
            foreach (var source in GetRangesWithSourceLocations(library).Distinct())
            {
                // We only care about things requested in this project
                if (!string.Equals(_projectPath, source.SourceFilePath))
                {
                    continue;
                }

                messages.Add(
                    new DiagnosticMessage(
                        errorCode,
                        message,
                        source.SourceFilePath,
                        severity,
                        source.SourceLine,
                        source.SourceColumn,
                        library));
            }
        }
Exemplo n.º 4
0
        private LibraryExport ExportSingle(LibraryDescription description = null)
        {
            var rootProject = new Project()
            {
                Name         = "RootProject",
                CompilerName = "csc"
            };

            var rootProjectDescription = new ProjectDescription(
                new LibraryRange(),
                rootProject,
                new LibraryRange[] { },
                new TargetFrameworkInformation(),
                true);

            if (description == null)
            {
                description = rootProjectDescription;
            }
            else
            {
                description.Parents.Add(rootProjectDescription);
            }

            var libraryManager = new LibraryManager(new[] { description }, new DiagnosticMessage[] { }, "");
            var allExports     = new LibraryExporter(rootProjectDescription, libraryManager, "config", "runtime", "basepath", "solutionroot").GetAllExports();
            var export         = allExports.Single();

            return(export);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a LibraryExport from LibraryDescription.
        ///
        /// When the library is not resolved the LibraryExport is created nevertheless.
        /// </summary>
        private LibraryExport GetExport(LibraryDescription library)
        {
            if (!library.Resolved)
            {
                // For a unresolved project reference returns a export with empty asset.
                return(new LibraryExport(library: library,
                                         compileAssemblies: Enumerable.Empty <LibraryAsset>(),
                                         sourceReferences: Enumerable.Empty <string>(),
                                         nativeLibraries: Enumerable.Empty <LibraryAsset>(),
                                         runtimeAssets: Enumerable.Empty <LibraryAsset>(),
                                         runtimeAssemblies: EmptyArray <LibraryAsset> .Value,
                                         analyzers: EmptyArray <AnalyzerReference> .Value));
            }

            if (Equals(LibraryType.Package, library.Identity.Type))
            {
                return(ExportPackage((PackageDescription)library));
            }
            else if (Equals(LibraryType.Project, library.Identity.Type))
            {
                return(ExportProject((ProjectDescription)library));
            }
            else
            {
                return(ExportFrameworkLibrary(library));
            }
        }
Exemplo n.º 6
0
        private IEnumerable <ProjectGraphNode> TraverseNonProject(LibraryDescription root, IDictionary <string, LibraryDescription> lookup)
        {
            Stack <LibraryDescription> libraries = new Stack <LibraryDescription>();

            libraries.Push(root);
            while (libraries.Count > 0)
            {
                var  current      = libraries.Pop();
                bool foundProject = false;
                foreach (var dependency in current.Dependencies)
                {
                    LibraryDescription libraryDescription;
                    if (lookup.TryGetValue(dependency.Name, out libraryDescription))
                    {
                        if (libraryDescription.Identity.Type.Equals(LibraryType.Project))
                        {
                            foundProject = true;
                            yield return(TraverseProject((ProjectDescription)libraryDescription, lookup));
                        }
                        else
                        {
                            libraries.Push(libraryDescription);
                        }
                    }
                }
                // if package didn't have any project dependencies inside remove it from lookup
                // and do not traverse anymore
                if (!foundProject)
                {
                    lookup.Remove(current.Identity.Name);
                }
            }
        }
Exemplo n.º 7
0
        private static DiagnosticMessage Validate(LibraryDescription library,
                                                  HashSet<string> projectCandidates,
                                                  Dictionary<string, LibraryRange> rootDependencies)
        {
            if (!library.Resolved || projectCandidates == null)
            {
                return null;
            }

            var foundCandidate = projectCandidates.Contains(library.Identity.Name);

            if ((library.Identity.Type == LibraryType.Project && !foundCandidate) ||
                (library.Identity.Type == LibraryType.Package && foundCandidate))
            {
                library.Resolved = false;

                var libraryRange = rootDependencies[library.Identity.Name];

                return new DiagnosticMessage(
                    ErrorCodes.NU1010,
                    $"The type of dependency {library.Identity.Name} was changed.",
                    libraryRange.SourceFilePath,
                    DiagnosticMessageSeverity.Error,
                    libraryRange.SourceLine,
                    libraryRange.SourceColumn,
                    library);
            }

            return null;
        }
Exemplo n.º 8
0
 private IEnumerable<ProjectGraphNode> TraverseNonProject(LibraryDescription root, IDictionary<string, LibraryDescription> lookup)
 {
     Stack<LibraryDescription> libraries = new Stack<LibraryDescription>();
     libraries.Push(root);
     while (libraries.Count > 0)
     {
         var current = libraries.Pop();
         bool foundProject = false;
         foreach (var dependency in current.Dependencies)
         {
             LibraryDescription libraryDescription;
             if (lookup.TryGetValue(dependency.Name, out libraryDescription))
             {
                 if (libraryDescription.Identity.Type.Equals(LibraryType.Project))
                 {
                     foundProject = true;
                     yield return TraverseProject((ProjectDescription) libraryDescription, lookup);
                 }
                 else
                 {
                     libraries.Push(libraryDescription);
                 }
             }
         }
         // if package didn't have any project dependencies inside remove it from lookup
         // and do not traverse anymore
         if (!foundProject)
         {
             lookup.Remove(current.Identity.Name);
         }
     }
 }
Exemplo n.º 9
0
        private DiagnosticMessage ValidateDependency(LibraryDescription library, HashSet <string> projectCandidates)
        {
            if (!library.Resolved || projectCandidates == null)
            {
                return(null);
            }

            var foundCandidate = projectCandidates.Contains(library.Identity.Name);

            if ((library.Type == LibraryTypes.Project && !foundCandidate) ||
                (library.Type == LibraryTypes.Package && foundCandidate))
            {
                library.Resolved = false;
                library.Type     = LibraryTypes.Unresolved;

                return(new DiagnosticMessage(
                           DiagnosticMonikers.NU1010,
                           $"The type of dependency {library.Identity.Name} was changed.",
                           library.RequestedRange.FileName,
                           DiagnosticMessageSeverity.Error,
                           library.RequestedRange.Line,
                           library.RequestedRange.Column,
                           library));
            }

            return(null);
        }
        private static DiagnosticMessage Validate(LibraryDescription library,
                                                  HashSet <string> projectCandidates,
                                                  Dictionary <string, LibraryRange> rootDependencies)
        {
            if (!library.Resolved || projectCandidates == null)
            {
                return(null);
            }

            var foundCandidate = projectCandidates.Contains(library.Identity.Name);

            if ((library.Identity.Type == LibraryType.Project && !foundCandidate) ||
                (library.Identity.Type == LibraryType.Package && foundCandidate))
            {
                library.Resolved = false;

                var libraryRange = rootDependencies[library.Identity.Name];

                return(new DiagnosticMessage(
                           ErrorCodes.NU1010,
                           $"The type of dependency {library.Identity.Name} was changed.",
                           libraryRange.SourceFilePath,
                           DiagnosticMessageSeverity.Error,
                           libraryRange.SourceLine,
                           libraryRange.SourceColumn,
                           library));
            }

            return(null);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Create a ProjectReferenceDescription from given LibraryDescription. If the library doesn't 
 /// represent a project reference returns null.
 /// </summary>
 public static ProjectReferenceDescription Create(LibraryDescription library)
 {
     if (library is ProjectDescription)
     {
         return new ProjectReferenceDescription
         {
             Framework = library.Framework.ToPayload(),
             Name = library.Identity.Name,
             Path = library.Path
         };
     }
     else if (library is MSBuildProjectDescription)
     {
         return new ProjectReferenceDescription
         {
             Framework = library.Framework.ToPayload(),
             Name = library.Identity.Name,
             Path = ((MSBuildProjectDescription)library).MSBuildProjectPath,
         };
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 12
0
        public static DependencyDescription Create(LibraryDescription library,
                                                   List<DiagnosticMessage> diagnostics,
                                                   IDictionary<string, LibraryExport> exportsLookup)
        {
            var result = new DependencyDescription
            {
                Name = library.Identity.Name,
                DisplayName = library.Identity.Name,
                Version = library.Identity.Version?.ToNormalizedString(),
                Type = library.Identity.Type.Value,
                Resolved = library.Resolved,
                Path = library.Path,
                Dependencies = library.Dependencies.Select(dependency => GetDependencyItem(dependency, exportsLookup)),
                Errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error)
                                    .Select(d => new DiagnosticMessageView(d)),
                Warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning)
                                      .Select(d => new DiagnosticMessageView(d))
            };

            var msbuildLibrary = library as MSBuildProjectDescription;
            if (msbuildLibrary != null)
            {
                result.Path = msbuildLibrary.MSBuildProjectPath;
            }

            return result;
        }
Exemplo n.º 13
0
        private static DependencyDescription CreateDependencyDescription(LibraryDescription library,
                                                                         IEnumerable <DiagnosticMessage> diagnostics,
                                                                         int protocolVersion)
        {
            var result = new DependencyDescription
            {
                Name         = library.Identity.Name,
                DisplayName  = library.Identity.IsGacOrFrameworkReference ? library.RequestedRange.GetReferenceAssemblyName() : library.Identity.Name,
                Version      = library.Identity.Version?.ToString(),
                Type         = library.Type,
                Resolved     = library.Resolved,
                Path         = library.Path,
                Dependencies = library.Dependencies.Select(dependency => new DependencyItem
                {
                    Name    = dependency.Name,
                    Version = dependency.Library?.Identity?.Version?.ToString()
                }),
                Errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error)
                         .Select(d => new DiagnosticMessageView(d)),
                Warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning)
                           .Select(d => new DiagnosticMessageView(d))
            };

            if (protocolVersion < 3 && !library.Resolved)
            {
                result.Type = "Unresolved";
            }

            return(result);
        }
Exemplo n.º 14
0
        private void DumpPackageContents(LibraryDescription library, SelectionCriteria criteria)
        {
            var packageContents = new ContentItemCollection();

            packageContents.Load(library.Path);

            var group = packageContents.FindBestItemGroup(criteria, Patterns.ManagedAssemblies);

            if (group == null)
            {
                // No matching groups
                return;
            }

            Logger.WriteInformation(library.ToString().White());
            Logger.WriteInformation("=========================");
            foreach (var item in group.Items)
            {
                Logger.WriteInformation(item.Path.White());

                foreach (var property in item.Properties)
                {
                    Logger.WriteInformation(property.Key.Yellow() + " = " + property.Value);
                }
            }

            Logger.WriteInformation("=========================");
            Console.WriteLine();
        }
Exemplo n.º 15
0
 /// <summary>
 /// Create a ProjectReferenceDescription from given LibraryDescription. If the library doesn't
 /// represent a project reference returns null.
 /// </summary>
 public static ProjectReferenceDescription Create(LibraryDescription library)
 {
     if (library is ProjectDescription)
     {
         return(new ProjectReferenceDescription
         {
             Framework = library.Framework.ToPayload(),
             Name = library.Identity.Name,
             Path = library.Path
         });
     }
     else if (library is MSBuildProjectDescription)
     {
         return(new ProjectReferenceDescription
         {
             Framework = library.Framework.ToPayload(),
             Name = library.Identity.Name,
             Path = ((MSBuildProjectDescription)library).MSBuildProjectPath,
         });
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 16
0
        public static DependencyDescription Create(LibraryDescription library,
                                                   List <DiagnosticMessage> diagnostics,
                                                   IDictionary <string, LibraryExport> exportsLookup)
        {
            var result = new DependencyDescription
            {
                Name         = library.Identity.Name,
                DisplayName  = library.Identity.Name,
                Version      = (library.Identity.Version ?? new NuGetVersion("1.0.0")).ToNormalizedString(),
                Type         = library.Identity.Type.Value,
                Resolved     = library.Resolved,
                Path         = library.Path,
                Dependencies = library.Dependencies.Select(dependency => GetDependencyItem(dependency, exportsLookup)),
                Errors       = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error)
                               .Select(d => new DiagnosticMessageView(d)),
                Warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning)
                           .Select(d => new DiagnosticMessageView(d))
            };

            var msbuildLibrary = library as MSBuildProjectDescription;

            if (msbuildLibrary != null)
            {
                result.Path = msbuildLibrary.MSBuildProjectPath;
            }

            return(result);
        }
Exemplo n.º 17
0
        public static DependencyDescription Create(LibraryDescription library,
                                                   List <DiagnosticMessage> diagnostics,
                                                   Dictionary <string, LibraryExport> allExports)
        {
            var name = library.GetUniqueName();

            return(new DependencyDescription
            {
                Name = name,
                DisplayName = library.Identity.Name,
                Version = library.Identity.Version?.ToNormalizedString(),
                Type = library.Identity.Type.Value,
                Resolved = library.Resolved,
                Path = library.Path,
                Dependencies = library.Dependencies.Select(dependency => new DependencyItem
                {
                    Name = dependency.GetUniqueName(),
                    Version = allExports[dependency.GetUniqueName()].Library.Identity.Version?.ToNormalizedString()
                }),
                Errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error)
                         .Select(d => new DiagnosticMessageView(d)),
                Warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning)
                           .Select(d => new DiagnosticMessageView(d))
            });
        }
Exemplo n.º 18
0
 public LibraryExport(LibraryDescription library, IEnumerable<LibraryAsset> compileAssemblies, IEnumerable<string> sourceReferences, IEnumerable<LibraryAsset> runtimeAssemblies, IEnumerable<LibraryAsset> nativeLibraries)
 {
     Library = library;
     CompilationAssemblies = compileAssemblies;
     SourceReferences = sourceReferences;
     RuntimeAssemblies = runtimeAssemblies;
     NativeLibraries = nativeLibraries;
 }
Exemplo n.º 19
0
 public LibraryExport(LibraryDescription library, IEnumerable <LibraryAsset> compileAssemblies, IEnumerable <string> sourceReferences, IEnumerable <LibraryAsset> runtimeAssemblies, IEnumerable <LibraryAsset> nativeLibraries)
 {
     Library = library;
     CompilationAssemblies = compileAssemblies;
     SourceReferences      = sourceReferences;
     RuntimeAssemblies     = runtimeAssemblies;
     NativeLibraries       = nativeLibraries;
 }
Exemplo n.º 20
0
 public static DependencyInfo Create(ProjectContext context, LibraryDescription library)
 {
     return new DependencyInfo
     {
         ProjectPath = context.ProjectFile.ProjectFilePath,
         Version = library.Identity.Version.ToString(),
         Name = library.Identity.Name
     };
 }
Exemplo n.º 21
0
 public PackProject(
     ProjectReferenceDependencyProvider projectReferenceDependencyProvider,
     IProjectResolver projectResolver,
     LibraryDescription libraryDescription)
 {
     _projectReferenceDependencyProvider = projectReferenceDependencyProvider;
     _projectResolver    = projectResolver;
     _libraryDescription = libraryDescription;
 }
Exemplo n.º 22
0
 public static DependencyInfo Create(ProjectContext context, LibraryDescription library)
 {
     return(new DependencyInfo
     {
         ProjectPath = context.ProjectFile.ProjectFilePath,
         Version = library.Identity.Version.ToString(),
         Name = library.Identity.Name
     });
 }
Exemplo n.º 23
0
 private LibraryExport ExportProject(LibraryDescription library, string aspect)
 {
     return(ProjectExporter.ExportProject(
                ((ProjectDescription)library).Project,
                _compilationEngine,
                aspect,
                _targetFramework,
                _configuration));
 }
Exemplo n.º 24
0
 public static Library ToLibrary(this LibraryDescription description)
 {
     return(new Library(
                description.Identity.Name,
                description.Identity.Version?.ToString(),
                description.Path,
                description.Type,
                description.Dependencies.Select(d => d.Name),
                description.Assemblies.Select(a => new AssemblyName(a))));
 }
Exemplo n.º 25
0
 private static LibraryDependency CreateDependency(LibraryDescription libraryDescription)
 {
     return(new LibraryDependency
     {
         LibraryRange = new LibraryRange(libraryDescription.Identity.Name, libraryDescription.Identity.IsGacOrFrameworkReference)
         {
             VersionRange = new SemanticVersionRange(libraryDescription.Identity.Version)
         }
     });
 }
Exemplo n.º 26
0
        private static string GetLibraryDisplayName(LibraryDescription library)
        {
            var name = library.Identity.Name;
            if (library.Identity.Type == LibraryType.ReferenceAssembly && name.StartsWith("fx/"))
            {
                name = name.Substring(3);
            }

            return name;
        }
Exemplo n.º 27
0
        private void LBDependancies_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (LBDependancies.SelectedIndex == -1)
            {
                return;
            }
            LibraryDescription lib = (LibraryDescription)LBDependancies.SelectedItem;

            Show(lib.Name, lib.Version);
        }
Exemplo n.º 28
0
        private LibraryExport ExportAssemblyLibrary(LibraryDescription library)
        {
            if (string.IsNullOrEmpty(library.Path))
            {
                Logger.TraceError($"[{nameof(LibraryExporter)}] Failed to export: {library.Identity.Name}");
                return(null);
            }

            // We assume the path is to an assembly
            return(new LibraryExport(new MetadataFileReference(library.Identity.Name, library.Path)));
        }
Exemplo n.º 29
0
        private static string GetLibraryDisplayName(LibraryDescription library)
        {
            var name = library.Identity.Name;

            if (library.Identity.Type == LibraryType.ReferenceAssembly && name.StartsWith("fx/"))
            {
                name = name.Substring(3);
            }

            return(name);
        }
Exemplo n.º 30
0
 private LibraryExport ExportFrameworkLibrary(LibraryDescription library)
 {
     // We assume the path is to an assembly. Framework libraries only export compile-time stuff
     // since they assume the runtime library is present already
     return(new LibraryExport(
                library,
                string.IsNullOrEmpty(library.Path) ?
                Enumerable.Empty <LibraryAsset>() :
                new[] { new LibraryAsset(library.Identity.Name, library.Path, library.Path) },
                Enumerable.Empty <string>(),
                Enumerable.Empty <LibraryAsset>(),
                Enumerable.Empty <LibraryAsset>()));
 }
Exemplo n.º 31
0
        private string GetLibraryHashPath(LibraryDescription description)
        {
            var packageDescription = description as PackageDescription;

            if (packageDescription != null)
            {
                // This hash path appended to the package path (much like package assets). This string should only be
                // mastered by NuGet.
                return(packageDescription.HashPath);
            }

            return(null);
        }
Exemplo n.º 32
0
 public DiagnosticMessage(string errorCode, string message, string filePath, DiagnosticMessageSeverity severity, int startLine, int startColumn, LibraryDescription source)
         : this(
             errorCode,
             message,
             $"{filePath}({startLine},{startColumn}): {severity.ToString().ToLowerInvariant()} {errorCode}: {message}",
             filePath,
             severity,
             startLine,
             startColumn,
             endLine: startLine,
             endColumn: startColumn,
             source: source)
 { }
Exemplo n.º 33
0
        private string GetLibraryPath(LibraryDescription description)
        {
            var packageDescription = description as PackageDescription;

            if (packageDescription != null)
            {
                // This is the relative path appended to a NuGet packages directory to find the directory containing
                // the package assets. This string should only be mastered by NuGet.
                return(packageDescription.PackageLibrary?.Path);
            }

            return(null);
        }
Exemplo n.º 34
0
 private LibraryExport Export(
     LibraryDescription description,
     IEnumerable <LibraryAsset> compilationAssemblies         = null,
     IEnumerable <LibraryAssetGroup> runtimeAssemblyGroups    = null,
     IEnumerable <LibraryAssetGroup> nativeLibraryGroups      = null,
     IEnumerable <LibraryResourceAssembly> resourceAssemblies = null)
 {
     return(LibraryExportBuilder.Create(description)
            .WithCompilationAssemblies(compilationAssemblies)
            .WithRuntimeAssemblyGroups(runtimeAssemblyGroups)
            .WithNativeLibraryGroups(nativeLibraryGroups)
            .WithResourceAssemblies(resourceAssemblies)
            .Build());
 }
Exemplo n.º 35
0
 /// <summary>
 /// Create a LibraryExport from LibraryDescription.
 ///
 /// When the library is not resolved the LibraryExport is created nevertheless.
 /// </summary>
 private LibraryExport GetExport(LibraryDescription library)
 {
     if (Equals(LibraryType.Package, library.Identity.Type))
     {
         return(ExportPackage((PackageDescription)library));
     }
     else if (Equals(LibraryType.Project, library.Identity.Type))
     {
         return(ExportProject((ProjectDescription)library));
     }
     else
     {
         return(ExportFrameworkLibrary(library));
     }
 }
Exemplo n.º 36
0
        private LibraryExport ExportFrameworkLibrary(LibraryDescription library)
        {
            // We assume the path is to an assembly. Framework libraries only export compile-time stuff
            // since they assume the runtime library is present already
            var builder = LibraryExportBuilder.Create(library);

            if (!string.IsNullOrEmpty(library.Path))
            {
                builder.WithCompilationAssemblies(new[]
                {
                    new LibraryAsset(library.Identity.Name, null, library.Path)
                });
            }
            return(builder.Build());
        }
Exemplo n.º 37
0
 private LibraryExport ExportFrameworkLibrary(LibraryDescription library)
 {
     // We assume the path is to an assembly. Framework libraries only export compile-time stuff
     // since they assume the runtime library is present already
     return(new LibraryExport(
                library,
                string.IsNullOrEmpty(library.Path) ?
                EmptyArray <LibraryAsset> .Value :
                new[] { new LibraryAsset(library.Identity.Name, library.Path, library.Path) },
                EmptyArray <string> .Value,
                EmptyArray <LibraryAsset> .Value,
                EmptyArray <LibraryAsset> .Value,
                EmptyArray <LibraryAsset> .Value,
                EmptyArray <AnalyzerReference> .Value));
 }
Exemplo n.º 38
0
 private static DependencyDescription CreateDependencyDescription(LibraryDescription library)
 {
     return(new DependencyDescription
     {
         Name = library.Identity.Name,
         Version = library.Identity.Version == null ? null : library.Identity.Version.ToString(),
         Type = library.Type ?? "Unresolved",
         Path = library.Path,
         Dependencies = library.Dependencies.Select(lib => new DependencyItem
         {
             Name = lib.Name,
             Version = lib.Version == null ? null : lib.Version.ToString()
         })
     });
 }
Exemplo n.º 39
0
 public LibraryExport(LibraryDescription library,
                      IEnumerable<LibraryAsset> compileAssemblies,
                      IEnumerable<LibraryAsset> sourceReferences,
                      IEnumerable<LibraryAsset> runtimeAssemblies,
                      IEnumerable<LibraryAsset> runtimeAssets,
                      IEnumerable<LibraryAsset> nativeLibraries,
                      IEnumerable<LibraryAsset> embeddedResources,
                      IEnumerable<AnalyzerReference> analyzers)
 {
     Library = library;
     CompilationAssemblies = compileAssemblies;
     SourceReferences = sourceReferences;
     RuntimeAssemblies = runtimeAssemblies;
     RuntimeAssets = runtimeAssets;
     NativeLibraries = nativeLibraries;
     EmbeddedResources = embeddedResources;
     AnalyzerReferences = analyzers;
 }
Exemplo n.º 40
0
 public static DependencyDescription Create(LibraryDescription library, IEnumerable<DiagnosticMessage> diagnostics)
 {
     return new DependencyDescription
     {
         Name = library.Identity.Name,
         DisplayName = GetLibraryDisplayName(library),
         Version = library.Identity.Version?.ToString(),
         Type = library.Identity.Type.Value,
         Resolved = library.Resolved,
         Path = library.Path,
         Dependencies = library.Dependencies.Select(dependency => new DependencyItem
         {
             Name = dependency.Name,
             Version = dependency.VersionRange?.ToString() // TODO: review
         }),
         Errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error)
                             .Select(d => new DiagnosticMessageView(d)),
         Warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning)
                               .Select(d => new DiagnosticMessageView(d))
     };
 }
Exemplo n.º 41
0
 public DiagnosticMessage(
     string errorCode,
     string message,
     string formattedMessage,
     string filePath,
     DiagnosticMessageSeverity severity,
     int startLine,
     int startColumn,
     int endLine,
     int endColumn,
     LibraryDescription source)
 {
     ErrorCode = errorCode;
     Message = message;
     SourceFilePath = filePath;
     Severity = severity;
     StartLine = startLine;
     EndLine = endLine;
     StartColumn = startColumn;
     EndColumn = endColumn;
     FormattedMessage = formattedMessage;
     Source = source;
 }
Exemplo n.º 42
0
 public static DependencyDescription Create(LibraryDescription library,
                                            List<DiagnosticMessage> diagnostics,
                                            Dictionary<string, LibraryExport> allExports)
 {
     var name = library.GetUniqueName();
     return new DependencyDescription
     {
         Name = name,
         DisplayName = library.Identity.Name,
         Version = library.Identity.Version?.ToNormalizedString(),
         Type = library.Identity.Type.Value,
         Resolved = library.Resolved,
         Path = library.Path,
         Dependencies = library.Dependencies.Select(dependency => new DependencyItem
         {
             Name = dependency.GetUniqueName(),
             Version = allExports[dependency.GetUniqueName()].Library.Identity.Version?.ToNormalizedString()
         }),
         Errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error)
                             .Select(d => new DiagnosticMessageView(d)),
         Warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning)
                               .Select(d => new DiagnosticMessageView(d))
     };
 }
Exemplo n.º 43
0
 internal ProjectContext(
     GlobalSettings globalSettings,
     ProjectDescription rootProject,
     LibraryDescription platformLibrary,
     NuGetFramework targetFramework,
     bool isPortable,
     string runtimeIdentifier,
     string packagesDirectory,
     LibraryManager libraryManager,
     LockFile lockfile,
     List<DiagnosticMessage> diagnostics)
 {
     Identity = new ProjectContextIdentity(rootProject?.Path, targetFramework);
     GlobalSettings = globalSettings;
     RootProject = rootProject;
     PlatformLibrary = platformLibrary;
     TargetFramework = targetFramework;
     RuntimeIdentifier = runtimeIdentifier;
     PackagesDirectory = packagesDirectory;
     LibraryManager = libraryManager;
     LockFile = lockfile;
     IsPortable = isPortable;
     Diagnostics = diagnostics;
 }
Exemplo n.º 44
0
        private void AddDiagnostics(List<DiagnosticMessage> messages, 
                                    LibraryDescription library, 
                                    string message, 
                                    DiagnosticMessageSeverity severity, 
                                    string errorCode)
        {
            // A (in project.json) -> B (unresolved) (not in project.json)
            foreach (var source in GetRangesWithSourceLocations(library).Distinct())
            {
                messages.Add(
                    new DiagnosticMessage(
                        errorCode,
                        message,
                        source.SourceFilePath,
                        severity,
                        source.SourceLine,
                        source.SourceColumn,
                        library));

            }
        }
Exemplo n.º 45
0
 private LibraryExport ExportFrameworkLibrary(LibraryDescription library)
 {
     // We assume the path is to an assembly. Framework libraries only export compile-time stuff
     // since they assume the runtime library is present already
     var builder = LibraryExportBuilder.Create(library);
     if (!string.IsNullOrEmpty(library.Path))
     {
         builder.WithCompilationAssemblies(new[]
         {
             new LibraryAsset(library.Identity.Name, null, library.Path)
         });
     }
     return builder.Build();
 }
Exemplo n.º 46
0
        /// <summary>
        /// Create a LibraryExport from LibraryDescription.
        ///
        /// When the library is not resolved the LibraryExport is created nevertheless.
        /// </summary>
        private LibraryExport GetExport(LibraryDescription library)
        {
            if (!library.Resolved)
            {
                // For a unresolved project reference returns a export with empty asset.
                return new LibraryExport(library: library,
                                         compileAssemblies: Enumerable.Empty<LibraryAsset>(),
                                         sourceReferences: Enumerable.Empty<string>(),
                                         nativeLibraries: Enumerable.Empty<LibraryAsset>(),
                                         runtimeAssets: Enumerable.Empty<LibraryAsset>(),
                                         runtimeAssemblies: EmptyArray<LibraryAsset>.Value,
                                         analyzers: EmptyArray<AnalyzerReference>.Value);
            }

            if (Equals(LibraryType.Package, library.Identity.Type))
            {
                return ExportPackage((PackageDescription)library);
            }
            else if (Equals(LibraryType.Project, library.Identity.Type))
            {
                return ExportProject((ProjectDescription)library);
            }
            else
            {
                return ExportFrameworkLibrary(library);
            }
        }
Exemplo n.º 47
0
 private static bool LibraryIsOfType(LibraryType type, LibraryDescription library)
 {
     return type.Equals(LibraryType.Unspecified) || // No type filter was requested
            library.Identity.Type.Equals(type);     // OR, library type matches requested type
 }
Exemplo n.º 48
0
        private LibraryExport ExportFrameworkLibrary(LibraryDescription library)
        {
            if (string.IsNullOrEmpty(library.Path))
            {
                return null;
            }

            // We assume the path is to an assembly. Framework libraries only export compile-time stuff
            // since they assume the runtime library is present already
            return new LibraryExport(
                library,
                new[] { new LibraryAsset(library.Identity.Name, library.Path, library.Path) },
                Enumerable.Empty<string>(),
                Enumerable.Empty<LibraryAsset>(),
                Enumerable.Empty<LibraryAsset>());
        }
Exemplo n.º 49
0
 /// <summary>
 /// Create a LibraryExport from LibraryDescription. 
 /// 
 /// When the library is not resolved the LibraryExport is created nevertheless.
 /// </summary>
 private LibraryExport GetExport(LibraryDescription library)
 {
     if (Equals(LibraryType.Package, library.Identity.Type))
     {
         return ExportPackage((PackageDescription)library);
     }
     else if (Equals(LibraryType.Project, library.Identity.Type))
     {
         return ExportProject((ProjectDescription)library);
     }
     else
     {
         return ExportFrameworkLibrary(library);
     }
 }
Exemplo n.º 50
0
 public DependencyItem(LibraryRange dependency, LibraryDescription library)
 {
     Dependency = dependency;
     Library = library;
 }
Exemplo n.º 51
0
        private IEnumerable<LibraryRange> GetRangesWithSourceLocations(LibraryDescription library)
        {
            foreach (var range in library.RequestedRanges)
            {
                if (!string.IsNullOrEmpty(range.SourceFilePath))
                {
                    yield return range;
                }
            }

            foreach (var parent in library.Parents)
            {
                foreach (var relevantPath in GetRangesWithSourceLocations(parent))
                {
                    yield return relevantPath;
                }
            }
        }
Exemplo n.º 52
0
        private void AddDiagnostics(List<DiagnosticMessage> messages, 
                                    LibraryDescription library, 
                                    string message, 
                                    DiagnosticMessageSeverity severity, 
                                    string errorCode)
        {
            // A (in project.json) -> B (unresolved) (not in project.json)
            foreach (var source in GetRangesWithSourceLocations(library).Distinct())
            {
                // We only care about things requested in this project
                if (!string.Equals(_projectPath, source.SourceFilePath))
                {
                    continue;
                }

                messages.Add(
                    new DiagnosticMessage(
                        errorCode,
                        message,
                        source.SourceFilePath,
                        severity,
                        source.SourceLine,
                        source.SourceColumn,
                        library));

            }
        }
 private LibraryExport Export(
     LibraryDescription description,
     IEnumerable<LibraryAsset> compilationAssemblies = null,
     IEnumerable<LibraryAssetGroup> runtimeAssemblyGroups = null,
     IEnumerable<LibraryAssetGroup> nativeLibraryGroups = null,
     IEnumerable<LibraryResourceAssembly> resourceAssemblies = null)
 {
     return LibraryExportBuilder.Create(description)
         .WithCompilationAssemblies(compilationAssemblies)
         .WithRuntimeAssemblyGroups(runtimeAssemblyGroups)
         .WithNativeLibraryGroups(nativeLibraryGroups)
         .WithResourceAssemblies(resourceAssemblies)
         .Build();
 }
        private LibraryExport ExportSingle(LibraryDescription description = null)
        {
            var rootProject = new Project()
            {
                Name = "RootProject",
                _defaultCompilerOptions = new CommonCompilerOptions
                {
                    CompilerName = "csc"
                }
            };

            var rootProjectDescription = new ProjectDescription(
                new LibraryRange(),
                rootProject,
                new LibraryRange[] { },
                new TargetFrameworkInformation(),
                true);

            if (description == null)
            {
                description = rootProjectDescription;
            }
            else
            {
                description.Parents.Add(rootProjectDescription);
            }

            var libraryManager = new LibraryManager(new[] { description }, new DiagnosticMessage[] { }, "");
            var allExports = new LibraryExporter(rootProjectDescription, libraryManager, "config", "runtime", null, "basepath", "solutionroot").GetAllExports();
            var export = allExports.Single();
            return export;
        }
Exemplo n.º 55
0
        private LibraryExport GetExport(LibraryDescription library)
        {
            // Don't even try to export unresolved libraries
            if (!library.Resolved)
            {
                return null;
            }

            if (Equals(LibraryType.Package, library.Identity.Type))
            {
                return ExportPackage((PackageDescription)library);
            }
            else if (Equals(LibraryType.Project, library.Identity.Type))
            {
                return ExportProject((ProjectDescription)library);
            }
            else
            {
                return ExportFrameworkLibrary(library);
            }
        }
Exemplo n.º 56
0
        /// <summary>
        /// Create a LibraryExport from LibraryDescription.
        ///
        /// When the library is not resolved the LibraryExport is created nevertheless.
        /// </summary>
        private LibraryExport GetExport(LibraryDescription library)
        {
            if (!library.Resolved)
            {
                // For a unresolved project reference returns a export with empty asset.
                return LibraryExportBuilder.Create(library).Build();
            }

            var libraryType = library.Identity.Type;
            if (Equals(LibraryType.Package, libraryType) || Equals(LibraryType.MSBuildProject, libraryType))
            {
                return ExportPackage((TargetLibraryWithAssets)library);
            }
            else if (Equals(LibraryType.Project, libraryType))
            {
                return ExportProject((ProjectDescription)library);
            }
            else
            {
                return ExportFrameworkLibrary(library);
            }
        }
Exemplo n.º 57
0
 public LibraryItem(LibraryRange requestedRange, LibraryDescription library)
 {
     RequestedRange = requestedRange;
     Library = library;
 }
Exemplo n.º 58
0
 private LibraryExport ExportFrameworkLibrary(LibraryDescription library)
 {
     // We assume the path is to an assembly. Framework libraries only export compile-time stuff
     // since they assume the runtime library is present already
     return new LibraryExport(
         library,
         string.IsNullOrEmpty(library.Path) ?
             EmptyArray<LibraryAsset>.Value :
             new[] { new LibraryAsset(library.Identity.Name, library.Path, library.Path) },
         EmptyArray<string>.Value,
         EmptyArray<LibraryAsset>.Value,
         EmptyArray<LibraryAsset>.Value,
         EmptyArray<LibraryAsset>.Value,
         EmptyArray<AnalyzerReference>.Value);
 }