Bug 15574. XML deserialization recursion: add array type to known_types?
[mono.git] / mcs / class / Moonlight.Build.Tasks / Moonlight.Build.Tasks / Respack.cs
1 //
2 // Respack.cs
3 //
4 // Author:
5 //   Ankit Jain (jankit@novell.com)
6 //
7 // Copyright 2010 Novell, Inc (http://www.novell.com)
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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.
27
28 using System;
29 using System.Diagnostics;
30 using System.IO;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Tasks;
33 using Microsoft.Build.Utilities;
34 using Mono.XBuild.Utilities;
35
36 namespace Moonlight.Build.Tasks {
37         public class Respack : ToolTask
38         {
39                 public override bool Execute ()
40                 {
41                         if (!ValidateParameters ()) {
42                                 // not generating any resource file
43                                 OutputFile = null;
44                                 return true;
45                         }
46
47                         return BuildRequired () ? base.Execute () : true;
48                 }
49
50                 bool BuildRequired ()
51                 {
52                         if (!File.Exists (OutputFile.ItemSpec))
53                                 return true;
54
55                         DateTime outputFileTime = File.GetLastWriteTime (OutputFile.ItemSpec);
56                         foreach (var res in Resources) {
57                                 string file = res.ItemSpec;
58                                 if (File.Exists (file) && File.GetLastWriteTime (file) > outputFileTime)
59                                         return true;
60                         }
61
62                         return false;
63                 }
64
65                 void AddCommandLineCommands (CommandLineBuilderExtension commandLine)
66                 {
67                         if (Resources.Length == 0)
68                                 return;
69
70                         commandLine.AppendFileNameIfNotNull (OutputFile);
71
72                         commandLine.AppendFileNamesIfNotNull (Resources, " ");
73                 }
74
75                 protected override string GenerateCommandLineCommands ()
76                 {
77                         CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
78                         AddCommandLineCommands (clbe);
79                         return clbe.ToString ();
80                 }
81
82                 protected override string GenerateFullPathToTool ()
83                 {
84                         return Path.Combine (ToolPath, ToolExe);
85                 }
86
87                 protected override bool ValidateParameters()
88                 {
89                         return Resources.Length > 0;
90                 }
91
92                 [Required]
93                 [Output]
94                 public ITaskItem OutputFile {
95                         get; set;
96                 }
97
98                 [Required]
99                 public ITaskItem[] Resources {
100                         get; set;
101                 }
102
103                 protected override string ToolName {
104                         get {
105                                 return RunningOnWindows ? "respack.bat" : "respack";
106                         }
107                 }
108
109                 static bool RunningOnWindows {
110                         get {
111                                 // Code from Mono.GetOptions/Options.cs
112                                 // check for non-Unix platforms - see FAQ for more details
113                                 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
114                                 int platform = (int) Environment.OSVersion.Platform;
115                                 return ((platform != 4) && (platform != 128));
116                         }
117
118                 }
119         }
120 }