11using System ;
2+ using System . Collections ;
23using System . Collections . Generic ;
34using System . Diagnostics ;
5+ using System . IO ;
46using System . Linq ;
57using System . Text ;
68using Exortech . NetReflector ;
9+ using ThoughtWorks . CruiseControl . Core . Util ;
710
811namespace ThoughtWorks . CruiseControl . Core . Tasks
912{
@@ -45,6 +48,8 @@ public class FakeTask : BaseExecutableTask
4548 public readonly Guid LogFileId = Guid . NewGuid ( ) ;
4649 public const ProcessPriorityClass DefaultPriority = ProcessPriorityClass . Normal ;
4750
51+ private readonly IFileDirectoryDeleter fileDirectoryDeleter = new IoService ( ) ;
52+
4853 /// <summary>
4954 /// The location of the FAKE executable.
5055 /// </summary>
@@ -86,6 +91,19 @@ public class FakeTask : BaseExecutableTask
8691 [ ReflectorProperty ( "buildFile" , Required = false ) ]
8792 public string BuildFile { get ; set ; }
8893
94+ public FakeTask ( ) :
95+ this ( new ProcessExecutor ( ) ) { }
96+
97+ public FakeTask ( ProcessExecutor executor )
98+ {
99+ this . executor = executor ;
100+ Executable = defaultExecutable ;
101+ ConfiguredBaseDirectory = string . Empty ;
102+ Priority = DefaultPriority ;
103+ BuildTimeoutSeconds = DefaultBuildTimeout ;
104+ BuildFile = string . Empty ;
105+ }
106+
89107 #region Overrides of TaskBase
90108
91109 /// <summary>
@@ -95,7 +113,25 @@ public class FakeTask : BaseExecutableTask
95113 /// <returns><c>true</c> if the task was successful; <c>false</c> otherwise.</returns>
96114 protected override bool Execute ( IIntegrationResult result )
97115 {
98- throw new NotImplementedException ( ) ;
116+ var fakeOutputFile = GetFakeOutputFile ( result ) ;
117+
118+ //delete old nant output logfile, if exist
119+ fileDirectoryDeleter . DeleteIncludingReadOnlyObjects ( fakeOutputFile ) ;
120+
121+ result . BuildProgressInformation . SignalStartRunTask ( ! string . IsNullOrEmpty ( Description ) ? Description :
122+ string . Format ( "Executing FAKE - {0}" , ToString ( ) ) ) ;
123+
124+ var processResult = TryToRun ( CreateProcessInfo ( result ) , result ) ;
125+
126+ if ( File . Exists ( fakeOutputFile ) )
127+ result . AddTaskResult ( new FileTaskResult ( fakeOutputFile ) ) ;
128+
129+ result . AddTaskResult ( new ProcessTaskResult ( processResult , true ) ) ;
130+
131+ if ( processResult . TimedOut )
132+ throw new BuilderException ( this , string . Concat ( "FAKE process timed out (after " , BuildTimeoutSeconds , " seconds)" ) ) ;
133+
134+ return ! processResult . Failed ;
99135 }
100136
101137 #endregion
@@ -109,7 +145,11 @@ protected override string GetProcessFilename()
109145
110146 protected override string GetProcessArguments ( IIntegrationResult result )
111147 {
112- throw new NotImplementedException ( ) ;
148+ var buffer = new ProcessArgumentBuilder ( ) ;
149+ buffer . AppendArgument ( StringUtil . AutoDoubleQuoteString ( BuildFile ) ) ;
150+ buffer . AppendArgument ( "logfile={0}" , StringUtil . AutoDoubleQuoteString ( GetFakeOutputFile ( result ) ) ) ;
151+ AppendIntegrationResultProperties ( buffer , result ) ;
152+ return buffer . ToString ( ) ;
113153 }
114154
115155 protected override string GetProcessBaseDirectory ( IIntegrationResult result )
@@ -128,5 +168,29 @@ protected override int GetProcessTimeout()
128168 }
129169
130170 #endregion
171+
172+ private static void AppendIntegrationResultProperties ( ProcessArgumentBuilder buffer , IIntegrationResult result )
173+ {
174+ // We have to sort this alphabetically, else the unit tests
175+ // that expect args in a certain order are unpredictable
176+ IDictionary properties = result . IntegrationProperties ;
177+ foreach ( string key in properties . Keys )
178+ {
179+ object value = result . IntegrationProperties [ key ] ;
180+ if ( value != null )
181+ buffer . AppendArgument ( string . Format ( "{0}={1}" , key , StringUtil . AutoDoubleQuoteString ( StringUtil . RemoveTrailingPathDelimeter ( StringUtil . IntegrationPropertyToString ( value ) ) ) ) ) ;
182+ }
183+ }
184+
185+ public override string ToString ( )
186+ {
187+ string baseDirectory = ConfiguredBaseDirectory ?? string . Empty ;
188+ return string . Format ( @" BaseDirectory: {0}, Executable: {1}, BuildFile: {2}" , baseDirectory , Executable , BuildFile ) ;
189+ }
190+
191+ private string GetFakeOutputFile ( IIntegrationResult result )
192+ {
193+ return Path . Combine ( result . ArtifactDirectory , string . Format ( logFilename , LogFileId ) ) ;
194+ }
131195 }
132196}
0 commit comments