mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 14:51:41 +01:00
MSBuild integration WIP
This commit is contained in:
parent
bf34494ae1
commit
6b81abb0f0
@ -4,12 +4,12 @@ using System.IO;
|
|||||||
|
|
||||||
namespace Capnpc.Csharp.MsBuild.Generation
|
namespace Capnpc.Csharp.MsBuild.Generation
|
||||||
{
|
{
|
||||||
public class FeatureCodeBehindGenerator : IDisposable
|
public class CapnpCodeBehindGenerator : IDisposable
|
||||||
{
|
{
|
||||||
//private SpecFlowProject _specFlowProject;
|
//private SpecFlowProject _specFlowProject;
|
||||||
//private ITestGenerator _testGenerator;
|
//private ITestGenerator _testGenerator;
|
||||||
|
|
||||||
public void InitializeProject(string projectPath, string rootNamespace, IEnumerable<string> generatorPlugins)
|
public void InitializeProject(string projectPath)
|
||||||
{
|
{
|
||||||
//_specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(Path.GetFullPath(projectPath), rootNamespace);
|
//_specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(Path.GetFullPath(projectPath), rootNamespace);
|
||||||
|
|
||||||
@ -21,14 +21,16 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public TestFileGeneratorResult GenerateCodeBehindFile(string featureFile)
|
public TestFileGeneratorResult GenerateCodeBehindFile(string capnpFile)
|
||||||
{
|
{
|
||||||
//var featureFileInput = new FeatureFileInput(featureFile);
|
//var featureFileInput = new FeatureFileInput(featureFile);
|
||||||
//var generatedFeatureFileName = Path.GetFileName(_testGenerator.GetTestFullPath(featureFileInput));
|
//var generatedFeatureFileName = Path.GetFileName(_testGenerator.GetTestFullPath(featureFileInput));
|
||||||
|
|
||||||
//var testGeneratorResult = _testGenerator.GenerateTestFile(featureFileInput, new GenerationSettings());
|
//var testGeneratorResult = _testGenerator.GenerateTestFile(featureFileInput, new GenerationSettings());
|
||||||
|
|
||||||
return new TestFileGeneratorResult(null, null);
|
return new TestFileGeneratorResult(
|
||||||
|
new TestGeneratorResult() { GeneratedTestCode = "//dummy" },
|
||||||
|
capnpFile + ".cs");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
@ -7,11 +7,11 @@ using Microsoft.Build.Utilities;
|
|||||||
|
|
||||||
namespace Capnpc.Csharp.MsBuild.Generation
|
namespace Capnpc.Csharp.MsBuild.Generation
|
||||||
{
|
{
|
||||||
public class FeatureFileCodeBehindGenerator : ICapnpCsharpGenerator
|
public class CapnpFileCodeBehindGenerator : ICapnpcCsharpGenerator
|
||||||
{
|
{
|
||||||
private readonly FilePathGenerator _filePathGenerator;
|
private readonly FilePathGenerator _filePathGenerator;
|
||||||
|
|
||||||
public FeatureFileCodeBehindGenerator(TaskLoggingHelper log)
|
public CapnpFileCodeBehindGenerator(TaskLoggingHelper log)
|
||||||
{
|
{
|
||||||
Log = log ?? throw new ArgumentNullException(nameof(log));
|
Log = log ?? throw new ArgumentNullException(nameof(log));
|
||||||
_filePathGenerator = new FilePathGenerator();
|
_filePathGenerator = new FilePathGenerator();
|
||||||
@ -21,27 +21,24 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
|
|
||||||
public IEnumerable<string> GenerateFilesForProject(
|
public IEnumerable<string> GenerateFilesForProject(
|
||||||
string projectPath,
|
string projectPath,
|
||||||
string rootNamespace,
|
List<string> capnpFiles,
|
||||||
List<string> CapnpFiles,
|
string projectFolder)
|
||||||
List<string> generatorPlugins,
|
|
||||||
string projectFolder,
|
|
||||||
string outputPath)
|
|
||||||
{
|
{
|
||||||
using (var featureCodeBehindGenerator = new FeatureCodeBehindGenerator())
|
using (var capnpCodeBehindGenerator = new CapnpCodeBehindGenerator())
|
||||||
{
|
{
|
||||||
featureCodeBehindGenerator.InitializeProject(projectPath, rootNamespace, generatorPlugins);
|
capnpCodeBehindGenerator.InitializeProject(projectPath);
|
||||||
|
|
||||||
var codeBehindWriter = new CodeBehindWriter(null);
|
var codeBehindWriter = new CodeBehindWriter(null);
|
||||||
|
|
||||||
if (CapnpFiles == null)
|
if (capnpFiles == null)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var featureFile in CapnpFiles)
|
foreach (var capnpFile in capnpFiles)
|
||||||
{
|
{
|
||||||
var featureFileItemSpec = featureFile;
|
var capnpFileItemSpec = capnpFile;
|
||||||
var generatorResult = featureCodeBehindGenerator.GenerateCodeBehindFile(featureFileItemSpec);
|
var generatorResult = capnpCodeBehindGenerator.GenerateCodeBehindFile(capnpFileItemSpec);
|
||||||
|
|
||||||
if (!generatorResult.Success)
|
if (!generatorResult.Success)
|
||||||
{
|
{
|
||||||
@ -63,11 +60,10 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
|
|
||||||
var targetFilePath = _filePathGenerator.GenerateFilePath(
|
var targetFilePath = _filePathGenerator.GenerateFilePath(
|
||||||
projectFolder,
|
projectFolder,
|
||||||
outputPath,
|
capnpFile,
|
||||||
featureFile,
|
|
||||||
generatorResult.Filename);
|
generatorResult.Filename);
|
||||||
|
|
||||||
var resultedFile = codeBehindWriter.WriteCodeBehindFile(targetFilePath, featureFile, generatorResult);
|
var resultedFile = codeBehindWriter.WriteCodeBehindFile(targetFilePath, capnpFile, generatorResult);
|
||||||
|
|
||||||
yield return FileSystemHelper.GetRelativePath(resultedFile, projectFolder);
|
yield return FileSystemHelper.GetRelativePath(resultedFile, projectFolder);
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
|
<TargetFrameworks>net471;netcoreapp2.1</TargetFrameworks>
|
||||||
<SignAssembly>false</SignAssembly>
|
<SignAssembly>false</SignAssembly>
|
||||||
<NuspecFile>$(MSBuildThisFileDirectory)Capnpc.Csharp.MsBuild.Generation.nuspec</NuspecFile>
|
<NuspecFile>$(MSBuildThisFileDirectory)Capnpc.Csharp.MsBuild.Generation.nuspec</NuspecFile>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
@ -68,7 +68,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="build\CPS\Buildsystem\Rules\FeatureFileType.xaml">
|
<None Update="build\CPS\Buildsystem\Rules\CapnpFileType.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</None>
|
</None>
|
||||||
<None Update="build\CPS\Buildsystem\Rules\ProjectItemsSchema.xaml">
|
<None Update="build\CPS\Buildsystem\Rules\ProjectItemsSchema.xaml">
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Capnpc.Csharp.Generation</id>
|
<id>Capnpc.Csharp.MsBuild.Generation</id>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<title>Capnpc.Csharp.MsBuild.Generation</title>
|
<title>Capnpc.Csharp.MsBuild.Generation</title>
|
||||||
<authors>Christian Köllner and contributors</authors>
|
<authors>Christian Köllner and contributors</authors>
|
||||||
@ -20,7 +20,7 @@
|
|||||||
<files>
|
<files>
|
||||||
<file src="build\**\*" target="build" />
|
<file src="build\**\*" target="build" />
|
||||||
<file src="buildMultiTargeting\**\*" target="buildMultiTargeting" />
|
<file src="buildMultiTargeting\**\*" target="buildMultiTargeting" />
|
||||||
<file src="bin\Release\netstandard2.0\*.dll" target="tasks\netstandard2.0" />
|
<file src="bin\Release\net471\*.dll" target="tasks\net471" />
|
||||||
<file src="bin\Release\netcoreapp2.1\*.dll" target="tasks\netcoreapp2.1" />
|
<file src="bin\Release\netcoreapp2.1\*.dll" target="tasks\netcoreapp2.1" />
|
||||||
<file src="bin\Release\netcoreapp2.1\*.deps.json" target="tasks\netcoreapp2.1" />
|
<file src="bin\Release\netcoreapp2.1\*.deps.json" target="tasks\netcoreapp2.1" />
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
|
|
||||||
public TaskLoggingHelper Log { get; }
|
public TaskLoggingHelper Log { get; }
|
||||||
|
|
||||||
public string WriteCodeBehindFile(string outputPath, string featureFile, TestFileGeneratorResult testFileGeneratorResult) //todo needs unit tests
|
public string WriteCodeBehindFile(string outputPath, string capnpFile, TestFileGeneratorResult testFileGeneratorResult)
|
||||||
{
|
{
|
||||||
//if (string.IsNullOrEmpty(testFileGeneratorResult.Filename))
|
//if (string.IsNullOrEmpty(testFileGeneratorResult.Filename))
|
||||||
//{
|
//{
|
||||||
@ -21,27 +21,27 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
// return null;
|
// return null;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//string directoryPath = Path.GetDirectoryName(outputPath) ?? throw new InvalidOperationException();
|
string directoryPath = Path.GetDirectoryName(outputPath) ?? throw new InvalidOperationException();
|
||||||
//Log?.LogWithNameTag(Log.LogMessage, directoryPath);
|
Log?.LogWithNameTag(Log.LogMessage, directoryPath);
|
||||||
|
|
||||||
//Log?.LogWithNameTag(Log.LogMessage, $"Writing data to {outputPath}; path = {directoryPath}; generatedFilename = {testFileGeneratorResult.Filename}");
|
Log?.LogWithNameTag(Log.LogMessage, $"Writing data to {outputPath}; path = {directoryPath}; generatedFilename = {testFileGeneratorResult.Filename}");
|
||||||
|
|
||||||
//if (File.Exists(outputPath))
|
if (File.Exists(outputPath))
|
||||||
//{
|
{
|
||||||
// if (!FileSystemHelper.FileCompareContent(outputPath, testFileGeneratorResult.GeneratedTestCode))
|
if (!FileSystemHelper.FileCompareContent(outputPath, testFileGeneratorResult.GeneratedCode))
|
||||||
// {
|
{
|
||||||
// File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedTestCode);
|
File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedCode);
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//else
|
else
|
||||||
//{
|
{
|
||||||
// if (!Directory.Exists(directoryPath))
|
if (!Directory.Exists(directoryPath))
|
||||||
// {
|
{
|
||||||
// Directory.CreateDirectory(directoryPath);
|
Directory.CreateDirectory(directoryPath);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedTestCode);
|
File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedCode);
|
||||||
//}
|
}
|
||||||
|
|
||||||
return outputPath;
|
return outputPath;
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,16 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
{
|
{
|
||||||
public class FilePathGenerator
|
public class FilePathGenerator
|
||||||
{
|
{
|
||||||
public string GenerateFilePath(string projectFolder, string relativeOutputPath, string featureFileName, string generatedCodeBehindFileName)
|
public string GenerateFilePath(string projectFolder, string capnpFileName, string generatedCodeBehindFileName)
|
||||||
{
|
{
|
||||||
if (projectFolder is null)
|
if (projectFolder is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(projectFolder));
|
throw new ArgumentNullException(nameof(projectFolder));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (featureFileName is null)
|
if (capnpFileName is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(featureFileName));
|
throw new ArgumentNullException(nameof(capnpFileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generatedCodeBehindFileName is null)
|
if (generatedCodeBehindFileName is null)
|
||||||
@ -22,7 +22,7 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
throw new ArgumentNullException(nameof(generatedCodeBehindFileName));
|
throw new ArgumentNullException(nameof(generatedCodeBehindFileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
string featureFileFullPath = Path.GetFullPath(Path.Combine(projectFolder, relativeOutputPath ?? "", featureFileName));
|
string featureFileFullPath = Path.GetFullPath(Path.Combine(projectFolder, capnpFileName));
|
||||||
string featureFileDirPath = Path.GetDirectoryName(featureFileFullPath);
|
string featureFileDirPath = Path.GetDirectoryName(featureFileFullPath);
|
||||||
|
|
||||||
return Path.Combine(featureFileDirPath, generatedCodeBehindFileName);
|
return Path.Combine(featureFileDirPath, generatedCodeBehindFileName);
|
||||||
|
@ -69,136 +69,44 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
|
|
||||||
// Open the two files.
|
// Open the two files.
|
||||||
using (FileStream fs1 = new FileStream(filePath1, FileMode.Open, FileAccess.Read))
|
using (FileStream fs1 = new FileStream(filePath1, FileMode.Open, FileAccess.Read))
|
||||||
using (FileStream fs2 = new FileStream(filePath2, FileMode.Open, FileAccess.Read))
|
|
||||||
{
|
{
|
||||||
// Check the file sizes. If they are not the same, the files
|
using (FileStream fs2 = new FileStream(filePath2, FileMode.Open, FileAccess.Read))
|
||||||
// are not the same.
|
|
||||||
if (fs1.Length != fs2.Length)
|
|
||||||
{
|
{
|
||||||
// Return false to indicate files are different
|
// Check the file sizes. If they are not the same, the files
|
||||||
return false;
|
// are not the same.
|
||||||
|
if (fs1.Length != fs2.Length)
|
||||||
|
{
|
||||||
|
// Return false to indicate files are different
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read and compare a byte from each file until either a
|
||||||
|
// non-matching set of bytes is found or until the end of
|
||||||
|
// file1 is reached.
|
||||||
|
do
|
||||||
|
{
|
||||||
|
// Read one byte from each file.
|
||||||
|
file1byte = fs1.ReadByte();
|
||||||
|
file2byte = fs2.ReadByte();
|
||||||
|
} while ((file1byte == file2byte) && (file1byte != -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read and compare a byte from each file until either a
|
|
||||||
// non-matching set of bytes is found or until the end of
|
|
||||||
// file1 is reached.
|
|
||||||
do
|
|
||||||
{
|
|
||||||
// Read one byte from each file.
|
|
||||||
file1byte = fs1.ReadByte();
|
|
||||||
file2byte = fs2.ReadByte();
|
|
||||||
} while ((file1byte == file2byte) && (file1byte != -1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the success of the comparison. "file1byte" is
|
// Return the success of the comparison. "file1byte" is
|
||||||
// equal to "file2byte" at this point only if the files are
|
// equal to "file2byte" at this point only if the files are
|
||||||
// the same.
|
// the same.
|
||||||
return ((file1byte - file2byte) == 0);
|
return ((file1byte - file2byte) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CopyDirectory(string sourcePath, string destPath, bool cleanDestination = true)
|
// This method accepts two strings the represent two files to
|
||||||
|
// compare. A return value of true indicates that the contents of the files
|
||||||
|
// are the same. A return value of any other value indicates that the
|
||||||
|
// files are not the same.
|
||||||
|
public static bool FileCompareContent(string filePath1, string fileContent)
|
||||||
{
|
{
|
||||||
if (cleanDestination)
|
var currentFileContent = File.ReadAllText(filePath1);
|
||||||
EnsureEmptyFolder(destPath);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(destPath))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(destPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string file in Directory.GetFiles(sourcePath))
|
return string.CompareOrdinal(currentFileContent, fileContent) == 0;
|
||||||
{
|
|
||||||
var fileName = Path.GetFileName(file);
|
|
||||||
Debug.Assert(fileName != null);
|
|
||||||
string dest = Path.Combine(destPath, fileName);
|
|
||||||
File.Copy(file, dest, true);
|
|
||||||
File.SetAttributes(dest, File.GetAttributes(dest) & (~FileAttributes.ReadOnly));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string folder in Directory.GetDirectories(sourcePath))
|
|
||||||
{
|
|
||||||
var folderName = Path.GetFileName(folder);
|
|
||||||
Debug.Assert(folderName != null);
|
|
||||||
string dest = Path.Combine(destPath, folderName);
|
|
||||||
CopyDirectory(folder, dest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void EnsureEmptyFolder(string folderName)
|
|
||||||
{
|
|
||||||
folderName = Path.GetFullPath(folderName);
|
|
||||||
|
|
||||||
if (!Directory.Exists(folderName))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(folderName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeleteFolderContent(folderName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void EnsureFolderOfFile(string filePath)
|
|
||||||
{
|
|
||||||
string directory = Path.GetDirectoryName(filePath);
|
|
||||||
if (directory != null && !Directory.Exists(directory))
|
|
||||||
Directory.CreateDirectory(directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static void Retry(int number, Action action)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
action();
|
|
||||||
}
|
|
||||||
catch (UnauthorizedAccessException)
|
|
||||||
{
|
|
||||||
var i = number - 1;
|
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
throw;
|
|
||||||
|
|
||||||
Retry(i, action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void DeleteFolderContent(string folderName)
|
|
||||||
{
|
|
||||||
foreach (string file in Directory.GetFiles(folderName))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Retry(5, () => File.Delete(file));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception("Unable to delete file: " + file, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string folder in Directory.GetDirectories(folderName))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Retry(5, () => Directory.Delete(folder, true));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception("Unable to delete folder: " + folder, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void DeleteFolder(string path)
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(path))
|
|
||||||
return;
|
|
||||||
|
|
||||||
DeleteFolderContent(path);
|
|
||||||
|
|
||||||
Retry(5, () => Directory.Delete(path, true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,23 +13,18 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
{
|
{
|
||||||
public GenerateCapnpFileCodeBehindTask()
|
public GenerateCapnpFileCodeBehindTask()
|
||||||
{
|
{
|
||||||
CodeBehindGenerator = new FeatureFileCodeBehindGenerator(Log);
|
CodeBehindGenerator = new CapnpFileCodeBehindGenerator(Log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICapnpCsharpGenerator CodeBehindGenerator { get; set; }
|
public ICapnpcCsharpGenerator CodeBehindGenerator { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string ProjectPath { get; set; }
|
public string ProjectPath { get; set; }
|
||||||
|
|
||||||
public string RootNamespace { get; set; }
|
|
||||||
|
|
||||||
public string ProjectFolder => Path.GetDirectoryName(ProjectPath);
|
public string ProjectFolder => Path.GetDirectoryName(ProjectPath);
|
||||||
public string OutputPath { get; set; }
|
|
||||||
|
|
||||||
public ITaskItem[] CapnpFiles { get; set; }
|
public ITaskItem[] CapnpFiles { get; set; }
|
||||||
|
|
||||||
public ITaskItem[] GeneratorPlugins { get; set; }
|
|
||||||
|
|
||||||
[Output]
|
[Output]
|
||||||
public ITaskItem[] GeneratedFiles { get; private set; }
|
public ITaskItem[] GeneratedFiles { get; private set; }
|
||||||
|
|
||||||
@ -55,21 +50,16 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
|
|
||||||
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
||||||
|
|
||||||
var generator = CodeBehindGenerator ?? new FeatureFileCodeBehindGenerator(Log);
|
var generator = CodeBehindGenerator ?? new CapnpFileCodeBehindGenerator(Log);
|
||||||
|
|
||||||
Log.LogWithNameTag(Log.LogMessage, "Starting GenerateFeatureFileCodeBehind");
|
Log.LogWithNameTag(Log.LogMessage, "Starting GenerateFeatureFileCodeBehind");
|
||||||
|
|
||||||
var generatorPlugins = GeneratorPlugins?.Select(gp => gp.ItemSpec).ToList() ?? new List<string>();
|
|
||||||
|
|
||||||
var capnpFiles = CapnpFiles?.Select(i => i.ItemSpec).ToList() ?? new List<string>();
|
var capnpFiles = CapnpFiles?.Select(i => i.ItemSpec).ToList() ?? new List<string>();
|
||||||
|
|
||||||
var generatedFiles = generator.GenerateFilesForProject(
|
var generatedFiles = generator.GenerateFilesForProject(
|
||||||
ProjectPath,
|
ProjectPath,
|
||||||
RootNamespace,
|
|
||||||
capnpFiles,
|
capnpFiles,
|
||||||
generatorPlugins,
|
ProjectFolder);
|
||||||
ProjectFolder,
|
|
||||||
OutputPath);
|
|
||||||
|
|
||||||
GeneratedFiles = generatedFiles.Select(file => new TaskItem { ItemSpec = file }).ToArray();
|
GeneratedFiles = generatedFiles.Select(file => new TaskItem { ItemSpec = file }).ToArray();
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace Capnpc.Csharp.MsBuild.Generation
|
namespace Capnpc.Csharp.MsBuild.Generation
|
||||||
{
|
{
|
||||||
public interface ICapnpCsharpGenerator
|
public interface ICapnpcCsharpGenerator
|
||||||
{
|
{
|
||||||
IEnumerable<string> GenerateFilesForProject(string projectPath, string rootNamespace, List<string> CapnpFiles, List<string> generatorPlugins, string projectFolder, string outputPath);
|
IEnumerable<string> GenerateFilesForProject(string projectPath, List<string> capnpFiles, string projectFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
|
|
||||||
Errors = generatorResult.Errors;
|
Errors = generatorResult.Errors;
|
||||||
IsUpToDate = generatorResult.IsUpToDate;
|
IsUpToDate = generatorResult.IsUpToDate;
|
||||||
GeneratedTestCode = generatorResult.GeneratedTestCode;
|
GeneratedCode = generatorResult.GeneratedTestCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -31,9 +31,9 @@ namespace Capnpc.Csharp.MsBuild.Generation
|
|||||||
public bool IsUpToDate { get; }
|
public bool IsUpToDate { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The generated test code.
|
/// The generated code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GeneratedTestCode { get; }
|
public string GeneratedCode { get; }
|
||||||
|
|
||||||
public bool Success => Errors == null || !Errors.Any();
|
public bool Success => Errors == null || !Errors.Any();
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PropertyPageSchema Include="$(CpsExtensionSchemaDirectory)\ProjectItemsSchema.xaml;"/>
|
<PropertyPageSchema Include="$(CpsExtensionSchemaDirectory)\ProjectItemsSchema.xaml;"/>
|
||||||
|
|
||||||
<PropertyPageSchema Include="$(CpsExtensionSchemaDirectory)\FeatureFileType.xaml;">
|
<PropertyPageSchema Include="$(CpsExtensionSchemaDirectory)\CapnpFileType.xaml;">
|
||||||
<Context>File;BrowseObject</Context>
|
<Context>File;BrowseObject</Context>
|
||||||
</PropertyPageSchema>
|
</PropertyPageSchema>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
<!--Copyright, Microsoft Corporation, All rights reserved.-->
|
<!--Copyright, Microsoft Corporation, All rights reserved.-->
|
||||||
|
|
||||||
<Rule
|
<Rule
|
||||||
Name="Feature"
|
Name="Capnp"
|
||||||
DisplayName="Feature"
|
DisplayName="Cap'n Proto"
|
||||||
PageTemplate="tool"
|
PageTemplate="tool"
|
||||||
Description="SpecFlow Feature file"
|
Description="Cap'n Proto schema file"
|
||||||
xmlns="http://schemas.microsoft.com/build/2009/properties">
|
xmlns="http://schemas.microsoft.com/build/2009/properties">
|
||||||
|
|
||||||
<Rule.DataSource>
|
<Rule.DataSource>
|
@ -4,15 +4,15 @@
|
|||||||
xmlns="http://schemas.microsoft.com/build/2009/properties">
|
xmlns="http://schemas.microsoft.com/build/2009/properties">
|
||||||
|
|
||||||
<ContentType
|
<ContentType
|
||||||
Name="FeatureFile"
|
Name="CapnpFile"
|
||||||
DisplayName="FeatureFileType source file"
|
DisplayName="CapnpFileType source file"
|
||||||
ItemType="CapnpFiles">
|
ItemType="CapnpFiles">
|
||||||
<NameValuePair Name="DependentExtensions" Value=".feature.cs" />
|
<NameValuePair Name="DependentExtensions" Value=".capnp.cs" />
|
||||||
|
|
||||||
</ContentType>
|
</ContentType>
|
||||||
|
|
||||||
<ItemType Name="CapnpFiles" DisplayName="Feature file"/>
|
<ItemType Name="CapnpFiles" DisplayName="Cap'n Proto schema file"/>
|
||||||
|
|
||||||
<FileExtension Name=".feature" ContentType="FeatureFile" />
|
<FileExtension Name=".capnp" ContentType="CapnpFile" />
|
||||||
|
|
||||||
</ProjectSchemaDefinitions>
|
</ProjectSchemaDefinitions>
|
||||||
|
|
@ -21,7 +21,7 @@
|
|||||||
<VerboseOutput Condition="'$(VerboseOutput)'==''">true</VerboseOutput>
|
<VerboseOutput Condition="'$(VerboseOutput)'==''">true</VerboseOutput>
|
||||||
<CapnpcCsharp_DebugMSBuildTask Condition="'$(CapnpcCsharp_DebugMSBuildTask)' == ''">false</CapnpcCsharp_DebugMSBuildTask>
|
<CapnpcCsharp_DebugMSBuildTask Condition="'$(CapnpcCsharp_DebugMSBuildTask)' == ''">false</CapnpcCsharp_DebugMSBuildTask>
|
||||||
|
|
||||||
<_SpecFlowPropsImported Condition="'$(_SpecFlowPropsImported)'==''">true</_SpecFlowPropsImported>
|
<_CapnpcCsharpPropsImported Condition="'$(_CapnpcCsharpPropsImported)'==''">true</_CapnpcCsharpPropsImported>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@ -38,14 +38,14 @@
|
|||||||
net.sdk support: feature flag to enable experimental support for net.sdk project system
|
net.sdk support: feature flag to enable experimental support for net.sdk project system
|
||||||
-->
|
-->
|
||||||
<CapnpcCsharp_EnableDefaultCompileItems Condition="'$(CapnpcCsharp_EnableDefaultCompileItems)'==''">true</CapnpcCsharp_EnableDefaultCompileItems>
|
<CapnpcCsharp_EnableDefaultCompileItems Condition="'$(CapnpcCsharp_EnableDefaultCompileItems)'==''">true</CapnpcCsharp_EnableDefaultCompileItems>
|
||||||
<CapnpcCsharp_EnableWarnForFeatureCodeBehindFilesWithoutCorrespondingFeatureFile Condition="'$(CapnpcCsharp_EnableWarnForFeatureCodeBehindFilesWithoutCorrespondingFeatureFile)'==''">$(CapnpcCsharp_EnableDefaultCompileItems)</CapnpcCsharp_EnableWarnForFeatureCodeBehindFilesWithoutCorrespondingFeatureFile>
|
<CapnpcCsharp_EnableWarnForFeatureCodeBehindFilesWithoutCorrespondingCapnpFile Condition="'$(CapnpcCsharp_EnableWarnForFeatureCodeBehindFilesWithoutCorrespondingCapnpFile)'==''">$(CapnpcCsharp_EnableDefaultCompileItems)</CapnpcCsharp_EnableWarnForFeatureCodeBehindFilesWithoutCorrespondingCapnpFile>
|
||||||
|
|
||||||
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.feature</DefaultItemExcludes>
|
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.capnp</DefaultItemExcludes>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CapnpFiles Include="**\*.capnp" >
|
<CapnpFiles Include="**\*.capnp" >
|
||||||
<CodeBehindFile>%(RelativeDir)%(Filename).capnp(DefaultLanguageSourceExtension)</CodeBehindFile>
|
<CodeBehindFile>%(RelativeDir)%(Filename).capnp.cs</CodeBehindFile>
|
||||||
<Visible>$(UsingMicrosoftNETSdk)</Visible>
|
<Visible>$(UsingMicrosoftNETSdk)</Visible>
|
||||||
</CapnpFiles>
|
</CapnpFiles>
|
||||||
|
|
||||||
@ -54,7 +54,7 @@
|
|||||||
- after deletion of a feature file
|
- after deletion of a feature file
|
||||||
- after pulling latest changes from version control with above changes
|
- after pulling latest changes from version control with above changes
|
||||||
-->
|
-->
|
||||||
<SpecFlowObsoleteCodeBehindFiles Include="**\*.capnp(DefaultLanguageSourceExtension)" Exclude="@(CapnpFiles->'%(CodeBehindFile)')" />
|
<SpecFlowObsoleteCodeBehindFiles Include="**\*.capnp.cs" Exclude="@(CapnpFiles->'%(CodeBehindFile)')" />
|
||||||
|
|
||||||
<!-- Support for Visual Studio Incremental Build
|
<!-- Support for Visual Studio Incremental Build
|
||||||
https://github.com/techtalk/SpecFlow/issues/1319
|
https://github.com/techtalk/SpecFlow/issues/1319
|
||||||
@ -67,7 +67,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">netcoreapp2.0</_CapnpcCsharp_TaskFolder>
|
<_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">netcoreapp2.1</_CapnpcCsharp_TaskFolder>
|
||||||
<_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">net471</_CapnpcCsharp_TaskFolder>
|
<_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">net471</_CapnpcCsharp_TaskFolder>
|
||||||
<_CapnpcCsharp_TaskAssembly Condition=" '$(_CapnpcCsharp_TaskAssembly)' == '' ">..\tasks\$(_CapnpcCsharp_TaskFolder)\Capnpc.Csharp.MsBuild.Generation.dll</_CapnpcCsharp_TaskAssembly>
|
<_CapnpcCsharp_TaskAssembly Condition=" '$(_CapnpcCsharp_TaskAssembly)' == '' ">..\tasks\$(_CapnpcCsharp_TaskFolder)\Capnpc.Csharp.MsBuild.Generation.dll</_CapnpcCsharp_TaskAssembly>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<Project>
|
<Project>
|
||||||
|
|
||||||
<Import Project="Capnpc.Csharp.MsBuild.Generation.props" Condition="'$(_SpecFlowPropsImported)'==''"/>
|
<Import Project="Capnpc.Csharp.MsBuild.Generation.props" Condition="'$(_CapnpcCsharpPropsImported)'==''"/>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(BuildServerMode)' == ''">
|
<PropertyGroup Condition="'$(BuildServerMode)' == ''">
|
||||||
<BuildServerMode Condition="'$(BuildingInsideVisualStudio)'=='true'">false</BuildServerMode>
|
<BuildServerMode Condition="'$(BuildingInsideVisualStudio)'=='true'">false</BuildServerMode>
|
||||||
@ -49,8 +49,8 @@
|
|||||||
|
|
||||||
|
|
||||||
<Target Name="WarnForFeatureCodeBehindFilesWithoutCorrespondingFeatureFile" AfterTargets="CoreCompile"
|
<Target Name="WarnForFeatureCodeBehindFilesWithoutCorrespondingFeatureFile" AfterTargets="CoreCompile"
|
||||||
Condition="'$(CapnpcCsharp_EnableWarnForFeatureCodeBehindFilesWithoutCorrespondingFeatureFile)' == 'true'">
|
Condition="'$(CapnpcCsharp_EnableWarnForFeatureCodeBehindFilesWithoutCorrespondingCapnpFile)' == 'true'">
|
||||||
<Warning Text="For codebehind file '@(SpecFlowObsoleteCodeBehindFiles)', no feature file was found." File="@(SpecFlowObsoleteCodeBehindFiles)" Condition="'@(SpecFlowObsoleteCodeBehindFiles)' != ''" />
|
<Warning Text="For codebehind file '@(SpecFlowObsoleteCodeBehindFiles)', no capnp file was found." File="@(SpecFlowObsoleteCodeBehindFiles)" Condition="'@(SpecFlowObsoleteCodeBehindFiles)' != ''" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
|
|
||||||
@ -66,26 +66,14 @@
|
|||||||
|
|
||||||
<Message Text="CapnpFiles: @(CapnpFiles)" Importance="high" Condition="'$(VerboseOutput)' == 'true'" />
|
<Message Text="CapnpFiles: @(CapnpFiles)" Importance="high" Condition="'$(VerboseOutput)' == 'true'" />
|
||||||
|
|
||||||
<Error
|
<GenerateCapnpFileCodeBehindTask
|
||||||
Text="CapnpCsharp codebehind generation is not compatible with MSBuild codebehind generation. The custom tool must be removed from the file."
|
|
||||||
File="@(None)"
|
|
||||||
Condition="%(None.Extension) == '.feature' AND %(None.Generator) == 'SpecFlowSingleFileGenerator'"/>
|
|
||||||
|
|
||||||
<!-- <PropertyGroup>
|
|
||||||
<SpecFlowCodeBehindOutputPath Condition="'$(SpecFlowCodeBehindOutputPath)' == ''">Features.Generated</SpecFlowCodeBehindOutputPath>
|
|
||||||
</PropertyGroup> -->
|
|
||||||
|
|
||||||
<GenerateFeatureFileCodeBehindTask
|
|
||||||
ProjectPath="$(MSBuildProjectFullPath)"
|
ProjectPath="$(MSBuildProjectFullPath)"
|
||||||
OutputPath="$(SpecFlowCodeBehindOutputPath)"
|
CapnpFiles="@(CapnpFiles)" >
|
||||||
CapnpFiles="@(CapnpFiles)"
|
|
||||||
RootNamespace="$(RootNamespace)"
|
|
||||||
GeneratorPlugins="@(SpecFlowGeneratorPlugins)" >
|
|
||||||
|
|
||||||
<Output TaskParameter="GeneratedFiles" ItemName="CapnpCsharpGeneratedFiles" />
|
<Output TaskParameter="GeneratedFiles" ItemName="CapnpcCsharpGeneratedFiles" />
|
||||||
</GenerateFeatureFileCodeBehindTask>
|
</GenerateCapnpFileCodeBehindTask>
|
||||||
|
|
||||||
<Message Text="CapnpCsharpGeneratedFiles: %(CapnpCsharpGeneratedFiles.Identity)" Importance="high" Condition="'$(VerboseOutput)' == 'true'" />
|
<Message Text="CapnpcCsharpGeneratedFiles: %(CapnpcCsharpGeneratedFiles.Identity)" Importance="high" Condition="'$(VerboseOutput)' == 'true'" />
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@ -123,7 +111,7 @@
|
|||||||
|
|
||||||
<Target Name="IncludeCodeBehindFilesInProject" DependsOnTargets="UpdateCapnpFilesInProject">
|
<Target Name="IncludeCodeBehindFilesInProject" DependsOnTargets="UpdateCapnpFilesInProject">
|
||||||
<ItemGroup Condition="'$(UsingMicrosoftNETSdk)' != 'true'">
|
<ItemGroup Condition="'$(UsingMicrosoftNETSdk)' != 'true'">
|
||||||
<Compile Include="@(CapnpCsharpGeneratedFiles)" Exclude="@(Compile)" />
|
<Compile Include="@(CapnpcCsharpGeneratedFiles)" Exclude="@(Compile)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
@ -132,12 +120,12 @@
|
|||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="CleanCapnpFilesInProject" Condition="'$(CapnpcCsharp_DeleteCodeBehindFilesOnCleanRebuild)' == 'true'">
|
<Target Name="CleanCapnpFilesInProject" Condition="'$(CapnpcCsharp_DeleteCodeBehindFilesOnCleanRebuild)' == 'true'">
|
||||||
<!-- remove known codebehind files for existing feature files -->
|
<!-- remove known codebehind files for existing capnp files -->
|
||||||
<Delete Files="%(CapnpFiles.CodeBehindFile)" ContinueOnError="true" />
|
<Delete Files="%(CapnpFiles.CodeBehindFile)" ContinueOnError="true" />
|
||||||
|
|
||||||
<!-- remove obsolete codebehind files, scenarios:
|
<!-- remove obsolete codebehind files, scenarios:
|
||||||
- after rename operation
|
- after rename operation
|
||||||
- after deletion of a feature file
|
- after deletion of a capnp file
|
||||||
- after pulling latest changes from version control with above changes
|
- after pulling latest changes from version control with above changes
|
||||||
-->
|
-->
|
||||||
<Delete Files="@(SpecFlowObsoleteCodeBehindFiles)" ContinueOnError="true" />
|
<Delete Files="@(SpecFlowObsoleteCodeBehindFiles)" ContinueOnError="true" />
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<UsingTask TaskName="Capnpc.Csharp.MsBuild.Generation.GenerateFeatureFileCodeBehindTask" AssemblyFile="$(_CapnpcCsharp_TaskAssembly)" />
|
<UsingTask TaskName="Capnpc.Csharp.MsBuild.Generation.GenerateCapnpFileCodeBehindTask" AssemblyFile="$(_CapnpcCsharp_TaskAssembly)" />
|
||||||
</Project>
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user