1

I want to use NAnt to execute sonar to scan my C# code. The sonar command line is "mvn sonar:sonar", in which 'mvn' is the command name, 'sonar:sonar' is the user name and password. I tried two ways to execute it:

1.

<target name="buildOM" description="......">
    <exec program="mvn" workingdir="C:\codes\projects\helloworld">
        <arg value="sonar:sonar"/>
    </exec>
</exec>

2.

<target name="buildOM" description="......">
    <exec program="mvn sonar:sonar" workingdir="C:\codes\projects\helloworld">
    </exec>
</exec>

But these do not work. I found 'input' tag for Ant. "Ant : Passing username and password to exec". But I cannot find it in NAnt help document. I try to search the solution in the internet for 2 days, but failed.

Could you help me how to resolve it ? Thank you.

Community
  • 1
  • 1
Jeffery You
  • 109
  • 2
  • 2
  • 11

2 Answers2

1

How about calling the command shell and running maven within it? Something like below...

<target name="buildOM" description="......">
    <exec program="cmd.exe" workingdir="C:\codes\projects\helloworld">
        <arg value="/c mvn sonar:sonar"/>
    </exec>
</exec>
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • Thank you for your help! Your solution can do it well. As an alternate, I found another way similar to yours. That is: specify the mvn.bat file location. But, generally speaking, you solution is better than mine, because it doesn't need to know where is mvn. Thank you for your help. – Jeffery You Nov 07 '11 at 08:25
0

The new version of the C# plugin uses the Java runner, not Maven, to launch Sonar. Details on setup are here

http://docs.codehaus.org/display/SONAR/C-Sharp+Plugins+Ecosystem

The Java runner is documented here

http://docs.codehaus.org/display/SONAR/Analyse+with+a+simple+Java+Runner

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Sorry, Sonar works well in my environment. I can use cmd, and redirect to the C# project folder, and input 'mvn sonar:sonar' to scan specified code. But did not know how to configure the execution in NAnt. – Jeffery You Nov 06 '11 at 12:01
  • So this is really a NANT question? You've tagged your question incorrectly in that case. – Mark O'Connor Nov 06 '11 at 15:23
  • I'm sorry, maybe it's my fault not to tag it correctly. Anyhow, thank you for your sincere help. ^_^ – Jeffery You Nov 07 '11 at 08:30