Browse Source

BuildModifiedProjectsOnlyService: remove static state

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
574d69cd6f
  1. 4
      src/Main/Base/Project/Util/ReactiveExtensions.cs
  2. 132
      src/Main/SharpDevelop/Project/Build/BuildEngine.cs
  3. 18
      src/Main/SharpDevelop/Project/Build/BuildModifiedProjectsOnlyService.cs

4
src/Main/Base/Project/Util/ReactiveExtensions.cs

@ -64,7 +64,7 @@ namespace ICSharpCode.SharpDevelop @@ -64,7 +64,7 @@ namespace ICSharpCode.SharpDevelop
public TaskToObserverSubscription(Func<CancellationToken, Action<T>, Task> func, IObserver<T> observer)
{
this.observer = observer;
func(cts.Token, Callback).ContinueWith(TaskCompleted);
func(cts.Token, Callback).ContinueWith(TaskCompleted).FireAndForget();
}
public TaskToObserverSubscription(Func<IProgressMonitor, Action<T>, Task> func, IProgressMonitor progressMonitor, IObserver<T> observer)
@ -72,7 +72,7 @@ namespace ICSharpCode.SharpDevelop @@ -72,7 +72,7 @@ namespace ICSharpCode.SharpDevelop
this.observer = observer;
this.progressMonitor = progressMonitor;
this.childProgressMonitor = progressMonitor.CreateSubTask(1, cts.Token);
func(childProgressMonitor, Callback).ContinueWith(TaskCompleted);
func(childProgressMonitor, Callback).ContinueWith(TaskCompleted).FireAndForget();
}
void Callback(T item)

132
src/Main/SharpDevelop/Project/Build/BuildEngine.cs

@ -23,138 +23,6 @@ namespace ICSharpCode.SharpDevelop.Project @@ -23,138 +23,6 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary>
sealed class BuildEngine
{
#region Building in the SharpDevelop GUI
/*static CancellationTokenSource guiBuildCancellation;
static IAnalyticsMonitorTrackedFeature guiBuildTrackedFeature;
/// <summary>
/// Starts to run a build inside the SharpDevelop GUI.
/// Only one build can run inside the GUI at one time.
/// </summary>
/// <param name="project">The project/solution to build.</param>
/// <param name="options">The build options.</param>
public static void BuildInGui(IBuildable project, BuildOptions options)
{
if (project == null)
throw new ArgumentNullException("project");
if (options == null)
throw new ArgumentNullException("options");
WorkbenchSingleton.AssertMainThread();
if (guiBuildCancellation != null) {
BuildResults results = new BuildResults();
SD.StatusBar.SetMessage(Core.ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning"));
BuildError error = new BuildError(null, Core.ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning"));
results.Add(error);
TaskService.Add(new SDTask(error));
results.Result = BuildResultCode.MSBuildAlreadyRunning;
if (options.Callback != null) {
options.Callback(results);
}
} else {
guiBuildCancellation = new CancellationTokenSource();
IProgressMonitor progressMonitor = SD.StatusBar.CreateProgressMonitor(guiBuildCancellation.Token);
guiBuildTrackedFeature = SD.AnalyticsMonitor.TrackFeature("ICSharpCode.SharpDevelop.Project.BuildEngine.Build");
SD.StatusBar.SetMessage(StringParser.Parse("${res:MainWindow.CompilerMessages.BuildVerb}..."));
ProjectService.RaiseEventBuildStarted(new BuildEventArgs(project, options));
StartBuild(project, options,
new MessageViewSink(TaskService.BuildMessageViewCategory, progressMonitor, SD.StatusBar));
}
}
/// <summary>
/// Gets whether there is a build currently running inside the SharpDevelop GUI.
/// </summary>
public static bool IsGuiBuildRunning {
get {
WorkbenchSingleton.AssertMainThread();
return guiBuildCancellation != null;
}
}
/// <summary>
/// Cancels the build currently running inside the SharpDevelop GUI.
/// This method does nothing if no build is running.
/// </summary>
public static void CancelGuiBuild()
{
WorkbenchSingleton.AssertMainThread();
if (guiBuildCancellation != null) {
guiBuildCancellation.Cancel();
}
}
/// <summary>
/// This error message sink is used for GUI builds.
/// </summary>
sealed class MessageViewSink : IBuildFeedbackSink
{
MessageViewCategory messageView;
IProgressMonitor progressMonitor;
IStatusBarService statusBarService;
public MessageViewSink(MessageViewCategory messageView, IProgressMonitor progressMonitor, IStatusBarService statusBarService)
{
Debug.Assert(messageView != null);
Debug.Assert(progressMonitor != null);
Debug.Assert(statusBarService != null);
this.messageView = messageView;
this.progressMonitor = progressMonitor;
this.statusBarService = statusBarService;
}
public IProgressMonitor ProgressMonitor {
get { return progressMonitor; }
}
public void ReportError(BuildError error)
{
WorkbenchSingleton.SafeThreadAsyncCall(
delegate {
TaskService.Add(new SDTask(error));
});
}
public void ReportMessage(string message)
{
messageView.AppendLine(message);
}
public void Done(bool success)
{
throw new InvalidOperationException("The Done(IBuildable,BuildOptions,BuildResults) method should be called instead.");
}
public void Done(IBuildable buildable, BuildOptions options, BuildResults results)
{
WorkbenchSingleton.SafeThreadAsyncCall(
delegate {
guiBuildCancellation = null;
if (guiBuildTrackedFeature != null) {
guiBuildTrackedFeature.EndTracking();
guiBuildTrackedFeature = null;
}
string message;
if (results.Result == BuildResultCode.Cancelled) {
message = "${res:MainWindow.CompilerMessages.BuildCancelled}";
} else {
if (results.Result == BuildResultCode.Success)
message = "${res:MainWindow.CompilerMessages.BuildFinished}";
else
message = "${res:MainWindow.CompilerMessages.BuildFailed}";
if (results.ErrorCount > 0)
message += " " + results.ErrorCount + " error(s)";
if (results.WarningCount > 0)
message += " " + results.WarningCount + " warning(s)";
}
statusBarService.SetMessage(message);
ProjectService.RaiseEventBuildFinished(new BuildEventArgs(buildable, options, results));
});
}
}*/
#endregion
#region StartBuild
/// <summary>
/// Starts to run a build.

18
src/Main/SharpDevelop/Project/Build/BuildModifiedProjectsOnlyService.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -19,7 +19,7 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary>
class BuildModifiedProjectsOnlyService
{
static readonly Dictionary<IProject, CompilationPass> unmodifiedProjects = new Dictionary<IProject, CompilationPass>();
readonly Dictionary<IProject, CompilationPass> unmodifiedProjects = new Dictionary<IProject, CompilationPass>();
public BuildModifiedProjectsOnlyService(IBuildService buildService)
{
@ -83,7 +83,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -83,7 +83,7 @@ namespace ICSharpCode.SharpDevelop.Project
LoggingService.Debug(pair.Key.Name + ": " + pair.Value);
}
}
return new WrapperFactory(setting).GetWrapper(buildable);
return new WrapperFactory(this, setting).GetWrapper(buildable);
case BuildDetection.RegularBuild:
return buildable;
default:
@ -141,10 +141,12 @@ namespace ICSharpCode.SharpDevelop.Project @@ -141,10 +141,12 @@ namespace ICSharpCode.SharpDevelop.Project
{
public readonly BuildDetection Setting;
public readonly CompilationPass CurrentPass = new CompilationPass();
internal readonly BuildModifiedProjectsOnlyService Service;
readonly Dictionary<IBuildable, IBuildable> dict = new Dictionary<IBuildable, IBuildable>();
public WrapperFactory(BuildDetection setting)
public WrapperFactory(BuildModifiedProjectsOnlyService service, BuildDetection setting)
{
this.Service = service;
this.Setting = setting;
}
@ -163,11 +165,13 @@ namespace ICSharpCode.SharpDevelop.Project @@ -163,11 +165,13 @@ namespace ICSharpCode.SharpDevelop.Project
{
internal readonly IBuildable wrapped;
internal readonly WrapperFactory factory;
internal readonly BuildModifiedProjectsOnlyService service;
public Wrapper(IBuildable wrapped, WrapperFactory factory)
{
this.wrapped = wrapped;
this.factory = factory;
this.service = factory.Service;
}
public string Name {
@ -217,8 +221,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -217,8 +221,8 @@ namespace ICSharpCode.SharpDevelop.Project
if (p == null) {
return await wrapped.BuildAsync(options, feedbackSink, progressMonitor);
} else {
lock (unmodifiedProjects) {
if (!unmodifiedProjects.TryGetValue(p, out lastCompilationPass)) {
lock (service.unmodifiedProjects) {
if (!service.unmodifiedProjects.TryGetValue(p, out lastCompilationPass)) {
lastCompilationPass = null;
}
}
@ -240,8 +244,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -240,8 +244,8 @@ namespace ICSharpCode.SharpDevelop.Project
lastCompilationPass = factory.CurrentPass;
var success = await wrapped.BuildAsync(options, feedbackSink, progressMonitor);
if (success) {
lock (unmodifiedProjects) {
unmodifiedProjects[p] = factory.CurrentPass;
lock (service.unmodifiedProjects) {
service.unmodifiedProjects[p] = factory.CurrentPass;
}
}
return success;

Loading…
Cancel
Save