Category Archives: sonar
Sonar PMD Plugin – Running in JDK 1.4 mode
If you are analyzing your project using sonar-runner (version 1.0) you might see the below exception
[ERROR] Fail to execute PMD. Following file is ignored: <path-to-java-file> net.sourceforge.pmd.ast.ParseException: Can't use static imports when running in JDK 1.4 mode! at net.sourceforge.pmd.ast.JavaParser.checkForBadStaticImportUsage(JavaParser.java:26) [pmd-4.2.5.jar:na] at net.sourceforge.pmd.ast.JavaParser.ImportDeclaration(JavaParser.java:248) [pmd-4.2.5.jar:na] at net.sourceforge.pmd.ast.JavaParser.CompilationUnit(JavaParser.java:124) [pmd-4.2.5.jar:na] at net.sourceforge.pmd.parsers.Java14Parser.parse(Java14Parser.java:23) [pmd-4.2.5.jar:na] at net.sourceforge.pmd.PMD.processFile(PMD.java:98) [pmd-4.2.5.jar:na] at net.sourceforge.pmd.PMD.processFile(PMD.java:75) [pmd-4.2.5.jar:na] at org.sonar.plugins.pmd.PmdExecutor.execute(PmdExecutor.java:70) [sonar-pmd-plugin-2.8.jar:na] at org.sonar.plugins.pmd.PmdSensor.analyse(PmdSensor.java:45) [sonar-pmd-plugin-2.8.jar:na] at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:58) [sonar-batch-2.8.jar:na] at org.sonar.batch.phases.Phases.execute(Phases.java:80) [sonar-batch-2.8.jar:na] at org.sonar.batch.ProjectBatch.execute(ProjectBatch.java:59) [sonar-batch-2.8.jar:na] at org.sonar.batch.Batch.analyzeModule(Batch.java:164) [sonar-batch-2.8.jar:na] at org.sonar.batch.Batch.analyzeModules(Batch.java:82) [sonar-batch-2.8.jar:na] at org.sonar.batch.Batch.execute(Batch.java:62) [sonar-batch-2.8.jar:na] at org.sonar.runner.Launcher.executeBatch(Launcher.java:60) [sonar-runner.jar:na] at org.sonar.runner.Launcher.execute(Launcher.java:53) [sonar-runner.jar:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.6.0_23] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [na:1.6.0_23] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [na:1.6.0_23] at java.lang.reflect.Method.invoke(Method.java:597) [na:1.6.0_23] at org.sonar.runner.Main.delegateExecution(Main.java:111) [sonar-runner.jar:na] at org.sonar.runner.Main.execute(Main.java:67) [sonar-runner.jar:na] at org.sonar.runner.Main.main(Main.java:48) [sonar-runner.jar:na]
The resolution to the above error is to specify java source and target versions using the advanced parameters named sonar.java.source and sonar.java.target. If you are analyzing using sonar-running you need to specify these properties in the sonar-project.properties file.
Installing Sonar With Oracle
Installing sonar (version 2.8) is fairly easy after following the installation guide. Below is one tip which you should consider when using oracle as the database for sonar installation.
The Oracle schema for sonar should be created with the below sql commands
CREATE USER sonar IDENTIFIED BY sonar; GRANT CREATE SESSION, CREATE TABLE, CREATE VIEW, CREATE SYNONYM, CREATE SEQUENCE, CREATE PROCEDURE, CREATE TRIGGER TO sonar; ALTER USER Sonar Quota 300M ON Users;
Before I discovered the above queries (thanks to this blog) I tried creating the schema using create user and grant all permissions sql queries. Starting the sonar server always failed with the below error
ActiveRecord::ActiveRecordError: ORA-00904: “ENABLED”: invalid identifier: INSERT INTO users (row_identifier, login_id, full_name, email, row_version, user_id, enabled, login, name, crypted_password, salt, created_at, updated_at, remember_token, remember_token_expires_at, id) VALUES(null, null, null, ”, null, null, 0, ‘admin’, ‘Administrator’, ‘fdf038c3d9a8f1a260c7fe3c6657e91dc46ca448′, ’43b15bc57d3bd82b408970c550c03fdd8f29d95e’, TIMESTAMP’2011-06-03 21:42:54′, TIMESTAMP’2011-06-03 21:42:54′, null, null, ?)