Gert Driesen wrote:
Ian,
I think we should have a way of checking whether a given task is available, and can be executed (on a given pc, framework, platform, ...).
Agreed. This would be very useful.
One way of achieving this would be to have a virtual IsAvailable (or CanBeExecuted, or you tell me ... man, am I bad in names or what) property (or should it be a method) with a default implementation that just checks whether a "available" (or whatever) attribute has not been set to false on the task node in the NAnt configuration file (so by default it would be true).
IsAvailable sounds fine.
eg.
<tasks> <!-- by default, available is set to true --> <task name="csc"> <attribute name="exename">csc</attribute> <attribute name="useruntimeengine">false</attribute> </task> <task name="jsc" available="false" /> </tasks>
ok - so the bool property just checks the config file or whatever and CheckAvailability does the runtime check. The bool property should probably be static so that it can be called without having to instantiate the Task class.Tasks that need to determine the availability at runtime (eg. need to check whether the JScript.NET compiler is installed), can override this property (or method), or even add addtional logic to the framework initialization project in the NAnt configuration file and set the available attribute accordingly, or a combination of both ...
eg.
<framework ...> <project> <!-- determine whether a given registry key exists, to find out if a given task can be executed ))> <readregistry property="doesntmatter" key="..." hive="LocalMachine" failonerror="false" /> </project> <tasks> <task name="dummy" available="${property::exists('doesntmatter')}" /> </task> </framework>
After giving it some more thought, it might be best to have a bool property on Task that is non-virtual, and which never throws an exception. And have a protected virtual method (called CheckAvailability or so) that will throw a (Build)Exception if the task is not available, while specifying the reason. That way we could call this method as part of Task.Execute, and output the reason why the task is not available in the build log.
To be able to use this in our tests to determine whether a given test can be executed, we'd need to initialize the task that we want to execute though.
not if we make it static.
looks good. It would also be worth having a task::is-available(string taskName ) function so the check can be done from a build file.eg.
[Test] public void Test_JscDebugBuild() { JscTask jscTask = new JscTask(); jscTask.Project = CreateEmptyProject(); if (!jscTask.IsAvailable) { // skip test return; } }
(I know this is kinda verbose, but ...)
What do you think ?
Ian
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
nant-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers
