You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mike Van <mv...@comcast.net> on 2012/03/23 03:44:28 UTC

Command-Line execution of a third-party task

How would you execute a third-party-task from the command-line? 
Specifically, I would like to execute the sonar-ant-task from the
command-line on a project with an existing build.xml file. Unfortunately,
editing the parent build.xml file isn't an option because of the 60+ modules
and thier sub-modules in the application.  I have seen that the
sonar-maven-plugin can be executed from the command line using the
following:
mvn -e org.codehaus.mojo:sonar-maven-plugin:1.0:sonar

Is there a similar mechanism that could be used to pass in a 3rd party
ant-task as an argument for an ant build along with its required properties?

--
View this message in context: http://ant.1045680.n5.nabble.com/Command-Line-execution-of-a-third-party-task-tp5588338p5588338.html
Sent from the Ant - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Command-Line execution of a third-party task

Posted by Sahan Maldeniya <sm...@gmail.com>.
you can use ant taskdef tag to invoke other 3rd party tools.
I have used ant taskdef to invoke hibernatetools once in my project

i hope you can get an idea from these articles
http://ant.apache.org/manual/Tasks/taskdef.html
http://ant.apache.org/manual/develop.html


regards.

On Fri, Mar 23, 2012 at 8:14 AM, Mike Van <mv...@comcast.net> wrote:

> How would you execute a third-party-task from the command-line?
> Specifically, I would like to execute the sonar-ant-task from the
> command-line on a project with an existing build.xml file. Unfortunately,
> editing the parent build.xml file isn't an option because of the 60+
> modules
> and thier sub-modules in the application.  I have seen that the
> sonar-maven-plugin can be executed from the command line using the
> following:
> mvn -e org.codehaus.mojo:sonar-maven-plugin:1.0:sonar
>
> Is there a similar mechanism that could be used to pass in a 3rd party
> ant-task as an argument for an ant build along with its required
> properties?
>
> --
> View this message in context:
> http://ant.1045680.n5.nabble.com/Command-Line-execution-of-a-third-party-task-tp5588338p5588338.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
*
*
*Sahan Maldeniya.*
*
About me <http://about.me/sahanlm>.*

Re: Command-Line execution of a third-party task

Posted by Dominique Devienne <dd...@gmail.com>.
On Fri, Mar 23, 2012 at 12:21 PM, Stefan Bodewig <bo...@apache.org> wrote:
> http://janmaterne.wordpress.com/2008/11/07/ant-javafront-start-ant-tasks-from-the-command-line/
> http://janmaterne.wordpress.com/2008/11/11/ant-javafront-start-ant-tasks-from-the-command-line-2/

I stand corrected Stefan, thanks. And this is cool! :) --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Command-Line execution of a third-party task

Posted by Andreas Krey <a....@gmx.de>.
On Fri, 23 Mar 2012 19:06:38 +0000, Mike Van wrote:
...
> So, I wrote a tool called the Sonar Code Quality Manager (SonarCQM), which
> will probably be donated to sonarsource later on this year.  That tool scans
> a "conf" directory. In that directory, for each build Sonar is doing, there
> is one configuration file with SVN checkout information,

=== sample.conf
url=http://svn/wherever/module/trunk
build="ant build"

> maven/ivy/ant/grails build information, and of course the name of the build
> tool being used. The tool also has a "workspace" directory into which a
> fresh copy of each build's code is checked out into, and then the tool
> "invokes" the build tool indicated in the .conf file.

=== buildall.sh (not tested)
for i in confs/*.conf; do
  . "$i"
  wsname="`basename "$i" conf`"
  wsdir="workspace/$wsname"
  mkdir -p workspace
  rm -rf "$wsdir"
  svn checkout -q "$url" "$wsdir"
  (cd "$wsdir" && $build)
done

> That build uses the
> sonar plugin/task/whatever to generate the sonar stats.  I just completed
> the subversion and maven invokers.

Don't be a one-tool guy. Seriously, a 'subversion invoker'.
That has been invented thirty years ago, just not in java.
ant/java is trying to reinvent a lot of wheels there, and
mostly in a bad form.

Andreas

-- 
"Totally trivial. Famous last words."
From: Linus Torvalds <torvalds@*.org>
Date: Fri, 22 Jan 2010 07:29:21 -0800

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Command-Line execution of a third-party task

Posted by Mike Van <mv...@comcast.net>.
Stefan,

Thats great!  I was trying to find a way to programmatically kick off an 
ant-build anyway. Doing it from the command-line was just a stepping stone. 
This will allow me to write an "AntInvoker" class for my projects that use
ant builds in the same was as I have a MavenBuildInvoker that uses the
mavenInvoker library.  Now to write the same thing for ivy and grails!  :-)

Thanks folks for all of your help, it is greatly a deeply appreciated.

Oh, and for you folks that were wondering, I help run an enterprise software
development organization with about 30 projects and > 60 different
applications.  Each application needs to have four seperate sonar builds:
development, project-level integration, enterprise-level integration, and
production. So, if you do the math, that over 250 seperate builds. Each
project may use their own build environment, and what  I don't want my folks
doing is getting into the business of modifying the build.xml files for each
project that has chosen to use Ant. So, running from the command-line
without modifying the build files was a good approach. Because I could
easily pop that into Jenkins to manage my sonar analysis.

However, after thinking about it a second time, Jenkins wasn't really the
best place to do this because I would have needed to add 250+ new builds to
the over 60 that existed. Running >300 builds through jenkins would have
been unwieldy.

So, I wrote a tool called the Sonar Code Quality Manager (SonarCQM), which
will probably be donated to sonarsource later on this year.  That tool scans
a "conf" directory. In that directory, for each build Sonar is doing, there
is one configuration file with SVN checkout information,
maven/ivy/ant/grails build information, and of course the name of the build
tool being used. The tool also has a "workspace" directory into which a
fresh copy of each build's code is checked out into, and then the tool
"invokes" the build tool indicated in the .conf file.  That build uses the
sonar plugin/task/whatever to generate the sonar stats.  I just completed
the subversion and maven invokers. Now that I have the information on how to
programmatically kick off an ant build, I'm stoked, cuz my job is nearly
complete.

Anyhow, thanks again!

--
View this message in context: http://ant.1045680.n5.nabble.com/Command-Line-execution-of-a-third-party-task-tp5588338p5591089.html
Sent from the Ant - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Command-Line execution of a third-party task

Posted by Stefan Bodewig <bo...@apache.org>.
On 2012-03-23, Dominique Devienne wrote:

> On Fri, Mar 23, 2012 at 3:44 AM, Mike Van <mv...@comcast.net> wrote:
>> How would you execute a third-party-task from the command-line?
>> [...]
>> Is there a similar mechanism that could be used to pass in a 3rd party
>> ant-task as an argument for an ant build along with its required properties?

> I don't think there is, but it's an interesting idea.

http://janmaterne.wordpress.com/2008/11/07/ant-javafront-start-ant-tasks-from-the-command-line/
http://janmaterne.wordpress.com/2008/11/11/ant-javafront-start-ant-tasks-from-the-command-line-2/

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Command-Line execution of a third-party task

Posted by Dominique Devienne <dd...@gmail.com>.
On Fri, Mar 23, 2012 at 3:44 AM, Mike Van <mv...@comcast.net> wrote:
> How would you execute a third-party-task from the command-line?
> [...]
> Is there a similar mechanism that could be used to pass in a 3rd party
> ant-task as an argument for an ant build along with its required properties?

I don't think there is, but it's an interesting idea. Might be used to
prototype build steps at the command line for example. And if you
continue that kind of thinking, lead up to a kind of Ant REPL.

It reminds me a bit of something I did in the past
(http://markmail.org/message/32zq2gviwqtq46z7) except here you don't
want positional arguments, but named ones.

I think you'd be limited to attributes of the task, unless -nest/attr
implicitly declared a nested element. (but then how to configure
several similarly named nested elements?)

Would make an interesting little project, although I'm not sure anyone
as enough of an itch to code that up. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Command-Line execution of a third-party task

Posted by Dominique Devienne <dd...@gmail.com>.
On Fri, Mar 23, 2012 at 2:28 PM, Andy Stevens
<in...@googlemail.com> wrote:
> The way I read his original message, Mike just wants to run sonar
> against a project with an existing build.xml and was asking about
> direct use from the command line only because he isn't able/allowed to
> change the build.xml. But I wasn't sure if that applied to just
> build.xml or was a more general restriction...

Makes sense.

> Besides, if using *only* the command line directly was so essential,
> why bother messing around with the ant task anyway when sonar itself
> has a command line runner?  The only advantage to the Ant task is that
> it's, well, an Ant task.  Run it from an Ant script, the way it's
> chiefly designed to be run ;-)

Ah, you've exposed my complete ignorance of sonar to the world :)

> Just my opinion, anyway.

I did misread the post then (and my answer was wrong too! blush).

Thanks for the precision Andy. Cheers, --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Command-Line execution of a third-party task

Posted by Andy Stevens <in...@googlemail.com>.
Hi Dominique,

The way I read his original message, Mike just wants to run sonar
against a project with an existing build.xml and was asking about
direct use from the command line only because he isn't able/allowed to
change the build.xml. But I wasn't sure if that applied to just
build.xml or was a more general restriction...

Given the hoops you might have jump through on the command line to
pass in the parameters, I figured it was worth pointing out that Ant
scripts don't *have* to be called "build.xml", and a supplementary
build script (which could even be created on the fly in a shell
script) that can import the first and inherit its existing properties
and init stuff might be much simpler than any workaround/hack to
execute the task directly.  Especially if you have to read some values
from a properties file, perform variable substitution to calculate
others, build paths from a fileset, ...

Besides, if using *only* the command line directly was so essential,
why bother messing around with the ant task anyway when sonar itself
has a command line runner?  The only advantage to the Ant task is that
it's, well, an Ant task.  Run it from an Ant script, the way it's
chiefly designed to be run ;-)

Just my opinion, anyway.


Andy.


On 23 Mar 2012 10:44, "Dominique Devienne" <dd...@gmail.com> wrote:
>
> On Fri, Mar 23, 2012 at 9:29 AM, Andy Stevens
> <in...@googlemail.com> wrote:
> > Why not just create your own mybuild.xml and run that with ant -f ?
> > No need to alter the original build.xml, but you could always import it to
> > take advantage of any initialise targets etc.
>
> Note that Mike mentioned executing *tasks* from the CLI, not targets,
> i.e. potentially without any build.xml.
>
> For example "ant -e mkdir -dir=foo" or "ant -e zip
> '-includes=classes/**' -destfile=classes.jar".
>
> He does mention having many build files, and using *custom* tasks,
> which might require explicit taskdefs and classpaths, but assuming the
> custom tasks are already packaged in an antlib that's already on the
> classpath, or explicitly loaded with -lib, then it's only the matter
> of prefixing the task name with its namespace, as in "ant -lib
> libs/ant-contrib.jar -e antlib:net.sf.antcontrib:sometask ...".
>
> But maybe I didn't quite understand Mike's original post. In any case,
> I kinda like his idea, or Maven's I guess, the way I understood it at
> least :) --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Command-Line execution of a third-party task

Posted by Dominique Devienne <dd...@gmail.com>.
On Fri, Mar 23, 2012 at 9:29 AM, Andy Stevens
<in...@googlemail.com> wrote:
> Why not just create your own mybuild.xml and run that with ant -f ?
> No need to alter the original build.xml, but you could always import it to
> take advantage of any initialise targets etc.

Note that Mike mentioned executing *tasks* from the CLI, not targets,
i.e. potentially without any build.xml.

For example "ant -e mkdir -dir=foo" or "ant -e zip
'-includes=classes/**' -destfile=classes.jar".

He does mention having many build files, and using *custom* tasks,
which might require explicit taskdefs and classpaths, but assuming the
custom tasks are already packaged in an antlib that's already on the
classpath, or explicitly loaded with -lib, then it's only the matter
of prefixing the task name with its namespace, as in "ant -lib
libs/ant-contrib.jar -e antlib:net.sf.antcontrib:sometask ...".

But maybe I didn't quite understand Mike's original post. In any case,
I kinda like his idea, or Maven's I guess, the way I understood it at
least :) --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Command-Line execution of a third-party task

Posted by Andy Stevens <in...@googlemail.com>.
Why not just create your own mybuild.xml and run that with ant -f ?
No need to alter the original build.xml, but you could always import it to
take advantage of any initialise targets etc.

Andy.
On 23 Mar 2012 02:50, "Mike Van" <mv...@comcast.net> wrote:

> How would you execute a third-party-task from the command-line?
> Specifically, I would like to execute the sonar-ant-task from the
> command-line on a project with an existing build.xml file. Unfortunately,
> editing the parent build.xml file isn't an option because of the 60+
> modules
> and thier sub-modules in the application.  I have seen that the
> sonar-maven-plugin can be executed from the command line using the
> following:
> mvn -e org.codehaus.mojo:sonar-maven-plugin:1.0:sonar
>
> Is there a similar mechanism that could be used to pass in a 3rd party
> ant-task as an argument for an ant build along with its required
> properties?
>
> --
> View this message in context:
> http://ant.1045680.n5.nabble.com/Command-Line-execution-of-a-third-party-task-tp5588338p5588338.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>