2

我正在使用带有 maven 的声纳来分析项目(php 和 java)。最近在扫描一些项目时,Sonar 显示这样的错误消息

+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'sonar'.
[INFO] Ignoring available plugin update: 2.0 as it requires Maven version 3.0
[INFO] Ignoring available plugin update: 2.0-beta-2 as it requires Maven version 3.0
[INFO] Ignoring available plugin update: 2.0-beta-1 as it requires Maven version 3.0
[INFO] ------------------------------------------------------------------------
[INFO] Building java
[INFO]    task-segment: [sonar:sonar] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [sonar:sonar {execution: default-cli}]
[INFO] Sonar host: http://localhost:9000
[INFO] Sonar version: 2.14
[INFO] Execute: org.codehaus.sonar:sonar-maven-plugin:2.14:sonar
[INFO] [sonar:sonar {execution: default-sonar}]
[WARN] [17:40:35.282] Derby database should be used for evaluation purpose only
[INFO] [17:40:35.298] Create JDBC datasource
[INFO] [17:40:36.757] Initializing Hibernate
[INFO] [17:40:41.233] -------------  Analyzing java
[INFO] [17:40:42.858] Selected quality profile : [name=Sonar way,language=java]
[INFO] [17:40:42.969] Configure maven plugins...
[INFO] [17:40:43.248] Compare to previous analysis (2012-06-06)
[INFO] [17:40:43.309] Compare over 5 days (2012-06-06, analysis of 2012-06-06 16:36:01.996)
[INFO] [17:40:43.336] Compare over 30 days (2012-05-12, analysis of 2012-05-30 17:05:04.248)
[INFO] [17:40:43.455] Initializer FindbugsMavenInitializer...
[INFO] [17:40:43.466] Initializer FindbugsMavenInitializer done: 11 ms
[INFO] [17:40:43.466] Initializer ProjectFileSystemLogger...
[INFO] [17:40:43.471] Source directories:
[INFO] [17:40:43.471]   /home/gamer/NetBeansProjects/QE
[INFO] [17:40:43.473] Initializer ProjectFileSystemLogger done: 7 ms
[INFO] [17:40:43.473] Initializer MavenInitializer...
[INFO] [17:40:43.476] Java source version: 1.5
[INFO] [17:40:43.476] Java target version: 1.5
[INFO] [17:40:43.476] Source encoding: null
[INFO] [17:40:43.476] Initializer MavenInitializer done: 3 ms
[INFO] [17:40:43.514] Sensor JavaSourceImporter...
[WARN] [17:40:43.552] SQL Error: -1, SQLState: 23505
[ERROR] [17:40:43.552] The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL110927104436930' defined on 'PROJECTS'.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Can not execute Sonar

Embedded error: Unable to read and import the source file : '/home/gamer/NetBeansProjects/QE/src/QEmain/QE_main.java' with the charset : 'UTF-8'.
The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL110927104436930' defined on 'PROJECTS'.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Can not execute Sonar
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    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:616)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Can not execute Sonar
    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:103)
    at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:79)
    at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:88)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    ... 17 more
Caused by: org.sonar.api.utils.SonarException: Unable to read and import the source file : '/home/gamer/NetBeansProjects/QE/src/QEmain/QE_main.java' with the charset : 'UTF-8'.
    at org.sonar.plugins.squid.JavaSourceImporter.importSource(JavaSourceImporter.java:87)
    at org.sonar.plugins.squid.JavaSourceImporter.parseDirs(JavaSourceImporter.java:73)
    at org.sonar.plugins.squid.JavaSourceImporter.analyse(JavaSourceImporter.java:66)
    at org.sonar.plugins.squid.JavaSourceImporter.analyse(JavaSourceImporter.java:62)
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:64)
    at org.sonar.batch.phases.Phases.execute(Phases.java:93)
    at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:143)
    at org.sonar.batch.bootstrap.Module.start(Module.java:83)
    at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:115)
    at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:105)
    at org.sonar.batch.bootstrap.Module.start(Module.java:83)
    at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:102)
    at org.sonar.batch.bootstrap.Module.start(Module.java:83)
    at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:71)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:58)
    at org.sonar.maven.SonarMojo.execute(SonarMojo.java:151)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:98)
    ... 21 more
Caused by: javax.persistence.PersistenceException: Unable to persist : org.sonar.api.database.model.ResourceModel@91a0c3[id=<null>,key=qb:artid:src.QEmain,scope=DIR,qualifier=PAC,name=src.QEmain,longName=src.QEmain,lang=java,enabled=true,rootId=1095,copyResourceId=<null>,personId=<null>]
    at org.sonar.jpa.session.JpaDatabaseSession.internalSave(JpaDatabaseSession.java:119)
    at org.sonar.jpa.session.JpaDatabaseSession.save(JpaDatabaseSession.java:89)
    at org.sonar.batch.index.DefaultResourcePersister.persistFileOrDirectory(DefaultResourcePersister.java:184)
    at org.sonar.batch.index.DefaultResourcePersister.persist(DefaultResourcePersister.java:132)
    at org.sonar.batch.index.DefaultResourcePersister.saveResource(DefaultResourcePersister.java:115)
    at org.sonar.batch.index.DefaultPersistenceManager.saveResource(DefaultPersistenceManager.java:72)
    at org.sonar.batch.index.DefaultIndex.doIndex(DefaultIndex.java:513)
    at org.sonar.batch.index.DefaultIndex.doIndex(DefaultIndex.java:479)
    at org.sonar.batch.index.DefaultIndex.doIndex(DefaultIndex.java:477)
    at org.sonar.batch.index.DefaultIndex.index(DefaultIndex.java:471)
    at org.sonar.batch.DefaultSensorContext.index(DefaultSensorContext.java:54)
    at org.sonar.plugins.squid.JavaSourceImporter.importSource(JavaSourceImporter.java:79)
    ... 38 more
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not insert: [org.sonar.api.database.model.ResourceModel]
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:226)
    at org.sonar.jpa.session.JpaDatabaseSession.internalSave(JpaDatabaseSession.java:113)
    ... 49 more
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [org.sonar.api.database.model.ResourceModel]
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:64)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2176)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2656)
    at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
    at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
    at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
    at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:646)
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:620)
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:624)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
    ... 50 more
Caused by: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL110927104436930' defined on 'PROJECTS'.
    at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    at org.apache.derby.client.am.PreparedStatement.executeUpdate(Unknown Source)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:57)
    ... 65 more
Caused by: org.apache.derby.client.am.SqlException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL110927104436930' defined on 'PROJECTS'.
    at org.apache.derby.client.am.Statement.completeExecute(Unknown Source)
    at org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(Unknown Source)
    at org.apache.derby.client.net.NetStatementReply.readExecute(Unknown Source)
    at org.apache.derby.client.net.StatementReply.readExecute(Unknown Source)
    at org.apache.derby.client.net.NetPreparedStatement.readExecute_(Unknown Source)
    at org.apache.derby.client.am.PreparedStatement.readExecute(Unknown Source)
    at org.apache.derby.client.am.PreparedStatement.flowExecute(Unknown Source)
    at org.apache.derby.client.am.PreparedStatement.executeUpdateX(Unknown Source)
    ... 69 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13 seconds
[INFO] Finished at: Mon Jun 11 17:40:43 IST 2012
[INFO] Final Memory: 22M/178M
[INFO] ------------------------------------------------------------------------

有人可以帮我理解这个错误信息吗?我该如何纠正这个错误?谷歌没有返回任何结果。

4

1 回答 1

1

您的问题与项目的配置有关。该消息具有误导性(Sonar 3.0 给出了更清晰的消息)。此问题的根本原因是 Sonar 尝试创建 2 个具有相同键的资源:“qb:artid:src.QEmain”。所以这可能意味着您有多个具有相同“src/QEmain”文件夹的源目录。

于 2012-06-11T13:57:56.610 回答