SonarQube Checkstyle插件无法分析Apache Axis WSDL2Java发射器生成的文件

时间:2016-01-21 11:40:20

标签: jenkins sonarqube checkstyle sonarqube5.3

我无法分析Apache Axis WSDL2Java发射器生成某些类的项目。该项目由Ant在Jenkins上构建,并由SonarQube Runner 2.4进行分析。如何解决这个问题而不忽略分析过程中的文件?

构建日志:

12:18:40 ERROR: Error during Sonar runner execution
12:18:40 org.sonar.runner.impl.RunnerException: Unable to execute Sonar
12:18:40    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
12:18:40    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
12:18:40    at java.security.AccessController.doPrivileged(Native Method)
12:18:40    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
12:18:40    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
12:18:40    at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
12:18:40    at org.sonar.runner.api.Runner.execute(Runner.java:100)
12:18:40    at org.sonar.runner.Main.executeTask(Main.java:70)
12:18:40    at org.sonar.runner.Main.execute(Main.java:59)
12:18:40    at org.sonar.runner.Main.main(Main.java:53)
12:18:40 Caused by: java.lang.IllegalStateException: Can not execute Checkstyle
12:18:40    at org.sonar.plugins.checkstyle.CheckstyleExecutor.execute(CheckstyleExecutor.java:92)
12:18:40    at org.sonar.plugins.checkstyle.CheckstyleSensor.analyse(CheckstyleSensor.java:57)
12:18:40    at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58)
12:18:40    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50)
12:18:40    at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:98)
12:18:40    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:185)
12:18:40    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
12:18:40    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
12:18:40    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:243)
12:18:40    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:238)
12:18:40    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:228)
12:18:40    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
12:18:40    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
12:18:40    at org.sonar.batch.task.ScanTask.execute(ScanTask.java:55)
12:18:40    at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
12:18:40    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
12:18:40    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
12:18:40    at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:    122)
12:18:40    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119)
12:18:40    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:79)
12:18:40    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
12:18:40    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:18:40    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
12:18:40    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
12:18:40    at java.lang.reflect.Method.invoke(Method.java:497)
12:18:40    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
12:18:40    ... 9 more
12:18:40 Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing /var/lib/jenkins/workspace/nord_trunk_sonar/src/java/comarch/vibank/nord/factor/utilities/webservice/BankTockensSoapStub.java
12:18:40    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:282)
12:18:40    at org.sonar.plugins.checkstyle.CheckstyleExecutor.execute(CheckstyleExecutor.java:87)
12:18:40    ... 34 more
12:18:40 Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: MismatchedTokenException occurred during the analysis of file /var/lib/jenkins/workspace/nord_trunk_sonar/src/java/comarch/vibank/nord/factor/utilities/webservice/BankTockensSoapStub.java.
12:18:40    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:218)
12:18:40    at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:79)
12:18:40    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:266)
12:18:40    ... 35 more
12:18:40 Caused by: /var/lib/jenkins/workspace/nord_trunk_sonar/src/java/comarch/vibank/nord/factor/utilities/webservice/BankTockensSoapStub.java:30:9: expecting EOF, found 'oper'
12:18:40    at antlr.Parser.match(Parser.java:211)
12:18:40    at com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:210)
12:18:40    at com.puppycrawl.tools.checkstyle.TreeWalker.parse(TreeWalker.java:468)
12:18:40    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:200)
12:18:40    ... 37 more
12:18:40 ERROR: 
12:18:40 ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

BankTockensSoapStub.java内容:

/**
 * BankTockensSoapStub.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis WSDL2Java emitter.
 */

package comarch.vibank.nord.factor.utilities.webservice;

public class BankTockensSoapStub extends org.apache.axis.client.Stub implements comarch.vibank.nord.factor.utilities.webservice.BankTockensSoap {
    private java.util.Vector cachedSerClasses = new java.util.Vector();
    private java.util.Vector cachedSerQNames = new java.util.Vector();
    private java.util.Vector cachedSerFactories = new java.util.Vector();
   private java.util.Vector cachedDeserFactories = new java.util.Vector();

    static org.apache.axis.description.OperationDesc [] _operations;

    static {
        _operations = new org.apache.axis.description.OperationDesc[1];
        org.apache.axis.description.OperationDesc oper;
        oper = new org.apache.axis.description.OperationDesc();
        oper.setName("returnTocken");
        oper.addParameter(new javax.xml.namespace.QName("http://www.comarch.com/", "ECODLogin"), new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, org.apache.axis.description.ParameterDesc.IN, false, false);
        oper.addParameter(new javax.xml.namespace.QName("http://www.comarch.com/", "viBankLogin"), new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, org.apache.axis.description.ParameterDesc.IN, false, false);
        oper.addParameter(new javax.xml.namespace.QName("http://www.comarch.com/", "viBankPass"), new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, org.apache.axis.description.ParameterDesc.IN, false, false);
        oper.setReturnType(new javax.xml.namespace.QName("http://www.comarch.com/", "RetRes"));
        oper.setReturnClass(comarch.vibank.nord.factor.utilities.webservice.RetRes.class);
        oper.setReturnQName(new javax.xml.namespace.QName("http://www.comarch.com/", "returnTockenResult"));
        oper.setStyle(org.apache.axis.enum.Style.WRAPPED);
        oper.setUse(org.apache.axis.enum.Use.LITERAL);
        _operations[0] = oper;
    }
    ...

导致错误的行:

        oper.setUse(org.apache.axis.enum.Use.LITERAL);

sonar-project.properties内容:

sonar.projectKey=nord_trunk
sonar.projectName=Nord (trunk)
sonar.projectDescription=viBank for Nord
sonar.projectVersion=rev15358

sonar.sourceEncoding=Cp1250
sonar.language=java
sonar.java.source=1.4
sonar.java.target=1.4
sonar.sources=src/java,src/web_adk,src/web_corpo  
sonar.binaries=build/classes,web_corpo/WEB-INF/classes,web_adk/WEB-INF/classes
sonar.libraries=lib/*.jar,lib/xmlbeans/*.jar

sonar.scm.url=scm:svn:svn://hodor/nord/trunk
sonar.verbose=true

环境:

  • SonarQube 5.3,java插件:
    • Checkstyle 2.4
    • Findbugs 3.3
    • Java 3.9
    • PMD 2.5
  • Jenkins 1.644:
    • SonarQube Jenkins Plugin 2.3
    • SonarQube Runner 2.4
  • Oracle JDK 1.8.0 Update 66

1 个答案:

答案 0 :(得分:0)

Checkstyle在解析Java 1.4代码时遇到问题。类型org.apache.axis.enum.Use在包中定义,使用保留关键字enum

更改这两行之后:

oper.setStyle(org.apache.axis.enum.Style.WRAPPED);
oper.setUse(org.apache.axis.enum.Use.LITERAL);

为:

oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
oper.setUse(org.apache.axis.constants.Use.LITERAL);

SonarQube分析成功。我没有在Checkstyle积压中报告问题,因为JDK 1.4已经死了,我不认为任何人都会修复它。

测试期间使用的类:

public class CheckstyleAxisTest {

    private java.util.Vector cachedSerClasses = new java.util.Vector();
    private java.util.Vector cachedSerQNames = new java.util.Vector();
    private java.util.Vector cachedSerFactories = new java.util.Vector();
    private java.util.Vector cachedDeserFactories = new java.util.Vector();

    static org.apache.axis.description.OperationDesc[] _operations;

    static {
        _operations = new org.apache.axis.description.OperationDesc[1];
        org.apache.axis.description.OperationDesc oper;
        oper = new org.apache.axis.description.OperationDesc();
        oper.setName("returnTocken");
        oper.addParameter(new javax.xml.namespace.QName("http://www.comarch.com/", "ECODLogin"), new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, org.apache.axis.description.ParameterDesc.IN, false, false);
        oper.addParameter(new javax.xml.namespace.QName("http://www.comarch.com/", "viBankLogin"), new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, org.apache.axis.description.ParameterDesc.IN, false, false);
        oper.addParameter(new javax.xml.namespace.QName("http://www.comarch.com/", "viBankPass"), new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, org.apache.axis.description.ParameterDesc.IN, false, false);
        oper.setReturnType(new javax.xml.namespace.QName("http://www.comarch.com/", "RetRes"));
        oper.setReturnClass(java.lang.Object.class);
        oper.setReturnQName(new javax.xml.namespace.QName("http://www.comarch.com/", "returnTockenResult"));
        oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
        oper.setUse(org.apache.axis.constants.Use.LITERAL);
        _operations[0] = oper;
    }
}

Maven依赖项:

<dependency>
    <groupId>org.apache.axis</groupId>
    <artifactId>axis</artifactId>
    <version>1.4</version>
</dependency>

测试环境:

  • SonarQube 7.0,java插件:
    • Checkstyle 4.8
    • Findbugs 3.6.0
    • Java 5.1.1
    • PMD 2.6
  • Jenkins 2.111:
    • SonarQube Jenkins插件2.6.1
  • SonarQube Maven Scanner 3.4.0.905
  • Oracle JDK 1.8.0 Update 162