- Bugfix: Trigger on new project.json file structure

- Bugfix: Trigger on folder deletion
- Add test for folder deletion
This commit is contained in:
Victor Hurdugaci 2016-05-25 15:15:28 -07:00
parent 526f22f072
commit 2cf772b575
5 changed files with 85 additions and 15 deletions

View File

@ -0,0 +1,25 @@
// 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 Microsoft.DotNet.ProjectModel.Files;
namespace Microsoft.DotNet.Watcher.Core
{
internal static class IncludeContextExtensions
{
public static IEnumerable<string> ResolveFiles(this IncludeContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return IncludeFilesResolver
.GetIncludeFiles(context, "/", diagnostics: null)
.Select(f => f.SourcePath);
}
}
}

View File

@ -1,9 +1,11 @@
// 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.IO;
using System.Linq;
using Microsoft.DotNet.ProjectModel.Files;
using Microsoft.DotNet.ProjectModel.Graph;
namespace Microsoft.DotNet.Watcher.Core.Internal
@ -15,15 +17,34 @@ namespace Microsoft.DotNet.Watcher.Core.Internal
ProjectFile = runtimeProject.ProjectFilePath;
ProjectDirectory = runtimeProject.ProjectDirectory;
Files = runtimeProject.Files.SourceFiles.Concat(
runtimeProject.Files.ResourceFiles.Values.Concat(
runtimeProject.Files.PreprocessSourceFiles.Concat(
runtimeProject.Files.SharedFiles))).Concat(
new string[] { runtimeProject.ProjectFilePath })
.ToList();
var compilerOptions = runtimeProject.GetCompilerOptions(targetFramework: null, configurationName: null);
var filesToWatch = new List<string>() { runtimeProject.ProjectFilePath };
if (compilerOptions?.CompileInclude != null)
{
filesToWatch.AddRange(compilerOptions.CompileInclude.ResolveFiles());
}
else
{
filesToWatch.AddRange(runtimeProject.Files.SourceFiles);
}
if (compilerOptions?.EmbedInclude != null)
{
filesToWatch.AddRange(compilerOptions.EmbedInclude.ResolveFiles());
}
else
{
filesToWatch.AddRange(runtimeProject.Files.ResourceFiles.Values);
}
filesToWatch.AddRange(runtimeProject.Files.SharedFiles);
filesToWatch.AddRange(runtimeProject.Files.PreprocessSourceFiles);
Files = filesToWatch;
var projectLockJsonPath = Path.Combine(runtimeProject.ProjectDirectory, "project.lock.json");
if (File.Exists(projectLockJsonPath))
{
var lockFile = LockFileReader.Read(projectLockJsonPath, designTime: false);

View File

@ -107,6 +107,10 @@ namespace Microsoft.DotNet.Watcher.Core.Internal
foreach (var file in project.Files)
{
closure.Add(file);
// We need to add the folder because folder deletions only trigger
// for the folder, not for the files inside it
closure.Add(Path.GetDirectoryName(file));
}
foreach (var dependency in project.ProjectDependencies)

View File

@ -85,6 +85,24 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
}
}
// Delete an entire folder
[Fact]
public void DeleteSourceFolder()
{
using (var scenario = new GlobbingAppScenario())
using (var wait = new WaitForFileToChange(scenario.StartedFile))
{
scenario.Start();
var folderToDelete = Path.Combine(scenario.TestAppFolder, "include");
Directory.Delete(folderToDelete, recursive: true);
wait.Wait(_defaultTimeout,
expectedToChange: true,
errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
}
}
// Rename a file included in compilation
[Fact]
public void RenameCompiledFile()

View File

@ -1,15 +1,17 @@
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
"emitEntryPoint": true,
"compile": {
"include": [
"Program.cs",
"include/*.cs"
],
"exclude": [
"exclude/*"
]
}
},
"compile": [
"Program.cs",
"include/*.cs"
],
"exclude": [
"exclude/*"
],
"frameworks": {
"netcoreapp1.0": {
"dependencies": {