Author: mhabersack
Date: 2007-12-21 15:59:53 -0500 (Fri, 21 Dec 2007)
New Revision: 91789
Modified:
trunk/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs
trunk/mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs
trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog
trunk/mcs/class/System.Web/System.Web.Compilation/WebServiceCompiler.cs
Log:
2007-12-21 Marek Habersack <[EMAIL PROTECTED]>
* BaseCompiler.cs: Refactoring. Move the provider creation code to
an internal static method, so that other piece of code which need
to create the provider can do it using the same code.
Added setters to several internal properties, so that they can be
shared with derivative classes.
* WebServiceCompiler.cs: adjust to the changes above. Fixes bug
#350398.
* CachingCompiler.cs: adjust to the changes above. Also some
refactoring.
Modified: trunk/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs
2007-12-21 20:17:42 UTC (rev 91788)
+++ trunk/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs
2007-12-21 20:59:53 UTC (rev 91789)
@@ -66,7 +66,6 @@
protected BaseCompiler (TemplateParser parser)
{
- compilerParameters = new CompilerParameters ();
this.parser = parser;
}
@@ -184,15 +183,6 @@
CreateConstructor (null, null);
}
-#if NET_2_0
- internal CodeDomProvider Provider {
- get { return provider; }
- }
-
- internal CodeCompileUnit CompileUnit {
- get { return unit; }
- }
-#endif
protected virtual void CreateStaticFields ()
{
CodeMemberField fld = new CodeMemberField (typeof
(bool), "__initialized");
@@ -473,34 +463,34 @@
return
AppDomain.CurrentDomain.SetupInformation.DynamicBase;
}
- [MonoTODO ("find out how to extract the warningLevel and
compilerOptions in the <system.codedom> case")]
- public virtual Type GetCompiledType ()
+ internal static CodeDomProvider CreateProvider (string lang,
out string compilerOptions, out int warningLevel, out string tempdir)
{
- Type type = CachingCompiler.GetTypeFromCache
(parser.InputFile);
- if (type != null)
- return type;
-
- Init ();
- string lang = parser.Language;
+ return CreateProvider (HttpContext.Current, lang, out
compilerOptions, out warningLevel, out tempdir);
+ }
+
+ internal static CodeDomProvider CreateProvider (HttpContext
context, string lang, out string compilerOptions, out int warningLevel, out
string tempdir)
+ {
+ CodeDomProvider ret = null;
+
#if NET_2_0
CompilationSection config = (CompilationSection)
WebConfigurationManager.GetSection ("system.web/compilation");
Compiler comp = config.Compilers[lang];
-
- string compilerOptions = "";
- int warningLevel = 0;
-
+
if (comp == null) {
CompilerInfo info =
CodeDomProvider.GetCompilerInfo (lang);
- if (info != null &&
info.IsCodeDomProviderTypeValid)
- provider = info.CreateProvider ();
+ if (info != null &&
info.IsCodeDomProviderTypeValid) {
+ ret = info.CreateProvider ();
- // XXX there's no way to get
- // warningLevel or compilerOptions out
- // of the provider.. they're in the
- // configuration section, though.
+ CompilerParameters cp =
info.CreateDefaultCompilerParameters ();
+ compilerOptions = cp.CompilerOptions;
+ warningLevel = cp.WarningLevel;
+ } else {
+ compilerOptions = String.Empty;
+ warningLevel = 2;
+ }
} else {
Type t = HttpApplication.LoadType (comp.Type,
true);
- provider = Activator.CreateInstance (t) as
CodeDomProvider;
+ ret = Activator.CreateInstance (t) as
CodeDomProvider;
compilerOptions = comp.CompilerOptions;
warningLevel = comp.WarningLevel;
@@ -508,46 +498,65 @@
#else
CompilationConfiguration config;
- config = CompilationConfiguration.GetInstance
(parser.Context);
- provider = config.GetProvider (lang);
+ config = CompilationConfiguration.GetInstance (context);
+ ret = config.GetProvider (lang);
- string compilerOptions = config.GetCompilerOptions
(lang);
- int warningLevel = config.GetWarningLevel (lang);
+ compilerOptions = config.GetCompilerOptions (lang);
+ warningLevel = config.GetWarningLevel (lang);
#endif
- if (provider == null)
+ tempdir = config.TempDirectory;
+
+ return ret;
+ }
+
+ [MonoTODO ("find out how to extract the warningLevel and
compilerOptions in the <system.codedom> case")]
+ public virtual Type GetCompiledType ()
+ {
+ Type type = CachingCompiler.GetTypeFromCache
(parser.InputFile);
+ if (type != null)
+ return type;
+
+ Init ();
+ string lang = parser.Language;
+ string tempdir;
+ string compilerOptions;
+ int warningLevel;
+
+ Provider = CreateProvider (parser.Context, lang, out
compilerOptions, out warningLevel, out tempdir);
+ if (Provider == null)
throw new HttpException ("Configuration error.
Language not supported: " +
lang, 500);
#if !NET_2_0
compiler = provider.CreateCompiler ();
#endif
+
+ CompilerParameters parameters = CompilerParameters;
+ parameters.IncludeDebugInformation = parser.Debug;
+ parameters.CompilerOptions = compilerOptions + " " +
parser.CompilerOptions;
+ parameters.WarningLevel = warningLevel;
- compilerParameters.IncludeDebugInformation =
parser.Debug;
- compilerParameters.CompilerOptions = compilerOptions +
" " + parser.CompilerOptions;
-
- compilerParameters.WarningLevel = warningLevel;
bool keepFiles = (Environment.GetEnvironmentVariable
("MONO_ASPNET_NODELETE") != null);
- string tempdir = config.TempDirectory;
if (tempdir == null || tempdir == "")
tempdir = DynamicDir ();
TempFileCollection tempcoll = new TempFileCollection
(tempdir, keepFiles);
- compilerParameters.TempFiles = tempcoll;
+ parameters.TempFiles = tempcoll;
string dllfilename = Path.GetFileName
(tempcoll.AddExtension ("dll", true));
- compilerParameters.OutputAssembly = Path.Combine
(DynamicDir (), dllfilename);
+ parameters.OutputAssembly = Path.Combine (DynamicDir
(), dllfilename);
CompilerResults results = CachingCompiler.Compile
(this);
CheckCompilerErrors (results);
Assembly assembly = results.CompiledAssembly;
if (assembly == null) {
- if (!File.Exists
(compilerParameters.OutputAssembly)) {
+ if (!File.Exists (parameters.OutputAssembly)) {
results.TempFiles.Delete ();
throw new CompilationException
(parser.InputFile, results.Errors,
"No assembly returned after
compilation!?");
}
- assembly = Assembly.LoadFrom
(compilerParameters.OutputAssembly);
+ assembly = Assembly.LoadFrom
(parameters.OutputAssembly);
}
results.TempFiles.Delete ();
@@ -635,18 +644,31 @@
}
#endif
+ internal CodeDomProvider Provider {
+ get { return provider; }
+ set { provider = value; }
+ }
+
+ internal ICodeCompiler Compiler {
+ get { return compiler; }
+ set { compiler = value; }
+ }
+
internal CompilerParameters CompilerParameters {
- get { return compilerParameters; }
+ get {
+ if (compilerParameters == null)
+ compilerParameters = new
CompilerParameters ();
+
+ return compilerParameters;
+ }
+
+ set { compilerParameters = value; }
}
- internal CodeCompileUnit Unit {
+ internal CodeCompileUnit CompileUnit {
get { return unit; }
}
- internal virtual ICodeCompiler Compiler {
- get { return compiler; }
- }
-
internal TemplateParser Parser {
get { return parser; }
}
Modified: trunk/mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs
2007-12-21 20:17:42 UTC (rev 91788)
+++ trunk/mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs
2007-12-21 20:59:53 UTC (rev 91789)
@@ -98,7 +98,7 @@
#endif
CompilerParameters options =
compiler.CompilerParameters;
GetExtraAssemblies (options);
- results = comp.CompileAssemblyFromDom (options,
compiler.Unit);
+ results = comp.CompileAssemblyFromDom (options,
compiler.CompileUnit);
string [] deps = (string [])
compiler.Parser.Dependencies.ToArray (typeof (string));
cache.Insert (key, results, new CacheDependency
(deps));
} finally {
@@ -132,9 +132,10 @@
#else
ICodeCompiler comp = compiler.Compiler;
#endif
- CompilerParameters options =
compiler.CompilerOptions;
+ CompilerParameters options =
compiler.CompilerParameters;
GetExtraAssemblies (options);
+
results = comp.CompileAssemblyFromFile
(options, compiler.InputFile);
string [] deps = (string [])
compiler.Parser.Dependencies.ToArray (typeof (string));
cache.Insert (key, results, new CacheDependency
(deps));
@@ -179,34 +180,11 @@
return results;
CodeDomProvider provider = null;
-#if NET_2_0
- CompilationSection config =
(CompilationSection) WebConfigurationManager.GetSection
("system.web/compilation");
- Compiler comp = config.Compilers[language];
+ int warningLevel;
+ string compilerOptions;
+ string tempdir;
- string compilerOptions = "";
- int warningLevel = 0;
-
- if (comp == null) {
- CompilerInfo info =
CodeDomProvider.GetCompilerInfo (language);
- if (info != null &&
info.IsCodeDomProviderTypeValid)
- provider = info.CreateProvider
();
-
- // XXX there's no way to get
- // warningLevel or compilerOptions out
- // of the provider.. they're in the
- // configuration section, though.
- } else {
- Type t = HttpApplication.LoadType
(comp.Type, true);
- provider = Activator.CreateInstance (t)
as CodeDomProvider;
-
- compilerOptions = comp.CompilerOptions;
- warningLevel = comp.WarningLevel;
- }
-#else
- CompilationConfiguration config;
- config = CompilationConfiguration.GetInstance
(HttpContext.Current);
- provider = config.GetProvider (language);
-#endif
+ provider = BaseCompiler.CreateProvider
(language, out compilerOptions, out warningLevel, out tempdir);
if (provider == null)
throw new HttpException ("Configuration
error. Language not supported: " +
language,
500);
@@ -217,7 +195,10 @@
#endif
CompilerParameters options = GetOptions
(assemblies);
- TempFileCollection tempcoll = new
TempFileCollection (config.TempDirectory, true);
+ options.WarningLevel = warningLevel;
+ options.CompilerOptions = compilerOptions;
+
+ TempFileCollection tempcoll = new
TempFileCollection (tempdir, true);
string dllfilename = Path.GetFileName
(tempcoll.AddExtension ("dll", true));
options.OutputAssembly = Path.Combine
(dynamicBase, dllfilename);
results = compiler.CompileAssemblyFromFile
(options, file);
Modified: trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog 2007-12-21
20:17:42 UTC (rev 91788)
+++ trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog 2007-12-21
20:59:53 UTC (rev 91789)
@@ -1,3 +1,17 @@
+2007-12-21 Marek Habersack <[EMAIL PROTECTED]>
+
+ * BaseCompiler.cs: Refactoring. Move the provider creation code to
+ an internal static method, so that other piece of code which need
+ to create the provider can do it using the same code.
+ Added setters to several internal properties, so that they can be
+ shared with derivative classes.
+
+ * WebServiceCompiler.cs: adjust to the changes above. Fixes bug
+ #350398.
+
+ * CachingCompiler.cs: adjust to the changes above. Also some
+ refactoring.
+
2007-12-15 Marek Habersack <[EMAIL PROTECTED]>
* AppCodeCompiler.cs: do not instantiate CodeDomProvider twice.
Modified:
trunk/mcs/class/System.Web/System.Web.Compilation/WebServiceCompiler.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Compilation/WebServiceCompiler.cs
2007-12-21 20:17:42 UTC (rev 91788)
+++ trunk/mcs/class/System.Web/System.Web.Compilation/WebServiceCompiler.cs
2007-12-21 20:59:53 UTC (rev 91789)
@@ -40,9 +40,6 @@
class WebServiceCompiler : BaseCompiler
{
SimpleWebHandlerParser parser;
- ICodeCompiler compiler;
- CodeDomProvider provider;
- CompilerParameters compilerParameters;
string inputFile;
public WebServiceCompiler (SimpleWebHandlerParser wService)
@@ -70,56 +67,30 @@
}
string lang = parser.Language;
-#if NET_2_0
- CompilationSection config = (CompilationSection)
WebConfigurationManager.GetSection ("system.web/compilation");
- Compiler comp = config.Compilers[lang];
+ string compilerOptions;
+ string tempdir;
+ int warningLevel;
- string compilerOptions = "";
- int warningLevel = 0;
-
- if (comp == null) {
- CompilerInfo info =
CodeDomProvider.GetCompilerInfo (lang);
- if (info != null &&
info.IsCodeDomProviderTypeValid)
- provider = info.CreateProvider ();
-
- // XXX there's no way to get
- // warningLevel or compilerOptions out
- // of the provider.. they're in the
- // configuration section, though.
- } else {
- Type t = HttpApplication.LoadType (comp.Type,
true);
- provider = Activator.CreateInstance (t) as
CodeDomProvider;
-
- compilerOptions = comp.CompilerOptions;
- warningLevel = comp.WarningLevel;
- }
-#else
- CompilationConfiguration config;
- config = CompilationConfiguration.GetInstance
(parser.Context);
- provider = config.GetProvider (lang);
-#endif
- if (provider == null)
+ CodeDomProvider provider;
+ Provider = provider = CreateProvider (parser.Context,
lang, out compilerOptions, out warningLevel, out tempdir);
+ if (Provider == null)
throw new HttpException ("Configuration error.
Language not supported: " +
lang, 500);
#if !NET_2_0
- compiler = provider.CreateCompiler ();
+ Compiler = provider.CreateCompiler ();
#endif
- compilerParameters = CachingCompiler.GetOptions
(parser.Assemblies);
+ CompilerParameters compilerParameters;
+ CompilerParameters = compilerParameters =
CachingCompiler.GetOptions (parser.Assemblies);
compilerParameters.IncludeDebugInformation =
parser.Debug;
-#if NET_2_0
- compilerParameters.CompilerOptions =
comp.CompilerOptions;
- compilerParameters.WarningLevel = comp.WarningLevel;
-#else
- compilerParameters.CompilerOptions =
config.GetCompilerOptions (lang);
- compilerParameters.WarningLevel =
config.GetWarningLevel (lang);
-#endif
+ compilerParameters.CompilerOptions = compilerOptions;
+ compilerParameters.WarningLevel = warningLevel;
bool keepFiles = (Environment.GetEnvironmentVariable
("MONO_ASPNET_NODELETE") != null);
TempFileCollection tempcoll;
- tempcoll = new TempFileCollection
(config.TempDirectory, keepFiles);
+ tempcoll = new TempFileCollection (tempdir, keepFiles);
compilerParameters.TempFiles = tempcoll;
inputFile = tempcoll.AddExtension
(provider.FileExtension);
@@ -160,14 +131,6 @@
get { return parser; }
}
- internal override ICodeCompiler Compiler {
- get { return compiler; }
- }
-
- internal CompilerParameters CompilerOptions {
- get { return compilerParameters; }
- }
-
internal string InputFile {
get { return inputFile; }
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches