Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
fc3bb71b
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fc3bb71b
编写于
7月 27, 2016
作者:
J
Jared Parsons
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better consumes implementation
上级
de349809
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
151 addition
and
52 deletion
+151
-52
src/Tools/RepoUtil/ConsumesUtil.cs
src/Tools/RepoUtil/ConsumesUtil.cs
+93
-0
src/Tools/RepoUtil/NuGetPackage.cs
src/Tools/RepoUtil/NuGetPackage.cs
+2
-2
src/Tools/RepoUtil/Program.cs
src/Tools/RepoUtil/Program.cs
+4
-27
src/Tools/RepoUtil/ProjectJsonUtil.cs
src/Tools/RepoUtil/ProjectJsonUtil.cs
+11
-5
src/Tools/RepoUtil/RepoData.cs
src/Tools/RepoUtil/RepoData.cs
+34
-7
src/Tools/RepoUtil/RepoUtil.csproj
src/Tools/RepoUtil/RepoUtil.csproj
+2
-1
src/Tools/RepoUtil/VerifyUtil.cs
src/Tools/RepoUtil/VerifyUtil.cs
+5
-10
未找到文件。
src/Tools/RepoUtil/ConsumesUtil.cs
0 → 100644
浏览文件 @
fc3bb71b
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
RepoUtil
{
internal
sealed
class
ConsumesUtil
{
private
readonly
RepoData
_repoData
;
internal
ConsumesUtil
(
RepoData
repoData
)
{
Debug
.
Assert
(
repoData
.
HasCurentData
);
_repoData
=
repoData
;
}
internal
static
string
Go
(
string
sourcesPath
,
RepoData
repoData
)
{
Debug
.
Assert
(!
repoData
.
HasCurentData
);
repoData
=
repoData
.
PopulateWithCurrentData
(
sourcesPath
);
var
util
=
new
ConsumesUtil
(
repoData
);
var
obj
=
util
.
GoCore
();
return
obj
.
ToString
(
Formatting
.
Indented
);
}
private
JObject
GoCore
()
{
var
obj
=
new
JObject
();
obj
.
Add
(
GetStaticPackages
());
obj
.
Add
(
GetBuildPackages
());
obj
.
Add
(
GetToolsetPackages
());
return
obj
;
}
private
JProperty
GetStaticPackages
()
{
var
obj
=
new
JObject
();
foreach
(
var
pair
in
_repoData
.
StaticPackagesMap
.
OrderBy
(
x
=>
x
.
Key
))
{
obj
.
Add
(
GetProperty
(
pair
.
Key
,
pair
.
Value
));
}
return
new
JProperty
(
"static"
,
obj
);
}
private
JProperty
GetBuildPackages
()
{
return
GetFloatingPackages
(
"build"
,
_repoData
.
FloatingBuildPackages
);
}
private
JProperty
GetToolsetPackages
()
{
return
GetFloatingPackages
(
"toolset"
,
_repoData
.
FloatingToolsetPackages
);
}
private
JProperty
GetFloatingPackages
(
string
name
,
IEnumerable
<
string
>
packages
)
{
var
array
=
new
JArray
();
foreach
(
var
package
in
packages
)
{
array
.
Add
(
package
);
}
return
new
JProperty
(
name
,
array
);
}
private
static
JProperty
GetProperty
(
NuGetPackage
package
)
{
return
new
JProperty
(
package
.
Name
,
package
.
Version
);
}
private
static
JProperty
GetProperty
(
string
packageName
,
ImmutableArray
<
string
>
versions
)
{
if
(
versions
.
Length
==
1
)
{
return
GetProperty
(
new
NuGetPackage
(
packageName
,
versions
[
0
]));
}
var
content
=
JArray
.
FromObject
(
versions
.
ToArray
());
return
new
JProperty
(
packageName
,
content
);
}
private
static
string
GetKey
(
NuGetPackage
nugetRef
)
{
return
$"
{
nugetRef
.
Name
}
:
{
nugetRef
.
Version
}
"
;
}
}
}
src/Tools/RepoUtil/NuGet
Referenc
e.cs
→
src/Tools/RepoUtil/NuGet
Packag
e.cs
浏览文件 @
fc3bb71b
...
...
@@ -6,12 +6,12 @@
namespace
RepoUtil
{
internal
struct
NuGet
Referenc
e
internal
struct
NuGet
Packag
e
{
internal
string
Name
{
get
;
}
internal
string
Version
{
get
;
}
internal
NuGet
Referenc
e
(
string
name
,
string
version
)
internal
NuGet
Packag
e
(
string
name
,
string
version
)
{
Name
=
name
;
Version
=
version
;
...
...
src/Tools/RepoUtil/Program.cs
浏览文件 @
fc3bb71b
...
...
@@ -42,36 +42,13 @@ private static bool Run(string[] args)
case
Mode
.
Verify
:
return
VerifyUtil
.
Go
(
sourcesPath
,
repoData
);
case
Mode
.
Consumes
:
return
Consumes
(
sourcesPath
);
default
:
throw
new
Exception
(
"Unrecognized mode"
);
}
}
private
static
bool
Consumes
(
string
sourcesPath
)
{
var
set
=
new
HashSet
<
string
>(
StringComparer
.
Ordinal
);
var
list
=
new
List
<
string
>();
var
all
=
Data
.
FloatingList
.
Concat
(
Data
.
StaticList
).
Select
(
x
=>
new
FileName
(
sourcesPath
,
x
));
foreach
(
var
fileName
in
all
)
{
foreach
(
var
nugetRef
in
ProjectJsonUtil
.
GetDependencies
(
fileName
.
FullPath
))
{
var
key
=
$@"""
{
nugetRef
.
Name
}
"" : ""
{
nugetRef
.
Version
}
"""
;
if
(
set
.
Add
(
key
))
{
list
.
Add
(
key
);
Console
.
WriteLine
(
ConsumesUtil
.
Go
(
sourcesPath
,
repoData
));
return
true
;
}
}
}
list
.
Sort
();
foreach
(
var
key
in
list
)
{
Console
.
WriteLine
(
key
);
default
:
throw
new
Exception
(
"Unrecognized mode"
);
}
return
true
;
}
private
static
void
Usage
()
...
...
src/Tools/RepoUtil/ProjectJsonUtil.cs
浏览文件 @
fc3bb71b
...
...
@@ -21,17 +21,17 @@ internal static bool NeedsTracking(string filePath)
}
// TOOD: use FileName here
internal
static
ImmutableArray
<
NuGet
Referenc
e
>
GetDependencies
(
string
filePath
)
internal
static
ImmutableArray
<
NuGet
Packag
e
>
GetDependencies
(
string
filePath
)
{
// Need to track any file that has dependencies
var
obj
=
JObject
.
Parse
(
File
.
ReadAllText
(
filePath
));
var
dependencies
=
(
JObject
)
obj
[
"dependencies"
];
if
(
dependencies
==
null
)
{
return
ImmutableArray
<
NuGet
Referenc
e
>.
Empty
;
return
ImmutableArray
<
NuGet
Packag
e
>.
Empty
;
}
var
builder
=
ImmutableArray
.
CreateBuilder
<
NuGet
Referenc
e
>();
var
builder
=
ImmutableArray
.
CreateBuilder
<
NuGet
Packag
e
>();
foreach
(
var
dependency
in
dependencies
.
Properties
())
{
builder
.
Add
(
ParseDependency
(
dependency
));
...
...
@@ -43,7 +43,7 @@ internal static ImmutableArray<NuGetReference> GetDependencies(string filePath)
/// <summary>
/// Parse out a dependency entry from the project.json file.
/// </summary>
internal
static
NuGet
Referenc
e
ParseDependency
(
JProperty
prop
)
internal
static
NuGet
Packag
e
ParseDependency
(
JProperty
prop
)
{
var
name
=
prop
.
Name
;
...
...
@@ -57,7 +57,7 @@ internal static NuGetReference ParseDependency(JProperty prop)
version
=
((
JObject
)
prop
.
Value
).
Value
<
string
>(
"version"
);
}
return
new
NuGet
Referenc
e
(
name
,
version
);
return
new
NuGet
Packag
e
(
name
,
version
);
}
internal
static
bool
VerifyTracked
(
string
sourcesPath
,
IEnumerable
<
FileName
>
fileNames
)
...
...
@@ -80,5 +80,11 @@ internal static bool VerifyTracked(string sourcesPath, IEnumerable<FileName> fil
return
allGood
;
}
// TODO: Need to include our toolset files not named project.json.
internal
static
IEnumerable
<
string
>
GetProjectJsonFiles
(
string
sourcesPath
)
{
return
Directory
.
EnumerateFiles
(
sourcesPath
,
"project.json"
,
SearchOption
.
AllDirectories
);
}
}
}
src/Tools/RepoUtil/RepoData.cs
浏览文件 @
fc3bb71b
...
...
@@ -39,7 +39,7 @@ internal class RepoData
/// <summary>
/// Fixed references which do not change during a build.
/// </summary>
internal
ImmutableArray
<
NuGet
Referenc
e
>
StaticPackages
{
get
;
}
internal
ImmutableArray
<
NuGet
Packag
e
>
StaticPackages
{
get
;
}
/// <summary>
/// This is a map of static package names to the list of supported versions.
...
...
@@ -47,13 +47,13 @@ internal class RepoData
internal
ImmutableDictionary
<
string
,
ImmutableArray
<
string
>>
StaticPackagesMap
{
get
;
}
internal
ImmutableArray
<
string
>
FloatingBuildPackages
{
get
;
}
internal
ImmutableArray
<
string
>
FloatingToolsetPackages
{
get
;
}
internal
ImmutableArray
<
string
>
FloatingPackages
{
get
;
}
internal
bool
HasCurentData
{
get
;
}
internal
RepoData
(
IEnumerable
<
NuGet
Reference
>
staticPackages
,
IEnumerable
<
string
>
floatingBuildPackages
,
IEnumerable
<
string
>
floatingToolsetPackages
)
internal
RepoData
(
IEnumerable
<
NuGet
Package
>
staticPackages
,
IEnumerable
<
string
>
floatingBuildPackages
,
IEnumerable
<
string
>
floatingToolsetPackages
,
bool
hasCurrentData
=
false
)
{
HasCurentData
=
hasCurrentData
;
StaticPackages
=
staticPackages
.
OrderBy
(
x
=>
x
.
Name
).
ToImmutableArray
();
// TODO: Validate duplicate names in the floating lists
...
...
@@ -86,20 +86,20 @@ internal static RepoData ReadFrom(string jsonFilePath)
// Need to track any file that has dependencies
var
obj
=
JObject
.
Parse
(
File
.
ReadAllText
(
jsonFilePath
));
var
staticPackages
=
(
JObject
)
obj
[
"staticPackages"
];
var
staticPackagesList
=
ImmutableArray
.
CreateBuilder
<
NuGet
Referenc
e
>();
var
staticPackagesList
=
ImmutableArray
.
CreateBuilder
<
NuGet
Packag
e
>();
foreach
(
var
prop
in
staticPackages
.
Properties
())
{
if
(
prop
.
Value
.
Type
==
JTokenType
.
String
)
{
var
version
=
(
string
)
prop
.
Value
;
var
nugetRef
=
new
NuGet
Referenc
e
(
prop
.
Name
,
version
);
var
nugetRef
=
new
NuGet
Packag
e
(
prop
.
Name
,
version
);
staticPackagesList
.
Add
(
nugetRef
);
}
else
{
foreach
(
var
version
in
((
JArray
)
prop
.
Value
).
Values
<
string
>())
{
var
nugetRef
=
new
NuGet
Referenc
e
(
prop
.
Name
,
version
);
var
nugetRef
=
new
NuGet
Packag
e
(
prop
.
Name
,
version
);
staticPackagesList
.
Add
(
nugetRef
);
}
}
...
...
@@ -114,5 +114,32 @@ internal static RepoData ReadFrom(string jsonFilePath)
build
.
Values
<
string
>(),
toolset
.
Values
<
string
>());
}
/// <summary>
/// The raw RepoData contains only the static + toolset packages that we need to track. This method will examine the current
/// state of the repo and add in the current data.
/// </summary>
internal
RepoData
PopulateWithCurrentData
(
string
sourcesPath
)
{
var
list
=
new
List
<
string
>(
FloatingPackages
);
foreach
(
var
fileName
in
ProjectJsonUtil
.
GetProjectJsonFiles
(
sourcesPath
))
{
foreach
(
var
nuget
in
ProjectJsonUtil
.
GetDependencies
(
fileName
))
{
if
(
StaticPackagesMap
.
ContainsKey
(
nuget
.
Name
)
||
FloatingToolsetPackages
.
Contains
(
nuget
.
Name
))
{
continue
;
}
list
.
Add
(
nuget
.
Name
);
}
}
return
new
RepoData
(
StaticPackages
,
list
,
FloatingToolsetPackages
,
hasCurrentData
:
true
);
}
}
}
src/Tools/RepoUtil/RepoUtil.csproj
浏览文件 @
fc3bb71b
...
...
@@ -23,10 +23,11 @@
<Reference
Include=
"WindowsBase"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"ConsumesUtil.cs"
/>
<Compile
Include=
"Data.cs"
/>
<Compile
Include=
"FileName.cs"
/>
<Compile
Include=
"JsonTypes.cs"
/>
<Compile
Include=
"NuGet
Referenc
e.cs"
/>
<Compile
Include=
"NuGet
Packag
e.cs"
/>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"ProjectJsonUtil.cs"
/>
<Compile
Include=
"RepoData.cs"
/>
...
...
src/Tools/RepoUtil/VerifyUtil.cs
浏览文件 @
fc3bb71b
...
...
@@ -16,10 +16,10 @@ internal sealed class VerifyUtil
{
private
struct
NuGetReferenceSource
{
internal
NuGet
Referenc
e
NuGetReference
{
get
;
}
internal
NuGet
Packag
e
NuGetReference
{
get
;
}
internal
FileName
FileName
{
get
;
}
internal
NuGetReferenceSource
(
NuGet
Referenc
e
nugetRef
,
FileName
fileName
)
internal
NuGetReferenceSource
(
NuGet
Packag
e
nugetRef
,
FileName
fileName
)
{
NuGetReference
=
nugetRef
;
FileName
=
fileName
;
...
...
@@ -50,7 +50,7 @@ private bool Go()
private
bool
VerifyPackages
()
{
var
allGood
=
false
;
foreach
(
var
filePath
in
GetProjectJsonFiles
(
))
foreach
(
var
filePath
in
ProjectJsonUtil
.
GetProjectJsonFiles
(
_sourcesPath
))
{
var
fileName
=
FileName
.
FromFullPath
(
_sourcesPath
,
filePath
);
foreach
(
var
nugetRef
in
ProjectJsonUtil
.
GetDependencies
(
filePath
))
...
...
@@ -75,7 +75,7 @@ private bool VerifyPackages()
return
allGood
;
}
private
bool
VerifyFloatingPackage
(
NuGet
Referenc
e
nugetRef
,
FileName
fileName
)
private
bool
VerifyFloatingPackage
(
NuGet
Packag
e
nugetRef
,
FileName
fileName
)
{
NuGetReferenceSource
source
;
if
(
_floatingPackageMap
.
TryGetValue
(
nugetRef
.
Name
,
out
source
))
...
...
@@ -95,7 +95,7 @@ private bool VerifyFloatingPackage(NuGetReference nugetRef, FileName fileName)
return
true
;
}
private
bool
VerifyStaticPackage
(
NuGet
Referenc
e
nugetRef
,
FileName
fileName
)
private
bool
VerifyStaticPackage
(
NuGet
Packag
e
nugetRef
,
FileName
fileName
)
{
Debug
.
Assert
(
_repoData
.
StaticPackagesMap
.
ContainsKey
(
nugetRef
.
Name
));
var
versions
=
_repoData
.
StaticPackagesMap
[
nugetRef
.
Name
];
...
...
@@ -108,10 +108,5 @@ private bool VerifyStaticPackage(NuGetReference nugetRef, FileName fileName)
return
true
;
}
// TODO: Need to include our toolset files not named project.json.
private
IEnumerable
<
string
>
GetProjectJsonFiles
()
{
return
Directory
.
EnumerateFiles
(
_sourcesPath
,
"project.json"
,
SearchOption
.
AllDirectories
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录