This repository was archived by the owner on Dec 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathProjectFilesCollection.cs
More file actions
202 lines (169 loc) · 8.31 KB
/
Copy pathProjectFilesCollection.cs
File metadata and controls
202 lines (169 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.Extensions.JsonParser.Sources;
namespace Microsoft.Dnx.Runtime
{
public class ProjectFilesCollection
{
public static readonly string[] DefaultCompileBuiltInPatterns = new[] { @"**/*.cs" };
public static readonly string[] DefaultPublishExcludePatterns = new[] { @"obj/**/*.*", @"bin/**/*.*", @"**/.*/**", @"**/global.json" };
public static readonly string[] DefaultPreprocessPatterns = new[] { @"compiler/preprocess/**/*.cs" };
public static readonly string[] DefaultSharedPatterns = new[] { @"compiler/shared/**/*.cs" };
public static readonly string[] DefaultResourcesBuiltInPatterns = new[] { @"compiler/resources/**/*", "**/*.resx" };
public static readonly string[] DefaultContentsBuiltInPatterns = new[] { @"**/*" };
public static readonly string[] DefaultBuiltInExcludePatterns = new[] { "bin/**", "obj/**", "**/*.xproj" };
public static readonly string PackIncludePropertyName = "packInclude";
private PatternGroup _sharedPatternsGroup;
private PatternGroup _resourcePatternsGroup;
private PatternGroup _preprocessPatternsGroup;
private PatternGroup _compilePatternsGroup;
private PatternGroup _contentPatternsGroup;
private IDictionary<string, string> _namedResources;
private IEnumerable<string> _publishExcludePatterns;
private IEnumerable<PackIncludeEntry> _packInclude;
private readonly string _projectDirectory;
private readonly string _projectFilePath;
private JsonObject _rawProject;
private bool _initialized;
internal ProjectFilesCollection(JsonObject rawProject, string projectDirectory, string projectFilePath)
{
_projectDirectory = projectDirectory;
_projectFilePath = projectFilePath;
_rawProject = rawProject;
}
internal void EnsureInitialized()
{
if (_initialized)
{
return;
}
var excludeBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "excludeBuiltIn", DefaultBuiltInExcludePatterns);
var excludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "exclude")
.Concat(excludeBuiltIns);
var contentBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "contentBuiltIn", DefaultContentsBuiltInPatterns);
var compileBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "compileBuiltIn", DefaultCompileBuiltInPatterns);
var resourceBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "resourceBuiltIn", DefaultResourcesBuiltInPatterns);
_publishExcludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "publishExclude", DefaultPublishExcludePatterns);
_sharedPatternsGroup = PatternGroup.Build(_rawProject, _projectDirectory, _projectFilePath, "shared", fallbackIncluding: DefaultSharedPatterns, additionalExcluding: excludePatterns);
_resourcePatternsGroup = PatternGroup.Build(_rawProject, _projectDirectory, _projectFilePath, "resource", additionalIncluding: resourceBuiltIns, additionalExcluding: excludePatterns);
_preprocessPatternsGroup = PatternGroup.Build(_rawProject, _projectDirectory, _projectFilePath, "preprocess", fallbackIncluding: DefaultPreprocessPatterns, additionalExcluding: excludePatterns)
.ExcludeGroup(_sharedPatternsGroup)
.ExcludeGroup(_resourcePatternsGroup);
_compilePatternsGroup = PatternGroup.Build(_rawProject, _projectDirectory, _projectFilePath, "compile", additionalIncluding: compileBuiltIns, additionalExcluding: excludePatterns)
.ExcludeGroup(_sharedPatternsGroup)
.ExcludeGroup(_preprocessPatternsGroup)
.ExcludeGroup(_resourcePatternsGroup);
_contentPatternsGroup = PatternGroup.Build(_rawProject, _projectDirectory, _projectFilePath, "content", additionalIncluding: contentBuiltIns, additionalExcluding: excludePatterns.Concat(_publishExcludePatterns))
.ExcludeGroup(_compilePatternsGroup)
.ExcludeGroup(_preprocessPatternsGroup)
.ExcludeGroup(_sharedPatternsGroup)
.ExcludeGroup(_resourcePatternsGroup);
_namedResources = NamedResourceReader.ReadNamedResources(_rawProject, _projectFilePath);
// Files to be packed along with the project
var packIncludeJson = _rawProject.ValueAsJsonObject(PackIncludePropertyName);
if (packIncludeJson != null)
{
_packInclude = packIncludeJson
.Keys
.Select(k => new PackIncludeEntry(k, packIncludeJson.Value(k)))
.ToList();
}
else
{
_packInclude = new List<PackIncludeEntry>();
}
_initialized = true;
_rawProject = null;
}
public IEnumerable<PackIncludeEntry> PackInclude
{
get
{
EnsureInitialized();
return _packInclude;
}
}
public IEnumerable<string> SourceFiles
{
get { return CompilePatternsGroup.SearchFiles(_projectDirectory).Distinct(); }
}
public IEnumerable<string> PreprocessSourceFiles
{
get { return PreprocessPatternsGroup.SearchFiles(_projectDirectory).Distinct(); }
}
public IDictionary<string, string> ResourceFiles
{
get
{
var resources = ResourcePatternsGroup
.SearchFiles(_projectDirectory)
.Distinct()
.ToDictionary(res => res, res => (string)null);
NamedResourceReader.ApplyNamedResources(_namedResources, resources);
return resources;
}
}
public IEnumerable<string> SharedFiles
{
get { return SharedPatternsGroup.SearchFiles(_projectDirectory).Distinct(); }
}
public IEnumerable<string> GetFilesForBundling(bool includeSource, IEnumerable<string> additionalExcludePatterns)
{
var patternGroup = new PatternGroup(ContentPatternsGroup.IncludePatterns,
ContentPatternsGroup.ExcludePatterns.Concat(additionalExcludePatterns),
ContentPatternsGroup.IncludeLiterals);
if (!includeSource)
{
foreach (var excludedGroup in ContentPatternsGroup.ExcludePatternsGroup)
{
patternGroup.ExcludeGroup(excludedGroup);
}
}
return patternGroup.SearchFiles(_projectDirectory);
}
internal PatternGroup CompilePatternsGroup
{
get
{
EnsureInitialized();
return _compilePatternsGroup;
}
}
internal PatternGroup SharedPatternsGroup
{
get
{
EnsureInitialized();
return _sharedPatternsGroup;
}
}
internal PatternGroup ResourcePatternsGroup
{
get
{
EnsureInitialized();
return _resourcePatternsGroup;
}
}
internal PatternGroup PreprocessPatternsGroup
{
get
{
EnsureInitialized();
return _preprocessPatternsGroup;
}
}
internal PatternGroup ContentPatternsGroup
{
get
{
EnsureInitialized();
return _contentPatternsGroup;
}
}
}
}