使用SonarQube Ant任务进行分析

时间:2015-04-28 16:37:48

标签: java ant sonarqube

我遵循here给出的有关如何将SonarQube与基于Ant的项目集成的说明。但是当我到达必须调用ant sonar的点时,它就会失败。

在达到这一点之前,我已经确认Sonar已启动并正在运行,并且可以访问以下网址并显示默认的“欢迎使用SonarQube信息中心”页面:

http://localhost:9000

通过做tail -f logs/sonar.log我在某个时刻看到以下内容似乎与问题重合:

$ tail -f sonarqube-4.5.4/logs/sonar.log
[...]/sonarqube-4.5.4/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/methodoverride.rb:24:in `call'
[...]/sonarqube-4.5.4/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/params_parser.rb:15:in `call'
[...]/sonarqube-4.5.4/lib/server/jruby-rack-1.1.13.2.jar!/jruby/rack/session_store.rb:70:in `context'
[...]/sonarqube-4.5.4/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/session/abstract/id.rb:58:in `call'
[...]/sonarqube-4.5.4/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/failsafe.rb:26:in `call'
[...]/sonarqube-4.5.4/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:106:in `call
[...]/sonarqube-4.5.4/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:34:in `serve_rails'
[...]/sonarqube-4.5.4/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:39:in `call'
[...]/sonarqube-4.5.4/lib/server/jruby-rack-1.1.13.2.jar!/rack/handler/servlet.rb:22:in `call'

2015.04.28 19:15:08 ERROR web[o.s.s.ui.JRubyFacade]  Fail to render: http://localhost:9000/api/server
undefined method `generate' for #<JSON::Ext::Generator::State:0x1d0f333>
/home/mperdikeas/.rvm/gems/ruby-2.0.0-p353@global/gems/json-1.8.1/lib/json/common.rb:223:in `generate'
 /home/mperdikeas/.rvm/gems/ruby-2.0.0-p353@global/gems/json-1.8.1/lib/json/common.rb:470:in `JSON'
 /home/mperdikeas/software-downloads/sonarqube/sonarqube-5.4/web/WEB-INF/app/controllers/api/api_controller.rb:48:in `jsonp'
 /home/mperdikeas/software-downloads/sonarqube/sonarqube-4.5.4/web/WEB-INF/app/controllers/api/server_controller.rb:42:in `index'

我附加在运行ant sonar的控制台上的跟踪下方:

蚂蚁声纳痕迹

$ ant sonar                                                                                                                                                                                                                                               
Buildfile: [...]/sample-sonar-ant-project/build.xml                                                                                                                                                                           

sonar:                                                                                                                                                                                                                                                    
[sonar:sonar] Apache Ant(TM) version 1.8.2 compiled on December 3 2011                                                                                                                                                                                    
[sonar:sonar] SonarQube Ant Task version: 2.2                                                                                                                                                                                                             
[sonar:sonar] Loaded from: file:/home/mperdikeas/software-downloads/sonarqube/sonar-ant-task-2.2.jar                                                                                                                                                      
[sonar:sonar] INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)                                                                                                                                               
[sonar:sonar] INFO: Work directory: /home/mperdikeas/playground-local/sample-sonar-ant-project/.sonar                                                                                                                                                     
[sonar:sonar] INFO: SonarQube Server 4.5.4                                                                                                                                                                                                                
[sonar:sonar] 19:15:06.240 INFO  - Load global referentials...                                                                                                                                                                                            
[sonar:sonar] 19:15:06.486 INFO  - Load global referentials done: 249 ms                                                                                                                                                                                  
[sonar:sonar] 19:15:06.500 INFO  - User cache: /home/mperdikeas/.sonar/cache                                                                                                                                                                              
[sonar:sonar] 19:15:06.512 INFO  - Install plugins                                                                                                                                                                                                        
[sonar:sonar] 19:15:06.572 INFO  - Install JDBC driver                                                                                                                                                                                                    
[sonar:sonar] 19:15:06.580 INFO  - Create JDBC datasource for jdbc:postgresql://localhost:5432/sonar?useUnicode=true&characterEncoding=utf8                                                                                                               

BUILD FAILED                                                                                                                                                                                                                                              
/home/mperdikeas/playground-local/sample-sonar-ant-project/build.xml:478: org.sonar.runner.impl.RunnerException: Unable to execute Sonar                                                                                                                  
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)                                                                                                                                                                         
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)                                                                                                                                                                                       
at java.security.AccessController.doPrivileged(Native Method)                                                                                                                                                                                             
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)                                                                                                                                                                                   
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)                                                                                                                                                                                     
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)                                                                                                                                                                                 
at org.sonar.runner.api.Runner.execute(Runner.java:100)                                                                                                                                                                                                   
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:53)                                                                                                                                                                                              
at org.sonar.ant.SonarTask.execute(SonarTask.java:48)                                                                                                                                                                                                     
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)                                                                                                                                                                                   
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)                                                                                                                                                                                            
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                                                                                                  
at java.lang.reflect.Method.invoke(Method.java:606)                                                                                                                                                                                                       
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)                                                                                                                                                                            
at org.apache.tools.ant.Task.perform(Task.java:348)                                                                                                                                                                                                       
at org.apache.tools.ant.Target.execute(Target.java:390)                                                                                                                                                                                                   
at org.apache.tools.ant.Target.performTasks(Target.java:411)                                                                                                                                                                                              
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)                                                                                                                                                                                   
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)                                                                                                                                                                                          
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)                                                                                                                                                                    
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)                                                                                                                                                                                         
at org.apache.tools.ant.Main.runBuild(Main.java:809)                                                                                                                                                                                                      
at org.apache.tools.ant.Main.startAnt(Main.java:217)                                                                                                                                                                                                      
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)                                                                                                                                                                                            
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)                                                                                                                                                                                           
Caused by: org.sonar.api.utils.HttpDownloader$HttpException: Fail to download [http://localhost:9000/api/server]. Response code: 500                                                                                                                      
at org.sonar.api.utils.HttpDownloader$BaseHttpDownloader$HttpInputSupplier.getInput(HttpDownloader.java:281)                                                                                                                                              
at org.sonar.api.utils.HttpDownloader$BaseHttpDownloader$HttpInputSupplier.getInput(HttpDownloader.java:235)                                                                                                                                              
at org.sonar.batch.bootstrap.ServerClient.request(ServerClient.java:89)                                                                                                                                                                                   
at org.sonar.batch.bootstrap.ServerClient.request(ServerClient.java:83)                                                                                                                                                                                   
at org.sonar.batch.bootstrap.ServerClient.request(ServerClient.java:79)                                                                                                                                                                                   
at org.sonar.batch.bootstrap.ServerMetadata.getServerId(ServerMetadata.java:99)                                                                                                                                                                           
at org.sonar.batch.bootstrap.DatabaseCompatibility.checkCorrectServerId(DatabaseCompatibility.java:57)                                                                                                                                                    
at org.sonar.batch.bootstrap.DatabaseCompatibility.start(DatabaseCompatibility.java:51)                                                                                                                                                                   
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                                                                                            
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)                                                                                                                                                                          
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                                                                                                  
at java.lang.reflect.Method.invoke(Method.java:606)                                                                                                                                                                                                       
at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)                                                                                                                                             
at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89)                                                                                                                                                     
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)                                                                                                                                          
at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)                                                                                                                                                                          
at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)                                                                                                                                                                       
at org.picocontainer.behaviors.Stored.start(Stored.java:110)                                                                                                                                                                                              
at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1015)                                                                                                                                                         
at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1008)                                                                                                                                                                   
at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:766)                                                                                                                                                                            
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)                                              
at org.sonar.batch.bootstrapper.Batch.start(Batch.java:81)                                                                                                                                                                                                
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)                                                                                                                                                                                              
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)                                                                                                                                                                              
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                                                                                            
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)                                                                                                                                                                          
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                                                                                                  
at java.lang.reflect.Method.invoke(Method.java:606)                                                                                                                                                                                                       
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)                                                                                                                                                                         
... 24 more                                                                                                                                                                                                                                               

Total time: 3 seconds     

1 个答案:

答案 0 :(得分:0)

这是根本原因(取自你的堆栈跟踪):

Caused by: org.sonar.api.utils.HttpDownloader$HttpException: Fail to download [http://localhost:9000/api/server]. Response code: 500                                                                       

HTTP 500代码表示您的Sonar服务器出现问题。它是否按预期在以下URL上运行?

http://localhost:9000

如果是这样,我建议接下来检查服务器端日志文件以获取错误消息。