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); }
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"); } }
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 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); }
/// <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)); } }
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); } } }
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; }
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); } } }
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); }
/// <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; } }
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; }
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); }
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(); }
/// <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); } }
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); }
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)) }); }
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; }
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; }
public static DependencyInfo Create(ProjectContext context, LibraryDescription library) { return new DependencyInfo { ProjectPath = context.ProjectFile.ProjectFilePath, Version = library.Identity.Version.ToString(), Name = library.Identity.Name }; }
public PackProject( ProjectReferenceDependencyProvider projectReferenceDependencyProvider, IProjectResolver projectResolver, LibraryDescription libraryDescription) { _projectReferenceDependencyProvider = projectReferenceDependencyProvider; _projectResolver = projectResolver; _libraryDescription = libraryDescription; }
public static DependencyInfo Create(ProjectContext context, LibraryDescription library) { return(new DependencyInfo { ProjectPath = context.ProjectFile.ProjectFilePath, Version = library.Identity.Version.ToString(), Name = library.Identity.Name }); }
private LibraryExport ExportProject(LibraryDescription library, string aspect) { return(ProjectExporter.ExportProject( ((ProjectDescription)library).Project, _compilationEngine, aspect, _targetFramework, _configuration)); }
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)))); }
private static LibraryDependency CreateDependency(LibraryDescription libraryDescription) { return(new LibraryDependency { LibraryRange = new LibraryRange(libraryDescription.Identity.Name, libraryDescription.Identity.IsGacOrFrameworkReference) { VersionRange = new SemanticVersionRange(libraryDescription.Identity.Version) } }); }
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; }
private void LBDependancies_MouseDoubleClick(object sender, MouseEventArgs e) { if (LBDependancies.SelectedIndex == -1) { return; } LibraryDescription lib = (LibraryDescription)LBDependancies.SelectedItem; Show(lib.Name, lib.Version); }
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))); }
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); }
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>())); }
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); }
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) { }
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); }
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()); }
/// <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)); } }
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()); }
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)); }
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() }) }); }
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; }
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)) }; }
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; }
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)) }; }
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; }
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)); } }
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(); }
/// <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); } }
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 }
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>()); }
/// <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); } }
public DependencyItem(LibraryRange dependency, LibraryDescription library) { Dependency = dependency; Library = library; }
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; } } }
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; }
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); } }
/// <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); } }
public LibraryItem(LibraryRange requestedRange, LibraryDescription library) { RequestedRange = requestedRange; Library = library; }
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); }