|
Hello,
Just yesterday I installed SonarSource with sonar-runner and was trying to use it for C analysis with the latest C plugin (1.4). Unfortunately, I bumped into the first hurdle: Exception in thread "main" org.sonar.batch.bootstrapper.BootstrapException: org.sonar.api.utils.SonarException: Unable to read and import the source file : '/home/marc/projects/MyProject/srcs/LATEST/fw/tiny_mq/src/mp_transport.c' with the charset : 'UTF-8'. at org.sonar.runner.Runner.delegateExecution(Runner.java:189) at org.sonar.runner.Runner.execute(Runner.java:78) at org.sonar.runner.Main.main(Main.java:61) Caused by: org.sonar.api.utils.SonarException: Unable to read and import the source file : '/home/marc/projects/MyProject/srcs/LATEST/fw/tiny_mq/src/mp_transport.c' with the charset : 'UTF-8'. at org.sonar.api.batch.AbstractSourceImporter.parseDirs(AbstractSourceImporter.java:84) at org.sonar.api.batch.AbstractSourceImporter.analyse(AbstractSourceImporter.java:69) at org.sonar.api.batch.AbstractSourceImporter.analyse(AbstractSourceImporter.java:60) at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:64) ... This seems related to an already known 'problem' albeit in the PHP plugin !!! If sonar-runner finds an identical filename under 2 different subdirectories the above exception is generated. I have: $ find . -name mp_transport.c ./fw/transport/src/mp_transport.c ./fw/tiny_mq/src/mp_transport.c See also http://markmail.org/search/?q=%22Unable+to+read+and+import%22+parseDirs+list%3Aorg.codehaus.sonar.dev Is this a known error? Should I add comments somewhere? Regards, Marc |
|
Hi Marc,
By default, Sonar uses the charset of the machine used to execute the Sonar batch. To override this default charset (which seems to be necessary in your case), you should use the property 'sonar.sourceEncoding'.
Kind regards, Freddy -----
Sonar for Continuous Inspection On Thu, Mar 8, 2012 at 2:43 PM, Marc Verwerft <[hidden email]> wrote: Hello, |
|
Hello Freddy,
I've pursuited your reasoning and tried figuring out any differences in encoding or dos/unix style between the files and others that can be handled by sonar. I found none. Then I concluded I needed a test. So I've created 2 identical named EMPTY files in 2 directories. And I get the same error - so I think this proves it must be due to the identical filenames ... So I don't think I can fix this with the sourceEncoding setting ... Thanks for the reply though. Regards, Marc On Fri, Mar 9, 2012 at 11:10 AM, Freddy Mallet <[hidden email]> wrote: Hi Marc, |
|
Hi guys,
Indeed due to chains of exceptions in Sonar it's hard to distinguish two cases :
And in order to distinguish them - you should take a look (or provide for us) full stack-strace of error, which will contain root cause explaining problem. On Mon, Mar 12, 2012 at 12:29, Marc Verwerft <[hidden email]> wrote: Hello Freddy, Best regards, Evgeny Mandrikov aka Godin <http://godin.net.ru> http://twitter.com/_godin_ |
|
Hi all,
I've created a small test case as an example. One project consisting of 2 directories, each having 1 'src' subdir and containing an empty file named a.c. Empty files don't have encoding issues ;-) In each directory I've placed an additional c-file with a different name. Note that this type of construct is not uncommon for C language (as opposed to java/PHP I guess). Graphically:. ├── dir1 │ └── src │ ├── a.c │ └── b.c ├── dir2 │ └── src │ ├── a.c │ └── c.c When I run sonar-runner: this is what I get: Exception in thread "main" org.sonar.batch.bootstrapper.BootstrapException: org.sonar.api.utils.SonarException: Unable to read and import the source file : '/home/marc/projects/sonar-identicalFilenames/dir2/src/a.c' with the charset : 'UTF-8'. at org.sonar.runner.Runner.delegateExecution(Runner.java:189) at org.sonar.runner.Runner.execute(Runner.java:78) .... This is the full stack: marc@marc-laptop:~/projects$ mkdir sonar-identicalFilenames marc@marc-laptop:~/projects$ cd sonar-identicalFilenames/ marc@marc-laptop:~/projects/sonar-identicalFilenames$ mkdir -p dir1/src marc@marc-laptop:~/projects/sonar-identicalFilenames$ mkdir -p dir2/src marc@marc-laptop:~/projects/sonar-identicalFilenames$ touch dir1/src/a.c marc@marc-laptop:~/projects/sonar-identicalFilenames$ touch dir2/src/a.c marc@marc-laptop:~/projects/sonar-identicalFilenames$ touch dir1/src/b.c marc@marc-laptop:~/projects/sonar-identicalFilenames$ touch dir2/src/c.c marc@marc-laptop:~/projects/sonar-identicalFilenames$ gvim sonar-project.properties marc@marc-laptop:~/projects/sonar-identicalFilenames$ sonar-runner Runner configuration file: /home/marc/sonar/sonar-runner/sonar-runner-1.2/conf/sonar-runner.properties Project configuration file: /home/marc/projects/sonar-identicalFilenames/sonar-project.properties Runner version: 1.2 Java version: 1.6.0_23, vendor: Sun Microsystems Inc. OS name: "Linux", version: "3.0.0-16-generic", arch: "i386" Server: http://localhost:9000 Work directory: /home/marc/projects/sonar-identicalFilenames/.sonar 10:05:52.610 WARN Derby database should be used for evaluation purpose only 10:05:52.650 INFO Create JDBC datasource 10:05:54.749 INFO Initializing Hibernate 10:06:06.667 INFO ------------- Analyzing TestIdenticalFilenames 10:06:08.315 INFO Selected quality profile : [name=CLS C way,language=c] 10:06:08.452 INFO Configure maven plugins... 10:06:08.682 INFO Compare to previous analysis 10:06:08.736 INFO Compare over 5 days (2012-03-07) 10:06:08.759 INFO Compare over 30 days (2012-02-11) 10:06:08.910 INFO Initializer ProjectFileSystemLogger... 10:06:08.928 INFO Source directories: 10:06:08.928 INFO /home/marc/projects/sonar-identicalFilenames/dir1/src 10:06:08.928 INFO /home/marc/projects/sonar-identicalFilenames/dir2/src 10:06:08.929 INFO Initializer ProjectFileSystemLogger done: 19 ms 10:06:08.979 INFO Sensor com.sonar.c.plugin.B@1bde392... Total time: 25.329s Final Memory: 5M/46M Exception in thread "main" org.sonar.batch.bootstrapper.BootstrapException: org.sonar.api.utils.SonarException: Unable to read and import the source file : '/home/marc/projects/sonar-identicalFilenames/dir2/src/a.c' with the charset : 'UTF-8'. at org.sonar.runner.Runner.delegateExecution(Runner.java:189) at org.sonar.runner.Runner.execute(Runner.java:78) at org.sonar.runner.Main.main(Main.java:61) Caused by: org.sonar.api.utils.SonarException: Unable to read and import the source file : '/home/marc/projects/sonar-identicalFilenames/dir2/src/a.c' with the charset : 'UTF-8'. at org.sonar.api.batch.AbstractSourceImporter.parseDirs(AbstractSourceImporter.java:84) at org.sonar.api.batch.AbstractSourceImporter.analyse(AbstractSourceImporter.java:69) at org.sonar.api.batch.AbstractSourceImporter.analyse(AbstractSourceImporter.java:60) 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:111) at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:101) 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.Batch.execute(Batch.java:100) at org.sonar.runner.Launcher.executeBatch(Launcher.java:65) at org.sonar.runner.Launcher.execute(Launcher.java:58) 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.sonar.runner.Runner.delegateExecution(Runner.java:186) ... 2 more Caused by: org.sonar.api.resources.DuplicatedSourceException: org.sonar.api.resources.File@13638d4[key=a.c,dir=<null>,filename=a.c,language=C] at org.sonar.batch.index.SourcePersister.saveSource(SourcePersister.java:45) at org.sonar.batch.index.DefaultPersistenceManager.setSource(DefaultPersistenceManager.java:78) at org.sonar.batch.index.DefaultIndex.setSource(DefaultIndex.java:402) at org.sonar.batch.DefaultSensorContext.saveSource(DefaultSensorContext.java:159) at org.sonar.api.batch.AbstractSourceImporter.parseDirs(AbstractSourceImporter.java:81) ... 21 more The sonar-project.properties file: sonar.projectKey=Sonar12345 sonar.projectName=TestIdenticalFilenames sonar.projectVersion=1.0 sonar.projectDescription=Test for 2 identical filenames within the same 'namespace' (or directory tree). # Other Sonar properties # - Relative path to the source code files sources=dir1/src, dir2/src sonar.language=c # - Comma separated list of relative or absolute paths # to source code libraries sonar.c.library.directories= Hope this is sufficient for you Evgeny? Do I need to make a bug report or add comments somewhere? On Mon, Mar 12, 2012 at 9:38 AM, Evgeny Mandrikov <[hidden email]> wrote: Hi guys, |
|
Is it not an option for you to set a single source directory, which would be the parent directory of both "dir1" and "dir2" ?
(as opposed as two source folders, dir1/src and dir2/src) I guess that this would solve the problem for now.
-- Dinesh Bolkensteyn www.SonarSource.com twitter.com/DBolkensteyn On Mon, Mar 12, 2012 at 10:21 AM, Marc Verwerft <[hidden email]> wrote: Hi all, |
|
Hello Dinesh,
On Mon, Mar 12, 2012 at 11:25 AM, Dinesh Bolkensteyn <[hidden email]> wrote: Is it not an option for you to set a single source directory, which would be the parent directory of both "dir1" and "dir2" ?
Thanks - setting only 1 directory in the properties file solves it for this particular instance. But I need to think how it applies to my real project.
|
|
Hi Marc,
In fact this is a matter of namespace. In your first use case you're asking Sonar to analyse two different files having the same name "a.c" and the same namespace "root". In such case, this is the expected behavior to return the "DuplicatedSourceException" exception. You should prevent having such conflict by using different namespaces(/directories).
Kind regards, Freddy -----
Sonar for Continuous Inspection On Mon, Mar 12, 2012 at 11:46 AM, Marc Verwerft <[hidden email]> wrote: Hello Dinesh, |
|
Hi Freddy,
Thanks for the explanation. So the entry 'sources=' in the sonar-project.properties file are actually namespaces. If in those namespaces more than 1 file with the same path and filename is found, Sonar flags it as a namespace clash. I have 2 remarks then: - the exception name is not really helpfull in that case - you probably need to have a distinction between a namespace clash and a file with another encoding than the default. - if you need to do specify a different encoding, can you do that per file? Because if you do it on the command line (-D ...) then it's propably affecting all files. Regards, Marc On Mon, Mar 12, 2012 at 3:28 PM, Freddy Mallet <[hidden email]> wrote: Hi Marc, |
|
Hi Marc,
As I said before - we agree that exception should be modified in order to distinguish those two cases. About your second question : IMO project where source encoding is mixed (different for different files) is a bad practice and even maybe doesn't make sence. Thus IMO Sonar shouldn't allow to do this and this is a case now.
On Mon, Mar 12, 2012 at 18:59, Marc Verwerft <[hidden email]> wrote: Hi Freddy, Best regards, Evgeny Mandrikov aka Godin <http://godin.net.ru> http://twitter.com/_godin_ |
|
In reply to this post by Marc Verwerft
Hi Marc,
Can you provide proper configuration (with namespaces) for your example? Regards, Tomek |
|
This post has NOT been accepted by the mailing list yet.
In reply to this post by Evgeny Mandrikov
Hi,
I'm trying to analyze a large project containing duplicate java files. but getting the error below; --- Exception in thread "main" org.sonar.runner.RunnerException: org.sonar.api.utils .SonarException: Unable to read and import the source file : 'xxx.java' with the charset : 'UTF-8'. --- I've Sonar 3.4.1 installed. Is a there a workaround to overcome this problem? Because it is a common issue to have the same file names in diffrerent directories in that project http://jira.codehaus.org/browse/SONAR-2444 In that record, there is a comment --- Freddy Mallet added a comment - 02/Apr/12 9:01 AM Perhaps we could support a new "sonar.supportSourceFileDuplications" parameter to fix this issue. --- is it applied or how can I solve this problem in some way ? Sincerely, |
| Powered by Nabble | Edit this page |
