X Tutup
Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit a725d63

Browse files
committed
Fixed SD2-1106: FxCop code analysis not run when building the entire solution
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2051 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
1 parent 6eda99a commit a725d63

File tree

19 files changed

+856
-308
lines changed

19 files changed

+856
-308
lines changed

src/AddIns/BackendBindings/VBNetBinding/Project/Src/VbcEncodingFixingLogger.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ namespace VBNetBinding
1818
/// </summary>
1919
public class VbcEncodingFixingLogger : IMSBuildAdditionalLogger
2020
{
21-
public ILogger CreateLogger(MSBuildEngine engine)
21+
public ILogger CreateLogger(MSBuildEngineWorker engineWorker)
2222
{
23-
return new VbcLoggerImpl(engine);
23+
return new VbcLoggerImpl(engineWorker);
2424
}
2525

2626
private class VbcLoggerImpl : ILogger
2727
{
28-
MSBuildEngine engine;
28+
MSBuildEngineWorker engineWorker;
2929

30-
public VbcLoggerImpl(MSBuildEngine engine)
30+
public VbcLoggerImpl(MSBuildEngineWorker engineWorker)
3131
{
32-
this.engine = engine;
32+
this.engineWorker = engineWorker;
3333
}
3434

3535
public LoggerVerbosity Verbosity {
@@ -80,8 +80,8 @@ void OnWarning(object sender, BuildWarningEventArgs e)
8080

8181
void FixMessage()
8282
{
83-
engine.CurrentErrorOrWarning.ErrorText = FixEncoding(engine.CurrentErrorOrWarning.ErrorText);
84-
engine.CurrentErrorOrWarning.FileName = FixEncoding(engine.CurrentErrorOrWarning.FileName);
83+
engineWorker.CurrentErrorOrWarning.ErrorText = FixEncoding(engineWorker.CurrentErrorOrWarning.ErrorText);
84+
engineWorker.CurrentErrorOrWarning.FileName = FixEncoding(engineWorker.CurrentErrorOrWarning.FileName);
8585
}
8686

8787
static string FixEncoding(string encoding)

src/AddIns/Misc/CodeAnalysis/Src/AnalysisProjectOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ class ConfigBinding : ConfigurationGuiBinding
295295
public ConfigBinding(AnalysisProjectOptions po)
296296
{
297297
this.po = po;
298+
this.TreatPropertyValueAsLiteral = false;
298299
po.OptionChanged += delegate {
299300
Helper.IsDirty = true;
300301
};

src/AddIns/Misc/CodeAnalysis/Src/FxCopLogger.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ namespace ICSharpCode.CodeAnalysis
1717
{
1818
public class FxCopLogger : IMSBuildAdditionalLogger
1919
{
20-
public ILogger CreateLogger(MSBuildEngine engine)
20+
public ILogger CreateLogger(MSBuildEngineWorker engineWorker)
2121
{
22-
return new FxCopLoggerImpl(engine);
22+
return new FxCopLoggerImpl(engineWorker);
2323
}
2424

2525
private class FxCopLoggerImpl : ILogger
2626
{
27-
MSBuildEngine engine;
27+
MSBuildEngineWorker engineWorker;
2828

29-
public FxCopLoggerImpl(MSBuildEngine engine)
29+
public FxCopLoggerImpl(MSBuildEngineWorker engineWorker)
3030
{
31-
this.engine = engine;
31+
this.engineWorker = engineWorker;
3232
}
3333

3434
public LoggerVerbosity Verbosity {
@@ -54,7 +54,7 @@ public string Parameters {
5454
public void Initialize(IEventSource eventSource)
5555
{
5656
this.eventSource = eventSource;
57-
engine.MessageView.AppendText("${res:ICSharpCode.CodeAnalysis.RunningFxCopOn} " + Path.GetFileNameWithoutExtension(engine.CurrentProjectFile) + "\r\n");
57+
engineWorker.OutputText("${res:ICSharpCode.CodeAnalysis.RunningFxCopOn} " + Path.GetFileNameWithoutExtension(engineWorker.CurrentProjectFile) + "\r\n");
5858
eventSource.ErrorRaised += OnError;
5959
eventSource.WarningRaised += OnWarning;
6060
}
@@ -85,12 +85,12 @@ void AppendError(string file, int lineNumber, int columnNumber,
8585
string category, string checkId, string subcategory)
8686
{
8787
string[] moreData = (subcategory ?? "").Split('|');
88-
BuildError err = engine.CurrentErrorOrWarning;
88+
BuildError err = engineWorker.CurrentErrorOrWarning;
8989
if (FileUtility.IsValidFileName(file) &&
9090
Path.GetFileName(file) == "SharpDevelop.CodeAnalysis.targets") {
9191
err.FileName = null;
9292
}
93-
IProject project = ProjectService.GetProject(engine.CurrentProjectFile);
93+
IProject project = ProjectService.GetProject(engineWorker.CurrentProjectFile);
9494
if (project != null) {
9595
IProjectContent pc = ParserService.GetProjectContent(project);
9696
if (pc != null) {

src/AddIns/Misc/UnitTesting/Src/RunTestCommands.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void Run(IProject project, IClass fixture, IMember test)
167167
{
168168
BuildProjectBeforeTestRun build = new BuildProjectBeforeTestRun(project);
169169
build.BuildComplete += delegate {
170-
OnBuildComplete(project, fixture, test);
170+
OnBuildComplete(build.LastBuildResults, project, fixture, test);
171171
};
172172
build.Run();
173173
}
@@ -277,9 +277,9 @@ void ShowErrorList()
277277
/// <summary>
278278
/// Runs the test for the project after a successful build.
279279
/// </summary>
280-
void OnBuildComplete(IProject project, IClass fixture, IMember test)
280+
void OnBuildComplete(BuildResults results, IProject project, IClass fixture, IMember test)
281281
{
282-
if (MSBuildEngine.LastErrorCount == 0 && IsRunningTest) {
282+
if (results.ErrorCount == 0 && IsRunningTest) {
283283
UnitTestApplicationStartHelper helper = new UnitTestApplicationStartHelper();
284284
helper.Initialize(project, fixture, test);
285285
helper.Results = Path.GetTempFileName();

src/Libraries/ICSharpCode.Build.Tasks/Project/ICSharpCode.Build.Tasks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<FileAlignment>4096</FileAlignment>
1717
<WarningLevel>4</WarningLevel>
1818
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
19+
<RunCodeAnalysis>False</RunCodeAnalysis>
1920
</PropertyGroup>
2021
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2122
<OutputPath>..\..\..\..\bin\</OutputPath>

src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Compile Include="Src\Internal\Undo\IUndoableOperation.cs" />
6565
<Compile Include="Src\Internal\Undo\UndoQueue.cs" />
6666
<Compile Include="Src\Internal\Undo\UndoStack.cs" />
67+
<Compile Include="Src\Project\MSBuildEngineWorker.cs" />
6768
<Compile Include="Src\Project\ProjectPropertyChangedEventArgs.cs" />
6869
<Compile Include="Src\Services\Debugger\BreakpointBookmark.cs" />
6970
<Compile Include="Src\Services\Debugger\BreakpointBookmarkEventArgs.cs" />

src/Main/Base/Project/Src/Commands/BuildCommands.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ public override void Run()
4848
BeforeBuild();
4949
StartBuild();
5050
} else {
51-
MSBuildEngine.AddNoSingleFileCompilationError();
51+
AddNoSingleFileCompilationError();
5252
}
5353
}
5454

55+
BuildResults lastBuildResults;
56+
57+
public BuildResults LastBuildResults {
58+
get { return lastBuildResults; }
59+
}
60+
5561
protected void CallbackMethod(BuildResults results)
5662
{
57-
MSBuildEngine.ShowResults(results);
63+
lastBuildResults = results;
64+
ShowResults(results);
5865
AfterBuild();
5966
if (BuildComplete != null)
6067
BuildComplete(this, EventArgs.Empty);
@@ -63,6 +70,35 @@ protected void CallbackMethod(BuildResults results)
6370
public abstract void StartBuild();
6471

6572
public event EventHandler BuildComplete;
73+
74+
75+
76+
public static void ShowResults(BuildResults results)
77+
{
78+
if (results != null) {
79+
TaskService.InUpdate = true;
80+
foreach (BuildError error in results.Errors) {
81+
TaskService.Add(new Task(error));
82+
}
83+
TaskService.InUpdate = false;
84+
if (results.Errors.Count > 0 && ErrorListPad.ShowAfterBuild) {
85+
WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad)).BringPadToFront();
86+
}
87+
}
88+
}
89+
90+
/// <summary>
91+
/// Notifies the user that #develp's internal MSBuildEngine
92+
/// implementation only supports compiling solutions and projects;
93+
/// it does not allow compiling individual files.
94+
/// </summary>
95+
/// <remarks>Adds a message to the <see cref="TaskService"/> and
96+
/// shows the <see cref="ErrorListPad"/>.</remarks>
97+
public static void AddNoSingleFileCompilationError()
98+
{
99+
TaskService.Add(new Task(null, StringParser.Parse("${res:BackendBindings.ExecutionManager.NoSingleFileCompilation}"), 0, 0, TaskType.Error));
100+
WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad)).BringPadToFront();
101+
}
66102
}
67103

68104
public sealed class Build : AbstractBuildMenuCommand

src/Main/Base/Project/Src/Commands/DebugCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override void Run()
2222
{
2323
Build build = new Build();
2424
build.BuildComplete += delegate {
25-
if (MSBuildEngine.LastErrorCount == 0) {
25+
if (build.LastBuildResults.ErrorCount == 0) {
2626
IProject startupProject = ProjectService.OpenSolution.StartupProject;
2727
if (startupProject != null) {
2828
startupProject.Start(withDebugger);

src/Main/Base/Project/Src/Project/BuildError.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,27 @@
1111

1212
namespace ICSharpCode.SharpDevelop.Project
1313
{
14+
[Serializable]
1415
public class BuildError
1516
{
1617
public BuildError()
1718
{
18-
this.line = 0;
19-
this.column = 0;
19+
this.line = -1;
20+
this.column = -1;
2021
this.errorCode = string.Empty;
2122
this.errorText = string.Empty;
2223
this.fileName = string.Empty;
2324
}
2425

26+
public BuildError(string fileName, string errorText)
27+
{
28+
this.line = -1;
29+
this.column = -1;
30+
this.errorCode = string.Empty;
31+
this.errorText = errorText;
32+
this.fileName = fileName;
33+
}
34+
2535
public BuildError(string fileName, int line, int column, string errorCode, string errorText)
2636
{
2737
this.line = line;
@@ -37,6 +47,7 @@ public BuildError(string fileName, int line, int column, string errorCode, strin
3747
string fileName;
3848
int line;
3949
bool warning;
50+
[NonSerialized]
4051
object tag;
4152
string contextMenuAddInTreeEntry;
4253

@@ -94,6 +105,13 @@ public bool IsWarning {
94105
}
95106
}
96107

108+
/// <summary>
109+
/// Allows to store any object with this error. An object might be attached by a custom
110+
/// MSBuild logger and later read by the context menu command.
111+
/// </summary>
112+
/// <remarks>The Tag property is [NonSerialized], which shouldn't be a problem
113+
/// because both custom loggers and context menu commands are guaranteed to run
114+
/// in the main AppDomain.</remarks>
97115
public object Tag {
98116
get {
99117
return tag;

src/Main/Base/Project/Src/Project/BuildResults.cs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using System;
99
using System.Collections.Generic;
10+
using System.Collections.ObjectModel;
1011

1112
namespace ICSharpCode.SharpDevelop.Project
1213
{
@@ -29,21 +30,54 @@ public enum BuildResultCode
2930
public class BuildResults
3031
{
3132
List<BuildError> errors = new List<BuildError>();
33+
ReadOnlyCollection<BuildError> readOnlyErrors;
3234
BuildResultCode result;
35+
int errorCount, warningCount;
3336

34-
public List<BuildError> Errors {
35-
get {
36-
return errors;
37+
/// <summary>
38+
/// Adds a build error/warning to the results.
39+
/// This method is thread-safe.
40+
/// </summary>
41+
public void Add(BuildError error)
42+
{
43+
if (error == null)
44+
throw new ArgumentNullException("error");
45+
lock (errors) {
46+
readOnlyErrors = null;
47+
errors.Add(error);
48+
if (error.IsWarning)
49+
warningCount++;
50+
else
51+
errorCount++;
3752
}
3853
}
3954

40-
public BuildResultCode Result {
55+
/// <summary>
56+
/// Gets the list of build errors or warnings.
57+
/// This property is thread-safe.
58+
/// </summary>
59+
public ReadOnlyCollection<BuildError> Errors {
4160
get {
42-
return result;
43-
}
44-
set {
45-
result = value;
61+
lock (errors) {
62+
if (readOnlyErrors == null) {
63+
readOnlyErrors = Array.AsReadOnly(errors.ToArray());
64+
}
65+
return readOnlyErrors;
66+
}
4667
}
4768
}
69+
70+
public BuildResultCode Result {
71+
get { return result; }
72+
set { result = value; }
73+
}
74+
75+
public int ErrorCount {
76+
get { return errorCount; }
77+
}
78+
79+
public int WarningCount {
80+
get { return warningCount; }
81+
}
4882
}
4983
}

0 commit comments

Comments
 (0)
X Tutup