SonarQube PHP
  1. SonarQube PHP
  2. SONARPHP-40

Common PHP filenames in multiple source of test derectories

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.4
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Number of attachments :
      0

      Description

      If a project consists of multiple source directories, or a source directory and a test directory, and these directories have files with same names, sonar can't import these projects, because these files are considered as a same files, which causes an exception.

      For example:

      Source code folder (application):

      • Bootrstrap.php
      • Module1/
        • Class1.php
        • Class2.php
      • Module2/
        • Class1.php
        • Class2.php
        • Class3.php

      and a UnitTests folder (tests):

      • Bootrstrap.php
      • Module1/
        • Class1Test.php
        • Class2Test.php
      • Module2/
        • Class1Test.php
        • Class2Test.php
        • Class3.php

      The Bootstrap.php file has problems:

       
      Embedded error: PhpFile[filename=Bootstrap,longName=Bootstrap,packageKey=(default),parent=org.sonar.plugins.php.core.PhpPackage@51184a30,unitTest=true]
      [INFO] ------------------------------------------------------------------------
      [INFO] Trace
      org.apache.maven.lifecycle.LifecycleExecutionException: Can not execute Sonar
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:583)
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512)
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482)
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:227)
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
      	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
      	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
      	at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	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:451)
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
      	... 16 more
      Caused by: org.sonar.api.resources.DuplicatedSourceException: PhpFile[filename=Bootstrap,longName=Bootstrap,packageKey=(default),parent=org.sonar.plugins.php.core.PhpPackage@51184a30,unitTest=true]
      	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:407)
      	at org.sonar.batch.DefaultSensorContext.saveSource(DefaultSensorContext.java:159)
      	at org.sonar.plugins.php.core.PhpSourceImporter.parseDirs(PhpSourceImporter.java:143)
      	at org.sonar.plugins.php.core.PhpSourceImporter.doAnalyse(PhpSourceImporter.java:128)
      	at org.sonar.plugins.php.core.PhpSourceImporter.analyse(PhpSourceImporter.java:76)
      	at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:58)
      	at org.sonar.batch.phases.Phases.execute(Phases.java:80)
      	at org.sonar.batch.ProjectBatch.execute(ProjectBatch.java:59)
      	at org.sonar.batch.Batch.analyzeModule(Batch.java:164)
      	at org.sonar.batch.Batch.analyzeModules(Batch.java:82)
      	at org.sonar.batch.Batch.execute(Batch.java:62)
      	at org.sonar.maven.SonarMojo.executeBatch(SonarMojo.java:155)
      	at org.sonar.maven.SonarMojo.execute(SonarMojo.java:144)
      	at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
      	at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:98)
      	... 20 more
      

      The same concerns Class3.php

      The reason of exception is that Resource Key is internally represented as a relative path to a file.

        Issue Links

          Activity

          Hide
          Khalil KHOUJA added a comment -

          Hello,
          I have reproduced the same problem.

          Show
          Khalil KHOUJA added a comment - Hello, I have reproduced the same problem.
          Hide
          Fabrice Bellingard added a comment -

          This is not possible to fix this issue in Sonar yet. This will be addressed in the future when Sonar evolves to analyse unit test files.

          In the mean time:

          • I remove the fixFor version of this issue as we don't know yet when Sonar Core will address this topic
          • I created the following ticket on Sonar to display a clearer message: SONAR-2971
          • If you encounter this problem, you can try to rename (if possible) the test files that make the analysis fail
          Show
          Fabrice Bellingard added a comment - This is not possible to fix this issue in Sonar yet. This will be addressed in the future when Sonar evolves to analyse unit test files. In the mean time: I remove the fixFor version of this issue as we don't know yet when Sonar Core will address this topic I created the following ticket on Sonar to display a clearer message: SONAR-2971 If you encounter this problem, you can try to rename (if possible) the test files that make the analysis fail
          Hide
          Fabrice Bellingard added a comment -

          SONAR-3024 will be fixed in Sonar 2.14, so this issue will be addressed when Sonar 2.14 is available (or under development).

          Show
          Fabrice Bellingard added a comment - SONAR-3024 will be fixed in Sonar 2.14, so this issue will be addressed when Sonar 2.14 is available (or under development).
          Hide
          Fabrice Bellingard added a comment -

          Decreasing criticity as it is always possible to exclude those files with "sonar.exclusions" patterns - even though I agree that this should be fixed sooner or later.

          Show
          Fabrice Bellingard added a comment - Decreasing criticity as it is always possible to exclude those files with "sonar.exclusions" patterns - even though I agree that this should be fixed sooner or later.
          Hide
          Fabrice Bellingard added a comment -

          This issue automatically will be fixed with SonarQube 4.2 (see SONAR-3024).

          Show
          Fabrice Bellingard added a comment - This issue automatically will be fixed with SonarQube 4.2 (see SONAR-3024 ).

            People

            • Assignee:
              Unassigned
              Reporter:
              Anonymous
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: