├── .gitignore
├── .gitmodules
├── Makefile
├── 3rdparty
├── Microsoft.Dnx.Runtime.Abstractions
│ └── 1.0.0-rc1-15838
│ │ ├── Microsoft.Dnx.Runtime.Abstractions.1.0.0-rc1-15838.nupkg.sha512
│ │ ├── lib
│ │ ├── dnx451
│ │ │ ├── Microsoft.Dnx.Runtime.Abstractions.dll
│ │ │ └── Microsoft.Dnx.Runtime.Abstractions.xml
│ │ └── dnxcore50
│ │ │ ├── Microsoft.Dnx.Runtime.Abstractions.dll
│ │ │ └── Microsoft.Dnx.Runtime.Abstractions.xml
│ │ ├── Microsoft.Dnx.Runtime.Abstractions.1.0.0-rc1-15838.nupkg
│ │ └── Microsoft.Dnx.Runtime.Abstractions.nuspec
└── Microsoft.Framework.CommandLineUtils.Sources
│ └── 1.0.0-rc1-15779
│ ├── Microsoft.Framework.CommandLineUtils.Sources.1.0.0-rc1-15779.nupkg.sha512
│ ├── lib
│ ├── dnx451
│ │ ├── Microsoft.Framework.CommandLineUtils.Sources.dll
│ │ └── Microsoft.Framework.CommandLineUtils.Sources.xml
│ └── dnxcore50
│ │ ├── Microsoft.Framework.CommandLineUtils.Sources.dll
│ │ └── Microsoft.Framework.CommandLineUtils.Sources.xml
│ ├── Microsoft.Framework.CommandLineUtils.Sources.1.0.0-rc1-15779.nupkg
│ ├── shared
│ ├── CommandOptionType.cs
│ ├── CommandParsingException.cs
│ ├── CommandArgument.cs
│ ├── CommandOption.cs
│ ├── AnsiConsole.cs
│ └── CommandLineApplication.cs
│ └── Microsoft.Framework.CommandLineUtils.Sources.nuspec
├── .bin
└── srclib-csharp
├── Srclib.Nuget
├── Srclib.Nuget.xproj.user
├── Models
│ ├── DependencyInfo.cs
│ ├── Target.cs
│ ├── Resolution.cs
│ ├── SourceUnit.cs
│ └── Output.cs
├── Utils.cs
├── Graph
│ ├── SymbolNameCache.cs
│ ├── GraphContext.cs
│ └── SymbolExtensions.cs
├── project.json
├── LibraryUtils.cs
├── Srclib.Nuget.xproj
├── RuntimeEnvironmentExtensions.cs
├── Program.cs
├── ConsoleCommands
│ ├── GraphConsoleCommand.cs
│ ├── DepresolveConsoleCommand.cs
│ ├── ScanConsoleCommand.cs
│ └── PackageVersions.cs
└── Documentation
│ └── DocProcessor.cs
├── testdata
└── expected
│ └── Proxy
│ └── Test
│ ├── NugetPackage.unit.json
│ ├── NugetPackage.depresolve.json
│ └── NugetPackage.graph.json
├── NuGet.Config
├── Srclibtoolchain
├── Srclib.Nuget.sln
├── LICENSE
├── .travis.yml
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | testdata/actual/
3 | project.lock.json
4 | log.json
5 | log.txt
6 | .vs/
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "testdata/case/Proxy"]
2 | path = testdata/case/Proxy
3 | url = https://github.com/sgtest/csharp-testcase
4 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: install dep
2 |
3 | default: install
4 |
5 | install:
6 | cd Srclib.Nuget && dnu restore
7 |
8 | dep:
9 | dnu restore Srclib.Nuget/project.json
10 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/Microsoft.Dnx.Runtime.Abstractions.1.0.0-rc1-15838.nupkg.sha512:
--------------------------------------------------------------------------------
1 | ttAofn7DI73KBu50QqPbB3hN/E1bZO+NNNZnpHkEmLP2dh5Lqm2isho3vdrm25Bv2S7RETrIPXcERMOfGCcaow==
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/Microsoft.Framework.CommandLineUtils.Sources.1.0.0-rc1-15779.nupkg.sha512:
--------------------------------------------------------------------------------
1 | rCtNsKlDIdK7Lbww0dIaDym2EfeEzM3zQcg4S1NzVZ4KRHvR9agmEs3yY01WRNYjUy/3/7GqCxoyVALwTIH38Q==
--------------------------------------------------------------------------------
/.bin/srclib-csharp:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | BIN_DIR="`dirname \"$BASH_SOURCE\"`"
4 | ROOT_DIR="`dirname \"$BIN_DIR\"`"
5 | PROJ_DIR="$ROOT_DIR/Srclib.Nuget"
6 | #echo "$PROJ_DIR"
7 |
8 | #echo dnx -p "$PROJ_DIR/project.json" run $*
9 | dnx -p "$PROJ_DIR" run $*
10 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/lib/dnx451/Microsoft.Dnx.Runtime.Abstractions.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourcegraph/srclib-csharp/HEAD/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/lib/dnx451/Microsoft.Dnx.Runtime.Abstractions.dll
--------------------------------------------------------------------------------
/Srclib.Nuget/Srclib.Nuget.xproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Start
5 |
6 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/lib/dnxcore50/Microsoft.Dnx.Runtime.Abstractions.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourcegraph/srclib-csharp/HEAD/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/lib/dnxcore50/Microsoft.Dnx.Runtime.Abstractions.dll
--------------------------------------------------------------------------------
/testdata/expected/Proxy/Test/NugetPackage.unit.json:
--------------------------------------------------------------------------------
1 | {"Name":"Test","Type":"NugetPackage","Files":["src/Test/Properties/AssemblyInfo.cs","src/Test/Class2.cs","src/Test/Class1.cs"],"Dir":"src/Test","Dependencies":[{"Version":"Newtonsoft.Json \u003e= 8.0.2","Name":"Newtonsoft.Json"}]}
2 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/Microsoft.Dnx.Runtime.Abstractions.1.0.0-rc1-15838.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourcegraph/srclib-csharp/HEAD/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/Microsoft.Dnx.Runtime.Abstractions.1.0.0-rc1-15838.nupkg
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/lib/dnx451/Microsoft.Framework.CommandLineUtils.Sources.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourcegraph/srclib-csharp/HEAD/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/lib/dnx451/Microsoft.Framework.CommandLineUtils.Sources.dll
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/lib/dnxcore50/Microsoft.Framework.CommandLineUtils.Sources.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourcegraph/srclib-csharp/HEAD/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/lib/dnxcore50/Microsoft.Framework.CommandLineUtils.Sources.dll
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/Microsoft.Framework.CommandLineUtils.Sources.1.0.0-rc1-15779.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourcegraph/srclib-csharp/HEAD/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/Microsoft.Framework.CommandLineUtils.Sources.1.0.0-rc1-15779.nupkg
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/lib/dnx451/Microsoft.Framework.CommandLineUtils.Sources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Microsoft.Framework.CommandLineUtils.Sources
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/lib/dnxcore50/Microsoft.Framework.CommandLineUtils.Sources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Microsoft.Framework.CommandLineUtils.Sources
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/shared/CommandOptionType.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 |
5 | namespace Microsoft.Dnx.Runtime.Common.CommandLine
6 | {
7 | internal enum CommandOptionType
8 | {
9 | MultipleValue,
10 | SingleValue,
11 | NoValue
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Srclibtoolchain:
--------------------------------------------------------------------------------
1 | {
2 | "Tools": [
3 | {
4 | "Subcmd": "scan",
5 | "Op": "scan",
6 | "SourceUnitTypes": [
7 | "NugetPackage"
8 | ]
9 | },
10 |
11 | {
12 | "Subcmd": "depresolve",
13 | "Op": "depresolve",
14 | "SourceUnitTypes": [
15 | "NugetPackage"
16 | ]
17 | },
18 |
19 | {
20 | "Subcmd": "graph",
21 | "Op": "graph",
22 | "SourceUnitTypes": [
23 | "NugetPackage"
24 | ]
25 | }
26 | ]
27 | }
--------------------------------------------------------------------------------
/Srclib.Nuget/Models/DependencyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Newtonsoft.Json;
3 | using Microsoft.Dnx.Runtime;
4 |
5 | namespace Srclib.Nuget
6 | {
7 | public class DependencyInfo
8 | {
9 | [JsonProperty]
10 | public string Name { get; set; }
11 |
12 | [JsonProperty]
13 | public string Version { get; set; }
14 |
15 | public static DependencyInfo FromLibraryDependency(LibraryDependency lib)
16 | {
17 | return new DependencyInfo {
18 | Name = lib.Name,
19 | Version = lib.LibraryRange.ToString()
20 | };
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/shared/CommandParsingException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 |
6 | namespace Microsoft.Dnx.Runtime.Common.CommandLine
7 | {
8 | internal class CommandParsingException : Exception
9 | {
10 | public CommandParsingException(CommandLineApplication command, string message)
11 | : base(message)
12 | {
13 | Command = command;
14 | }
15 |
16 | public CommandLineApplication Command { get; }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Models/Target.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace Srclib.Nuget
8 | {
9 | public class Target
10 | {
11 | [JsonProperty("ToRepoCloneURL")]
12 | public string RepoCloneURL { get; set; } = "";
13 |
14 | [JsonProperty("ToUnit")]
15 | public string Unit { get; set; }
16 |
17 | [JsonProperty("ToUnitType")]
18 | public string UnitType { get; set; } = SourceUnit.NUGET_PACKAGE;
19 |
20 | [JsonProperty("ToVersionString")]
21 | public string VersionString { get; set; } = "";
22 |
23 | [JsonProperty("ToRevSpec")]
24 | public string RevSpec { get; set; } = "";
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Utils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 | using System.IO;
4 |
5 | namespace Srclib.Nuget
6 | {
7 | static class Utils
8 | {
9 | ///
10 | /// gets a relative filepath from folder to filespec
11 | ///
12 | /// base path
13 | /// destination path
14 | public static string GetRelativePath(string filespec, string folder)
15 | {
16 | filespec = "file://" + filespec;
17 | folder = "file://" + folder;
18 | Uri pathUri = new Uri(filespec);
19 | // Folders must end in a slash
20 | if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString()))
21 | {
22 | folder += Path.DirectorySeparatorChar;
23 | }
24 | Uri folderUri = new Uri(folder);
25 | String s = Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar));
26 | return s;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/shared/CommandArgument.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 |
8 | namespace Microsoft.Dnx.Runtime.Common.CommandLine
9 | {
10 | internal class CommandArgument
11 | {
12 | public CommandArgument()
13 | {
14 | Values = new List();
15 | }
16 |
17 | public string Name { get; set; }
18 | public string Description { get; set; }
19 | public List Values { get; private set; }
20 | public bool MultipleValues { get; set; }
21 | public string Value
22 | {
23 | get
24 | {
25 | return Values.FirstOrDefault();
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Graph/SymbolNameCache.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Collections.Immutable;
5 | using System.Linq;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 |
9 | namespace Srclib.Nuget.Graph
10 | {
11 | static class SymbolNameCache
12 | {
13 | static ImmutableDictionary _cache = ImmutableDictionary.Create();
14 | static ImmutableDictionary _nextId = ImmutableDictionary.Create();
15 |
16 | ///
17 | /// generate a unique for local variable
18 | ///
19 | /// semantic info element representing local variable
20 | public static string GenerateUniqueName(this ISymbol symbol, string kind)
21 | {
22 | var nextId = ImmutableInterlocked.AddOrUpdate(ref _nextId, kind, 0, (_, old) => old + 1);
23 | var id = ImmutableInterlocked.GetOrAdd(ref _cache, symbol, nextId);
24 | return $"{kind}${id}";
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Srclib.Nuget.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Srclib.Nuget", "Srclib.Nuget\Srclib.Nuget.xproj", "{8A6AE90C-B083-42E4-8D47-34C7C22EAD27}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {8A6AE90C-B083-42E4-8D47-34C7C22EAD27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {8A6AE90C-B083-42E4-8D47-34C7C22EAD27}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {8A6AE90C-B083-42E4-8D47-34C7C22EAD27}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {8A6AE90C-B083-42E4-8D47-34C7C22EAD27}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/Srclib.Nuget/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.0.0-beta-*",
3 | "authors": [ "Alxandr" ],
4 |
5 | "dependencies": {
6 | "Newtonsoft.Json": "7.0.1",
7 | "Microsoft.Dnx.Runtime": "1.0.0-rc1-final",
8 | "Microsoft.Dnx.Compilation": "1.0.0-rc1-final",
9 | "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-rc1-15838",
10 | "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-rc1-final",
11 | "Microsoft.Framework.CommandLineUtils.Sources": {"type": "build", "version": "1.0.0-rc1-15779"}
12 | },
13 |
14 | "frameworks": {
15 | "dnx451": {
16 | "frameworkAssemblies": {
17 | "System.Globalization": ""
18 | }
19 | },
20 | "dnxcore50": {
21 | "dependencies": {
22 | "System.Console": "4.0.0-rc2-23530",
23 | "System.Collections": "4.0.11-rc2-23727",
24 | "System.IO": "4.0.11-rc2-23530",
25 | "System.IO.FileSystem": "4.0.1-rc2-23530",
26 | "System.Linq": "4.0.1-rc2-23530",
27 | "System.Diagnostics.Process": "4.1.0-rc2-23530",
28 | "System.Globalization": "4.0.0.0"
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Srclib.Nuget/LibraryUtils.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Dnx.Runtime;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace Srclib.Nuget
8 | {
9 | public static class LibraryUtils
10 | {
11 | public static IEqualityComparer Comparer => new LibraryComparer();
12 |
13 | class LibraryComparer : IEqualityComparer
14 | {
15 | public bool Equals(LibraryDescription x, LibraryDescription y)
16 | {
17 | if (x == null && y == null)
18 | return true;
19 |
20 | if (x.Identity == null || y.Identity == null)
21 | return false;
22 |
23 | return x.Identity.Name == y.Identity.Name &&
24 | x.Identity.Version == y.Identity.Version;
25 | }
26 |
27 | public int GetHashCode(LibraryDescription obj)
28 | {
29 | if (obj == null) return 0;
30 |
31 | if (obj.Identity == null)
32 | return 0;
33 |
34 | return obj.Identity.Name.GetHashCode() ^ obj.Identity.Version.GetHashCode();
35 | }
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Sourcegraph
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Srclib.Nuget.xproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 14.0
5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
6 |
7 |
8 |
9 | 8a6ae90c-b083-42e4-8d47-34c7c22ead27
10 | Srclib.Nuget
11 | ..\artifacts\obj\$(MSBuildProjectName)
12 | ..\artifacts\bin\$(MSBuildProjectName)\
13 |
14 |
15 |
16 | 2.0
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 | dist: trusty
3 |
4 | language: csharp
5 |
6 | before_install:
7 | # installing srclib
8 | - mkdir $HOME/gocode
9 | - export GOPATH=$HOME/gocode
10 | - go get -u -v sourcegraph.com/sourcegraph/srclib/cmd/srclib
11 | - export PATH=$PATH:$HOME/gocode/bin
12 | - mkdir -p $HOME/.srclib/sourcegraph.com/sourcegraph
13 | # installing libunwind (required by C# runtime from Microsoft)
14 | - cd /tmp
15 | - wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
16 | - tar -xvf libunwind-1.1.tar.gz
17 | - cd libunwind-1.1 && ./configure && make > /dev/null 2>&1
18 | - sudo make install
19 | # installing C# runtime from Microsoft
20 | - cd /tmp
21 | - curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
22 | - sudo apt-get install -y gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev
23 | - dnvm upgrade -r coreclr
24 | # registering C# toolchain
25 | - ln -s $TRAVIS_BUILD_DIR $HOME/.srclib/sourcegraph.com/sourcegraph/srclib-csharp
26 | - srclib toolchain list
27 | - cd $TRAVIS_BUILD_DIR
28 |
29 | install:
30 | - dnu restore Srclib.Nuget/project.json
31 |
32 | script:
33 | - srclib -v test
34 |
--------------------------------------------------------------------------------
/Srclib.Nuget/RuntimeEnvironmentExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Text;
5 |
6 | namespace Microsoft.Dnx.Runtime
7 | {
8 | internal static class RuntimeEnvironmentExtensions
9 | {
10 | public static string GetFullVersion(this IRuntimeEnvironment env)
11 | {
12 | var str = new StringBuilder();
13 | str.AppendLine($" Version: {env.RuntimeVersion}");
14 | str.AppendLine($" Type: {env.RuntimeType}");
15 | str.AppendLine($" Architecture: {env.RuntimeArchitecture}");
16 | str.AppendLine($" OS Name: {env.OperatingSystem}");
17 |
18 | if (!string.IsNullOrEmpty(env.OperatingSystemVersion))
19 | {
20 | str.AppendLine($" OS Version: {env.OperatingSystemVersion}");
21 | }
22 |
23 | return str.ToString();
24 | }
25 |
26 | public static string GetShortVersion(this IRuntimeEnvironment env)
27 | {
28 | return $"{env.RuntimeType}-{env.RuntimeArchitecture}-{env.RuntimeVersion}";
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ## Requirements
3 |
4 | srclib-csharp requires:
5 |
6 | * DNX (.NET Execution Environment) aka ASP.NET 5
7 | * .NET Core (coreclr)
8 |
9 | Environmanet installation is described here: http://docs.asp.net/en/latest/getting-started/installing-on-linux.html
10 |
11 | Briefly, you need to install dnvm
12 |
13 | curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
14 |
15 | DNX prerequisites, if necessary
16 |
17 | sudo apt-get install libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev
18 |
19 | and .NET Core
20 |
21 | dnvm upgrade -r coreclr
22 |
23 | ## Building
24 |
25 | With DNX framework there is no explicit building, so just add a new toolchain to srclib by creating a symlink that points to srclib directory
26 |
27 | ln -s . $HOME/.srclib/sourcegraph.com/sourcegraph/srclib-csharp
28 |
29 | You should also load project dependencies by running
30 |
31 | dnu restore Srclib.Nuget/project.json
32 |
33 | or using
34 |
35 | make dep
36 |
37 | which does exactly the same
38 |
39 | ## Testing
40 |
41 | Run `git submodule update --init` the first time to fetch the submodule test
42 | cases in `testdata/case`.
43 |
44 | `srclib test` - run tests
45 |
46 | `srclib test --gen` - regenerate new test data
47 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Graph/GraphContext.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Dnx.Compilation;
2 | using Microsoft.Dnx.Runtime;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using Microsoft.CodeAnalysis.CSharp;
8 |
9 |
10 | namespace Srclib.Nuget.Graph
11 | {
12 | public class GraphContext
13 | {
14 | public SourceUnit SourceUnit { get; set; }
15 | public string ProjectDirectory { get; set; }
16 | public Project Project { get; set; }
17 | public ApplicationHostContext ApplicationHostContext { get; set; }
18 | public Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment HostEnvironment { get; set; }
19 | public Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment ApplicationEnvironment { get; set; }
20 | public Microsoft.Extensions.PlatformAbstractions.IAssemblyLoadContextAccessor LoadContextAccessor { get; set; }
21 | public CompilationEngineContext CompilationContext { get; set; }
22 | public CompilationEngine CompilationEngine { get; set; }
23 | public ILibraryExporter LibraryExporter { get; set; }
24 | public LibraryExport Export { get; set; }
25 | public CSharpCompilation Compilation { get; set; }
26 | public string RootPath { get; set; }
27 | public Microsoft.Extensions.PlatformAbstractions.IRuntimeEnvironment RuntimeEnvironment { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/Microsoft.Framework.CommandLineUtils.Sources.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Microsoft.Framework.CommandLineUtils.Sources
5 | 1.0.0-rc1-15779
6 | true
7 | Microsoft
8 | Microsoft
9 | http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm
10 | http://www.asp.net/
11 | http://go.microsoft.com/fwlink/?LinkID=288859
12 | Microsoft.Framework.CommandLineUtils.Sources
13 | Copyright © Microsoft Corporation
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Dnx.Runtime;
3 | using Microsoft.Dnx.Runtime.Common.CommandLine;
4 |
5 | namespace Srclib.Nuget
6 | {
7 | public class Program
8 | {
9 | readonly Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment _env;
10 | readonly Microsoft.Extensions.PlatformAbstractions.IRuntimeEnvironment _runtimeEnv;
11 | readonly Microsoft.Extensions.PlatformAbstractions.IAssemblyLoadContextAccessor _loadContextAccessor;
12 |
13 | public Program(Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment env, Microsoft.Extensions.PlatformAbstractions.IRuntimeEnvironment runtimeEnv, Microsoft.Extensions.PlatformAbstractions.IAssemblyLoadContextAccessor loadContextAccessor)
14 | {
15 | _env = env;
16 | _runtimeEnv = runtimeEnv;
17 | _loadContextAccessor = loadContextAccessor;
18 | }
19 |
20 | public int Main(string[] args)
21 | {
22 | var app = new CommandLineApplication(throwOnUnexpectedArg: true);
23 | app.Name = "srclib-csharp";
24 | app.FullName = "Scrlib C# toolchain";
25 |
26 | app.HelpOption("-?|-h|--help");
27 |
28 | // Show help information if no subcommand/option was specified
29 | app.OnExecute(() =>
30 | {
31 | app.ShowHelp();
32 | return 2;
33 | });
34 |
35 | ScanConsoleCommand.Register(app, _env);
36 | GraphConsoleCommand.Register(app, _env, _loadContextAccessor, _runtimeEnv);
37 | DepresolveConsoleCommand.Register(app, _env, _runtimeEnv);
38 |
39 | return app.Execute(args);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Srclib.Nuget/ConsoleCommands/GraphConsoleCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Collections.Generic;
4 | using Microsoft.Dnx.Runtime;
5 | using Microsoft.Dnx.Runtime.Common.CommandLine;
6 | using Newtonsoft.Json;
7 | using Srclib.Nuget.Graph;
8 |
9 | namespace Srclib.Nuget
10 | {
11 | class GraphConsoleCommand
12 | {
13 | public static void Register(CommandLineApplication cmdApp, Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment appEnvironment, Microsoft.Extensions.PlatformAbstractions.IAssemblyLoadContextAccessor loadContextAccessor, Microsoft.Extensions.PlatformAbstractions.IRuntimeEnvironment runtimeEnvironment)
14 | {
15 | cmdApp.Command("graph", (Action)(c => {
16 | c.Description = "Perform parsing, static analysis, semantic analysis, and type inference";
17 |
18 | c.HelpOption("-?|-h|--help");
19 |
20 | c.OnExecute((Func>)(async () => {
21 | var jsonIn = await Console.In.ReadToEndAsync();
22 | var sourceUnit = JsonConvert.DeserializeObject(jsonIn);
23 |
24 | var root = Directory.GetCurrentDirectory();
25 | var dir = Path.Combine(root, sourceUnit.Dir);
26 | var context = new GraphContext
27 | {
28 | RootPath = root,
29 | SourceUnit = sourceUnit,
30 | ProjectDirectory = dir,
31 | HostEnvironment = appEnvironment,
32 | LoadContextAccessor = loadContextAccessor,
33 | RuntimeEnvironment = runtimeEnvironment
34 | };
35 |
36 | var result = await GraphRunner.Graph(context);
37 |
38 | Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
39 | return 0;
40 | }));
41 | }));
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/Microsoft.Dnx.Runtime.Abstractions.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Microsoft.Dnx.Runtime.Abstractions
5 | 1.0.0-rc1-15838
6 | true
7 | Microsoft
8 | Microsoft
9 | http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm
10 | http://www.asp.net/
11 | http://go.microsoft.com/fwlink/?LinkID=288859
12 | ASP.NET 5 interfaces to take advantage of capabilities exposed by the runtime.
13 | Copyright © Microsoft Corporation
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Models/Resolution.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.Dnx.Runtime;
7 | using System.IO;
8 |
9 | namespace Srclib.Nuget
10 | {
11 | public class Resolution
12 | {
13 | const string REPO_FILE_NAME = "repo.json";
14 |
15 | [JsonProperty]
16 | public ResolutionIdentity Raw { get; set; }
17 |
18 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
19 | public Target ResolvedTarget { get; set; }
20 |
21 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
22 | public string Error { get; set; }
23 |
24 | internal static Resolution FromLibrary(LibraryDescription lib)
25 | {
26 | if (lib.Identity != null)
27 | {
28 | var url = "";
29 | var commit = "";
30 | var repoFile = Path.Combine(lib.Path, REPO_FILE_NAME);
31 | if (File.Exists(repoFile))
32 | {
33 | var content = File.ReadAllText(repoFile);
34 | var spec = JsonConvert.DeserializeObject(content);
35 | if (spec.Url.Contains("github"))
36 | {
37 | url = spec.Url;
38 | commit = spec.Commit;
39 | }
40 | }
41 |
42 | return new Resolution
43 | {
44 | Raw = new ResolutionIdentity
45 | {
46 | Name = lib.Identity.Name,
47 | Version = lib.Identity.Version.ToString()
48 | },
49 | ResolvedTarget = new Target
50 | {
51 | Unit = lib.Identity.Name,
52 | VersionString = lib.Identity.Version.ToString(),
53 | RepoCloneURL = url,
54 | RevSpec = commit
55 | }
56 | };
57 | }
58 | else
59 | {
60 | return new Resolution
61 | {
62 | Raw = new ResolutionIdentity
63 | {
64 | Name = lib.RequestedRange.Name,
65 | Version = lib.RequestedRange.VersionRange.ToString()
66 | },
67 | Error = "Dependensy resolution failed"
68 | };
69 | }
70 | }
71 | }
72 |
73 | public class ResolutionIdentity
74 | {
75 | [JsonProperty]
76 | public string Name { get; set; }
77 |
78 | [JsonProperty]
79 | public string Version { get; set; }
80 | }
81 |
82 | public class RepoJson
83 | {
84 | [JsonProperty("url")]
85 | public string Url { get; set; }
86 |
87 | [JsonProperty("commit")]
88 | public string Commit { get; set; }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Models/SourceUnit.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using Newtonsoft.Json;
4 | using Microsoft.Dnx.Runtime;
5 | using System;
6 | using System.IO;
7 |
8 | namespace Srclib.Nuget
9 | {
10 | public class SourceUnit
11 | {
12 | public const string NUGET_PACKAGE = "NugetPackage";
13 |
14 | [JsonProperty]
15 | public string Name { get; set; }
16 |
17 | [JsonProperty]
18 | public string Type { get; set; } = NUGET_PACKAGE;
19 |
20 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
21 | public string Repo { get; set; }
22 |
23 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
24 | public string CommitID { get; set; }
25 |
26 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
27 | public string[] Globs { get; set; }
28 |
29 | [JsonProperty]
30 | public string[] Files { get; set; }
31 |
32 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
33 | public string Dir { get; set; }
34 |
35 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
36 | public DependencyInfo[] Dependencies { get; set; }
37 |
38 | [JsonProperty]
39 | public SourceUnit Data { get; set; }
40 |
41 | internal static SourceUnit FromProject(Project project, string root)
42 | {
43 | var su = new SourceUnit
44 | {
45 | Name = project.Name,
46 | Dir = Utils.GetRelativePath(project.ProjectDirectory, root),
47 | Files = project.Files.SourceFiles.Select(p => Utils.GetRelativePath(p, root)).OrderByDescending(p => p).ToArray(),
48 | Dependencies = project.Dependencies.Select(DependencyInfo.FromLibraryDependency).ToArray(),
49 | };
50 |
51 | return su;
52 | }
53 |
54 | internal static SourceUnit FromDirectory(string name, string root)
55 | {
56 | DirectoryInfo di = new DirectoryInfo(root);
57 | FileInfo[] sources = DepresolveConsoleCommand.FindSources(di);
58 | string[] files = new string[sources.Length];
59 | for (int i = 0; i < sources.Length; i++)
60 | {
61 | files[i] = Utils.GetRelativePath(sources[i].FullName, root);
62 | }
63 | files.OrderByDescending(p => p);
64 | var su = new SourceUnit
65 | {
66 | Name = name,
67 | Dir = root,
68 | Files = files,
69 | Dependencies = new DependencyInfo[0],
70 | };
71 |
72 | return su;
73 | }
74 |
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/shared/CommandOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 |
8 | namespace Microsoft.Dnx.Runtime.Common.CommandLine
9 | {
10 | internal class CommandOption
11 | {
12 | public CommandOption(string template, CommandOptionType optionType)
13 | {
14 | Template = template;
15 | OptionType = optionType;
16 | Values = new List();
17 |
18 | foreach (var part in Template.Split(new[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries))
19 | {
20 | if (part.StartsWith("--"))
21 | {
22 | LongName = part.Substring(2);
23 | }
24 | else if (part.StartsWith("-"))
25 | {
26 | var optName = part.Substring(1);
27 |
28 | // If there is only one char and it is not an English letter, it is a symbol option (e.g. "-?")
29 | if (optName.Length == 1 && !IsEnglishLetter(optName[0]))
30 | {
31 | SymbolName = optName;
32 | }
33 | else
34 | {
35 | ShortName = optName;
36 | }
37 | }
38 | else if (part.StartsWith("<") && part.EndsWith(">"))
39 | {
40 | ValueName = part.Substring(1, part.Length - 2);
41 | }
42 | else
43 | {
44 | throw new ArgumentException($"Invalid template pattern '{template}'", nameof(template));
45 | }
46 | }
47 |
48 | if (string.IsNullOrEmpty(LongName) && string.IsNullOrEmpty(ShortName) && string.IsNullOrEmpty(SymbolName))
49 | {
50 | throw new ArgumentException($"Invalid template pattern '{template}'", nameof(template));
51 | }
52 | }
53 |
54 | public string Template { get; set; }
55 | public string ShortName { get; set; }
56 | public string LongName { get; set; }
57 | public string SymbolName { get; set; }
58 | public string ValueName { get; set; }
59 | public string Description { get; set; }
60 | public List Values { get; private set; }
61 | public CommandOptionType OptionType { get; private set; }
62 |
63 | public bool TryParse(string value)
64 | {
65 | switch (OptionType)
66 | {
67 | case CommandOptionType.MultipleValue:
68 | Values.Add(value);
69 | break;
70 | case CommandOptionType.SingleValue:
71 | if (Values.Any())
72 | {
73 | return false;
74 | }
75 | Values.Add(value);
76 | break;
77 | case CommandOptionType.NoValue:
78 | if (value != null)
79 | {
80 | return false;
81 | }
82 | // Add a value to indicate that this option was specified
83 | Values.Add("on");
84 | break;
85 | default:
86 | break;
87 | }
88 | return true;
89 | }
90 |
91 | public bool HasValue()
92 | {
93 | return Values.Any();
94 | }
95 |
96 | public string Value()
97 | {
98 | return HasValue() ? Values[0] : null;
99 | }
100 |
101 | private bool IsEnglishLetter(char c)
102 | {
103 | return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
104 | }
105 | }
106 | }
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/shared/AnsiConsole.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.IO;
6 |
7 | namespace Microsoft.Dnx.Runtime.Common.CommandLine
8 | {
9 | internal class AnsiConsole
10 | {
11 | private AnsiConsole(TextWriter writer, bool useConsoleColor)
12 | {
13 | Writer = writer;
14 |
15 | _useConsoleColor = useConsoleColor;
16 | if (_useConsoleColor)
17 | {
18 | OriginalForegroundColor = Console.ForegroundColor;
19 | }
20 | }
21 |
22 | private int _boldRecursion;
23 | private bool _useConsoleColor;
24 |
25 | public static AnsiConsole GetOutput(bool useConsoleColor)
26 | {
27 | return new AnsiConsole(Console.Out, useConsoleColor);
28 | }
29 |
30 | public static AnsiConsole GetError(bool useConsoleColor)
31 | {
32 | return new AnsiConsole(Console.Error, useConsoleColor);
33 | }
34 |
35 | public TextWriter Writer { get; }
36 |
37 | public ConsoleColor OriginalForegroundColor { get; }
38 |
39 | private void SetColor(ConsoleColor color)
40 | {
41 | Console.ForegroundColor = (ConsoleColor)(((int)Console.ForegroundColor & 0x08) | ((int)color & 0x07));
42 | }
43 |
44 | private void SetBold(bool bold)
45 | {
46 | _boldRecursion += bold ? 1 : -1;
47 | if (_boldRecursion > 1 || (_boldRecursion == 1 && !bold))
48 | {
49 | return;
50 | }
51 |
52 | Console.ForegroundColor = (ConsoleColor)((int)Console.ForegroundColor ^ 0x08);
53 | }
54 |
55 | public void WriteLine(string message)
56 | {
57 | if (!_useConsoleColor)
58 | {
59 | Writer.WriteLine(message);
60 | return;
61 | }
62 |
63 | var escapeScan = 0;
64 | for (; ;)
65 | {
66 | var escapeIndex = message.IndexOf("\x1b[", escapeScan);
67 | if (escapeIndex == -1)
68 | {
69 | var text = message.Substring(escapeScan);
70 | Writer.Write(text);
71 | break;
72 | }
73 | else
74 | {
75 | var startIndex = escapeIndex + 2;
76 | var endIndex = startIndex;
77 | while (endIndex != message.Length &&
78 | message[endIndex] >= 0x20 &&
79 | message[endIndex] <= 0x3f)
80 | {
81 | endIndex += 1;
82 | }
83 |
84 | var text = message.Substring(escapeScan, escapeIndex - escapeScan);
85 | Writer.Write(text);
86 | if (endIndex == message.Length)
87 | {
88 | break;
89 | }
90 |
91 | switch (message[endIndex])
92 | {
93 | case 'm':
94 | int value;
95 | if (int.TryParse(message.Substring(startIndex, endIndex - startIndex), out value))
96 | {
97 | switch (value)
98 | {
99 | case 1:
100 | SetBold(true);
101 | break;
102 | case 22:
103 | SetBold(false);
104 | break;
105 | case 30:
106 | SetColor(ConsoleColor.Black);
107 | break;
108 | case 31:
109 | SetColor(ConsoleColor.Red);
110 | break;
111 | case 32:
112 | SetColor(ConsoleColor.Green);
113 | break;
114 | case 33:
115 | SetColor(ConsoleColor.Yellow);
116 | break;
117 | case 34:
118 | SetColor(ConsoleColor.Blue);
119 | break;
120 | case 35:
121 | SetColor(ConsoleColor.Magenta);
122 | break;
123 | case 36:
124 | SetColor(ConsoleColor.Cyan);
125 | break;
126 | case 37:
127 | SetColor(ConsoleColor.Gray);
128 | break;
129 | case 39:
130 | SetColor(OriginalForegroundColor);
131 | break;
132 | }
133 | }
134 | break;
135 | }
136 |
137 | escapeScan = endIndex + 1;
138 | }
139 | }
140 | Writer.WriteLine();
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Graph/SymbolExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Collections.Immutable;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 |
8 | namespace Srclib.Nuget.Graph
9 | {
10 | static class SymbolExtensions
11 | {
12 | public struct KeyData
13 | {
14 | public string Key { get; }
15 | public string Path { get; }
16 | internal string Sep { get; }
17 |
18 | public KeyData(string key, string path, string sep)
19 | {
20 | Key = key;
21 | Path = path;
22 | Sep = sep;
23 | }
24 |
25 | internal static KeyData Empty { get; } = new KeyData(null, null, null);
26 | internal static KeyData FromKey(string key) => new KeyData(key, null, null);
27 | internal static KeyData Append(KeyData key, Segment segment) =>
28 | new KeyData(key.Key + key.Sep + segment.Name, string.IsNullOrEmpty(key.Path) ? segment.Name : key.Path + "/" + segment.Name, segment.Separator);
29 | }
30 |
31 | internal struct Segment
32 | {
33 | public string Name { get; }
34 | public string Separator { get; }
35 |
36 | private Segment(string name, string sep)
37 | {
38 | Name = name;
39 | Separator = sep;
40 | }
41 |
42 | public static Segment From(ISymbol symbol, string separator)
43 | {
44 | return new Segment(GetSymbolName(symbol), separator);
45 | }
46 | }
47 |
48 | public static KeyData GetGraphKey(this ISymbol symbol)
49 | {
50 | var key = GetGraphKeyImpl(symbol);
51 | if (string.IsNullOrEmpty(key.Key))
52 | throw new InvalidOperationException("Key cannot be empty");
53 | if (string.IsNullOrEmpty(key.Path))
54 | throw new InvalidOperationException("Path cannot be empty");
55 |
56 | return key;
57 | }
58 |
59 | static KeyData GetGraphKeyImpl(ISymbol symbol,
60 | bool allowTypeParameter = false)
61 | {
62 | if (allowTypeParameter && symbol is ITypeParameterSymbol)
63 | {
64 | return KeyData.FromKey(GetSymbolName(symbol));
65 | }
66 |
67 | var segments = GetGraphKeyImpl(symbol, ImmutableList.Create());
68 | return segments.Aggregate(KeyData.Empty, KeyData.Append);
69 | }
70 |
71 | static IEnumerable GetGraphKeyImpl(ISymbol symbol, IImmutableList acc)
72 | {
73 | if (symbol == null)
74 | return acc.Reverse();
75 |
76 | if (symbol is ITypeSymbol)
77 | return GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "+")));
78 |
79 | if (symbol is INamespaceSymbol)
80 | {
81 | if (((INamespaceSymbol)symbol).IsGlobalNamespace)
82 | return GetGraphKeyImpl(symbol.ContainingSymbol, acc);
83 |
84 | return GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, ".")));
85 | }
86 |
87 | if (symbol is IModuleSymbol)
88 | return GetGraphKeyImpl(symbol.ContainingSymbol, acc);
89 |
90 | if (symbol is IAssemblySymbol)
91 | return GetGraphKeyImpl(symbol.ContainingSymbol, acc);
92 |
93 | return GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "!")));
94 | }
95 |
96 | static string GetSymbolName(ISymbol symbol)
97 | {
98 | var method = symbol as IMethodSymbol;
99 | if (method != null)
100 | {
101 | var name = method.MetadataName;
102 | if (method.MethodKind == MethodKind.LambdaMethod)
103 | {
104 | name = method.GenerateUniqueName("-lambda");
105 | }
106 | else if (method.MethodKind == MethodKind.Conversion)
107 | {
108 | string returnTypeName;
109 | if (method.ReturnType is INamedTypeSymbol)
110 | {
111 | var t = method.ReturnType as INamedTypeSymbol;
112 | if (t.TypeArguments.Length > 0)
113 | {
114 | returnTypeName = $"{t.MetadataName}<{string.Join(",", t.TypeArguments.Select(p => GetGraphKeyImpl(p, allowTypeParameter: true).Key))}>";
115 | }
116 | else
117 | {
118 | returnTypeName = t.MetadataName;
119 | }
120 | }
121 | else
122 | {
123 | returnTypeName = method.ReturnType.MetadataName;
124 | }
125 | name = returnTypeName + "=" + name;
126 | }
127 |
128 | if (method.IsGenericMethod)
129 | {
130 | name = name + "`" + method.TypeParameters.Length;
131 | }
132 |
133 | return $"{name}({string.Join(";", method.Parameters.Select(p => GetGraphKeyImpl(p.Type, allowTypeParameter: true).Key))})";
134 | }
135 |
136 | if (symbol is INamedTypeSymbol)
137 | {
138 | var type = symbol as INamedTypeSymbol;
139 | var name = type.MetadataName;
140 | if (type.TypeArguments.Length > 0)
141 | {
142 | return $"{name}<{string.Join(",", type.TypeArguments.Select(p => GetGraphKeyImpl(p, allowTypeParameter: true).Key))}>";
143 | }
144 | else
145 | {
146 | return symbol.MetadataName;
147 | }
148 | }
149 |
150 | if (symbol is IArrayTypeSymbol)
151 | {
152 | var s = symbol as IArrayTypeSymbol;
153 | string underlying = GetSymbolName(s.ElementType);
154 | int rank = s.Rank;
155 | string res = underlying + "[";
156 | for (int i = 0; i < rank - 1; i++)
157 | {
158 | res = res + ",";
159 | }
160 | res = res + "]";
161 | return res;
162 | }
163 |
164 | var local = symbol as ILocalSymbol;
165 | if (local != null)
166 | {
167 | // As far as I know, you can define the same named local several places within a single method body.
168 | return local.GenerateUniqueName(local.MetadataName);
169 | }
170 |
171 | return symbol.MetadataName;
172 | }
173 |
174 | public static bool IsExported(this ISymbol symbol)
175 | {
176 | return symbol.DeclaredAccessibility == Accessibility.Public
177 | || symbol.DeclaredAccessibility == Accessibility.Protected
178 | || symbol.DeclaredAccessibility == Accessibility.ProtectedAndInternal
179 | || symbol.DeclaredAccessibility == Accessibility.ProtectedOrInternal;
180 | }
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Documentation/DocProcessor.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Xml;
8 | using System.Xml.Linq;
9 |
10 | namespace Srclib.Nuget.Documentation
11 | {
12 | ///
13 | /// Utility class to deal with xml documentation.
14 | ///
15 | ///
16 | /// These remarks are just here to test that it works.
17 | ///
18 | public static class DocProcessor
19 | {
20 | ///
21 | /// Process a type (class or struct or interface) declaration for documentation.
22 | ///
23 | /// The type in question.
24 | /// Docs if the type contains any, otherwise null.
25 | public static Doc ForClass(INamedTypeSymbol symbol)
26 | {
27 | try
28 | {
29 | var doc = symbol.GetDocumentationCommentXml();
30 | if (string.IsNullOrEmpty(doc))
31 | {
32 | return null;
33 | }
34 |
35 | var sections = new List>();
36 | var xdoc = XDocument.Parse(doc).Root;
37 |
38 | ProcessFull(xdoc, sections);
39 |
40 | if (sections.Count == 0)
41 | return null;
42 |
43 | var resultString = String.Join("\n", sections.Select(t => $"{t.Item2}{t.Item3}"));
44 |
45 | return new Doc
46 | {
47 | Format = "text/html",
48 | Data = resultString
49 | };
50 | }
51 | catch (Exception e)
52 | {
53 | return null;
54 | }
55 | }
56 |
57 | ///
58 | /// Process a method declaration for documentation.
59 | ///
60 | /// The method in question.
61 | /// Docs if the method contains any, otherwise null.
62 | public static Doc ForMethod(IMethodSymbol symbol)
63 | {
64 | try
65 | {
66 | var doc = symbol.GetDocumentationCommentXml();
67 | if (string.IsNullOrEmpty(doc))
68 | {
69 | return null;
70 | }
71 |
72 | var sections = new List>();
73 | var xdoc = XDocument.Parse(doc).Root;
74 |
75 | ProcessFull(xdoc, sections);
76 | var cursor = sections.FindIndex(t => t.Item2 == "Summary");
77 | var paramsSection = ProcessParameters(xdoc, symbol.Parameters.Select(p => p.Name).ToList());
78 | sections.Insert(cursor + 1, paramsSection);
79 |
80 | var returnElement = xdoc.Element("returns");
81 | if (returnElement != null)
82 | {
83 | var content = ProcessContent(returnElement);
84 | if (!string.IsNullOrEmpty(content))
85 | {
86 | sections.Insert(cursor + 2, Tuple.Create(2, "Return value", $"{content}
"));
87 | }
88 | }
89 |
90 | var resultString = string.Join("\n", sections.Select(t => $"{t.Item2}{t.Item3}"));
91 |
92 | return new Doc
93 | {
94 | Format = "text/html",
95 | Data = resultString
96 | };
97 | }
98 | catch (Exception e)
99 | {
100 | return null;
101 | }
102 | }
103 |
104 | public static Tuple ProcessParameters(XElement doc, IList names)
105 | {
106 | var sb = new StringBuilder();
107 | using (var writer = XmlWriter.Create(sb, new XmlWriterSettings { OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Fragment }))
108 | {
109 | writer.WriteStartElement("dl");
110 | foreach (var name in names)
111 | {
112 | writer.WriteStartElement("dt");
113 | writer.WriteStartElement("em");
114 | writer.WriteString(name);
115 | writer.WriteEndElement();
116 | writer.WriteEndElement();
117 |
118 | writer.WriteStartElement("dd");
119 | var node = doc.Elements("param").Where(e => e.Attribute("name").Value == name).FirstOrDefault();
120 | if (node != null)
121 | {
122 | ProcessContent(node, writer);
123 | }
124 | else
125 | {
126 | writer.WriteStartElement("span");
127 | writer.WriteAttributeString("class", "empty-param");
128 | writer.WriteString("No documentation found.");
129 | writer.WriteEndElement();
130 | }
131 | writer.WriteEndElement();
132 | }
133 | writer.WriteEndElement();
134 | }
135 |
136 | return Tuple.Create(2, "Parameters", sb.ToString());
137 | }
138 |
139 | static void ProcessFull(XElement doc, List> sections)
140 | {
141 | var summary = doc.Element("summary");
142 | var remarks = doc.Element("remarks");
143 |
144 | if (summary != null)
145 | {
146 | var text = ProcessContent(summary);
147 | if (!string.IsNullOrEmpty(text))
148 | sections.Add(Tuple.Create(1, "Summary", $"{text}
"));
149 | }
150 |
151 | if (remarks != null)
152 | {
153 | var text = ProcessContent(remarks);
154 | if (!string.IsNullOrEmpty(text))
155 | sections.Add(Tuple.Create(1, "Remarks", $"{text}
"));
156 | }
157 | }
158 |
159 | static string ProcessContent(XElement node)
160 | {
161 | var sb = new StringBuilder();
162 | using (var writer = XmlWriter.Create(sb, new XmlWriterSettings { OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Fragment }))
163 | {
164 | var notEmpty = ProcessContent(node, writer);
165 | if (!notEmpty)
166 | {
167 | return null;
168 | }
169 | }
170 |
171 | return sb.ToString();
172 | }
173 |
174 | static bool ProcessContent(XElement node, XmlWriter writer)
175 | {
176 | bool written = false;
177 | using (var reader = node.CreateReader())
178 | {
179 | while (!reader.EOF)
180 | {
181 | switch (reader.NodeType)
182 | {
183 | case XmlNodeType.Text:
184 | written = true;
185 | writer.WriteString(reader.Value);
186 | break;
187 |
188 | case XmlNodeType.Element:
189 | switch (reader.LocalName)
190 | {
191 | case "see":
192 | written = true;
193 | var cref = reader.GetAttribute("cref");
194 | writer.WriteStartElement("span");
195 |
196 | //TODO($Alxandr): lookup actual symbol.
197 | writer.WriteAttributeString("data-cref", cref);
198 | writer.WriteString(cref);
199 | writer.WriteEndElement();
200 | break;
201 |
202 | case "c":
203 | written = true;
204 | writer.WriteStartElement("strong");
205 | break;
206 | }
207 |
208 | break;
209 |
210 | case XmlNodeType.EndElement:
211 | switch (reader.LocalName)
212 | {
213 | case "c":
214 | writer.WriteEndElement();
215 | break;
216 | }
217 |
218 | break;
219 | }
220 |
221 | reader.Read();
222 | }
223 | }
224 |
225 | return written;
226 | }
227 | }
228 | }
229 |
--------------------------------------------------------------------------------
/testdata/expected/Proxy/Test/NugetPackage.depresolve.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "Raw": {
4 | "Name": "Microsoft.CSharp",
5 | "Version": "4.0.1-beta-23516"
6 | },
7 | "ResolvedTarget": {
8 | "ToRepoCloneURL": "",
9 | "ToUnit": "Microsoft.CSharp",
10 | "ToUnitType": "NugetPackage",
11 | "ToVersionString": "4.0.1-beta-23516",
12 | "ToRevSpec": ""
13 | }
14 | },
15 | {
16 | "Raw": {
17 | "Name": "Newtonsoft.Json",
18 | "Version": "8.0.2"
19 | },
20 | "ResolvedTarget": {
21 | "ToRepoCloneURL": "",
22 | "ToUnit": "Newtonsoft.Json",
23 | "ToUnitType": "NugetPackage",
24 | "ToVersionString": "8.0.2",
25 | "ToRevSpec": ""
26 | }
27 | },
28 | {
29 | "Raw": {
30 | "Name": "System.Collections",
31 | "Version": "4.0.10"
32 | },
33 | "ResolvedTarget": {
34 | "ToRepoCloneURL": "",
35 | "ToUnit": "System.Collections",
36 | "ToUnitType": "NugetPackage",
37 | "ToVersionString": "4.0.10",
38 | "ToRevSpec": ""
39 | }
40 | },
41 | {
42 | "Raw": {
43 | "Name": "System.Diagnostics.Debug",
44 | "Version": "4.0.10"
45 | },
46 | "ResolvedTarget": {
47 | "ToRepoCloneURL": "",
48 | "ToUnit": "System.Diagnostics.Debug",
49 | "ToUnitType": "NugetPackage",
50 | "ToVersionString": "4.0.10",
51 | "ToRevSpec": ""
52 | }
53 | },
54 | {
55 | "Raw": {
56 | "Name": "System.Dynamic.Runtime",
57 | "Version": "4.0.0"
58 | },
59 | "ResolvedTarget": {
60 | "ToRepoCloneURL": "",
61 | "ToUnit": "System.Dynamic.Runtime",
62 | "ToUnitType": "NugetPackage",
63 | "ToVersionString": "4.0.0",
64 | "ToRevSpec": ""
65 | }
66 | },
67 | {
68 | "Raw": {
69 | "Name": "System.Globalization",
70 | "Version": "4.0.10"
71 | },
72 | "ResolvedTarget": {
73 | "ToRepoCloneURL": "",
74 | "ToUnit": "System.Globalization",
75 | "ToUnitType": "NugetPackage",
76 | "ToVersionString": "4.0.10",
77 | "ToRevSpec": ""
78 | }
79 | },
80 | {
81 | "Raw": {
82 | "Name": "System.IO",
83 | "Version": "4.0.0"
84 | },
85 | "ResolvedTarget": {
86 | "ToRepoCloneURL": "",
87 | "ToUnit": "System.IO",
88 | "ToUnitType": "NugetPackage",
89 | "ToVersionString": "4.0.0",
90 | "ToRevSpec": ""
91 | }
92 | },
93 | {
94 | "Raw": {
95 | "Name": "System.Linq",
96 | "Version": "4.0.0"
97 | },
98 | "ResolvedTarget": {
99 | "ToRepoCloneURL": "",
100 | "ToUnit": "System.Linq",
101 | "ToUnitType": "NugetPackage",
102 | "ToVersionString": "4.0.0",
103 | "ToRevSpec": ""
104 | }
105 | },
106 | {
107 | "Raw": {
108 | "Name": "System.Linq.Expressions",
109 | "Version": "4.0.0"
110 | },
111 | "ResolvedTarget": {
112 | "ToRepoCloneURL": "",
113 | "ToUnit": "System.Linq.Expressions",
114 | "ToUnitType": "NugetPackage",
115 | "ToVersionString": "4.0.0",
116 | "ToRevSpec": ""
117 | }
118 | },
119 | {
120 | "Raw": {
121 | "Name": "System.ObjectModel",
122 | "Version": "4.0.10"
123 | },
124 | "ResolvedTarget": {
125 | "ToRepoCloneURL": "",
126 | "ToUnit": "System.ObjectModel",
127 | "ToUnitType": "NugetPackage",
128 | "ToVersionString": "4.0.10",
129 | "ToRevSpec": ""
130 | }
131 | },
132 | {
133 | "Raw": {
134 | "Name": "System.Reflection",
135 | "Version": "4.0.10"
136 | },
137 | "ResolvedTarget": {
138 | "ToRepoCloneURL": "",
139 | "ToUnit": "System.Reflection",
140 | "ToUnitType": "NugetPackage",
141 | "ToVersionString": "4.0.10",
142 | "ToRevSpec": ""
143 | }
144 | },
145 | {
146 | "Raw": {
147 | "Name": "System.Reflection.Extensions",
148 | "Version": "4.0.0"
149 | },
150 | "ResolvedTarget": {
151 | "ToRepoCloneURL": "",
152 | "ToUnit": "System.Reflection.Extensions",
153 | "ToUnitType": "NugetPackage",
154 | "ToVersionString": "4.0.0",
155 | "ToRevSpec": ""
156 | }
157 | },
158 | {
159 | "Raw": {
160 | "Name": "System.Reflection.Primitives",
161 | "Version": "4.0.0"
162 | },
163 | "ResolvedTarget": {
164 | "ToRepoCloneURL": "",
165 | "ToUnit": "System.Reflection.Primitives",
166 | "ToUnitType": "NugetPackage",
167 | "ToVersionString": "4.0.0",
168 | "ToRevSpec": ""
169 | }
170 | },
171 | {
172 | "Raw": {
173 | "Name": "System.Reflection.TypeExtensions",
174 | "Version": "4.0.0"
175 | },
176 | "ResolvedTarget": {
177 | "ToRepoCloneURL": "",
178 | "ToUnit": "System.Reflection.TypeExtensions",
179 | "ToUnitType": "NugetPackage",
180 | "ToVersionString": "4.0.0",
181 | "ToRevSpec": ""
182 | }
183 | },
184 | {
185 | "Raw": {
186 | "Name": "System.Resources.ResourceManager",
187 | "Version": "4.0.0"
188 | },
189 | "ResolvedTarget": {
190 | "ToRepoCloneURL": "",
191 | "ToUnit": "System.Resources.ResourceManager",
192 | "ToUnitType": "NugetPackage",
193 | "ToVersionString": "4.0.0",
194 | "ToRevSpec": ""
195 | }
196 | },
197 | {
198 | "Raw": {
199 | "Name": "System.Runtime",
200 | "Version": "4.0.20"
201 | },
202 | "ResolvedTarget": {
203 | "ToRepoCloneURL": "",
204 | "ToUnit": "System.Runtime",
205 | "ToUnitType": "NugetPackage",
206 | "ToVersionString": "4.0.20",
207 | "ToRevSpec": ""
208 | }
209 | },
210 | {
211 | "Raw": {
212 | "Name": "System.Runtime.Extensions",
213 | "Version": "4.0.10"
214 | },
215 | "ResolvedTarget": {
216 | "ToRepoCloneURL": "",
217 | "ToUnit": "System.Runtime.Extensions",
218 | "ToUnitType": "NugetPackage",
219 | "ToVersionString": "4.0.10",
220 | "ToRevSpec": ""
221 | }
222 | },
223 | {
224 | "Raw": {
225 | "Name": "System.Runtime.Handles",
226 | "Version": "4.0.0"
227 | },
228 | "ResolvedTarget": {
229 | "ToRepoCloneURL": "",
230 | "ToUnit": "System.Runtime.Handles",
231 | "ToUnitType": "NugetPackage",
232 | "ToVersionString": "4.0.0",
233 | "ToRevSpec": ""
234 | }
235 | },
236 | {
237 | "Raw": {
238 | "Name": "System.Runtime.InteropServices",
239 | "Version": "4.0.20"
240 | },
241 | "ResolvedTarget": {
242 | "ToRepoCloneURL": "",
243 | "ToUnit": "System.Runtime.InteropServices",
244 | "ToUnitType": "NugetPackage",
245 | "ToVersionString": "4.0.20",
246 | "ToRevSpec": ""
247 | }
248 | },
249 | {
250 | "Raw": {
251 | "Name": "System.Text.Encoding",
252 | "Version": "4.0.0"
253 | },
254 | "ResolvedTarget": {
255 | "ToRepoCloneURL": "",
256 | "ToUnit": "System.Text.Encoding",
257 | "ToUnitType": "NugetPackage",
258 | "ToVersionString": "4.0.0",
259 | "ToRevSpec": ""
260 | }
261 | },
262 | {
263 | "Raw": {
264 | "Name": "System.Threading",
265 | "Version": "4.0.10"
266 | },
267 | "ResolvedTarget": {
268 | "ToRepoCloneURL": "",
269 | "ToUnit": "System.Threading",
270 | "ToUnitType": "NugetPackage",
271 | "ToVersionString": "4.0.10",
272 | "ToRevSpec": ""
273 | }
274 | },
275 | {
276 | "Raw": {
277 | "Name": "System.Threading.Tasks",
278 | "Version": "4.0.0"
279 | },
280 | "ResolvedTarget": {
281 | "ToRepoCloneURL": "",
282 | "ToUnit": "System.Threading.Tasks",
283 | "ToUnitType": "NugetPackage",
284 | "ToVersionString": "4.0.0",
285 | "ToRevSpec": ""
286 | }
287 | }
288 | ]
289 |
--------------------------------------------------------------------------------
/Srclib.Nuget/ConsoleCommands/DepresolveConsoleCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Collections.Generic;
5 | using Microsoft.Dnx.Runtime;
6 | using Microsoft.Dnx.Runtime.Common.CommandLine;
7 | using Newtonsoft.Json;
8 | using System.Threading.Tasks;
9 | using System.Diagnostics;
10 |
11 | namespace Srclib.Nuget
12 | {
13 | class DepresolveConsoleCommand
14 | {
15 | static Lazy _dnuPath;
16 |
17 | ///
18 | /// Initialization method for depresolve process
19 | ///
20 | /// application to run (srclib-csharp)
21 | /// common application information
22 | /// environment representation
23 | public static void Register(CommandLineApplication cmdApp, Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment appEnv, Microsoft.Extensions.PlatformAbstractions.IRuntimeEnvironment runtimeEnv)
24 | {
25 | _dnuPath = new Lazy(FindDnuNix);
26 |
27 | cmdApp.Command("depresolve", c =>
28 | {
29 | c.Description = "Perform a combination of parsing, static analysis, semantic analysis, and type inference";
30 |
31 | c.HelpOption("-?|-h|--help");
32 |
33 | c.OnExecute(async () =>
34 | {
35 | var jsonIn = await Console.In.ReadToEndAsync();
36 | var sourceUnit = JsonConvert.DeserializeObject(jsonIn);
37 | var dir = Path.Combine(Directory.GetCurrentDirectory(), sourceUnit.Dir);
38 | var deps = DepResolve(dir);
39 | var result = new List();
40 | foreach (var dep in deps)
41 | {
42 | result.Add(Resolution.FromLibrary(dep));
43 | }
44 | Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
45 | return 0;
46 | });
47 | });
48 | }
49 |
50 | static IEnumerable DepResolve(string dir)
51 | {
52 | Project proj;
53 | if(!Project.TryGetProject(dir, out proj))
54 | {
55 | //not a DNX project
56 | List empty = new List();
57 | return empty;
58 | }
59 |
60 | var allDeps = GetAllDeps(proj);
61 | return allDeps;
62 | }
63 |
64 |
65 | public static IEnumerable DepResolve(Project proj)
66 | {
67 | var allDeps = GetAllDeps(proj);
68 | return allDeps;
69 | }
70 |
71 |
72 | static IEnumerable GetAllDeps(Project proj) =>
73 | proj.GetTargetFrameworks().Select(f => f.FrameworkName)
74 | .SelectMany(f =>
75 | {
76 | var context = new ApplicationHostContext
77 | {
78 | Project = proj,
79 | TargetFramework = f
80 | };
81 | IList libs = null;
82 | while (libs == null) {
83 | try
84 | {
85 | libs = ApplicationHostContext.GetRuntimeLibraries(context);
86 | }
87 | catch (Exception e)
88 | {
89 | }
90 | }
91 | // the first library description is always self-reference, so skip it
92 | return libs.Skip(1);
93 | })
94 | .Distinct(LibraryUtils.Comparer)
95 | .OrderBy(l => l.Identity?.Name);
96 |
97 |
98 | public static async Task RunResolve(string dir)
99 | {
100 | var p = new Process();
101 | p.StartInfo.WorkingDirectory = dir;
102 | p.StartInfo.FileName = _dnuPath.Value;
103 | p.StartInfo.Arguments = "restore";
104 | p.StartInfo.UseShellExecute = false;
105 | p.StartInfo.CreateNoWindow = true;
106 | p.StartInfo.RedirectStandardInput = true;
107 | p.StartInfo.RedirectStandardOutput = true;
108 | p.StartInfo.RedirectStandardError = true;
109 | p.Start();
110 | // it's important to read stdout and stderr, else it might deadlock
111 | var outs = await Task.WhenAll(p.StandardOutput.ReadToEndAsync(), p.StandardError.ReadToEndAsync());
112 | p.WaitForExit();
113 | }
114 |
115 | static string FindDnuNix()
116 | {
117 | return RunForResult("/bin/bash", "-c \"which dnu\"");
118 | }
119 |
120 | public static string RunForResult(string shell, string command)
121 | {
122 | var p = new Process();
123 | p.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
124 | p.StartInfo.FileName = shell;
125 | p.StartInfo.Arguments = command;
126 | p.StartInfo.UseShellExecute = false;
127 | p.StartInfo.CreateNoWindow = true;
128 | p.StartInfo.RedirectStandardInput = true;
129 | p.StartInfo.RedirectStandardOutput = true;
130 | p.StartInfo.RedirectStandardError = false;
131 |
132 | p.Start();
133 | var result = p.StandardOutput.ReadToEnd().Trim();
134 | p.WaitForExit();
135 | return result;
136 | }
137 |
138 | public static FileInfo[] FindSources(DirectoryInfo root)
139 | {
140 | FileInfo[] files = null;
141 | DirectoryInfo[] subDirs = null;
142 |
143 | try
144 | {
145 | files = root.GetFiles("*.cs");
146 | }
147 | catch (Exception e)
148 | {
149 | }
150 |
151 | subDirs = root.GetDirectories();
152 | foreach (DirectoryInfo dirInfo in subDirs)
153 | {
154 | // Resursive call for each subdirectory.
155 | FileInfo[] res = FindSources(dirInfo);
156 | files = files.Concat(res).ToArray();
157 | }
158 | return files;
159 | }
160 |
161 | public static string FindDll(DirectoryInfo root, string name)
162 | {
163 | FileInfo[] files = null;
164 | DirectoryInfo[] subDirs = null;
165 |
166 | try
167 | {
168 | files = root.GetFiles("*.dll");
169 | }
170 | catch (Exception e)
171 | {
172 | }
173 |
174 | if (files != null)
175 | {
176 | foreach (FileInfo fi in files)
177 | {
178 | if (fi.Name.Equals(name + ".dll"))
179 | {
180 | return fi.FullName;
181 | }
182 | }
183 | }
184 |
185 | subDirs = root.GetDirectories();
186 | foreach (DirectoryInfo dirInfo in subDirs)
187 | {
188 | // Resursive call for each subdirectory.
189 | string res = FindDll(dirInfo, name);
190 | if (res != null)
191 | {
192 | return res;
193 | }
194 | }
195 | return null;
196 | }
197 |
198 | public static string FindNuspec(DirectoryInfo root)
199 | {
200 | FileInfo[] files = null;
201 | DirectoryInfo[] subDirs = null;
202 |
203 | try
204 | {
205 | files = root.GetFiles("*.nuspec");
206 | }
207 | catch (Exception e)
208 | {
209 | }
210 |
211 | if (files != null)
212 | {
213 | return files[0].FullName;
214 | }
215 |
216 | subDirs = root.GetDirectories();
217 | foreach (DirectoryInfo dirInfo in subDirs)
218 | {
219 | // Resursive call for each subdirectory.
220 | string res = FindNuspec(dirInfo);
221 | if (res != null)
222 | {
223 | return res;
224 | }
225 | }
226 | return null;
227 | }
228 |
229 | }
230 | }
231 |
--------------------------------------------------------------------------------
/testdata/expected/Proxy/Test/NugetPackage.graph.json:
--------------------------------------------------------------------------------
1 | {
2 | "Defs": [
3 | {
4 | "Path": "Test",
5 | "Name": "Test",
6 | "Kind": "namespace",
7 | "File": "src/Test/Class1.cs",
8 | "DefStart": 13,
9 | "DefEnd": 17,
10 | "Exported": true,
11 | "Data": {
12 | "FmtStrings": {
13 | "Name": {
14 | "Unqualified": "Test",
15 | "ScopeQualified": "Test",
16 | "DepQualified": "Test",
17 | "RepositoryWideQualified": "Test",
18 | "LanguageWideQualified": "Test"
19 | },
20 | "Type": {
21 | "Unqualified": "namespace",
22 | "ScopeQualified": "namespace",
23 | "DepQualified": "namespace",
24 | "RepositoryWideQualified": "namespace",
25 | "LanguageWideQualified": "namespace"
26 | },
27 | "NameAndTypeSeparator": " ",
28 | "Language": "C#",
29 | "DefKeyword": "",
30 | "Kind": "namespace"
31 | }
32 | },
33 | "TreePath": "Test"
34 | },
35 | {
36 | "Path": "Test.A",
37 | "Name": "A",
38 | "Kind": "class",
39 | "File": "src/Test/Class1.cs",
40 | "DefStart": 37,
41 | "DefEnd": 38,
42 | "Exported": true,
43 | "Data": {
44 | "FmtStrings": {
45 | "Name": {
46 | "Unqualified": "A",
47 | "ScopeQualified": "A",
48 | "DepQualified": "Test.A",
49 | "RepositoryWideQualified": "Test.A",
50 | "LanguageWideQualified": "Test.A"
51 | },
52 | "Type": {
53 | "Unqualified": "class",
54 | "ScopeQualified": "class",
55 | "DepQualified": "class",
56 | "RepositoryWideQualified": "class",
57 | "LanguageWideQualified": "class"
58 | },
59 | "NameAndTypeSeparator": " ",
60 | "Language": "C#",
61 | "DefKeyword": "",
62 | "Kind": "class"
63 | }
64 | },
65 | "TreePath": "Test/A"
66 | },
67 | {
68 | "Path": "Test.B",
69 | "Name": "B",
70 | "Kind": "class",
71 | "File": "src/Test/Class1.cs",
72 | "DefStart": 67,
73 | "DefEnd": 68,
74 | "Data": {
75 | "FmtStrings": {
76 | "Name": {
77 | "Unqualified": "B",
78 | "ScopeQualified": "B",
79 | "DepQualified": "Test.B",
80 | "RepositoryWideQualified": "Test.B",
81 | "LanguageWideQualified": "Test.B"
82 | },
83 | "Type": {
84 | "Unqualified": "class",
85 | "ScopeQualified": "class",
86 | "DepQualified": "class",
87 | "RepositoryWideQualified": "class",
88 | "LanguageWideQualified": "class"
89 | },
90 | "NameAndTypeSeparator": " ",
91 | "Language": "C#",
92 | "DefKeyword": "",
93 | "Kind": "class"
94 | }
95 | },
96 | "TreePath": "Test/B"
97 | },
98 | {
99 | "Path": "Test.C",
100 | "Name": "C",
101 | "Kind": "interface",
102 | "File": "src/Test/Class1.cs",
103 | "DefStart": 104,
104 | "DefEnd": 105,
105 | "Data": {
106 | "FmtStrings": {
107 | "Name": {
108 | "Unqualified": "C",
109 | "ScopeQualified": "C",
110 | "DepQualified": "Test.C",
111 | "RepositoryWideQualified": "Test.C",
112 | "LanguageWideQualified": "Test.C"
113 | },
114 | "Type": {
115 | "Unqualified": "interface",
116 | "ScopeQualified": "interface",
117 | "DepQualified": "interface",
118 | "RepositoryWideQualified": "interface",
119 | "LanguageWideQualified": "interface"
120 | },
121 | "NameAndTypeSeparator": " ",
122 | "Language": "C#",
123 | "DefKeyword": "",
124 | "Kind": "interface"
125 | }
126 | },
127 | "TreePath": "Test/C"
128 | },
129 | {
130 | "Path": "Test.Class",
131 | "Name": "Class",
132 | "Kind": "class",
133 | "File": "src/Test/Class2.cs",
134 | "DefStart": 61,
135 | "DefEnd": 66,
136 | "Exported": true,
137 | "Data": {
138 | "FmtStrings": {
139 | "Name": {
140 | "Unqualified": "Class",
141 | "ScopeQualified": "Class",
142 | "DepQualified": "Test.Class",
143 | "RepositoryWideQualified": "Test.Class",
144 | "LanguageWideQualified": "Test.Class"
145 | },
146 | "Type": {
147 | "Unqualified": "class",
148 | "ScopeQualified": "class",
149 | "DepQualified": "class",
150 | "RepositoryWideQualified": "class",
151 | "LanguageWideQualified": "class"
152 | },
153 | "NameAndTypeSeparator": " ",
154 | "Language": "C#",
155 | "DefKeyword": "",
156 | "Kind": "class"
157 | }
158 | },
159 | "TreePath": "Test/Class"
160 | },
161 | {
162 | "Path": "Test.Class+s",
163 | "Name": "s",
164 | "Kind": "field",
165 | "File": "src/Test/Class2.cs",
166 | "DefStart": 88,
167 | "DefEnd": 89,
168 | "Data": {
169 | "FmtStrings": {
170 | "Name": {
171 | "Unqualified": "string s",
172 | "ScopeQualified": "string Class.s",
173 | "DepQualified": "string Test.Class.s",
174 | "RepositoryWideQualified": "string Test.Class.s",
175 | "LanguageWideQualified": "string Test.Class.s"
176 | },
177 | "Type": {
178 | "Unqualified": "field",
179 | "ScopeQualified": "field",
180 | "DepQualified": "field",
181 | "RepositoryWideQualified": "field",
182 | "LanguageWideQualified": "field"
183 | },
184 | "NameAndTypeSeparator": " ",
185 | "Language": "C#",
186 | "DefKeyword": "",
187 | "Kind": "field"
188 | }
189 | },
190 | "TreePath": "Test/Class/s"
191 | },
192 | {
193 | "Path": "Test.D",
194 | "Name": "D",
195 | "Kind": "interface",
196 | "File": "src/Test/Class1.cs",
197 | "DefStart": 134,
198 | "DefEnd": 135,
199 | "Data": {
200 | "FmtStrings": {
201 | "Name": {
202 | "Unqualified": "D",
203 | "ScopeQualified": "D",
204 | "DepQualified": "Test.D",
205 | "RepositoryWideQualified": "Test.D",
206 | "LanguageWideQualified": "Test.D"
207 | },
208 | "Type": {
209 | "Unqualified": "interface",
210 | "ScopeQualified": "interface",
211 | "DepQualified": "interface",
212 | "RepositoryWideQualified": "interface",
213 | "LanguageWideQualified": "interface"
214 | },
215 | "NameAndTypeSeparator": " ",
216 | "Language": "C#",
217 | "DefKeyword": "",
218 | "Kind": "interface"
219 | }
220 | },
221 | "TreePath": "Test/D"
222 | },
223 | {
224 | "Path": "Test.E",
225 | "Name": "E",
226 | "Kind": "struct",
227 | "File": "src/Test/Class1.cs",
228 | "DefStart": 161,
229 | "DefEnd": 162,
230 | "Data": {
231 | "FmtStrings": {
232 | "Name": {
233 | "Unqualified": "E",
234 | "ScopeQualified": "E",
235 | "DepQualified": "Test.E",
236 | "RepositoryWideQualified": "Test.E",
237 | "LanguageWideQualified": "Test.E"
238 | },
239 | "Type": {
240 | "Unqualified": "struct",
241 | "ScopeQualified": "struct",
242 | "DepQualified": "struct",
243 | "RepositoryWideQualified": "struct",
244 | "LanguageWideQualified": "struct"
245 | },
246 | "NameAndTypeSeparator": " ",
247 | "Language": "C#",
248 | "DefKeyword": "",
249 | "Kind": "struct"
250 | }
251 | },
252 | "TreePath": "Test/E"
253 | }
254 | ],
255 | "Refs": [
256 | {
257 | "DefRepo": "github.com/JamesNK/Newtonsoft.Json",
258 | "DefUnitType": "NugetPackage",
259 | "DefUnit": "Newtonsoft.Json",
260 | "DefPath": "Newtonsoft.Json.JsonConvert+NaN",
261 | "File": "src/Test/Class2.cs",
262 | "Start": 104,
263 | "End": 107
264 | },
265 | {
266 | "DefRepo": "github.com/JamesNK/Newtonsoft.Json",
267 | "DefUnitType": "NugetPackage",
268 | "DefUnit": "Newtonsoft.Json",
269 | "DefPath": "Newtonsoft.Json.JsonConvert",
270 | "File": "src/Test/Class2.cs",
271 | "Start": 92,
272 | "End": 103
273 | },
274 | {
275 | "DefPath": "Test.A",
276 | "Def": true,
277 | "File": "src/Test/Class1.cs",
278 | "Start": 37,
279 | "End": 38
280 | },
281 | {
282 | "DefPath": "Test.A",
283 | "File": "src/Test/Class1.cs",
284 | "Start": 71,
285 | "End": 72
286 | },
287 | {
288 | "DefPath": "Test.B",
289 | "Def": true,
290 | "File": "src/Test/Class1.cs",
291 | "Start": 67,
292 | "End": 68
293 | },
294 | {
295 | "DefPath": "Test.Class+s",
296 | "Def": true,
297 | "File": "src/Test/Class2.cs",
298 | "Start": 88,
299 | "End": 89
300 | },
301 | {
302 | "DefPath": "Test.Class",
303 | "Def": true,
304 | "File": "src/Test/Class2.cs",
305 | "Start": 61,
306 | "End": 66
307 | },
308 | {
309 | "DefPath": "Test.C",
310 | "Def": true,
311 | "File": "src/Test/Class1.cs",
312 | "Start": 104,
313 | "End": 105
314 | },
315 | {
316 | "DefPath": "Test.C",
317 | "File": "src/Test/Class1.cs",
318 | "Start": 165,
319 | "End": 166
320 | },
321 | {
322 | "DefPath": "Test.C",
323 | "File": "src/Test/Class1.cs",
324 | "Start": 41,
325 | "End": 42
326 | },
327 | {
328 | "DefPath": "Test.D",
329 | "Def": true,
330 | "File": "src/Test/Class1.cs",
331 | "Start": 134,
332 | "End": 135
333 | },
334 | {
335 | "DefPath": "Test.D",
336 | "File": "src/Test/Class1.cs",
337 | "Start": 168,
338 | "End": 169
339 | },
340 | {
341 | "DefPath": "Test.D",
342 | "File": "src/Test/Class1.cs",
343 | "Start": 74,
344 | "End": 75
345 | },
346 | {
347 | "DefPath": "Test.E",
348 | "Def": true,
349 | "File": "src/Test/Class1.cs",
350 | "Start": 161,
351 | "End": 162
352 | },
353 | {
354 | "DefPath": "Test",
355 | "File": "src/Test/Class1.cs",
356 | "Start": 13,
357 | "End": 17
358 | },
359 | {
360 | "DefPath": "Test",
361 | "Def": true,
362 | "File": "src/Test/Class1.cs",
363 | "Start": 13,
364 | "End": 17
365 | },
366 | {
367 | "DefPath": "Test",
368 | "File": "src/Test/Class2.cs",
369 | "Start": 37,
370 | "End": 41
371 | }
372 | ]
373 | }
--------------------------------------------------------------------------------
/Srclib.Nuget/ConsoleCommands/ScanConsoleCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Collections.Generic;
4 | using Microsoft.Dnx.Runtime;
5 | using Microsoft.Dnx.Runtime.Common.CommandLine;
6 | using Newtonsoft.Json;
7 | using System.Linq;
8 |
9 | namespace Srclib.Nuget
10 | {
11 | class ScanConsoleCommand
12 | {
13 |
14 | private static PackageVersions pv = new PackageVersions();
15 |
16 | ///
17 | /// Convert .csproj files into DNX configuration files
18 | ///
19 | /// path to project folder
20 | public static void ConvertCsproj(string path)
21 | {
22 | HashSet names = new HashSet();
23 | string dir = path.Substring(0, path.LastIndexOf('/'));
24 | if (!File.Exists(dir + "/project.json"))
25 | {
26 | //gac works correctly only in docker image
27 | string gac = "/gac/v4.5/";
28 | string global = "";
29 | string input = File.ReadAllText(path);
30 | string output = "{\n \"frameworks\": {\n \"dnx451\": {\n \"dependencies\": {\n";
31 | int idx = input.IndexOf(" 0)
63 | {
64 | File.WriteAllText(dir + "/global.log", global);
65 | }
66 | }
67 | }
68 |
69 | ///
70 | /// finds all c# Visual Studio project files in project folder and subfolders
71 | ///
72 | /// directory info for project folder
73 | /// returns an array of csproj files
74 | public static FileInfo[] FindVSProjects(DirectoryInfo root)
75 | {
76 | FileInfo[] files = null;
77 | DirectoryInfo[] subDirs = null;
78 |
79 | try
80 | {
81 | files = root.GetFiles("*.csproj");
82 | }
83 | catch (Exception e)
84 | {
85 | }
86 |
87 | subDirs = root.GetDirectories();
88 | foreach (DirectoryInfo dirInfo in subDirs)
89 | {
90 | // Resursive call for each subdirectory.
91 | FileInfo[] res = FindVSProjects(dirInfo);
92 | files = files.Concat(res).ToArray();
93 | }
94 | return files;
95 | }
96 |
97 | private static string getGitUrl()
98 | {
99 | try
100 | {
101 | string config = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "./.git/config"));
102 | int i = config.IndexOf("\turl = ");
103 | if (i != -1)
104 | {
105 | int j = config.IndexOf('\n', i);
106 | string url = config.Substring(i + 7, j - i - 7);
107 | return url;
108 | }
109 | else
110 | {
111 | return null;
112 | }
113 | }
114 | catch (Exception e)
115 | {
116 | return null;
117 | }
118 | }
119 |
120 |
121 | public static void Register(CommandLineApplication cmdApp, Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment appEnvironment)
122 | {
123 | cmdApp.Command("scan", c => {
124 | c.Description = "Scan a directory tree and produce a JSON array of source units";
125 |
126 | c.HelpOption("-?|-h|--help");
127 |
128 | c.OnExecute(async () => {
129 |
130 | string url = getGitUrl();
131 | if (url.EndsWith("github.com/dotnet/coreclr"))
132 | {
133 | Console.Error.WriteLine("special case coreclr");
134 | DepresolveConsoleCommand.RunForResult("/bin/bash", "-c \"rm `find -name project.json`\"");
135 | DepresolveConsoleCommand.RunForResult("/bin/bash", "-c \"rm `find -name '*.csproj'`\"");
136 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./src/mscorlib/project.json"), "{\n \"frameworks\": {\n \"dnx451\": {\n \"dependencies\": {\n }\n }\n }\n}");
137 | }
138 | else if (url.EndsWith("github.com/Microsoft/referencesource"))
139 | {
140 | Console.Error.WriteLine("special case referencesource");
141 | string json = "{\n \"frameworks\": {\n \"dnx451\": {\n \"dependencies\": {\n }\n }\n }\n}";
142 |
143 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./mscorlib/project.json"), json);
144 |
145 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Activities/project.json"), json);
146 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Xml.Linq/project.json"), json);
147 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Numerics/project.json"), json);
148 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Web.Services/project.json"), json);
149 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.IdentityModel/project.json"), json);
150 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl/System.IO.v2.5/project.json"), json);
151 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl/System.Runtime.v1.5/project.json"), json);
152 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl/System.IO.v1.5/project.json"), json);
153 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl/System.Threading.Tasks.v2.5/project.json"), json);
154 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl/System.Threading.Tasks.v1.5/project.json"), json);
155 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl/System.Runtime.v2.5/project.json"), json);
156 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Activities.Presentation/project.json"), json);
157 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ServiceModel.Activities/project.json"), json);
158 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System/project.json"), json);
159 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Web.ApplicationServices/project.json"), json);
160 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ServiceModel/project.json"), json);
161 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./XamlBuildTask/project.json"), json);
162 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.IdentityModel.Selectors/project.json"), json);
163 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Workflow.Runtime/project.json"), json);
164 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Web.Extensions/project.json"), json);
165 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Web.Mobile/project.json"), json);
166 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ServiceModel.Activation/project.json"), json);
167 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Net/project.json"), json);
168 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Xml/project.json"), json);
169 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ServiceModel.Channels/project.json"), json);
170 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Data.SqlXml/project.json"), json);
171 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Data.DataSetExtensions/project.json"), json);
172 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ServiceModel.Discovery/project.json"), json);
173 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Activities.DurableInstancing/project.json"), json);
174 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ServiceModel.Routing/project.json"), json);
175 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Core/project.json"), json);
176 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Workflow.ComponentModel/project.json"), json);
177 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Web.Entity.Design/project.json"), json);
178 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Data.Entity.Design/project.json"), json);
179 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ComponentModel.DataAnnotations/project.json"), json);
180 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Runtime.DurableInstancing/project.json"), json);
181 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Web.DynamicData/project.json"), json);
182 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Web/project.json"), json);
183 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ServiceModel.Internals/project.json"), json);
184 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Data/project.json"), json);
185 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./SMDiagnostics/project.json"), json);
186 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.WorkflowServices/project.json"), json);
187 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Workflow.Activities/project.json"), json);
188 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ServiceModel.WasHosting/project.json"), json);
189 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Web.Entity/project.json"), json);
190 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Data.Entity/project.json"), json);
191 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Configuration/project.json"), json);
192 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Web.Routing/project.json"), json);
193 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Runtime.Serialization/project.json"), json);
194 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Runtime.Caching/project.json"), json);
195 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Xaml.Hosting/project.json"), json);
196 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.ServiceModel.Web/project.json"), json);
197 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Activities.Core.Presentation/project.json"), json);
198 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./System.Data.Linq/project.json"), json);
199 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl.Async/Microsoft.Threading.Tasks.Extensions.Desktop/project.json"), json);
200 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl.Async/Microsoft.Threading.Tasks.Extensions.Phone/project.json"), json);
201 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl.Async/Microsoft.Threading.Tasks.Extensions/project.json"), json);
202 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl.Async/Microsoft.Threading.Tasks/project.json"), json);
203 | File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "./Microsoft.Bcl.Async/Microsoft.Threading.Tasks.Extensions.Silverlight/project.json"), json);
204 | }
205 | else if (url.EndsWith("github.com/AutoMapper/AutoMapper"))
206 | {
207 | DepresolveConsoleCommand.RunForResult("/bin/bash", @"-c ""sed 's/..\\\\/..\//g' -i `find -name project.json`""");
208 | }
209 |
210 |
211 | var dir = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "."));
212 |
213 | DirectoryInfo di = new DirectoryInfo(Directory.GetCurrentDirectory());
214 | FileInfo[] fis = FindVSProjects(di);
215 | string[] projects = new string[fis.Length];
216 | for (int i = 0; i < fis.Length; i++)
217 | {
218 | projects[i] = fis[i].FullName;
219 | ConvertCsproj(projects[i]);
220 | }
221 |
222 |
223 | var sourceUnits = new List();
224 | foreach(var proj in Scan(dir))
225 | {
226 | sourceUnits.Add(SourceUnit.FromProject(proj, dir));
227 | }
228 |
229 | if (sourceUnits.Count == 0)
230 | {
231 | //not a DNX project and not a VS project
232 | sourceUnits.Add(SourceUnit.FromDirectory("name", dir));
233 | }
234 |
235 | Console.WriteLine(JsonConvert.SerializeObject(sourceUnits, Formatting.Indented));
236 |
237 | await DepresolveConsoleCommand.RunResolve(dir);
238 |
239 | return 0;
240 | });
241 | });
242 | }
243 |
244 | static IEnumerable Scan(string dir)
245 | {
246 | if (Project.HasProjectFile(dir))
247 | {
248 | Project proj;
249 | if (Project.TryGetProject(dir, out proj) && proj.CompilerServices == null)
250 | yield return proj;
251 | yield break;
252 | }
253 |
254 | foreach (var subdir in Directory.EnumerateDirectories(dir))
255 | {
256 | // Skip directories starting with .
257 | if (subdir.StartsWith("."))
258 | continue;
259 |
260 | foreach (var proj in Scan(subdir))
261 | yield return proj;
262 | }
263 | }
264 | }
265 | }
266 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/lib/dnxcore50/Microsoft.Dnx.Runtime.Abstractions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Microsoft.Dnx.Runtime.Abstractions
5 |
6 |
7 |
8 |
9 | Exposes the ambient service provider.
10 |
11 |
12 |
13 |
14 | Provides access to the .
15 |
16 |
17 |
18 |
19 | Provides access to the current .
20 |
21 |
22 |
23 |
24 | Gets or sets the current .
25 |
26 |
27 |
28 |
29 | Represents a single diagnostic message, such as a compilation error or a project.json parsing error.
30 |
31 |
32 |
33 |
34 | The moniker associated with the error message
35 |
36 |
37 |
38 |
39 | Path of the file that produced the message.
40 |
41 |
42 |
43 |
44 | Gets the error message.
45 |
46 |
47 |
48 |
49 | Gets the .
50 |
51 |
52 |
53 |
54 | Gets the one-based line index for the start of the compilation error.
55 |
56 |
57 |
58 |
59 | Gets the zero-based column index for the start of the compilation error.
60 |
61 |
62 |
63 |
64 | Gets the one-based line index for the end of the compilation error.
65 |
66 |
67 |
68 |
69 | Gets the zero-based column index for the end of the compilation error.
70 |
71 |
72 |
73 |
74 | Gets the formatted error message.
75 |
76 |
77 |
78 |
79 | Gets the source of this message
80 |
81 |
82 |
83 |
84 | Returns true if has at least one message with .
85 |
86 | Sequence of objects.
87 | true if any messages is an error message, false otherwise.
88 |
89 |
90 |
91 | Specifies the severity of a .
92 |
93 |
94 |
95 |
96 | Provides access to common application information.
97 |
98 |
99 |
100 |
101 | Gets the application name.
102 |
103 |
104 |
105 |
106 | Gets the version of the application, as specified in the project.json file.
107 |
108 |
109 |
110 |
111 | Gets the base directory of the application, defined as the path to the directory containing the project.json file.
112 |
113 |
114 |
115 |
116 | Gets the configuration. This should only be used for runtime compilation.
117 |
118 |
119 |
120 |
121 | Gets the target version and profile of the .NET Framework for the application.
122 |
123 |
124 |
125 |
126 | Gets the specified value from Application Global Data.
127 |
128 |
129 |
130 | Application Global Data is a collection of name-value pairs that is stored in a global set of data shared by the entire
131 | application. On Desktop CLR, this is backed by the and
132 | methods, and provides access to the same data. In other environments, such as CoreCLR, where AppDomains are not available,
133 | this data set is backed by a specially created global dictionary controlled by the implementor of this interface.
134 |
135 |
136 | On Desktop CLR, this method can be used to retrieve predefined application domain properties. See
137 | for a complete list.
138 |
139 |
140 | The name of the Application Global Data item to retrieve.
141 | The value of the item identified by , or null if no item exists.
142 |
143 |
144 |
145 | Sets the specified value in Application Global Data.
146 |
147 |
148 |
149 | Application Global Data is a collection of name-value pairs that is stored in a global set of data shared by the entire
150 | application. On Desktop CLR, this is backed by the and
151 | methods, and provides access to the same data. In other environments, such as CoreCLR, where AppDomains are not available,
152 | this data set is backed by a specially created global dictionary controlled by the implementor of this interface.
153 |
154 |
155 | On Desktop CLR, this method can be used to modify SOME predefined application domain properties. See
156 | for a complete list.
157 |
158 |
159 | The name of the Application Global Data item to set.
160 | The value to store in Application Global Data.
161 |
162 |
163 |
164 | Exposes methods that allow control over the application lifetime.
165 |
166 |
167 |
168 |
169 | Requests termination the current application.
170 |
171 |
172 |
173 |
174 | Gets a that is signaled when application shutdown is requested.
175 |
176 |
177 |
178 |
179 | A context in which assemblies can be loaded.
180 |
181 |
182 |
183 |
184 | Load an assembly by name.
185 |
186 | The name of the assembly.
187 | The loaded assembly.
188 |
189 |
190 |
191 | Loads the assembly located at the provided file system path.
192 |
193 | The fully qualified path of the file to load.
194 | The loaded assembly.
195 |
196 |
197 |
198 | Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols for the assembly.
199 |
200 | The stream representing the assembly.
201 | The stream representing the symbols.
202 | The loaded assembly.
203 |
204 |
205 |
206 | Provides access to created
207 |
208 |
209 |
210 |
211 | Gets the default .
212 |
213 |
214 |
215 |
216 | Gets the associated with the specified .
217 |
218 | The assembly.
219 |
220 |
221 |
222 |
223 | Defines a contract for an assembly loader. This is an extension point that can be used to implement custom assembly loading logic.
224 |
225 |
226 |
227 |
228 | Load an assembly by name.
229 |
230 | The name of the assembly.
231 | The loaded assembly.
232 |
233 |
234 |
235 | Provides access to assembly loaders used for runtime assembly resolution.
236 |
237 |
238 |
239 |
240 | Adds an to the runtime.
241 |
242 | The loader to add.
243 | A disposable object representing the registration of the loader. Disposing it removes the loader from the runtime.
244 |
245 |
246 |
247 | Provides an interface to well-known Compiler Options like "defines" and "optimize", as well as a
248 | general-purpose interface for reading from the 'compilerOptions' section.
249 |
250 |
251 |
252 |
253 | Provides access to the complete graph of dependencies for the application.
254 |
255 |
256 |
257 |
258 | Provides access to the runtime environment.
259 |
260 |
261 |
262 |
263 | Gets the current operating system name.
264 |
265 |
266 |
267 |
268 | Gets the current operating system version.
269 |
270 |
271 |
272 |
273 | Gets the runtime type. Common values include CLR, CoreCLR and Mono.
274 |
275 |
276 |
277 |
278 | Gets the runtime architecture. Common values include x86 and x64.
279 |
280 |
281 |
282 |
283 | Gets the runtime version.
284 |
285 |
286 |
287 |
288 | Gets the path to the runtime foler.
289 |
290 |
291 |
292 |
293 | Provides a list of service types exposed by the runtime.
294 |
295 |
296 |
297 |
298 | Gets the list of exposed service types.
299 |
300 |
301 |
302 |
303 | Exposes information about a library which can be an assembly, project, or a package.
304 |
305 |
306 |
307 |
308 | Gets the name of the library.
309 |
310 |
311 |
312 |
313 | Gets the version of the library.
314 |
315 |
316 |
317 |
318 | Gets the path to the library. For projects, this is a path to the project.json file.
319 |
320 |
321 |
322 |
323 | Gets the type of library. Common values include Project, Package, and Assembly.
324 |
325 |
326 |
327 |
328 | Gets a list of dependencies for the library. The dependencies are names of other objects.
329 |
330 |
331 |
332 |
333 | Gets a list of assembly names from the library that can be loaded. Packages can contain multiple assemblies.
334 |
335 |
336 |
337 |
338 | Represents the options passed into the runtime on boot
339 |
340 |
341 |
342 |
343 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Dnx.Runtime.Abstractions/1.0.0-rc1-15838/lib/dnx451/Microsoft.Dnx.Runtime.Abstractions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Microsoft.Dnx.Runtime.Abstractions
5 |
6 |
7 |
8 |
9 | Exposes the ambient service provider.
10 |
11 |
12 |
13 |
14 | Provides access to the .
15 |
16 |
17 |
18 |
19 | Provides access to the current .
20 |
21 |
22 |
23 |
24 | Gets or sets the current .
25 |
26 |
27 |
28 |
29 | Represents a single diagnostic message, such as a compilation error or a project.json parsing error.
30 |
31 |
32 |
33 |
34 | The moniker associated with the error message
35 |
36 |
37 |
38 |
39 | Path of the file that produced the message.
40 |
41 |
42 |
43 |
44 | Gets the error message.
45 |
46 |
47 |
48 |
49 | Gets the .
50 |
51 |
52 |
53 |
54 | Gets the one-based line index for the start of the compilation error.
55 |
56 |
57 |
58 |
59 | Gets the zero-based column index for the start of the compilation error.
60 |
61 |
62 |
63 |
64 | Gets the one-based line index for the end of the compilation error.
65 |
66 |
67 |
68 |
69 | Gets the zero-based column index for the end of the compilation error.
70 |
71 |
72 |
73 |
74 | Gets the formatted error message.
75 |
76 |
77 |
78 |
79 | Gets the source of this message
80 |
81 |
82 |
83 |
84 | Returns true if has at least one message with .
85 |
86 | Sequence of objects.
87 | true if any messages is an error message, false otherwise.
88 |
89 |
90 |
91 | Specifies the severity of a .
92 |
93 |
94 |
95 |
96 | Provides access to common application information.
97 |
98 |
99 |
100 |
101 | Gets the application name.
102 |
103 |
104 |
105 |
106 | Gets the version of the application, as specified in the project.json file.
107 |
108 |
109 |
110 |
111 | Gets the base directory of the application, defined as the path to the directory containing the project.json file.
112 |
113 |
114 |
115 |
116 | Gets the configuration. This should only be used for runtime compilation.
117 |
118 |
119 |
120 |
121 | Gets the target version and profile of the .NET Framework for the application.
122 |
123 |
124 |
125 |
126 | Gets the specified value from Application Global Data.
127 |
128 |
129 |
130 | Application Global Data is a collection of name-value pairs that is stored in a global set of data shared by the entire
131 | application. On Desktop CLR, this is backed by the and
132 | methods, and provides access to the same data. In other environments, such as CoreCLR, where AppDomains are not available,
133 | this data set is backed by a specially created global dictionary controlled by the implementor of this interface.
134 |
135 |
136 | On Desktop CLR, this method can be used to retrieve predefined application domain properties. See
137 | for a complete list.
138 |
139 |
140 | The name of the Application Global Data item to retrieve.
141 | The value of the item identified by , or null if no item exists.
142 |
143 |
144 |
145 | Sets the specified value in Application Global Data.
146 |
147 |
148 |
149 | Application Global Data is a collection of name-value pairs that is stored in a global set of data shared by the entire
150 | application. On Desktop CLR, this is backed by the and
151 | methods, and provides access to the same data. In other environments, such as CoreCLR, where AppDomains are not available,
152 | this data set is backed by a specially created global dictionary controlled by the implementor of this interface.
153 |
154 |
155 | On Desktop CLR, this method can be used to modify SOME predefined application domain properties. See
156 | for a complete list.
157 |
158 |
159 | The name of the Application Global Data item to set.
160 | The value to store in Application Global Data.
161 |
162 |
163 |
164 | Exposes methods that allow control over the application lifetime.
165 |
166 |
167 |
168 |
169 | Requests termination the current application.
170 |
171 |
172 |
173 |
174 | Gets a that is signaled when application shutdown is requested.
175 |
176 |
177 |
178 |
179 | A context in which assemblies can be loaded.
180 |
181 |
182 |
183 |
184 | Load an assembly by name.
185 |
186 | The name of the assembly.
187 | The loaded assembly.
188 |
189 |
190 |
191 | Loads the assembly located at the provided file system path.
192 |
193 | The fully qualified path of the file to load.
194 | The loaded assembly.
195 |
196 |
197 |
198 | Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly, optionally including symbols for the assembly.
199 |
200 | The stream representing the assembly.
201 | The stream representing the symbols.
202 | The loaded assembly.
203 |
204 |
205 |
206 | Provides access to created
207 |
208 |
209 |
210 |
211 | Gets the default .
212 |
213 |
214 |
215 |
216 | Gets the associated with the specified .
217 |
218 | The assembly.
219 |
220 |
221 |
222 |
223 | Defines a contract for an assembly loader. This is an extension point that can be used to implement custom assembly loading logic.
224 |
225 |
226 |
227 |
228 | Load an assembly by name.
229 |
230 | The name of the assembly.
231 | The loaded assembly.
232 |
233 |
234 |
235 | Provides access to assembly loaders used for runtime assembly resolution.
236 |
237 |
238 |
239 |
240 | Adds an to the runtime.
241 |
242 | The loader to add.
243 | A disposable object representing the registration of the loader. Disposing it removes the loader from the runtime.
244 |
245 |
246 |
247 | Provides an interface to well-known Compiler Options like "defines" and "optimize", as well as a
248 | general-purpose interface for reading from the 'compilerOptions' section.
249 |
250 |
251 |
252 |
253 | Provides access to the complete graph of dependencies for the application.
254 |
255 |
256 |
257 |
258 | Provides access to the runtime environment.
259 |
260 |
261 |
262 |
263 | Gets the current operating system name.
264 |
265 |
266 |
267 |
268 | Gets the current operating system version.
269 |
270 |
271 |
272 |
273 | Gets the runtime type. Common values include CLR, CoreCLR and Mono.
274 |
275 |
276 |
277 |
278 | Gets the runtime architecture. Common values include x86 and x64.
279 |
280 |
281 |
282 |
283 | Gets the runtime version.
284 |
285 |
286 |
287 |
288 | Gets the path to the runtime foler.
289 |
290 |
291 |
292 |
293 | Provides a list of service types exposed by the runtime.
294 |
295 |
296 |
297 |
298 | Gets the list of exposed service types.
299 |
300 |
301 |
302 |
303 | Exposes information about a library which can be an assembly, project, or a package.
304 |
305 |
306 |
307 |
308 | Gets the name of the library.
309 |
310 |
311 |
312 |
313 | Gets the version of the library.
314 |
315 |
316 |
317 |
318 | Gets the path to the library. For projects, this is a path to the project.json file.
319 |
320 |
321 |
322 |
323 | Gets the type of library. Common values include Project, Package, and Assembly.
324 |
325 |
326 |
327 |
328 | Gets a list of dependencies for the library. The dependencies are names of other objects.
329 |
330 |
331 |
332 |
333 | Gets a list of assembly names from the library that can be loaded. Packages can contain multiple assemblies.
334 |
335 |
336 |
337 |
338 | Represents the options passed into the runtime on boot
339 |
340 |
341 |
342 |
343 |
--------------------------------------------------------------------------------
/Srclib.Nuget/Models/Output.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.Text;
3 | using Newtonsoft.Json;
4 | using Srclib.Nuget.Graph;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Threading.Tasks;
9 |
10 | namespace Srclib.Nuget
11 | {
12 | public class Output
13 | {
14 | [JsonProperty]
15 | public List Defs { get; set; } = new List();
16 |
17 | [JsonProperty]
18 | public List[ Refs { get; set; } = new List][();
19 |
20 | [JsonProperty]
21 | public List Docs { get; set; } = new List();
22 | }
23 |
24 | public class Def
25 | {
26 | ///
27 | /// DefKey is the natural unique key for a def. It is stable
28 | /// (subsequent runs of a grapher will emit the same defs with the same
29 | /// DefKeys).
30 | ///
31 | [JsonProperty("Path")]
32 | public string DefKey { get; set; }
33 |
34 | ///
35 | /// Name of the definition. This need not be unique.
36 | ///
37 | [JsonProperty]
38 | public string Name { get; set; }
39 |
40 | ///
41 | /// Kind is the kind of thing this definition is. This is
42 | /// language-specific. Possible values include "type", "func",
43 | /// "var", etc.
44 | ///
45 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
46 | public string Kind { get; set; }
47 |
48 | [JsonProperty]
49 | public string File { get; set; }
50 |
51 | [JsonProperty]
52 | public UInt32 DefStart { get; set; }
53 |
54 | [JsonProperty]
55 | public UInt32 DefEnd { get; set; }
56 |
57 | ///
58 | /// External
59 | ///
60 | [JsonProperty]
61 | public bool External { get; set; } = false;
62 |
63 | ///
64 | /// Exported is whether this def is part of a source unit's
65 | /// public API. For example, in Java a "public" field is
66 | /// Exported.
67 | ///
68 | [JsonProperty]
69 | public bool Exported { get; set; } = false;
70 |
71 | ///
72 | /// Local is whether this def is local to a function or some
73 | /// other inner scope. Local defs do *not* have module,
74 | /// package, or file scope. For example, in Java a function's
75 | /// args are Local, but fields with "private" scope are not
76 | /// Local.
77 | ///
78 | [JsonProperty]
79 | public bool Local { get; set; } = false;
80 |
81 | ///
82 | /// Test is whether this def is defined in test code (as opposed to main
83 | /// code). For example, definitions in Go *_test.go files have Test = true.
84 | ///
85 | [JsonProperty]
86 | public bool Test { get; set; } = false;
87 |
88 | ///
89 | /// TreePath is a structurally significant path descriptor for a def. For
90 | /// many languages, it may be identical or similar to DefKey.Path.
91 | ///
92 | ///
93 | /// A tree-path has the following restraints:
94 | ///
95 | /// A tree-path is a chain of '/'-delimited components. A component is either a
96 | /// def name or a ghost component.
97 | /// ]
98 | /// - A def name satifies the regex [^/-][^/]*
99 | /// - A ghost component satisfies the regex -[^/]*
100 | ///
101 | /// Any prefix of a tree-path that terminates in a def name must be a valid
102 | /// tree-path for some def.
103 | ///
104 | /// The following regex captures the children of a tree-path X: X(/-[^/]*)*(/[^/-][^/]*).
105 | ///
106 | [JsonProperty]
107 | public string TreePath { get; set; }
108 |
109 | [JsonProperty]
110 | public DefData Data { get; set; }
111 |
112 | internal static Def For(ISymbol symbol, string type, string name)
113 | {
114 | var key = symbol.GetGraphKey();
115 |
116 | return new Def
117 | {
118 | DefKey = key.Key,
119 | TreePath = key.Path,
120 | Kind = type,
121 | Name = name,
122 | Data = new DefData
123 | {
124 | FmtStrings = DefFormatStrings.From(symbol, key, type)
125 | }
126 | };
127 | }
128 |
129 | internal Def At(string file, TextSpan span)
130 | {
131 | File = file;
132 | DefStart = (uint)span.Start;
133 | DefEnd = (uint)span.End;
134 | return this;
135 | }
136 | }
137 |
138 | public class Ref
139 | {
140 | ///
141 | /// DefRepo is the repository URI of the Def that this Ref refers to.
142 | ///
143 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
144 | public string DefRepo { get; set; } = null;
145 |
146 | ///
147 | /// DefUnitType is the source unit type of the Def that this Ref refers to.
148 | ///
149 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
150 | public string DefUnitType { get; set; } = null;
151 |
152 | ///
153 | /// DefUnit is the name of the source unit that this ref exists in.
154 | ///
155 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
156 | public string DefUnit { get; set; } = null;
157 |
158 | ///
159 | /// Path is the path of the Def that this ref refers to.
160 | ///
161 | [JsonProperty]
162 | public string DefPath { get; set; }
163 |
164 | ///
165 | /// Repo is the VCS repository in which this ref exists.
166 | ///
167 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
168 | public string Repo { get; set; } = null;
169 |
170 | ///
171 | /// CommitID is the ID of the VCS commit that this ref exists
172 | /// in. The CommitID is always a full commit ID (40 hexadecimal
173 | /// characters for git and hg), never a branch or tag name.
174 | ///
175 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
176 | public string CommitID { get; set; } = null;
177 |
178 | ///
179 | /// UnitType is the type name of the source unit that this ref
180 | /// exists in.
181 | ///
182 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
183 | public string UnitType { get; set; } = null;
184 |
185 | ///
186 | /// Unit is the name of the source unit that this ref exists in.
187 | ///
188 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
189 | public string Unit { get; set; } = null;
190 |
191 | ///
192 | /// Def is true if this Ref spans the name of the Def it points to.
193 | ///
194 | [JsonProperty]
195 | public bool Def { get; set; } = false;
196 |
197 | ///
198 | /// File is the filename in which this Ref exists.
199 | ///
200 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
201 | public string File { get; set; }
202 |
203 | ///
204 | /// Start is the byte offset of this ref's first byte in File.
205 | ///
206 | [JsonProperty]
207 | public UInt32 Start { get; set; }
208 |
209 | ///
210 | /// End is the byte offset of this ref's last byte in File.
211 | ///
212 | [JsonProperty]
213 | public UInt32 End { get; set; }
214 |
215 | internal static Ref To(ISymbol symbol)
216 | {
217 | var key = symbol.GetGraphKey();
218 |
219 | return new Ref
220 | {
221 | DefPath = key.Key
222 | };
223 | }
224 |
225 | internal Ref At(string file, TextSpan span)
226 | {
227 | File = file;
228 | Start = (uint)span.Start;
229 | End = (uint)span.End;
230 | return this;
231 | }
232 |
233 | internal static Ref AtDef(Def def)
234 | {
235 | return new Ref
236 | {
237 | DefPath = def.DefKey,
238 | File = def.File,
239 | Start = def.DefStart,
240 | End = def.DefEnd,
241 | Def = true
242 | };
243 | }
244 | }
245 |
246 | public class Doc
247 | {
248 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
249 | public string UnitType { get; set; }
250 |
251 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
252 | public string Unit { get; set; }
253 |
254 | [JsonProperty]
255 | public string Path { get; set; }
256 |
257 | ///
258 | /// Format is the the MIME-type that the documentation is stored
259 | /// in. Valid formats include 'text/html', 'text/plain',
260 | /// 'text/x-markdown', text/x-rst'.
261 | ///
262 | [JsonProperty]
263 | public string Format { get; set; }
264 |
265 | ///
266 | /// Data is the actual documentation text.
267 | ///
268 | [JsonProperty]
269 | public string Data { get; set; }
270 |
271 | ///
272 | /// File is the filename where this Doc exists.
273 | ///
274 | [JsonProperty]
275 | public string File { get; set; }
276 |
277 | ///
278 | /// Start is the byte offset of this Doc's first byte in File.
279 | ///
280 | [JsonProperty]
281 | public uint Start { get; set; }
282 |
283 | ///
284 | /// End is the byte offset of this Doc's last byte in File.
285 | ///
286 | [JsonProperty]
287 | public uint End { get; set; }
288 | }
289 |
290 | public class DefData
291 | {
292 | [JsonProperty]
293 | public DefFormatStrings FmtStrings { get; set; }
294 | }
295 |
296 | public class DefFormatStrings
297 | {
298 | [JsonProperty]
299 | public QualFormatStrings Name { get; set; }
300 |
301 | [JsonProperty]
302 | public QualFormatStrings Type { get; set; }
303 |
304 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
305 | public string NameAndTypeSeparator { get; set; }
306 |
307 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
308 | public string Language { get; set; }
309 |
310 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
311 | public string DefKeyword { get; set; }
312 |
313 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
314 | public string Kind { get; set; }
315 |
316 | static SymbolDisplayFormat Unqualified { get; } =
317 | new SymbolDisplayFormat(
318 | globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
319 | genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
320 | memberOptions:
321 | SymbolDisplayMemberOptions.IncludeParameters |
322 | SymbolDisplayMemberOptions.IncludeType,
323 | kindOptions: SymbolDisplayKindOptions.IncludeMemberKeyword,
324 | parameterOptions:
325 | SymbolDisplayParameterOptions.IncludeName |
326 | SymbolDisplayParameterOptions.IncludeType |
327 | SymbolDisplayParameterOptions.IncludeParamsRefOut |
328 | SymbolDisplayParameterOptions.IncludeExtensionThis |
329 | SymbolDisplayParameterOptions.IncludeOptionalBrackets,
330 | localOptions: SymbolDisplayLocalOptions.IncludeType,
331 | miscellaneousOptions:
332 | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
333 | SymbolDisplayMiscellaneousOptions.UseSpecialTypes);
334 |
335 | static SymbolDisplayFormat ScopeQualified { get; } =
336 | new SymbolDisplayFormat(
337 | globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
338 | typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypes,
339 | genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
340 | memberOptions:
341 | SymbolDisplayMemberOptions.IncludeParameters |
342 | SymbolDisplayMemberOptions.IncludeType |
343 | SymbolDisplayMemberOptions.IncludeContainingType,
344 | kindOptions: SymbolDisplayKindOptions.IncludeMemberKeyword,
345 | parameterOptions:
346 | SymbolDisplayParameterOptions.IncludeName |
347 | SymbolDisplayParameterOptions.IncludeType |
348 | SymbolDisplayParameterOptions.IncludeParamsRefOut |
349 | SymbolDisplayParameterOptions.IncludeExtensionThis |
350 | SymbolDisplayParameterOptions.IncludeOptionalBrackets,
351 | localOptions: SymbolDisplayLocalOptions.IncludeType,
352 | miscellaneousOptions:
353 | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
354 | SymbolDisplayMiscellaneousOptions.UseSpecialTypes);
355 |
356 | static SymbolDisplayFormat DepQualified { get; } =
357 | new SymbolDisplayFormat(
358 | globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
359 | typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
360 | genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
361 | memberOptions:
362 | SymbolDisplayMemberOptions.IncludeParameters |
363 | SymbolDisplayMemberOptions.IncludeType |
364 | SymbolDisplayMemberOptions.IncludeContainingType,
365 | kindOptions: SymbolDisplayKindOptions.IncludeMemberKeyword,
366 | parameterOptions:
367 | SymbolDisplayParameterOptions.IncludeName |
368 | SymbolDisplayParameterOptions.IncludeType |
369 | SymbolDisplayParameterOptions.IncludeParamsRefOut |
370 | SymbolDisplayParameterOptions.IncludeExtensionThis |
371 | SymbolDisplayParameterOptions.IncludeOptionalBrackets,
372 | localOptions: SymbolDisplayLocalOptions.IncludeType,
373 | miscellaneousOptions:
374 | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
375 | SymbolDisplayMiscellaneousOptions.UseSpecialTypes);
376 |
377 | static SymbolDisplayFormat RepositoryWideQualified { get; } =
378 | DepQualified;
379 |
380 | static SymbolDisplayFormat LanguageWideQualified { get; } =
381 | RepositoryWideQualified;
382 |
383 | internal static DefFormatStrings From(ISymbol symbol, SymbolExtensions.KeyData key, string typeString)
384 | {
385 | var name = new QualFormatStrings
386 | {
387 | Unqualified = symbol.ToDisplayString(Unqualified),
388 | ScopeQualified = symbol.ToDisplayString(ScopeQualified),
389 | DepQualified = symbol.ToDisplayString(DepQualified),
390 | RepositoryWideQualified = symbol.ToDisplayString(RepositoryWideQualified),
391 | LanguageWideQualified = symbol.ToDisplayString(LanguageWideQualified)
392 | };
393 |
394 | var type = QualFormatStrings.Single(typeString);
395 |
396 | return new DefFormatStrings
397 | {
398 | Name = name,
399 | Type = type,
400 | NameAndTypeSeparator = " ",
401 | Language = "C#",
402 | DefKeyword = "",
403 | Kind = typeString
404 | };
405 | }
406 | }
407 |
408 | public class QualFormatStrings
409 | {
410 | ///
411 | /// An Unqualified name is just the def's name.
412 | ///
413 | /// Examples:
414 | ///
415 | /// Go method `MyMethod`
416 | /// Python method `my_method`
417 | /// JavaScript method `myMethod`
418 | ///
419 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
420 | public string Unqualified { get; set; }
421 |
422 | ///
423 | /// A ScopeQualified name is the language-specific description of the
424 | /// def's defining scope plus the def's unqualified name. It should
425 | /// uniquely describe the def among all other defs defined in the same
426 | /// logical package (but this is not strictly defined or enforced).
427 | ///
428 | /// Examples:
429 | ///
430 | /// Go method `(*MyType).MyMethod`
431 | /// Python method `MyClass.my_method`
432 | /// JavaScript method `MyConstructor.prototype.myMethod`
433 | ///
434 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
435 | public string ScopeQualified { get; set; }
436 |
437 | ///
438 | /// A DepQualified name is the package/module name (as seen by an external
439 | /// library that imports/depends on the def's package/module) plus the
440 | /// def's scope-qualified name. If there are nested packages, it should
441 | /// describe enough of the package hierarchy to distinguish it from other
442 | /// similarly named defs (but this is not strictly defined or enforced).
443 | ///
444 | /// Examples:
445 | ///
446 | /// Go method `(*mypkg.MyType).MyMethod`
447 | /// Python method `mypkg.MyClass.my_method`
448 | /// CommonJS method `mymodule.MyConstructor.prototype.myMethod`
449 | ///
450 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
451 | public string DepQualified { get; set; }
452 |
453 | ///
454 | /// A RepositoryWideQualified name is the full package/module name(s) plus
455 | /// the def's scope-qualified name. It should describe enough of the
456 | /// package hierarchy so that it is unique in its repository.
457 | /// RepositoryWideQualified differs from DepQualified in that the former
458 | /// includes the full nested package/module path from the repository root
459 | /// (e.g., 'a/b.C' for a Go func C in the repository 'github.com/user/a'
460 | /// subdirectory 'b'), while DepQualified would only be the last directory
461 | /// component (e.g., 'b.C' in that example).
462 | ///
463 | /// Examples:
464 | ///
465 | /// Go method `(*mypkg/subpkg.MyType).MyMethod`
466 | /// Python method `mypkg.subpkg.MyClass.my_method` (unless mypkg =~ subpkg)
467 | /// CommonJS method `mypkg.mymodule.MyConstructor.prototype.myMethod` (unless mypkg =~ mymodule)
468 | ///
469 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
470 | public string RepositoryWideQualified { get; set; }
471 |
472 | ///
473 | /// A LanguageWideQualified name is the library/repository name plus the
474 | /// package-qualified def name. It should describe the def so that it
475 | /// is logically unique among all defs that could reasonably exist for the
476 | /// language that the def is written in (but this is not strictly defined
477 | /// or enforced).
478 | ///
479 | /// Examples:
480 | ///
481 | /// Go method `(*github.com/user/repo/mypkg.MyType).MyMethod`
482 | /// Python method `mylib.MyClass.my_method` (if mylib =~ mypkg, as for Django, etc.)
483 | /// CommonJS method `mylib.MyConstructor.prototype.myMethod` (if mylib =~ mymod, as for caolan/async, etc.)
484 | ///
485 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
486 | public string LanguageWideQualified { get; set; }
487 |
488 | internal static QualFormatStrings Single(string val)
489 | {
490 | return new QualFormatStrings
491 | {
492 | Unqualified = val,
493 | ScopeQualified = val,
494 | DepQualified = val,
495 | RepositoryWideQualified = val,
496 | LanguageWideQualified = val
497 | };
498 | }
499 | }
500 | }
501 |
--------------------------------------------------------------------------------
/Srclib.Nuget/ConsoleCommands/PackageVersions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace Srclib.Nuget
7 | {
8 |
9 | ///
10 |
11 | ///Nuget cannot load a package only if both
12 | ///name and version are provided, while visual studio configuration files
13 | ///hold only dependency name. So this class holds a name->version map for top several
14 | ///hundred most popular nuget packages
15 | ///Generated based on https://www.nuget.org/stats/packageversions
16 |
17 | ///
18 | public class PackageVersions
19 | {
20 | private Dictionary versions;
21 |
22 | public PackageVersions()
23 | {
24 | versions = new Dictionary()
25 | {
26 | { "microsoft.web.infrastructure", "1.0.0" },
27 | { "entityframework", "6.1.3" },
28 | { "newtonsoft.json", "8.0.2" },
29 | { "microsoft.aspnet.webapi.client", "5.2.3" },
30 | { "microsoft.aspnet.webpages", "3.2.3" },
31 | { "microsoft.aspnet.mvc", "5.2.3" },
32 | { "microsoft.aspnet.razor", "3.2.3" },
33 | { "owin", "1.0.0" },
34 | { "microsoft.aspnet.webapi.core", "5.2.3" },
35 | { "microsoft.aspnet.web.optimization", "1.1.3" },
36 | { "microsoft.aspnet.webapi.webhost", "5.2.3" },
37 | { "microsoft.owin", "3.0.1" },
38 | { "microsoft.aspnet.webapi", "5.2.3" },
39 | { "system.collections", "4.0.10" },
40 | { "system.resources.resourcemanager", "4.0.0" },
41 | { "system.runtime", "4.0.20" },
42 | { "microsoft.owin.host.systemweb", "3.0.1" },
43 | { "antlr", "3.4.1.9004" },
44 | { "microsoft.owin.security", "3.0.1" },
45 | { "system.threading", "4.0.10" },
46 | { "system.reflection.primitives", "4.0.0" },
47 | { "system.threading.tasks", "4.0.10" },
48 | { "system.io", "4.0.10" },
49 | { "system.private.uri", "4.0.0" },
50 | { "webgrease", "1.5.2" },
51 | { "system.reflection.extensions", "4.0.0" },
52 | { "system.text.encoding", "4.0.10" },
53 | { "system.io.filesystem.primitives", "4.0.0" },
54 | { "system.reflection", "4.0.0" },
55 | { "system.text.encoding.extensions", "4.0.10" },
56 | { "system.globalization", "4.0.0" },
57 | { "system.diagnostics.tracing", "4.0.20" },
58 | { "system.diagnostics.debug", "4.0.0" },
59 | { "system.runtime.extensions", "4.0.10" },
60 | { "system.io.filesystem", "4.0.0" },
61 | { "modernizr", "2.6.2" },
62 | { "system.runtime.handles", "4.0.0" },
63 | { "microsoft.bcl", "1.1.10" },
64 | { "system.linq.expressions", "4.0.10" },
65 | { "microsoft.owin.security.oauth", "3.0.1" },
66 | { "system.runtime.interopservices", "4.0.20" },
67 | { "system.threading.overlapped", "4.0.0" },
68 | { "microsoft.net.http", "2.2.29" },
69 | { "jquery", "1.10.2" },
70 | { "system.reflection.typeextensions", "4.0.0" },
71 | { "system.globalization.calendars", "4.0.0" },
72 | { "microsoft.aspnet.identity.core", "2.2.1" },
73 | { "microsoft.owin.security.cookies", "3.0.1" },
74 | { "system.objectmodel", "4.0.10" },
75 | { "microsoft.bcl.build", "1.0.21" },
76 | { "system.reflection.emit.ilgeneration", "4.0.0" },
77 | { "system.reflection.emit", "4.0.0" },
78 | { "microsoft.jquery.unobtrusive.validation", "3.2.3" },
79 | { "system.linq", "4.0.0" },
80 | { "microsoft.win32.primitives", "4.0.0" },
81 | { "system.reflection.emit.lightweight", "4.0.0" },
82 | { "bootstrap", "3.0.0" },
83 | { "system.collections.nongeneric", "4.0.0" },
84 | { "microsoft.aspnet.identity.owin", "2.2.1" },
85 | { "respond", "1.2.0" },
86 | { "system.runtime.numerics", "4.0.0" },
87 | { "moq", "4.2.1510.2205" },
88 | { "jquery.validation", "1.11.1" },
89 | { "microsoft.net.compilers", "1.0.0" },
90 | { "xunit.abstractions", "2.0.0" },
91 | { "system.collections.immutable", "1.1.37" },
92 | { "system.diagnostics.tools", "4.0.0" },
93 | { "system.text.regularexpressions", "4.0.10" },
94 | { "commonservicelocator", "1.3.0" },
95 | { "microsoft.bcl.async", "1.0.168" },
96 | { "microsoft.aspnet.identity.entityframework", "2.2.1" },
97 | { "nunit", "2.6.4" },
98 | { "xunit.extensibility.execution", "2.1.0" },
99 | { "system.security.principal", "4.0.0" },
100 | { "xunit.core", "2.1.0" },
101 | { "microsoft.aspnet.webapi.owin", "5.2.3" },
102 | { "xunit.extensibility.core", "2.1.0" },
103 | { "microsoft.codedom.providers.dotnetcompilerplatform", "1.0.0" },
104 | { "microsoft.azure.keyvault.core", "1.0.0" },
105 | { "microsoft.data.odata", "5.6.4" },
106 | { "system.collections.concurrent", "4.0.10" },
107 | { "microsoft.data.edm", "5.6.4" },
108 | { "system.spatial", "5.6.4" },
109 | { "system.componentmodel.primitives", "4.0.0" },
110 | { "xunit.assert", "2.1.0" },
111 | { "xunit", "2.1.0" },
112 | { "system.componentmodel", "4.0.0" },
113 | { "system.xml.readerwriter", "4.0.10" },
114 | { "log4net", "2.0.5" },
115 | { "system.security.claims", "4.0.0" },
116 | { "microsoft.aspnet.cors", "5.2.3" },
117 | { "microsoft.data.services.client", "5.6.4" },
118 | { "system.net.primitives", "4.0.10" },
119 | { "microsoft.owin.security.google", "3.0.1" },
120 | { "microsoft.owin.security.facebook", "3.0.1" },
121 | { "microsoft.applicationinsights", "1.2.3" },
122 | { "system.net.http", "4.0.0" },
123 | { "microsoft.owin.security.twitter", "3.0.1" },
124 | { "microsoft.owin.security.microsoftaccount", "3.0.1" },
125 | { "system.appcontext", "4.0.0" },
126 | { "system.private.networking", "4.0.0" },
127 | { "microsoft.applicationinsights.windowsserver.telemetrychannel", "1.2.3" },
128 | { "microsoft.applicationinsights.dependencycollector", "1.2.3" },
129 | { "microsoft.applicationinsights.perfcountercollector", "1.2.3" },
130 | { "microsoft.applicationinsights.windowsserver", "1.2.3" },
131 | { "microsoft.applicationinsights.web", "1.2.3" },
132 | { "autofac", "3.5.2" },
133 | { "system.componentmodel.eventbasedasync", "4.0.10" },
134 | { "microsoft.aspnet.webapi.cors", "5.2.3" },
135 | { "system.globalization.extensions", "4.0.0" },
136 | { "system.threading.timer", "4.0.0" },
137 | { "system.io.compression", "4.0.0" },
138 | { "windowsazure.storage", "6.2.0" },
139 | { "htmlagilitypack", "1.4.9" },
140 | { "microsoft.windowsazure.configurationmanager", "3.1.0" },
141 | { "nuget.commandline", "3.3.0" },
142 | { "system.reflection.metadata", "1.1.0" },
143 | { "microsoft.applicationinsights.agent.intercept", "1.2.0" },
144 | { "system.data.common", "4.0.0" },
145 | { "microsoft.aspnet.webapi.helppage", "5.2.3" },
146 | { "sharpziplib", "0.86.0" },
147 | { "restsharp", "105.2.3" },
148 | { "system.identitymodel.tokens.jwt", "4.0.2.206221351" },
149 | { "system.threading.threadpool", "4.0.10-beta-23409" },
150 | { "microsoft.aspnet.signalr.core", "2.2.0" },
151 | { "system.security.cryptography.primitives", "4.0.0-beta-23409" },
152 | { "system.threading.thread", "4.0.0-beta-23409" },
153 | { "system.xml.xmldocument", "4.0.0" },
154 | { "unity", "4.0.1" },
155 | { "system.threading.tasks.parallel", "4.0.0" },
156 | { "system.diagnostics.tracesource", "4.0.0-beta-23409" },
157 | { "system.collections.specialized", "4.0.0" },
158 | { "system.io.compression.clrcompression-x64", "4.0.0" },
159 | { "system.linq.queryable", "4.0.0" },
160 | { "system.io.compression.clrcompression-x86", "4.0.0" },
161 | { "microsoft.csharp", "4.0.0" },
162 | { "jquery.ui.combined", "1.11.4" },
163 | { "system.console", "4.0.0-beta-23409" },
164 | { "xunit.runner.utility", "2.1.0" },
165 | { "system.dynamic.runtime", "4.0.10" },
166 | { "microsoft.applicationinsights.javascript", "0.15.0-build58334" },
167 | { "microsoft.extensions.dependencyinjection.abstractions", "1.0.0-rc1-final" },
168 | { "nlog", "4.2.3" },
169 | { "microsoft.aspnet.signalr.js", "2.2.0" },
170 | { "microsoft.extensions.logging.abstractions", "1.0.0-rc1-final" },
171 | { "system.diagnostics.contracts", "4.0.0" },
172 | { "microsoft.owin.cors", "3.0.1" },
173 | { "system.io.unmanagedmemorystream", "4.0.0" },
174 | { "microsoft.extensions.logging", "1.0.0-rc1-final" },
175 | { "microsoft.framework.dependencyinjection.abstractions", "1.0.0-beta8" },
176 | { "system.security.cryptography.algorithms", "4.0.0-beta-23409" },
177 | { "ninject", "3.2.2" },
178 | { "microsoft.aspnet.signalr.systemweb", "2.2.0" },
179 | { "microsoft.framework.configuration", "1.0.0-beta8" },
180 | { "system.componentmodel.annotations", "4.0.10" },
181 | { "microsoft.framework.configuration.abstractions", "1.0.0-beta8" },
182 | { "system.security.cryptography.encoding", "4.0.0-beta-23409" },
183 | { "system.security.cryptography.x509certificates", "4.0.0-beta-23409" },
184 | { "system.xml.xdocument", "4.0.10" },
185 | { "microsoft.extensions.primitives", "1.0.0-rc1-final" },
186 | { "microsoft.framework.logging.abstractions", "1.0.0-beta8" },
187 | { "microsoft.extensions.configuration.abstractions", "1.0.0-rc1-final" },
188 | { "webactivatorex", "2.0.6" },
189 | { "microsoft.extensions.platformabstractions", "1.0.0-rc1-final" },
190 | { "microsoft.framework.dependencyinjection", "1.0.0-beta8" },
191 | { "microsoft.codeanalysis.analyzers", "1.0.0" },
192 | { "microsoft.extensions.configuration", "1.0.0-rc1-final" },
193 | { "nuget.build", "2.8.6" },
194 | { "microsoft.framework.primitives", "1.0.0-beta8" },
195 | { "microsoft.framework.logging", "1.0.0-beta8" },
196 | { "microsoft.framework.optionsmodel", "1.0.0-beta8" },
197 | { "xunit.runner.console", "2.1.0" },
198 | { "microsoft.framework.configuration.binder", "1.0.0-beta8" },
199 | { "microsoft.aspnet.signalr", "2.2.0" },
200 | { "microsoft.framework.configuration.json", "1.0.0-beta8" },
201 | { "system.linq.parallel", "4.0.0" },
202 | { "microsoft.dnx.runtime.abstractions", "1.0.0-beta8" },
203 | { "microsoft.framework.configuration.fileextensions", "1.0.0-beta8" },
204 | { "system.io.filesystem.watcher", "4.0.0-beta-23409" },
205 | { "microsoft.netcore.targets", "1.0.0" },
206 | { "microsoft.framework.webencoders.core", "1.0.0-beta8" },
207 | { "microsoft.aspnet.http.abstractions", "1.0.0-beta8" },
208 | { "microsoft.aspnet.http.features", "1.0.0-beta8" },
209 | { "microsoft.aspnet.fileproviders.abstractions", "1.0.0-beta8" },
210 | { "microsoft.aspnet.hosting.abstractions", "1.0.0-beta8" },
211 | { "system.componentmodel.typeconverter", "4.0.1-beta-23409" },
212 | { "microsoft.net.http.headers", "1.0.0-beta8" },
213 | { "microsoft.aspnet.http.extensions", "1.0.0-beta8" },
214 | { "microsoft.dnx.compilation.abstractions", "1.0.0-beta8" },
215 | { "system.diagnostics.tracing.telemetry", "4.0.0-beta-23409" },
216 | { "microsoft.aspnet.webutilities", "1.0.0-beta8" },
217 | { "microsoft.aspnet.fileproviders.physical", "1.0.0-beta8" },
218 | { "system.net.websockets", "4.0.0-beta-23409" },
219 | { "microsoft.extensions.dependencyinjection", "1.0.0-rc1-final" },
220 | { "microsoft.framework.configuration.environmentvariables", "1.0.0-beta8" },
221 | { "system.net.networkinformation", "4.0.0" },
222 | { "microsoft.aspnet.http", "1.0.0-beta8" },
223 | { "microsoft.framework.configuration.commandline", "1.0.0-beta8" },
224 | { "microsoft.aspnet.hosting", "1.0.0-beta8" },
225 | { "microsoft.aspnet.hosting.server.abstractions", "1.0.0-beta8" },
226 | { "microsoft.framework.webencoders", "1.0.0-beta8" },
227 | { "microsoft.netcore.platforms", "1.0.0" },
228 | { "microsoft.aspnet.server.kestrel", "1.0.0-beta8" },
229 | { "elmah.corelibrary", "1.2.2" },
230 | { "system.numerics.vectors", "4.1.1-beta-23409" },
231 | { "system.diagnostics.stacktrace", "4.0.1-beta-23409" },
232 | { "runtime.unix.system.diagnostics.tracesource", "4.0.0-beta-23409" },
233 | { "microsoft.owin.hosting", "3.0.1" },
234 | { "microsoft.aspnet.staticfiles", "1.0.0-beta8" },
235 | { "runtime.unix.system.security.cryptography.encoding", "4.0.0-beta-23409" },
236 | { "runtime.unix.system.security.cryptography.x509certificates", "4.0.0-beta-23409" },
237 | { "system.security.cryptography.openssl", "4.0.0-beta-23409" },
238 | { "runtime.unix.system.console", "4.0.0-beta-23409" },
239 | { "automapper", "4.1.1" },
240 | { "runtime.unix.system.private.uri", "4.0.1-beta-23409" },
241 | { "runtime.unix.system.threading", "4.0.11-beta-23409" },
242 | { "microsoft.extensions.configuration.binder", "1.0.0-rc1-final" },
243 | { "runtime.linux.system.runtime.extensions", "4.0.11-beta-23409" },
244 | { "runtime.unix.system.diagnostics.debug", "4.0.11-beta-23409" },
245 | { "runtime.linux.system.io.filesystem", "4.0.1-beta-23409" },
246 | { "system.diagnostics.diagnosticsource", "4.0.0-beta-23516" },
247 | { "runtime.linux.system.security.cryptography.algorithms", "4.0.0-beta-23409" },
248 | { "runtime.unix.system.globalization.extensions", "4.0.1-beta-23409" },
249 | { "runtime.unix.system.net.primitives", "4.0.11-beta-23409" },
250 | { "runtime.linux.system.io.filesystem.watcher", "4.0.0-beta-23409" },
251 | { "microsoft.extensions.optionsmodel", "1.0.0-rc1-final" },
252 | { "xunit.runner.visualstudio", "2.1.0" },
253 | { "microsoft.netcore.targets.universalwindowsplatform", "5.0.0" },
254 | { "system.xml.xmlserializer", "4.0.10" },
255 | { "microsoft.extensions.webencoders.core", "1.0.0-rc1-final" },
256 | { "dapper", "1.42.0" },
257 | { "system.runtime.interopservices.windowsruntime", "4.0.0" },
258 | { "system.net.webheadercollection", "4.0.0" },
259 | { "nunittestadapter", "2.0.0" },
260 | { "rx-core", "2.2.5" },
261 | { "dnx-coreclr-linux-x64", "1.0.0-beta8" },
262 | { "system.reflection.dispatchproxy", "4.0.0" },
263 | { "rx-interfaces", "2.2.5" },
264 | { "microsoft.netcore.runtime.coreclr-x64", "1.0.0" },
265 | { "system.text.encoding.codepages", "4.0.0" },
266 | { "rx-linq", "2.2.5" },
267 | { "microsoft.netcore.runtime.coreclr-x86", "1.0.0" },
268 | { "microsoft.jquery.unobtrusive.ajax", "3.2.3" },
269 | { "microsoft.extensions.configuration.json", "1.0.0-rc1-final" },
270 | { "microsoft.extensions.caching.abstractions", "1.0.0-rc1-final" },
271 | { "microsoft.extensions.caching.memory", "1.0.0-rc1-final" },
272 | { "castle.core", "3.3.3" },
273 | { "nuget.galleryuptime", "1.0.0" },
274 | { "microsoft.extensions.configuration.fileextensions", "1.0.0-rc1-final" },
275 | { "microsoft.visualbasic", "10.0.0" },
276 | { "xunit.runner.reporters", "2.1.0" },
277 | { "system.runtime.serialization.json", "4.0.0" },
278 | { "microsoft.owin.security.jwt", "3.0.1" },
279 | { "system.runtime.windowsruntime", "4.0.10" },
280 | { "system.security.cryptography.cng", "4.0.0-beta-23516" },
281 | { "microsoft.extensions.configuration.environmentvariables", "1.0.0-rc1-final" },
282 | { "ix-async", "1.2.5" },
283 | { "microsoft.extensions.configuration.commandline", "1.0.0-rc1-final" },
284 | { "microsoft.extensions.webencoders", "1.0.0-rc1-final" },
285 | { "microsoft.netcore.runtime.coreclr-arm", "1.0.0" },
286 | { "autofac.webapi2", "3.4.0" },
287 | { "microsoft.codeanalysis.csharp", "1.1.0-rc1-20151109-01" },
288 | { "system.runtime.serialization.primitives", "4.0.10" },
289 | { "system.threading.tasks.dataflow", "4.5.25" },
290 | { "microsoft.codeanalysis.common", "1.1.0-rc1-20151109-01" },
291 | { "bouncycastle", "1.7.0" },
292 | { "rx-platformservices", "2.2.5" },
293 | { "documentformat.openxml", "2.5.0" },
294 | { "microsoft.owin.host.httplistener", "3.0.1" },
295 | { "enterpriselibrary.transientfaulthandling", "6.0.1304" },
296 | { "system.io.compression.zipfile", "4.0.0" },
297 | { "microsoft.aspnet.html.abstractions", "1.0.0-rc1-final" },
298 | { "microsoft.dnx.compilation.csharp.abstractions", "1.0.0-rc1-final" },
299 | { "system.private.datacontractserialization", "4.0.0" },
300 | { "microsoft.aspnet.cryptography.internal", "1.0.0-rc1-final" },
301 | { "microsoft.aspnet.razor.runtime", "4.0.0-rc1-final" },
302 | { "microsoft.aspnet.dataprotection", "1.0.0-rc1-final" },
303 | { "microsoft.aspnet.dataprotection.abstractions", "1.0.0-rc1-final" },
304 | { "microsoft.aspnet.diagnostics.abstractions", "1.0.0-rc1-final" },
305 | { "microsoft.aspnet.authorization", "1.0.0-rc1-final" },
306 | { "microsoft.aspnet.mvc.core", "6.0.0-rc1-final" },
307 | { "microsoft.extensions.memorypool", "1.0.0-rc1-final" },
308 | { "microsoft.aspnet.mvc.abstractions", "6.0.0-rc1-final" },
309 | { "microsoft.aspnet.routing", "1.0.0-rc1-final" },
310 | { "microsoft.aspnet.iisplatformhandler", "1.0.0-rc1-final" },
311 | { "microsoft.aspnet.jsonpatch", "1.0.0-rc1-final" },
312 | { "system.runtime.serialization.xml", "4.0.10" },
313 | { "microsoft.extensions.localization.abstractions", "1.0.0-rc1-final" },
314 | { "microsoft.extensions.localization", "1.0.0-rc1-final" },
315 | { "microsoft.aspnet.antiforgery", "1.0.0-rc1-final" },
316 | { "microsoft.aspnet.pageexecutioninstrumentation.interfaces", "1.0.0-rc1-final" },
317 | { "microsoft.aspnet.mvc.razor.host", "6.0.0-rc1-final" },
318 | { "microsoft.extensions.globalization.cultureinfocache", "1.0.0-rc1-final" },
319 | { "microsoft.aspnet.localization", "1.0.0-rc1-final" },
320 | { "sendgrid.smtpapi", "1.3.1" },
321 | { "microsoft.aspnet.mvc.formatters.json", "6.0.0-rc1-final" },
322 | { "microsoft.netcore.portable.compatibility", "1.0.0" },
323 | { "microsoft.aspnet.mvc.viewfeatures", "6.0.0-rc1-final" },
324 | { "microsoft.aspnet.mvc.dataannotations", "6.0.0-rc1-final" },
325 | { "microsoft.aspnet.mvc.razor", "6.0.0-rc1-final" },
326 | { "microsoft.aspnet.mvc.apiexplorer", "6.0.0-rc1-final" },
327 | { "microsoft.aspnet.mvc.cors", "6.0.0-rc1-final" },
328 | { "rx-main", "2.2.5" },
329 | { "microsoft.aspnet.mvc.localization", "6.0.0-rc1-final" },
330 | { "microsoft.aspnet.razor.runtime.precompilation", "4.0.0-rc1-final" },
331 | { "microsoft.netcore.runtime", "1.0.0" },
332 | { "microsoft.dnx.compilation.csharp.common", "1.0.0-rc1-final" }
333 | };
334 | }
335 |
336 | ///
337 | /// get a version for a certain package name
338 | ///
339 | /// Package name.
340 | /// returns a string with package version, if package name is present in a map,
341 | /// null otherwise
342 | public string GetVersion(string name)
343 | {
344 | if (versions.ContainsKey(name))
345 | {
346 | return versions[name];
347 | }
348 | else
349 | {
350 | return null;
351 | }
352 | }
353 | }
354 | }
355 |
356 |
--------------------------------------------------------------------------------
/3rdparty/Microsoft.Framework.CommandLineUtils.Sources/1.0.0-rc1-15779/shared/CommandLineApplication.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace Microsoft.Dnx.Runtime.Common.CommandLine
12 | {
13 | internal class CommandLineApplication
14 | {
15 | // Indicates whether the parser should throw an exception when it runs into an unexpected argument.
16 | // If this field is set to false, the parser will stop parsing when it sees an unexpected argument, and all
17 | // remaining arguments, including the first unexpected argument, will be stored in RemainingArguments property.
18 | private readonly bool _throwOnUnexpectedArg;
19 |
20 | public CommandLineApplication(bool throwOnUnexpectedArg = true)
21 | {
22 | _throwOnUnexpectedArg = throwOnUnexpectedArg;
23 | Options = new List();
24 | Arguments = new List();
25 | Commands = new List();
26 | RemainingArguments = new List();
27 | Invoke = () => 0;
28 | }
29 |
30 | public CommandLineApplication Parent { get; set; }
31 | public string Name { get; set; }
32 | public string FullName { get; set; }
33 | public string Syntax { get; set; }
34 | public string Description { get; set; }
35 | public List Options { get; private set; }
36 | public CommandOption OptionHelp { get; private set; }
37 | public CommandOption OptionVersion { get; private set; }
38 | public List Arguments { get; private set; }
39 | public List RemainingArguments { get; private set; }
40 | public bool IsShowingInformation { get; protected set; } // Is showing help or version?
41 | public Func Invoke { get; set; }
42 | public Func LongVersionGetter { get; set; }
43 | public Func ShortVersionGetter { get; set; }
44 | public List Commands { get; private set; }
45 |
46 | public CommandLineApplication Command(string name, Action configuration,
47 | bool throwOnUnexpectedArg = true)
48 | {
49 | var command = new CommandLineApplication(throwOnUnexpectedArg) { Name = name, Parent = this };
50 | Commands.Add(command);
51 | configuration(command);
52 | return command;
53 | }
54 |
55 | public CommandOption Option(string template, string description, CommandOptionType optionType)
56 | {
57 | return Option(template, description, optionType, _ => { });
58 | }
59 |
60 | public CommandOption Option(string template, string description, CommandOptionType optionType, Action configuration)
61 | {
62 | var option = new CommandOption(template, optionType) { Description = description };
63 | Options.Add(option);
64 | configuration(option);
65 | return option;
66 | }
67 |
68 | public CommandArgument Argument(string name, string description, bool multipleValues = false)
69 | {
70 | return Argument(name, description, _ => { }, multipleValues);
71 | }
72 |
73 | public CommandArgument Argument(string name, string description, Action configuration, bool multipleValues = false)
74 | {
75 | var lastArg = Arguments.LastOrDefault();
76 | if (lastArg != null && lastArg.MultipleValues)
77 | {
78 | var message = string.Format("The last argument '{0}' accepts multiple values. No more argument can be added.",
79 | lastArg.Name);
80 | throw new InvalidOperationException(message);
81 | }
82 |
83 | var argument = new CommandArgument { Name = name, Description = description, MultipleValues = multipleValues };
84 | Arguments.Add(argument);
85 | configuration(argument);
86 | return argument;
87 | }
88 |
89 | public void OnExecute(Func invoke)
90 | {
91 | Invoke = invoke;
92 | }
93 |
94 | public void OnExecute(Func> invoke)
95 | {
96 | Invoke = () => invoke().Result;
97 | }
98 |
99 | public int Execute(params string[] args)
100 | {
101 | CommandLineApplication command = this;
102 | CommandOption option = null;
103 | IEnumerator arguments = null;
104 |
105 | for (var index = 0; index < args.Length; index++)
106 | {
107 | var arg = args[index];
108 | var processed = false;
109 | if (!processed && option == null)
110 | {
111 | string[] longOption = null;
112 | string[] shortOption = null;
113 |
114 | if (arg.StartsWith("--"))
115 | {
116 | longOption = arg.Substring(2).Split(new[] { ':', '=' }, 2);
117 | }
118 | else if (arg.StartsWith("-"))
119 | {
120 | shortOption = arg.Substring(1).Split(new[] { ':', '=' }, 2);
121 | }
122 | if (longOption != null)
123 | {
124 | processed = true;
125 | option = command.Options.SingleOrDefault(opt => string.Equals(opt.LongName, longOption[0], StringComparison.Ordinal));
126 |
127 | if (option == null)
128 | {
129 | HandleUnexpectedArg(command, args, index, argTypeName: "option");
130 | break;
131 | }
132 |
133 | // If we find a help/version option, show information and stop parsing
134 | if (command.OptionHelp == option)
135 | {
136 | command.ShowHelp();
137 | return 0;
138 | }
139 | else if (command.OptionVersion == option)
140 | {
141 | command.ShowVersion();
142 | return 0;
143 | }
144 |
145 | if (longOption.Length == 2)
146 | {
147 | if (!option.TryParse(longOption[1]))
148 | {
149 | command.ShowHint();
150 | throw new CommandParsingException(command, $"Unexpected value '{longOption[1]}' for option '{option.LongName}'");
151 | }
152 | option = null;
153 | }
154 | else if (option.OptionType == CommandOptionType.NoValue)
155 | {
156 | // No value is needed for this option
157 | option.TryParse(null);
158 | option = null;
159 | }
160 | }
161 | if (shortOption != null)
162 | {
163 | processed = true;
164 | option = command.Options.SingleOrDefault(opt => string.Equals(opt.ShortName, shortOption[0], StringComparison.Ordinal));
165 |
166 | // If not a short option, try symbol option
167 | if (option == null)
168 | {
169 | option = command.Options.SingleOrDefault(opt => string.Equals(opt.SymbolName, shortOption[0], StringComparison.Ordinal));
170 | }
171 |
172 | if (option == null)
173 | {
174 | HandleUnexpectedArg(command, args, index, argTypeName: "option");
175 | break;
176 | }
177 |
178 | // If we find a help/version option, show information and stop parsing
179 | if (command.OptionHelp == option)
180 | {
181 | command.ShowHelp();
182 | return 0;
183 | }
184 | else if (command.OptionVersion == option)
185 | {
186 | command.ShowVersion();
187 | return 0;
188 | }
189 |
190 | if (shortOption.Length == 2)
191 | {
192 | if (!option.TryParse(shortOption[1]))
193 | {
194 | command.ShowHint();
195 | throw new CommandParsingException(command, $"Unexpected value '{shortOption[1]}' for option '{option.LongName}'");
196 | }
197 | option = null;
198 | }
199 | else if (option.OptionType == CommandOptionType.NoValue)
200 | {
201 | // No value is needed for this option
202 | option.TryParse(null);
203 | option = null;
204 | }
205 | }
206 | }
207 |
208 | if (!processed && option != null)
209 | {
210 | processed = true;
211 | if (!option.TryParse(arg))
212 | {
213 | command.ShowHint();
214 | throw new CommandParsingException(command, $"Unexpected value '{arg}' for option '{option.LongName}'");
215 | }
216 | option = null;
217 | }
218 |
219 | if (!processed && arguments == null)
220 | {
221 | var currentCommand = command;
222 | foreach (var subcommand in command.Commands)
223 | {
224 | if (string.Equals(subcommand.Name, arg, StringComparison.OrdinalIgnoreCase))
225 | {
226 | processed = true;
227 | command = subcommand;
228 | break;
229 | }
230 | }
231 |
232 | // If we detect a subcommand
233 | if (command != currentCommand)
234 | {
235 | processed = true;
236 | }
237 | }
238 | if (!processed)
239 | {
240 | if (arguments == null)
241 | {
242 | arguments = new CommandArgumentEnumerator(command.Arguments.GetEnumerator());
243 | }
244 | if (arguments.MoveNext())
245 | {
246 | processed = true;
247 | arguments.Current.Values.Add(arg);
248 | }
249 | }
250 | if (!processed)
251 | {
252 | HandleUnexpectedArg(command, args, index, argTypeName: "command or argument");
253 | break;
254 | }
255 | }
256 |
257 | if (option != null)
258 | {
259 | command.ShowHint();
260 | throw new CommandParsingException(command, $"Missing value for option '{option.LongName}'");
261 | }
262 |
263 | return command.Invoke();
264 | }
265 |
266 | // Helper method that adds a help option
267 | public CommandOption HelpOption(string template)
268 | {
269 | // Help option is special because we stop parsing once we see it
270 | // So we store it separately for further use
271 | OptionHelp = Option(template, "Show help information", CommandOptionType.NoValue);
272 |
273 | return OptionHelp;
274 | }
275 |
276 | public CommandOption VersionOption(string template,
277 | string shortFormVersion,
278 | string longFormVersion = null)
279 | {
280 | if (longFormVersion == null)
281 | {
282 | return VersionOption(template, () => shortFormVersion);
283 | }
284 | else
285 | {
286 | return VersionOption(template, () => shortFormVersion, () => longFormVersion);
287 | }
288 | }
289 |
290 | // Helper method that adds a version option
291 | public CommandOption VersionOption(string template,
292 | Func shortFormVersionGetter,
293 | Func longFormVersionGetter = null)
294 | {
295 | // Version option is special because we stop parsing once we see it
296 | // So we store it separately for further use
297 | OptionVersion = Option(template, "Show version information", CommandOptionType.NoValue);
298 | ShortVersionGetter = shortFormVersionGetter;
299 | LongVersionGetter = longFormVersionGetter ?? shortFormVersionGetter;
300 |
301 | return OptionVersion;
302 | }
303 |
304 | // Show short hint that reminds users to use help option
305 | public void ShowHint()
306 | {
307 | if (OptionHelp != null)
308 | {
309 | Console.WriteLine(string.Format("Specify --{0} for a list of available options and commands.", OptionHelp.LongName));
310 | }
311 | }
312 |
313 | // Show full help
314 | public void ShowHelp(string commandName = null)
315 | {
316 | var headerBuilder = new StringBuilder("Usage:");
317 | for (var cmd = this; cmd != null; cmd = cmd.Parent)
318 | {
319 | cmd.IsShowingInformation = true;
320 | headerBuilder.Insert(6, string.Format(" {0}", cmd.Name));
321 | }
322 |
323 | CommandLineApplication target;
324 |
325 | if (commandName == null || string.Equals(Name, commandName, StringComparison.OrdinalIgnoreCase))
326 | {
327 | target = this;
328 | }
329 | else
330 | {
331 | target = Commands.SingleOrDefault(cmd => string.Equals(cmd.Name, commandName, StringComparison.OrdinalIgnoreCase));
332 |
333 | if (target != null)
334 | {
335 | headerBuilder.AppendFormat(" {0}", commandName);
336 | }
337 | else
338 | {
339 | // The command name is invalid so don't try to show help for something that doesn't exist
340 | target = this;
341 | }
342 |
343 | }
344 |
345 | var optionsBuilder = new StringBuilder();
346 | var commandsBuilder = new StringBuilder();
347 | var argumentsBuilder = new StringBuilder();
348 |
349 | if (target.Arguments.Any())
350 | {
351 | headerBuilder.Append(" [arguments]");
352 |
353 | argumentsBuilder.AppendLine();
354 | argumentsBuilder.AppendLine("Arguments:");
355 | var maxArgLen = MaxArgumentLength(target.Arguments);
356 | var outputFormat = string.Format(" {{0, -{0}}}{{1}}", maxArgLen + 2);
357 | foreach (var arg in target.Arguments)
358 | {
359 | argumentsBuilder.AppendFormat(outputFormat, arg.Name, arg.Description);
360 | argumentsBuilder.AppendLine();
361 | }
362 | }
363 |
364 | if (target.Options.Any())
365 | {
366 | headerBuilder.Append(" [options]");
367 |
368 | optionsBuilder.AppendLine();
369 | optionsBuilder.AppendLine("Options:");
370 | var maxOptLen = MaxOptionTemplateLength(target.Options);
371 | var outputFormat = string.Format(" {{0, -{0}}}{{1}}", maxOptLen + 2);
372 | foreach (var opt in target.Options)
373 | {
374 | optionsBuilder.AppendFormat(outputFormat, opt.Template, opt.Description);
375 | optionsBuilder.AppendLine();
376 | }
377 | }
378 |
379 | if (target.Commands.Any())
380 | {
381 | headerBuilder.Append(" [command]");
382 |
383 | commandsBuilder.AppendLine();
384 | commandsBuilder.AppendLine("Commands:");
385 | var maxCmdLen = MaxCommandLength(target.Commands);
386 | var outputFormat = string.Format(" {{0, -{0}}}{{1}}", maxCmdLen + 2);
387 | foreach (var cmd in target.Commands.OrderBy(c => c.Name))
388 | {
389 | commandsBuilder.AppendFormat(outputFormat, cmd.Name, cmd.Description);
390 | commandsBuilder.AppendLine();
391 | }
392 |
393 | if (OptionHelp != null)
394 | {
395 | commandsBuilder.AppendLine();
396 | commandsBuilder.AppendFormat("Use \"{0} [command] --help\" for more information about a command.", Name);
397 | commandsBuilder.AppendLine();
398 | }
399 | }
400 |
401 | headerBuilder.AppendLine();
402 |
403 | var nameAndVersion = new StringBuilder();
404 | nameAndVersion.AppendLine(GetFullNameAndVersion());
405 | nameAndVersion.AppendLine();
406 |
407 | Console.Write("{0}{1}{2}{3}{4}", nameAndVersion, headerBuilder, argumentsBuilder, optionsBuilder, commandsBuilder);
408 | }
409 |
410 | public void ShowVersion()
411 | {
412 | for (var cmd = this; cmd != null; cmd = cmd.Parent)
413 | {
414 | cmd.IsShowingInformation = true;
415 | }
416 |
417 | Console.WriteLine(FullName);
418 | Console.WriteLine(LongVersionGetter());
419 | }
420 |
421 | public string GetFullNameAndVersion()
422 | {
423 | return ShortVersionGetter == null ? FullName : string.Format("{0} {1}", FullName, ShortVersionGetter());
424 | }
425 |
426 | public void ShowRootCommandFullNameAndVersion()
427 | {
428 | var rootCmd = this;
429 | while (rootCmd.Parent != null)
430 | {
431 | rootCmd = rootCmd.Parent;
432 | }
433 |
434 | Console.WriteLine(rootCmd.GetFullNameAndVersion());
435 | Console.WriteLine();
436 | }
437 |
438 | private int MaxOptionTemplateLength(IEnumerable options)
439 | {
440 | var maxLen = 0;
441 | foreach (var opt in options)
442 | {
443 | maxLen = opt.Template.Length > maxLen ? opt.Template.Length : maxLen;
444 | }
445 | return maxLen;
446 | }
447 |
448 | private int MaxCommandLength(IEnumerable commands)
449 | {
450 | var maxLen = 0;
451 | foreach (var cmd in commands)
452 | {
453 | maxLen = cmd.Name.Length > maxLen ? cmd.Name.Length : maxLen;
454 | }
455 | return maxLen;
456 | }
457 |
458 | private int MaxArgumentLength(IEnumerable arguments)
459 | {
460 | var maxLen = 0;
461 | foreach (var arg in arguments)
462 | {
463 | maxLen = arg.Name.Length > maxLen ? arg.Name.Length : maxLen;
464 | }
465 | return maxLen;
466 | }
467 |
468 | private void HandleUnexpectedArg(CommandLineApplication command, string[] args, int index, string argTypeName)
469 | {
470 | if (command._throwOnUnexpectedArg)
471 | {
472 | command.ShowHint();
473 | throw new CommandParsingException(command, $"Unrecognized {argTypeName} '{args[index]}'");
474 | }
475 | else
476 | {
477 | // All remaining arguments are stored for further use
478 | command.RemainingArguments.AddRange(new ArraySegment(args, index, args.Length - index));
479 | }
480 | }
481 |
482 | private class CommandArgumentEnumerator : IEnumerator
483 | {
484 | private readonly IEnumerator _enumerator;
485 |
486 | public CommandArgumentEnumerator(IEnumerator enumerator)
487 | {
488 | _enumerator = enumerator;
489 | }
490 |
491 | public CommandArgument Current
492 | {
493 | get
494 | {
495 | return _enumerator.Current;
496 | }
497 | }
498 |
499 | object IEnumerator.Current
500 | {
501 | get
502 | {
503 | return Current;
504 | }
505 | }
506 |
507 | public void Dispose()
508 | {
509 | _enumerator.Dispose();
510 | }
511 |
512 | public bool MoveNext()
513 | {
514 | if (Current == null || !Current.MultipleValues)
515 | {
516 | return _enumerator.MoveNext();
517 | }
518 |
519 | // If current argument allows multiple values, we don't move forward and
520 | // all later values will be added to current CommandArgument.Values
521 | return true;
522 | }
523 |
524 | public void Reset()
525 | {
526 | _enumerator.Reset();
527 | }
528 | }
529 | }
530 | }
531 |
--------------------------------------------------------------------------------