Skip to content

Commit c644b45

Browse files
committed
Merge branch 'hotfix/0.10.4'
2 parents cc3c61a + 08a6d40 commit c644b45

4 files changed

Lines changed: 371 additions & 107 deletions

File tree

src/nbuildkit/actions/shared.prepare.npm.restore.msbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
</Target>
2323

2424
<Target
25+
Condition=" '$(ToolsExternalNodeJsPath)' == 'UNDEFINED' OR '$(ToolsExternalNpmPath)' == 'UNDEFINED' "
2526
Name="_nBuildKit_Shared_Prepare_Npm_Restore_GetToolPaths">
2627
<NuGetInstall
2728
Condition=" '$(ToolsExternalNodeJsPath)' == 'UNDEFINED' "

src/nbuildkit/tasks/Test.Unit.MsBuild.Tasks.Core/FileSystem/PathUtilitiesTest.cs

Lines changed: 184 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,95 @@ public void IncludedPathsWithAbsolutePaths()
197197
}));
198198
}
199199

200+
[Test]
201+
public void IncludedPathsWithAbsolutePathsAndUnnecessaryWhiteSpace()
202+
{
203+
var directory = CreateTempDirectory();
204+
var file1 = Path.Combine(directory, "temp", "file.txt");
205+
CreateTempFile(file1);
206+
207+
var file2 = Path.Combine(directory, "other path", "temp", "file.txt");
208+
CreateTempFile(file2);
209+
210+
var file3 = Path.Combine(directory, "file.txt");
211+
CreateTempFile(file3);
212+
213+
Assert.That(
214+
PathUtilities.IncludedPaths(file3 + " ", directory),
215+
Is.EquivalentTo(
216+
new[]
217+
{
218+
file3
219+
}));
220+
Assert.That(
221+
PathUtilities.IncludedPaths(" " + file1, directory),
222+
Is.EquivalentTo(
223+
new[]
224+
{
225+
file1
226+
}));
227+
Assert.That(
228+
PathUtilities.IncludedPaths(
229+
string.Format(
230+
CultureInfo.InvariantCulture,
231+
" {0}\\temp\\*.txt ",
232+
directory),
233+
directory),
234+
Is.EquivalentTo(
235+
new[]
236+
{
237+
file1,
238+
}));
239+
Assert.That(
240+
PathUtilities.IncludedPaths(
241+
string.Format(
242+
CultureInfo.InvariantCulture,
243+
" {0}\\**\\*.txt ",
244+
directory),
245+
directory),
246+
Is.EquivalentTo(
247+
new[]
248+
{
249+
file1,
250+
file2,
251+
file3,
252+
}));
253+
Assert.That(
254+
PathUtilities.IncludedPaths(
255+
string.Format(
256+
CultureInfo.InvariantCulture,
257+
" {0}\\other*\\**\\*.txt ",
258+
directory),
259+
directory),
260+
Is.EquivalentTo(
261+
new[]
262+
{
263+
file2
264+
}));
265+
Assert.That(
266+
PathUtilities.IncludedPaths(
267+
string.Format(
268+
CultureInfo.InvariantCulture,
269+
" {0}\\other\\**\\*.txt ",
270+
directory),
271+
directory),
272+
Is.EquivalentTo(
273+
new string[0]));
274+
Assert.That(
275+
PathUtilities.IncludedPaths(
276+
string.Format(
277+
CultureInfo.InvariantCulture,
278+
" {0}\\**\\temp\\*.txt ",
279+
directory),
280+
directory),
281+
Is.EquivalentTo(
282+
new[]
283+
{
284+
file1,
285+
file2
286+
}));
287+
}
288+
200289
[Test]
201290
public void IncludedPathsWithExclusionsAndAbsolutePaths()
202291
{
@@ -292,6 +381,101 @@ public void IncludedPathsWithExclusionsAndAbsolutePaths()
292381
}));
293382
}
294383

384+
[Test]
385+
public void IncludedPathsWithExclusionsAndAbsolutePathsAndUnnecessaryWhiteSpace()
386+
{
387+
var directory = CreateTempDirectory();
388+
var file1 = Path.Combine(directory, "temp", "file.txt");
389+
CreateTempFile(file1);
390+
391+
var file2 = Path.Combine(directory, "temp", "other.txt");
392+
CreateTempFile(file2);
393+
394+
var file3 = Path.Combine(directory, "other path", "temp", "file.txt");
395+
CreateTempFile(file3);
396+
397+
var file4 = Path.Combine(directory, "other", "temp", "other.txt");
398+
CreateTempFile(file4);
399+
400+
Assert.That(
401+
PathUtilities.IncludedPaths(
402+
string.Format(
403+
CultureInfo.InvariantCulture,
404+
@" {0}\**\*.txt ",
405+
directory),
406+
Enumerable.Empty<string>(),
407+
directory),
408+
Is.EquivalentTo(
409+
new[]
410+
{
411+
file1,
412+
file2,
413+
file3,
414+
file4,
415+
}));
416+
Assert.That(
417+
PathUtilities.IncludedPaths(
418+
string.Format(
419+
CultureInfo.InvariantCulture,
420+
@"{0}\**\*.txt ",
421+
directory),
422+
new[]
423+
{
424+
string.Format(
425+
CultureInfo.InvariantCulture,
426+
@" {0}\other*\**\*.* ",
427+
directory)
428+
},
429+
directory),
430+
Is.EquivalentTo(
431+
new[]
432+
{
433+
file1,
434+
file2,
435+
}));
436+
Assert.That(
437+
PathUtilities.IncludedPaths(
438+
string.Format(
439+
CultureInfo.InvariantCulture,
440+
@" {0}\**\*.txt",
441+
directory),
442+
new[]
443+
{
444+
string.Format(
445+
CultureInfo.InvariantCulture,
446+
@"{0}\temp\other.* ",
447+
directory)
448+
},
449+
directory),
450+
Is.EquivalentTo(
451+
new[]
452+
{
453+
file1,
454+
file3,
455+
file4,
456+
}));
457+
Assert.That(
458+
PathUtilities.IncludedPaths(
459+
string.Format(
460+
CultureInfo.InvariantCulture,
461+
@"{0}\**\*.txt ",
462+
directory),
463+
new[]
464+
{
465+
string.Format(
466+
CultureInfo.InvariantCulture,
467+
@" {0}\**\other.*",
468+
directory)
469+
},
470+
directory),
471+
Is.EquivalentTo(
472+
new[]
473+
{
474+
file1,
475+
file3
476+
}));
477+
}
478+
295479
[Test]
296480
public void IncludedPathsWithExclusionsAndRelativePaths()
297481
{
@@ -375,7 +559,6 @@ public void IncludedPathsWithExclusionsAndRelativePaths()
375559
}));
376560
}
377561

378-
// [Ignore("Ignoring files without directories doesn't work yet.")]
379562
[Test]
380563
public void IncludedPathsWithFileExclusions()
381564
{
@@ -392,7 +575,6 @@ public void IncludedPathsWithFileExclusions()
392575
var file4 = Path.Combine(directory, "other", "temp", "other.txt");
393576
CreateTempFile(file4);
394577

395-
// This doesn't work yet
396578
Assert.That(
397579
PathUtilities.IncludedPaths(
398580
@"**\*.txt",

src/nbuildkit/tasks/nBuildKit.MsBuild.Tasks.Core/FileSystem/PathUtilities.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,29 +256,32 @@ public static IEnumerable<string> IncludedPaths(string pathExpression, IEnumerab
256256
excludedPathExpressions.Select(
257257
e =>
258258
{
259-
return Path.IsPathRooted(e) ? GetFilePathRelativeToDirectory(e, baseDirectory) : e;
259+
var path = e.Trim();
260+
return Path.IsPathRooted(path) ? GetFilePathRelativeToDirectory(path, baseDirectory) : path;
260261
}));
261262
}
262263

263-
var relativeExpression = pathExpression;
264-
if (Path.IsPathRooted(pathExpression))
264+
var localBaseDirectory = baseDirectory.Trim();
265+
var localPathExpression = pathExpression.Trim();
266+
var relativeExpression = localPathExpression;
267+
if (Path.IsPathRooted(localPathExpression))
265268
{
266269
// If the path has a root drive then we assume the user gave us a full path. The matcher doesn't seem
267270
// to handle full paths very well so now we need to create a 'relative expression'.
268271
//
269272
// First grab the longest part of the expression that doesn't have any '*' characters in it
270-
var baseExpression = BaseDirectory(pathExpression);
273+
var baseExpression = BaseDirectory(localPathExpression);
271274

272275
// Get the left overs of the expression with all the wild cards etc.
273-
var remainder = pathExpression.Substring(baseExpression.Length).TrimStart('\\');
276+
var remainder = localPathExpression.Substring(baseExpression.Length).TrimStart('\\');
274277

275278
// Get the relative directory
276-
var relativeDirectory = GetDirectoryPathRelativeToDirectory(baseExpression, baseDirectory);
279+
var relativeDirectory = GetDirectoryPathRelativeToDirectory(baseExpression, localBaseDirectory);
277280
relativeExpression = Path.Combine(relativeDirectory, remainder).TrimStart('\\');
278281
}
279282

280283
matcher.AddInclude(relativeExpression);
281-
return matcher.GetResultsInFullPath(baseDirectory);
284+
return matcher.GetResultsInFullPath(localBaseDirectory);
282285
}
283286
}
284287
}

0 commit comments

Comments
 (0)