SonarQube Plugins
  1. SonarQube Plugins
  2. SONARPLUGINS-1468

Make the Sonar Ant task work with property "sonar.modules" containing absolute paths.

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: ANT-TASK-1.4
    • Component/s: Ant Task
    • Labels:
      None
    • Environment:
      Windows; Ant 1.8.2, Sonar 2.11, sonar-ant-task-1.2
    • Number of attachments :
      0

      Description

      Anttask failed if property "sonar.modules" contains absolute pathes.
      I used following code to find modules dynamically:

      <fileset dir="./modules" id="sonar.modules">
      <include name="*/build.xml"/>
      </fileset>
      <pathconvert property="sonar.modules" dirsep="/" pathsep="," refid="sonar.modules"/>

      https://svn.codehaus.org/sonar-plugins/trunk/ant-task/src/main/java/org/sonar/ant/Launcher.java
      Revision 4577
      private void defineModules(Project antProject, ProjectDefinition definition) {
      String[] modules = StringUtils.split(definition.getProperties().getProperty("sonar.modules", ""), ',');
      for (String module : modules)

      { File buildFile = new File(antProject.getBaseDir(), module); // <--------------------- Project antSubProject = prepareSubProject(antProject, buildFile); definition.addModule(defineProject(antSubProject)); }

      }

      C:\java_svn\aikuchi\installer\analyze-installer\build.xml:211: java.io.FileNotFoundException: C:\test\C:\test\module-a\build.xml
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.<init>(FileInputStream.java:120)
      at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:278)
      at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:178)
      at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:82)
      at org.sonar.ant.Launcher.prepareSubProject(Launcher.java:174)
      at org.sonar.ant.Launcher.defineModules(Launcher.java:163)
      at org.sonar.ant.Launcher.defineProject(Launcher.java:109)
      at org.sonar.ant.Launcher.executeBatch(Launcher.java:207)
      at org.sonar.ant.Launcher.execute(Launcher.java:66)
      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.sonar.ant.SonarTask.delegateExecution(SonarTask.java:205)
      at org.sonar.ant.SonarTask.execute(SonarTask.java:189)
      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      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)

        Activity

        Hide
        Damien Bouillot added a comment -

        Ugly workaround in xml file is to use <map> to transform absolute path in relative path

        example :

        <path id="modules">
        <fileset dir='task' includes='*.xml'/>
        </path>
        <pathconvert property='sonar.modules' refid='modules' pathsep=','>
        <!-- hack because sonar.modules doesn't accept absolute path -->
        <map from="$

        {basedir}

        " to=""/>
        </pathconvert>

        Show
        Damien Bouillot added a comment - Ugly workaround in xml file is to use <map> to transform absolute path in relative path example : <path id="modules"> <fileset dir='task' includes='*.xml'/> </path> <pathconvert property='sonar.modules' refid='modules' pathsep=','> <!-- hack because sonar.modules doesn't accept absolute path --> <map from="$ {basedir} " to=""/> </pathconvert>
        Hide
        Christoph Forster added a comment -

        Workaround doesn't work because at this point the basedir isn't actually added. Basedir will be added within the call of <sonar:sonar ...>.

        Show
        Christoph Forster added a comment - Workaround doesn't work because at this point the basedir isn't actually added. Basedir will be added within the call of <sonar:sonar ...>.
        Hide
        Fabrice Bellingard added a comment -

        Done and IT added.

        Show
        Fabrice Bellingard added a comment - Done and IT added.
        Hide
        Freddy Mallet added a comment -

        Manually tested !

        Show
        Freddy Mallet added a comment - Manually tested !

          People

          • Assignee:
            Fabrice Bellingard
            Reporter:
            Florian Vogler
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: