You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Daniele Development-ML <da...@googlemail.com> on 2008/11/05 18:16:19 UTC
Using Ant Tasks programmatically - SignJar Tasl
Hello everybody:
I am trying to use Ant Task programmatically by invoking the API within my
Java code.
I get an exception, but everything appears to be fine to my eyes - I indeed
set all the compulsory attributes of the SignJar task. Probably somebody
else here has a good suggestion or the solution.
Thanks in advance!
Dan
----------------------------
My code is:
String sigFile = Paths.SIG_FILE_PATH;
SignJar sj = new SignJar();
sj.setAlias("myDep");
sj.setStorepass("aPassword");
sj.setJar(new File(fileName));
sj.setSigfile(sigFile);
sj.execute();
The exception I get is:
Exception in thread "main" java.lang.NullPointerException
at
org.apache.tools.ant.types.AbstractFileSet.setupDirectoryScanner(AbstractFileSet.java:477)
at
org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFileSet.java:442)
at org.apache.tools.ant.types.FileSet.iterator(FileSet.java:69)
at
org.apache.tools.ant.types.resources.Union.getCollection(Union.java:110)
at
org.apache.tools.ant.types.resources.Union.getCollection(Union.java:90)
at
org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.cacheCollection(BaseResourceCollectionContainer.java:250)
at
org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.iterator(BaseResourceCollectionContainer.java:126)
at org.apache.tools.ant.types.Path.iterator(Path.java:693)
at org.apache.tools.ant.taskdefs.SignJar.execute(SignJar.java:321)
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Mark Salter <ma...@talktalk.net>.
Daniele Development-ML wrote:
> I am trying to use Ant Task programmatically by invoking the API within my
> Java code.
You need a Project :-
SignJar sj = new SignJar();
sj.setProject(new Project());
I surmised this by stepping through the code, but only 'blindly'.
I guess all tasks need a project (it's presence is presumed), but I
would hope this would be stated somewhere - I am going looking now.
--
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Daniele Development-ML <da...@googlemail.com>.
Yes, Peter, I totally agree with you. However, I would expect that the XML
elements and attributes are matched against some Java classes and calling
them in the same order as does the Ant parser does, it would work. And
actually it does with the above suggested statements.
Of course, it depends on the way Ant it's implemented, but considering the
team, I was sure they did a great job.
Cheers,
Dan
On Thu, Nov 6, 2008 at 1:18 PM, Peter Reilly <pe...@gmail.com>wrote:
> Also be aware that the ant java code is not designed or created to be
> used as a library. Ant java code is written to read and execute ant xml
> scripts.
>
> Peter
>
> On Thu, Nov 6, 2008 at 12:53 PM, Mark Salter <ma...@talktalk.net>
> wrote:
> > Steve Loughran wrote:
> >> There's some coverage of it the Ant docs
> >> http://ant.apache.org/manual/antexternal.html
> >>
> >> as usual, contributions to improve this -more examples etc- are welcome.
> >
> > Thanks Steve, certainly the advice given at the bottom of this page is
> > probably most relevant to the OP:-
> >
> > "
> > The question you are probably asking yourself at this point is: How
> > would I know which classes and methods have to be called in order to set
> > up a dummy Project and Target? The answer is: you don't. Ultimately, you
> > have to be willing to get your feet wet and read the source code. The
> > above example is merely designed to whet your appetite and get you
> > started. Go for it!
> > "
> >
> > --
> > Mark
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Peter Reilly <pe...@gmail.com>.
Also be aware that the ant java code is not designed or created to be
used as a library. Ant java code is written to read and execute ant xml scripts.
Peter
On Thu, Nov 6, 2008 at 12:53 PM, Mark Salter <ma...@talktalk.net> wrote:
> Steve Loughran wrote:
>> There's some coverage of it the Ant docs
>> http://ant.apache.org/manual/antexternal.html
>>
>> as usual, contributions to improve this -more examples etc- are welcome.
>
> Thanks Steve, certainly the advice given at the bottom of this page is
> probably most relevant to the OP:-
>
> "
> The question you are probably asking yourself at this point is: How
> would I know which classes and methods have to be called in order to set
> up a dummy Project and Target? The answer is: you don't. Ultimately, you
> have to be willing to get your feet wet and read the source code. The
> above example is merely designed to whet your appetite and get you
> started. Go for it!
> "
>
> --
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Mark Salter <ma...@talktalk.net>.
Steve Loughran wrote:
> There's some coverage of it the Ant docs
> http://ant.apache.org/manual/antexternal.html
>
> as usual, contributions to improve this -more examples etc- are welcome.
Thanks Steve, certainly the advice given at the bottom of this page is
probably most relevant to the OP:-
"
The question you are probably asking yourself at this point is: How
would I know which classes and methods have to be called in order to set
up a dummy Project and Target? The answer is: you don't. Ultimately, you
have to be willing to get your feet wet and read the source code. The
above example is merely designed to whet your appetite and get you
started. Go for it!
"
--
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Steve Loughran <st...@apache.org>.
Mark Salter wrote:
> Morgan Kinne wrote:
>> try sj.perform()
>>
> It looks to me like you will still need to set a sj.setProject(project).
>
> I can't find anything that states this requirement, sorry.
>
There's some coverage of it the Ant docs
http://ant.apache.org/manual/antexternal.html
as usual, contributions to improve this -more examples etc- are welcome.
--
Steve Loughran http://www.1060.org/blogxter/publish/5
Author: Ant in Action http://antbook.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 06 Nov 2008, Steve Loughran <st...@apache.org> wrote:
> Some of that code is something we should really pull into Ant to
> make it easier; some EmbeddedProject you create to remove
> effort. What do you think, Stefan?
Sounds good. This might help projects like Gant or Lancet
<http://groups.google.de/group/clojure/browse_thread/thread/7fc2ac972e9a39c9>
as well.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Steve Loughran <st...@apache.org>.
Stefan Bodewig wrote:
> On Thu, 6 Nov 2008, Daniele Development-ML <da...@googlemail.com> wrote:
>
>> Now, I get another exception, which seems somehow related to ant
>> libraries - this is my understanding.
>
> Not really.
>
>> Exception in thread "main" jarsigner returned: 1 at
>
> means the native jarsigner executable invoked eby Ant xited with exit
> code 1, which means an error occured while running it. It also means
> that Ant was able to invoke jarsigner.
>
> If you were running the same task with the same attributes inside Ant,
> you should get the command line when running in verbose mode. You
> don't seem to have set up any loggers/listeners so it's hard to tell
> where your log messages end up now.
Here's some example code to set up the logging in a project when
embedding Ant
http://antbook.cvs.sourceforge.net/viewvc/antbook/examples/sections/extending/ch18_extras/embed/src/org/antbook/embed/Embedded.java?revision=1.3&view=markup
Some of that code is something we should really pull into Ant to make it
easier; some EmbeddedProject you create to remove effort. What do you
think, Stefan?
--
Steve Loughran http://www.1060.org/blogxter/publish/5
Author: Ant in Action http://antbook.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 6 Nov 2008, Daniele Development-ML <da...@googlemail.com> wrote:
> Now, I get another exception, which seems somehow related to ant
> libraries - this is my understanding.
Not really.
> Exception in thread "main" jarsigner returned: 1 at
means the native jarsigner executable invoked eby Ant xited with exit
code 1, which means an error occured while running it. It also means
that Ant was able to invoke jarsigner.
If you were running the same task with the same attributes inside Ant,
you should get the command line when running in verbose mode. You
don't seem to have set up any loggers/listeners so it's hard to tell
where your log messages end up now.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Daniele Development-ML <da...@googlemail.com>.
Thanks.
I tried your suggestions, and the problem concerned that seems to be solved
- thanks!
Now, I get another exception, which seems somehow related to ant libraries -
this is my understanding. I have included all the ant jars in my
application. I post the exception and the new code - hoping in other
suggestions.
Thanks!
Dan
The new code is:
Project project = new Project();
Target target = new Target();
SignJar sj = new SignJar();
target.addTask(sj);
project.addTarget("sign_jar", target);
sj.setAlias("myDep");
sj.setStorepass("myPrj");
sj.setProject(project);
sj.setJar(new File(fileName));
sj.setSigfile(sigFile);
project.executeTarget("sign_jar");
Exception:
Exception in thread "main" jarsigner returned: 1
at
org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:636)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:662)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:487)
at
org.apache.tools.ant.taskdefs.SignJar.signOneJar(SignJar.java:407)
at org.apache.tools.ant.taskdefs.SignJar.execute(SignJar.java:336)
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.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:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
On Wed, Nov 5, 2008 at 9:10 PM, Mark Salter <ma...@talktalk.net> wrote:
> Morgan Kinne wrote:
> > try sj.perform()
> >
> It looks to me like you will still need to set a sj.setProject(project).
>
> I can't find anything that states this requirement, sorry.
>
> --
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Mark Salter <ma...@talktalk.net>.
Morgan Kinne wrote:
> try sj.perform()
>
It looks to me like you will still need to set a sj.setProject(project).
I can't find anything that states this requirement, sorry.
--
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Using Ant Tasks programmatically - SignJar Tasl
Posted by Morgan Kinne <ki...@us.ibm.com>.
try sj.perform()
From:
"Daniele Development-ML" <da...@googlemail.com>
To:
"Ant Users List" <us...@ant.apache.org>
Date:
11/05/2008 12:17 PM
Subject:
Using Ant Tasks programmatically - SignJar Tasl
Hello everybody:
I am trying to use Ant Task programmatically by invoking the API within my
Java code.
I get an exception, but everything appears to be fine to my eyes - I
indeed
set all the compulsory attributes of the SignJar task. Probably somebody
else here has a good suggestion or the solution.
Thanks in advance!
Dan
----------------------------
My code is:
String sigFile = Paths.SIG_FILE_PATH;
SignJar sj = new SignJar();
sj.setAlias("myDep");
sj.setStorepass("aPassword");
sj.setJar(new File(fileName));
sj.setSigfile(sigFile);
sj.execute();
The exception I get is:
Exception in thread "main" java.lang.NullPointerException
at
org.apache.tools.ant.types.AbstractFileSet.setupDirectoryScanner(AbstractFileSet.java:477)
at
org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFileSet.java:442)
at org.apache.tools.ant.types.FileSet.iterator(FileSet.java:69)
at
org.apache.tools.ant.types.resources.Union.getCollection(Union.java:110)
at
org.apache.tools.ant.types.resources.Union.getCollection(Union.java:90)
at
org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.cacheCollection(BaseResourceCollectionContainer.java:250)
at
org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.iterator(BaseResourceCollectionContainer.java:126)
at org.apache.tools.ant.types.Path.iterator(Path.java:693)
at org.apache.tools.ant.taskdefs.SignJar.execute(SignJar.java:321)