コード例 #1
0
ファイル: ProjectStateResolver.cs プロジェクト: yossidev/dnx
        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);
        }
コード例 #2
0
        private void PopulateDependencies(Dictionary <string, DependencyDescription> packageMap, ITaskItem[] packageDependecyItems)
        {
            Requires.NotNull(packageMap, nameof(packageMap));
            Requires.NotNull(packageDependecyItems, nameof(packageDependecyItems));
            foreach (var item in packageDependecyItems)
            {
                var depSpecs = item.GetMetadata("Dependencies")
                               ?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                DependencyDescription current = null;
                if (depSpecs == null || !packageMap.TryGetValue(item.ItemSpec, out current))
                {
                    return;
                }

                foreach (var depSpec in depSpecs)
                {
                    var spec = item.ItemSpec.Split('/').FirstOrDefault() + "/" + depSpec;
                    DependencyDescription d = null;
                    if (packageMap.TryGetValue(spec, out d))
                    {
                        current.AddDependency(new Dependency(d.Name, d.Version));
                    }
                }
            }
        }
コード例 #3
0
ファイル: Dependency.cs プロジェクト: HelpOrMe/Ject
        protected Dependency(DependencyTranslateInfo info)
        {
            Writer      = info.Writer;
            Description = info.Description;

            Writer.Rewrite(this);
        }
コード例 #4
0
    protected virtual bool CheckDependencies(ArgumentDescriptionAttribute InArugmentDescription, DependencyDescription[] InDependencies, string[] InArguments, out string OutMessage)
    {
        OutMessage = string.Empty;
        if (InArguments == null)
        {
            OutMessage = "缺少所有必要参数";
            return(false);
        }
        for (int i = 0; i < InDependencies.Length; i++)
        {
            DependencyDescription dependencyDescription = InDependencies[i];
            DebugHelper.Assert(dependencyDescription.dependsIndex >= 0 && dependencyDescription.dependsIndex < this.argumentsTypes.Length, "maybe internal error, can't find depend argument description.");
            if (dependencyDescription.dependsIndex < 0 || dependencyDescription.dependsIndex >= this.argumentsTypes.Length)
            {
                OutMessage = "maybe internal error, can't find depend argument description.";
                return(false);
            }
            DebugHelper.Assert(dependencyDescription.dependsIndex < InArguments.Length);
            string text         = InArguments[dependencyDescription.dependsIndex];
            Type   argumentType = this.argumentsTypes[dependencyDescription.dependsIndex].argumentType;
            IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(argumentType);

            DebugHelper.Assert(description != null);
            text = description.GetValue(argumentType, text);
            if (dependencyDescription.ShouldBackOff(text))
            {
                OutMessage = string.Format("您必须提供参数<{2}>, 因为参数<{0}>=\"{1}\"", this.argumentsTypes[dependencyDescription.dependsIndex].name, text, InArugmentDescription.name);
                return(false);
            }
        }
        return(true);
    }
コード例 #5
0
 public DependencyNode(
     DependenciesMessage message,
     DependencyDescription dependency,
     FrameworkNode parentNode = null)
 {
     this.message    = message;
     this.dependency = dependency;
     this.parentNode = parentNode;
 }
コード例 #6
0
        public static ProjectContextSnapshot Create(ProjectContext context, string configuration, IEnumerable <string> currentSearchPaths)
        {
            var snapshot = new ProjectContextSnapshot();

            var allDependencyDiagnostics = new List <DiagnosticMessage>();

            allDependencyDiagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
            allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(context, currentSearchPaths));

            var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);

            var allExports = context.CreateExporter(configuration)
                             .GetAllExports()
                             .ToDictionary(export => export.Library.Identity.Name);

            var allSourceFiles       = new List <string>(context.ProjectFile.Files.SourceFiles);
            var allFileReferences    = new List <string>();
            var allProjectReferences = new List <ProjectReferenceDescription>();
            var allDependencies      = new Dictionary <string, DependencyDescription>();

            // All exports are returned. When the same library name have a ReferenceAssembly type export and a Package type export
            // both will be listed as dependencies. Prefix "fx/" will be added to ReferenceAssembly type dependency.
            foreach (var export in allExports.Values)
            {
                allSourceFiles.AddRange(export.SourceReferences.Select(f => f.ResolvedPath));
                var diagnostics = diagnosticsLookup[export.Library].ToList();
                var description = DependencyDescription.Create(export.Library, diagnostics, allExports);
                allDependencies[description.Name] = description;

                var projectDescription = export.Library as ProjectDescription;
                if (projectDescription != null)
                {
                    if (projectDescription.Identity.Name != context.ProjectFile.Name)
                    {
                        allProjectReferences.Add(ProjectReferenceDescription.Create(projectDescription));
                    }
                }
                else
                {
                    allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));
                }
            }

            snapshot.RootDependency        = context.ProjectFile.Name;
            snapshot.TargetFramework       = context.TargetFramework;
            snapshot.SourceFiles           = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.CompilerOptions       = context.GetLanguageSpecificCompilerOptions(context.TargetFramework, configuration);
            snapshot.ProjectReferences     = allProjectReferences.OrderBy(reference => reference.Name).ToList();
            snapshot.FileReferences        = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.DependencyDiagnostics = allDependencyDiagnostics;
            snapshot.Dependencies          = allDependencies;

            return(snapshot);
        }
コード例 #7
0
        private IList <DependencyDescription> DeserializePackages(JsonElement packages, JsonElement packageFolderPath, string targetFrameworkMoniker)
        {
            IList <DependencyDescription> packageDependencies = new List <DependencyDescription>();
            var packagesEnumerator = packages.EnumerateObject();

            //populate are our own List<DependencyDescription> of all the dependencies we find.
            foreach (var package in packagesEnumerator)
            {
                var fullName = package.Name;
                //get default nuget package path.
                var path = packageFolderPath.EnumerateObject().Any() ? packageFolderPath.EnumerateObject().First().Name : string.Empty;
                if (!string.IsNullOrEmpty(fullName) && !string.IsNullOrEmpty(path) && package.Value.TryGetProperty(TypeProperty, out var type))
                {
                    //fullName is in the format {Package Name}/{Version} for example "System.Text.MoreText/2.1.1" Split into tuple.
                    Tuple <string, string> nameAndVersion = GetName(fullName);
                    if (nameAndVersion != null)
                    {
                        var dependencyTypeValue = type.ToString();
                        var DependencyTypeEnum  = DependencyType.Unknown;
                        if (Enum.TryParse(typeof(DependencyType), dependencyTypeValue, true, out var dependencyType))
                        {
                            DependencyTypeEnum = (DependencyType)dependencyType;
                        }

                        string packagePath = GetPath(path, nameAndVersion);
                        DependencyDescription dependency = new DependencyDescription(nameAndVersion.Item1,
                                                                                     nameAndVersion.Item2,
                                                                                     Directory.Exists(packagePath) ? packagePath : string.Empty,
                                                                                     targetFrameworkMoniker,
                                                                                     DependencyTypeEnum,
                                                                                     true);
                        if (package.Value.TryGetProperty(DependencyProperty, out var dependencies))
                        {
                            var dependenciesList = dependencies.EnumerateObject();
                            //Add all transitive dependencies
                            foreach (var dep in dependenciesList)
                            {
                                if (!string.IsNullOrEmpty(dep.Name))
                                {
                                    Dependency transitiveDependency = new Dependency(dep.Name, dep.Value.ToString());
                                    dependency.AddDependency(transitiveDependency);
                                }
                            }
                        }
                        packageDependencies.Add(dependency);
                    }
                }
            }

            return(packageDependencies);
        }
コード例 #8
0
ファイル: ProjectInfo.cs プロジェクト: sethjuarez/cli
        public ProjectInfo(ProjectContext context,
                           string configuration,
                           IEnumerable <string> currentSearchPaths)
        {
            var allExports     = context.CreateExporter(configuration).GetAllExports().ToList();
            var allDiagnostics = context.LibraryManager.GetAllDiagnostics();

            Context       = context;
            Configuration = configuration;

            var allSourceFiles    = new List <string>(context.ProjectFile.Files.SourceFiles);
            var allFileReferences = new List <string>();

            foreach (var export in allExports)
            {
                allSourceFiles.AddRange(export.SourceReferences);
                allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));
            }

            SourceFiles           = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            CompilationAssembiles = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();

            var allProjectReferences = new List <ProjectReferenceDescription>();

            var allDependencyDiagnostics = new List <DiagnosticMessage>();

            allDependencyDiagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
            allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(Context, currentSearchPaths));

            var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);

            Dependencies = new Dictionary <string, DependencyDescription>();

            foreach (var library in context.LibraryManager.GetLibraries())
            {
                var diagnostics = diagnosticsLookup[library].ToList();
                var description = DependencyDescription.Create(library, diagnostics);
                Dependencies[description.Name] = description;

                if (library is ProjectDescription && library.Identity.Name != context.ProjectFile.Name)
                {
                    allProjectReferences.Add(ProjectReferenceDescription.Create((ProjectDescription)library));
                }
            }

            DependencyDiagnostics = allDependencyDiagnostics;
            ProjectReferences     = allProjectReferences.OrderBy(reference => reference.Name).ToList();
        }
コード例 #9
0
        public static ProjectContextSnapshot Create(ProjectContext context, string configuration, IEnumerable <string> currentSearchPaths)
        {
            var snapshot = new ProjectContextSnapshot();

            var allDependencyDiagnostics = new List <DiagnosticMessage>();

            allDependencyDiagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
            allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(context, currentSearchPaths));

            var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);

            var allSourceFiles       = new List <string>(context.ProjectFile.Files.SourceFiles);
            var allFileReferences    = new List <string>();
            var allProjectReferences = new List <ProjectReferenceDescription>();
            var allDependencies      = new Dictionary <string, DependencyDescription>();

            foreach (var export in context.CreateExporter(configuration).GetDependencies())
            {
                allSourceFiles.AddRange(export.SourceReferences);
                allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));

                var library     = export.Library;
                var diagnostics = diagnosticsLookup[library].ToList();
                var description = DependencyDescription.Create(library, diagnostics);
                allDependencies[description.Name] = description;

                var projectDescription = library as ProjectDescription;

                if (projectDescription != null)
                {
                    allProjectReferences.Add(ProjectReferenceDescription.Create(projectDescription));
                }
            }

            snapshot.RootDependency        = context.ProjectFile.Name;
            snapshot.TargetFramework       = context.TargetFramework;
            snapshot.SourceFiles           = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.CompilerOptions       = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
            snapshot.ProjectReferences     = allProjectReferences.OrderBy(reference => reference.Name).ToList();
            snapshot.FileReferences        = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.DependencyDiagnostics = allDependencyDiagnostics;
            snapshot.Dependencies          = allDependencies;

            return(snapshot);
        }
コード例 #10
0
    private bool ShouldSkip(ArgumentDescriptionAttribute InArgAttr, ref string[] ExistsValues)
    {
        DebugHelper.Assert(InArgAttr.isOptional);
        DependencyDescription[] depends = InArgAttr.depends;
        for (int i = 0; i < depends.Length; i++)
        {
            DependencyDescription dependencyDescription = depends[i];
            string text         = ExistsValues[dependencyDescription.dependsIndex];
            Type   argumentType = this.CheatCommand.argumentsTypes[dependencyDescription.dependsIndex].argumentType;
            IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(argumentType);

            DebugHelper.Assert(description != null);
            text = description.GetValue(argumentType, text);
            if (dependencyDescription.ShouldBackOff(text))
            {
                return(false);
            }
        }
        return(true);
    }
コード例 #11
0
 public FrameworkNode(DependenciesMessage message)
 {
     this.message   = message;
     rootDependency = message.Dependencies[message.RootDependency];
 }
コード例 #12
0
 private bool IsCandidateLibrary(DependencyDescription library)
 {
     return(!_exclusions.Contains(library.Name));
 }
コード例 #13
0
        private IEnumerable <DependencyDescription> GetPackageDependencies(string projectAssetsFile)
        {
            IList <DependencyDescription> packageDependencies = new List <DependencyDescription>();

            if (!string.IsNullOrEmpty(projectAssetsFile) && File.Exists(projectAssetsFile) && !string.IsNullOrEmpty(TargetFramework))
            {
                //target framework moniker for the current project. We use this to get all targets for said moniker.
                var    targetFrameworkMoniker = TargetFrameworkMoniker;
                string json = File.ReadAllText(projectAssetsFile);
                if (!string.IsNullOrEmpty(json) && !string.IsNullOrEmpty(targetFrameworkMoniker))
                {
                    try
                    {
                        JsonDocument baseDocument = JsonDocument.Parse(json);
                        if (baseDocument != null)
                        {
                            JsonElement root = baseDocument.RootElement;
                            //"targets" gives us all top-level and transitive dependencies. "packageFolders" gives us the path where the dependencies are on disk.
                            if (root.TryGetProperty(TargetsProperty, out var targets) && root.TryGetProperty(PackageFoldersProperty, out var packageFolderPath))
                            {
                                if (targets.TryGetProperty(targetFrameworkMoniker, out var packages))
                                {
                                    var packagesEnumerator = packages.EnumerateObject();
                                    //populate are our own List<DependencyDescription> of all the dependencies we find.
                                    foreach (var package in packagesEnumerator)
                                    {
                                        var fullName = package.Name;
                                        //get default nuget package path.
                                        var path = packageFolderPath.EnumerateObject().Any() ? packageFolderPath.EnumerateObject().First().Name : string.Empty;
                                        if (!string.IsNullOrEmpty(fullName) && !string.IsNullOrEmpty(path) && package.Value.TryGetProperty(TypeProperty, out var type))
                                        {
                                            //fullName is in the format {Package Name}/{Version} for example "System.Text.MoreText/2.1.1" Split into tuple.
                                            Tuple <string, string> nameAndVersion = GetName(fullName);
                                            if (nameAndVersion != null)
                                            {
                                                var dependencyTypeValue = type.ToString();
                                                var DependencyTypeEnum  = DependencyType.Unknown;
                                                if (Enum.TryParse(typeof(DependencyType), dependencyTypeValue, true, out var dependencyType))
                                                {
                                                    DependencyTypeEnum = (DependencyType)dependencyType;
                                                }

                                                string packagePath = GetPath(path, nameAndVersion);
                                                DependencyDescription dependency = new DependencyDescription(nameAndVersion.Item1,
                                                                                                             nameAndVersion.Item2,
                                                                                                             Directory.Exists(packagePath) ? packagePath : string.Empty,
                                                                                                             targetFrameworkMoniker,
                                                                                                             DependencyTypeEnum,
                                                                                                             true);
                                                if (package.Value.TryGetProperty(DependencyProperty, out var dependencies))
                                                {
                                                    var dependenciesList = dependencies.EnumerateObject();
                                                    //Add all transitive dependencies
                                                    foreach (var dep in dependenciesList)
                                                    {
                                                        if (!string.IsNullOrEmpty(dep.Name))
                                                        {
                                                            Dependency transitiveDependency = new Dependency(dep.Name, dep.Value.ToString());
                                                            dependency.AddDependency(transitiveDependency);
                                                        }
                                                    }
                                                }
                                                packageDependencies.Add(dependency);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (JsonException)
                    {
                        Debug.Assert(false, "Completely empty json.");
                    }
                }
            }

            return(packageDependencies);
        }
コード例 #14
0
 public DependencyNode(DependenciesMessage message, DependencyDescription dependency)
 {
     this.message    = message;
     this.dependency = dependency;
 }
コード例 #15
0
 public DependencyTranslateInfo(IDependencyWriter writer, DependencyDescription description)
 {
     Writer      = writer;
     Description = description;
 }
コード例 #16
0
 /// <summary>
 /// Determins whether an addin can be installed to the application, i.e, whether its dependencies is satisfied.
 /// </summary>
 /// <param name="dependencyDescription"></param>
 /// <returns></returns>
 public bool CanInstall(DependencyDescription dependencyDescription)
 {
     VerifyInitialized();
     return(false);
 }