Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve functionality of the classloader task when applied to the core loader #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

gagern
Copy link
Contributor

@gagern gagern commented Nov 27, 2014

Revisiting issue 47003. The original title was “Add to ant lib classpath from within project file” which still describes what I'm trying to accomplish here.

With these changes, the core class loader is guaranteed to always be an AntClassLoader, so the (still undocumented) <classloader> task can be used to add to that without replacing it. One use case is the following: users only have ant core available, but some dependency management tool (e.g. Ivy) provides jar files for optional tasks and their dependencies. Then adding those jars to the core class loader will make those optional tasks available without having to <taskdef> each one with the corresponding <classpath>. There is an antunit test case demonstrating this, using <junit> as an example. This approach can be used for third-party tasks as well, potentially simplifying things a lot. This should in particular help projects which up to now had a dedicated build script (or two, one shell script for *nix and one batch file for Windows) to build the class path resp. library path before invoking ant. Now they can drop those scripts and portably build the class path in ant itself.

Of course it would be useful to also document the <classloader> task, and give examples where modifying a non-core loader would be useful, and add antunit tests for that as well. But since I haven't yet figured out those non-core use cases, I'd like to keep that out of this pull request. And I'd welcome input on that.

Changes Main.runBuild to always provide an AntClassLoader as the core
loader, so there will always be a loader to which additional path elements
can be added.

Also changes the behaviour of the classloader task when name is omitted or
specified as "ant.coreLoader".  In that case, the loader is not looked up by
reference, but instead the core loader of the project is used.  This avoids
having to register a reference to this loader anywhere else.

This patch was taken from PR #47003 and dates back to April 2009.
Instead of introducing an AntClassLoader in Main, we now have the Project
class itself ensure that the core class loader is always an AntClassLoader.
This should cater for the embedded mode, where Main isn't even used.

We also use the factory method to make sure we get the right subclass of the
class loader class.  And there is some API documentation about all of this.
The documentation now specifies the version when the behavior changed. The
private variable is adjusted to reflect the fact that we always want an
AntClassLoader there.  The public interface is left as is, though, to avoid
trouble in case someone subclasses Project and overrides that method.
Although I can't imagine why someone would do that.
@bodewig
Copy link
Member

bodewig commented Nov 28, 2014

Personally I'd prefer to have the discussion about this pull request in a single place - see https://issues.apache.org/bugzilla/show_bug.cgi?id=47003

lelou6666 pushed a commit to lelou6666/ant that referenced this pull request Mar 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants