2013-01-23 2 views
2

나는 프로그래밍 방식으로 내가의 FxCop 분석 결과에 대한 파서 XML 파일을 원하는파서의 FxCop 결과 XML 파일은

의 FxCop 분석 결과 (XML 파일)을 생성하기위한 VS2010와의 FxCop 10.0 (fxcopcmd.exe)를 사용합니다. 파서 C 번호 http://grepcode.com/file/repo1.maven.org/maven2/org.jvnet.hudson.plugins/violations/0.7.7/hudson/plugins/violations/types/fxcop/FxCopParser.java

제안 : 자바 언어에서

이걸 발견했습니다?

+0

정확히 무엇을하려고합니까? 예를 들어, 때때로 XSLT를 사용하여 위반 사항을 제거합니다. – Mightymuke

+0

fxcop의 실행에 대한 정보 수집이 필요합니다 : Messages (Issues - Level Error, Warning) 및 예외 – Kiquenet

답변

2

이 코드를 사용하여 보고서에 문제 수를 표시합니다. XElement에서도 실제 메시지를 검색 할 수 있습니다.

public class Parser 
{ 
    public Parser(string fileName) 
    { 
     XDocument doc = XDocument.Load(fileName); 
     var issues = GetAllIssues(doc); 
     NumberOfIssues = issues.Count; 

     var criticalErrors = GetCriticalErrors(issues); 
     var errors = GetErrors(issues); 
     var criticalWarnings = GetCriticalWarnings(issues); 
     var warnings = GetWarnings(issues); 

     NumberOfCriticalErrors = criticalErrors.Count; 
     NumberOfErrors = errors.Count; 
     NumberOfCriticalWarnings = criticalWarnings.Count; 
     NumberOfWarnings = warnings.Count; 
    } 

    public int NumberOfIssues 
    { 
     get; 
     private set; 
    } 

    public int NumberOfCriticalErrors 
    { 
     get; 
     private set; 
    } 

    public int NumberOfErrors 
    { 
     get; 
     private set; 
    } 

    public int NumberOfCriticalWarnings 
    { 
     get; 
     private set; 
    } 

    public int NumberOfWarnings 
    { 
     get; 
     private set; 
    } 

    private List<XElement> GetAllIssues(XDocument doc) 
    { 
     IEnumerable<XElement> issues = 
      from el in doc.Descendants("Issue") 
      select el; 

     return issues.ToList(); 
    } 

    private List<XElement> GetCriticalErrors(List<XElement> issues) 
    { 
     IEnumerable<XElement> errors = 
      from el in issues 
      where (string)el.Attribute("Level") == "CriticalError" 
      select el; 

     return errors.ToList(); 
    } 

    private List<XElement> GetErrors(List<XElement> issues) 
    { 
     IEnumerable<XElement> errors = 
      from el in issues 
      where (string)el.Attribute("Level") == "Error" 
      select el; 

     return errors.ToList(); 
    } 

    private List<XElement> GetCriticalWarnings(List<XElement> issues) 
    { 
     IEnumerable<XElement> warn = 
      from el in issues 
      where (string)el.Attribute("Level") == "CriticalWarning" 
      select el; 

     return warn.ToList(); 
    } 

    private List<XElement> GetWarnings(List<XElement> issues) 
    { 
     IEnumerable<XElement> warn = 
      from el in issues 
      where (string)el.Attribute("Level") == "Warning" 
      select el; 

     return warn.ToList(); 
    } 
}