Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1590 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
31 changed files with 978 additions and 550 deletions
@ -0,0 +1,100 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Daniel Grunwald |
||||||
|
* Date: 16.07.2006 |
||||||
|
* Time: 20:29 |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using Microsoft.Build.Framework; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.CodeAnalysis |
||||||
|
{ |
||||||
|
public class FxCopLogger : IMSBuildAdditionalLogger |
||||||
|
{ |
||||||
|
public ILogger CreateLogger(MSBuildEngine engine) |
||||||
|
{ |
||||||
|
return new FxCopLoggerImpl(engine); |
||||||
|
} |
||||||
|
|
||||||
|
private class FxCopLoggerImpl : ILogger |
||||||
|
{ |
||||||
|
MSBuildEngine engine; |
||||||
|
|
||||||
|
public FxCopLoggerImpl(MSBuildEngine engine) |
||||||
|
{ |
||||||
|
this.engine = engine; |
||||||
|
} |
||||||
|
|
||||||
|
public LoggerVerbosity Verbosity { |
||||||
|
get { |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
set { |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string Parameters { |
||||||
|
get { |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
set { |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
IEventSource eventSource; |
||||||
|
|
||||||
|
public void Initialize(IEventSource eventSource) |
||||||
|
{ |
||||||
|
this.eventSource = eventSource; |
||||||
|
engine.MessageView.AppendText("Running FxCop...\r\n"); |
||||||
|
eventSource.ErrorRaised += OnError; |
||||||
|
eventSource.WarningRaised += OnWarning; |
||||||
|
} |
||||||
|
|
||||||
|
public void Shutdown() |
||||||
|
{ |
||||||
|
if (eventSource != null) { |
||||||
|
eventSource.ErrorRaised -= OnError; |
||||||
|
eventSource.WarningRaised -= OnWarning; |
||||||
|
eventSource = null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void OnError(object sender, BuildErrorEventArgs e) |
||||||
|
{ |
||||||
|
AppendError(e.File, e.LineNumber, e.ColumnNumber, e.Code, e.Message, false); |
||||||
|
} |
||||||
|
|
||||||
|
void OnWarning(object sender, BuildWarningEventArgs e) |
||||||
|
{ |
||||||
|
AppendError(e.File, e.LineNumber, e.ColumnNumber, e.Code, e.Message, true); |
||||||
|
} |
||||||
|
|
||||||
|
void AppendError(string file, int lineNumber, int columnNumber, string code, string message, bool isWarning) |
||||||
|
{ |
||||||
|
BuildError err = engine.CurrentErrorOrWarning; |
||||||
|
if (file.StartsWith("positionof#")) { |
||||||
|
string memberName = file.Substring(11); |
||||||
|
file = ""; |
||||||
|
IProject project = ProjectService.GetProject(engine.CurrentProjectFile); |
||||||
|
if (project != null) { |
||||||
|
IProjectContent pc = ParserService.GetProjectContent(project); |
||||||
|
if (pc != null) { |
||||||
|
Position pos = pc.GetPosition(memberName); |
||||||
|
if (pos != null && pos.Cu != null) { |
||||||
|
err.FileName = pos.Cu.FileName ?? ""; |
||||||
|
err.Line = pos.Line; |
||||||
|
err.Column = pos.Column; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,131 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Globalization; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Project |
||||||
|
{ |
||||||
|
public class BuildError |
||||||
|
{ |
||||||
|
public BuildError() |
||||||
|
{ |
||||||
|
this.line = 0; |
||||||
|
this.column = 0; |
||||||
|
this.errorCode = string.Empty; |
||||||
|
this.errorText = string.Empty; |
||||||
|
this.fileName = string.Empty; |
||||||
|
} |
||||||
|
|
||||||
|
public BuildError(string fileName, int line, int column, string errorCode, string errorText) |
||||||
|
{ |
||||||
|
this.line = line; |
||||||
|
this.column = column; |
||||||
|
this.errorCode = errorCode; |
||||||
|
this.errorText = errorText; |
||||||
|
this.fileName = fileName; |
||||||
|
} |
||||||
|
|
||||||
|
int column; |
||||||
|
string errorCode; |
||||||
|
string errorText; |
||||||
|
string fileName; |
||||||
|
int line; |
||||||
|
bool warning; |
||||||
|
object tag; |
||||||
|
string contextMenuAddInTreeEntry; |
||||||
|
|
||||||
|
public int Column { |
||||||
|
get { |
||||||
|
return column; |
||||||
|
} |
||||||
|
set { |
||||||
|
column = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string ErrorCode { |
||||||
|
get { |
||||||
|
return errorCode; |
||||||
|
} |
||||||
|
set { |
||||||
|
errorCode = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string ErrorText { |
||||||
|
get { |
||||||
|
return errorText; |
||||||
|
} |
||||||
|
set { |
||||||
|
errorText = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string FileName { |
||||||
|
get { |
||||||
|
return fileName; |
||||||
|
} |
||||||
|
set { |
||||||
|
fileName = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int Line { |
||||||
|
get { |
||||||
|
return line; |
||||||
|
} |
||||||
|
set { |
||||||
|
line = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsWarning { |
||||||
|
get { |
||||||
|
return warning; |
||||||
|
} |
||||||
|
set { |
||||||
|
warning = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public object Tag { |
||||||
|
get { |
||||||
|
return tag; |
||||||
|
} |
||||||
|
set { |
||||||
|
tag = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string ContextMenuAddInTreeEntry { |
||||||
|
get { |
||||||
|
return contextMenuAddInTreeEntry; |
||||||
|
} |
||||||
|
set { |
||||||
|
contextMenuAddInTreeEntry = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override string ToString() |
||||||
|
{ |
||||||
|
if (string.IsNullOrEmpty(this.FileName)) { |
||||||
|
return string.Format(CultureInfo.CurrentCulture, |
||||||
|
"{0} {1}: {2}", |
||||||
|
StringParser.Parse(this.IsWarning ? "${res:Global.WarningText}" : "${res:Global.ErrorText}"), |
||||||
|
this.ErrorCode, this.ErrorText); |
||||||
|
} else { |
||||||
|
return string.Format(CultureInfo.CurrentCulture, |
||||||
|
"{0}({1},{2}) : {3} {4}: {5}", |
||||||
|
this.FileName, this.Line, this.Column, |
||||||
|
StringParser.Parse(this.IsWarning ? "${res:Global.WarningText}" : "${res:Global.ErrorText}"), |
||||||
|
this.ErrorCode, this.ErrorText); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Project |
||||||
|
{ |
||||||
|
public enum BuildResultCode |
||||||
|
{ |
||||||
|
None, |
||||||
|
/// <summary>Build finished successful.</summary>
|
||||||
|
Success, |
||||||
|
/// <summary>A build error occurred, see BuildResults.Error collection</summary>
|
||||||
|
Error, |
||||||
|
/// <summary>A project build file is not valid</summary>
|
||||||
|
BuildFileError, |
||||||
|
/// <summary>Build was not executed because another build is running</summary>
|
||||||
|
MSBuildAlreadyRunning |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Class wrapping the results of a build run.
|
||||||
|
/// </summary>
|
||||||
|
public class BuildResults |
||||||
|
{ |
||||||
|
List<BuildError> errors = new List<BuildError>(); |
||||||
|
BuildResultCode result; |
||||||
|
|
||||||
|
public List<BuildError> Errors { |
||||||
|
get { |
||||||
|
return errors; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public BuildResultCode Result { |
||||||
|
get { |
||||||
|
return result; |
||||||
|
} |
||||||
|
set { |
||||||
|
result = value; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,164 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Daniel Grunwald |
||||||
|
* Date: 16.07.2006 |
||||||
|
* Time: 19:51 |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using Microsoft.Build.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Project |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interface for elements in /SharpDevelop/MSBuildEngine/AdditionalLoggers
|
||||||
|
/// </summary>
|
||||||
|
public interface IMSBuildAdditionalLogger |
||||||
|
{ |
||||||
|
ILogger CreateLogger(MSBuildEngine engine); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates <see cref="IMSBuildAdditionalLogger"/> objects that are only
|
||||||
|
/// activated when a specific MSBuild task is running.
|
||||||
|
/// </summary>
|
||||||
|
/// <attribute name="class" use="required">
|
||||||
|
/// Name of the IMSBuildAdditionalLogger class.
|
||||||
|
/// </attribute>
|
||||||
|
/// <attribute name="taskname" use="required">
|
||||||
|
/// Specifies the name of the MSBuild task that must be running for
|
||||||
|
/// this logger to be active.
|
||||||
|
/// </attribute>
|
||||||
|
/// <example>
|
||||||
|
/// <TaskBoundAdditionalLogger
|
||||||
|
/// id = "FxCopLogger"
|
||||||
|
/// taskname = "FxCop"
|
||||||
|
/// class = "ICSharpCode.CodeAnalysis.FxCopLogger"/>
|
||||||
|
/// </example>
|
||||||
|
/// <usage>Only in /SharpDevelop/MSBuildEngine/AdditionalLoggers</usage>
|
||||||
|
/// <returns>
|
||||||
|
/// A IMSBuildAdditionalLogger object that lazy-loads the specified
|
||||||
|
/// IMSBuildAdditionalLogger when the specified task is running.
|
||||||
|
/// </returns>
|
||||||
|
public class TaskBoundAdditionalLoggerDoozer : IDoozer |
||||||
|
{ |
||||||
|
public bool HandleConditions { |
||||||
|
get { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public object BuildItem(object caller, Codon codon, System.Collections.ArrayList subItems) |
||||||
|
{ |
||||||
|
return new TaskBoundAdditionalLoggerDescriptor(codon); |
||||||
|
} |
||||||
|
|
||||||
|
private class TaskBoundAdditionalLoggerDescriptor : IMSBuildAdditionalLogger |
||||||
|
{ |
||||||
|
internal string taskname; |
||||||
|
internal string classname; |
||||||
|
internal AddIn addIn; |
||||||
|
|
||||||
|
public TaskBoundAdditionalLoggerDescriptor(Codon codon) |
||||||
|
{ |
||||||
|
classname = codon.Properties["class"]; |
||||||
|
taskname = codon.Properties["taskname"]; |
||||||
|
addIn = codon.AddIn; |
||||||
|
} |
||||||
|
|
||||||
|
public ILogger CreateLogger(MSBuildEngine engine) |
||||||
|
{ |
||||||
|
return new TaskBoundAdditionalLogger(this, engine); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private class TaskBoundAdditionalLogger : ILogger |
||||||
|
{ |
||||||
|
TaskBoundAdditionalLoggerDescriptor desc; |
||||||
|
MSBuildEngine engine; |
||||||
|
ILogger baseLogger; |
||||||
|
bool isActive; |
||||||
|
|
||||||
|
public TaskBoundAdditionalLogger(TaskBoundAdditionalLoggerDescriptor desc, MSBuildEngine engine) |
||||||
|
{ |
||||||
|
this.desc = desc; |
||||||
|
this.engine = engine; |
||||||
|
} |
||||||
|
|
||||||
|
void CreateBaseLogger() |
||||||
|
{ |
||||||
|
if (baseLogger == null) { |
||||||
|
object obj = desc.addIn.CreateObject(desc.classname); |
||||||
|
baseLogger = obj as ILogger; |
||||||
|
IMSBuildAdditionalLogger addLog = obj as IMSBuildAdditionalLogger; |
||||||
|
if (addLog != null) { |
||||||
|
baseLogger = addLog.CreateLogger(engine); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void OnTaskStarted(object sender, TaskStartedEventArgs e) |
||||||
|
{ |
||||||
|
if (desc.taskname.Equals(e.TaskName, StringComparison.InvariantCultureIgnoreCase)) { |
||||||
|
CreateBaseLogger(); |
||||||
|
if (baseLogger != null) { |
||||||
|
baseLogger.Initialize(eventSource); |
||||||
|
isActive = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void OnTaskFinished(object sender, TaskFinishedEventArgs e) |
||||||
|
{ |
||||||
|
if (isActive) { |
||||||
|
baseLogger.Shutdown(); |
||||||
|
isActive = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#region ILogger interface implementation
|
||||||
|
LoggerVerbosity verbosity = LoggerVerbosity.Minimal; |
||||||
|
|
||||||
|
public LoggerVerbosity Verbosity { |
||||||
|
get { |
||||||
|
return verbosity; |
||||||
|
} |
||||||
|
set { |
||||||
|
verbosity = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
string parameters; |
||||||
|
|
||||||
|
public string Parameters { |
||||||
|
get { |
||||||
|
return parameters; |
||||||
|
} |
||||||
|
set { |
||||||
|
parameters = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
IEventSource eventSource; |
||||||
|
|
||||||
|
public void Initialize(IEventSource eventSource) |
||||||
|
{ |
||||||
|
this.eventSource = eventSource; |
||||||
|
eventSource.TaskStarted += OnTaskStarted; |
||||||
|
eventSource.TaskFinished += OnTaskFinished; |
||||||
|
} |
||||||
|
|
||||||
|
public void Shutdown() |
||||||
|
{ |
||||||
|
OnTaskFinished(null, null); |
||||||
|
if (eventSource != null) { |
||||||
|
eventSource.TaskStarted -= OnTaskStarted; |
||||||
|
eventSource.TaskFinished -= OnTaskFinished; |
||||||
|
eventSource = null; |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue