You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Anders Rundgren <an...@telia.com> on 2012/09/20 12:11:10 UTC

Request - Native Java "Script" Support

Dear Ant-Team,
I am an avid Ant user since more than 10 years back and I'm happy to see how it has progressed!

Recently I have begun writing very complex build scripts and found myself craving for a more programmatic solution which using Ant in standard configurations means using JavaScript or writing extensions.

In addition, I have also been using .NET tools like NAnt.

In NAnt there is no JavaScript support but there is support for native C#.

I find C# and Java much better for this purpose than JavaScript so my question is really:
Would it be completely unthinkable to add Java as a scripting language?
Since Ant already presumes JDK it doesn't sound completely undoable either.

Beanshell isn't an active project and I don't see any advantage with Beanshell compared to native Java.

Sincerely,
Anders Rundgren

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


RE: Request - Native Java "Script" Support

Posted by Martin Gainty <mg...@hotmail.com>.
jarekczek

I am now compiling and packaging axis2-1.6.2 a series of maven and ant scripts ..all libraries i have are version specific so
my recommendation is to go with maven 3+
http://maven.apache.org/download.html
and <configure> the call to build.xml on your specific target

pom.xml would contain
<plugins>
              <plugin>
                <artifactId>maven-antrun-plugin</artifactId>

 <configure>
 <ant antfile="${basedir}/build.xml">
                  <target name="test"/>
 </ant>http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html


				
					
					
					Dziękujemy,
Martin Gainty 
______________________________________________ 
Note de déni et de confidentialité
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.


> Date: Fri, 21 Sep 2012 08:33:20 +0200
> From: jarekczek@poczta.onet.pl
> To: dev@ant.apache.org
> Subject: Re: Request - Native Java "Script" Support
> 
> W dniu 2012-09-20 13:55, Anders Rundgren pisze:
> > I haven't tried with Groovy script and my request is really about getting
> > a core feature already verified being useful in NAnt into the default Ant
> > installation so you can *ship build scripts to anybody* (having an upgraded
> > Ant NB...) without requiring yet another install.
> 
> Hi Ants :)
> 
> I'd like to note that tools like ivy allow installing additional modules 
> (like groovy jar) on the fly. That is: a smart ant script first checks 
> for ivy, then downloads it. When ivy is already there, downloading and 
> adding to execution path a groovy jar is a piece of cake. And there are 
> examples of such smart scripts (ivy page) and they are in common use.
> 
> So the groovy solution may be more acceptable than you first thought of 
> it, Anders.
> 
> I'm afraid that there is a general crisis among open source developers 
> and they should spare resources whenever possible. Any new feature draws 
> resources, so it's general disadvantage of new features. Generating 
> future bugs is a long-time cost and I would expect many such bugs from 
> such a complex feature.
> 
> And finally if maven (or anything) is ever really undisputably better, 
> than we all switch to maven and be happy. No need to have many open 
> source tools doing the same. That would also mean a waste of resources.
> 
> Regards
> Jarek
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
> 
 		 	   		  

Re: Request - Native Java "Script" Support

Posted by Jarek Czekalski <ja...@poczta.onet.pl>.
W dniu 2012-09-20 13:55, Anders Rundgren pisze:
> I haven't tried with Groovy script and my request is really about getting
> a core feature already verified being useful in NAnt into the default Ant
> installation so you can *ship build scripts to anybody* (having an upgraded
> Ant NB...) without requiring yet another install.

Hi Ants :)

I'd like to note that tools like ivy allow installing additional modules 
(like groovy jar) on the fly. That is: a smart ant script first checks 
for ivy, then downloads it. When ivy is already there, downloading and 
adding to execution path a groovy jar is a piece of cake. And there are 
examples of such smart scripts (ivy page) and they are in common use.

So the groovy solution may be more acceptable than you first thought of 
it, Anders.

I'm afraid that there is a general crisis among open source developers 
and they should spare resources whenever possible. Any new feature draws 
resources, so it's general disadvantage of new features. Generating 
future bugs is a long-time cost and I would expect many such bugs from 
such a complex feature.

And finally if maven (or anything) is ever really undisputably better, 
than we all switch to maven and be happy. No need to have many open 
source tools doing the same. That would also mean a waste of resources.

Regards
Jarek


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


Re: Request - Native Java "Script" Support

Posted by Matt Benson <gu...@gmail.com>.
Some years ago Stefan Bodewig and Jan Materne worked on this:

http://svn.apache.org/repos/asf/ant/sandbox/javafront/

YMMV

Matt

On Thu, Sep 20, 2012 at 11:45 AM, Jeffrey E Care <ca...@us.ibm.com> wrote:
> Anders Rundgren <an...@telia.com> wrote on 09/20/2012 09:27:10
> AM:
>
>> I guess I knew that this idea wouldn't get a big hooray...
>>
>> If you had tried NAnt you would probably agree that in-line Java
>> is cooler than custom tasks because you (can) have the entire script
>> in one file.
>>
>> The proposal wasn't to satisfy my own needs but to serve a large base
>> of Ant users who are considering jumping the ship for Maven and other
>> tools.
>
> I doubt I would agree.
>
> In my experience anything sufficiently complicated that it can't be
> handled by the standard tasks is going to require non-trivial custom code.
> No matter what technology I'm using to implement that custom code (e.g.
> javascript, java, groovy) I'm not going to want to clutter up my build.xml
> with it. I'm going to want to use my regular development tools to write
> that code.
>
> Having operated in both the Ant & Maven worlds my answer is the same: if I
> need to do something custom in Ant I'm going to want to write a
> full-fledged custom task instead of trying to inline it in my build.xml;
> if I need to do something custom in Maven I'm going to want to write a
> full-fledged mojo instead of trying to inline it in my POM.

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


Re: Request - Native Java "Script" Support

Posted by Anders Rundgren <an...@telia.com>.
On 2012-09-20 18:45, Jeffrey E Care wrote:
> Anders Rundgren <an...@telia.com> wrote on 09/20/2012 09:27:10 
> AM:
> 
>> I guess I knew that this idea wouldn't get a big hooray...
>>
>> If you had tried NAnt you would probably agree that in-line Java
>> is cooler than custom tasks because you (can) have the entire script
>> in one file.
>>
>> The proposal wasn't to satisfy my own needs but to serve a large base
>> of Ant users who are considering jumping the ship for Maven and other
>> tools.
> 
> I doubt I would agree.
> 
> In my experience anything sufficiently complicated that it can't be 
> handled by the standard tasks is going to require non-trivial custom code. 
> No matter what technology I'm using to implement that custom code (e.g. 
> javascript, java, groovy) I'm not going to want to clutter up my build.xml 
> with it. I'm going to want to use my regular development tools to write 
> that code.
> 
> Having operated in both the Ant & Maven worlds my answer is the same: if I 
> need to do something custom in Ant I'm going to want to write a 
> full-fledged custom task instead of trying to inline it in my build.xml; 
> if I need to do something custom in Maven I'm going to want to write a 
> full-fledged mojo instead of trying to inline it in my POM.
> 

We all do our choices.  The request was simply about extending the
range of those :-)

Anders

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


Re: Request - Native Java "Script" Support

Posted by Jeffrey E Care <ca...@us.ibm.com>.
Anders Rundgren <an...@telia.com> wrote on 09/20/2012 09:27:10 
AM:

> I guess I knew that this idea wouldn't get a big hooray...
> 
> If you had tried NAnt you would probably agree that in-line Java
> is cooler than custom tasks because you (can) have the entire script
> in one file.
> 
> The proposal wasn't to satisfy my own needs but to serve a large base
> of Ant users who are considering jumping the ship for Maven and other
> tools.

I doubt I would agree.

In my experience anything sufficiently complicated that it can't be 
handled by the standard tasks is going to require non-trivial custom code. 
No matter what technology I'm using to implement that custom code (e.g. 
javascript, java, groovy) I'm not going to want to clutter up my build.xml 
with it. I'm going to want to use my regular development tools to write 
that code.

Having operated in both the Ant & Maven worlds my answer is the same: if I 
need to do something custom in Ant I'm going to want to write a 
full-fledged custom task instead of trying to inline it in my build.xml; 
if I need to do something custom in Maven I'm going to want to write a 
full-fledged mojo instead of trying to inline it in my POM.

Re: Request - Native Java "Script" Support

Posted by Anders Rundgren <an...@telia.com>.
On 2012-09-20 15:11, Jeffrey E Care wrote:
> Anders Rundgren <an...@telia.com> wrote on 09/20/2012 07:55:13 
> AM:
> 
>> I haven't tried with Groovy script and my request is really about getting
>> a core feature already verified being useful in NAnt into the default Ant
>> installation so you can ship build scripts to anybody (having an upgraded
>> Ant NB...) without requiring yet another install.
>>
>> It is quite possible that I'm wrong but it seems that this would something
>> like the "javac" and "java" targets combined so 90% of the code should already
>> be in place sort of :-)
>>
>> IMO such a feature could extend the life of Ant considerably.  Nobody can beat
>> the power of a full-blown programming language!
> 
> Why not just write a custom task? 

Jeffrey,

I guess I knew that this idea wouldn't get a big hooray...

If you had tried NAnt you would probably agree that in-line Java
is cooler than custom tasks because you (can) have the entire script
in one file.

The proposal wasn't to satisfy my own needs but to serve a large base
of Ant users who are considering jumping the ship for Maven and other
tools.

Oh well.

Anders


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


Re: Request - Native Java "Script" Support

Posted by Jeffrey E Care <ca...@us.ibm.com>.
Anders Rundgren <an...@telia.com> wrote on 09/20/2012 07:55:13 
AM:

> I haven't tried with Groovy script and my request is really about 
getting
> a core feature already verified being useful in NAnt into the default 
Ant
> installation so you can ship build scripts to anybody (having an 
upgraded
> Ant NB...) without requiring yet another install.
> 
> It is quite possible that I'm wrong but it seems that this would 
something
> like the "javac" and "java" targets combined so 90% of the code should 
already
> be in place sort of :-)
> 
> IMO such a feature could extend the life of Ant considerably.  Nobody 
can beat
> the power of a full-blown programming language!

Why not just write a custom task? 

Re: Request - Native Java "Script" Support

Posted by Anders Rundgren <an...@telia.com>.
On 2012-09-20 13:21, Vimil Saju wrote:
> Hi Anders,
> 
> Have you tried groovy script? I think groovy is completely compatible with java.
> That is any valid java code is valid groovy code too.

Hi Vimil,
I guess you refer to: http://groovy.codehaus.org ?

I haven't tried with Groovy script and my request is really about getting
a core feature already verified being useful in NAnt into the default Ant
installation so you can ship build scripts to anybody (having an upgraded
Ant NB...) without requiring yet another install.

It is quite possible that I'm wrong but it seems that this would something
like the "javac" and "java" targets combined so 90% of the code should already
be in place sort of :-)

IMO such a feature could extend the life of Ant considerably.  Nobody can beat
the power of a full-blown programming language!

Regards,
Anders

> 
> 
> ________________________________
>  From: Anders Rundgren <an...@telia.com>
> To: dev@ant.apache.org 
> Sent: Thursday, September 20, 2012 3:11 AM
> Subject: Request - Native Java "Script" Support
>  
> Dear Ant-Team,
> I am an avid Ant user since more than 10 years back and I'm happy to see how it has progressed!
> 
> Recently I have begun writing very complex build scripts and found myself craving for a more programmatic solution which using Ant in standard configurations means using JavaScript or writing extensions.
> 
> In addition, I have also been using .NET tools like NAnt.
> 
> In NAnt there is no JavaScript support but there is support for native C#.
> 
> I find C# and Java much better for this purpose than JavaScript so my question is really:
> Would it be completely unthinkable to add Java as a scripting language?
> Since Ant already presumes JDK it doesn't sound completely undoable either.
> 
> Beanshell isn't an active project and I don't see any advantage with Beanshell compared to native Java.
> 
> Sincerely,
> Anders Rundgren
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
> 


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


Re: Request - Native Java "Script" Support

Posted by Vimil Saju <vi...@yahoo.com>.
Hi Anders,

Have you tried groovy script? I think groovy is completely compatible with java. That is any valid java code is valid groovy code too. 


________________________________
 From: Anders Rundgren <an...@telia.com>
To: dev@ant.apache.org 
Sent: Thursday, September 20, 2012 3:11 AM
Subject: Request - Native Java "Script" Support
 
Dear Ant-Team,
I am an avid Ant user since more than 10 years back and I'm happy to see how it has progressed!

Recently I have begun writing very complex build scripts and found myself craving for a more programmatic solution which using Ant in standard configurations means using JavaScript or writing extensions.

In addition, I have also been using .NET tools like NAnt.

In NAnt there is no JavaScript support but there is support for native C#.

I find C# and Java much better for this purpose than JavaScript so my question is really:
Would it be completely unthinkable to add Java as a scripting language?
Since Ant already presumes JDK it doesn't sound completely undoable either.

Beanshell isn't an active project and I don't see any advantage with Beanshell compared to native Java.

Sincerely,
Anders Rundgren

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

Re: Request - Native Java "Script" Support

Posted by Jesse Glick <jg...@cloudbees.com>.
On 09/21/2012 12:06 AM, Stefan Bodewig wrote:
> Adding support for Java as "scripting language" wouldn't be incredibly difficult

There is already a ScriptEngine for *.java out there somewhere. Not sure if it is maintained.

> write a temporary file, compile it, add the resulting class to a classloader, load it

If you drop Java 5 support you can use JSR 199 and dispense with the temporary file.


The main difficulty with *.java in <script> is that your natural inclination is to just compile

public class _ implements Callable<Void> {
   @Override public Void call() throws Exception {
     /* insert body of script here */
     return null;
   }
}

so that you can ((Callable<?>) loader.loadClass("_").newInstance()).call() to run it. Unfortunately this makes it very awkward to define helper functions in the script 
before Java 8’s lambdas; the best you can do is something like

<script>
final AtomicReference<Integer> param1 = new AtomicReference<>();
Callable<String> function = new Callable<String>() {
   @Override public String call() throws Exception {
     return "The answer is " + param1.get() + ".";
   }
};
param1.set(42);
String result = function.call();
</script>

By contrast, Groovy makes it possible to freely mix function definitions and statements, while otherwise looking like Java code, which is what you want here.


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


Re: Request - Native Java "Script" Support

Posted by Stefan Bodewig <bo...@apache.org>.
On 2012-09-20, Anders Rundgren wrote:

> Beanshell isn't an active project and I don't see any advantage with
> Beanshell compared to native Java.

The main advantage is that is provides ScriptEngine or whatever that is
called, i.e. Ant doesn't have to do anything special to handle it.

I think what Vimil wanted to say when he suggested Groovy is that you
get native Java support by using Groovy as a scripting language.  You
won't notice you are writing Groovy.

Adding support for Java as "scripting language" wouldn't be incredibly
difficult but it had to be done in a completely different way than
<script> (write a temporary file, compile it, add the resulting class to
a classloader, load it).

BTW, .NETs suppport for generating C# classes (or VB for that matter)
and compiling it on the fly is way more sophisticated than what you get
in Java.  This makes the approach look more natural to NAnt's developers
than having Java as a scripting language ever felt to us.

Stefan

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