Skip to content

Commit

Permalink
chore: auto reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Ernst committed Dec 12, 2024
1 parent 8c6b45a commit f54ec9f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 47 deletions.
14 changes: 7 additions & 7 deletions Mono.TextTemplating.Build.Tests/MSBuildExecutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void TransformOnBuild ()

var instance = project.Build ("Build");

var generatedFilePath = project.DirectoryPath["foo.txt"].AssertTextStartsWith("Hello 2019!");
var generatedFilePath = project.DirectoryPath["foo.txt"].AssertTextStartsWith ("Hello 2019!");

instance.AssertSingleItem ("GeneratedTemplates", withFullPath: generatedFilePath);
instance.AssertNoItems ("PreprocessedTemplates");
Expand Down Expand Up @@ -120,13 +120,13 @@ public void IncrementalTransform ()

project.Restore ();

var fooGenerated = project.DirectoryPath ["foo.txt"];
var fooTemplate = project.DirectoryPath ["foo.tt"];
var barGenerated = project.DirectoryPath ["bar.txt"];
var barTemplate = project.DirectoryPath ["bar.tt"];
var includeFile = project.DirectoryPath ["helper.ttinclude"];
var fooGenerated = project.DirectoryPath["foo.txt"];
var fooTemplate = project.DirectoryPath["foo.tt"];
var barGenerated = project.DirectoryPath["bar.txt"];
var barTemplate = project.DirectoryPath["bar.tt"];
var includeFile = project.DirectoryPath["helper.ttinclude"];

void ExecuteAndValidate()
void ExecuteAndValidate ()
{
var instance = project.Build ("TransformTemplates");

Expand Down
32 changes: 16 additions & 16 deletions Mono.TextTemplating.Build/TemplateBuildState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class TemplateBuildState
public List<TransformTemplate> TransformTemplates { get; set; }
[Key (9)]
public List<Parameter> Parameters { get; set; }
[Key(10)]
[Key (10)]
public string PreprocessTargetRuntimeIdentifier { get; set; }

internal (List<TransformTemplate> transforms, List<PreprocessedTemplate> preprocessed) GetStaleAndNewTemplates (
Expand Down Expand Up @@ -70,7 +70,7 @@ public class TemplateBuildState
// if it's up to date, use the values from the previous run
t.Dependencies = pt.Dependencies;
t.OutputFile = pt.OutputFile;
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.SkippingTransformUpToDate), t.InputFile, t.OutputFile);
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.SkippingTransformUpToDate), t.InputFile, t.OutputFile);
} else {
staleOrNewTransforms.Add (t);
}
Expand All @@ -91,7 +91,7 @@ public class TemplateBuildState
t.Dependencies = pt.Dependencies;
t.References = pt.Dependencies;
t.OutputFile = pt.OutputFile;
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.SkippingPreprocessedOutputUpToDate), t.InputFile, t.OutputFile);
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.SkippingPreprocessedOutputUpToDate), t.InputFile, t.OutputFile);
} else {
staleOrNewPreprocessed.Add (t);
}
Expand All @@ -114,7 +114,7 @@ public class TemplateBuildState
}

if (lastSession.DefaultNamespace != session.DefaultNamespace) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingAllDefaultNamespaceChanged));
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingAllDefaultNamespaceChanged));
return regenAll;
}

Expand All @@ -125,36 +125,36 @@ public class TemplateBuildState

// this is probably impossible as the previous session is loaded from the intermediate directory, but let's be safe
if (lastSession.IntermediateDirectory != session.IntermediateDirectory) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingAllIntermediateDirChanged));
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingAllIntermediateDirChanged));
return regenAll;
}

// this is probably impossible as the previous session is loaded from the intermediate directory, but let's be safe
if (!ListsEqual (lastSession.AssemblyReferences, session.AssemblyReferences)) {
// references only affect transformed templates
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingTransformsAsmRefsChanged));
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingTransformsAsmRefsChanged));
return regenTransforms;
}

if (!ListsEqual (lastSession.ReferencePaths, session.ReferencePaths)) {
// however, reference paths may affect the "requiredreferences" of preprocessed templates as well
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingAllReferencePathsChanged));
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingAllReferencePathsChanged));
return regenAll;
}

if (!ListsEqual (lastSession.IncludePaths, session.IncludePaths)) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingAllIncludePathsChanged));
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingAllIncludePathsChanged));
return regenAll;
}

if (!ListsEqual (lastSession.DirectiveProcessors, session.DirectiveProcessors)) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingAllDirectiveProcessorsChanged));
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingAllDirectiveProcessorsChanged));
return regenAll;
}

if (!ListsEqual (lastSession.Parameters, session.Parameters)) {
// parameters can affect includes and references in precoressed templates
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingAllParametersChanged));
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingAllParametersChanged));
return regenAll;
}

Expand Down Expand Up @@ -232,19 +232,19 @@ public class TransformTemplate
public bool IsStale (Func<string, DateTime?> getFileWriteTime, TaskLoggingHelper logger)
{
if (getFileWriteTime (OutputFile) is not DateTime outputTime) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingTransformMissingOutputFile), InputFile, OutputFile);
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingTransformMissingOutputFile), InputFile, OutputFile);
return true;
}

if (getFileWriteTime (InputFile) is not DateTime inputTime || inputTime > outputTime) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingTransformOutputFileOlderThanTemplate), InputFile, OutputFile);
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingTransformOutputFileOlderThanTemplate), InputFile, OutputFile);
return true;
}

if (Dependencies != null) {
foreach (var dep in Dependencies) {
if (getFileWriteTime (dep) is not DateTime depTime || depTime > outputTime) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingTransformOutputFileOlderThanDependency), InputFile, OutputFile, dep);
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingTransformOutputFileOlderThanDependency), InputFile, OutputFile, dep);
return true;
}
}
Expand All @@ -270,19 +270,19 @@ public class PreprocessedTemplate
public bool IsStale (Func<string, DateTime?> getFileWriteTime, TaskLoggingHelper logger)
{
if (getFileWriteTime (OutputFile) is not DateTime outputTime) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingPreprocessedOutputFileMissing), InputFile, OutputFile);
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingPreprocessedOutputFileMissing), InputFile, OutputFile);
return true;
}

if (getFileWriteTime (InputFile) is not DateTime inputTime || inputTime > outputTime) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingPreprocessedOutputFileOlderThanTemplate), InputFile, OutputFile);
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingPreprocessedOutputFileOlderThanTemplate), InputFile, OutputFile);
return true;
}

if (Dependencies != null) {
foreach (var dep in Dependencies) {
if (getFileWriteTime (dep) is not DateTime depTime || depTime > outputTime) {
logger.LogMessageFromResources (MessageImportance.Low, nameof(Messages.RegeneratingPreprocessedOutputFileOlderThanDependency), InputFile, OutputFile, dep);
logger.LogMessageFromResources (MessageImportance.Low, nameof (Messages.RegeneratingPreprocessedOutputFileOlderThanDependency), InputFile, OutputFile, dep);
return true;
}
}
Expand Down
46 changes: 23 additions & 23 deletions Mono.TextTemplating.Build/TextTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public class TextTransform : Task
public TextTransform () : base (Messages.ResourceManager) { }

public string DefaultNamespace { get; set; }
public ITaskItem [] PreprocessTemplates { get; set; }
public ITaskItem [] TransformTemplates { get; set; }
public ITaskItem [] IncludePaths { get; set; }
public ITaskItem [] DirectiveProcessors { get; set; }
public ITaskItem [] AssemblyReferences { get; set; }
public ITaskItem [] ReferencePaths { get; set; }
public ITaskItem[] PreprocessTemplates { get; set; }
public ITaskItem[] TransformTemplates { get; set; }
public ITaskItem[] IncludePaths { get; set; }
public ITaskItem[] DirectiveProcessors { get; set; }
public ITaskItem[] AssemblyReferences { get; set; }
public ITaskItem[] ReferencePaths { get; set; }

public ITaskItem [] ParameterValues { get; set; }
public ITaskItem[] ParameterValues { get; set; }

public bool PreprocessOnly { get; set; }
public bool UseLegacyPreprocessingMode { get; set; }
Expand All @@ -41,13 +41,13 @@ public TextTransform () : base (Messages.ResourceManager) { }
public string IntermediateDirectory { get; set; }

[Output]
public ITaskItem [] RequiredAssemblies { get; set; }
public ITaskItem[] RequiredAssemblies { get; set; }

[Output]
public ITaskItem [] TransformTemplateOutput { get; set; }
public ITaskItem[] TransformTemplateOutput { get; set; }

[Output]
public ITaskItem [] PreprocessedTemplateOutput { get; set; }
public ITaskItem[] PreprocessedTemplateOutput { get; set; }

public override bool Execute ()
{
Expand All @@ -67,7 +67,7 @@ public override bool Execute ()
if (TransformOutOfDateOnly) {
previousBuildState = LoadBuildState (buildStateFilename, msgPackOptions);
if (previousBuildState != null) {
Log.LogMessageFromResources (MessageImportance.Low, nameof(Messages.LoadedStateFile), buildStateFilename);
Log.LogMessageFromResources (MessageImportance.Low, nameof (Messages.LoadedStateFile), buildStateFilename);
}
}

Expand Down Expand Up @@ -204,8 +204,8 @@ bool AddParameters (TemplateBuildState buildState)
directiveName = directiveMetadata;
}

if(paramVal is null) {
Log.LogWarningFromResources (nameof(Messages.ArgumentNoValue), par);
if (paramVal is null) {
Log.LogWarningFromResources (nameof (Messages.ArgumentNoValue), par);
success = false;
continue;
}
Expand Down Expand Up @@ -236,10 +236,10 @@ bool AddDirectiveProcessors (TemplateBuildState buildState)
var name = dirItem.ItemSpec;
string className = null, assembly = null;

if (name.IndexOf('!') > -1) {
if (name.IndexOf ('!') > -1) {
var split = name.Split ('!');
if (split.Length != 3) {
Log.LogErrorFromResources (nameof(Messages.DirectiveProcessorDoesNotHaveThreeValues), name);
Log.LogErrorFromResources (nameof (Messages.DirectiveProcessorDoesNotHaveThreeValues), name);
return false;
}
//empty values for these are fine; they may get set through metadata
Expand All @@ -261,12 +261,12 @@ bool AddDirectiveProcessors (TemplateBuildState buildState)
}

if (string.IsNullOrEmpty (className)) {
Log.LogErrorFromResources (nameof(Messages.DirectiveProcessorNoClass), name);
Log.LogErrorFromResources (nameof (Messages.DirectiveProcessorNoClass), name);
hasErrors = true;
}

if (string.IsNullOrEmpty (assembly)) {
Log.LogErrorFromResources (nameof(Messages.DirectiveProcessorNoAssembly), name);
Log.LogErrorFromResources (nameof (Messages.DirectiveProcessorNoAssembly), name);
hasErrors = true;
}

Expand All @@ -282,17 +282,17 @@ bool AddDirectiveProcessors (TemplateBuildState buildState)

TemplateBuildState LoadBuildState (string filePath, MessagePackSerializerOptions options)
{
if (!File.Exists(filePath)) {
if (!File.Exists (filePath)) {
return null;
}

try {
using var stream = File.OpenRead (filePath);

var state = MessagePackSerializer.Deserialize<TemplateBuildState> (stream, options);
var state = MessagePackSerializer.Deserialize<TemplateBuildState> (stream, options);

if (state.FormatVersion != TemplateBuildState.CurrentFormatVersion) {
Log.LogMessageFromResources (MessageImportance.Low, nameof(Messages.BuildStateFormatChanged));
Log.LogMessageFromResources (MessageImportance.Low, nameof (Messages.BuildStateFormatChanged));
}

return state;
Expand All @@ -301,7 +301,7 @@ TemplateBuildState LoadBuildState (string filePath, MessagePackSerializerOptions
// show a meaningful error message without internal details
Log.LogWarningFromResources (nameof (Messages.BuildStateLoadFailed));
// log a stack trace so it can be reported
Log.LogMessageFromResources (MessageImportance.Normal, nameof(Messages.InternalException), ex);
Log.LogMessageFromResources (MessageImportance.Normal, nameof (Messages.InternalException), ex);
}

return null;
Expand All @@ -317,9 +317,9 @@ void SaveBuildState (TemplateBuildState buildState, string filePath, MessagePack
// show a meaningful error message without internal details
Log.LogWarningFromResources (nameof (Messages.BuildStateSaveFailed));
// log a stack trace so it can be reported
Log.LogMessageFromResources (MessageImportance.Normal, nameof(Messages.InternalException), ex);
Log.LogMessageFromResources (MessageImportance.Normal, nameof (Messages.InternalException), ex);
try {
if (File.Exists(filePath)) {
if (File.Exists (filePath)) {
File.Delete (filePath);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Mono.TextTemplating.Build/TextTransformProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ sealed class WriteTimeCache
public DateTime? GetWriteTime (string filepath)
{
if (!writeTimeCache.TryGetValue (filepath, out var value)) {
writeTimeCache.Add (filepath, value = File.Exists(filepath)? File.GetLastWriteTime (filepath) : null);
writeTimeCache.Add (filepath, value = File.Exists (filepath) ? File.GetLastWriteTime (filepath) : null);
}
return value;
}
Expand Down

0 comments on commit f54ec9f

Please sign in to comment.