Calling a rakefile from NAnt - ruby

I am dealing with a relatively large project, and up until this point building has been done in a NAnt build script. Recently a small portion of development was done in ruby, and is built using a rake file. I would like to create a NAnt target that will call the rakefile. Current set-up in the NAnt build: (Note that the rakefile is in a different directory from the NAnt script)
<property overwrite="false" name="project.rootdirectory" value="${project::get-base-directory()}" />
<property overwrite="false" name="rake.exe" value="rake.bat" />
<target name="callrake">
<exec program="${rake.exe}" verbose="true">
<arg value="build:foo" />
<arg line="-f ${project.rootdirectory}/../pathtorakefile" />
</exec>
</target>
The error that I recieve when I run nant callrake is:
[exec] ruby.exe: No such file or directory -- c:/pathtoNAntscript/rake (LoadError)
c:/pathtoNAntscript/NAntscript.build
External Program Failed: rake.bat (return code was 1)
Ruby and rake are installed, and the Ruby bin is in the path variable. Not sure why NAnt cant seem to call rake.

This issue is solved by calling cmd.exe and passing it the rake command as text:
<exec program="cmd.exe" verbose="true">
<arg line="/c ${rake.exe} build:foo" />
<arg line="-f ${project.rootdirectory}/../pathtorakefile/Rakefile.rb" />
</exec>

Related

How to run Maven command in ant script?

I am trying to create an ant task to execute a maven command, but I am getting error while running the ant task
<target name="Junit">
<exec dir="./MServer/BuildServer/Workspc/CustMgmt" executable="cmd">
<arg value="/C"/>
<arg value="E:\EOM Setup\maven-3.3.9\bin\mvn.bat"/>
<arg value="test" />
</exec>
</target>
While am running this, am getting an error:
'E:\EOM' is not recognized as internal or external command, operable program or batch file
(I am running on Windows 7)
You can get around this issue by using Ant's property task with the location attribute (as opposed to the more common value attribute). This will store the value as a properly formatted path. In addition, you can use this to reference mvn.bat instead of typing out the entire path every time.
<target name="Junit">
<property name="mvn.executable" location="E:\EOM Setup\maven-3.3.9\bin\mvn.bat" />
<exec dir="./MServer/BuildServer/Workspc/CustMgmt" executable="cmd">
<arg value="/C"/>
<arg value="${mvn.executable}"/>
<arg value="test" />
</exec>
</target>

How to use skipTests option when using mvn-ant-tasks in ant

I am using mvn-ant-task in a build file to clean and install the Maven projects.
Below is the configuration I did
<project name="maven-project"
default="default"
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
and in the target, I have added something like this
<target name="CleanInstall">
<echo message="Building the project using maven and skipping tests if any in ${RepoFolder}" />
<artifact:mvn pom="${GIT_REPO_HOME}\${RepoFolder}\pom.xml">
<arg value="clean:clean" />
</artifact:mvn>
<artifact:mvn pom="${GIT_REPO_HOME}\${RepoFolder}\pom.xml">
<arg value="install:install -DskipTests=true" />
</artifact:mvn>
</target>
When I run this build, clean is processing properly, but I am unable to send the arguments skipTests in the install plugin.
Is there any other way to execute the Maven commands from Ant? I also tried
<exec command="mvn install -DskipTests=true" dir=""${GIT_REPO_HOME}\${RepoFolder}\pom.xml"/>
Its failing with error given below
C:\Users\sharath\Desktop\devsetup\build.xml:102: Execute failed:
java.io.IOException: Cannot run program "mvn" (in directory
"D:\sbhaskara\GIT\connectmodel"): CreateProcess error=2, The system
cannot find the file specified
You are not building the argument for the task correctly, it should be:
<target name="CleanInstall">
<echo message="Building the project using maven and skipping tests if any in ${RepoFolder}" />
<artifact:mvn pom="${GIT_REPO_HOME}\${RepoFolder}\pom.xml" >
<arg value="-Dmaven.test.skip=true" />
<arg value="clean" />
<arg value="install" />
</artifact:mvn>
</target>
i.e. each argument must be in its own <arg> tag. Note that I collapsed all the calls to Maven inside a single task.

install highcharts exporting server

I'm trying to install highcharts exporting server(by java). I want to write below maven command line in build.xml file of my project. Not run from cmd.
$ cd highcharts-export/
$ mvn install
How should I do that in build.xml file?
I wrote following in build.xml file and run by ANT. But nothing happens. And idea?
<target name="buildHighchartsExporting" description="Builds highcharts exporting">
<exec dir="${basedir}/highcharts-export" executable="cmd">
<arg value="mvn" />
<arg line="-f highcharts-export/pom.xml install" />
</exec>
<target name="buildWarFile" description="Builds highcharts exporting War">
<exec dir="${basedir}/highcharts-export/highcharts-export-web" executable="cmd">
<arg value="mvn" />
<arg line="clean package" />
</exec>
If you are just trying to execute a project where the pom.xml is at another folder, you can use the -f parameter:
6.1.6. Using a Custom POM or Custom Settings File
If you don’t like the pom.xml file name, the location of your user-specific Maven
settings, or the default location of your global settings file, you
can customize any of these things with the following options:
-f, --file <file>
Forces the use of an alternate POM file
This way, from where you'd execute:
$ cd highcharts-export/
$ mvn install
You can just use:
$ mvn -f highcharts-export/pom.xml install
Running mvn from an ANT build.xml file
You can use the Ant Exec Task:
<target name="buildProject" description="Builds the project">
<exec dir="${source.dir}\${projectName}" executable="cmd">
<arg value="mvn" />
<arg line="-f highcharts-export/pom.xml install" />
</exec>
</target>
Or, more specifically (to your example):
<target name="buildWarFile" description="Builds highcharts exporting War">
<exec dir="${basedir}/highcharts-export" executable="cmd">
<arg value="mvn" />
<arg line="clean package" />
</exec>

Running Ruby tests (Rspec and Cucumber) through Ant

I'm currently looking at TeamCity and how to get our Ruby tests running. I can run the tests just fine when using the Command line or Rake builders. The question I'm trying to solve right now is two fold:
In one of my previous jobs, we also relied on TeamCity to run our .NET tests. We used Nant for this and we had means of tracking the amount of queries that were ran during tests as well as the average execution time for these queries.
I'm trying to do the same right now with my Ruby project. So the first logical step I want to tackle is, How do I run for example RSpec or Cucumber tests using Ant?
I tried looking at Ant itself and grasp it a little bit, but all the examples I find are for jRuby, which we don't use. We rely on RVM and a normal Ruby installation.
The second part of the question is, How can I track the amount of queries ran and their execution time? I'm guessing there is probably a gem for it or some sort of global variable to track. Would love to output this information back to TeamCity somehow.
EDIT
Ok, so I managed to get things running with Ant for my TeamCity server.
This is the XML i'm using atm:
<?xml version="1.0"?>
<project name="rubycas" default="init">
<description>
This buildfile is used to build the RubyCAS project under TeamCity and run the required tasks to validated
whether the project is stable and fully functional.
</description>
<property name="test_type" value="cucumber" />
<target name="init">
<echo message="##teamcity[testStarted name='Rubycas']" />
<condition property="cucumberBool">
<equals arg1="${test_type}" arg2="cucumber" />
</condition>
<condition property="rspecBool">
<equals arg1="${test_type}" arg2="rspec" />
</condition>
</target>
<target name="rspec" if="rspecBool" depends="init">
<exec executable="rspec" outputproperty="result">
<arg value="--require teamcity/spec/runner/formatter/teamcity/formatter" /> <arg value="--format Spec::Runner::Formatter::TeamcityFormatter" />
</exec>
<echo message="${result}" />
</target>
<target name="cucumber" if="cucumberBool" depends="init">
<exec executable="cucumber" outputproperty="result">
<arg value="--format junit" />
<arg value="--out results" />
<arg value="features" />
</exec>
<echo message="${result}" />
</target>
</project>
Problem now is, I cannot get the output from RSpec into TeamCity to recognize the tests.
You can use ant's exec task to run arbitrary system calls, which in your case might be rspec:
https://ant.apache.org/manual/Tasks/exec.html
Something along the lines of
<target name="rspec">
<exec executable="rake">
<arg value="spec"/>
</exec>
</target>
I don't know if your tracking stuff will work with this though, because it's really executing the commands outside of ant.

How can I run perl and ruby scripts as tasks in ant?

I would like to be able to run ruby and perl scripts from build.xml in ant.
Languages like Ruby have Java implementations.
<project name="RunRubyExample">
<property environment="env" />
<script language="ruby" manager="bsf">
<classpath>
<fileset dir="${env.JRUBY_HOME}/lib" includes="*.jar" />
</classpath>
print 'hello world'
</script>
</project>
See the list of languages supporting the JSR233 standard.
Unfortunately no Java version of Perl is available. The only way to run Perl scripts is to invoke the interpreter directly:
<project name="RunPerlExample">
<exec executable="perl" failonerror="true">
<arg value="-e" />
<arg value="print 'hello world'" />
</exec>
</project>
You can always use the ant`s exec task to run arbitrary programs, such as ruby and perl. For example and from the docs:
<target name="help">
<exec executable="cmd">
<arg value="/c"/>
<arg value="ant.bat"/>
<arg value="-p"/>
</exec>
</target>

Resources