Ver Fonte

2003-03-10 Gonzalo Paniagua Javier <[email protected]>

	* AspGenerator.cs:
	* BaseCompiler.cs:
	* CachingCompiler.cs:
	* CompilationResult.cs:
	* GlobalAsaxCompiler.cs:
	* PageCompiler.cs:
	* UserControlCompiler.cs: recompile the page if dependencies change.

svn path=/trunk/mcs/; revision=12401
Gonzalo Paniagua Javier há 23 anos atrás
pai
commit
3f3247b3ee

+ 18 - 3
mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs

@@ -303,6 +303,7 @@ class AspGenerator
 	Element current;
 	ScriptStatus sstatus = ScriptStatus.Close;
 	string waitClosing;
+	ArrayList dependencies;
 
 	HttpContext context;
 
@@ -393,6 +394,10 @@ class AspGenerator
 		}
 	}
 	
+	public ArrayList Dependencies {
+		get { return dependencies; }
+	}
+	
 	internal HttpContext Context {
 		get { return context; }
 		set { context = value; }
@@ -437,6 +442,9 @@ class AspGenerator
 
 	private void Init ()
 	{
+		dependencies = new ArrayList ();
+		dependencies.Add (fullPath);
+
 		controls = new ControlStack ();
 		controls.Push (typeof (System.Web.UI.Control), "Root", null, ChildrenKind.CONTROLS, null);
 		prolog = new StringBuilder ();
@@ -571,8 +579,10 @@ class AspGenerator
 				Console.WriteLine ("ASP.NET Warning: error was: {0}", e.Message);
 			}
 
-			if (type != null)
+			if (type != null) {
+				dependencies.Add (dllPath);
 				return type;
+			}
 		}
 
 		return null;
@@ -653,11 +663,13 @@ class AspGenerator
 								att.ToString ());
 
 			AddUsing (name_space);
-			string dll = privateBinPath + Path.DirectorySeparatorChar + assembly_name + ".dll";
+			string dll = Path.Combine (privateBinPath, assembly_name + ".dll");
 			// Hack: it should use assembly.load semantics...
 			// may be when we don't run mcs as a external program...
 			if (!File.Exists (dll))
 				dll = assembly_name;
+			else
+				dependencies.Add (dll);
 
 			Foundry.RegisterFoundry (tag_prefix, dll, name_space);
 			AddReference (dll);
@@ -2017,7 +2029,7 @@ class AspGenerator
 		public string assemblyName;
 	}
 
-	private static UserControlData GenerateUserControl (string src, HttpContext context)
+	private UserControlData GenerateUserControl (string src, HttpContext context)
 	{
 		UserControlData data = new UserControlData ();
 		data.result = UserControlResult.OK;
@@ -2031,6 +2043,9 @@ class AspGenerator
 		
 		data.className = t.Name;
 		data.assemblyName = compiler.TargetFile;
+		dependencies.Add (src);
+		foreach (string s in compiler.Dependencies)
+			dependencies.Add (s);
 		
 		return data;
 	}

+ 13 - 1
mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs

@@ -21,6 +21,7 @@ namespace System.Web.Compilation
 		static Random rnd = new Random ((int) DateTime.Now.Ticks);
 		string randomName;
 		protected Hashtable options;
+		protected ArrayList dependencies;
 
 		protected BaseCompiler ()
 		{
@@ -45,9 +46,20 @@ namespace System.Web.Compilation
 
 		public virtual string [] Dependencies {
 			get {
-				return null;
+				if (dependencies == null)
+					return new string [0];
+
+				return (string []) dependencies.ToArray (typeof (string));
 			}
 		}
+
+		public virtual void AddDependency (string filename)
+		{
+			if (dependencies == null)
+				dependencies = new ArrayList ();
+
+			dependencies.Add (filename);
+		}
 		
 		public virtual string CompilerOptions {
 			get {

+ 27 - 15
mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs

@@ -20,17 +20,30 @@ namespace System.Web.Compilation
 	internal class CompilationCacheItem
 	{
 		CompilationResult result;
-		DateTime time;
+		DateTime reference;
+		bool invalidated;
 
-		public CompilationCacheItem (CompilationResult result, DateTime time)
+		public CompilationCacheItem (CompilationResult result)
 		{
 			this.result = result;
-			this.time = time;
+			this.reference = File.GetLastWriteTime (result.OutputFile);
 		}
 
-		public bool CheckDependencies (string [] newDependencies, DateTime time)
+		public bool CheckDependencies ()
 		{
-			// FIXME
+			if (invalidated || result.Dependencies == null)
+				return false;
+
+			if (!File.Exists (result.OutputFile))
+				return false;
+
+			foreach (string s in result.Dependencies) {
+				if (!File.Exists (s) || File.GetLastWriteTime (s) > reference) {
+					invalidated = true;
+					return false;
+				}
+			}
+			
 			return true;
 		}
 
@@ -89,7 +102,10 @@ namespace System.Web.Compilation
 				throw new ArgumentNullException ("key");
 
 			CompilationCacheItem item = cache [key];
-			return item;
+			if (item != null && item.CheckDependencies ())
+				return item;
+
+			return null;
 		}
 
 		static object compilationLock = new object ();
@@ -103,23 +119,19 @@ namespace System.Web.Compilation
 
 			item = GetCached (key);
 			if (item != null) {
-				if (item.CheckDependencies (compiler.Dependencies, DateTime.Now) == true) {
-					result.CopyFrom (item.Result);
-					return true;
-				}
+				result.CopyFrom (item.Result);
+				return true;
 			}
 			
 			lock (compilationLock) {
 				item = GetCached (key);
 				if (item != null) {
-					if (item.CheckDependencies (compiler.Dependencies, DateTime.Now) == true) {
-						result.CopyFrom (item.Result);
-						return true;
-					}
+					result.CopyFrom (item.Result);
+					return true;
 				}
 
 				RealCompile (result);
-				cache [key] = new CompilationCacheItem (result, DateTime.Now);
+				cache [key] = new CompilationCacheItem (result);
 			}
 
 			return (result.ExitCode == 0);

+ 10 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,13 @@
+2003-03-10  Gonzalo Paniagua Javier <[email protected]>
+
+	* AspGenerator.cs:
+	* BaseCompiler.cs:
+	* CachingCompiler.cs:
+	* CompilationResult.cs:
+	* GlobalAsaxCompiler.cs:
+	* PageCompiler.cs:
+	* UserControlCompiler.cs: recompile the page if dependencies change.
+
 2003-02-15  Gonzalo Paniagua Javier <[email protected]>
 
 	* AspGenerator.cs: corrected typo and wrong fix.

+ 6 - 0
mcs/class/System.Web/System.Web.Compilation/CompilationResult.cs

@@ -19,6 +19,7 @@ namespace System.Web.Compilation
 		string outputFile;
 		object data;
 		Hashtable options;
+		ArrayList dependencies;
 		
 		public CompilationResult ()
 		{
@@ -72,6 +73,11 @@ namespace System.Web.Compilation
 			set { options = value; }
 		}
 
+		public ArrayList Dependencies {
+			get { return dependencies; }
+			set { dependencies = value; }
+		}
+
 		public override string ToString ()
 		{
 			return String.Format ("CompilationResult: {0} {1} {2} {3}", exitCode, output, outputFile, data);

+ 3 - 1
mcs/class/System.Web/System.Web.Compilation/GlobalAsaxCompiler.cs

@@ -35,7 +35,8 @@ namespace System.Web.Compilation
 			result.Options = options;
 			if (compiler.Compile (result) == false)
 				throw new CompilationException (result);
-				
+			
+			result.Dependencies = dependencies;
 			Assembly assembly = Assembly.LoadFrom (result.OutputFile);
 			Type [] types = assembly.GetTypes ();
 			foreach (Type t in types) {
@@ -84,6 +85,7 @@ namespace System.Web.Compilation
 			generator.ProcessElements ();
 			string generated = generator.GetCode ().ReadToEnd ();
 			options = generator.Options;
+			dependencies = generator.Dependencies;
 
 			//FIXME: should get Tmp dir for this application
 			string csName = Path.GetTempFileName () + ".cs";

+ 2 - 0
mcs/class/System.Web/System.Web.Compilation/PageCompiler.cs

@@ -36,6 +36,7 @@ namespace System.Web.Compilation
 			if (compiler.Compile (result) == false)
 				throw new CompilationException (result);
 			
+			result.Dependencies = dependencies;
 			if (result.Data is Type)
 				return (Type) result.Data;
 
@@ -87,6 +88,7 @@ namespace System.Web.Compilation
 			generator.BaseType = pageParser.BaseType.ToString ();
 			generator.ProcessElements ();
 			pageParser.Text = generator.GetCode ().ReadToEnd ();
+			dependencies = generator.Dependencies;
 			options = generator.Options;
 
 			//FIXME: should get Tmp dir for this application

+ 2 - 0
mcs/class/System.Web/System.Web.Compilation/UserControlCompiler.cs

@@ -36,6 +36,7 @@ namespace System.Web.Compilation
 			if (compiler.Compile (result) == false)
 				throw new CompilationException (result);
 			
+			result.Dependencies = dependencies;
 			if (result.Data is Type) {
 				targetFile = result.OutputFile;
 				return (Type) result.Data;
@@ -101,6 +102,7 @@ namespace System.Web.Compilation
 			generator.ProcessElements ();
 			userControlParser.Text = generator.GetCode ().ReadToEnd ();
 			options = generator.Options;
+			dependencies = generator.Dependencies;
 
 			//FIXME: should get Tmp dir for this application
 			string csName = Path.GetTempFileName () + ".cs";