1

我无法分析 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.

BankTokensSoapStub.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
    • 查找错误 3.3
    • Java 3.9
    • PMD 2.5
  • 詹金斯 1.644:
    • SonarQube 詹金斯插件 2.3
    • SonarQube 亚军 2.4
  • Oracle JDK 1.8.0 更新 66
4

1 回答 1

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 backlog 中的问题,因为 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
    • 2.6
  • 詹金斯 2.111:
    • SonarQube 詹金斯插件 2.6.1
  • SonarQube Maven 扫描仪 3.4.0.905
  • Oracle JDK 1.8.0 更新 162
于 2018-03-18T10:19:40.120 回答