Class ExtensionMethodsProjectAnalysis
Provides a set of extension methods to run analysis (only available with a Build Machine license) and to collect existing analysis results references.
public static class ExtensionMethodsProjectAnalysis
- Inheritance
-
ExtensionMethodsProjectAnalysis
- Inherited Members
Methods (32)
AnalyzeAssemblies(ICollection<IAbsoluteFilePath>)
Analyze a set of assemblies, in-process and synchronously, and return a IAnalysisResult object. (Only available with a Build Machine license).
public static IAnalysisResult AnalyzeAssemblies(this ICollection<IAbsoluteFilePath> applicationAssembliesPath)
Parameters
applicationAssembliesPathICollection<IAbsoluteFilePath>A collection of IAbsoluteFilePath object that contains assemblies file paths.
Returns
- IAnalysisResult
The analysis result.
Remarks
Calling this method will typically takes a few seconds, the time the analysis is performed.
Internally, this methods creates a temporary project with the method CreateTemporaryProject(ICollection<IAbsoluteFilePath>, TemporaryProjectMode) and then call RunAnalysis(IProject, string) on this temporary project.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.
Exceptions
- Exception
Cannot run analysis without a Build Machine license.
- ProjectException
Problem with creating a temporary project.
- AnalysisException
The analysis execution failed. The InnerException contains additional information concerning the failure.
AnalyzeAssemblies(ICollection<string>)
Analyze a set of assemblies, in-process and synchronously, and return a IAnalysisResult object. (Only available with a Build Machine license).
public static IAnalysisResult AnalyzeAssemblies(this ICollection<string> applicationAssembliesPath)
Parameters
applicationAssembliesPathICollection<string>A collection of string that contains assemblies file paths.
Returns
- IAnalysisResult
The analysis result.
Remarks
Calling this method will typically takes a few seconds, the time the analysis is performed.
Internally, this methods creates a temporary project with the method CreateTemporaryProject(ICollection<IAbsoluteFilePath>, TemporaryProjectMode) and then call RunAnalysis(IProject, string) on this temporary project.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.
Exceptions
- ProjectException
Problem with creating a temporary project.
- Exception
Cannot run analysis without a Build Machine license.
- AnalysisException
The analysis execution failed. The InnerException contains additional information concerning the failure.
- ArgumentNullException
One of the string in
applicationAssembliesPathis null.- ArgumentException
One of the string in
applicationAssembliesPathis not a valid absolute file path.- FileNotFoundException
One absolute file path in
applicationAssembliesPathdoesn't exist.
BuildAnalysisResultRefFor(IProject, IAbsoluteFilePath)
Create an IAnalysisResultRef object from a project, an analysis result file (.ndar extension) and a date.
public static IAnalysisResultRef BuildAnalysisResultRefFor(this IProject project, IAbsoluteFilePath analysisResultFilePath)
Parameters
projectIProjectThe project.
analysisResultFilePathIAbsoluteFilePathThe analysis result file path (.ndar extension).
Returns
- IAnalysisResultRef
The analysis result reference.
Remarks
The analysis result is not loaded, only the reference to the analysis result is returned.
The IAnalysisResultRef.Date is inferred from the directy path if the analysis result parent directory path. NDepend stores historic analysis result in a folder hierarchy named after YYYY_MM and then sub folder DD_HH_MM_SS.
If the analysis result file is not stored in such folder, IAnalysisResultRef.Date is the last write date of the analysis result file.
Exceptions
- FileNotFoundException
This exception is thrown if the analysis result file
analysisResultFilePathdoesn't exist.
CanAllPathsReferencedBeResolvedAsAbsolute(IProject)
This method returns a list of string, that each describes in plain-english, the failure to resolve as absolute a path referenced by project. The list returned is empty if all paths can be resolved as absolute.
public static IReadOnlyList<string> CanAllPathsReferencedBeResolvedAsAbsolute(this IProject project)
Parameters
projectIProjectThe project on which to try to resolve paths referenced as absolute.
Returns
ComputeIssues(IAnalysisResult)
This method compiles and runs all rules against analysisResult.CodeBase and returns all issues in an IIssuesSet object.
public static IIssuesSet ComputeIssues(this IAnalysisResult analysisResult)
Parameters
analysisResultIAnalysisResultThe analysis result on which to compute the issues.
Returns
Remarks
This method calls ComputeIssues(IAnalysisResult, TimeSpan, IssueReferenceRecord, out ICodeBaseView, out IEnumerable<IIssueComputationLog>) with one day for cqlinqQueryExecTimeOut parameter, and with IssueReferenceRecord.No value for issueReferenceRecord parameter.
ComputeIssues(IAnalysisResult, TimeSpan, IssueReferenceRecord, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)
This method compiles and runs all rules on analysisResult.CodeBase and returns all issues in an IIssuesSet object.
public static IIssuesSet ComputeIssues(this IAnalysisResult analysisResult, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out ICodeBaseView justMyCode, out IEnumerable<IIssueComputationLog> logs)
Parameters
analysisResultIAnalysisResultThe analysis result on which to compute the issues.
cqlinqQueryExecTimeOutTimeSpanThe code query execution time-out duration.
issueReferenceRecordIssueReferenceRecordA value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.
justMyCodeICodeBaseViewThe just-my-codeICodeBaseView object computed, against which rules have been executed.
logsIEnumerable<IIssueComputationLog>A sequence of plain-english logs that represent all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSet object.
Returns
Remarks
The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project,
the active rules in active rule file(s) referenced by this project,
and the active rules found in analysisResult.RulesExtractedFromCode.
The issues debt is computed and formatted against this project IProjectDebtSettings.
Before running the rules, this method also computes the just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns it through justMyCode .
Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules.
This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.
ComputeIssuesAndTrendMetrics(IAnalysisResult, TimeSpan, IssueReferenceRecord, out IReadOnlyList<MetricValue>, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)
This method compiles and runs all rules and trend metrics on analysisResult.CodeBase and returns all issues in an IIssuesSet object and returns also all trendMetricsValues.
public static IIssuesSet ComputeIssuesAndTrendMetrics(this IAnalysisResult analysisResult, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out IReadOnlyList<MetricValue> trendMetricsValues, out ICodeBaseView justMyCode, out IEnumerable<IIssueComputationLog> logs)
Parameters
analysisResultIAnalysisResultThe analysis result on which to compute the issues.
cqlinqQueryExecTimeOutTimeSpanThe code query execution time-out duration.
issueReferenceRecordIssueReferenceRecordA value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.
trendMetricsValuesIReadOnlyList<MetricValue>The trend metrics values extracted from the project
analysisResult.AnalysisResultRef.Project.justMyCodeICodeBaseViewThe just-my-codeICodeBaseView object computed, against which rules have been executed.
logsIEnumerable<IIssueComputationLog>A sequence of plain-english logs that represent all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSet object.
Returns
Remarks
This method is optimized and takes account of the returned IIssuesSet object to compute trend metrics.
Hence this method is almost twice faster than calling first ComputeIssues(IAnalysisResult) and then LogTrendMetrics(IAnalysisResult, DateTime).
If you wish to log the obtained trendMetricsValues first call TryComputeLogLabel(IProject, ICodeBase, out string) and then call LogTrendMetrics(IAnalysisResult, DateTime).
The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project,
the active rules in active rule file(s) referenced by this project,
and the active rules found in analysisResult.RulesExtractedFromCode.
The issues debt is computed and formatted against this project IProjectDebtSettings.
Before running the rules, this method also computes the just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns it through justMyCode .
Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules.
This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.
ComputeIssuesDiff(IAnalysisResult, ICompareContext)
This method compiles and runs all rules against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object.
public static IIssuesSetDiff ComputeIssuesDiff(this IAnalysisResult analysisResult, ICompareContext compareContext)
Parameters
analysisResultIAnalysisResultThe analysis result on which to compute the issues.
compareContextICompareContextIssues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.
Returns
Remarks
This method calls ComputeIssuesDiff(IAnalysisResult, ICompareContext, TimeSpan, IssueReferenceRecord, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>) with one day for cqlinqQueryExecTimeOut parameter, and with IssueReferenceRecord.No for issueReferenceRecord parameter.
ComputeIssuesDiff(IAnalysisResult, ICompareContext, IRuleIssues[], IRuleIssues[], TimeSpan, IssueReferenceRecord, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)
This method compiles and runs all rules against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object.
public static IIssuesSetDiff ComputeIssuesDiff(this IAnalysisResult analysisResult, ICompareContext compareContext, IRuleIssues[] newIssuesImported, IRuleIssues[] oldIssuesImported, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out ICodeBaseView justMyCodeNew, out ICodeBaseView justMyCodeOld, out IEnumerable<IIssueComputationLog> logs)
Parameters
analysisResultIAnalysisResultThe analysis result on which to compute the issues.
compareContextICompareContextIssues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.
newIssuesImportedIRuleIssues[]Issues imported for the newer snapshot.
oldIssuesImportedIRuleIssues[]Issues imported for the older snapshot.
cqlinqQueryExecTimeOutTimeSpanThe code query execution time-out duration.
issueReferenceRecordIssueReferenceRecordA value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.
justMyCodeNewICodeBaseViewThe just-my-codeICodeBaseView object computed for
compareContext.NewerCodeBase, against which rules have been executed.justMyCodeOldICodeBaseViewThe just-my-codeICodeBaseView object computed for
compareContext.OlderCodeBase, against which rules have been executed.logsIEnumerable<IIssueComputationLog>A sequence of plain-english log that represents all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSetDiff object.
Returns
Remarks
The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project,
the active rules in active rule file(s) referenced by this project,
and the active rules found in analysisResult.RulesExtractedFromCode.
The issues debt is computed and formatted against this project IProjectDebtSettings.
Before running the rules, this method also computes both just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns them through justMyCodeOld and justMyCodeNew.
Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules.
This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.
Rules are executed twice against compareContextNewerCodeBase and OlderCodeBase,
except rule that relies on diff, like the rule API breaking change for example.
Such rule is only executed once and its issues are only present in the NewerIssuesSet of the returned IIssuesSetDiff object.
If a rule has compilation or execution error on one code base snapshot but not on the other one,
a log is emitted and issues obtained from execution against the other snapshot are not taken account in the returned IIssuesSetDiff object.
ComputeIssuesDiff(IAnalysisResult, ICompareContext, TimeSpan, IssueReferenceRecord, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)
This method compiles and runs all rules against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object.
public static IIssuesSetDiff ComputeIssuesDiff(this IAnalysisResult analysisResult, ICompareContext compareContext, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out ICodeBaseView justMyCodeNew, out ICodeBaseView justMyCodeOld, out IEnumerable<IIssueComputationLog> logs)
Parameters
analysisResultIAnalysisResultThe analysis result on which to compute the issues.
compareContextICompareContextIssues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.
cqlinqQueryExecTimeOutTimeSpanThe code query execution time-out duration.
issueReferenceRecordIssueReferenceRecordA value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.
justMyCodeNewICodeBaseViewThe just-my-codeICodeBaseView object computed for
compareContext.NewerCodeBase, against which rules have been executed.justMyCodeOldICodeBaseViewThe just-my-codeICodeBaseView object computed for
compareContext.OlderCodeBase, against which rules have been executed.logsIEnumerable<IIssueComputationLog>A sequence of plain-english log that represents all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSetDiff object.
Returns
Remarks
The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project,
the active rules in active rule file(s) referenced by this project,
and the active rules found in analysisResult.RulesExtractedFromCode.
The issues debt is computed and formatted against this project IProjectDebtSettings.
Before running the rules, this method also computes both just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns them through justMyCodeOld and justMyCodeNew.
Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules.
This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.
Rules are executed twice against compareContextNewerCodeBase and OlderCodeBase,
except rule that relies on diff, like the rule API breaking change for example.
Such rule is only executed once and its issues are only present in the NewerIssuesSet of the returned IIssuesSetDiff object.
If a rule has compilation or execution error on one code base snapshot but not on the other one,
a log is emitted and issues obtained from execution against the other snapshot are not taken account in the returned IIssuesSetDiff object.
ComputeIssuesDiffAndTrendMetrics(IAnalysisResult, ICompareContext, IRuleIssues[], IRuleIssues[], TimeSpan, IssueReferenceRecord, out IReadOnlyList<MetricValue>, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)
This method compiles and runs all rules and trend metrics against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object and returns also all trendMetricsValues.
public static IIssuesSetDiff ComputeIssuesDiffAndTrendMetrics(this IAnalysisResult analysisResult, ICompareContext compareContext, IRuleIssues[] newIssuesImported, IRuleIssues[] oldIssuesImported, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out IReadOnlyList<MetricValue> trendMetricsValues, out ICodeBaseView justMyCodeNew, out ICodeBaseView justMyCodeOld, out IEnumerable<IIssueComputationLog> logs)
Parameters
analysisResultIAnalysisResultThe analysis result on which to compute the issues.
compareContextICompareContextIssues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.
newIssuesImportedIRuleIssues[]Issues imported for the newer build.
oldIssuesImportedIRuleIssues[]Issues imported for the older build.
cqlinqQueryExecTimeOutTimeSpanThe code query execution time-out duration.
issueReferenceRecordIssueReferenceRecordA value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.
trendMetricsValuesIReadOnlyList<MetricValue>The trend metrics values extracted from the project
analysisResult.AnalysisResultRef.Project.justMyCodeNewICodeBaseViewThe just-my-codeICodeBaseView object computed for
compareContext.NewerCodeBase, against which rules have been executed.justMyCodeOldICodeBaseViewThe just-my-codeICodeBaseView object computed for
compareContext.OlderCodeBase, against which rules have been executed.logsIEnumerable<IIssueComputationLog>A sequence of plain-english log that represents all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSetDiff object.
Returns
Remarks
This method is optimized and takes account of the returned IIssuesSetDiff object to compute trend metrics.
Hence this method is almost twice faster than calling first ComputeIssuesDiff(IAnalysisResult, ICompareContext) and then LogTrendMetrics(IAnalysisResult, DateTime).
If you wish to log the obtained trendMetricsValues first call TryComputeLogLabel(IProject, ICodeBase, out string) and then call LogTrendMetrics(IAnalysisResult, DateTime).
The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project,
the active rules in active rule file(s) referenced by this project,
and the active rules found in analysisResult.RulesExtractedFromCode.
The issues debt is computed and formatted against this project IProjectDebtSettings.
Before running the rules, this method also computes both just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns them through justMyCodeOld and justMyCodeNew.
Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules.
This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.
Rules are executed twice against compareContextNewerCodeBase and OlderCodeBase,
except rule that relies on diff, like the rule API breaking change for example.
Such rule is only executed once and its issues are only present in the NewerIssuesSet of the returned IIssuesSetDiff object.
If a rule has compilation or execution error on one code base snapshot but not on the other one,
a log is emitted and issues obtained from execution against the other snapshot are not taken account in the returned IIssuesSetDiff object.
ComputeIssuesDiffAndTrendMetrics(IAnalysisResult, ICompareContext, TimeSpan, IssueReferenceRecord, out IReadOnlyList<MetricValue>, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)
This method compiles and runs all rules and trend metrics against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object and returns also all trendMetricsValues.
public static IIssuesSetDiff ComputeIssuesDiffAndTrendMetrics(this IAnalysisResult analysisResult, ICompareContext compareContext, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out IReadOnlyList<MetricValue> trendMetricsValues, out ICodeBaseView justMyCodeNew, out ICodeBaseView justMyCodeOld, out IEnumerable<IIssueComputationLog> logs)
Parameters
analysisResultIAnalysisResultThe analysis result on which to compute the issues.
compareContextICompareContextIssues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.
cqlinqQueryExecTimeOutTimeSpanThe code query execution time-out duration.
issueReferenceRecordIssueReferenceRecordA value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.
trendMetricsValuesIReadOnlyList<MetricValue>The trend metrics values extracted from the project
analysisResult.AnalysisResultRef.Project.justMyCodeNewICodeBaseViewThe just-my-codeICodeBaseView object computed for
compareContext.NewerCodeBase, against which rules have been executed.justMyCodeOldICodeBaseViewThe just-my-codeICodeBaseView object computed for
compareContext.OlderCodeBase, against which rules have been executed.logsIEnumerable<IIssueComputationLog>A sequence of plain-english log that represents all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSetDiff object.
Returns
Remarks
This method is optimized and takes account of the returned IIssuesSetDiff object to compute trend metrics.
Hence this method is almost twice faster than calling first ComputeIssuesDiff(IAnalysisResult, ICompareContext) and then LogTrendMetrics(IAnalysisResult, DateTime).
If you wish to log the obtained trendMetricsValues first call TryComputeLogLabel(IProject, ICodeBase, out string) and then call LogTrendMetrics(IAnalysisResult, DateTime).
The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project,
the active rules in active rule file(s) referenced by this project,
and the active rules found in analysisResult.RulesExtractedFromCode.
The issues debt is computed and formatted against this project IProjectDebtSettings.
Before running the rules, this method also computes both just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns them through justMyCodeOld and justMyCodeNew.
Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules.
This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.
Rules are executed twice against compareContextNewerCodeBase and OlderCodeBase,
except rule that relies on diff, like the rule API breaking change for example.
Such rule is only executed once and its issues are only present in the NewerIssuesSet of the returned IIssuesSetDiff object.
If a rule has compilation or execution error on one code base snapshot but not on the other one,
a log is emitted and issues obtained from execution against the other snapshot are not taken account in the returned IIssuesSetDiff object.
GetAvailableAnalysisResultsRefs(IProject)
Gets a collection of all analysis results available for this project ordered by IAnalysisResultRef.Date descending.
public static IReadOnlyList<IAnalysisResultRef> GetAvailableAnalysisResultsRefs(this IProject project)
Parameters
projectIProjectThis NDepend project.
Returns
Remarks
If project.HistoricAnalysisResult doesn't save historic analysis results, then the returned list will contain the most recent analysis result available for this project, or nothing if no analysis result is available for this project.
On a NDepend project with many analysis results available for years, it is performant wise to prefer calling GetAvailableAnalysisResultsRefsGroupedPerMonth(IProject) instead of this method, because analysis results references are then lazy-resolved, per month.
GetAvailableAnalysisResultsRefsGroupedPerMonth(IProject)
Gets a collection of all analysis results available for this project, grouped per months.
public static IReadOnlyList<IAnalysisResultsRefsForAMonth> GetAvailableAnalysisResultsRefsGroupedPerMonth(this IProject project)
Parameters
projectIProjectThis NDepend project.
Returns
Remarks
If project.HistoricAnalysisResult doesn't save historic analysis results, then the returned list will contain the most recent analysis result available for this project, or nothing if no analysis result is available for this project.
On a NDepend project with many analysis results available for years, it is performant wise to call this method than calling GetAvailableAnalysisResultsRefs(IProject), because analysis results references are then lazy-resolved, per month.
LoadAnalysisResultFromFile(IProject, IAbsoluteFilePath)
Loads the analysis result of a project from an analysis result file (.ndar extension).
public static IAnalysisResult LoadAnalysisResultFromFile(this IProject project, IAbsoluteFilePath analysisResultFilePath)
Parameters
projectIProjectThe project.
analysisResultFilePathIAbsoluteFilePathThe analysis result file path.
Returns
- IAnalysisResult
The analysis result loaded.
Exceptions
- AnalysisException
If the analysis load fails, an AnalysisException with an informative message is thrown.
- FileNotFoundException
This exception is thrown if the analysis result file
analysisResultFilePathdoesn't exist.
LoadCodeBaseFromAnalysisResultFile(IAbsoluteFilePath)
Loads a code base snapshot from an analysis result file (.ndar extension).
public static ICodeBase LoadCodeBaseFromAnalysisResultFile(this IAbsoluteFilePath analysisResultFilePath)
Parameters
analysisResultFilePathIAbsoluteFilePathThe analysis result file path (.ndar extension).
Returns
- ICodeBase
The code base snapshot.
Exceptions
- AnalysisException
If the analysis load fails, an AnalysisException with an informative message is thrown.
- FileNotFoundException
This exception is thrown if the analysis result file
analysisResultFilePathdoesn't exist.
LogTrendMetrics(IAnalysisResult, ICompareContext, IRuleIssues[], DateTime)
Force log trend metrics values for this analysisResult, with the possibility to execute code rules and trend metrics that require to be run in diff mode.
public static void LogTrendMetrics(this IAnalysisResult analysisResult, ICompareContext compareContext, IRuleIssues[] baselineIssuesImported, DateTime logDateTime)
Parameters
analysisResultIAnalysisResultThis analysisResult on which trend metrics values are computed.
compareContextICompareContextThe ICompareContext object used to execute code rules and trend metrics that require to be run in diff mode.
baselineIssuesImportedIRuleIssues[]Issues imported for the baseline snapshot.
logDateTimeDateTimeThe time at which trend metrics values are persisted, typically DateTime.Now or IAnalysisResult.AnalysisResultRef.Date.
Remarks
Trend metrics are extracted from code queries found in IAnalysisResult.AnalysisResultRef.Project.CodeQueries and IAnalysisResult.RulesExtractedFromCode.
Rules are extracted from the same code queries sets, for computation of code metrics: # Rules, # Rules Violated, # Rules Violations.
Trend metrics values are logged into the trend metrics store of the project IAnalysisResult.AnalysisResultRef.Project.
Exceptions
- TrendStoreException
An error occurred while persisting in the trend store.
LogTrendMetrics(IAnalysisResult, DateTime)
Force log trend metrics values for this analysisResult.
public static void LogTrendMetrics(this IAnalysisResult analysisResult, DateTime logDateTime)
Parameters
analysisResultIAnalysisResultThis analysisResult on which trend metrics values are computed.
logDateTimeDateTimeThe time at which trend metrics values are persisted, typically DateTime.Now or IAnalysisResult.AnalysisResultRef.Date.
Remarks
Trend metrics are extracted from code queries found in IAnalysisResult.AnalysisResultRef.Project.CodeQueries and IAnalysisResult.RulesExtractedFromCode.
Rules are extracted from the same code queries sets, for computation of code metrics: # Rules, # Rules Violated, # Rules Violations.
Trend metrics values are logged into the trend metrics store of the project IAnalysisResult.AnalysisResultRef.Project.
Exceptions
- TrendStoreException
An error occurred while persisting in the trend store.
LogTrendMetrics(IProject, IReadOnlyList<MetricValue>, string, DateTime)
Force log trend metrics trendMetricsValues already computed, for this project.
public static void LogTrendMetrics(this IProject project, IReadOnlyList<MetricValue> trendMetricsValues, string label, DateTime logDateTime)
Parameters
projectIProjectThis project for which trend metrics values are computed.
trendMetricsValuesIReadOnlyList<MetricValue>Trend metric values already computed.
labelstringThe log label string. If null or empty no label will be stored. Typically this label is computed through TryComputeLogLabel(IProject, ICodeBase, out string)
logDateTimeDateTimeThe time at which trend metrics values are persisted, typically DateTime.Now or IAnalysisResult.AnalysisResultRef.Date.
Remarks
Typically this overload of LogTrendMetrics is used with trendMetricsValues computed from
ComputeIssuesAndTrendMetrics(IAnalysisResult, TimeSpan, IssueReferenceRecord, out IReadOnlyList<MetricValue>, out ICodeBaseView, out IEnumerable<IIssueComputationLog>) or ComputeIssuesDiffAndTrendMetrics(IAnalysisResult, ICompareContext, TimeSpan, IssueReferenceRecord, out IReadOnlyList<MetricValue>, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>).
Exceptions
- TrendStoreException
An error occurred while persisting in the trend store.
PointsToSameAnalysisResultAs(IAnalysisResultRef, IAnalysisResultRef)
Returns true if both analysis result references point to the same analysis result.
public static bool PointsToSameAnalysisResultAs(this IAnalysisResultRef ref1, IAnalysisResultRef ref2)
Parameters
ref1IAnalysisResultRefThis analysis result reference
ref2IAnalysisResultRefThe other analysis result reference
Returns
RunAnalysis(IProject, Action<IAnalysisLog>, Action<IProgressLog>, string)
Runs a full analysis on this project, in-process and synchronously. (Only available with a Build Machine license).
public static IAnalysisResult RunAnalysis(this IProject project, Action<IAnalysisLog> analysisLogHandler, Action<IProgressLog> progressLogHandler, string analysisResultId = "")
Parameters
projectIProjectThis NDepend project to analyze.
analysisLogHandlerAction<IAnalysisLog>A procedure delegate object invoked each time the current analysis run emits a new IAnalysisLog object.
progressLogHandlerAction<IProgressLog>A procedure delegate object invoked each time the current analysis run emits a new IProgressLog object.
analysisResultIdstring(Optional) An id to identify the analysis result build by this call.
Returns
- IAnalysisResult
The analysis result.
Remarks
Calling this method will typically takes a few seconds, the time the analysis is performed.
The analysis result is persisted in the project.Properties.OutputDir directory.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.
Exceptions
- Exception
Cannot run analysis without a Build Machine license.
- AnalysisException
The analysis execution failed. The InnerException contains additional information concerning the failure.
- XmlException
The project file might be corrupted.
- ArgumentException
The string for
analysisResultIdis invalid. It must be trimmed, a length of maximum 64 characters, excluding characters that cannot fit in a file name \ / : * ? " > < |
RunAnalysis(IProject, string)
Runs a full analysis on this project, in-process and synchronously. (Only available with a Build Machine license).
public static IAnalysisResult RunAnalysis(this IProject project, string analysisResultId = "")
Parameters
projectIProjectThis NDepend project to analyze.
analysisResultIdstring(Optional) An id to identify the analysis result build by this call.
Returns
- IAnalysisResult
The analysis result.
Remarks
Calling this method will typically takes a few seconds, the time the analysis is performed.
The analysis result is persisted in the project.Properties.OutputDir directory.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.
Exceptions
- Exception
Cannot run analysis without a Build Machine license.
- AnalysisException
The analysis execution failed. The InnerException contains additional information concerning the failure.
- ArgumentException
The string for
analysisResultIdis invalid. It must be trimmed, a length of maximum 64 characters, excluding characters that cannot fit in a file name \ / : * ? " > < |
RunAnalysisAndBuildReport(IProject, Action<IAnalysisLog>, Action<IProgressLog>, string)
Runs a full analysis on this project, in-process and synchronously, and then generate a HTML report. (Only available with a Build Machine license).
public static IAnalysisResult RunAnalysisAndBuildReport(this IProject project, Action<IAnalysisLog> analysisLogHandler, Action<IProgressLog> progressLogHandler, string analysisResultId = "")
Parameters
projectIProjectThis NDepend project to analyze.
analysisLogHandlerAction<IAnalysisLog>A procedure delegate object invoked each time the current analysis run emits a new IAnalysisLog object.
progressLogHandlerAction<IProgressLog>A procedure delegate object invoked each time the current analysis run emits a new IProgressLog object.
analysisResultIdstring(Optional) An id to identify the analysis result build by this call.
Returns
- IAnalysisResult
The analysis result.
Remarks
The report generated is available in project.Properties.OutputDir, named "NDependReport.html".
Calling this method will typically takes a few seconds, the time the analysis is performed.
The analysis result is persisted in the project.Properties.OutputDir directory.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.
Exceptions
- Exception
Cannot run analysis without a Build Machine license.
- AnalysisException
The analysis execution failed. The InnerException contains additional information concerning the failure.
- ArgumentException
The string for
analysisResultIdis invalid. It must be trimmed, a length of maximum 64 characters, excluding characters that cannot fit in a file name \ / : * ? " > < |
RunAnalysisAndBuildReport(IProject, string)
Runs a full analysis on this project, in-process and synchronously, and then generate a HTML report. (Only available with a Build Machine license).
public static IAnalysisResult RunAnalysisAndBuildReport(this IProject project, string analysisResultId = "")
Parameters
projectIProjectThis NDepend project to analyze.
analysisResultIdstring(Optional) An id to identify the analysis result build by this call.
Returns
- IAnalysisResult
The analysis result.
Remarks
The report generated is available in project.Properties.OutputDir, named "NDependReport.html".
Calling this method will typically takes a few seconds, the time the analysis is performed.
The analysis result is persisted in the project.Properties.OutputDir directory.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.
Exceptions
- Exception
Cannot run analysis without a Build Machine license.
- AnalysisException
The analysis execution failed. The InnerException contains additional information concerning the failure.
- ArgumentException
The string for
analysisResultIdis invalid. It must be trimmed, a length of maximum 64 characters, excluding characters that cannot fit in a file name \ / : * ? " > < |
TryComputeLogLabel(IProject, ICodeBase, out string)
Try compute the log label from project and codeBase.
public static bool TryComputeLogLabel(this IProject project, ICodeBase codeBase, out string label)
Parameters
projectIProjectThe project that contains trend metrics log settings.
codeBaseICodeBaseThe code base thta contains application assemblies from which log versionning is inferred.
labelstringThe log label returned.
Returns
Remarks
Typically this method is called to compute the parameter label in this overload LogTrendMetrics(IAnalysisResult, DateTime).
TryExportIssues(IEnumerable<IIssue>, IAnalysisResult, IIssuesSet, IIssuesSetDiff, IssuesExportFormat, out string, out string, string)
Exports these issues in JSON or SARIF, without quality gates.
This is the content written by NDepend.Console.exe /IssueCheck with /OutJson or /OutSarif,
and by the Export Issues to SARIF File menu of a query result that matches issues.
public static bool TryExportIssues(this IEnumerable<IIssue> issues, IAnalysisResult analysisResult, IIssuesSet issuesSet, IIssuesSetDiff issuesSetDiff, IssuesExportFormat format, out string content, out string failureReason, string issuesQueryName = null)
Parameters
issuesIEnumerable<IIssue>The issues to export. They must belong to
issuesSet. Duplicates are exported once.analysisResultIAnalysisResultThe analysis result on which
issuesSethas been computed. Its project name, project file path and analysis date are exported.issuesSetIIssuesSetThe issues-set computed on
analysisResult.issuesSetDiffIIssuesSetDiffCan be null. Else the issues-set-diff whose NewerIssuesSet is
issuesSet: it tells which issues are new.formatIssuesExportFormatThe export format, JSON or SARIF.
contentstringThe JSON or SARIF document if the method returns true, else null.
failureReasonstringA description of the failure if the method returns false, else null.
issuesQueryNamestringOptional: the name of the rule or of the query that matched
issues, exported as issuesQuery.
Returns
- bool
true if the export succeeded.
Remarks
To export the issues of a rule or of a query from its rule id, its rule name or its query name, or the issues matched by a code query compiled,
first get them and the name to export as issuesQueryName with
TryGetIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, string, out IEnumerable<IIssue>, out string, out string, ICodeBaseView, TimeSpan?)
or TryGetIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, IQueryCompiledSuccess, out IEnumerable<IIssue>, out string, out string, ICodeBaseView, TimeSpan?).
The JSON format is described by the schema https://www.ndepend.com/schemas/issues-export/1.0.json, the quality gates properties are null.
The SARIF format is SARIF 2.1.0.
The message of each issue contains the issue explanation only if the issues have been computed with IssueReferenceRecord.Yes.
TryExportQualityGatesAndIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, IssuesExportFormat, out string, out string)
Exports the quality gates status and all the issues of issuesSet in JSON or SARIF.
This is the content written by NDepend.Console.exe /QualityGateCheck with /OutJson or /OutSarif.
public static bool TryExportQualityGatesAndIssues(this IAnalysisResult analysisResult, IIssuesSet issuesSet, IIssuesSetDiff issuesSetDiff, IssuesExportFormat format, out string content, out string failureReason)
Parameters
analysisResultIAnalysisResultThe analysis result on which
issuesSethas been computed. Its project name, project file path and analysis date are exported.issuesSetIIssuesSetThe issues-set computed on
analysisResult.issuesSetDiffIIssuesSetDiffCan be null. Else the issues-set-diff whose NewerIssuesSet is
issuesSet: it tells which issues are new, and the count of issues fixed since the baseline.formatIssuesExportFormatThe export format, JSON or SARIF.
contentstringThe JSON or SARIF document if the method returns true, else null.
failureReasonstringA description of the failure if the method returns false, else null.
Returns
- bool
true if the export succeeded.
Remarks
The JSON format is described by the schema https://www.ndepend.com/schemas/issues-export/1.0.json.
The SARIF format is SARIF 2.1.0, the quality gates are in the run property bag.
The message of each issue contains the issue explanation only if the issues have been computed with IssueReferenceRecord.Yes,
see ComputeIssues(IAnalysisResult, TimeSpan, IssueReferenceRecord, out ICodeBaseView, out IEnumerable<IIssueComputationLog>).
Else the message contains the code element and the values of the rule columns.
TryGetAnalysisResultRefToCompareWith(IProjectBaseline, out IAnalysisResultRef)
Try gets an analysis reference corresponding to this project baseline to compare with.
public static TryGetAnalysisResultRefToCompareWithResult TryGetAnalysisResultRefToCompareWith(this IProjectBaseline projectBaseline, out IAnalysisResultRef analysisResultRef)
Parameters
projectBaselineIProjectBaselineThis NDepend project baseline, obtained from IProject.BaselineDuringAnalysis or IProject.BaselineInUI.
analysisResultRefIAnalysisResultRefIf the method returns TryGetAnalysisResultRefToCompareWithResult.DoCompareWith,
analysisResultRefis not null and references the analysis result used for baseline.
Returns
- TryGetAnalysisResultRefToCompareWithResult
TryGetAnalysisResultRefToCompareWithResult.DoCompareWith if an an analysis result reference representing the baseline to compare with can be found, else returns another value of the enumeration TryGetAnalysisResultRefToCompareWithResult.
TryGetAnalysisResultRefToCompareWith(IProjectBaseline, out IAnalysisResultRef, out string)
Try gets an analysis reference corresponding to this project baseline to compare with.
public static TryGetAnalysisResultRefToCompareWithResult TryGetAnalysisResultRefToCompareWith(this IProjectBaseline projectBaseline, out IAnalysisResultRef analysisResultRef, out string failureReason)
Parameters
projectBaselineIProjectBaselineThis NDepend project baseline, obtained from IProject.BaselineDuringAnalysis or IProject.BaselineInUI.
analysisResultRefIAnalysisResultRefIf the method returns TryGetAnalysisResultRefToCompareWithResult.DoCompareWith,
analysisResultRefis not null and references the analysis result used for baseline.failureReasonstringIf the method returns TryGetAnalysisResultRefToCompareWithResult.ErrorGettingTheAnalysisResultRef,
failureReasonis not null not empty, and explains in plain-english why the project baseline cannot be retrieved.
Returns
- TryGetAnalysisResultRefToCompareWithResult
TryGetAnalysisResultRefToCompareWithResult.DoCompareWith if an an analysis result reference representing the baseline to compare with can be found, else returns another value of the enumeration TryGetAnalysisResultRefToCompareWithResult.
TryGetIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, IQueryCompiledSuccess, out IEnumerable<IIssue>, out string, out string, ICodeBaseView, TimeSpan?)
Gets the issues matched by issuesQuery.
public static bool TryGetIssues(this IAnalysisResult analysisResult, IIssuesSet issuesSet, IIssuesSetDiff issuesSetDiff, IQueryCompiledSuccess issuesQuery, out IEnumerable<IIssue> issues, out string issuesQueryName, out string failureReason, ICodeBaseView justMyCode = null, TimeSpan? cqlinqQueryExecTimeOut = null)
Parameters
analysisResultIAnalysisResultThe analysis result on which
issuesSethas been computed.issuesSetIIssuesSetThe issues-set computed on
analysisResult.issuesSetDiffIIssuesSetDiffCan be null. Else the issues-set-diff whose NewerIssuesSet is
issuesSet. Needed by queries that rely on the diff.issuesQueryIQueryCompiledSuccessA code query compiled that matches issues.
issuesIEnumerable<IIssue>The issues matched if the method returns true, else null.
issuesQueryNamestringThe name of the query if the method returns true and the query has a name, else null.
failureReasonstringA description of the failure if the method returns false, else null.
justMyCodeICodeBaseViewOptional: the just-my-code code base view used to execute the query, as returned by ComputeIssues().
cqlinqQueryExecTimeOutTimeSpan?Optional: the query execution time-out, one day if null.
Returns
- bool
true if the query has been executed and matches issues.
Remarks
A query that relies on the diff, like from i in Issues where i.WasAdded() select i, must be compiled against
issuesSetDiff.CompareContext, see ExtensionMethodsQuery.Compile(string, ICompareContext).
The method fails if the query doesn't match issues, or matches fixed issues or suppressed issues.
To export the issues matched, call
TryExportIssues(IEnumerable<IIssue>, IAnalysisResult, IIssuesSet, IIssuesSetDiff, IssuesExportFormat, out string, out string, string)
on them, with issuesQueryName.
TryGetIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, string, out IEnumerable<IIssue>, out string, out string, ICodeBaseView, TimeSpan?)
Gets the issues of a rule or of a query, from its rule id, its rule name or its query name. This is how NDepend.Console.exe /IssueCheck "rule or query" finds the issues it exports.
public static bool TryGetIssues(this IAnalysisResult analysisResult, IIssuesSet issuesSet, IIssuesSetDiff issuesSetDiff, string ruleIdOrQueryName, out IEnumerable<IIssue> issues, out string issuesQueryName, out string failureReason, ICodeBaseView justMyCode = null, TimeSpan? cqlinqQueryExecTimeOut = null)
Parameters
analysisResultIAnalysisResultThe analysis result on which
issuesSethas been computed.issuesSetIIssuesSetThe issues-set computed on
analysisResult.issuesSetDiffIIssuesSetDiffCan be null. Else the issues-set-diff whose NewerIssuesSet is
issuesSet. Needed by queries that rely on the diff.ruleIdOrQueryNamestringA rule id, a rule name or the name of a query that matches issues.
issuesIEnumerable<IIssue>The issues found if the method returns true, else null.
issuesQueryNamestringThe name of the rule or of the query found if the method returns true, else null.
failureReasonstringA description of the failure if the method returns false, else null.
justMyCodeICodeBaseViewOptional: the just-my-code code base view used to execute a query, as returned by ComputeIssues().
cqlinqQueryExecTimeOutTimeSpan?Optional: the query execution time-out, one day if null.
Returns
- bool
true if the rule or the query has been found.
Remarks
ruleIdOrQueryName is searched in this order, ignoring case:
1) the active rule with this id, like ND1000, or like CA1822 for an imported Roslyn rule,
2) the active rule with this name, like Avoid types too big,
3) the query with this name that matches issues, like New issues since baseline, in the project, in the rule files referenced by the project,
and in analysisResult.RulesExtractedFromCode.
The method fails if the name is unknown, if several rules or queries have this name, if the rule is not active,
or if the query doesn't match issues, or matches fixed issues or suppressed issues.
To export the issues found, call
TryExportIssues(IEnumerable<IIssue>, IAnalysisResult, IIssuesSet, IIssuesSetDiff, IssuesExportFormat, out string, out string, string)
on them, with issuesQueryName.
TryGetMostRecentAnalysisResultRef(IProject, out IAnalysisResultRef)
Gets a reference to the most recent analysis result available for this project.
public static bool TryGetMostRecentAnalysisResultRef(this IProject project, out IAnalysisResultRef mostRecentAnalysisResultRef)
Parameters
projectIProjectThis NDepend project.
mostRecentAnalysisResultRefIAnalysisResultRefThe reference to the most recent analysis result or null if the method call returned false.
Returns
- bool
A value indicating if a most recent analysis result referece has been found for this
project.