diff options
author | Michael Hutchinson <mhutch@xamarin.com> | 2014-02-14 02:01:50 +0400 |
---|---|---|
committer | Michael Hutchinson <mhutch@xamarin.com> | 2014-02-14 10:42:47 +0400 |
commit | 63f8ecfff223bcc52ec64db9b8b677470c6e1ee1 (patch) | |
tree | 752f7b884b6ae98715662bf8ef7a3f1f47bf0f8b /main/src/core/MonoDevelop.Projects.Formats.MSBuild | |
parent | 3f84f7f9a416f41ac86ce86f5c961130d6875002 (diff) |
[MSBuild] Minor cleanup
Diffstat (limited to 'main/src/core/MonoDevelop.Projects.Formats.MSBuild')
7 files changed, 53 insertions, 58 deletions
diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/Main.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/Main.cs index 323cdca106..2b8b5144a1 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/Main.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/Main.cs @@ -37,25 +37,25 @@ namespace MonoDevelop.Projects.Formats.MSBuild { class MainClass { - static ManualResetEvent exitEvent = new ManualResetEvent (false); + static readonly ManualResetEvent exitEvent = new ManualResetEvent (false); [STAThread] - public static void Main (string[] args) + public static void Main () { try { RegisterRemotingChannel (); WatchProcess (Console.ReadLine ()); - BuildEngine builderEngine = new BuildEngine (); - BinaryFormatter bf = new BinaryFormatter (); + var builderEngine = new BuildEngine (); + var bf = new BinaryFormatter (); ObjRef oref = RemotingServices.Marshal (builderEngine); - MemoryStream ms = new MemoryStream (); + var ms = new MemoryStream (); bf.Serialize (ms, oref); Console.Error.WriteLine (Convert.ToBase64String (ms.ToArray ())); if (WaitHandle.WaitAny (new WaitHandle[] { builderEngine.WaitHandle, exitEvent }) == 0) { // Wait before exiting, so that the remote call that disposed the builder can be completed - System.Threading.Thread.Sleep (400); + Thread.Sleep (400); } } catch (Exception ex) { @@ -66,8 +66,8 @@ namespace MonoDevelop.Projects.Formats.MSBuild public static void RegisterRemotingChannel () { IDictionary dict = new Hashtable (); - BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider(); - BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(); + var clientProvider = new BinaryClientFormatterSinkProvider(); + var serverProvider = new BinaryServerFormatterSinkProvider(); dict ["port"] = 0; dict ["rejectRemoteRequests"] = true; serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; @@ -77,7 +77,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild public static void WatchProcess (string procId) { int id = int.Parse (procId); - Thread t = new Thread (delegate () { + var t = new Thread (delegate () { while (true) { Thread.Sleep (1000);
try {
diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.cs index e13959e8dd..f27b93dd8b 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.cs @@ -39,16 +39,17 @@ namespace MonoDevelop.Projects.Formats.MSBuild { public class BuildEngine: MarshalByRefObject, IBuildEngine { - static AutoResetEvent wordDoneEvent = new AutoResetEvent (false); + static readonly AutoResetEvent workDoneEvent = new AutoResetEvent (false); static ThreadStart workDelegate; - static object workLock = new object (); + static readonly object workLock = new object (); static Thread workThread; static CultureInfo uiCulture; static Exception workError; - ManualResetEvent doneEvent = new ManualResetEvent (false); - Dictionary<string,string> unsavedProjects = new Dictionary<string, string> (); - Engine engine; + readonly ManualResetEvent doneEvent = new ManualResetEvent (false); + readonly Dictionary<string,string> unsavedProjects = new Dictionary<string, string> (); + + internal Engine Engine { get; private set; } public void Dispose () { @@ -62,12 +63,12 @@ namespace MonoDevelop.Projects.Formats.MSBuild public void Initialize (string slnFile, CultureInfo uiCulture) { BuildEngine.uiCulture = uiCulture; - engine = InitializeEngine (slnFile); + Engine = InitializeEngine (slnFile); } public IProjectBuilder LoadProject (string file) { - return new ProjectBuilder (this, engine, file); + return new ProjectBuilder (this, file); } public void UnloadProject (IProjectBuilder pb) @@ -106,15 +107,15 @@ namespace MonoDevelop.Projects.Formats.MSBuild return engine; } - internal void UnloadProject (Engine engine, string file, bool releaseEngine) + internal void UnloadProject (string file) { lock (unsavedProjects) unsavedProjects.Remove (file); RunSTA (delegate { - var loadedProj = engine.GetLoadedProject (file); + var loadedProj = Engine.GetLoadedProject (file); if (loadedProj != null) - engine.UnloadProject (loadedProj); + Engine.UnloadProject (loadedProj); }); } @@ -150,13 +151,13 @@ namespace MonoDevelop.Projects.Formats.MSBuild // Awaken the existing thread Monitor.Pulse (threadLock); } - wordDoneEvent.WaitOne (); + workDoneEvent.WaitOne (); } if (workError != null) throw new Exception ("MSBuild operation failed", workError); } - static object threadLock = new object (); + static readonly object threadLock = new object (); static void STARunner () { @@ -168,7 +169,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild catch (Exception ex) { workError = ex; } - wordDoneEvent.Set (); + workDoneEvent.Set (); } while (Monitor.Wait (threadLock, 60000)); diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.v4.0.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.v4.0.cs index 6e2db2895f..03d365b6f0 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.v4.0.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/BuildEngine.v4.0.cs @@ -27,11 +27,8 @@ using System;
using System.Threading;
using System.IO;
-using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Remoting;
using System.Collections.Generic;
-using System.Collections;
-using Microsoft.Build.Framework;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Construction;
using System.Linq;
@@ -41,15 +38,15 @@ namespace MonoDevelop.Projects.Formats.MSBuild {
public class BuildEngine: MarshalByRefObject, IBuildEngine
{
- static AutoResetEvent wordDoneEvent = new AutoResetEvent (false);
+ static readonly AutoResetEvent workDoneEvent = new AutoResetEvent (false);
static ThreadStart workDelegate;
- static object workLock = new object ();
+ static readonly object workLock = new object ();
static Thread workThread;
static CultureInfo uiCulture;
static Exception workError;
- ManualResetEvent doneEvent = new ManualResetEvent (false);
- Dictionary<string, string> unsavedProjects = new Dictionary<string, string> ();
+ readonly ManualResetEvent doneEvent = new ManualResetEvent (false);
+ readonly Dictionary<string, string> unsavedProjects = new Dictionary<string, string> ();
ProjectCollection engine; @@ -170,13 +167,13 @@ namespace MonoDevelop.Projects.Formats.MSBuild // Awaken the existing thread
Monitor.Pulse (threadLock);
}
- wordDoneEvent.WaitOne ();
+ workDoneEvent.WaitOne ();
}
if (workError != null)
throw new Exception ("MSBuild operation failed", workError);
}
- static object threadLock = new object ();
+ static readonly object threadLock = new object ();
static void STARunner ()
{
@@ -188,7 +185,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild catch (Exception ex) {
workError = ex;
}
- wordDoneEvent.Set ();
+ workDoneEvent.Set ();
}
while (Monitor.Wait (threadLock, 60000));
diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/IProjectBuilder.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/IProjectBuilder.cs index 8253c49b33..d85aa365a2 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/IProjectBuilder.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/IProjectBuilder.cs @@ -28,7 +28,7 @@ using System; namespace MonoDevelop.Projects.Formats.MSBuild { - public interface IProjectBuilder + public interface IProjectBuilder : IDisposable { MSBuildResult[] RunTarget (string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter, MSBuildVerbosity verbosity); diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/LocalLogger.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/LocalLogger.cs index e2e22d9a0c..9aa8cf14e1 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/LocalLogger.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/LocalLogger.cs @@ -35,7 +35,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild public class LocalLogger: Logger { IEventSource eventSource; - List<MSBuildResult> results = new List<MSBuildResult> (); + readonly List<MSBuildResult> results = new List<MSBuildResult> (); string basePath; public LocalLogger (string basePath) diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.cs index 21bcc7e56b..fe80c4cd0c 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.cs @@ -39,33 +39,31 @@ namespace MonoDevelop.Projects.Formats.MSBuild { public class ProjectBuilder: MarshalByRefObject, IProjectBuilder { - Engine engine; - string file; + readonly string file; ILogWriter currentLogWriter; - MDConsoleLogger consoleLogger; - BuildEngine buildEngine; + readonly MDConsoleLogger consoleLogger; + readonly BuildEngine buildEngine; - public ProjectBuilder (BuildEngine buildEngine, Engine engine, string file) + public ProjectBuilder (BuildEngine buildEngine, string file) { this.file = file; - this.engine = engine; this.buildEngine = buildEngine; consoleLogger = new MDConsoleLogger (LoggerVerbosity.Normal, LogWriteLine, null, null);
} public void Dispose () { - buildEngine.UnloadProject (engine, file, true); + buildEngine.UnloadProject (file); } public void Refresh () {
- buildEngine.UnloadProject (engine, file, false); + buildEngine.UnloadProject (file); } public void RefreshWithContent (string projectContent) { - buildEngine.UnloadProject (engine, file, false); + buildEngine.UnloadProject (file); buildEngine.SetUnsavedProjectContent (file, projectContent); } @@ -86,15 +84,15 @@ namespace MonoDevelop.Projects.Formats.MSBuild currentLogWriter = logWriter;
LocalLogger logger = new LocalLogger (Path.GetDirectoryName (file)); - engine.UnregisterAllLoggers ();
- engine.RegisterLogger (logger); - engine.RegisterLogger (consoleLogger);
+ buildEngine.Engine.UnregisterAllLoggers ();
+ buildEngine.Engine.RegisterLogger (logger); + buildEngine.Engine.RegisterLogger (consoleLogger);
consoleLogger.Verbosity = GetVerbosity (verbosity); // We are using this BuildProject overload and the BuildSettings.None argument as a workaround to // an xbuild bug which causes references to not be resolved after the project has been built once. - engine.BuildProject (project, new string[] { target }, new Hashtable (), BuildSettings.None); + buildEngine.Engine.BuildProject (project, new [] { target }, new Hashtable (), BuildSettings.None); result = logger.BuildResult.ToArray ();
} catch (InvalidProjectFileException ex) { @@ -113,7 +111,6 @@ namespace MonoDevelop.Projects.Formats.MSBuild return LoggerVerbosity.Quiet; case MSBuildVerbosity.Minimal: return LoggerVerbosity.Minimal; - case MSBuildVerbosity.Normal: default: return LoggerVerbosity.Normal; case MSBuildVerbosity.Detailed: @@ -133,9 +130,9 @@ namespace MonoDevelop.Projects.Formats.MSBuild // We are using this BuildProject overload and the BuildSettings.None argument as a workaround to // an xbuild bug which causes references to not be resolved after the project has been built once. - engine.BuildProject (project, new string[] { "ResolveAssemblyReferences" }, new Hashtable (), BuildSettings.None); + buildEngine.Engine.BuildProject (project, new [] { "ResolveAssemblyReferences" }, new Hashtable (), BuildSettings.None); BuildItemGroup grp = project.GetEvaluatedItemsByName ("ReferencePath"); - List<string> refs = new List<string> (); + var refs = new List<string> (); foreach (BuildItem item in grp) refs.Add (UnescapeString (item.Include)); refsArray = refs.ToArray (); @@ -148,9 +145,9 @@ namespace MonoDevelop.Projects.Formats.MSBuild Project project = null; foreach (var pc in configurations) { - var p = engine.GetLoadedProject (pc.ProjectFile); + var p = buildEngine.Engine.GetLoadedProject (pc.ProjectFile); if (p == null) { - p = new Project (engine); + p = new Project (buildEngine.Engine); var content = buildEngine.GetUnsavedProjectContent (pc.ProjectFile);
if (content == null)
p.Load (pc.ProjectFile);
@@ -185,7 +182,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild bool HasXbuildFileBug () { if (hasXbuildFileBug == null) { - Project p = new Project (); + var p = new Project (); p.FullFileName = "foo"; p.LoadXml ("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"/>"); hasXbuildFileBug = p.FullFileName.Length == 0; diff --git a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.v4.0.cs b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.v4.0.cs index 339b3bd92f..8ca033df91 100644 --- a/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.v4.0.cs +++ b/main/src/core/MonoDevelop.Projects.Formats.MSBuild/MonoDevelop.Projects.Formats.MSBuild/ProjectBuilder.v4.0.cs @@ -38,11 +38,11 @@ namespace MonoDevelop.Projects.Formats.MSBuild {
public class ProjectBuilder: MarshalByRefObject, IProjectBuilder
{
- ProjectCollection engine;
- string file;
+ readonly ProjectCollection engine;
+ readonly string file;
ILogWriter currentLogWriter;
- ConsoleLogger consoleLogger;
- BuildEngine buildEngine;
+ readonly ConsoleLogger consoleLogger;
+ readonly BuildEngine buildEngine;
public ProjectBuilder (BuildEngine buildEngine, ProjectCollection engine, string file)
{
@@ -133,7 +133,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild // an xbuild bug which causes references to not be resolved after the project has been built once.
var pi = project.CreateProjectInstance ();
pi.Build ("ResolveAssemblyReferences", null);
- List<string> refs = new List<string> ();
+ var refs = new List<string> ();
foreach (ProjectItemInstance item in pi.GetItems ("ReferencePath"))
refs.Add (UnescapeString (item.EvaluatedInclude));
refsArray = refs.ToArray ();
|