Bug 21856 - Request standardized way of finding ant.jar
Summary: Request standardized way of finding ant.jar
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.5.3
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: 1.7.0
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-24 15:22 UTC by Jesse Glick
Modified: 2008-02-22 12:18 UTC (History)
1 user (show)



Attachments
Suggested patch (5.88 KB, patch)
2003-07-24 16:06 UTC, Jesse Glick
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2003-07-24 15:22:57 UTC
It is common for build scripts to compile their own tasks and then taskdef them.
Unfortunately there is then no standard way to find ant.jar to put in the
classpath (assuming you use ${build.sysclasspath}=ignore), unless you happen to
include a copy of this JAR with your project.

You can use ${ant.home}/lib/ant.jar which works with command-line Ant from
apache.org but might not work with (1) IDEs which bundle Ant, (2) the RPM from
jpackage.org which uses a different directory structure, etc.

Suggest a new built-in property, ${ant.jar}, specifically for a JAR file
containing central Ant classes you would want to import into custom task
sources. (org.apache.tools.ant.*, basic datatypes and utilities, MatchingTask, etc.)

Motivation:

http://www.netbeans.org/issues/show_bug.cgi?id=35123
Comment 1 Jesse Glick 2003-07-24 16:06:52 UTC
Created attachment 7494 [details]
Suggested patch
Comment 2 Conor MacNeill 2003-07-25 01:30:44 UTC
Can you use the Locator class in o.a.t.a.launch?
Comment 3 Jesse Glick 2003-07-25 01:54:37 UTC
Yes, probably Locator.getClassSource would work as well as using
java.security.CodeSource.

Note that Locator.fromURI is obsoleted by the File(URI) constructor in JRE 1.4 -
I think I already filed that separately.
Comment 4 Conor MacNeill 2003-07-25 02:00:35 UTC
yes but we are going for 1.2 compat now - not 1.4
Comment 5 Jesse Glick 2003-07-25 02:13:32 UTC
[Re. File(URI)] - yes of course, I meant using reflection, when available.
Comment 6 Jesse Glick 2004-11-30 22:34:48 UTC
Cf. also bug #32405.
Comment 7 Matt Benson 2005-03-08 23:44:00 UTC
can we close this issue?
Comment 8 Jesse Glick 2005-03-09 20:14:20 UTC
I still think it would be helpful, but am willing to drop it if others disagree
(or to work on a patch if others agree).
Comment 9 Matt Benson 2005-03-09 20:29:42 UTC
For the 1.4 introspection or another way to find ant.jar ?
Comment 10 Jesse Glick 2005-03-09 20:33:32 UTC
Doesn't really matter since there is a general util method to take URI -> File,
which should in the future be fixed to behave correctly under JDK 1.4+ (and use
whatever tricks on 1.2 + 1.3).
Comment 11 Matt Benson 2005-03-09 20:39:43 UTC
I don't see any reason you can't add whatever you want in that regard.
Comment 12 Matt Benson 2005-05-25 20:24:07 UTC
In any event, the original request here is satisfied:

File antjar = org.apache.tools.ant.launch.Locator.getClassSource(
  org.apache.tools.ant.Project.class);
Comment 13 Jesse Glick 2005-05-26 01:59:10 UTC
From *code* it's available, but not from a build script.
Comment 14 Matt Benson 2005-05-26 16:47:02 UTC
Against CVS HEAD:

  <whichresource class="org.apache.tools.ant.Main" property="main" />
  <pathconvert>
    <string value="${main}" />
    <chainedmapper>
      <globmapper from="*!/org/apache/tools/ant/Main.class" to="*" />
      <globmapper from="jar:*" to="*" />
      <!-- if you want to assume it's a file, use:
      <globmapper from="jar:file:/*" to="*" /-->
    </chainedmapper>
  </pathconvert>

yields:
[pathconvert] file:/D:/ant/lib/ant.jar

an alternative would be

  <pathconvert>
    <url javaresource="org/apache/tools/ant/Main.class" />
    <chainedmapper>
      <globmapper from="*!/org/apache/tools/ant/Main.class" to="*" />
      <globmapper from="jar:*" to="*" />
      <!-- if you want to assume it's a file, use:
      <globmapper from="jar:file:/*" to="*" /-->
    </chainedmapper>
  </pathconvert>

i.e., <url javaresource="" /> overlaps <whichresource> somewhat.
Comment 15 Jesse Glick 2005-05-26 18:17:13 UTC
1. That's way too complicated. Few people would ever figure out such a thing for
themselves.

2. URL -> file conversion using prefix removal is not safe on all platforms /
filesystems and for all directory names.
Comment 16 Jesse Glick 2006-03-25 16:32:21 UTC
Also poses a problem for running the NB IDE over JNLP (under development) using
the bundled Ant, since the original Ant directory structure is not preserved:

http://www.netbeans.org/nonav/issues/show_bug.cgi?id=73990
Comment 17 J.M. (Martijn) Kruithof 2006-03-25 22:36:00 UTC
I have implemented this using ingredients from matt, jesse and myself.
I have called the property ant.core.lib as to not tie the property to a jar file
per se.
Comment 18 Matt Benson 2006-03-27 16:08:10 UTC
(In reply to comment #15)
> 1. That's way too complicated. Few people would ever figure out such a thing for
> themselves.


Just reread this and had me laughing my a$$ off... yes, it was way too
complicated, but oh what fun!  :)

-Matt