当前位置: 首页 > 工具软件 > COBE > 使用案例 >

Cobertura 好像不支持java1.8

谭刚毅
2023-12-01

参考 :https://stackoverflow.com/questions/34664152/cobertura-parsing-errorcobertura-javancss-parser-parseexception

https://blog.csdn.net/cathy_sunshine/article/details/75258298

https://github.com/cobertura/cobertura/wiki/line-coverage-explained

使用Cobertura做代码覆盖率

执行mvn cobertura:cobertura

遇到问题:

[ERROR] net.sourceforge.cobertura.javancss.parser.ParseException: Encountered " ">" "> "" at line 71, column 72.
Was expecting one of:
    "assert" ...
    "boolean" ...
    "byte" ...
    "char" ...
    "double" ...
    "enum" ...
    "false" ...
    "float" ...
    "int" ...
    "long" ...
    "new" ...
    "null" ...
    "short" ...
    "super" ...
    "this" ...
    "true" ...
    "void" ...
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <CHARACTER_LITERAL> ...
    <STRING_LITERAL> ...
    <IDENTIFIER> ...
    "(" ...
    "!" ...
    "~" ...
    "++" ...
    "--" ...
    "+" ...
    "-" ...

        at net.sourceforge.cobertura.javancss.parser.JavaParser.generateParseException(JavaParser.java:10490)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.jj_consume_token(JavaParser.java:10366)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.UnaryExpression(JavaParser.java:3175)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.MultiplicativeExpression(JavaParser.java:3090)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.AdditiveExpression(JavaParser.java:3085)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ShiftExpression(JavaParser.java:3027)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.RelationalExpression(JavaParser.java:2990)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.InstanceOfExpression(JavaParser.java:2977)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.AssigmentExpression(JavaParser.java:2959)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.EqualityExpression(JavaParser.java:2886)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.AndExpression(JavaParser.java:2860)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ExclusiveOrExpression(JavaParser.java:2843)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.InclusiveOrExpression(JavaParser.java:2826)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ConditionalAndExpression(JavaParser.java:2808)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ConditionalOrExpression(JavaParser.java:2790)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ConditionalExpression(JavaParser.java:2774)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Expression(JavaParser.java:2718)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ArgumentList(JavaParser.java:3620)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Arguments(JavaParser.java:3610)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.PrimarySuffix(JavaParser.java:3511)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.PrimaryExpression(JavaParser.java:3384)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.StatementExpression(JavaParser.java:4070)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Statement(JavaParser.java:3795)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.BlockStatement(JavaParser.java:3984)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Block(JavaParser.java:3934)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Statement(JavaParser.java:3765)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.IfStatement(JavaParser.java:4240)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Statement(JavaParser.java:3803)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.BlockStatement(JavaParser.java:3984)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Block(JavaParser.java:3934)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Statement(JavaParser.java:3765)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.IfStatement(JavaParser.java:4240)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Statement(JavaParser.java:3803)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.BlockStatement(JavaParser.java:3984)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Block(JavaParser.java:3934)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Statement(JavaParser.java:3765)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.WhileStatement(JavaParser.java:4259)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Statement(JavaParser.java:3807)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.BlockStatement(JavaParser.java:3984)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Block(JavaParser.java:3934)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.MethodDeclaration(JavaParser.java:1987)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ClassBodyDeclaration(JavaParser.java:1039)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ClassBody(JavaParser.java:898)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.UnmodifiedClassDeclaration(JavaParser.java:824)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ClassDeclaration(JavaParser.java:728)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.TypeDeclaration(JavaParser.java:575)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.CompilationUnit(JavaParser.java:318)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.parse(JavaParser.java:100)
        at net.sourceforge.cobertura.javancss.Javancss._measureSource(Javancss.java:192)
        at net.sourceforge.cobertura.javancss.Javancss._measureRoot(Javancss.java:268)
        at net.sourceforge.cobertura.javancss.Javancss.<init>(Javancss.java:347)
        at net.sourceforge.cobertura.javancss.JavancssFactory.newInstance(JavancssFactory.java:40)
        at net.sourceforge.cobertura.reporting.ComplexityCalculator.getFunctionMetricsForSingleFile(ComplexityCalculator.java:243)
        at net.sourceforge.cobertura.reporting.ComplexityCalculator.getAccumlatedCCNForSingleFile(ComplexityCalculator.java:143)
        at net.sourceforge.cobertura.reporting.ComplexityCalculator.getCCNForSourceFileNameInternal(ComplexityCalculator.java:273)
        at net.sourceforge.cobertura.reporting.ComplexityCalculator.getCCNForPackageInternal(ComplexityCalculator.java:208)
        at net.sourceforge.cobertura.reporting.ComplexityCalculator.getCCNForProject(ComplexityCalculator.java:174)
        at net.sourceforge.cobertura.reporting.xml.XMLReport.<init>(XMLReport.java:70)
        at net.sourceforge.cobertura.reporting.xml.XMLReportFormatStrategy.save(XMLReportFormatStrategy.java:18)
        at net.sourceforge.cobertura.reporting.NativeReport.export(NativeReport.java:31)
        at net.sourceforge.cobertura.reporting.CompositeReport.export(CompositeReport.java:19)
        at net.sourceforge.cobertura.reporting.ReportMain.parseArgumentsAndReport(ReportMain.java:91)
        at net.sourceforge.cobertura.reporting.ReportMain.generateReport(ReportMain.java:141)
        at net.sourceforge.cobertura.reporting.ReportMain.main(ReportMain.java:151)

 

javancss can't handle certain Java8 Code and you get an error while parsing.

The last commit was 2 years ago so you have to try an alternative like SonarCube

答案来自

https://stackoverflow.com/questions/34664152/cobertura-parsing-errorcobertura-javancss-parser-parseexception

https://github.com/cobertura/cobertura/issues/176

 

后面使用jacoco 来做的代码覆盖率 使用ant 集成jenkins

 

 类似资料: