1- using AggregateConfig . Contracts ;
2- using AggregateConfig . FileHandlers ;
3- using AggregateConfigBuildTask ;
1+ using AggregateConfigBuildTask . Contracts ;
2+ using AggregateConfigBuildTask . FileHandlers ;
43using Microsoft . Build . Framework ;
54using System ;
65using System . IO ;
7- using System . Linq ;
6+ using System . Reflection ;
87using System . Runtime . CompilerServices ;
9- using System . Text . Json ;
108using Task = Microsoft . Build . Utilities . Task ;
119
1210[ assembly: InternalsVisibleTo ( "AggregateConfig.Tests.UnitTests" ) ]
1311
14- namespace AggregateConfig
12+ namespace AggregateConfigBuildTask
1513{
1614 public class AggregateConfig : Task
1715 {
@@ -46,8 +44,7 @@ public override bool Execute()
4644 {
4745 try
4846 {
49- bool hasError = false ;
50- JsonElement ? finalResult = null ;
47+ EmitHeader ( ) ;
5148
5249 OutputFile = Path . GetFullPath ( OutputFile ) ;
5350
@@ -74,48 +71,7 @@ public override bool Execute()
7471 fileSystem . CreateDirectory ( directoryPath ) ;
7572 }
7673
77- var expectedExtensions = FileHandlerFactory . GetExpectedFileExtensions ( inputType ) ;
78- var files = fileSystem . GetFiles ( InputDirectory , "*.*" )
79- . Where ( file => expectedExtensions . Contains ( Path . GetExtension ( file ) . ToLower ( ) ) )
80- . ToList ( ) ;
81-
82- foreach ( var file in files )
83- {
84- Log . LogMessage ( MessageImportance . High , "- Found file {0}" , file ) ;
85-
86- IInputReader outputWriter ;
87- try
88- {
89- outputWriter = FileHandlerFactory . GetInputReader ( fileSystem , inputType ) ;
90- }
91- catch ( ArgumentException ex )
92- {
93- hasError = true ;
94- Log . LogError ( "No reader found for file {0}: {1} Stacktrace: {2}" , file , ex . Message , ex . StackTrace ) ;
95- continue ;
96- }
97-
98- JsonElement fileData ;
99- try
100- {
101- fileData = outputWriter . ReadInput ( file ) ;
102- }
103- catch ( Exception ex )
104- {
105- hasError = true ;
106- Log . LogError ( "Could not parse {0}: {1}" , file , ex . Message ) ;
107- Log . LogErrorFromException ( ex , true , true , file ) ;
108- continue ;
109- }
110-
111- // Merge the deserialized object into the final result
112- finalResult = ObjectManager . MergeObjects ( finalResult , fileData , file , AddSourceProperty ) ;
113- }
114-
115- if ( hasError )
116- {
117- return false ;
118- }
74+ var finalResult = ObjectManager . MergeFileObjects ( InputDirectory , inputType , AddSourceProperty , fileSystem , Log ) . GetAwaiter ( ) . GetResult ( ) ;
11975
12076 if ( finalResult == null )
12177 {
@@ -124,11 +80,7 @@ public override bool Execute()
12480 }
12581
12682 var additionalPropertiesDictionary = JsonHelper . ParseAdditionalProperties ( AdditionalProperties ) ;
127- if ( ! ObjectManager . InjectAdditionalProperties ( ref finalResult , additionalPropertiesDictionary ) )
128- {
129- Log . LogError ( "Additional properties could not be injected since the top-level is not a JSON object." ) ;
130- return false ;
131- }
83+ finalResult = ObjectManager . InjectAdditionalProperties ( finalResult , additionalPropertiesDictionary , Log ) . GetAwaiter ( ) . GetResult ( ) ;
13284
13385 var writer = FileHandlerFactory . GetOutputWriter ( fileSystem , outputType ) ;
13486 writer . WriteOutput ( finalResult , OutputFile ) ;
@@ -138,10 +90,20 @@ public override bool Execute()
13890 }
13991 catch ( Exception ex )
14092 {
141- Log . LogError ( "An unknown exception occured : {0}" , ex . Message ) ;
93+ Log . LogError ( "An unknown exception occurred : {0}" , ex . Message ) ;
14294 Log . LogErrorFromException ( ex , true , true , null ) ;
14395 return false ;
14496 }
14597 }
98+
99+ private void EmitHeader ( )
100+ {
101+ var assembly = Assembly . GetExecutingAssembly ( ) ;
102+ var informationalVersion = assembly
103+ . GetCustomAttribute < AssemblyInformationalVersionAttribute > ( ) ?
104+ . InformationalVersion ;
105+
106+ Log . LogMessage ( $ "AggregateConfig Version: { informationalVersion } ") ;
107+ }
146108 }
147109}
0 commit comments