@@ -21,27 +21,11 @@ internal class Assets
21
21
"netstandard.library.ref"
22
22
} ;
23
23
24
-
25
24
internal Assets ( ProgressMonitor progressMonitor )
26
25
{
27
26
this . progressMonitor = progressMonitor ;
28
27
}
29
28
30
- /// <summary>
31
- /// In most cases paths in asset files point to dll's or the empty _._ file, which
32
- /// is sometimes there to avoid the directory being empty.
33
- /// That is, if the path specifically adds a .dll we use that, otherwise we as a fallback
34
- /// add the entire directory (which should be fine in case of _._ as well).
35
- /// </summary>
36
- private static string ParseFilePath ( string path )
37
- {
38
- if ( path . EndsWith ( ".dll" ) )
39
- {
40
- return path ;
41
- }
42
- return Path . GetDirectoryName ( path ) ?? path ;
43
- }
44
-
45
29
/// <summary>
46
30
/// Class needed for deserializing parts of an assets file.
47
31
/// It holds information about a reference.
@@ -62,10 +46,11 @@ private class ReferenceInfo
62
46
}
63
47
64
48
/// <summary>
65
- /// Gets the package dependencies from the assets file.
49
+ /// Add the package dependencies from the assets file to dependencies .
66
50
///
67
- /// Parse a part of the JSon assets file and returns the paths
68
- /// to the dependencies required for compilation.
51
+ /// Parse a part of the JSon assets file and add the paths
52
+ /// to the dependencies required for compilation (and collect
53
+ /// information about used packages).
69
54
///
70
55
/// Example:
71
56
/// {
@@ -88,12 +73,17 @@ private class ReferenceInfo
88
73
/// }
89
74
/// }
90
75
///
91
- /// Returns {
92
- /// "castle.core/4.4.1/lib/netstandard1.5/Castle.Core.dll",
93
- /// "json.net/1.0.33/lib/netstandard2.0/Json.Net.dll"
94
- /// }
76
+ /// Returns dependencies
77
+ /// Required = {
78
+ /// "castle.core/4.4.1/lib/netstandard1.5/Castle.Core.dll",
79
+ /// "json.net/1.0.33/lib/netstandard2.0/Json.Net.dll"
80
+ /// }
81
+ /// UsedPackages = {
82
+ /// "castle.core",
83
+ /// "json.net"
84
+ /// }
95
85
/// </summary>
96
- private IEnumerable < string > GetPackageDependencies ( JObject json )
86
+ private Dependencies AddPackageDependencies ( JObject json , Dependencies dependencies )
97
87
{
98
88
// If there are more than one framework we need to pick just one.
99
89
// To ensure stability we pick one based on the lexicographic order of
@@ -108,49 +98,41 @@ private IEnumerable<string> GetPackageDependencies(JObject json)
108
98
if ( references is null )
109
99
{
110
100
progressMonitor . LogDebug ( "No references found in the targets section in the assets file." ) ;
111
- return Array . Empty < string > ( ) ;
101
+ return dependencies ;
112
102
}
113
103
114
104
// Find all the compile dependencies for each reference and
115
105
// create the relative path to the dependency.
116
- var dependencies = references
117
- . SelectMany ( r =>
106
+ return references
107
+ . Aggregate ( dependencies , ( deps , r ) =>
118
108
{
119
109
var info = r . Value ;
120
110
var name = r . Key . ToLowerInvariant ( ) ;
121
111
if ( info . Type != "package" )
122
112
{
123
- return Array . Empty < string > ( ) ;
113
+ return deps ;
124
114
}
125
115
126
116
// If this is a .NET framework reference then include everything.
127
117
return netFrameworks . Any ( framework => name . StartsWith ( framework ) )
128
- ? new [ ] { name }
118
+ ? deps . Add ( name , "" )
129
119
: info
130
120
. Compile
131
- . Select ( p => Path . Combine ( name , ParseFilePath ( p . Key ) ) ) ;
132
- } )
133
- . ToList ( ) ;
134
-
135
- return dependencies ;
121
+ . Aggregate ( deps , ( d , p ) => d . Add ( name , p . Key ) ) ;
122
+ } ) ;
136
123
}
137
124
138
125
/// <summary>
139
- /// Parse `json` as project.assets.json content and populate `dependencies` with the
140
- /// relative paths to the dependencies required for compilation.
126
+ /// Parse `json` as project.assets.json content and add relative paths to the dependencies
127
+ /// (together with used package information) required for compilation.
141
128
/// </summary>
142
129
/// <returns>True if parsing succeeds, otherwise false.</returns>
143
- public bool TryParse ( string json , out IEnumerable < string > dependencies )
130
+ public bool TryParse ( string json , Dependencies dependencies )
144
131
{
145
- dependencies = Array . Empty < string > ( ) ;
146
-
147
132
try
148
133
{
149
134
var obj = JObject . Parse ( json ) ;
150
- var packages = GetPackageDependencies ( obj ) ;
151
-
152
- dependencies = packages . ToList ( ) ;
153
-
135
+ AddPackageDependencies ( obj , dependencies ) ;
154
136
return true ;
155
137
}
156
138
catch ( Exception e )
@@ -160,13 +142,14 @@ public bool TryParse(string json, out IEnumerable<string> dependencies)
160
142
}
161
143
}
162
144
163
- public static IEnumerable < string > GetCompilationDependencies ( ProgressMonitor progressMonitor , IEnumerable < string > assets )
145
+ public static Dependencies GetCompilationDependencies ( ProgressMonitor progressMonitor , IEnumerable < string > assets )
164
146
{
165
147
var parser = new Assets ( progressMonitor ) ;
166
- return assets . SelectMany ( asset =>
148
+ return assets . Aggregate ( new Dependencies ( ) , ( dependencies , asset ) =>
167
149
{
168
150
var json = File . ReadAllText ( asset ) ;
169
- return parser . TryParse ( json , out var dependencies ) ? dependencies : Array . Empty < string > ( ) ;
151
+ parser . TryParse ( json , dependencies ) ;
152
+ return dependencies ;
170
153
} ) ;
171
154
}
172
155
}
0 commit comments