2 // BatchingImpl.cs: Class that implements BatchingAlgorithm from the wiki.
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2005 Marek Sieradzki
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 namespace Microsoft.Build.BuildEngine {
33 internal class BatchingImpl {
39 public BatchingImpl (Project project, XmlElement targetElement)
41 if (targetElement == null)
42 throw new ArgumentNullException ("targetElement");
44 throw new ArgumentNullException ("project");
46 this.project = project;
48 inputs = targetElement.GetAttribute ("Inputs");
49 outputs = targetElement.GetAttribute ("Outputs");
52 public bool BuildNeeded ()
54 // FIXME: change this to ITaskItem instead of string
56 Expression inputExpr, outputExpr;
57 string[] inputFiles, outputFiles;
58 DateTime oldestInput, youngestOutput;
60 if (inputs == String.Empty) {
63 if (outputs == String.Empty) {
67 inputExpr = new Expression (project, inputs);
68 outputExpr = new Expression (project, outputs);
70 inputFiles = (string[]) inputExpr.ToArray (typeof (string[]));
71 outputFiles = (string[]) outputExpr.ToArray (typeof (string[]));
73 if (inputFiles == null) {
76 if (outputFiles == null) {
79 if (inputFiles.Length == 0) {
82 if (outputFiles.Length == 0) {
86 if (File.Exists (inputFiles [0])) {
87 oldestInput = File.GetLastWriteTime (inputFiles [0]);
91 if (File.Exists (outputFiles [0])) {
92 youngestOutput = File.GetLastWriteTime (outputFiles [0]);
97 foreach (string file in inputFiles) {
98 if (file.Trim () == String.Empty)
101 if (File.Exists (file.Trim ())) {
102 if (File.GetLastWriteTime (file.Trim ()) > oldestInput)
103 oldestInput = File.GetLastWriteTime (file.Trim ());
108 foreach (string file in outputFiles) {
109 if (file.Trim () == String.Empty)
112 if (File.Exists (file.Trim ())) {
113 if (File.GetLastWriteTime (file.Trim ()) < youngestOutput)
114 youngestOutput = File.GetLastWriteTime (file.Trim ());
120 if (oldestInput > youngestOutput) {
128 public bool BatchTaskElement (TaskElement taskElement)
130 return taskElement.Execute ();